From 4ab5c9c275482d8a0b510dfe504dd37660525e24 Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Mon, 10 Jan 2022 21:46:44 +0100 Subject: [PATCH] adding first test script for logging in into the FritzBox --- fb-login-test.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 fb-login-test.sh diff --git a/fb-login-test.sh b/fb-login-test.sh new file mode 100755 index 0000000..537f7dc --- /dev/null +++ b/fb-login-test.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +SID=0 +FB_IP=fritz.box + +# +# define FB_USER and FB_PASS in file fbconfig.config the user must have access to the SmartHome +source fbconfig.config + +# +# login into the FB, grabbing a valid Session Key into variable SID +# parameters: FritzboxIP Username Passwort +# +function login () { + local CID + local PW + local TMP + + CID=$(curl -s http://$1/login_sid.lua | grep -o "[a-z0-9]\{8\}" | cut -d">" -f 2) + PW=$(echo -n "$CID-$3" | iconv -f ISO8859-1 -t UTF-16LE | md5sum -b | cut -c -32) + SID=$(curl -s http://$1/login_sid.lua -d response=$CID-$PW -d username=$2 | grep -o "[a-z0-9]\{16\}" | cut -d ">" -f 2) + if [ "$SID" == "0000000000000000" ]; then + return 0 + else + return 1 + fi +} + +# +# listing all switches FB using the SID parameter +# parameter +function getdevices () { + LIST=$(curl -s "http://$1/webservices/homeautoswitch.lua?switchcmd=getdevicelistinfos&sid=$SID") + return 0 +} + + +login $FB_IP $FB_USER $FB_PASS +getdevices $FB_IP + +echo $LIST