From 79599e2a4595cb4a5c4ee3d446f329071934c81f Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Sun, 18 Mar 2018 22:03:48 +0100 Subject: [PATCH] doorlockd.py: Add lock/unlock scripts Signed-off-by: Ralf Ramsauer --- doorlockd-new/TODOs | 1 - doorlockd-new/doorlockd.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/doorlockd-new/TODOs b/doorlockd-new/TODOs index e01dd7d..1fdd826 100644 --- a/doorlockd-new/TODOs +++ b/doorlockd-new/TODOs @@ -1,3 +1,2 @@ - Connect to LDAP -- Add support for post/pre lock/unlock hooks - Implement proper RS232 support diff --git a/doorlockd-new/doorlockd.py b/doorlockd-new/doorlockd.py index 801acc0..8995fbf 100755 --- a/doorlockd-new/doorlockd.py +++ b/doorlockd-new/doorlockd.py @@ -23,6 +23,7 @@ import sys from enum import Enum from random import sample from serial import Serial +from subprocess import Popen from threading import Thread from time import sleep @@ -87,6 +88,14 @@ def choose_insult(): return(sample(eperm_insults, 1)[0]) +def start_hook(script): + if simulate: + log.info('Simulation mode: not starting %s' % script) + return + log.info('Starting hook %s' % script) + Popen(['nohup', script]) + + class AuthMethod(Enum): LDAP_USER_PW = 1 @@ -165,6 +174,7 @@ class DoorHandler: return LogicResponse.AlreadyOpen self.state = DoorState.Open + start_hook('./scripts/post_unlock.sh') return LogicResponse.Success def close(self): @@ -172,6 +182,7 @@ class DoorHandler: return LogicResponse.AlreadyLocked self.state = DoorState.Close + start_hook('./scripts/post_lock.sh') return LogicResponse.Success def request(self, state):