Skip to content

Commit

Permalink
Merge pull request #5 from jhubig/addAnswerMachine
Browse files Browse the repository at this point in the history
TAM added and minor updates
  • Loading branch information
jhubig committed Jan 4, 2020
2 parents 4716624 + 7c4cc90 commit e3facb7
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 56 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<!---
[![start with why](https://img.shields.io/badge/start%20with-why%3F-brightgreen.svg?style=flat)](http://www.ted.com/talks/simon_sinek_how_great_leaders_inspire_action)
--->
[![GitHub release](https://img.shields.io/github/release/elbosso/FritzBoxShell/all.svg?maxAge=1)](https://GitHub.com/elbosso/FritzBoxShell/releases/)
[![GitHub tag](https://img.shields.io/github/tag/elbosso/FritzBoxShell.svg)](https://GitHub.com/elbosso/FritzBoxShell/tags/)
[![GitHub release](https://img.shields.io/github/release/jhubig/FritzBoxShell/all.svg?maxAge=1)](https://GitHub.com/jhubig/FritzBoxShell/releases/)
[![GitHub tag](https://img.shields.io/github/tag/jhubig/FritzBoxShell.svg)](https://GitHub.com/jhubig/FritzBoxShell/tags/)
[![made-with-bash](https://img.shields.io/badge/Made%20with-Bash-1f425f.svg)](https://www.gnu.org/software/bash/)
[![GitHub license](https://img.shields.io/github/license/elbosso/FritzBoxShell.svg)](https://github.com/elbosso/FritzBoxShell/blob/master/LICENSE)
[![GitHub issues](https://img.shields.io/github/issues/elbosso/FritzBoxShell.svg)](https://GitHub.com/elbosso/FritzBoxShell/issues/)
[![GitHub issues-closed](https://img.shields.io/github/issues-closed/elbosso/FritzBoxShell.svg)](https://GitHub.com/elbosso/FritzBoxShell/issues?q=is%3Aissue+is%3Aclosed)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/elbosso/FritzBoxShell/issues)
[![GitHub contributors](https://img.shields.io/github/contributors/elbosso/FritzBoxShell.svg)](https://GitHub.com/elbosso/FritzBoxShell/graphs/contributors/)
[![Github All Releases](https://img.shields.io/github/downloads/elbosso/FritzBoxShell/total.svg)](https://github.com/elbosso/FritzBoxShell)
[![Website elbosso.github.io](https://img.shields.io/website-up-down-green-red/https/elbosso.github.io.svg)](https://elbosso.github.io/)
[![GitHub license](https://img.shields.io/github/license/jhubig/FritzBoxShell.svg)](https://github.com/jhubig/FritzBoxShell/blob/master/LICENSE)
[![GitHub issues](https://img.shields.io/github/issues/jhubig/FritzBoxShell.svg)](https://GitHub.com/jhubig/FritzBoxShell/issues/)
[![GitHub issues-closed](https://img.shields.io/github/issues-closed/jhubig/FritzBoxShell.svg)](https://GitHub.com/jhubig/FritzBoxShell/issues?q=is%3Aissue+is%3Aclosed)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/jhubig/FritzBoxShell/issues)
[![GitHub contributors](https://img.shields.io/github/contributors/jhubig/FritzBoxShell.svg)](https://GitHub.com/jhubig/FritzBoxShell/graphs/contributors/)
[![Github All Releases](https://img.shields.io/github/downloads/jhubig/FritzBoxShell/total.svg)](https://github.com/jhubig/FritzBoxShell)
[![Github All Releases](https://img.shields.io/github/watchers/jhubig/FritzBoxShell?style=social)](https://github.com/jhubig/FritzBoxShell)

# FritzBoxShell

Expand All @@ -25,13 +25,13 @@ The shell script uses cURL to create an SOAP request based on the TR-064 protoco

Please raise an issue with your function you would like to add.

This package (before the fork) was tested on
* OK: Fritz!Box 7490, with firmware version `6.93`
* NOK: Fritz!Box 7490, with firmware version `06.98-53696 BETA`
* Status check not working anymore. NewStatus field not updated. Stays "Disabled".
* OK: Fritz!Repeater 310, with firmware version `6.92`
This package was tested on
* OK: Fritz!Box 7490, with firmware version `7.12`
* OK: Fritz!Repeater 310, with firmware version `7.12`
* everything concerning Wifi works as expected
* nothing else works (also as expected because - it is no Fritz!Box)

After the fork, it has solely been tested on
After the fork (pull request #2), it has solely been tested on
* FRITZ!Box 6490 Cable (kdg) with firmware version `06.87`
* DSL not working
* WAN partly working (rates are always 0)
Expand All @@ -43,15 +43,11 @@ After the fork, it has solely been tested on

### Become a part of it!

If you want to check out if your AVM device actually works with this script, you can do so by
executing `fritzBoxShellTest.sh`. It orints for (almost) every Service/Action pair if they
delivered data when called.
If you want to check out if your AVM device actually works with this script, you can do so by executing `fritzBoxShellTest.sh`. It prints for (almost) every Service/Action pair if they delivered data when called.

Authentication is handled exactly as described for `fritzBoxShell.sh`.

The result is a list written to the console containing the names of the checked service and actions
followed by the resuklt of the check. Finally, the device type and firmware version are printed (of
course only if this functionality was accessible!).
The result is a list written to the console containing the names of the checked service and actions followed by the result of the check. Finally, the device type and firmware version are printed (of course only if this functionality was accessible!).

As an example - the result for my Fritz!Box:

Expand Down Expand Up @@ -92,12 +88,13 @@ Copy the fritzBoxShell.sh to your desired location (In my personal use case, I p

```
chmod 755 fritzBoxShell.sh
chmod 755 fritzBoxShellTest.sh
```
## Configuration

The file fritzBoxShellConfig.sh contains all Information pertaining to endpoints and credentials. You can
choose to adjust it or you can choose to give this information as environment variables at the start of the script.
If you choose to use environment variables, you need not comment or delete anything in fritzBoxShellConfig.sh -
If you choose to use environment variables, you need not comment or delete anything in fritzBoxShellConfig.sh -
environment variables alway take precedence over the contents of fritzBoxShellConfig.sh.

Calling fritzBoxShell.sh using environment variables could look like this:
Expand Down Expand Up @@ -127,6 +124,9 @@ Example (Deactivates the 5Ghz on your FritzBox):
| WLAN_5G | 0 or 1 or STATE | Switching ON, OFF or checking the state of the 5 Ghz WiFi |
| WLAN_5G | STATISTICS | Statistics for the 5 Ghz WiFi easily digestible by telegraf |
| WLAN | 0 or 1 or STATE | Switching ON, OFF or checking the state of the 2,4Ghz and 5 Ghz WiFi |
| TAM | <index> and GetInfo | e.g. TAM 0 GetInfo (gives info about answering machine) |
| TAM | <index> and ON or OFF | e.g. TAM 0 ON (switches ON the answering machine) |
| TAM | <index> and GetMsgs | e.g. TAM 0 GetMsgs (gives XML formatted list of messages) |
| LAN | STATE | Statistics for the LAN easily digestible by telegraf |
| DSL | STATE | Statistics for the DSL easily digestible by telegraf |
| WAN | STATE | Statistics for the WAN easily digestible by telegraf |
Expand All @@ -136,6 +136,8 @@ Example (Deactivates the 5Ghz on your FritzBox):
| IGDIP | STATE | Statistics for the DSL IP easily digestible by telegraf |
| REPEATER | 0 | Switching OFF the WiFi of the Repeater |
| REBOOT | Box or Repeater | Rebooting your Fritz!Box or Fritz!Repeater |
| UPNPMetaData | STATE or <filename> | Full unformatted output of tr64desc.xml to console or file |
| IGDMetaData | STATE or <filename> | Full unformatted output of igddesc.xml to console or file |

### Notes:

Expand All @@ -150,7 +152,7 @@ Currently I'm using the script (located on my RaspberryPi which is always connec

### Example Use with Telegraf
Suppose, you want to visualize the overall Download Rate of your FritzBox: The way to go here is to use the Action IGDWAN with parameter STATE. It gives (for example) this output:

```
NewByteSendRate 265
NewByteReceiveRate 17
Expand Down Expand Up @@ -196,4 +198,3 @@ Now for the ugly truth: we can not use the command shown earlier for where it sa

#### Note
Data with huge absolute values probably dont fit into type `integer` - in this case, `long` is the way to go...

98 changes: 71 additions & 27 deletions fritzBoxShell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@

# 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
Expand Down Expand Up @@ -41,17 +35,22 @@ source "$DIRECTORY/fritzBoxShellConfig.sh"

option1="$1"
option2="$2"
option3="$3"

UPNPMetaData(){
location="/tr64desc.xml"

curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" "http://$BoxIP:49000$location" >"$option2"
if [ "$option2" = "STATE" ]; then curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" "http://$BoxIP:49000$location"
else curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" "http://$BoxIP:49000$location" >"$DIRECTORY/$option2"
fi
}

IGDMetaData(){
location="/igddesc.xml"

curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" "http://$BoxIP:49000$location" >"$option2"
if [ "$option2" = "STATE" ]; then curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" "http://$BoxIP:49000$location"
else curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" "http://$BoxIP:49000$location" >"$DIRECTORY/$option2"
fi
}

readout() {
Expand Down Expand Up @@ -80,7 +79,7 @@ WLAN5statistics() {
location="/upnp/control/wlanconfig2"
uri="urn:dslforum-org:service:WLANConfiguration:2"
action='GetStatistics'

readout

action='GetTotalAssociations'
Expand Down Expand Up @@ -245,6 +244,38 @@ Deviceinfo() {

}

TAM() {
location="/upnp/control/x_tam"
uri="urn:dslforum-org:service:X_AVM-DE_TAM:1"

if [ "$option3" = "GetInfo" ]; then
action='GetInfo'
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'><NewIndex>$option2</NewIndex></u:$action></s:Body></s:Envelope>" | grep "<New" | awk -F"</" '{print $1}' |sed -En "s/<(.*)>(.*)/\1 \2/p"

# Switch ON the TAM
elif [ "$option3" = "ON" ]; then
action='SetEnable'
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'><NewIndex>$option2</NewIndex><NewEnable>1</NewEnable></u:$action></s:Body></s:Envelope>" | grep "<New" | awk -F"</" '{print $1}' |sed -En "s/<(.*)>(.*)/\1 \2/p"
echo "Answering machine is switched ON"

# Switch OFF the TAM
elif [ "$option3" = "OFF" ]; then
action='SetEnable'
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'><NewIndex>$option2</NewIndex><NewEnable>0</NewEnable></u:$action></s:Body></s:Envelope>" | grep "<New" | awk -F"</" '{print $1}' |sed -En "s/<(.*)>(.*)/\1 \2/p"
echo "Answering machine is switched OFF"

# Get CallList from TAM
elif [ "$option3" = "GetMsgs" ]; then
action='GetMessageList'
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'><NewIndex>$option2</NewIndex></u:$action></s:Body></s:Envelope>" | grep "<New" | awk -F"</" '{print $1}' |sed -En "s/<(.*)>(.*)/\1 \2/p")

#WGETresult=$(wget -O - "$curlOutput1" 2>/dev/null) Doesn't work with double quotes. Therefore in line below the shellcheck fails.
WGETresult=$(wget -O - $curlOutput1 2>/dev/null)
echo "$WGETresult"

fi
}

WLANstate() {

# Building the inputs for the SOAP Action based on which WiFi to switch ON/OFF
Expand Down Expand Up @@ -304,24 +335,33 @@ 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 "|--------------|------------------------|-------------------------------------------------------------------------|"
echo "| Action | Parameter | Description |"
echo "|--------------|------------------------|-------------------------------------------------------------------------|"
echo "|--------------|------------------------|-------------------------------------------------------------------------|"
echo "| DeviceInfo | STATE | Show information about your Fritz!Box like ModelName, SN, etc. |"
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 "|--------------|------------------------|-------------------------------------------------------------------------|"
echo "| TAM | <index> and GetInfo | e.g. TAM 0 GetInfo (gives info about answering machine) |"
echo "| TAM | <index> and ON or OFF | e.g. TAM 0 ON (switches ON the answering machine) |"
echo "| TAM | <index> and GetMsgs | e.g. TAM 0 GetMsgs (gives XML formatted list of messages) |"
echo "|--------------|------------------------|-------------------------------------------------------------------------|"
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 "| UPNPMetaData | STATE or <filename> | Full unformatted output of tr64desc.xml to console or file |"
echo "| IGDMetaData | STATE or <filename> | Full unformatted output of igddesc.xml to console or file |"
echo "|--------------|------------------------|-------------------------------------------------------------------------|"
echo ""
}

Expand Down Expand Up @@ -379,6 +419,10 @@ else
IGDMetaData "$option2";
elif [ "$option1" = "Deviceinfo" ]; then
Deviceinfo "$option2";
elif [ "$option1" = "TAM" ]; then
if [[ $option2 =~ ^[+-]?[0-9]+$ ]] && { [ "$option3" = "GetInfo" ] || [ "$option3" = "ON" ] || [ "$option3" = "OFF" ] || [ "$option3" = "GetMsgs" ];}; then TAM
else DisplayArguments
fi
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";
Expand Down
9 changes: 4 additions & 5 deletions fritzBoxShellTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# shellcheck disable=SC1090
#************************************************************#
#** Autor: Jürgen Key https://elbosso.github.io/index.html **#
#** Autor: Johannes Hubig <johannes.hubig@gmail.com> **#
#************************************************************#

# The following script is supposed to test what actions are
Expand All @@ -13,9 +14,9 @@ DIRECTORY=$(cd "$dir" && pwd)
source "$DIRECTORY/fritzBoxShellConfig.sh"

## declare an array variable
declare -a services=("WLAN_2G" "WLAN_2G" "WLAN_5G" "WLAN_2G" "WLAN" "LAN" "DSL" "WAN" "LINK" "IGDWAN" "IGDDSL" "IGDIP" )
declare -a actions=("STATISTICS" "STATE" "STATISTICS" "STATE" "STATE" "STATE" "STATE" "STATE" "STATE" "STATE" "STATE" "STATE" )
declare -a minwords=(3 5 3 5 9 1 1 1 1 1 1 1 )
declare -a services=("WLAN_2G" "WLAN_2G" "WLAN_5G" "WLAN_2G" "WLAN" "LAN" "DSL" "WAN" "LINK" "IGDWAN" "IGDDSL" "IGDIP" "TAM")
declare -a actions=("STATISTICS" "STATE" "STATISTICS" "STATE" "STATE" "STATE" "STATE" "STATE" "STATE" "STATE" "STATE" "STATE" "0 GetInfo")
declare -a minwords=(3 5 3 5 9 1 1 1 1 1 1 1 5 )

## now loop through the above array
counter=0
Expand All @@ -29,5 +30,3 @@ do
done
/bin/bash "$DIRECTORY/fritzBoxShell.sh" Deviceinfo 3 | grep NewModelName
/bin/bash "$DIRECTORY/fritzBoxShell.sh" Deviceinfo 3 | grep NewSoftwareVersion


0 comments on commit e3facb7

Please sign in to comment.