1
0
mirror of https://github.com/QSCTech/zjunet.git synced 2026-01-22 11:44:48 +08:00
zjunet/lib/wlan.sh

89 lines
2.2 KiB
Bash
Raw Normal View History

2014-09-20 17:19:56 +08:00
#!/bin/sh
# wlan.sh -- login/logout for ZJUWLAN
2014-09-20 15:39:28 +08:00
#
2014-10-02 13:25:28 +08:00
# Requirements: curl
2014-09-20 18:20:13 +08:00
#
2014-09-20 15:39:28 +08:00
# Copyright (C) 2014 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
# Copyright (C) 2014 Zeno Zeng <zenoofzeng@gmail.com>
#
# 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)
USER="${BASEDIR}/user.sh"
USERNAME=$($USER get)
PASSWORD=$($USER getpwd $USERNAME)
2014-09-20 15:39:28 +08:00
logout() {
USERNAME=$1
PASSWORD=$2
echo "Logout: ${USERNAME}"
2014-09-23 16:31:12 +08:00
RESPONSE=$(curl "https://net.zju.edu.cn/cgi-bin/srun_portal" -H "Content-Type: application/x-www-form-urlencoded" -d "action=logout" -s)
2014-09-20 18:13:40 +08:00
case "${RESPONSE}" in
*ok*)
echo "Logout: success."
2014-09-23 16:31:12 +08:00
;;
*成功*)
echo "Logout: success."
2014-09-20 18:13:40 +08:00
;;
*)
2014-09-20 18:20:13 +08:00
echo "Logout: ${RESPONSE}"
2014-09-20 18:13:40 +08:00
exit 1;
;;
esac
2014-09-20 15:39:28 +08:00
}
login() {
USERNAME=$1
PASSWORD=$2
logout $USERNAME $PASSWORD
echo "Login: ${USERNAME}"
2014-10-02 13:25:28 +08:00
RESPONSE=$(curl "https://net.zju.edu.cn/cgi-bin/srun_portal" -H "Content-Type: application/x-www-form-urlencoded" -d "action=login&username=${USERNAME}&password=${PASSWORD}&ac_id=3&type=1&is_ldap=1&local_auth=1" -s)
2014-09-20 18:13:40 +08:00
case "${RESPONSE}" in
*help.html*)
echo "Login: success."
;;
*login_ok*)
echo "Login: success."
;;
*)
echo "Login: ${RESPONSE}" >&2
exit 1
;;
esac
2014-09-20 15:39:28 +08:00
}
2014-09-20 17:19:56 +08:00
2014-09-19 23:36:35 +08:00
case "$1" in
2014-09-28 21:39:15 +08:00
disconnect)
logout $USERNAME $PASSWORD
2014-09-19 23:36:35 +08:00
;;
2014-09-28 21:39:15 +08:00
-d)
2014-09-20 17:19:56 +08:00
logout $USERNAME $PASSWORD
2014-09-19 23:36:35 +08:00
;;
2014-09-20 18:13:40 +08:00
*)
2014-09-28 21:39:15 +08:00
login $USERNAME $PASSWORD
2014-09-20 18:13:40 +08:00
;;
2014-10-15 15:24:31 +08:00
"${BASEDIR}/sudo.sh" "${BASEDIR}/route.sh"
2014-09-19 23:36:35 +08:00
esac