发信人: zenz.hu(真)
整理人: hackerbay(2002-09-06 16:48:51), 站内信件
|
★原文转载自openbsd版zenz.hu的《PPPoE拨号脚本生成器》★ 帮一个懒惰的朋友写的,看看大家有没有用。
#!/bin/sh
isin(){
local _a=$1
shift
while [ $# != 0 ]; do
if [ "$_a" = "$1" ]; then return 0; fi
shift
done
return 1
}
cutword(){
local _a _n _oifs="$IFS"
case "$1" in
-t?*) IFS=${1#-t}; shift;;
esac
_n=$1
while read _a; do
set -- $_a
test "$1" = "" && break
eval echo \$$_n
done
IFS="$_oifs"
}
get_ifdevs(){
ifconfig -a | egrep -v '^([[:space:]]|(lo|enc|gre|ppp|sl|tun|bridge|pflog|vlan)[[:digit:]])' | cutword -t: 1
}
getresp() {
local _shell_aware=0
local _no_shell=0
# -s option means exit after a shell (caller is shell-aware)
if [ "$1" = "-s" ]; then
_shell_aware=1
shift
fi
# -n option means don't try to run shell commands
if [ "$1" = "-n" ]; then
_no_shell=1
shift
fi
set -o noglob
valid="false"
while [ "X$valid" = "Xfalse" ]; do
read resp
if [ ${_no_shell} -eq 1 ]; then
test -z "$resp" && resp=$1
else
case "$resp" in
"") resp=$1
;;
!) echo "Type 'exit' to return to install."
sh
test $_shell_aware -eq 0 && continue
;;
!*)
eval ${resp#?}
test $_shell_aware -eq 0 && continue
;;
esac
fi
if [ $# -gt 1 ]; then
for i in $@; do
if [ "X$resp" = "X$i" ]; then
valid="true"
fi
done
else
valid="true"
fi
if [ "X$valid" = "Xfalse" ]; then
echo "Try again: Enter one of [$@]"
fi
done
set +o noglob
}
createscript(){
local _a=$1 _hostfile _authname _authkey _authpair
_hostfile="/etc/hostname.$_a"
if [ -f $_hostfile ]; then
echo "hostfile already exist!"
else
touch $_hostfile
echo "up" >> $_hostfile
fi
_authpair=
while [ $_authname != $_authpair ]; do
echo -n "give me your account:[sample] "
getresp "sample"
_authname=$resp
echo -n "input account again:[$_authname] "
getresp "sample"
_authpair=$resp
done
_authpair=
while [ $_authkey != $_authpair ]; do
echo -n "give me your password:[password] "
getresp "password"
_authkey=$resp
echo -n "input password again:[$_authkey] "
getresp "password"
_authpair=$resp
done
if [ -f /etc/ppp/ppp.conf ]; then
mv /etc/ppp/ppp.conf /etc/ppp/ppp.conf.old
fi
cat > /etc/ppp/ppp.conf << __EOT
default:
set log Phase Chat tun command
pppoe:
set device !/usr/sbin/pppoe -i $_a
set mru 1492
set mtu 1492
set speed sync
disable acfcomp protocomp
deny acfcomp
set authname $_authname
set authkey $_authkey
set ifaddr 10.0.0.1/0 10.0.0.2/0
add default HISADDR
nat enable yes
enable mssfixup
__EOT
chmod 600 /etc/ppp/ppp.conf
}
chooseifdev(){
local _show_advice=1
valid_ifdev=`get_ifdevs`
while [ X"${resp}" != X"none" ]; do
if [ $_show_advice=1 ]; then
echo "The if device that you can choose for pppoe:"
echo "$valid_ifdev"
echo -n "please make a choose:[none]"
fi
getresp "none"
case $resp in
none)
echo "You choose to not make a adsl dialup script. good bye."
;;
*)
_show_advice=1;
if isin $resp $valid_ifdev; then
createscript $resp
echo "ok, i will make adsl dialup script for you."
resp="none"
else
echo "Invalid response:\"$resp\" is not in list."
fi
;;
esac
done
}
chooseifdev
----
来OpenBSD版看看吧!
我的QQ:2562293 |
|