mirror of
https://github.com/QSCTech/zjunet.git
synced 2026-01-22 11:44:48 +08:00
wlan.sh (in Bourne Shell)
This commit is contained in:
parent
ee1e5e95ab
commit
4b38353f33
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
Command Line Scripts for ZJU (VPN / WLAN / DNS)
|
Command Line Scripts for ZJU (VPN / WLAN / DNS)
|
||||||
|
|
||||||
|
## Require
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt-get install curl
|
||||||
|
```
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- zjunet vpn
|
- zjunet vpn
|
||||||
@ -25,3 +31,5 @@ Command Line Scripts for ZJU (VPN / WLAN / DNS)
|
|||||||
## Links
|
## Links
|
||||||
|
|
||||||
- [Array in unix Bourne Shell](http://unix.stackexchange.com/questions/137566/array-in-unix-bourne-shell)
|
- [Array in unix Bourne Shell](http://unix.stackexchange.com/questions/137566/array-in-unix-bourne-shell)
|
||||||
|
|
||||||
|
- [How do you tell if a string contains another string in Unix shell scripting?](http://stackoverflow.com/questions/2829613/how-do-you-tell-if-a-string-contains-another-string-in-unix-shell-scripting)
|
||||||
|
|||||||
11
user.sh
11
user.sh
@ -22,6 +22,10 @@
|
|||||||
DIR="$HOME/.zjunet"
|
DIR="$HOME/.zjunet"
|
||||||
mkdir -p $DIR
|
mkdir -p $DIR
|
||||||
|
|
||||||
|
getall() {
|
||||||
|
ls -1A $DIR | xargs | tr "\n" " "
|
||||||
|
}
|
||||||
|
|
||||||
# dispatch
|
# dispatch
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
|
||||||
@ -38,7 +42,8 @@ case "$1" in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
delete)
|
delete)
|
||||||
read -p "USERNAME: " USERNAME
|
USERS=$(getall)
|
||||||
|
read -p "Delete User [ ${USERS}]: " USERNAME
|
||||||
rm -i "$DIR/${USERNAME}"
|
rm -i "$DIR/${USERNAME}"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@ -55,7 +60,7 @@ case "$1" in
|
|||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
if [ "${COUNT}" -gt "1" ]; then
|
if [ "${COUNT}" -gt "1" ]; then
|
||||||
USERS=$(ls -1A $DIR | xargs | tr "\n" " ")
|
USERS=$(getall)
|
||||||
read -p "Choose User [ ${USERS}]: " USERNAME
|
read -p "Choose User [ ${USERS}]: " USERNAME
|
||||||
else
|
else
|
||||||
USERNAME=$(ls -1 $DIR | head -n1)
|
USERNAME=$(ls -1 $DIR | head -n1)
|
||||||
@ -67,7 +72,7 @@ case "$1" in
|
|||||||
# Get all users
|
# Get all users
|
||||||
# @private
|
# @private
|
||||||
getall)
|
getall)
|
||||||
ls -1A $DIR | xargs | tr "\n" " "
|
getall
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
|
|||||||
40
wlan.sh
40
wlan.sh
@ -25,10 +25,16 @@ logout() {
|
|||||||
|
|
||||||
echo "Logout: ${USERNAME}"
|
echo "Logout: ${USERNAME}"
|
||||||
RESPONSE=$(curl "https://net.zju.edu.cn/rad_online.php" -H "Content-Type: application/x-www-form-urlencoded" -d "action=auto_dm&username=${USERNAME}&password=${PASSWORD}" -s)
|
RESPONSE=$(curl "https://net.zju.edu.cn/rad_online.php" -H "Content-Type: application/x-www-form-urlencoded" -d "action=auto_dm&username=${USERNAME}&password=${PASSWORD}" -s)
|
||||||
if [[ "${RESPONSE}" != "ok" ]]; then
|
|
||||||
echo "${RESPONSE}" >&2
|
case "${RESPONSE}" in
|
||||||
exit 1
|
*ok*)
|
||||||
fi
|
echo "Logout: success."
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Logout: ${RESPONSE}."
|
||||||
|
exit 1;
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
login() {
|
login() {
|
||||||
@ -39,19 +45,25 @@ login() {
|
|||||||
|
|
||||||
echo "Login: ${USERNAME}"
|
echo "Login: ${USERNAME}"
|
||||||
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)
|
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)
|
||||||
if [[ "${RESPONSE}" = *"help.html"* || "${response}" = *"login_ok"* ]]; then
|
|
||||||
echo "Login successful"
|
case "${RESPONSE}" in
|
||||||
else
|
*help.html*)
|
||||||
echo "${RESPONSE}" >&2
|
echo "Login: success."
|
||||||
exit 1
|
;;
|
||||||
fi
|
*login_ok*)
|
||||||
|
echo "Login: success."
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Login: ${RESPONSE}" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
BASEDIR=$(dirname $0)
|
BASEDIR=$(dirname $0)
|
||||||
USER="${BASEDIR}/user.sh"
|
USER="${BASEDIR}/user.sh"
|
||||||
|
|
||||||
USERNAME=$($USER get)
|
USERNAME=$($USER get)
|
||||||
|
|
||||||
PASSWORD=$($USER getpwd $USERNAME)
|
PASSWORD=$($USER getpwd $USERNAME)
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -61,4 +73,10 @@ case "$1" in
|
|||||||
logout)
|
logout)
|
||||||
logout $USERNAME $PASSWORD
|
logout $USERNAME $PASSWORD
|
||||||
;;
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: "
|
||||||
|
echo " zjunet wlan login"
|
||||||
|
echo " zjunet wlan logout"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|||||||
@ -28,10 +28,10 @@ case "$1" in
|
|||||||
ip route show 0/0 | cut -d " " -f 3
|
ip route show 0/0 | cut -d " " -f 3
|
||||||
;;
|
;;
|
||||||
wlan)
|
wlan)
|
||||||
"${BASEDIR}/wlan.sh"
|
"${BASEDIR}/wlan.sh" $2
|
||||||
;;
|
;;
|
||||||
vpn)
|
vpn)
|
||||||
"${BASEDIR}/vpn.sh"
|
"${BASEDIR}/vpn.sh" $2
|
||||||
;;
|
;;
|
||||||
dns)
|
dns)
|
||||||
"${BASEDIR}/dns.sh"
|
"${BASEDIR}/dns.sh"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user