Compare commits
No commits in common. "2576ad0dce9f76afa482bd70934ccbea28e4ded8" and "4ac7e46ca84de79556401130d45a4e4e39593537" have entirely different histories.
2576ad0dce
...
4ac7e46ca8
45
door.py
45
door.py
|
@ -77,26 +77,16 @@ def read_valid_tokens():
|
|||
log("Loading tokens")
|
||||
valid = {}
|
||||
lines =[ s.strip() for s in open(config.valid_tokens, "r").readlines() ]
|
||||
for i, line in enumerate(lines):
|
||||
l = line.split('|')
|
||||
if len(l) == 5:
|
||||
if not l[0].strip().startswith('#'):
|
||||
token, name, organization, email, valid_thru = l
|
||||
try:
|
||||
if len(valid_thru.strip()) > 0:
|
||||
valid_thru = datetime.date.fromisoformat(valid_thru)
|
||||
for l in lines:
|
||||
l = l.split('|', 1)
|
||||
if len(l) > 1:
|
||||
if l[0] in valid:
|
||||
log("Warning: Overwriting token %s" % (l[0],))
|
||||
log("Got token: %s (%s)" % (l[0], l[1]))
|
||||
valid[l[0]] = l[1]
|
||||
else:
|
||||
valid_thru = None
|
||||
except Exception:
|
||||
log(f"Could not parse valid thru date for token {token} in line {i}")
|
||||
valid_thru = None
|
||||
log(f"Got token {token} associated with {name} <{email}> of {organization}, valid thru {valid_thru}")
|
||||
if token in valid:
|
||||
log(f"Warning: Overwriting token {token}")
|
||||
valid[token] = {'name': name, 'organization': organization, 'email': email,
|
||||
'valid_thru': valid_thru}
|
||||
else:
|
||||
log(f"Skipping line {i} ({line}) since it does not contain exactly 5 data field")
|
||||
log("Got unnamed token: %s" % (l[0],))
|
||||
valid[l[0]] = None
|
||||
except:
|
||||
valid = {}
|
||||
log("Error reading token file")
|
||||
|
@ -262,20 +252,13 @@ def handle_nfc_token(token = None):
|
|||
|
||||
token = token.strip()
|
||||
if token in valid:
|
||||
data = valid[token]
|
||||
|
||||
if data['valid_thru'] is not None:
|
||||
# if a valid thru date has been set we check if the token is still valid
|
||||
authorized = datetime.date.today() <= data['valid_thru']
|
||||
name = valid[token]
|
||||
if name:
|
||||
name = "%s (%s)" % (token, name)
|
||||
else:
|
||||
# otherwise we don't need to check
|
||||
authorized = True
|
||||
|
||||
if authorized:
|
||||
log(f"Valid token {token} of {data['name']}")
|
||||
name = token
|
||||
log("Valid token: %s" % name)
|
||||
toggle_door_state()
|
||||
else:
|
||||
log(f"Token {token} of {data['name']} expired on {data['valid_thru']}")
|
||||
else:
|
||||
log("Invalid token:", token)
|
||||
mqtt("token/last_invalid", "%s;%s" % (timestamp(), token))
|
||||
|
|
Loading…
Reference in New Issue
Block a user