純命令寫成,可以記錄登錄時間與用戶,二次開發空間大,需busybox與ash的支持,話不多說直接上腳本:
登錄腳本(login.sh):
#!/bin/ash
cname=$(cat /etc/telnet.cfg | grep username)
cpwd=$(cat /etc/telnet.cfg | grep passwd)
#/etc/telnet.cfg可修改,與createconfig創建的保持一致即可
echo "---------" >> /tmp/telnetLOG
echo "有新登錄請求!時間:" >> /tmp/telnetLOG
uptime >> /tmp/telnetLOG
read -p "login: " username
echo "用戶:"$username >> /tmp/telnetLOG
if [ "$cname" = "username $username" ]
then
read -p "Password:" passwd
if [ "$cpwd" = "passwd $passwd" ]
then
echo "登錄成功!" >> /tmp/telnetLOG
/bin/ash --login
else
echo Error!
#可自定義顯示內容
fi
else
echo Error!
fi
更換密碼腳本(changepasswd.sh):
#!/bin/ash
cname=$(cat /etc/telnet.cfg | grep username)
cpwd=$(cat /etc/telnet.cfg | grep passwd)
echo "Changing telnet passwd..."
read -p "Old Passwd: " tpwd
read -p "New Passwd: " npwd
if [ "passwd $tpwd" = "$cpwd" ]
then
rm /etc/telnet.cfg
touch /etc/telnet.cfg
echo "$cname" >/etc/telnet.cfg
echo "passwd $npwd" >>/etc/telnet.cfg
chown root /etc/telnet.cfg
chmod 000 /etc/telnet.cfg
chmod +r /etc/telnet.cfg
chmod +w /etc/telnet.cfg
#上方四行如為單用戶系統(即只有root可登陸)可以洗掉
else
echo "Error!"
#可定制顯示內容
fi
創建組態檔腳本(createconfig.sh):
#!/bin/ash
echo "Changing telnet config..."
if [ "$(cat /etc/telnet.cfg 2>/dev/null)"x != "x" ]
then
echo "passwd file already exists"
else
read -p "Username: " uname
read -p "Passwd: " upwd
#檔案地址可修改,與其他腳本保持一致
rm /etc/telnet.cfg
echo "username $uname" >/etc/telnet.cfg
echo "passwd $upwd" >>/etc/telnet.cfg
chown root /etc/telnet.cfg
chmod 000 /etc/telnet.cfg
chmod +r /etc/telnet.cfg
chmod +w /etc/telnet.cfg
#同樣如為單用戶可洗掉
fi
查看日志腳本(showlog.sh):
#!/bin/ash
cat /tmp/telnetLOG
清除日志腳本(clearlog.sh):
#!/bin/ash
cpwd=$(cat /etc/telnet.cfg | grep passwd)
read -p "input:" passwd
if [ "passwd $passwd" = "$cpwd" ]
then
rm /tmp/telnetLOG
touch /tmp/telnetLOG
chown root /etc/telnet.cfg
chmod 000 /etc/telnet.cfg
chmod +r /etc/telnet.cfg
chmod +w /etc/telnet.cfg
else
echo Error!
fi
一鍵安裝腳本(install.sh):
#!/bin/ash
busybox=$(which busybox)
#下方代碼塊如果確定有ln和whoami可洗掉
for i in ln whoami
do
if [ "$(which $i)"x = "x" ]
then
busybox ln -s $busybox /bin/$i
fi
done
ifroot=$(whoami)
if [ "$ifroot" = "root" ]
then
echo "1.復制所有檔案到/bin下..."
#cp /bin/login.sh /bin/logib.sh.bak
rm /bin/login.sh
#如/bin下真的有login.sh請洗掉上方注釋
cp *.sh /bin
echo "2.創建必須檔案鏈接(可能出現報錯請忽略)"
#如確信下方軟體都存在可直接洗掉
for file in cp rm ln whoami chmod which grep uptime chown touch
do
if [ "$(which $file)"x = "x" ]
then
ln -s $busybox /bin/$file
fi
done
if [ "$(which telnetd)"x = "x" ]
then
echo "你沒有telnetd...正從busybox復制(如果支持)"
ln -s $busybox /bin/telnetd
else
echo "找到telnetd..."
fi
echo "3.給主程式可執行權限"
chmod +x /bin/*.sh
echo "4.配置"
/bin/createconfig.sh
echo "5.啟動telnetd"
$(which telnetd) -l /bin/login.sh
echo "如果需要將telnetd加入啟動串列請按1,其他鍵即跳過"
read -p "choise: " rc
if [ "$rc" = "1" ]
then
echo "$(which telnetd) -l /bin/login.sh" > /etc/init.d/telnetd
ln -s /etc/init.d/telnetd /etc/rc.d/S50telnet
#請確保系統使用rc.d而不是rc*.d 如是請自行修改.
else
echo "已跳過……"
fi
echo "安裝完成!"
rm /bin/install.sh
else
echo "請使用root用戶打開或檢查報錯資訊!"
fi
下載:藍奏云
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/417024.html
標籤:嵌入式
上一篇:白話linux作業系統原理
下一篇:基礎夯實:作業系統
