forked from honsa/FritzBoxShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfritzBoxShell.sh
More file actions
executable file
·388 lines (287 loc) · 14.1 KB
/
fritzBoxShell.sh
File metadata and controls
executable file
·388 lines (287 loc) · 14.1 KB
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#!/bin/bash
#************************************************************#
#** Autor: Johannes Hubig <johannes.hubig@gmail.com> **#
#** Autor: Jürgen Key https://elbosso.github.io/index.html **#
#************************************************************#
# The following script should work from FritzOS 6.0 on-
# wards.
# Was tested successfully on:
# * Fritz!Box 7490 FritzOS 6.93
# * Fritz!Repeater 310 FritzOS 6.92
# Was tested (partly) successfully on:
# * FRITZ!Box 6490 Cable (kdg) with firmware version `06.87`
# * FRITZ!WLAN Repeater DVB-C with firmware version `06.92`
#
# Protokoll TR-064 was used to control the Fritz!Box and
# Fritz!Repeater. For sure not all commands are
# available on Fritz!Repeater.
# Additional info and documentation can be found here:
# http://fritz.box:49000/tr64desc.xml
# https://wiki.fhem.de/wiki/FRITZBOX#TR-064
# https://avm.de/service/schnittstellen/
DIRECTORY=$(cd `dirname $0` && pwd)
source $DIRECTORY/fritzBoxShellConfig.sh
#******************************************************#
#*********************** SCRIPT ***********************#
#******************************************************#
# Storing shell parameters in variables
# Example:
# ./fritzBoxShell.sh WLAN_2G 1
# $1 = "WLAN_2G"
# $2 = "1"
option1=$1
option2=$2
UPNPMetaData(){
location="/tr64desc.xml"
curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location >$option2
}
IGDMetaData(){
location="/igddesc.xml"
curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location >$option2
}
readout() {
curlOutput1=$(curl -s -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'></u:$action></s:Body></s:Envelope>" | grep "<New" | awk -F"</" '{print $1}' |sed -En "s/<(.*)>(.*)/\1 \2/p")
echo "$curlOutput1"
}
WLANstatistics() {
location="/upnp/control/wlanconfig1"
uri="urn:dslforum-org:service:WLANConfiguration:1"
action='GetStatistics'
readout
action='GetTotalAssociations'
readout
action='GetInfo'
readout
echo "NewGHz 2.4"
}
WLAN5statistics() {
location="/upnp/control/wlanconfig2"
uri="urn:dslforum-org:service:WLANConfiguration:2"
action='GetStatistics'
readout
action='GetTotalAssociations'
readout
action='GetInfo'
readout
echo "NewGHz 5"
}
LANstate() {
location="/upnp/control/lanethernetifcfg"
uri="urn:dslforum-org:service:LANEthernetInterfaceConfig:1"
action='GetStatistics'
readout
}
DSLstate() {
location="/igdupnp/control/wandslifconfig1"
uri="urn:dslforum-org:service:WANDSLInterfaceConfig:1"
action='GetInfo'
readout
}
WANstate() {
location="/upnp/control/wancommonifconfig1"
uri="urn:dslforum-org:service:WANCommonInterfaceConfig:1"
action='GetTotalBytesReceived'
readout
action='GetTotalBytesSent'
readout
action='GetTotalPacketsReceived'
readout
action='GetTotalPacketsSent'
readout
action='GetCommonLinkProperties'
readout
#action='GetInfo'
#readout
}
WANDSLLINKstate() {
location="/upnp/control/wandsllinkconfig1"
uri="urn:dslforum-org:service:WANDSLLinkConfig:1"
action='GetStatistics'
readout
}
IGDWANstate() {
location="/igdupnp/control/WANCommonIFC1"
uri="urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"
action='GetAddonInfos'
readout
}
IGDDSLLINKstate() {
location="/igdupnp/control/WANDSLLinkC1"
uri="urn:schemas-upnp-org:service:WANDSLLinkConfig:1"
action='GetDSLLinkInfo'
readout
action='GetAutoConfig'
readout
action='GetModulationType'
readout
action='GetDestinationAddress'
readout
action='GetATMEncapsulation'
readout
action='GetFCSPreserved'
readout
}
IGDIPstate() {
location="/igdupnp/control/WANIPConn1"
uri="urn:schemas-upnp-org:service:WANIPConnection:1"
action='GetConnectionTypeInfo'
readout
action='GetAutoDisconnectTime'
readout
action='GetIdleDisconnectTime'
readout
action='GetStatusInfo'
readout
action='GetNATRSIPStatus'
readout
action='GetExternalIPAddress'
readout
action='X_AVM_DE_GetExternalIPv6Address'
readout
action='X_AVM_DE_GetIPv6Prefix'
readout
action='X_AVM_DE_GetDNSServer'
readout
action='X_AVM_DE_GetIPv6DNSServer'
readout
}
Deviceinfo() {
location="/upnp/control/deviceinfo"
uri="urn:dslforum-org:service:DeviceInfo:1"
action='GetInfo'
readout
# location="/upnp/control/userif"
# uri="urn:dslforum-org:service:UserInterface:1"
# action='X_AVM-DE_GetInfo'
# readout
}
WLANstate() {
# Building the inputs for the SOAP Action based on which WiFi to switch ON/OFF
if [ $option1 = "WLAN_2G" ] || [ "$option1" = "WLAN" ]; then
location="/upnp/control/wlanconfig1"
uri="urn:dslforum-org:service:WLANConfiguration:1"
action='SetEnable'
if [ $option2 = "0" ] || [ "$option2" = "1" ]; then echo "Sending WLAN_2G $1"; curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'><NewEnable>$option2</NewEnable></u:$action></s:Body></s:Envelope>" -s > /dev/null; fi # Changing the state of the WIFI
action='GetInfo'
if [ $option2 = "STATE" ]; then
curlOutput1=$(curl -s -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'></u:$action></s:Body></s:Envelope>" | grep NewEnable | awk -F">" '{print $2}' | awk -F"<" '{print $1}')
curlOutput2=$(curl -s -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'></u:$action></s:Body></s:Envelope>" | grep NewSSID | awk -F">" '{print $2}' | awk -F"<" '{print $1}')
echo "2,4 Ghz Network $curlOutput2 is $curlOutput1"
fi
fi
if [ $option1 = "WLAN_5G" ] || [ "$option1" = "WLAN" ]; then
location="/upnp/control/wlanconfig2"
uri="urn:dslforum-org:service:WLANConfiguration:2"
action='SetEnable'
if [ $option2 = "0" ] || [ "$option2" = "1" ]; then echo "Sending WLAN_5G $1"; curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'><NewEnable>$option2</NewEnable></u:$action></s:Body></s:Envelope>" -s > /dev/null; fi # Changing the state of the WIFI
action='GetInfo'
if [ $option2 = "STATE" ]; then
curlOutput1=$(curl -s -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'></u:$action></s:Body></s:Envelope>" | grep NewEnable | awk -F">" '{print $2}' | awk -F"<" '{print $1}')
curlOutput2=$(curl -s -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'></u:$action></s:Body></s:Envelope>" | grep NewSSID | awk -F">" '{print $2}' | awk -F"<" '{print $1}')
echo " 5 Ghz Network $curlOutput2 is $curlOutput1"
fi
fi
}
RepeaterWLANstate() {
# Building the inputs for the SOAP Action
location="/upnp/control/wlanconfig1"
uri="urn:dslforum-org:service:WLANConfiguration:1"
action='SetEnable'
echo "Sending Repeater WLAN $1"; curl -k -m 5 --anyauth -u "$RepeaterUSER:$RepeaterPW" http://$RepeaterIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'><NewEnable>$option2</NewEnable></u:$action></s:Body></s:Envelope>" -s > /dev/null
}
Reboot() {
# Building the inputs for the SOAP Action
location="/upnp/control/deviceconfig"
uri="urn:dslforum-org:service:DeviceConfig:1"
action='Reboot'
if [[ "$option2" = "Box" ]]; then echo "Sending Reboot command to $1"; curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'></u:$action></s:Body></s:Envelope>" -s > /dev/null; fi
if [[ "$option2" = "Repeater" ]]; then echo "Sending Reboot command to $1"; curl -k -m 5 --anyauth -u "$RepeaterUSER:$RepeaterPW" http://$RepeaterIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'></u:$action></s:Body></s:Envelope>" -s > /dev/null; fi
}
DisplayArguments() {
echo ""
echo "Invalid Action and/or parameter. Possible combinations:"
echo ""
echo "|----------|-----------------|----------------------------------------------------------------------|"
echo "| Action | Parameter | Description |"
echo "|----------|-----------------|----------------------------------------------------------------------|"
echo "| WLAN_2G | 0 or 1 or STATE | Switching ON, OFF or checking the state of the 2,4 Ghz WiFi |"
echo "| WLAN_2G | STATISTICS | Statistics for the 2,4 Ghz WiFi easily digestible by telegraf |"
echo "| WLAN_5G | 0 or 1 or STATE | Switching ON, OFF or checking the state of the 5 Ghz WiFi |"
echo "| WLAN_5G | STATISTICS | Statistics for the 5 Ghz WiFi easily digestible by telegraf |"
echo "| WLAN | 0 or 1 or STATE | Switching ON, OFF or checking the state of the 2,4Ghz and 5 Ghz WiFi |"
echo "| LAN | STATE | Statistics for the LAN easily digestible by telegraf |"
echo "| DSL | STATE | Statistics for the DSL easily digestible by telegraf |"
echo "| WAN | STATE | Statistics for the WAN easily digestible by telegraf |"
echo "| LINK | STATE | Statistics for the WAN DSL LINK easily digestible by telegraf |"
echo "| IGDWAN | STATE | Statistics for the WAN LINK easily digestible by telegraf |"
echo "| IGDDSL | STATE | Statistics for the DSL LINK easily digestible by telegraf |"
echo "| IGDIP | STATE | Statistics for the DSL IP easily digestible by telegraf |"
echo "| REPEATER | 0 | Switching OFF the WiFi of the Repeater |"
echo "| REBOOT | Box or Repeater | Rebooting your Fritz!Box or Fritz!Repeater |"
echo "|----------|-----------------|----------------------------------------------------------------------|"
echo ""
}
# Check if an argument was supplied for shell script
if [ $# -eq 0 ]
then
DisplayArguments
elif [ -z "$2" ]
then
DisplayArguments
else
#If argument was provided, check which function to be called
if [ "$option1" = "WLAN_2G" ] || [ "$option1" = "WLAN_5G" ] || [ "$option1" = "WLAN" ]; then
if [ "$option2" = "1" ]; then WLANstate "ON";
elif [ "$option2" = "0" ]; then WLANstate "OFF";
elif [ "$option2" = "STATE" ]; then WLANstate "STATE";
elif [ "$option2" = "STATISTICS" ]; then
if [ "$option1" = "WLAN_2G" ]; then WLANstatistics;
elif [ "$option1" = "WLAN_5G" ]; then WLAN5statistics;
else DisplayArguments
fi
else DisplayArguments
fi
elif [ "$option1" = "LAN" ]; then
if [ "$option2" = "STATE" ]; then LANstate "$option2";
else DisplayArguments
fi
elif [ "$option1" = "DSL" ]; then
if [ "$option2" = "STATE" ]; then DSLstate "$option2";
else DisplayArguments
fi
elif [ "$option1" = "WAN" ]; then
if [ "$option2" = "STATE" ]; then WANstate "$option2";
else DisplayArguments
fi
elif [ "$option1" = "LINK" ]; then
if [ "$option2" = "STATE" ]; then WANDSLLINKstate "$option2";
else DisplayArguments
fi
elif [ "$option1" = "IGDWAN" ]; then
if [ "$option2" = "STATE" ]; then IGDWANstate "$option2";
else DisplayArguments
fi
elif [ "$option1" = "IGDDSL" ]; then
if [ "$option2" = "STATE" ]; then IGDDSLLINKstate "$option2";
else DisplayArguments
fi
elif [ "$option1" = "IGDIP" ]; then
if [ "$option2" = "STATE" ]; then IGDIPstate "$option2";
else DisplayArguments
fi
elif [ "$option1" = "UPNPMetaData" ]; then
UPNPMetaData "$option2";
elif [ "$option1" = "IGDMetaData" ]; then
IGDMetaData "$option2";
elif [ "$option1" = "Deviceinfo" ]; then
Deviceinfo "$option2";
elif [ "$option1" = "REPEATER" ]; then
if [ "$option2" = "1" ]; then RepeaterWLANstate "ON"; # Usually this will not work because there is no connection possible to the Fritz!Repeater as long as WiFi is OFF
elif [ "$option2" = "0" ]; then RepeaterWLANstate "OFF";
else DisplayArguments
fi
elif [ "$option1" = "REBOOT" ]; then
Reboot $option2
else DisplayArguments
fi
fi