diff --git a/routes/tscm.py b/routes/tscm.py index 3ed3ffb..bca41ff 100644 --- a/routes/tscm.py +++ b/routes/tscm.py @@ -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}") diff --git a/templates/index.html b/templates/index.html index bdb2771..186d1fb 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2253,6 +2253,17 @@ + +
+
+ RF Signals + 0 +
+
+
Enable RF scanning with an SDR device
+
+
+
@@ -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 = '
No RF signals detected
'; + } else { + rfList.innerHTML = tscmRfSignals.map(s => ` +
+
${s.frequency.toFixed(3)} MHz
+
+ ${s.band} + ${s.power.toFixed(1)} dBm +
+
+ `).join(''); + } + document.getElementById('tscmRfCount').textContent = tscmRfSignals.length; + // Update threats list const threatList = document.getElementById('tscmThreatList'); if (tscmThreats.length === 0) {