diff --git a/Changelog.md b/Changelog.md index e68292a..2d1d555 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,4 +1,7 @@ # Changelog +## +*2021-06-14* +- Support for FRITZ!OS 7.24. Login without Username was removed. ## 6.83.2 *2017-09-05* diff --git a/README.md b/README.md index e08b648..1d8f6c1 100644 --- a/README.md +++ b/README.md @@ -70,17 +70,20 @@ If you are using the scripts on a different Fritz!Box model please let me know b [fritzbox_*] env.fritzbox_password + env.fritzbox_user # User name is automaticly detected if you do have password only login and this value doesn't need to be set. env.traffic_remove_max true # if you do not want the possible max values 2. multiple fritzboxes: [fritzbox__*] - env.fritzbox_password - env.traffic_remove_max true # if you do not want the possible max values + env.fritzbox_password + env.fritzbox_user # User name is automaticly detected if you do have password only login and this value doesn't need to be set. + env.traffic_remove_max true # if you do not want the possible max values [fritzbox__*] - env.fritzbox_password - env.traffic_remove_max true # if you do not want the possible max values + env.fritzbox_password + env.fritzbox_user # User name is automaticly detected if you do have password only login and this value doesn't need to be set. + env.traffic_remove_max true # if you do not want the possible max values 6. Create symbolic link in `/etc/munin/plugins` for `fritzbox_helper.py`. diff --git a/fritzbox_helper.py b/fritzbox_helper.py index 074b01e..a0d9714 100755 --- a/fritzbox_helper.py +++ b/fritzbox_helper.py @@ -27,6 +27,7 @@ import hashlib import sys +import os import requests import urllib.parse @@ -38,12 +39,6 @@ USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:10.0) Gecko/2010010 Code from https://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AVM_Technical_Note_-_Session_ID_deutsch_2021-05-03.pdf start """ -class LoginState: - def __init__(self, challenge: str, blocktime: int): - self.challenge = challenge - self.blocktime = blocktime - self.is_pbkdf2 = challenge.startswith("2$") - def calculate_pbkdf2_response(challenge: str, password: str) -> str: """ Calculate the response for a given challenge via PBKDF2 """ challenge_parts = challenge.split("$") @@ -96,11 +91,18 @@ def get_session_id(server, password, port=80): print(err) sys.exit(1) - root = etree.fromstring(r.content) session_id = root.xpath('//SessionInfo/SID/text()')[0] - user_id = root.xpath('//SessionInfo/Users/User/text()')[0] challenge = root.xpath('//SessionInfo/Challenge/text()')[0] + new_login = True + + try: + user_id = root.xpath('//SessionInfo/Users/User/text()')[0] + except IndexError: + new_login = False + + if "fritzbox_user" in os.environ: + user_id = os.environ['fritzbox_user'] if session_id == "0000000000000000": if challenge.startswith("2$"): @@ -114,10 +116,14 @@ def get_session_id(server, password, port=80): "Content-Type": "application/x-www-form-urlencoded", "User-Agent": USER_AGENT} - url = 'http://{}:{}/login_sid.lua?version=2'.format(server, port) try: - data = {"username": "fritz8535", "response": response_bf} - r = requests.post(url, urllib.parse.urlencode(data).encode(), headers=headers) + if new_login: + url = 'http://{}:{}/login_sid.lua?version=2'.format(server, port) + data = {"username": user_id,"response": response_bf} + r = requests.post(url, urllib.parse.urlencode(data).encode(), headers=headers) + else: + url = 'http://{}:{}/login_sid.lua?&response={}'.format(server, port, response_bf) + r = requests.get(url, headers=headers) r.raise_for_status() except requests.exceptions.HTTPError as err: print(err)