2018-05-27 17:17:36 -04:00
|
|
|
import json
|
2018-05-12 09:49:51 -04:00
|
|
|
import urllib3
|
|
|
|
from xml.etree import ElementTree as ET
|
|
|
|
import requests
|
|
|
|
|
|
|
|
from passwords import *
|
|
|
|
|
|
|
|
# it's fine, ssl certs are for losers anyway
|
|
|
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
|
|
|
2018-05-27 17:17:36 -04:00
|
|
|
config = json.load(open("config.json"))
|
|
|
|
|
2018-05-14 22:36:24 -04:00
|
|
|
ET.register_namespace("hid", "http://www.hidglobal.com/VertX")
|
|
|
|
ET.register_namespace("hid", "http://www.hidcorp.com/VertX")
|
|
|
|
|
2018-05-12 09:49:51 -04:00
|
|
|
fieldnames = "CardNumber,CardFormat,PinRequired,PinCode,ExtendedAccess,ExpiryDate,Forename,Initial,Surname,Email,Phone,Custom1,Custom2,Schedule1,Schedule2,Schedule3,Schedule4,Schedule5,Schedule6,Schedule7,Schedule8".split(",")
|
|
|
|
|
|
|
|
def doImportRequest(ip, params=None, files=None):
|
|
|
|
"""Send a request to the door control import script"""
|
|
|
|
r = requests.post(
|
|
|
|
'https://' + ip + '/cgi-bin/import.cgi',
|
|
|
|
params=params,
|
|
|
|
files=files,
|
|
|
|
auth=requests.auth.HTTPDigestAuth(DOOR_USERNAME, DOOR_PASSWORD),
|
|
|
|
timeout=10,
|
|
|
|
verify=False) # ignore insecure SSL
|
|
|
|
xml = ET.XML(r.text)
|
|
|
|
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)
|
|
|
|
|
|
|
|
def doCSVImport(doorIP, csv):
|
|
|
|
"""Do the CSV import procedure on a door control"""
|
|
|
|
doImportRequest(doorIP, {"task": "importInit"})
|
|
|
|
doImportRequest(doorIP,
|
|
|
|
{"task": "importCardsPeople", "name": "cardspeopleschedule.csv"},
|
|
|
|
{"importCardsPeopleButton": ("cardspeopleschedule.csv", csv, 'text/csv')})
|
|
|
|
doImportRequest(doorIP, {"task": "importDone"})
|
2018-05-14 11:23:25 -04:00
|
|
|
|
|
|
|
def doXMLRequest(doorIP, xml, prefix=b'<?xml version="1.0" encoding="UTF-8"?>'):
|
|
|
|
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
|