1
0
mirror of https://github.com/Tafkas/fritzbox-munin.git synced 2023-10-10 13:36:55 +02:00

remove type hints

This commit is contained in:
Christian Stade-Schuldt 2021-03-26 14:16:41 +01:00
parent 485846a780
commit f35f0bb2f4

View File

@ -25,7 +25,6 @@
""" """
import hashlib import hashlib
import os
import sys import sys
import time import time
@ -38,13 +37,13 @@ LOGIN_SID_ROUTE = "/login_sid.lua?version=2"
class LoginState: class LoginState:
def __init__(self, challenge: str, blocktime: int): def __init__(self, challenge, blocktime):
self.challenge = challenge self.challenge = challenge
self.blocktime = blocktime self.blocktime = blocktime
self.is_pbkdf2 = challenge.startswith("2$") self.is_pbkdf2 = challenge.startswith("2$")
def get_session_id(server: str, username: str, password: str, port: int = 80) -> str: def get_session_id(server, username, password, port=80):
""" Get a sid by solving the PBKDF2 (or MD5) challenge-response process. """ """ Get a sid by solving the PBKDF2 (or MD5) challenge-response process. """
box_url = "http://{}:{}".format(server, port) box_url = "http://{}:{}".format(server, port)
try: try:
@ -69,7 +68,7 @@ def get_session_id(server: str, username: str, password: str, port: int = 80) ->
return sid return sid
def get_login_state(box_url: str) -> LoginState: def get_login_state(box_url):
""" Get login state from FRITZ!Box using login_sid.lua?version=2 """ """ Get login state from FRITZ!Box using login_sid.lua?version=2 """
url = box_url + LOGIN_SID_ROUTE url = box_url + LOGIN_SID_ROUTE
r = requests.get(url) r = requests.get(url)
@ -79,7 +78,7 @@ def get_login_state(box_url: str) -> LoginState:
return LoginState(challenge, blocktime) return LoginState(challenge, blocktime)
def calculate_pbkdf2_response(challenge: str, password: str) -> str: def calculate_pbkdf2_response(challenge, password):
""" Calculate the response for a given challenge via PBKDF2 """ """ Calculate the response for a given challenge via PBKDF2 """
challenge_parts = challenge.split("$") challenge_parts = challenge.split("$")
# Extract all necessary values encoded into the challenge # Extract all necessary values encoded into the challenge
@ -94,7 +93,7 @@ def calculate_pbkdf2_response(challenge: str, password: str) -> str:
return f"{challenge_parts[4]}${hash2.hex()}" return f"{challenge_parts[4]}${hash2.hex()}"
def calculate_md5_response(challenge: str, password: str) -> str: def calculate_md5_response(challenge, password):
""" Calculate the response for a challenge using legacy MD5 """ """ Calculate the response for a challenge using legacy MD5 """
response = challenge + "-" + password response = challenge + "-" + password
# the legacy response needs utf_16_le encoding # the legacy response needs utf_16_le encoding
@ -105,7 +104,7 @@ def calculate_md5_response(challenge: str, password: str) -> str:
return response return response
def send_response(box_url: str, username: str, challenge_response: str) -> str: def send_response(box_url, username, challenge_response):
""" Send the response and return the parsed sid. raises an Exception on error """ """ Send the response and return the parsed sid. raises an Exception on error """
# Build response params # Build response params
post_data = {"username": username, "response": challenge_response} post_data = {"username": username, "response": challenge_response}