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)
|
||||
|
||||
## Require
|
||||
|
||||
```bash
|
||||
sudo apt-get install curl
|
||||
```
|
||||
|
||||
## TODO
|
||||
|
||||
- zjunet vpn
|
||||
@ -25,3 +31,5 @@ Command Line Scripts for ZJU (VPN / WLAN / DNS)
|
||||
## Links
|
||||
|
||||
- [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"
|
||||
mkdir -p $DIR
|
||||
|
||||
getall() {
|
||||
ls -1A $DIR | xargs | tr "\n" " "
|
||||
}
|
||||
|
||||
# dispatch
|
||||
case "$1" in
|
||||
|
||||
@ -38,7 +42,8 @@ case "$1" in
|
||||
;;
|
||||
|
||||
delete)
|
||||
read -p "USERNAME: " USERNAME
|
||||
USERS=$(getall)
|
||||
read -p "Delete User [ ${USERS}]: " USERNAME
|
||||
rm -i "$DIR/${USERNAME}"
|
||||
;;
|
||||
|
||||
@ -55,7 +60,7 @@ case "$1" in
|
||||
exit 1
|
||||
else
|
||||
if [ "${COUNT}" -gt "1" ]; then
|
||||
USERS=$(ls -1A $DIR | xargs | tr "\n" " ")
|
||||
USERS=$(getall)
|
||||
read -p "Choose User [ ${USERS}]: " USERNAME
|
||||
else
|
||||
USERNAME=$(ls -1 $DIR | head -n1)
|
||||
@ -67,7 +72,7 @@ case "$1" in
|
||||
# Get all users
|
||||
# @private
|
||||
getall)
|
||||
ls -1A $DIR | xargs | tr "\n" " "
|
||||
getall
|
||||
;;
|
||||
|
||||
# @private
|
||||
|
||||
40
wlan.sh
40
wlan.sh
@ -25,10 +25,16 @@ logout() {
|
||||
|
||||
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)
|
||||
if [[ "${RESPONSE}" != "ok" ]]; then
|
||||
echo "${RESPONSE}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "${RESPONSE}" in
|
||||
*ok*)
|
||||
echo "Logout: success."
|
||||
;;
|
||||
*)
|
||||
echo "Logout: ${RESPONSE}."
|
||||
exit 1;
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
login() {
|
||||
@ -39,19 +45,25 @@ login() {
|
||||
|
||||
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)
|
||||
if [[ "${RESPONSE}" = *"help.html"* || "${response}" = *"login_ok"* ]]; then
|
||||
echo "Login successful"
|
||||
else
|
||||
echo "${RESPONSE}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "${RESPONSE}" in
|
||||
*help.html*)
|
||||
echo "Login: success."
|
||||
;;
|
||||
*login_ok*)
|
||||
echo "Login: success."
|
||||
;;
|
||||
*)
|
||||
echo "Login: ${RESPONSE}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
BASEDIR=$(dirname $0)
|
||||
USER="${BASEDIR}/user.sh"
|
||||
|
||||
USERNAME=$($USER get)
|
||||
|
||||
PASSWORD=$($USER getpwd $USERNAME)
|
||||
|
||||
case "$1" in
|
||||
@ -61,4 +73,10 @@ case "$1" in
|
||||
logout)
|
||||
logout $USERNAME $PASSWORD
|
||||
;;
|
||||
*)
|
||||
echo "Usage: "
|
||||
echo " zjunet wlan login"
|
||||
echo " zjunet wlan logout"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user