-
Notifications
You must be signed in to change notification settings - Fork 2
/
dial.sh
executable file
·151 lines (135 loc) · 6.14 KB
/
dial.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/sh
set -euo pipefail
####################################
# Error Code: #
# 1: Missing wget and/or curl #
# 2: username or password is empty #
####################################
VERSION="1.1.2"
################## Config Segment ###################
## Contents in this section will remain in self updating.
# Config area
username="" # 你的学号 Your CampusID
password="" # 你的密码 Your Password
# Uncomment below line to configure your network isp
isp="" # 校园网 Campus Network
#isp="%40telecom" # 中国电信 China Telecom
#isp="%40unicom" # 中国联通 China Unicom
#isp="%40cmcc" # 中国移动 China Mobile
# Self update
auto_update=1 # 1: yes 0: no
watchdog_update=1 # 1: yes 0: no
######################################################
################### Code Segment #####################
login() {
if [[ $have_wget = 1 ]]; then
wget --no-check-certificate -q -O - "http://10.0.1.5/drcom/login?callback=dr1003&DDDDD=${username}${isp}&upass=${password}&0MKKey=123456&R1=0&R2=&R3=0&R6=0¶=00&v6ip=&terminal_type=1&lang=zh-cn&jsVersion=4.1&v=2223&lang=zh"
fi
if [[ $have_curl = 1 ]]; then
curl --silent --insecure "http://10.0.1.5/drcom/login?callback=dr1003&DDDDD=${username}${isp}&upass=${password}&0MKKey=123456&R1=0&R2=&R3=0&R6=0¶=00&v6ip=&terminal_type=1&lang=zh-cn&jsVersion=4.1&v=2223&lang=zh"
fi
}
logout() {
if [[ $have_wget = 1 ]]; then
wget --no-check-certificate -q -O - "http://10.0.1.5:801/eportal/portal/mac/unbind?callback=dr1003&user_account=$username$isp&wlan_user_mac=000000000000&wlan_user_ip=$(get_ip)&jsVersion=4.1&v=3685&lang=zh"
wget --no-check-certificate -q -O - "http://10.0.1.5:801/eportal/portal/logout?callback=dr1004&login_method=0&user_account=drcom&user_password=123&ac_logout=1®ister_mode=1&wlan_user_ip=$(get_ip)&wlan_user_ipv6=&wlan_vlan_id=1&wlan_user_mac=000000000000&wlan_ac_ip=&wlan_ac_name=&jsVersion=4.1&v=3340&lang=zh"
fi
if [[ $have_curl = 1 ]]; then
curl --silent --insecure "http://10.0.1.5:801/eportal/portal/mac/unbind?callback=dr1003&user_account=$username$isp&wlan_user_mac=000000000000&wlan_user_ip=$(get_ip)&jsVersion=4.1&v=3685&lang=zh"
curl --silent --insecure "http://10.0.1.5:801/eportal/portal/logout?callback=dr1004&login_method=0&user_account=drcom&user_password=123&ac_logout=1®ister_mode=1&wlan_user_ip=$(get_ip)&wlan_user_ipv6=&wlan_vlan_id=1&wlan_user_mac=000000000000&wlan_ac_ip=&wlan_ac_name=&jsVersion=4.1&v=3340&lang=zh"
fi
}
get_ip() {
ifconfig | grep -E '^(eth|en)' -A 5 | grep -E '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' -o | head -1
}
help() {
echo 'A simple script to play around with GUET network auth system.'
echo 'GitHub page: https://github.com/the-eric-kwok/GUET_Dialer_New'
echo ''
echo -e '\033[1mMODIFY THE SCRIPT TO CONFIGURE BEFORE YOU USE IT!\033[0m'
echo ''
echo 'Usage: dial.sh <option>'
echo ''
echo 'Options:'
echo ' login login with provided info'
echo ' logout you got that'
echo ' version print your script version'
echo ''
}
print_version() {
echo "Version: $VERSION"
}
update() {
echo 'Checking for update...'
remote_link='https://gitee.com/erickwok404/GUET_Dialer_New/raw/main/dial.sh'
watchdog_link='https://gitee.com/erickwok404/GUET_Dialer_New/raw/main/watchdog.sh'
[ $have_wget -eq 1 ] && [ $have_curl -eq 0 ] && remote_version=$(wget --no-check-certificate -q -O - $remote_link | grep "VERSION=")
[ $have_curl -eq 1 ] && [ $have_wget -eq 0 ] && remote_version=$(curl --insecure -fsSL $remote_link | grep "VERSION=")
[ $have_curl -eq 1 ] && [ $have_wget -eq 1 ] && remote_version=$(curl --insecure -fsSL $remote_link | grep "VERSION=")
remote_version=$(echo $remote_version | grep -o '\d*\.\d*\.\d*')
rD1=$(echo $remote_version | cut -d'.' -f1)
rD2=$(echo $remote_version | cut -d'.' -f2)
rD3=$(echo $remote_version | cut -d'.' -f3)
lD1=$(echo $VERSION | cut -d'.' -f1)
lD2=$(echo $VERSION | cut -d'.' -f2)
lD3=$(echo $VERSION | cut -d'.' -f3)
if [ $lD1 -ge $rD1 ] && [ $lD2 -ge $rD2 ] && [ $lD3 -ge $rD3 ]; then
echo 'Already up-to-date.'
return
else
if [ $auto_update -eq 0 ]; then
echo "Auto update is disabled"
return
elif [ $have_wget -eq 1 ]; then
echo 'Updating...'
wget --no-check-certificate -q -O dial_new.sh $remote_link
[ $watchdog_update -eq 1 ] && rm watchdog.sh && wget --no-check-certificate -q $watchdog_link
elif [ $have_curl -eq 1 ]; then
echo 'Updating...'
curl --insecure -fsSL -o dial_new.sh $remote_link
[ $watchdog_update -eq 1 ] && curl --insecure -fsSOL $watchdog_link
fi
sed -i "s/username=\"\"/username=\"$username\"/g" dial_new.sh
sed -i "s/password=\"\"/password=\"$password\"/g" dial_new.sh
sed -i "s/#isp=\"$isp\"/isp=\"$isp\"/g" dial_new.sh
sed -i "s/auto_update=\d/auto_update=$auto_update/g" dial_new.sh
sed -i "s/watchdog_update=\d/watchdog_update=$watchdog_update/g" dial_new.sh
chmod +x dial_new.sh
chmod +x watchdog.sh
mv dial.sh dial_old.sh
mv dial_new.sh dial.sh
rm dial_old.sh
echo 'Done!'
fi
}
which wget > /dev/null && have_wget=1 || have_wget=0
which curl > /dev/null && have_curl=1 || have_curl=0
if [[ $have_curl = 0 ]] && [[ $have_wget = 0 ]]; then
echo "Missing wget and/or curl, please install one of them with opkg."
exit 1
fi
if [ -z $username ] || [ -z $password ]; then
echo '$username or $password is empty, please modify script and fill them with your username and password.'
exit 2
fi
if [ -z ${1+x} ]; then
# If $1 is empty
help
elif [ "$1" = "version" ]; then
print_version
elif [ "$1" = "update" ]; then
update
elif [ "$1" = "login" ]; then
echo "Logging..."
login
echo "Done!"
sh -c "sleep 30 && ./dial.sh update" &
elif [ "$1" = "logout" ]; then
echo "Logging out..."
logout
echo "Done!"
else
help
fi
exit 0
#####################################################