feat(keamanan): security watchdog brute-force + soundbox TTS (port upstream)

- securityWatchdogService: deteksi brute force login admin/kasir/teknisi/kolektor & log MikroTik, blokir IP 15 menit, alert suara + WA/Telegram
- soundboxService + voiceTtsService (TTS Google Translate, cache)
- hook login admin/teknisi/kolektor, hook soundbox saat invoice lunas
- route /admin/api/soundbox/poll dan /test
This commit is contained in:
oxpoe
2026-11-05 01:27:33 +07:00
parent 95fa69e968
commit 1c40e6a0e8
7 changed files with 742 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
const express = require('express');
const router = express.Router();
const techSvc = require('../services/techService');
const securityWatchdog = require('../services/securityWatchdogService');
const customerSvc = require('../services/customerService');
const odpSvc = require('../services/odpService');
const { getSetting, getNowLocal, getCurrentDateInTimezone, getNowLocalISO, formatDateLocal, getSettings, formatTimeLocal, parseDateInTimezone } = require('../config/settingsManager');
@@ -140,15 +141,32 @@ router.get('/login', (req, res) => {
res.render('tech/login', { title: 'Teknisi Login', company: company(), error: null });
});
router.post('/login', loginRateLimiter, express.urlencoded({ extended: true }), (req, res) => {
router.post('/login', loginRateLimiter, express.urlencoded({ extended: true }), async (req, res) => {
const ip = req.ip || req.connection?.remoteAddress || '127.0.0.1';
if (securityWatchdog.isIpBlocked(ip)) {
return res.render('tech/login', {
title: 'Teknisi Login',
company: company(),
error: 'Akses login diblokir sementara karena terlalu banyak percobaan gagal. Coba lagi nanti.'
});
}
const { username, password } = req.body;
const tech = techSvc.authenticate(username, password);
if (tech) {
await securityWatchdog.recordAppLoginAttempt({ type: 'technician', username, ip, success: true });
req.session.isTechnician = true;
req.session.techId = tech.id;
req.session.techName = tech.name;
return res.redirect('/tech');
}
await securityWatchdog.recordAppLoginAttempt({
type: 'technician',
username: username || '',
ip,
success: false,
userAgent: req.get('user-agent')
});
res.render('tech/login', { title: 'Teknisi Login', company: company(), error: 'Username atau password salah!' });
});