Fix SSE reconnect storm and document node dropout findings

- Fix stale EventSource accumulation: onerror handler now closes the
  existing EventSource before creating a new one, preventing multiple
  live instances from stacking up and flooding /api/nodes on reconnect.
- Add in-flight guard on /api/nodes fetch so concurrent requests are
  dropped if one is already in progress.
- Add dominant reason code column to Alerts tab (Most Impersonated
  Networks and Most Targeted Devices tables) and Sessions tab rows.
- README: document node dropout root cause (AP overwhelm on staggered
  power cycle), overnight stability confirmation, and dedicated AP todo.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
bot
2026-04-07 09:51:46 +03:00
parent 36c7248d0e
commit 7f702133cc
2 changed files with 51 additions and 10 deletions
+37 -10
View File
@@ -34,6 +34,13 @@ function impBadge(imp) {
return `<span class="imp-${cls}">${fmt(imp)}</span>`;
}
function reasonCell(code, desc, cls) {
if (code == null) return '<span class="muted">—</span>';
const color = cls === 'attack' ? '#e74c3c' : cls === 'suspicious' ? '#e67e22' : 'var(--text-muted)';
return `<span style="color:${color};font-weight:${cls === 'attack' ? 500 : 400}">${code}</span>`
+ `<span class="muted" style="font-size:10px;margin-left:4px">${desc || ''}</span>`;
}
function encClass(enc) {
if (!enc || enc === 'OPEN' || enc === 'None') return 'enc-open';
if (enc === 'WPA3' || enc === 'WPA2/WPA3') return 'enc-secure';
@@ -652,6 +659,7 @@ function renderSessionsView() {
<td>${s.unique_targets.length}</td>
<td>${s.node_count}</td>
<td>${s.peak_rssi != null ? s.peak_rssi + ' dBm' : '—'}</td>
<td>${reasonCell(s.dominant_reason, s.dominant_reason_desc, s.dominant_reason_class)}</td>
<td><span class="sev-label ${sevClass}">${s.severity}</span></td>
`;
tbody.appendChild(mainRow);
@@ -683,14 +691,14 @@ function renderSessionsView() {
: '';
detailRow.innerHTML = `
<td colspan="11" class="session-detail-cell">
<td colspan="12" class="session-detail-cell">
<div class="session-detail-inner">
<div class="session-meta">
<span><strong>BSSIDs:</strong> ${bssidList}</span>
<span><strong>Targets:</strong> ${targetList}</span>
<span><strong>Nodes:</strong> ${nodeList}</span>
<span><strong>Avg RSSI:</strong> ${s.avg_rssi != null ? s.avg_rssi + ' dBm' : '—'}</span>
<span><strong>Reason:</strong> ${s.dominant_reason}</span>
<span><strong>Dominant Reason:</strong> ${reasonCell(s.dominant_reason, s.dominant_reason_desc, s.dominant_reason_class)}</span>
</div>
<table class="session-events-table">
<thead><tr>
@@ -791,6 +799,7 @@ function renderAlertsView() {
<td class="dim">${fmt(t.bssid)}</td>
<td>${fmt(t.ssid, '<hidden>')}</td>
<td style="color:#e74c3c;font-weight:500">${t.total_frames}</td>
<td>${reasonCell(t.dominant_reason, t.dominant_reason_desc, t.dominant_reason_class)}</td>
<td class="muted">${t.unique_srcs}</td>
<td class="${t.node_count > 1 ? 'nodes-multi' : 'muted'}">${t.node_count}</td>
<td class="dim">${shortTime(t.last_seen)}</td>
@@ -814,6 +823,7 @@ function renderAlertsView() {
<td class="dim">${fmt(d.dst)}</td>
<td class="${vendorCls}">${d.vendor || '—'}</td>
<td style="color:#e74c3c;font-weight:500">${d.total_frames}</td>
<td>${reasonCell(d.dominant_reason, d.dominant_reason_desc, d.dominant_reason_class)}</td>
<td class="muted">${d.networks_used}</td>
<td class="${d.node_count > 1 ? 'nodes-multi' : 'muted'}">${d.node_count}</td>
<td class="dim">${shortTime(d.last_seen)}</td>
@@ -1234,8 +1244,14 @@ async function init() {
}
// ── SSE ───────────────────────────────────────────────────────────────────────
let _currentES = null; // track active EventSource so we can close it on reconnect
let _nodesFetching = false; // in-flight guard — prevents concurrent /api/nodes requests
function startSSE() {
if (_currentES) { _currentES.close(); _currentES = null; }
const es = new EventSource('/api/stream');
_currentES = es;
const dot = document.getElementById('live-dot');
let sseTimer = null;
@@ -1265,18 +1281,29 @@ function startSSE() {
else if (currentView === 'alerts') await fetchAlerts();
else if (currentView === 'analysis') await showAnalysis();
const nodes = await fetch('/api/nodes').then(r => r.json());
nodeData = Object.fromEntries(nodes.map(n => [n.node_id, n]));
renderSidebar(nodes);
if (currentView === 'detail' && currentNode) {
const data = await fetch(`/api/nodes/${currentNode}`).then(r => r.json());
renderDetail(data);
if (!_nodesFetching) {
_nodesFetching = true;
try {
const nodes = await fetch('/api/nodes').then(r => r.json());
nodeData = Object.fromEntries(nodes.map(n => [n.node_id, n]));
renderSidebar(nodes);
if (currentView === 'detail' && currentNode) {
const data = await fetch(`/api/nodes/${currentNode}`).then(r => r.json());
renderDetail(data);
}
} finally {
_nodesFetching = false;
}
}
}, 2000);
};
es.onerror = () => { dot.classList.remove('alive'); setTimeout(startSSE, 3000); };
es.onerror = () => {
dot.classList.remove('alive');
es.close();
_currentES = null;
setTimeout(startSSE, 3000);
};
}
// ── Boot ──────────────────────────────────────────────────────────────────────