From 48333d1e6dff707758676974b1e22e23ce410c1c Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 16 Aug 2018 10:59:31 -0400 Subject: [PATCH] viewer: add basic buttons to lock/unlock front door --- doorUtil.py | 7 +++++++ membershipViewer.py | 7 +++++++ templates/members.html | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/doorUtil.py b/doorUtil.py index 08fba9f..18b4620 100644 --- a/doorUtil.py +++ b/doorUtil.py @@ -50,6 +50,13 @@ def sendCardFormat(targetIP, formatName, templateID, facilityCode): attrib={"value": str(facilityCode)}) return doXMLRequest(targetIP, ET.tostring(el)) +def lockOrUnlockDoor(targetIP, lock=True): + el = ET.Element("VertXMessage") + ET.SubElement(el, "hid:Doors", + attrib={"action": "CM", + "command": "lockDoor" if lock else "unlockDoor"}) + return doXMLRequest(targetIP, ET.tostring(el)) + def forEachDoor(fxn): for doorName, doorData in config["doors"].items(): print(doorName) diff --git a/membershipViewer.py b/membershipViewer.py index 7685bd0..8b99177 100644 --- a/membershipViewer.py +++ b/membershipViewer.py @@ -1,11 +1,13 @@ #!/usr/bin/env python3 import re +import http from flask import Flask, render_template, request app = Flask(__name__) from common import * +from doorUtil import lockOrUnlockDoor def parse_list(member, regex): data_list = [] @@ -60,5 +62,10 @@ def main(): return render_template("members.html", headers=headers, members=members) +@app.route('/frontDoor/', methods=['POST']) +def unlockLockDoor(lock): + lockOrUnlockDoor(config['doors']['Front Door']['ip'], lock != 'unlock') + return ('', http.HTTPStatus.NO_CONTENT) + if __name__ == "__main__": app.run(debug=True, host='0.0.0.0') diff --git a/templates/members.html b/templates/members.html index 0fa6813..2b230f0 100644 --- a/templates/members.html +++ b/templates/members.html @@ -24,6 +24,10 @@ +
+ + +