feat: журнал попыток входа и сброс счётчика на служебной странице

This commit is contained in:
anor
2026-08-15 03:16:01 +10:00
parent a2a1da6dde
commit 8be0487c46
3 changed files with 88 additions and 2 deletions
+35 -2
View File
@@ -12,7 +12,7 @@ import express from 'express';
* Every endpoint answers 200 with { available: false, ... } when the DB is
* away: for the page that is a normal, expected state, not a server error.
*/
export function createAdminRouter({ history, getStatus }) {
export function createAdminRouter({ history, getStatus, auth = null }) {
const router = express.Router();
const toInt = (value, fallback, min, max) => {
@@ -27,7 +27,40 @@ export function createAdminRouter({ history, getStatus }) {
});
router.get('/status', (request, response) => {
response.json({ ...getStatus(), dbAvailable: history.available, dbPath: history.path });
response.json({
...getStatus(),
dbAvailable: history.available,
dbPath: history.path,
// Состояние входа: взведённый аварийный обход нельзя забыть - его должно
// быть видно, иначе панель месяцами простоит с выключенной защитой.
auth: auth
? { enabled: true, storeAvailable: auth.available }
: { enabled: false, storeAvailable: false },
});
});
/** Журнал попыток входа: по нему разбирают, кого пустили и кого остановили. */
router.get('/logins', (request, response) => {
if (!auth) {
response.json({ available: false, attempts: [] });
return;
}
response.json({ available: true, attempts: auth.recentAttempts(toInt(request.query.limit, 50, 1, 500)) });
});
/**
* Сброс счётчика попыток. Единственный запрос служебной страницы, который
* что-то меняет: блокировку панелью можно навести чужими руками, и человека
* надо уметь открыть, не дожидаясь конца паузы.
*/
router.post('/logins/reset', (request, response) => {
const login = String(request.body?.login ?? '').trim();
if (!auth || !login) {
response.status(400).json({ error: 'нужна почта, у которой сбросить счётчик' });
return;
}
auth.resetAttempts(login);
response.json({ ok: true, login });
});
router.get('/loads', (request, response) => {