Last active
August 29, 2015 13:56
-
-
Save pyropeter/9141252 to your computer and use it in GitHub Desktop.
Script to dial any number using the AVM FritzBox 7360 "Wählhilfe"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
set -u | |
hostname="$1" | |
username="$2" | |
password="$3" | |
number="$4" | |
url="http://$hostname" | |
challenge="`curl -sS "$url"/login.lua | grep 'security:status/challenge'`" | |
challenge="`echo "$challenge" | cut -d'"' -f4`" | |
echo challenge: $challenge | |
# password magic. assumes there are no non-ascii characters in the password | |
# (avm's javascript implementation replaces all codepoints > 255 with '.') | |
# step 1: concat challenge and password | |
magic="${challenge}-${password}" | |
# step 2: convert everything to UTF-16 little endian and md5sum | |
# (md5sum needs to be done at once, since bash variables don't seem to be | |
# able to hold null bytes) | |
magic="`echo -n "$magic" | sed 's/./\0\x00/g' | md5sum | cut -d\ -f1`" | |
# step 3: prepend challenge | |
magic="${challenge}-${magic}" | |
# now we should be able to login... | |
# (curl's -d option is completely stupid, but can be used for this, since | |
# the form data probably doesn't need urlencoding. when copying code, | |
# think s/-d/--data-urlencode/g) | |
loginpage="`curl -vsS "$url"/login.lua -d page= -d site_mode=classic -d username=$username -d response=$magic 2>&1`" | |
redirect="`echo "$loginpage" | grep '< Location: ' | cut -d\ -f3`" | |
sid="`echo "$redirect" | cut -d= -f2 | tr -d '\r'`" | |
echo sid: $sid | |
# do the dialing... | |
# (in case it isn't obvious: don't copy your urlencoding routines from here) | |
urlnumber="`echo "$number" | sed 's/ /%20/g; s/\+/%2b/g'`" | |
curl -sS "${url}/fon_num/fonbook_list.lua?sid=${sid}&dial=${urlnumber}&xhr=1" | |
echo | |
echo Dialing... Answer your phone. | |
echo To hangup, press ^D | |
cat | |
curl -sS "${url}/fon_num/fonbook_list.lua?sid=${sid}&hangup=&xhr=1" | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Question: I need a script to make two calls to two different internal numbers parallel (doorbell) by using the "Wählhilfe". Is this possible?