diff --git a/common.py b/common.py index 97d751f..422f5d5 100644 --- a/common.py +++ b/common.py @@ -32,3 +32,18 @@ def doCSVImport(doorIP, csv): {"task": "importCardsPeople", "name": "cardspeopleschedule.csv"}, {"importCardsPeopleButton": ("cardspeopleschedule.csv", csv, 'text/csv')}) doImportRequest(doorIP, {"task": "importDone"}) + +def doXMLRequest(doorIP, xml, prefix=b''): + r = requests.get( + 'https://' + doorIP + '/cgi-bin/vertx_xml.cgi', + params={'XML': prefix + xml}, + auth=requests.auth.HTTPDigestAuth(DOOR_USERNAME, DOOR_PASSWORD), + verify=False) + xml = ET.XML(r.text) + # probably meed to be more sane about this + if r.status_code != 200 \ + or len(xml.findall("{http://www.hidglobal.com/VertX}Error")) > 0: + print("Door Updating Error: ", r.status_code, r.reason) + print(r.text) + sys.exit(1) + return xml diff --git a/events.py b/events.py index 4e39d93..35522aa 100755 --- a/events.py +++ b/events.py @@ -1,12 +1,9 @@ #!/usr/bin/env python3 -import requests from xml.etree import ElementTree as ET -import urllib3 -from passwords import * - -urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) +from common import * +TARGET_IP = '172.18.51.11' # From /html/en_EN/en_EN.js localeStrings eventStrings = { @@ -36,22 +33,13 @@ eventStrings = { 4045: 'Battery Failure', } -def doRequest(xml): - r = requests.get( - 'https://172.18.51.11/cgi-bin/vertx_xml.cgi', - params={'XML': b'' + xml}, - auth=requests.auth.HTTPDigestAuth(DOOR_USERNAME, DOOR_PASSWORD), - verify=False) - return ET.XML(r.text) - - # # XML = ET.Element("VertXMessage") ET.SubElement(XML, "hid:EventMessages", attrib={"action": "LR"}) -xml = doRequest(ET.tostring(XML)) +xml = doXMLRequest(TARGET_IP, ET.tostring(XML)) print(xml[0].attrib) XML = ET.Element("VertXMessage") @@ -60,7 +48,7 @@ ET.SubElement(XML, "hid:EventMessages", "recordCount": "1000", "historyRecordMarker": xml[0].attrib["historyRecordMarker"], "historyTimestamp": xml[0].attrib["historyTimestamp"]}) -xml = doRequest(ET.tostring(XML)) +xml = doXMLRequest(TARGET_IP, ET.tostring(XML)) for event in xml[0]: ET.dump(event) att = event.attrib diff --git a/sendSchedule.py b/sendSchedule.py index c2769e2..9176987 100755 --- a/sendSchedule.py +++ b/sendSchedule.py @@ -8,14 +8,6 @@ from common import * TARGET_IP = '172.18.51.15' -def doRequest(xml): - r = requests.get( - 'https://' + TARGET_IP + '/cgi-bin/vertx_xml.cgi', - params={'XML': xml}, - auth=requests.auth.HTTPDigestAuth(DOOR_USERNAME, DOOR_PASSWORD), - verify=False) - print(r.text) - # clear all people outString = StringIO() writer = csv.DictWriter(outString, fieldnames) @@ -29,8 +21,7 @@ delXML = ET.Element("VertXMessage") for ii in range(1, 8): ET.SubElement(delXML, "hid:Schedules", attrib={"action": "DD", "scheduleID": str(ii)}) -print(b'' + ET.tostring(delXML)) -doRequest(b'' + ET.tostring(delXML)) +doXMLRequest(TARGET_IP, ET.tostring(delXML)) # load new schedules with open("schedules.xml", "rb") as f: