When I run the following script, I get a value back, API still not running:
SERVER="192.168.178.1"
PASSWORD="secret"
challengeRsp=$(curl --header "Accept: application/xml" \
--header "Content-Type: text/plain" \
"http://$SERVER/login_sid.lua" 2>/dev/null)
challenge=$(echo $challengeRsp | sed "s/^.//" | sed "s/<\/Challenge>.$//")
if [[ -z $challenge ]]; then
echo "No challenge found"
exit 0
fi
challenge_bf="$challenge-$PASSWORD"
challenge_bf=$(echo -n $challenge_bf | iconv -t UTF-16LE | md5sum - | cut -c 1-32)
response_bf="$challenge-$challenge_bf"
url="http://$SERVER/login_sid.lua"
sidRsp=$(curl --header "Accept: text/html,application/xhtml+xml,application/xml" \
--header "Content-Type: application/x-www-form-urlencoded" \
-d "response=$response_bf" \
$url 2>/dev/null)
sid=$(echo $sidRsp | sed "s/^.//" | sed "s/<\/SID>.$//")
regex="^0+$"
if [[ $sid =~ $regex ]]; then
echo "Invalid password"
exit 0
fi
IFS=' '
stats=$(curl --header "Accept: application/xml" \
--header "Content-Type: text/plain" \
"http://$SERVER/webservices/homeautoswitch.lua?ain=087610156436&switchcmd=getswitchpower&sid=$sid" 2>/dev/null)
echo $stats
... View more