Test replacing those?

This commit is contained in:
Christopher Cookman 2025-08-31 23:17:08 -06:00
parent c7874c19a6
commit 7c6a99b6a6
2 changed files with 65 additions and 7 deletions

View file

@ -4,15 +4,73 @@ const db = global.db;
const router = express.Router();
const expressWs = require('express-ws')(router);
// GET /login
dataTypes = {
DoorMode: {
1: 'NormallyOpen',
2: 'NormallyClosed',
3: 'Controlled'
},
Direction: {
1: 'In',
2: 'Out'
},
EventType: {
0: 'None',
1: 'Swipe',
2: 'Door',
3: 'Alarm',
255: 'Overwritten'
},
EventReason: {
0: 'None',
1: 'Swipe',
2: 'SwipeOpen',
3: 'SwipeClose',
5: 'Denied',
6: 'NoAccessRights',
7: 'IncorrectPassword',
8: 'AntiPassback',
9: 'MoreCards',
10: 'FirstCardOpen',
11: 'DoorIsNormallyClosed',
12: 'Interlock',
13: 'NotInAllowedTimePeriod',
15: 'InvalidTimezone',
18: 'AccessDenied',
20: 'PushbuttonOk',
23: 'DoorOpened',
24: 'DoorClosed',
25: 'DoorOpenedSupervisorPassword',
28: 'ControllerPowerOn',
29: 'ControllerReset',
31: 'PushbuttonInvalidDoorLocked',
32: 'PushbuttonInvalidOffline',
33: 'PushbuttonInvalidInterlock',
34: 'PushbuttonInvalidThreat',
37: 'DoorOpenTooLong',
38: 'ForcedOpen',
39: 'Fire',
40: 'ForcedClosed',
41: 'TheftPrevention',
42: 'Zone24x7',
43: 'Emergency',
44: 'RemoteOpenDoor',
45: 'RemoteOpenDoorUSBReader'
}
}
router.get('/', async (req, res) => {
const logs = await db.query('SELECT * FROM Events ORDER BY EventIndex DESC LIMIT 100');
res.render('event-logs', { logs, user: req.session.user });
res.render('event-logs', { logs, user: req.session.user, dataTypes });
});
router.ws('/', (ws, req) => {
log.debug(`Client ${req.sessionID} connected to event logs WebSocket`);
if (!req.session.user) {
ws.send(JSON.stringify({ error: 'Not authenticated' }))
ws.send(JSON.stringify({ error: 'Not authenticated' }))
ws.close();
return;
}

View file

@ -79,7 +79,7 @@
<th>Granted</th>
<th>Door</th>
<th>Direction</th>
<th>Card Number</th>
<th>Data</th>
<th>Reason</th>
</tr>
</thead>
@ -102,12 +102,12 @@
%>
<%= `${yyyy}-${mm}-${dd} ${HH}:${MM}:${ss} ${tz}` %>
</td>
<td><%= log.Type %></td>
<td><%= log.Granted %></td>
<td><%= dataTypes.EventType[log.Type] %></td>
<td><%= log.Granted ? "True" : "False" %></td>
<td><%= log.Door %></td>
<td><%= log.Direction %></td>
<td><%= dataTypes.Direction[log.Direction] %></td>
<td><%= log.CardNumber %></td>
<td><%= log.Reason %></td>
<td><%= dataTypes.EventReason[log.Reason] %></td>
</tr>
<% }); %>
</tbody>