Skip to content

Commit

Permalink
Adds SimpleRfidAuth, rfid_auth module using plain access list in conf…
Browse files Browse the repository at this point in the history
…ig.ini
  • Loading branch information
wie-niet committed May 30, 2024
1 parent 6e449bd commit 1391477
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config-default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ log_level = "DEBUG"
# logfile_level = "INFO"
logfile_name = "/var/log/doorlockd.log"

##
## /* SimpleRfidAuth: plain list of hardware ids */
##
# [module.rfid_auth]
# type = "SimpleRfidAuth"
# access_list = ["01:0a:0f:08", "...", "..."]


#
# DjangoBackendRfidAuth -> Comunicate with Django-backend for authentication
Expand Down
53 changes: 53 additions & 0 deletions libs/module/SimpleRfidAuth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import requests
import simplejson as json
import threading
import datetime
import time
import hashlib
import os

# import logging
# logger = logging.getLogger(__name__)

from libs.data_container import data_container as dc

logger = dc.logger


class SimpleRfidAuth:
"""rfid_auth using a plain list of hardware ids"""

def __init__(self, config={}):

# init BackendApi with config:
#
# [module.rfid_auth]
# type = "SimpleRfidAuth"
# access_list = ["01:0a:0f:08", "...", "..."]

self.access_list = set()
for hwid in config.get("access_list"):
self.access_list.add(hwid.lower())

# declare self as rfid_auth:
dc.rfid_auth = self

def setup(self):
# self.api.setup()
pass

def enable(self):
pass

def disable(self):
pass

def teardown(self):
pass

def has_access(self, hwid_str):
"""lookup detected hwid,"""
# lookup hwid in db
access = hwid_str in self.access_list
logger.debug(f"RFID KEY lookup({hwid_str}): access={access}")
return access

0 comments on commit 1391477

Please sign in to comment.