2014-09-20 18:46:30 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
# vpn.sh -- xl2tpd connect / disconnect
|
|
|
|
|
#
|
|
|
|
|
# Requirements: xl2tpd
|
|
|
|
|
#
|
|
|
|
|
# Copyright (C) 2014 Zeno Zeng <zenoofzeng@gmail.com>
|
2014-09-21 15:33:26 +08:00
|
|
|
# Copyright (C) 2014 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
|
2014-09-20 18:46:30 +08:00
|
|
|
#
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
# General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program. If not, see
|
|
|
|
|
# <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2014-09-28 21:39:15 +08:00
|
|
|
BASEDIR=$(dirname $0)
|
2014-09-20 18:46:30 +08:00
|
|
|
|
2014-09-21 23:59:24 +08:00
|
|
|
disconnect() {
|
2014-09-21 20:28:40 +08:00
|
|
|
users=$("${BASEDIR}/user.sh" getall)
|
|
|
|
|
for username in $users; do
|
2014-09-28 19:44:56 +08:00
|
|
|
echo "[INFO] Logout: ${username}"
|
2014-09-21 23:59:24 +08:00
|
|
|
"${BASEDIR}/xl2tpd.sh" disconnect $username
|
2014-09-21 20:28:40 +08:00
|
|
|
done
|
2014-09-28 21:39:15 +08:00
|
|
|
"${BASEDIR}/route.sh"
|
2014-09-20 18:46:30 +08:00
|
|
|
}
|
|
|
|
|
|
2014-09-21 23:59:24 +08:00
|
|
|
connect() {
|
|
|
|
|
disconnect
|
2014-09-21 23:03:24 +08:00
|
|
|
users=$("${BASEDIR}/user.sh" getall)
|
2014-09-28 19:44:56 +08:00
|
|
|
|
2014-09-21 23:03:24 +08:00
|
|
|
for username in $users; do
|
2014-09-21 23:59:24 +08:00
|
|
|
password=$("${BASEDIR}/user.sh" getpwd $username)
|
2014-09-28 19:44:56 +08:00
|
|
|
echo "[INFO] Login using ${username}"
|
2014-09-21 23:59:24 +08:00
|
|
|
"${BASEDIR}/xl2tpd.sh" connect $username $password
|
2014-09-21 23:03:24 +08:00
|
|
|
done
|
2014-09-28 19:44:56 +08:00
|
|
|
|
2014-09-28 21:39:15 +08:00
|
|
|
"${BASEDIR}/route.sh"
|
2014-09-21 23:03:24 +08:00
|
|
|
}
|
|
|
|
|
|
2014-09-21 15:33:26 +08:00
|
|
|
#####################################
|
|
|
|
|
#
|
|
|
|
|
# Dispatch
|
|
|
|
|
#
|
|
|
|
|
#####################################
|
|
|
|
|
|
2014-09-20 18:46:30 +08:00
|
|
|
case "$1" in
|
|
|
|
|
|
|
|
|
|
-d)
|
|
|
|
|
disconnect
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
disconnect)
|
|
|
|
|
disconnect
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
*)
|
|
|
|
|
connect
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
esac
|