1
0
mirror of https://github.com/QSCTech/zjunet.git synced 2026-01-23 04:04:48 +08:00

use xl2tpd.conf, abandon .zjunet/

This commit is contained in:
Zeno Zeng 2014-10-15 16:24:20 +08:00
parent 2536ecd32e
commit 28f310e4b1
5 changed files with 26 additions and 49 deletions

View File

@ -26,12 +26,12 @@ Command Line Scripts for ZJU (VPN / WLAN / DNS)
### Debian / Ubuntu
https://github.com/QSCTech/zjunet/releases
https://github.com/QSCTech/zjunet/releases
下载 deb双击安装就是。
### Openwrt
https://github.com/QSCTech/zjunet/releases
https://github.com/QSCTech/zjunet/releases
下载 opk然后 `opkg install` 就是。
### From source

View File

@ -19,21 +19,18 @@
# <http://www.gnu.org/licenses/>.
# init
users_enabled="$HOME/.zjunet/users-enabled"
users_disabled="$HOME/.zjunet/users-disabled"
mkdir -p $users_enabled
mkdir -p $users_disabled
L2TPD_CFG_FILE=/etc/xl2tpd/xl2tpd.conf
BASEDIR=$(dirname $0)
getall() {
ls -1A $users_enabled | xargs | tr "\n" " "
cat $L2TPD_CFG_FILE | grep lac | sed 's/\[lac zju-l2tp-//' | sed 's/\]//'
}
edituser() {
username=$1
password=$2
echo $password > "$users_enabled/${username}"
echo "[INFO] Disconnect VPN"
"${BASEDIR}/vpn.sh" disconnect
echo "[INFO] Write to xl2tpd.conf"
@ -45,18 +42,6 @@ edituser() {
# dispatch
case "$1" in
enable)
users=$(ls -1A $users_disabled | xargs | tr "\n" " ")
read -p "Enable User [ ${users}]: " username
mv "${users_disabled}/${username}" "${users_enabled}/${username}"
;;
disable)
users=$(getall)
read -p "Disable User [ ${users}]: " username
mv "${users_enabled}/${username}" "${users_disabled}/${username}"
;;
add)
read -p "username: " username
read -p "password: " password
@ -70,14 +55,8 @@ case "$1" in
edituser $username $password
;;
delete)
users=$(getall)
read -p "Delete User [ ${users}]: " username
rm -i "$users_enabled/${username}"
;;
list)
ls -1A $users_enabled
getall
;;
# Get a user
@ -107,8 +86,9 @@ case "$1" in
# @private
getpwd)
username=$2
cat "${users_enabled}/${username}"
"${BASEDIR}/sudo.sh" cat /etc/ppp/peers/zju-l2tp-${username} | grep password | sed 's/password //'
;;
*)
${BASEDIR}/zjunet.sh usage
;;

View File

@ -42,12 +42,16 @@ disconnect() {
connect() {
disconnect
sleep 3
users=$("${BASEDIR}/user.sh" getall)
"${BASEDIR}/sudo.sh" "${BASEDIR}/xl2tpd.sh" restart
for username in $users; do
password=$("${BASEDIR}/user.sh" getpwd $username)
echo "[INFO] Login using ${username}"
"${BASEDIR}/sudo.sh" "${BASEDIR}/xl2tpd.sh" connect $username $password
"${BASEDIR}/sudo.sh" "${BASEDIR}/xl2tpd.sh" waituser $username
flush
done

View File

@ -27,7 +27,7 @@ L2TPD_CFG_FILE=/etc/xl2tpd/xl2tpd.conf
USERNAME=$2
PASSWORD=$3
LAC_NAME=zju-l2tp-${USERNAME}
PPP_LOG_FILE=/tmp/zju-l2tp-log
PPP_LOG_FILE=/tmp/zju-l2tp-log-${USERNAME}
PPP_OPT_FILE=/etc/ppp/peers/${LAC_NAME}
mkdir -p /var/log/zjunet/
@ -86,7 +86,6 @@ xl2tpd_restart() {
}
xl2tpd_create_lac() {
#touch $PPP_LOG_FILE
cat > $PPP_OPT_FILE <<EOF
noauth
@ -123,14 +122,7 @@ xl2tpd_disconnect() {
xl2tpd-control disconnect $1
}
connect() {
xl2tpd_disconnect ${LAC_NAME}
xl2tpd_connect ${LAC_NAME}
echo -n > $PPP_LOG_FILE
prev_count=$(ip addr show | grep 'inet.*ppp' | grep ' 10.5.' | wc -l)
xl2tpd_waituser() {
for i in $(seq 0 10000); do
tail $PPP_LOG_FILE >> $LOG_FILE
@ -146,10 +138,13 @@ connect() {
fi
echo -n > $PPP_LOG_FILE
count=$(ip addr show | grep 'inet.*ppp' | grep ' 10.5.' | wc -l)
if [ ${count} -gt ${prev_count} ]; then
echo "Bring up ppp, done."
return
pid="/var/run/ppp-${LAC_NAME}.pid"
if [ -e $pid ]; then
ppp=$(cat $pid | grep ppp)
if ip addr show | grep "inet.*${ppp}" > /dev/null; then
ip addr show | grep "inet.*${ppp}" | sed 's/^ */[VPN] /'
return
fi
fi
done
@ -180,8 +175,8 @@ case $1 in
xl2tpd_create_lac
;;
connect)
connect
waituser)
xl2tpd_waituser
;;
disconnect)

View File

@ -52,11 +52,9 @@ Usage: zjunet [ACTION]
Actions:
user
add Add a user
edit Edit a (enabled) user
delete Delete a (enabled) user
list List all enabled users
enable Enable a user
disable Disable a user
edit Edit a (enabled) user
Note: to delete/disable a user, edit /etc/xl2tpd/xl2tpd.conf yourself
all
connect(-c) Connect VPN & ZJUWLAN, and combine them using nexthop
disconnect(-d) Disconnect VPN & ZJUWLAN