Skip to content

Commit

Permalink
Fix access logs and visualization
Browse files Browse the repository at this point in the history
Access logs were missing a lot of access denied, which are now added and the UI was displaying only the role of the person trying the access, not the actual result.

So now we are logging the card, the role and the result of the opening.

For example a standard card could have failed because it has expired, it's disabled or it's outside of the opening hours. In all these cases we should add a line in the access logs saying that the person with the specific role had a denied access.
  • Loading branch information
matjack1 committed Apr 23, 2024
1 parent 142dc5b commit cf043b7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/log.esp
Expand Up @@ -26,12 +26,13 @@ void ICACHE_FLASH_ATTR writeEvent(String type, String src, String desc, String d
#endif
}

void ICACHE_FLASH_ATTR writeLatest(String uid, String username, int acctype)
void ICACHE_FLASH_ATTR writeLatest(String uid, String username, int acctype, int access = ACCESS_GRANTED)
{
DynamicJsonDocument root(512);
root["uid"] = uid;
root["username"] = username;
root["acctype"] = acctype;
root["access"] = access;
root["timestamp"] = epoch;
File latestlog = SPIFFS.open("/latestlog.json", "a");
serializeJson(root, latestlog);
Expand Down
2 changes: 1 addition & 1 deletion src/magicnumbers.h
Expand Up @@ -17,7 +17,7 @@

#define ACCESS_GRANTED 1
#define ACCESS_ADMIN 99
#define ACCCESS_DENIED 0
#define ACCESS_DENIED 0

// Reader defines

Expand Down
11 changes: 8 additions & 3 deletions src/rfid.esp
Expand Up @@ -426,7 +426,7 @@ void rfidProcess()
if (validUntilL < nowL || validSinceL > nowL)
{
processingState = expired;
} else if (config.openingHours[weekdayFromMonday(weekday())][hourTz] != '1')
} else if (config.openingHours[weekdayFromMonday(weekday(epoch))][hourTz] != '1')
{
processingState = notValid;
} else
Expand Down Expand Up @@ -482,6 +482,7 @@ void rfidOutsideMessaging()
#ifdef DEBUG
Serial.println(" has access relay");
#endif
writeLatest(uid, username, accountType, ACCESS_GRANTED);
if (config.numRelays == 1) {
mqttPublishAccess(epoch, "true", "Always", username, uid);
} else {
Expand All @@ -495,6 +496,7 @@ void rfidOutsideMessaging()
#ifdef DEBUG
Serial.println(" has admin access, enable wifi");
#endif
writeLatest(uid, username, accountType, ACCESS_GRANTED);
if (config.numRelays == 1) {
mqttPublishAccess(epoch, "true", "Admin", username, uid);
} else {
Expand All @@ -507,12 +509,14 @@ void rfidOutsideMessaging()
#ifdef DEBUG
Serial.println(" expired");
#endif
writeLatest(uid, username, accountType, ACCESS_DENIED);
mqttPublishAccess(epoch, "true", "Expired", username, uid);
ledAccessDeniedOn();
beeperAccessDenied();
}
if (processingState == wrongPincode)
{
writeLatest(uid, username, accountType, ACCESS_DENIED);
mqttPublishAccess(epoch, "true", "Wrong pin code", username, uid);
ledAccessDeniedOn();
beeperAccessDenied();
Expand All @@ -522,6 +526,7 @@ void rfidOutsideMessaging()
#ifdef DEBUG
Serial.println(" does not have access");
#endif
writeLatest(uid, username, accountType, ACCESS_DENIED);
mqttPublishAccess(epoch, "true", "Disabled", username, uid);
ledAccessDeniedOn();
beeperAccessDenied();
Expand All @@ -530,7 +535,7 @@ void rfidOutsideMessaging()
{
String data = String(uid) += " " + String(type);
writeEvent("WARN", "rfid", "Unknown rfid tag is scanned", data);
writeLatest(uid, "Unknown", 98);
writeLatest(uid, "Unknown", 98, ACCESS_DENIED);
DynamicJsonDocument root(512);
root["command"] = "piccscan";
root["uid"] = uid;
Expand All @@ -548,7 +553,7 @@ void rfidOutsideMessaging()
beeperAccessDenied();
} else if (uid != "" && processingState != waitingProcessing)
{
writeLatest(uid, username, accountType);
// message to the web UI to tell who has opened the door
DynamicJsonDocument root(512);
root["command"] = "piccscan";
root["uid"] = uid;
Expand Down

0 comments on commit cf043b7

Please sign in to comment.