forked from taherfattahi/Hi-Link-wifi-enable-disable-bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
disableNetwork.sh
74 lines (58 loc) · 2.13 KB
/
disableNetwork.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
#!/bin/bash
username='root'
password=''
getSysAuth=$(curl -D headers.txt -X POST -F 'luci_username='${username}'' -F 'luci_password='${password}'' http://192.168.1.1/cgi-bin/luci)
substrSysAuth="sysauth="
sysauth=""
while read line; do
if [[ $line == *"$substrSysAuth"* ]];
then
# echo $line
sysAuthIndex=${line/sysauth*/}
indexStart=${#sysAuthIndex}
indexStart=$((indexStart + 9))
indexEnd=${#sysAuthIndex}
indexEnd=$((indexEnd + 40))
sysauth=$(echo $line| cut -c ${indexStart}-${indexEnd})
else
true
fi
done < headers.txt
getSessionIdToken=$(curl --cookie "sysauth=${sysauth}" http://192.168.1.1/cgi-bin/luci >> headers.txt)
substrSessionIdToken="L = new LuCI("
sessionId=""
tokenId=""
while read line; do
if [[ $line == *"$substrSessionIdToken"* ]];
then
sessionIndex=${line/sessionid*/}
tokenIndex=${line/token*/}
indexStart=${#sessionIndex}
indexStart=$((indexStart + 13))
indexEnd=${#sessionIndex}
indexEnd=$((indexEnd + 44))
sessionId=$(echo $line| cut -c ${indexStart}-${indexEnd})
indexStart=${#tokenIndex}
indexStart=$((indexStart + 9))
indexEnd=${#tokenIndex}
indexEnd=$((indexEnd + 40))
tokenId=$(echo $line| cut -c ${indexStart}-${indexEnd})
else
true
fi
done < headers.txt
echo $sysauth
echo $sessionId
echo $tokenId
generate_post_data()
{
cat <<EOF
[{"jsonrpc": "2.0","id": 1,"method": "call","params": ["${sessionId}","uci","set",{"config": "wireless","section": "default_radio0","values": {"disabled": "1"}}]},{"jsonrpc": "2.0","id": 2,"method": "call","params": ["${sessionId}","uci","set",{"config": "wireless","section": "radio0","values": {"disabled": "1"}}]}]
EOF
}
disableNetwork=$(curl -X POST http://192.168.1.1/ubus/ -H 'Content-Type: application/json' -d "$(generate_post_data)")
disableApplyNetwork=$(curl -v --cookie "sysauth=${sysauth}" -X POST -F 'sid='${sessionId}'' -F 'token='${tokenId}'' http://192.168.1.1/cgi-bin/luci/admin/uci/apply_unchecked)
file="headers.txt"
if [ -f "$file" ] ; then
rm "$file"
fi