From f0d43e8168201dad5902f841dd0699554911aeef Mon Sep 17 00:00:00 2001 From: Christoph Wempe Date: Fri, 3 Mar 2017 00:44:12 +0100 Subject: [PATCH] handle empty or missing fritzbox_username --- fritzbox_cpu_temperature.py | 2 +- fritzbox_cpu_usage.py | 2 +- fritzbox_helper.py | 5 ++++- fritzbox_memory_usage.py | 2 +- fritzbox_power_consumption.py | 2 +- fritzbox_uptime.py | 2 +- fritzbox_wifi_devices.py | 2 +- 7 files changed, 10 insertions(+), 7 deletions(-) diff --git a/fritzbox_cpu_temperature.py b/fritzbox_cpu_temperature.py index 1dad21a..90c6362 100755 --- a/fritzbox_cpu_temperature.py +++ b/fritzbox_cpu_temperature.py @@ -33,7 +33,7 @@ def get_cpu_temperature(): """get the current cpu temperature""" server = os.environ['fritzbox_ip'] - username = os.environ['fritzbox_username'] + username = os.getenv('fritzbox_username', "None") password = os.environ['fritzbox_password'] sid = fh.get_sid(server, username, password) diff --git a/fritzbox_cpu_usage.py b/fritzbox_cpu_usage.py index bbaef23..fa3217b 100755 --- a/fritzbox_cpu_usage.py +++ b/fritzbox_cpu_usage.py @@ -33,7 +33,7 @@ def get_cpu_usage(): """get the current cpu usage""" server = os.environ['fritzbox_ip'] - username = os.environ['fritzbox_username'] + username = os.getenv('fritzbox_username', "None") password = os.environ['fritzbox_password'] sid = fh.get_sid(server, username, password) diff --git a/fritzbox_helper.py b/fritzbox_helper.py index 4ffabf6..991e29b 100755 --- a/fritzbox_helper.py +++ b/fritzbox_helper.py @@ -58,7 +58,10 @@ def get_sid(server, username, password, port=80): "Content-Type": "application/x-www-form-urlencoded", "User-Agent": USER_AGENT} - login_page = "/login_sid.lua?username=" + username + "&response=" + response_bf + if username == '' or username == 'None': + login_page = "/login_sid.lua?&response=" + response_bf + else: + login_page = "/login_sid.lua?username=" + username + "&response=" + response_bf conn.request("GET", login_page, '', headers) response = conn.getresponse() data = response.read() diff --git a/fritzbox_memory_usage.py b/fritzbox_memory_usage.py index b4f1f47..34bbff8 100755 --- a/fritzbox_memory_usage.py +++ b/fritzbox_memory_usage.py @@ -34,7 +34,7 @@ def get_memory_usage(): """get the current memory usage""" server = os.environ['fritzbox_ip'] - username = os.environ['fritzbox_username'] + username = os.getenv('fritzbox_username', "None") password = os.environ['fritzbox_password'] sid = fh.get_sid(server, username, password) diff --git a/fritzbox_power_consumption.py b/fritzbox_power_consumption.py index 20f063f..2cbbac3 100755 --- a/fritzbox_power_consumption.py +++ b/fritzbox_power_consumption.py @@ -34,7 +34,7 @@ def get_power_consumption(): """get the current power consumption usage""" server = os.environ['fritzbox_ip'] - username = os.environ['fritzbox_username'] + username = os.getenv('fritzbox_username', "None") password = os.environ['fritzbox_password'] sid = fh.get_sid(server, username, password) diff --git a/fritzbox_uptime.py b/fritzbox_uptime.py index 43d0625..582b348 100755 --- a/fritzbox_uptime.py +++ b/fritzbox_uptime.py @@ -33,7 +33,7 @@ def get_uptime(): """get the current uptime""" server = os.environ['fritzbox_ip'] - username = os.environ['fritzbox_username'] + username = os.getenv('fritzbox_username', "None") password = os.environ['fritzbox_password'] sid = fh.get_sid(server, username, password) diff --git a/fritzbox_wifi_devices.py b/fritzbox_wifi_devices.py index eb8030f..fe4f5d1 100755 --- a/fritzbox_wifi_devices.py +++ b/fritzbox_wifi_devices.py @@ -33,7 +33,7 @@ def get_connected_wifi_devices(): """gets the numbrer of currently connected wifi devices""" server = os.environ['fritzbox_ip'] - username = os.environ['fritzbox_username'] + username = os.getenv('fritzbox_username', "None") password = os.environ['fritzbox_password'] sid = fh.get_sid(server, username, password)