Stream devices to dashboard in real-time during TSCM sweep

- Emit wifi_device, bt_device, rf_signal events as devices are found
- Add frontend handlers to populate device lists in real-time
- Add RF Signals panel to TSCM dashboard
- Dashboard now updates during sweep, not just at the end
This commit is contained in:
Smittix
2026-01-14 13:43:19 +00:00
parent 0acbf87dde
commit c11c1200e2
2 changed files with 101 additions and 0 deletions

View File

@@ -904,14 +904,27 @@ def _run_sweep(
bssid = network.get('bssid', '')
if bssid and bssid not in all_wifi:
all_wifi[bssid] = network
# Emit device event for frontend
is_threat = False
# Analyze for threats
threat = detector.analyze_wifi_device(network)
if threat:
_handle_threat(threat)
threats_found += 1
is_threat = True
sev = threat.get('severity', 'low').lower()
if sev in severity_counts:
severity_counts[sev] += 1
# Send device to frontend
_emit_event('wifi_device', {
'bssid': bssid,
'ssid': network.get('essid', 'Hidden'),
'channel': network.get('channel', ''),
'signal': network.get('power', ''),
'security': network.get('privacy', ''),
'is_threat': is_threat,
'is_new': True
})
last_wifi_scan = current_time
except Exception as e:
logger.error(f"WiFi scan error: {e}")
@@ -924,14 +937,25 @@ def _run_sweep(
mac = device.get('mac', '')
if mac and mac not in all_bt:
all_bt[mac] = device
is_threat = False
# Analyze for threats
threat = detector.analyze_bt_device(device)
if threat:
_handle_threat(threat)
threats_found += 1
is_threat = True
sev = threat.get('severity', 'low').lower()
if sev in severity_counts:
severity_counts[sev] += 1
# Send device to frontend
_emit_event('bt_device', {
'mac': mac,
'name': device.get('name', 'Unknown'),
'type': device.get('type', ''),
'rssi': device.get('rssi', ''),
'is_threat': is_threat,
'is_new': True
})
last_bt_scan = current_time
except Exception as e:
logger.error(f"Bluetooth scan error: {e}")
@@ -951,14 +975,25 @@ def _run_sweep(
freq_key = f"{signal['frequency']:.3f}"
if freq_key not in [f"{s['frequency']:.3f}" for s in all_rf]:
all_rf.append(signal)
is_threat = False
# Analyze RF signal for threats
threat = detector.analyze_rf_signal(signal)
if threat:
_handle_threat(threat)
threats_found += 1
is_threat = True
sev = threat.get('severity', 'low').lower()
if sev in severity_counts:
severity_counts[sev] += 1
# Send signal to frontend
_emit_event('rf_signal', {
'frequency': signal['frequency'],
'power': signal['power'],
'band': signal['band'],
'signal_strength': signal.get('signal_strength', 0),
'is_threat': is_threat,
'is_new': True
})
last_rf_scan = current_time
except Exception as e:
logger.error(f"RF scan error: {e}")

View File

@@ -2253,6 +2253,17 @@
</div>
</div>
<!-- RF Signals Panel -->
<div class="tscm-panel">
<div class="tscm-panel-header">
RF Signals
<span class="badge" id="tscmRfCount">0</span>
</div>
<div class="tscm-panel-content" id="tscmRfList">
<div class="tscm-empty">Enable RF scanning with an SDR device</div>
</div>
</div>
<!-- Threats Panel -->
<div class="tscm-panel" style="grid-column: span 2;">
<div class="tscm-panel-header">
@@ -9770,6 +9781,7 @@
tscmThreats = [];
tscmWifiDevices = [];
tscmBtDevices = [];
tscmRfSignals = [];
updateTscmDisplays();
// Start SSE stream
@@ -9851,6 +9863,15 @@
case 'sweep_progress':
updateTscmProgress(data);
break;
case 'wifi_device':
addTscmWifiDevice(data);
break;
case 'bt_device':
addTscmBtDevice(data);
break;
case 'rf_signal':
addTscmRfSignal(data);
break;
case 'threat_detected':
addTscmThreat(data);
break;
@@ -9864,6 +9885,34 @@
}
}
function addTscmWifiDevice(device) {
// Check if already exists
const exists = tscmWifiDevices.some(d => d.bssid === device.bssid);
if (!exists) {
tscmWifiDevices.push(device);
updateTscmDisplays();
}
}
function addTscmBtDevice(device) {
// Check if already exists
const exists = tscmBtDevices.some(d => d.mac === device.mac);
if (!exists) {
tscmBtDevices.push(device);
updateTscmDisplays();
}
}
let tscmRfSignals = [];
function addTscmRfSignal(signal) {
// Check if already exists (within 0.1 MHz)
const exists = tscmRfSignals.some(s => Math.abs(s.frequency - signal.frequency) < 0.1);
if (!exists) {
tscmRfSignals.push(signal);
updateTscmDisplays();
}
}
function updateTscmProgress(data) {
// Update percentage text
document.getElementById('tscmProgressPercent').textContent = data.progress + '%';
@@ -9967,6 +10016,23 @@
}
document.getElementById('tscmBtCount').textContent = tscmBtDevices.length;
// Update RF list
const rfList = document.getElementById('tscmRfList');
if (tscmRfSignals.length === 0) {
rfList.innerHTML = '<div class="tscm-empty">No RF signals detected</div>';
} else {
rfList.innerHTML = tscmRfSignals.map(s => `
<div class="tscm-device-item ${s.is_threat ? 'threat' : (s.is_new ? 'new' : 'baseline')}">
<div class="tscm-device-name">${s.frequency.toFixed(3)} MHz</div>
<div class="tscm-device-meta">
<span>${s.band}</span>
<span>${s.power.toFixed(1)} dBm</span>
</div>
</div>
`).join('');
}
document.getElementById('tscmRfCount').textContent = tscmRfSignals.length;
// Update threats list
const threatList = document.getElementById('tscmThreatList');
if (tscmThreats.length === 0) {