1
0
mirror of https://github.com/QSCTech/zjunet.git synced 2026-01-22 19:54: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

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

View File

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

View File

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

View File

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