-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHiLink.au3
277 lines (256 loc) · 8.41 KB
/
HiLink.au3
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Huawei.ico
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_Res_Comment=HiLink
#AutoIt3Wrapper_Res_Description=Huawei E3372h-153 HiLink Client
#AutoIt3Wrapper_Res_Fileversion=1.0.0.60
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_AU3Check_Parameters=-d
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Au3Stripper=y
#AutoIt3Wrapper_Run_After=rename "%out%" "HiLink_win32.exe"
#AutoIt3Wrapper_Run_After=rename "%outx64%" "HiLink.exe"
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <AutoItConstants.au3>
#include <StringConstants.au3>
#include <String.au3>
#include "HTTP.au3"
Opt("TrayMenuMode", 1)
Global $sProgramName = StringReplace(@ScriptName, ".exe", "")
Global $sCurlPath = ""
Global $sHost = "192.168.8.1"
Global $iDebugLevel = 0
Local $sCommand = ""
Local $sApi = ""
Local $sXml = ""
Local $iMsgCount = 0
;Local $CmdLine[2] = [1, 'info']
If $CmdLine[0] < 1 Then
usage()
Exit (1)
Else
For $n = 1 To $CmdLine[0]
; ConsoleWrite($CmdLine[$n] & @CRLF)
Switch StringLeft($CmdLine[$n], 2)
Case "-c"
If $CmdLine[0] > $n Then
$sCommand = $CmdLine[$n + 1]
EndIf
Case "-h"
If $CmdLine[0] > $n Then
$sHost = $CmdLine[$n + 1]
EndIf
Case "-a"
If $CmdLine[0] > $n Then
$sApi = $CmdLine[$n + 1]
EndIf
Case "-x"
If $CmdLine[0] > $n Then
$sXml = $CmdLine[$n + 1]
EndIf
Case "-d"
If $CmdLine[0] > $n And StringIsInt($CmdLine[$n + 1]) Then
$iDebugLevel = $CmdLine[$n + 1]
Else
$iDebugLevel = 1
EndIf
Case Else
If $CmdLine[0] = 1 Then $sCommand = $CmdLine[$n]
EndSwitch
Next
EndIf
If @error Then
usage()
Exit (1)
EndIf
Switch $sCommand
Case 'info'
$sApi = "api/device/information"
Case 'status'
$sApi = "api/monitoring/status"
Case 'net'
$sApi = "api/net/current-plmn"
Case 'sms'
$sApi = "api/monitoring/check-notifications"
ConsoleWrite("# SMS Notifications" & @CRLF)
Case 'smscount'
$sApi = "api/sms/sms-count"
Case 'smslist'
$sApi = "api/sms/sms-list"
$sXml = "<request><PageIndex>1</PageIndex><ReadCount>10</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>1</Ascending><UnreadPreferred>1</UnreadPreferred></request>"
Case 'stats'
$sApi = "api/monitoring/traffic-statistics"
Case 'monthstats'
$sApi = "api/monitoring/month_statistics"
Case 'resetstats'
$sApi = "api/monitoring/clear-traffic"
$sXml = "<request><ClearTraffic>1</ClearTraffic></request>"
ConsoleWrite("# Reset TrafficStats / Clear History" & @CRLF)
Case 'reboot'
$sApi = "api/device/control"
$sXml = "<request><Control>1</Control></request>"
ConsoleWrite("# Reboot Device" & @CRLF)
Case 'con'
$sApi = "api/dialup/connection"
ConsoleWrite("# Dialup Info" & @CRLF)
Case 'hack'
$sApi = "api/dialup/connection"
$sXml = "<request><RoamAutoConnectEnable>0</RoamAutoConnectEnable><MaxIdelTime>86400</MaxIdelTime><ConnectMode>0</ConnectMode><MTU>1500</MTU><auto_dial_switch>1</auto_dial_switch><pdp_always_on>0</pdp_always_on></request>"
ConsoleWrite("# Reconnect Hack (https://blog.idorobots.org/entries/hacking-huawei-e3372-hilink..html)" & @CRLF)
Case 'emptyinbox'
$iMsgCount = SmsCount()
If $iMsgCount > 50 Then $iMsgCount = 50
ConsoleWrite("# Delete " & $iMsgCount & " SMS messages from inbox" & @CRLF)
SmsDelete($iMsgCount)
If @error Then
ConsoleWrite("Error" & @CRLF)
EndIf
Exit
EndSwitch
If StringLen($sApi) == 0 Then
ConsoleWrite("Incorrect Parameter(s)" & @CRLF & @CRLF)
usage()
Exit (1)
EndIf
If $iDebugLevel == 1 Then
ConsoleWrite("Host: " & $sHost & @CRLF)
ConsoleWrite("Uri: " & $sApi & @CRLF)
ConsoleWrite(@CRLF)
EndIf
runCurl($sApi, $sXml)
Exit
; Status:
; Status 112: "No autoconnect"
; Status 113: "No autoconnect (roaming)"
; Status 114: "No reconnect on timeout"
; Status 115: "No reconnect on timeout (roaming)"
; Status 900: "Connecting"
; Status 901: "Connected"
; Status 902: "Disconnected"
; Status 903: "Disconnecting"
; Other : "Unknown status"
Func SmsCount()
Local $iSmsCount = 0
Local $sSmsXml = runCurl("api/sms/sms-count")
Local $aSmsCount = _StringBetween($sSmsXml, "<LocalInbox>", "</LocalInbox>")
If Not @error Then
If $iDebugLevel > 1 Then
ConsoleWrite("SMS Inbox messages: " & $aSmsCount[0] & @CRLF)
EndIf
$iSmsCount = Int($aSmsCount[0])
EndIf
Return $iSmsCount
EndFunc ;==>SmsCount
Func SmsDelete($iMax)
If $iMax > 50 Then SetError(1)
If SmsCount() < $iMax Then SetError(1)
If @error Then Return
; BoxType 1 is inbox, 2 is sentbox
Local $sSmsList = runCurl("api/sms/sms-list", "<request><PageIndex>1</PageIndex><ReadCount>" & $iMax & "</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>1</Ascending><UnreadPreferred>1</UnreadPreferred></request>")
Local $aList = StringSplit($sSmsList, "</Message>", $STR_ENTIRESPLIT)
Local $sIndexes = ""
For $sMsg In $aList
Local $aIndex = _StringBetween($sMsg, "<Index>", "</Index>")
If Not @error Then
$sIndexes &= "<Index>" & $aIndex[0] & "</Index>"
EndIf
Next
If $iDebugLevel > 1 Then
ConsoleWrite("SMS Msg indexes to delete: " & $sIndexes & @CRLF)
EndIf
runCurl("api/sms/delete-sms", "<request>" & $sIndexes & "</request>")
EndFunc ;==>SmsDelete
Func getSessionHeaders()
Dim $aSession[0]
Local $url = "/api/webserver/SesTokInfo"
HttpConnect($sHost)
Dim $aHeaders[1] = [""]
HttpGet($sHost, $url, $aHeaders)
Local $sResponse = HttpRead()
HttpClose()
;ConsoleWrite("Session: " & $sResponse & @CRLF)
Local $aCookie = _StringBetween($sResponse, "<SesInfo>", "</SesInfo>")
If Not @error Then
Local $aToken = _StringBetween($sResponse, "<TokInfo>", "</TokInfo>")
If Not @error Then
ReDim $aSession[2]
$aSession[0] = "Cookie: " & $aCookie[0]
$aSession[1] = "__RequestVerificationToken: " & $aToken[0]
EndIf
EndIf
Return $aSession
EndFunc ;==>getSessionHeaders
Func runCurl($sApi, $sRequestXml = "")
Local $aHeaders = getSessionHeaders()
HttpConnect($sHost)
If StringLen($sRequestXml) = 0 Then
HttpGet($sHost, $sApi, $aHeaders)
Else
If $iDebugLevel == 1 Then
ConsoleWrite("# Request:" & @CRLF)
ConsoleWrite($sRequestXml & @CRLF & @CRLF)
EndIf
HttpPost($sHost, $sApi, $aHeaders, $sRequestXml)
EndIf
Local $sResponse = HttpRead()
HttpClose()
Local $sTitle = _StringTitleCase(StringReplace(StringMid($sApi, StringInStr($sApi, "/") + 1), "/", " "))
If $iDebugLevel == 1 Then
ConsoleWrite("# Response:" & @CRLF)
ConsoleWrite($sResponse & @CRLF & @CRLF)
EndIf
If $iDebugLevel == 0 Then
If UBound($aHeaders) > 1 Then
ConsoleWrite("# " & $sTitle & ":" & @CRLF)
EndIf
ParseXml($sResponse)
EndIf
Return $sResponse
EndFunc ;==>runCurl
Func ParseXml($sXml)
Local $aTags = StringSplit($sXml, "<")
Local $sItem = ""
For $sTag In $aTags
$sTag = StringStripWS($sTag, $STR_STRIPLEADING)
$sTag = StringStripWS($sTag, $STR_STRIPTRAILING)
; ConsoleWrite("[" & $sTag & "]" & @CRLF)
If StringLeft($sTag, 1) == "/" Then
If StringInStr($sItem, StringMid($sTag, 2)) > 0 Then
$sItem = StringReplace($sItem, ">", ": ")
If StringRight($sItem, 2) == ": " Then $sItem &= "-"
ConsoleWrite($sItem & @CRLF)
EndIf
$sItem = ""
Else
$sItem = $sTag
EndIf
Next
ConsoleWrite(@CRLF)
EndFunc ;==>ParseXml
Func usage()
Local $build = " x32"
If @AutoItX64 Then
$build = " x64"
EndIf
Local $sVersion = StringLeft(FileGetVersion(@ScriptDir & "\" & @ScriptName, "FileVersion"), 5)
ConsoleWrite($sProgramName & $build & " " & $sVersion & @CRLF)
ConsoleWrite("Usage: " & @CRLF)
ConsoleWrite("command (without other parameters)" & @CRLF)
ConsoleWrite("-c command (-c info)" & @CRLF)
ConsoleWrite(" commands: info, status, net, sms, smscount, smslist, stats, monthstats, resetstats, reboot, con, hack, emptyinbox" & @CRLF)
ConsoleWrite("-h host, IP Address (default " & $sHost & ")" & @CRLF)
ConsoleWrite("-d debuglevel (none=1, 0-2)" & @CRLF)
ConsoleWrite("-a api path (-a api/**/**)" & @CRLF)
ConsoleWrite("-x request XML (-x ""<request>***</request>"")" & @CRLF)
ConsoleWrite(@CRLF)
ConsoleWrite("Examples:" & @CRLF)
ConsoleWrite($sProgramName & " info" & @CRLF)
ConsoleWrite($sProgramName & " -c info" & @CRLF)
ConsoleWrite($sProgramName & " -d -c status" & @CRLF)
ConsoleWrite($sProgramName & " -d 2 -a api/device/information" & @CRLF)
ConsoleWrite($sProgramName & ' -a api/monitoring/clear-traffic -x "<request><ClearTraffic>1</ClearTraffic></request>"' & @CRLF)
ConsoleWrite(@CRLF)
EndFunc ;==>usage