diff --git a/routes/acl.js b/routes/acl.js index 1b970ec..a29278d 100644 --- a/routes/acl.js +++ b/routes/acl.js @@ -179,9 +179,22 @@ router.get('/delete/:cardNumber', async (req, res) => { // Delete ACL entry. Fai }); router.get('/bulk-add', async (req, res) => { // Render form to bulk add ACL entries - res.render('acl-bulk-add', { user: req.session.user }); + doorList = {} + await db.query('SHOW COLUMNS FROM ACL;').then(columns => { + columns.forEach(col => { + if (col.Field !== 'Name' && col.Field !== 'CardNumber' && col.Field !== 'PIN' && col.Field !== 'StartDate' && col.Field !== 'EndDate') { + doorList[col.Field] = false; + } + }); + }).catch(err => { + log.error(`Database error fetching ACL columns: ${err}`); + return {}; + }); + res.render('acl-bulk-add', { user: req.session.user, doorList }); }); + + router.post('/bulk-add', async (req, res) => { // Process bulk add of ACL entries const data = req.body; if (!Array.isArray(data)) { @@ -230,4 +243,18 @@ router.post('/bulk-add', async (req, res) => { // Process bulk add of ACL entrie return res.status(200).json({ results }); }); +router.ws("/bulk-add", (ws, req) => { + log.debug(`Client ${req.sessionID} connected to ACL bulk add WebSocket`); + if (!req.session.user) { + ws.send(JSON.stringify({ error: 'Not authenticated' })) + ws.close(); + return; + } + + global.dbEvent.on('event', (event) => { + if (event.EventType != 1 || event.Granted != 0) return; // Only process 'Swipe' events that were denied + ws.send(JSON.stringify(event)); + }); +}); + module.exports = router; \ No newline at end of file