愤怒的大鸟 发表于 2015-1-16 14:10:09

给大家带来Linux情况下wu-ftp服务办理剧本详解

Linux的常用命令find,察看man文档,初学者一定会觉得太复杂而不原意用,但是你一旦学会就爱不释手。
1、testftp_server.sh
1、用法:
Usage:
./testftp_server.sh{start|stop|restart|status|userconf|mini|limit|loginfails|view|access|message|guest|denyuser|denyhost}
2、参数申明:
start:
改动设置文件,并启动FTP服务器;下一次体系启动时,会主动启动该服务。
stop:
改动设置文件,并中断FTP服务器;下一次体系启动时,不主动启动该服务。
restart:
从头启动FTP服务器。
status:
检察FTP服务器的运转形态(运转或中断)。
userconf:
为体系增加FTP用户,详细用法为:
./testftp_server.shuserconfusername
新增加的用户承继超等用户的暗码。
mini:
最小化FTP服务器的设置文件,只留下FTP服务器一般运转所必需的设置项。
limit:
设置FTP服务器限定的各种用户的最年夜在线数量,详细用法为:
./testftp_server.shlimituser_counttimes
user_count---为最年夜在线数量,剧本会依据FTP服务器的设置文件主动处置某类用户。
times---times中的字符串用逗号离隔,每个字串暗示一天。礼拜一到日曜日分离用Mo、Tu、We、Th、Fr、Sa和Su暗示,周末也能够用Wk暗示。暗示工夫的小时和分钟之间不要用冒号离隔。“-”用来暗示局限。
loginfails:
设置用户最年夜的登录失利次数,详细用法为:
./testftp_server.shloginfailsfailed_counts
failed_counts---为用户最年夜的登录失利次数。
view:
检察FTP服务器的主设置文件的内容。
access:
设置FTP用户的存取权限,详细请检察利用剧本该功效的输入信息。
message:
设置FTP服务器显现的信息。
guest:
设置作为guest看待的用户,详细用法为:
./testftp_server.shguestusername
denyuser:
设置哪些用户不克不及登录FTP服务器,能够删除大概增加用户,用法:
./testftp_server.shdenyuserdel/addusername
del/add---指明是从回绝的用户列表中删除用户仍是增加用户到回绝的用户列表中。
denyhost:
指明哪些用户能够从哪些地点或回绝哪些用户能够从哪些地点会见FTP服务器,用法:
./testftp_server.shdenyhostadd/delallow/denyusernamehostname
add---为增加一条划定规矩到设置文件;假如用户名和主机名不异,则以为是统一条划定规矩;
del---为从设置文件删除一条划定规矩;假如用户名和主机名不异,则以为是统一条划定规矩;
allow/deny---指明同意仍是回绝。
username---为欲对其实行该划定规矩的用户;
hostname---为主机名
2、testftp_client.sh
客户端剧本只测试服务器真个limit选项,即最年夜在线用户限定。用法:
./testftp_client.shconn_countusernamepasswordhostname
个中:
conn_count:
与FTP服务器创建毗连的数量,应当比FTP服务器的限定数量年夜;
username:
登录FTP服务器的用户名;
password:
登录FTP服务器的用户暗码;
hostname:
FTP服务器的主机名或IP地点
FTP服务器的主机名或IP地点。

--------------------------test_server.sh------------------------
#!/bin/bash
./etc/rc.d/init.d/functions
test-f/etc/ftpaccess
if[$?-ne0];then
echo-e"07FTPServercongiffile--/etc/ftpaccessnotfound!"
echo"PleasechecktheinstallionoftheFTPServer!"
exit1
else
arg_count=$#
fi
class_defined(){
echo"Pleaserun{GetProperty(Content)}minior{GetProperty(Content)}minireal/aonoymousaddressfirst!"
exit1
fi
}
start(){
if[-f/etc/xinetd.d/wu-ftpd];then
grep-v-E"disable|}"/etc/xinetd.d/wu-ftpd>/etc/xinetd.d/wu-ftpd.tmp
echo-e"        disable                        =no
}">>/etc/xinetd.d/wu-ftpd.tmp
mv-f/etc/xinetd.d/wu-ftpd.tmp/etc/xinetd.d/wu-ftpd
/etc/rc.d/init.d/xinetdrestart>/dev/null2>&1
#CheckResult
if[`/usr/bin/nmap-p21-21localhost|grep-cftp`-eq1];then
echo"StartFTPSERVERSucceed!"
else
echo"StartFTPSERVERFailed!"
fi
fi
}
stop(){
if[-f/etc/xinetd.d/wu-ftpd];then
grep-v-E"disable|}"/etc/xinetd.d/
wu-ftpd>/etc/xinetd.d/wu-ftpd.tmp
echo-e"        disable                        =yes
}">>/
etc/xinetd.d/wu-ftpd.tmp
mv-f/etc/xinetd.d/wu-ftpd.tmp/etc/xinetd.d/wu-ftpd
/etc/rc.d/init.d/xinetdrestart>/dev/null2>&1
#CheckResult
if[`/usr/bin/nmap-p21-21localhost|grep-cftp`-eq0];then
echo"StopFTPSERVERSucceed!"
else
echo"StopFTPSERVERFailed!"
fi
fi
}
echo"FTPSERVERisrunning!"
else
echo"FTPSERVERstoped!"
fi
}
userconf(){
if[-d/home/ftp/];then
echo"Thedirectory/home/ftp/doesexist"
else
mkdir/home/ftp/
fi
if[`grep-c^$username/etc/passwd`-ne1];then
useradd-d/home/ftp/$username-s/dev/null$username
echo"User$usernameadded"
grep-v^$username/etc/shadow>/etc/shadow.tmp
echo"$username:`grep^root/etc/shadow|cut-f2-9-d:`">>
/etc/shadow.tmp
mv-f/etc/shadow.tmp/etc/shadow
echo"User$usernamepasswordisrootspassword"
fi
grep-v^$username/etc/passwd>/etc/passwd.tmp
echo"`grep^$username/etc/passwd|cut-f1-5
-d:`:/home/ftp/./$username/:/dev/null">>/etc/passwd.tmp
mv-f/etc/passwd.tmp/etc/passwd
echo"ConfigUser$usernameshellssucceed"
if[`grep-cnull/etc/shells`-ne1];then
echo-e"/dev/null">>/etc/shells
echo"SystemShell/dev/nulladded"
fi
if[-d/home/ftp/dev/];then
echo"Thedirectory/home/ftp/dev/doesexist"
else
mkdir/home/ftp/dev
echo"Createdirectory/home/ftp/devsucceed"
fi
if[-d/home/ftp/etc/];then
echo"Thedirectory/home/ftp/etc/doesexist"
echo"Createdirectory/home/ftp/etcsucceed"
fi
if[-d/home/ftp/bin/];then
echo"Thedirectory/home/ftp/bin/doesexist"
else
mkdir/home/ftp/bin
echo"Createdirectory/home/ftp/binsucceed"
fi
if[-d/home/ftp/lib/];then
echo"Thedirectory/home/ftp/lib/doesexist"
else
mkdir/home/ftp/lib
echo"Createdirectory/home/ftp/libsucceed"
fi
chmod0511/home/ftp/dev//home/ftp/etc//home/ftp/bin//home/ftp/lib/-R
if[-c/home/ftp/dev/null];then
echo"Thedirectory/home/ftp/dev/nulldoesexist"
else
mknod/home/ftp/dev/nullc13
chmod666/home/ftp/dev/null
echo"Thenod/home/ftp/dev/nulladded"
fi
if[-f/home/ftp/etc/passwd];then
:
else
echo"`grep^root/etc/passwd`">/home/ftp/etc/passwd
echo"`grep^$username/etc/passwd`">>/home/ftp/etc/passwd
echo"/home/ftp/etc/passwdconfigsucceed"
fi
if[-f/home/ftp/etc/group];then
:
else
echo"`grep^root/etc/group`">/home/ftp/etc/group
echo"`grep^$username/etc/group`">>/home/ftp/etc/group
echo"/home/ftp/etc/groupconfigsucceed"
fi
}
mini(){
if[$arg_count-eq1];then
if[-f/etc/ftpaccess.bak];then
grep^class/etc/ftpaccess.bak>/etc/ftpaccess
echo"MiniConfigFileready,now,runftpclient.shfromclient!"
grep^class/etc/ftpaccess.bak>/etc/ftpaccess
echo"MiniConfigFileready,now,runftpclient
.shfromclient!"
fi
elif[$arg_count-eq3];then
echo-e"class        $arg_type        $arg_type        $arg_addr">/etc/ftpaccess
echo"Only$arg_typeuserfrom$arg_addrbeallowedtousetheFTPServer"
else
echo-e$"07Usage:        {GetProperty(Content)}minior{GetProperty(Content)}minireal/aonoymousaddress"
echo-e"        Use*or"*"or*toreplaceAnyaddress"
fi
}
limit(){
class_defined
if[$arg_count-ne3];then
echo-e"07Usage:       
{GetProperty(Content)}limituser_counttimes"
echo-e"        user_count---MAXonlineusersatthesametime
"
echo-e"        times---duringtheperiodofonlineuserslimited"
echo-e"        Mo---Monday"
echo-e"        Tu---Tuesday"
echo-e"        We---Wednesday"
echo-e"        Th---Thursday"
echo-e"        Fr---Friday"
echo-e"        Sa---Saturday"
echo-e"        Su---Sunday"
echo-e"        Wk---Weekend"
echo-e"        0000-1800---from00:00to18:00"
echo-e"        MoTuWe---Monday,TuesdayandWednesday"
else
grep-v^limit/etc/ftpaccess|grep-v^$>/etc/ftpaccess.tmp
mv-f/etc/ftpaccess.tmp/etc/ftpaccess
echo-e"limit        $arg_class        $arg_user_count        $times        /home/ftp/.
too_many.$arg_class">>/etc/ftpaccess
echo-e"
Morethan$arg_user_count($arg_classclass)usersonline."
>/home/ftp/.too_many.$arg_class
echo-e"
Pleasetryalater!">>/home/ftp/.too_many.$arg_class
echo"Online$arg_classuserlimitedto$arg_user_countat$times!"
fi
}
loginfails(){
class_defined
if[`grep-c^loginfails/etc/ftpaccess`-eq1];then
grep-v^loginfails/etc/ftpaccess>/etc/ftpaccess.tmp
mv-f/etc/ftpaccess.tmp/etc/ftpaccess
fi
if[$arg_count-ne2];then
echo-e"07Usage:        {GetProperty(Content)}loginfailsfailed_counts"
e"loginfails        $failed_count">>/etc/ftpaccess
echo"loginfailscountlimitedto$failed_count!"
fi
}
view(){
echo-e"
*****/etc/ftpaccess*****
"
cat/etc/ftpaccess
echo-e"
*****/etc/ftpusers*****
"
cat/etc/ftpusers
echo-e"
*****/etc/ftphosts*****
"
cat/etc/ftphosts
#echo-e"
****/etc/ftpgroups****
"
#cat/etc/ftpgroups
#echo-e"
****/etc/ftpconversions****
"
#cat/etc/ftpconversions
}
access(){
class_defined
if[`grep-c^guestgroup/etc/ftpaccess`-lt1];then
echo-e"07
Guestgroupdefinenotfound!please
run{GetProperty(Content)}guestusernamefirst!"
exit1
fi
if[`grep-c^upload/etc/ftpaccess`-ne0];then
grep-v^upload/etc/ftpaccess>/etc/ftpaccess.tmp
mv-f/etc/ftpaccess.tmp/etc/ftpaccess
fi
if[-d/home/ftp/upload];then
echo"Directory/home/ftp/uploadexist!"
else
mkdir/home/ftp/upload
chmoda+w/home/ftp/upload
echo"Directory/home/ftp/uploadforusertouploadfilesredeay!"
fi
echo-e"
upload        /home/ftp/*        /        no">>/etc/ftpaccess
echo-e"upload        /home/ftp/*        /etc        no">>/etc/ftpaccess
echo-e"upload        /home/ftp/*        /dev        no"
>>/etc/ftpaccess
echo-e"
upload        /home/ftp        /upload        yes        root        ftpadmin        0600
tnodirs
">>/etc/ftpaccess
echo"Youcanuploadfilesonlytodirectory/upload!"
grep-v^chmod/etc/ftpaccess|grep-v^delete|grep-v^rename|
grep-v^overwrite>/etc/ftpaccess.tmp
mv-f/etc/ftpaccess.tmp/etc/ftpaccess
echo-e"
chmod                no        guest,anonymous">>/etc/ftpaccess
echo-e"delete                no        anonymous">>/etc/ftpaccess
echo-e"overwrite        no        anonymous">>/etc/ftpaccess
echo-e"rename                no        anonymous">>/etc/ftpaccess
e"rename                yes        real
">>/etc/ftpaccess
grep-v^noretrieve/etc/ftpaccess>/etc/ftpaccess.tmp
mv-f/etc/ftpaccess.tmp/etc/ftpaccess
echo-e"
noretrieve        /home/ftp/upload">>/etc/ftpaccess
#echo-e"noretrieve        /home/ftp/dev">>/etc/ftpaccess
#echo-e"noretrieve        /home/ftp/lib">>/etc/ftpaccess
#echo-e"noretrieve        /home/ftp/bin
">>/etc/ftpaccess
echo"Youcouldntdownloadfilesfromdirectory/home/ftp/upload!"
grep-v^guest-root/etc/ftpaccess|grep-v^restricted-gid|grep-v
^restricted-uid>/etc/ftpaccess.tmp
mv-f/etc/ftpaccess.tmp/etc/ftpaccess
echo-e"
guest-root        /home/ftp        ftpadmin">>/etc/ftpaccess
echo-e"restricted-uid        ftpadmin">>/etc/ftpaccess
echo-e"restricted-gid        ftpadmin
">>/etc/ftpaccess
}
message(){
class_defined
grep-v^message/etc/ftpaccess|grep-v^readme|grep-v^greeting
>/etc/ftpaccess.tmp
mv-f/etc/ftpaccess.tmp/etc/ftpaccess
echo-e"
ThisisMESSAGETEST,ifyouseetheinformation,
congratulations!
">/home/ftp/.welcome.msg
echo-e"
message        /home/ftp/.welcome.msg        LOGIN">>/etc/ftpaccess
echo-e"
ThisisREADMETEST,ifyouseetheinformation,congratulations
!
">/home/ftp/README.txt
echo-e"readme        readme        README*        login">>/etc/ftpaccess
echo-e"readme        README*        cwd=*">>/etc/ftpaccess
echo-e"greeting        terse
">>/etc/ftpaccess
echo-e"Only"FTPserverready"echowhenconnected!"
}
security(){
class_defined
grep-vcommands/etc/ftpaccess|grep-vtransfers|grep-vsecurity
|grep-v^passwd_check>/etc/ftpaccess.tmp
mv-f/etc/ftpaccess.tmp/etc/ftpaccess
echo-e"
log        commands        real,guest">>/etc/ftpaccess
echo-e"log        transfers        real,guest        inbound,outbound">>/etc/ftpaccess
echo"Commandsusedbyrealusersandguestuserslogedto/var/log/message!"
echo-e"passwd-check        rfc822        enforce">>/etc/ftpaccess
echo"Ifthepasswordisnttherfc822emailaddress,youwillnotloginin!"
}
guest(){
class_defined
if[$arg_count-ne2];then
echo-e"07
Usage:{GetProperty(Content)}guestusername!
"
exit1
fi
if[`grep-c^$username/etc/passwd`-lt1];then
echo-e"07Theuser$usernamedoesnotexist.
Pleaserun{GetProperty(Content)}userconffirst!"
exit1
fi
if[`grep^guestgroup/etc/ftpaccess|grep-c$username`-ge1];then
echo-e"07
User$usernamedoesexistinguestgroup!
Tryanotheruser"
else
echo-e"
guestgroup        $username">>/etc/ftpaccess
echo-e"User$usernameaddedtoguestgroup!"
fi
}
denyuser(){
if[$arg_count-ne3];then
echo-e"
07Usage:{GetProperty(Content)}denyuseradd/delusername!
"
exit1
fi
if[-f/etc/ftpusers];then
echo-e"
Deny-userlistfileready!"
else
echo"Deny-userlistfilenotfound!"
touch/etc/ftpusers
chmod0600/etc/ftpusers
echo"Createit(/etc/ftpusers)succeed!"
fi
if[`grep-c^$username/etc/passwd`-lt1];then
echo-e"07
Theuser$usernamedoesnotexist.

Pleaserun{GetProperty(Content)}userconffirst!"
exit1
fi
case"$action"in
add)
if[`grep-c^$username/etc/ftpusers`-ge1];then
echo-e"07
User$usernamedoesexistindeny-userlist
!
Tryanotheruser"
else
echo"$username">>/etc/ftpusers
echo-e"User$usernameaddedtodeny-userlist!"
fi
;;
del)
v^$username/etc/ftpusers>/etc/ftpusers.tmp
mv-f/etc/ftpusers.tmp/etc/ftpusers
echo"User$usernamedeletedfromdeny-userlist!"
;;
*)
echo-e"07Usage:{GetProperty(Content)}denyuser"add/del"username"
;;
esac
}
denyhost(){
if[$arg_count-ne5];then
echo-e"07
Usage:{GetProperty(Content)}denyhostadd/delallow/deny
usernamehostname!
"
exit1
fi
if[-f/etc/ftphosts];then
echo-e"
Deny-hostlistfileready!"
else
echo"Deny-hostlistfilenotfound!"
touch/etc/ftphosts
chmod0600/etc/ftphosts
echo"Createit(/etc/ftphosts)succeed!"
fi

case"$action"in
add)
if[`grep-w$hostname/etc/ftphosts|grep-w-c$username`
-ge1];then
echo-e"07
Deny-rule"$rule$username
$hostname"doesexistindeny-hostlist!
Tryanotherrule"
else
echo-e"$rule        $username        $hostname">>/
etc/ftphosts
echo-e"Deny-rule"$rule$username$hostname"
addedtodeny-hostlist!"
fi
;;
del)
if[`grep$hostname/etc/ftphosts|grep-c$username`-lt1];then
echo-e"07
Deny-rule"$rule$username
$hostname"doesnotexistindeny-hostlist!
Tryanotherrule"
v$username/etc/ftphosts>/etc/ftphosts.tmp
grep-w$username/etc/ftphosts|grep-v$hostname$>>/etc/ftphosts.tmp
mv/etc/ftphosts.tmp/etc/ftphosts
echo-e"
Deny-reul"$rule$username$hostname
"deletedfromdeny-hostlist!"
fi
;;
*)
echo-e"07
Usage:{GetProperty(Content)}denyhostadd/del
allow/denyusernamehostname!
"
;;
esac
}

case"{GetProperty(Content)}"in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
userconf)
if[$arg_count-lt2];then
echo-e$"07Usage:{GetProperty(Content)}userconfusername"
exit1
fi
username=$2
userconf
;;
mini)
arg_type=$2
arg_addr=$3
mini
;;
limit)
arg_class=`grep^class/etc/ftpaccess|tr
-s"[]"|cut-f2-d""|cut-f2`
arg_user_count=$2
times=$3
limit
;;
loginfails)
failed_count=$2
loginfails
;;
view)
view
;;
access)
access
;;
message)
message
;;
guest)
username=$2
guest
;;
denyuser)
action=$2
username=$3
denyuser
;;
denyhost)
if[$arg_count-ne5];then
echo-e"07
Usage:{GetProperty(Content)}denyhostadd/del
allow/denyusernamehostname!
"
exit1
fi
action=$2
rule=$3
username=$4
hostname=$5
denyhost
;;
*)
echo-e$"07Usage:
        {GetProperty(Content)}{start|stop|restart|status|
userconf|mini|limit|loginfails
                       
|view|access|message|guest|denyuser|denyhost}"
exit1
esac
-------------------------------test_client.sh--------------------------
#!/bin/sh
flags=1
conn_count={GetProperty(Content)}
username=$2
password=$3
hostname=$4
usage()
{
echo-e"07Usage:"
echo"`basename{GetProperty(Content)}`conn_countusername
passwordhostname"
echo
exit1
}

if[$#-lt4]
then
usage
fi
if[`/usr/bin/nmap-p21-21localhost
|grep-cftp`-ne1];then
echo-e"07
FTPSERVERstoped!"
fi
killall-9nc2>/dev/null
echo-e"        FTPECHO">/tmp/ftpecho
while[$flags-le$conn_count]
do
echo-e"USER$username
PASS$password
"|
nc$hostname21>/tmp/ftpecho&
sleep1
if[`grep-c"530-Please-try-a-later!"/
tmp/ftpecho`-eq1];then
echo-e"07
        `expr$flags-1`onlineusers
limitreached,Pleasetryalater!
"
break
fi
echo-e"
        $flagsFTPConnectionCompleted!"
flags=`expr$flags+1`
done


----------------------------autotelnet.sh-----------------------------
#!/usr/bin/expect-f
#wrappertomakepasswd(1)benon-interactive
#usernameispassedas1starg,passwdas2ndsetmachine
setuser
setpassword
#setsend_human{.2.41.52}
#execadduser$user
spawntelnet$machine
expect"login:"
#execsleep1
send"$user"
expect"Password:"
#execsleep1
send"$password"
#execsleep1
send"exit"
expecteof

</p>
如果你让他去用linux搭建一个web服务器,做一个linux网关,他就什么都不会了.他们把时间都浪费在了版本的转换上了.

老尸 发表于 2015-1-16 15:45:35

给大家带来Linux情况下wu-ftp服务办理剧本详解

一定要养成在命令行下工作的习惯,要知道X-window只是运行在命令行模式下的一个应用程序。在命令行下学习虽然一开始进度较慢。

山那边是海 发表于 2015-1-18 18:26:01

目前全球有超过一百多个Linux发行版本,在国内也能找到十几个常见版本。如何选择请根据你的需求和能力,RedhatLinux和DebianLinux是网络管理员的理想选择。

不帅 发表于 2015-1-27 16:24:36

如果你想深入学习Linux,看不懂因为文档实在是太难了。写的最好的、最全面的文档都是英语写的,最先发布的技术信息也都是用英语写的。

分手快乐 发表于 2015-2-5 14:26:42

随着实验课程的结束,理论课也该结束了,说实话教OS的这两位老师是我们遇到过的不错的老师(这话放这可能不太恰当).

变相怪杰 发表于 2015-2-12 06:43:47

虽然大家都比较喜欢漂亮的mm,但是在学 linux 的过程中,还是要多和“男人”接触一下:P 遇到问题的时候,出来看说和上网查之外,就是要多用 linux 下的 man 命令找找帮助。

乐观 发表于 2015-3-3 01:04:03

在学习linux的工程中,linux学习方法有很多种,这里是小编的学习心得,给大家拿出来分享一下。

第二个灵魂 发表于 2015-3-11 08:51:15

不同于Windows?系统需要花钱购买,因为Linux的核心是免费的,自由使用的,核心源代码是开放的。

小妖女 发表于 2015-3-18 03:42:12

随着IT从业人员越来越多,理论上会有更多的人使用Linux,可以肯定,Linux在以后这多时间不会消失。

灵魂腐蚀 发表于 2015-3-25 12:13:08

一些显而易见的小错误还是用vi改正比较方便。以后的大一点的程序就得在Linux下调试了,因为有的头文件在VC里面说找不到。?
页: [1]
查看完整版本: 给大家带来Linux情况下wu-ftp服务办理剧本详解