UI/UX mejorados 5

This commit is contained in:
2025-09-26 19:10:17 -06:00
parent 9848bd46f1
commit 0d4b0cbf67
6 changed files with 108 additions and 5 deletions

View File

@@ -176,4 +176,30 @@ router.patch('/devices/:id', async (req, res) => {
}
});
router.post('/users/:username/disconnect', async (req, res) => {
try {
const uname = String(req.params.username);
await disconnectUserSessions(uname);
res.json({ ok: true });
} catch (e) {
console.error('POST /api/users/:username/disconnect error:', e?.message || e);
res.status(500).json({ ok: false, error: 'disconnect_error' });
}
});
import { disconnectByMac } from '../services/radius.js';
router.post('/devices/:id/disconnect', async (req, res) => {
try {
const id = parseInt(String(req.params.id), 10);
if (!Number.isInteger(id) || id <= 0) return res.status(400).json({ ok: false, error: 'invalid_id' });
const r = await pool.query('SELECT mac FROM dispositivos WHERE id = $1', [id]);
if (r.rows.length === 0) return res.status(404).json({ ok: false, error: 'not_found' });
await disconnectByMac(r.rows[0].mac);
res.json({ ok: true });
} catch (e) {
console.error('POST /api/devices/:id/disconnect error:', e?.message || e);
res.status(500).json({ ok: false, error: 'disconnect_error' });
}
});
export default router;

View File

@@ -125,3 +125,49 @@ export async function disconnectUserSessions(username) {
}
}
export async function disconnectByMac(mac) {
if (!mac) return;
const targets = [];
for (const sess of activeSessions.values()) {
if (String(sess.callingStationId || '').toLowerCase() === String(mac).toLowerCase() && sess.nasIp) {
targets.push(sess);
}
}
if (targets.length === 0) return;
for (const sess of targets) {
try {
const result = await sendDisconnectRequest({
nasIp: sess.nasIp,
username: sess.username,
sessionId: sess.sessionId,
callingStationId: sess.callingStationId,
nasId: sess.nasId,
});
pushRequest({
id: Date.now() + ':' + Math.random().toString(16).slice(2),
ts: new Date().toISOString(),
type: 'coa-disconnect',
attrs: {
'User-Name': sess.username,
'NAS-IP-Address': sess.nasIp,
'Acct-Session-Id': sess.sessionId,
'Calling-Station-Id': sess.callingStationId,
'result': result.code,
},
});
} catch (e) {
pushRequest({
id: Date.now() + ':' + Math.random().toString(16).slice(2),
ts: new Date().toISOString(),
type: 'coa-disconnect',
attrs: {
'User-Name': sess.username,
'NAS-IP-Address': sess.nasIp,
'Acct-Session-Id': sess.sessionId,
'Calling-Station-Id': sess.callingStationId,
'error': String(e?.message || e),
},
});
}
}
}