-
Notifications
You must be signed in to change notification settings - Fork 26
Description
First of all thank you very much for maintaining this very helpful piece of software. I'm using it regularly.
I was really exited that the latest version allows to move devices to certain internet profiles. When I tried to use it I found its documentation rather lacking. With dev devname profile as parameters I wasnt sure what values exactly to use. Perhaps a hint that landevice01235-type dev IDs and filtprof01235-type profile IDs must be specified would be helpful for users not as throughoutly informed.
After finding out what I was looking for I struggled to find the needed IDs until I remembered about the web browser developer console. Using that it was possible to extract the needed IDs one by one but found that way rather tedious. Hence I kept looking for the specific URLs to the pages containing the relevant information and automated the extraction of said information:
#!/bin/bash
# the login procedure is adapted from https://github.com/Tscherno/Fritzbox.sh
FritzBoxURL="http://fritz.box"
Username=""
Passwd=""
FRITZLOGIN="/login_sid.lua"
login(){
htmlLoginPage=$(curl -s "$FritzBoxURL$FRITZLOGIN")
SessionInfoChallenge=$(sed -e 's#<Challenge>#§#' -e 's#</Challenge>#§#' <<< "$htmlLoginPage" | awk -F'§' '{print $2}')
SessionInfoSID=$(sed -e 's#<SID>#§#' -e 's#</SID>#§#' <<< "$htmlLoginPage" | awk -F'§' '{print $2}')
if [ "$SessionInfoSID" = "0000000000000000" ]; then
CPSTR="$SessionInfoChallenge-$Passwd" # Combine Challenge and Passwd
MD5=$(echo -n "$CPSTR" | sed -e 's,.,&\n,g' | tr '\n' '\0' | md5sum | grep -o "[0-9a-z]\{32\}") # here the MD5 checksum is calculated
RESPONSE="$SessionInfoChallenge-$MD5"
GETDATA="?username=$Username&response=$RESPONSE"
SID=$(curl -s "$FritzBoxURL$FRITZLOGIN$GETDATA" | sed -e 's#<SID>#§#' -e 's#</SID>#§#' | awk -F'§' '{print $2}')
else
SID=$SessionInfoSID
fi
}
# gets a json object containing an array of all known (offline and online) devices
curl -s "$FritzBoxURL/data.lua" --data-raw "xhr=1&sid=${SID}&page=netDev&xhrId=cleanup&useajax=1&no_sidrenew="
# formats said json object to a list with IPv4, mac, landevice-ID and DeviceName on one line per device sorted by IPv4
curl -s "$FritzBoxURL/data.lua" --data-raw "xhr=1&sid=${SID}&page=netDev&xhrId=cleanup&useajax=1&no_sidrenew=" | jq -r '.data.active[],.data.passive[] | "\(.ipv4.ip) \(.mac) \(.UID) \(.name)"' | sort -h
# gets the html from the filters-page of the Fritzbox-WebUI and extracts the filters with filtprof-ID and name one filter per Line
curl -s "$FritzBoxURL/data.lua" --data-raw "xhr=1^&sid=${SID}^&page=kidPro" | grep -Eo 'value="(filtprof[0-9]+)" class="[^"]+"[ a-z]*data-name="([0-9a-zA-Z_-]+)"' | sed -Ee 's/value="([^"]+)".*data-name="([^"]+)"/\1 \2/g'
Example output of the devices list:
192.168.178.2 00:1A:2B:3C:4D:5E landevice2185 Device1
192.168.178.3 00:1A:2B:3C:4D:5F landevice32561 Device2
192.168.178.5 00:1A:2B:3C:4D:3E landevice2728 device-15
Example output of the filters list:
filtprof2 Profil1
filtprof15 Profil2
Maybe this would be helpful as a basis to implement such a feature.
(Another but probably much more difficult to implement idea would be to parse these lists and allow the user to refer to device and filter by name only, in case there are only unique names. Also the device could be referred to by its mac address as that should be unique, too.)