Commit 0dd54232 authored by Bc. Petr Elexa's avatar Bc. Petr Elexa

server: treat missing door as warning

parent 3369b7fd
......@@ -113,6 +113,10 @@ class acs_database(object):
def get_panels_in_group(self, group:str):
return self.__rclient_group.smembers(group)
# Return true if door is in database
def is_door_registered(self, reader_addr:int) -> bool:
self.__rclient_door.llen(reader_addr) == 2
# Return True if user is authorized for given reader (door) number.
def is_user_authorized(self, user_id:int, reader_addr:int) -> bool:
group = self.get_user_group(user_id)
......@@ -125,7 +129,7 @@ class acs_database(object):
# Log that user accessed a door/reader.
def log_user_access(self, user_id, reader_addr):
logging.info("User \"{}\" accessed door \"{}\"".format(user_id, reader_addr))
logging.info("User \"{}\" accessed \"{}\"".format(user_id, reader_addr))
# Mode is one of DOOR_MODE_...
def set_door_mode(self, reader_addr, mode):
......@@ -133,7 +137,10 @@ class acs_database(object):
# Return one of DOOR_MODE_...
def get_door_mode(self, reader_addr):
return self.__rclient_door.lindex(reader_addr, self.__DOOR_MODE_IDX)
door_mode = self.__rclient_door.lindex(reader_addr, self.__DOOR_MODE_IDX)
if door_mode is None:
logging.warning("Door {} does not exist! Check DB consistency.".format(reader_addr))
return door_mode
# Door open/close status is tracked.
def set_door_is_open(self, reader_addr, is_open:bool):
......
......@@ -62,7 +62,7 @@ class acs_server(object):
self.proto.can_sock.send(can_id, dlc, data)
# add a new user to database
def add_new_user(self, reader_addr, user_id):
def add_new_user(self, user_id, reader_addr):
if self.debug:
logging.debug("add_new_user: reader={}, user={}".format(reader_addr, user_id))
# do not add existing users
......@@ -85,9 +85,7 @@ class acs_server(object):
logging.debug("resp_to_auth_req: reader={}, user={}".format(reader_addr, user_id))
mode = self.db.get_door_mode(reader_addr)
if mode is None:
if self.debug:
logging.debug("resp_to_auth_req: no door mode!")
mode = self.db.DOOR_MODE_ENABLED # fallback to default
return False # treat as invalid request (door does not exist)
if mode == self.db.DOOR_MODE_ENABLED:
if self.db.is_user_authorized(user_id, reader_addr):
self.db.log_user_access(user_id, reader_addr)
......@@ -95,13 +93,13 @@ class acs_server(object):
else:
return False
elif mode == self.db.DOOR_MODE_LEARN:
self.add_new_user(reader_addr, user_id)
self.add_new_user(user_id, reader_addr)
return True
else:
return False
# callback for door status update
def door_status_update(self, reader_addr, is_open):
def door_status_update(self, reader_addr, is_open:bool):
if self.debug:
logging.debug("door_status_update: reader={} open={}".format(reader_addr, is_open))
self.db.set_door_is_open(reader_addr, is_open)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment