forked from CMS/memberPlumbing
76 lines
2.8 KiB
Python
Executable File
76 lines
2.8 KiB
Python
Executable File
#!/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 /html/en_EN/en_EN.js localeStrings
|
|
eventStrings = {
|
|
1022: 'Denied Access{6} Card Not Found {3}',
|
|
1023: 'Denied Access{6} Access PIN Not Found {3}',
|
|
2020: 'Granted Access{6} {2}',
|
|
2021: 'Granted Access{6} Extended Time {2}',
|
|
2024: 'Denied Access{6} Schedule {2}',
|
|
2029: 'Denied Access{6} Wrong PIN {2}',
|
|
2036: 'Denied Access{6} Card Expired {2}',
|
|
2042: 'Denied Access{6} PIN Lockout {2}',
|
|
2043: 'Denied Access{6} Unassigned Card {3}',
|
|
2044: 'Denied Access{6} Unassigned Access PIN {3}',
|
|
2046: 'Denied Access - PIN Expired {2}',
|
|
4051: 'REX Switch Alarm',
|
|
7020: 'Time Set to: {5}',
|
|
12031: 'Granted Access{6} Manual',
|
|
12032: 'Door Unlocked',
|
|
12033: 'Door Locked',
|
|
4034: 'Alarm Acknowledged',
|
|
4035: 'Door Locked-Scheduled',
|
|
4036: 'Door Unlocked-Scheduled',
|
|
4041: 'Door Forced Alarm',
|
|
4042: 'Door Held Alarm',
|
|
4043: 'Tamper Switch Alarm',
|
|
4044: 'AC Failure',
|
|
4045: 'Battery Failure',
|
|
}
|
|
|
|
def doRequest(xml):
|
|
r = requests.get(
|
|
'https://172.18.51.11/cgi-bin/vertx_xml.cgi',
|
|
params={'XML': b'<?xml version="1.0" encoding="UTF-8"?>' + xml},
|
|
auth=requests.auth.HTTPDigestAuth(DOOR_USERNAME, DOOR_PASSWORD),
|
|
verify=False)
|
|
return ET.XML(r.text)
|
|
|
|
|
|
#<?xml version="1.0" encoding="UTF-8"?> <VertXMessage> <hid:EventMessages action="LR" recordCount="100" historyRecordMarker="463" historyTimestamp="1525824431"/> </VertXMessage>
|
|
|
|
#<?xml version="1.0" encoding="UTF-8"?><VertXMessage xmlns:hid="http://www.hidcorp.com/VertX"><hid:EventMessages action="RL" historyRecordMarker="463" historyTimestamp="1525824431" currentRecordMarker="463" currentTimestamp="1525824431" /></VertXMessage>
|
|
|
|
XML = ET.Element("VertXMessage")
|
|
ET.SubElement(XML, "hid:EventMessages", attrib={"action": "LR"})
|
|
xml = doRequest(ET.tostring(XML))
|
|
print(xml[0].attrib)
|
|
|
|
XML = ET.Element("VertXMessage")
|
|
ET.SubElement(XML, "hid:EventMessages",
|
|
attrib={"action": "LR",
|
|
"recordCount": "1000",
|
|
"historyRecordMarker": xml[0].attrib["historyRecordMarker"],
|
|
"historyTimestamp": xml[0].attrib["historyTimestamp"]})
|
|
xml = doRequest(ET.tostring(XML))
|
|
for event in xml[0]:
|
|
ET.dump(event)
|
|
att = event.attrib
|
|
eventType = int(att["eventType"])
|
|
print(att["timestamp"], eventStrings[eventType].format(
|
|
'ios-' + att.get('ioState', ''),
|
|
'status-' + att.get('commandStatus', ''),
|
|
att.get('forename', '') + " " + att.get('surname', ''),
|
|
att.get('rawCardNumber', ''),
|
|
att.get('oldTime', ''),
|
|
att.get('newTime', ''),
|
|
"IN" if att.get("readerAddress", '') == '0' else "OUT"))
|