97 lines
2.2 KiB
JavaScript
97 lines
2.2 KiB
JavaScript
const express = require('express');
|
|
const log = require("../logger.js");
|
|
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.use((req, res, next) => {
|
|
if (!req.session.user) return res.redirect('/login?err=4');
|
|
const perms = req.session.user.perms ? JSON.parse(req.session.user.perms) : [];
|
|
if (perms.includes('*') || perms.includes('eventLog')) {
|
|
return next();
|
|
}
|
|
return res.status(403).render('error', { error: 'Forbidden', button: { text: 'Back', action: 'back' } });
|
|
});
|
|
|
|
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, 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.close();
|
|
return;
|
|
}
|
|
if (global.checkACL(req, 'eventLog') == false) {
|
|
ws.send(JSON.stringify({ error: 'Not authorized' }))
|
|
ws.close();
|
|
return;
|
|
}
|
|
|
|
global.dbEvent.on('event', (event) => {
|
|
ws.send(JSON.stringify(event));
|
|
});
|
|
});
|
|
|
|
module.exports = router; |