Skip to content

Commit

Permalink
Support Firtz OS 7.24
Browse files Browse the repository at this point in the history
  • Loading branch information
oe73773 committed Jun 14, 2021
1 parent a394a3f commit 72c2fbb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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*
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fritzbox_password>
env.fritzbox_user <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_<fqdn1>_*]
env.fritzbox_password <fritzbox_password>
env.traffic_remove_max true # if you do not want the possible max values
env.fritzbox_password <fritzbox_password>
env.fritzbox_user <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_<fqdn2>_*]
env.fritzbox_password <fritzbox_password>
env.traffic_remove_max true # if you do not want the possible max values
env.fritzbox_password <fritzbox_password>
env.fritzbox_user <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`.

Expand Down
28 changes: 17 additions & 11 deletions fritzbox_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import hashlib
import sys
import os

import requests
import urllib.parse
Expand All @@ -38,12 +39,6 @@
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("$")
Expand Down Expand Up @@ -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$"):
Expand All @@ -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)
Expand Down

0 comments on commit 72c2fbb

Please sign in to comment.