mirror of
https://github.com/Tafkas/fritzbox-munin.git
synced 2023-10-10 13:36:55 +02:00
pep8 formatting
This commit is contained in:
parent
056bae26b1
commit
598c695d9c
@ -18,14 +18,13 @@
|
|||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import httplib
|
import httplib
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
from io import StringIO, BytesIO
|
|
||||||
|
|
||||||
USER_AGENT = "Mozilla/5.0 (U; Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0"
|
USER_AGENT = "Mozilla/5.0 (U; Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0"
|
||||||
|
|
||||||
|
|
||||||
def get_sid(server, password, port=80):
|
def get_sid(server, password, port=80):
|
||||||
"""Obtains the sid after login into the fritzbox"""
|
"""Obtains the sid after login into the fritzbox"""
|
||||||
conn = httplib.HTTPConnection(server + ':' + str(port))
|
conn = httplib.HTTPConnection(server + ':' + str(port))
|
||||||
@ -34,20 +33,20 @@ def get_sid(server,password,port=80):
|
|||||||
"Content-Type": "text/plain",
|
"Content-Type": "text/plain",
|
||||||
"User-Agent": USER_AGENT}
|
"User-Agent": USER_AGENT}
|
||||||
|
|
||||||
initialPage='/login_sid.lua'
|
initial_page = '/login_sid.lua'
|
||||||
conn.request("GET", initialPage, '', headers)
|
conn.request("GET", initial_page, '', headers)
|
||||||
response = conn.getresponse()
|
response = conn.getresponse()
|
||||||
data = response.read()
|
data = response.read()
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
print "%s %s" % (response.status, response.reason)
|
print "%s %s" % (response.status, response.reason)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
theXml = minidom.parseString(data)
|
xml_data = minidom.parseString(data)
|
||||||
sidInfo = theXml.getElementsByTagName('SID')
|
sid_info = xml_data.getElementsByTagName('SID')
|
||||||
sid=sidInfo[0].firstChild.data
|
sid = sid_info[0].firstChild.data
|
||||||
if sid == "0000000000000000":
|
if sid == "0000000000000000":
|
||||||
challengeInfo = theXml.getElementsByTagName('Challenge')
|
challenge_info = xml_data.getElementsByTagName('Challenge')
|
||||||
challenge=challengeInfo[0].firstChild.data
|
challenge = challenge_info[0].firstChild.data
|
||||||
challenge_bf = (challenge + '-' + password).decode('iso-8859-1').encode('utf-16le')
|
challenge_bf = (challenge + '-' + password).decode('iso-8859-1').encode('utf-16le')
|
||||||
m = hashlib.md5()
|
m = hashlib.md5()
|
||||||
m.update(challenge_bf)
|
m.update(challenge_bf)
|
||||||
@ -59,20 +58,21 @@ def get_sid(server,password,port=80):
|
|||||||
"Content-Type": "application/x-www-form-urlencoded",
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
"User-Agent": USER_AGENT}
|
"User-Agent": USER_AGENT}
|
||||||
|
|
||||||
loginPage="/login_sid.lua?&response=" + response_bf
|
login_page = "/login_sid.lua?&response=" + response_bf
|
||||||
conn.request("GET", loginPage, '', headers)
|
conn.request("GET", login_page, '', headers)
|
||||||
response = conn.getresponse()
|
response = conn.getresponse()
|
||||||
data = response.read()
|
data = response.read()
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
print "%s %s" % (response.status, response.reason)
|
print "%s %s" % (response.status, response.reason)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
sid = re.search('<SID>(.*?)</SID>', data).group(1)
|
sid = re.search("<SID>(.*?)</SID>", data).group(1)
|
||||||
if sid == "0000000000000000":
|
if sid == "0000000000000000":
|
||||||
print "ERROR - No SID received because of invalid password"
|
print "ERROR - No SID received because of invalid password"
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
return sid
|
return sid
|
||||||
|
|
||||||
|
|
||||||
def get_page(server, sid, page, port=80):
|
def get_page(server, sid, page, port=80):
|
||||||
"""Fetches a page from the Fritzbox and returns its content"""
|
"""Fetches a page from the Fritzbox and returns its content"""
|
||||||
conn = httplib.HTTPConnection(server + ':' + str(port))
|
conn = httplib.HTTPConnection(server + ':' + str(port))
|
||||||
@ -81,8 +81,8 @@ def get_page(server, sid, page, port=80):
|
|||||||
"Content-Type": "text/plain",
|
"Content-Type": "text/plain",
|
||||||
"User-Agent": USER_AGENT}
|
"User-Agent": USER_AGENT}
|
||||||
|
|
||||||
pageWithSid=page+"?sid="+sid
|
page_with_sid = page + "?sid=" + sid
|
||||||
conn.request("GET", pageWithSid, '', headers)
|
conn.request("GET", page_with_sid, '', headers)
|
||||||
response = conn.getresponse()
|
response = conn.getresponse()
|
||||||
data = response.read()
|
data = response.read()
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user