#!/bin/sh # vpn.sh -- xl2tpd connect / disconnect # # Requirements: xl2tpd # # Copyright (C) 2014 Zeno Zeng # Copyright (C) 2014 Zhang Hai # # 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 # . BASEDIR=$(dirname $0) flush() { # see also: https://github.com/QSCTech/zjunet/issues/39 "${BASEDIR}/sudo.sh" ip route flush 10.5.1.5 "${BASEDIR}/sudo.sh" ip route flush 10.5.1.7 "${BASEDIR}/sudo.sh" ip route flush 10.5.1.9 "${BASEDIR}/sudo.sh" ip route flush 10.5.6.2 } disconnect() { users=$("${BASEDIR}/user.sh" getall) for username in $users; do "${BASEDIR}/sudo.sh" "${BASEDIR}/xl2tpd.sh" disconnect $username done "${BASEDIR}/sudo.sh" "${BASEDIR}/route.sh" } connect() { 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" waituser $username flush done "${BASEDIR}/sudo.sh" "${BASEDIR}/route.sh" } ##################################### # # Dispatch # ##################################### # start xl2tpd if not "${BASEDIR}/sudo.sh" "${BASEDIR}/xl2tpd.sh" trystart case "$1" in d|-d|disconnect) disconnect ;; ""|c|-c|connect) disconnect sleep 3 connect ;; *) echo Invalid subcommand \"$1\" for \`zjunet vpn\`. Run \`zjunet usage\` for help. ;; esac