mirror of
https://github.com/smittix/intercept.git
synced 2026-04-24 14:50:00 -07:00
Refactor timeline as reusable ActivityTimeline component
- Extract signal-timeline into configurable activity-timeline.js - Add visual modes: compact, enriched, summary - Create data adapters for RF, Bluetooth, WiFi normalization - Integrate timeline into Listening Post, Bluetooth, WiFi modes - Preserve backward compatibility for existing TSCM code - Add mode-specific configuration presets via adapters Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1233
static/js/components/activity-timeline.js
Normal file
1233
static/js/components/activity-timeline.js
Normal file
File diff suppressed because it is too large
Load Diff
288
static/js/components/timeline-adapters/bluetooth-adapter.js
Normal file
288
static/js/components/timeline-adapters/bluetooth-adapter.js
Normal file
@@ -0,0 +1,288 @@
|
||||
/**
|
||||
* Bluetooth Timeline Adapter
|
||||
* Normalizes Bluetooth device data for the Activity Timeline component
|
||||
* Used by: Bluetooth mode, TSCM (Bluetooth detections)
|
||||
*/
|
||||
|
||||
const BluetoothTimelineAdapter = (function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* RSSI to strength category mapping for Bluetooth
|
||||
* Bluetooth RSSI typically ranges from -30 (very close) to -100 (far)
|
||||
*/
|
||||
const RSSI_THRESHOLDS = {
|
||||
VERY_STRONG: -45, // 5 - device likely within 1m
|
||||
STRONG: -60, // 4 - device likely within 3m
|
||||
MODERATE: -75, // 3 - device likely within 10m
|
||||
WEAK: -90, // 2 - device at edge of range
|
||||
MINIMAL: -100 // 1 - barely detectable
|
||||
};
|
||||
|
||||
/**
|
||||
* Known device type patterns
|
||||
*/
|
||||
const DEVICE_PATTERNS = {
|
||||
// Apple devices
|
||||
AIRPODS: /airpods/i,
|
||||
IPHONE: /iphone/i,
|
||||
IPAD: /ipad/i,
|
||||
MACBOOK: /macbook|mac\s*pro|imac/i,
|
||||
APPLE_WATCH: /apple\s*watch/i,
|
||||
AIRTAG: /airtag/i,
|
||||
|
||||
// Trackers
|
||||
TILE: /tile/i,
|
||||
CHIPOLO: /chipolo/i,
|
||||
SAMSUNG_TAG: /smarttag|galaxy\s*tag/i,
|
||||
|
||||
// Audio
|
||||
HEADPHONES: /headphone|earphone|earbud|bose|sony|beats|jabra|sennheiser/i,
|
||||
SPEAKER: /speaker|soundbar|echo|homepod|sonos/i,
|
||||
|
||||
// Wearables
|
||||
FITBIT: /fitbit/i,
|
||||
GARMIN: /garmin/i,
|
||||
SMARTWATCH: /watch|band|mi\s*band|galaxy\s*fit/i,
|
||||
|
||||
// Input devices
|
||||
KEYBOARD: /keyboard/i,
|
||||
MOUSE: /mouse|trackpad|magic/i,
|
||||
CONTROLLER: /controller|gamepad|xbox|playstation|dualshock/i,
|
||||
|
||||
// Vehicles
|
||||
CAR: /car\s*kit|handsfree|obd|vehicle|toyota|honda|ford|bmw|mercedes/i
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert RSSI to strength category
|
||||
*/
|
||||
function rssiToStrength(rssi) {
|
||||
if (rssi === null || rssi === undefined) return 3;
|
||||
|
||||
const r = parseFloat(rssi);
|
||||
if (isNaN(r)) return 3;
|
||||
|
||||
if (r > RSSI_THRESHOLDS.VERY_STRONG) return 5;
|
||||
if (r > RSSI_THRESHOLDS.STRONG) return 4;
|
||||
if (r > RSSI_THRESHOLDS.MODERATE) return 3;
|
||||
if (r > RSSI_THRESHOLDS.WEAK) return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Classify device type from name
|
||||
*/
|
||||
function classifyDevice(name) {
|
||||
if (!name) return { type: 'unknown', category: 'device' };
|
||||
|
||||
for (const [pattern, regex] of Object.entries(DEVICE_PATTERNS)) {
|
||||
if (regex.test(name)) {
|
||||
return {
|
||||
type: pattern.toLowerCase(),
|
||||
category: getCategoryForType(pattern)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return { type: 'unknown', category: 'device' };
|
||||
}
|
||||
|
||||
/**
|
||||
* Get category for device type
|
||||
*/
|
||||
function getCategoryForType(type) {
|
||||
const categories = {
|
||||
AIRPODS: 'audio',
|
||||
IPHONE: 'phone',
|
||||
IPAD: 'tablet',
|
||||
MACBOOK: 'computer',
|
||||
APPLE_WATCH: 'wearable',
|
||||
AIRTAG: 'tracker',
|
||||
TILE: 'tracker',
|
||||
CHIPOLO: 'tracker',
|
||||
SAMSUNG_TAG: 'tracker',
|
||||
HEADPHONES: 'audio',
|
||||
SPEAKER: 'audio',
|
||||
FITBIT: 'wearable',
|
||||
GARMIN: 'wearable',
|
||||
SMARTWATCH: 'wearable',
|
||||
KEYBOARD: 'input',
|
||||
MOUSE: 'input',
|
||||
CONTROLLER: 'input',
|
||||
CAR: 'vehicle'
|
||||
};
|
||||
return categories[type] || 'device';
|
||||
}
|
||||
|
||||
/**
|
||||
* Format MAC address for display (truncated)
|
||||
*/
|
||||
function formatMac(mac, full = false) {
|
||||
if (!mac) return 'Unknown';
|
||||
if (full) return mac.toUpperCase();
|
||||
return mac.substring(0, 8).toUpperCase() + '...';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if device is a tracker type
|
||||
*/
|
||||
function isTracker(device) {
|
||||
if (device.is_tracker) return true;
|
||||
|
||||
const name = device.name || '';
|
||||
return /airtag|tile|chipolo|smarttag|tracker/i.test(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a Bluetooth device detection for the timeline
|
||||
*/
|
||||
function normalizeDevice(device) {
|
||||
const mac = device.mac || device.address || device.id;
|
||||
const name = device.name || device.device_name || formatMac(mac);
|
||||
const classification = classifyDevice(name);
|
||||
|
||||
const tags = [device.type || 'ble'];
|
||||
tags.push(classification.category);
|
||||
|
||||
if (isTracker(device)) tags.push('tracker');
|
||||
if (device.is_beacon) tags.push('beacon');
|
||||
if (device.is_connectable) tags.push('connectable');
|
||||
if (device.manufacturer) tags.push('identified');
|
||||
|
||||
return {
|
||||
id: mac,
|
||||
label: name,
|
||||
strength: rssiToStrength(device.rssi),
|
||||
duration: device.scan_duration || device.duration || 1000,
|
||||
type: classification.type,
|
||||
tags: tags,
|
||||
metadata: {
|
||||
mac: mac,
|
||||
rssi: device.rssi,
|
||||
device_type: device.type,
|
||||
manufacturer: device.manufacturer,
|
||||
services: device.services,
|
||||
is_tracker: isTracker(device),
|
||||
classification: classification
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize for TSCM context (includes threat assessment)
|
||||
*/
|
||||
function normalizeTscmDevice(device) {
|
||||
const normalized = normalizeDevice(device);
|
||||
|
||||
// Add TSCM-specific tags
|
||||
if (device.is_new) normalized.tags.push('new');
|
||||
if (device.threat_level) normalized.tags.push(`threat-${device.threat_level}`);
|
||||
if (device.baseline_known === false) normalized.tags.push('unknown');
|
||||
|
||||
normalized.metadata.threat_level = device.threat_level;
|
||||
normalized.metadata.first_seen = device.first_seen;
|
||||
normalized.metadata.appearance_count = device.appearance_count;
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch normalize multiple devices
|
||||
*/
|
||||
function normalizeDevices(devices, context = 'scan') {
|
||||
const normalizer = context === 'tscm' ? normalizeTscmDevice : normalizeDevice;
|
||||
return devices.map(normalizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create timeline configuration for Bluetooth mode
|
||||
*/
|
||||
function getBluetoothConfig() {
|
||||
return {
|
||||
title: 'Device Activity',
|
||||
mode: 'bluetooth',
|
||||
visualMode: 'enriched',
|
||||
collapsed: false,
|
||||
showAnnotations: true,
|
||||
showLegend: true,
|
||||
defaultWindow: '15m',
|
||||
availableWindows: ['5m', '15m', '30m', '1h'],
|
||||
filters: {
|
||||
hideBaseline: { enabled: true, label: 'Hide Known', default: false },
|
||||
showOnlyNew: { enabled: true, label: 'New Only', default: false },
|
||||
showOnlyBurst: { enabled: false, label: 'Bursts', default: false }
|
||||
},
|
||||
customFilters: [
|
||||
{
|
||||
key: 'showOnlyTrackers',
|
||||
label: 'Trackers Only',
|
||||
default: false,
|
||||
predicate: (item) => item.tags.includes('tracker')
|
||||
},
|
||||
{
|
||||
key: 'hideWearables',
|
||||
label: 'Hide Wearables',
|
||||
default: false,
|
||||
predicate: (item) => !item.tags.includes('wearable')
|
||||
}
|
||||
],
|
||||
maxItems: 75,
|
||||
maxDisplayedLanes: 12,
|
||||
labelGenerator: (id) => formatMac(id)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create compact timeline configuration (for sidebar use)
|
||||
*/
|
||||
function getCompactConfig() {
|
||||
return {
|
||||
title: 'BT Devices',
|
||||
mode: 'bluetooth',
|
||||
visualMode: 'compact',
|
||||
collapsed: false,
|
||||
showAnnotations: false,
|
||||
showLegend: false,
|
||||
defaultWindow: '15m',
|
||||
availableWindows: ['5m', '15m', '30m'],
|
||||
filters: {
|
||||
hideBaseline: { enabled: false },
|
||||
showOnlyNew: { enabled: true, label: 'New', default: false },
|
||||
showOnlyBurst: { enabled: false }
|
||||
},
|
||||
customFilters: [],
|
||||
maxItems: 30,
|
||||
maxDisplayedLanes: 8
|
||||
};
|
||||
}
|
||||
|
||||
// Public API
|
||||
return {
|
||||
// Normalization
|
||||
normalizeDevice: normalizeDevice,
|
||||
normalizeTscmDevice: normalizeTscmDevice,
|
||||
normalizeDevices: normalizeDevices,
|
||||
|
||||
// Utilities
|
||||
rssiToStrength: rssiToStrength,
|
||||
classifyDevice: classifyDevice,
|
||||
formatMac: formatMac,
|
||||
isTracker: isTracker,
|
||||
|
||||
// Configuration presets
|
||||
getBluetoothConfig: getBluetoothConfig,
|
||||
getCompactConfig: getCompactConfig,
|
||||
|
||||
// Constants
|
||||
RSSI_THRESHOLDS: RSSI_THRESHOLDS,
|
||||
DEVICE_PATTERNS: DEVICE_PATTERNS
|
||||
};
|
||||
})();
|
||||
|
||||
// Export for module systems
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = BluetoothTimelineAdapter;
|
||||
}
|
||||
|
||||
window.BluetoothTimelineAdapter = BluetoothTimelineAdapter;
|
||||
241
static/js/components/timeline-adapters/rf-adapter.js
Normal file
241
static/js/components/timeline-adapters/rf-adapter.js
Normal file
@@ -0,0 +1,241 @@
|
||||
/**
|
||||
* RF Signal Timeline Adapter
|
||||
* Normalizes RF signal data for the Activity Timeline component
|
||||
* Used by: Listening Post, TSCM
|
||||
*/
|
||||
|
||||
const RFTimelineAdapter = (function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* RSSI to strength category mapping
|
||||
* Uses confidence-safe thresholds
|
||||
*/
|
||||
const RSSI_THRESHOLDS = {
|
||||
VERY_STRONG: -40, // 5 - indicates likely nearby source
|
||||
STRONG: -55, // 4 - probable close proximity
|
||||
MODERATE: -70, // 3 - likely in proximity
|
||||
WEAK: -85, // 2 - potentially distant or obstructed
|
||||
MINIMAL: -100 // 1 - may be ambient noise or distant source
|
||||
};
|
||||
|
||||
/**
|
||||
* Frequency band categorization
|
||||
*/
|
||||
const FREQUENCY_BANDS = [
|
||||
{ min: 2400, max: 2500, label: 'Wi-Fi 2.4GHz', type: 'wifi' },
|
||||
{ min: 5150, max: 5850, label: 'Wi-Fi 5GHz', type: 'wifi' },
|
||||
{ min: 5925, max: 7125, label: 'Wi-Fi 6E', type: 'wifi' },
|
||||
{ min: 2402, max: 2480, label: 'Bluetooth', type: 'bluetooth' },
|
||||
{ min: 433, max: 434, label: '433MHz ISM', type: 'ism' },
|
||||
{ min: 868, max: 869, label: '868MHz ISM', type: 'ism' },
|
||||
{ min: 902, max: 928, label: '915MHz ISM', type: 'ism' },
|
||||
{ min: 315, max: 316, label: '315MHz', type: 'keyfob' },
|
||||
{ min: 144, max: 148, label: 'VHF Ham', type: 'amateur' },
|
||||
{ min: 420, max: 450, label: 'UHF Ham', type: 'amateur' },
|
||||
{ min: 462.5625, max: 467.7125, label: 'FRS/GMRS', type: 'personal' },
|
||||
{ min: 151, max: 159, label: 'VHF Business', type: 'commercial' },
|
||||
{ min: 450, max: 470, label: 'UHF Business', type: 'commercial' },
|
||||
{ min: 88, max: 108, label: 'FM Broadcast', type: 'broadcast' },
|
||||
{ min: 118, max: 137, label: 'Airband', type: 'aviation' },
|
||||
{ min: 156, max: 162, label: 'Marine VHF', type: 'marine' }
|
||||
];
|
||||
|
||||
/**
|
||||
* Convert RSSI (dBm) to strength category (1-5)
|
||||
*/
|
||||
function rssiToStrength(rssi) {
|
||||
if (rssi === null || rssi === undefined) return 3;
|
||||
|
||||
const r = parseFloat(rssi);
|
||||
if (isNaN(r)) return 3;
|
||||
|
||||
if (r > RSSI_THRESHOLDS.VERY_STRONG) return 5;
|
||||
if (r > RSSI_THRESHOLDS.STRONG) return 4;
|
||||
if (r > RSSI_THRESHOLDS.MODERATE) return 3;
|
||||
if (r > RSSI_THRESHOLDS.WEAK) return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Categorize frequency into human-readable band name
|
||||
*/
|
||||
function categorizeFrequency(freqMHz) {
|
||||
const f = parseFloat(freqMHz);
|
||||
if (isNaN(f)) return { label: String(freqMHz), type: 'unknown' };
|
||||
|
||||
for (const band of FREQUENCY_BANDS) {
|
||||
if (f >= band.min && f <= band.max) {
|
||||
return { label: band.label, type: band.type };
|
||||
}
|
||||
}
|
||||
|
||||
// Generic labeling by range
|
||||
if (f < 30) return { label: `${f.toFixed(3)} MHz HF`, type: 'hf' };
|
||||
if (f < 300) return { label: `${f.toFixed(3)} MHz VHF`, type: 'vhf' };
|
||||
if (f < 3000) return { label: `${f.toFixed(3)} MHz UHF`, type: 'uhf' };
|
||||
return { label: `${f.toFixed(3)} MHz`, type: 'unknown' };
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a scanner signal detection for the timeline
|
||||
*/
|
||||
function normalizeSignal(signalData) {
|
||||
const freq = signalData.frequency || signalData.freq;
|
||||
const category = categorizeFrequency(freq);
|
||||
|
||||
return {
|
||||
id: String(freq),
|
||||
label: signalData.name || category.label,
|
||||
strength: rssiToStrength(signalData.rssi || signalData.signal_strength),
|
||||
duration: signalData.duration || 1000,
|
||||
type: category.type,
|
||||
tags: buildTags(signalData, category),
|
||||
metadata: {
|
||||
frequency: freq,
|
||||
rssi: signalData.rssi,
|
||||
modulation: signalData.modulation,
|
||||
bandwidth: signalData.bandwidth
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a TSCM RF detection
|
||||
*/
|
||||
function normalizeTscmSignal(detection) {
|
||||
const freq = detection.frequency;
|
||||
const category = categorizeFrequency(freq);
|
||||
|
||||
const tags = buildTags(detection, category);
|
||||
|
||||
// Add TSCM-specific tags
|
||||
if (detection.is_new) tags.push('new');
|
||||
if (detection.baseline_deviation) tags.push('deviation');
|
||||
if (detection.threat_level) tags.push(`threat-${detection.threat_level}`);
|
||||
|
||||
return {
|
||||
id: String(freq),
|
||||
label: detection.name || category.label,
|
||||
strength: rssiToStrength(detection.rssi),
|
||||
duration: detection.duration || 1000,
|
||||
type: category.type,
|
||||
tags: tags,
|
||||
metadata: {
|
||||
frequency: freq,
|
||||
rssi: detection.rssi,
|
||||
threat_level: detection.threat_level,
|
||||
source: detection.source
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Build tags array from signal data
|
||||
*/
|
||||
function buildTags(data, category) {
|
||||
const tags = [];
|
||||
|
||||
if (category.type) tags.push(category.type);
|
||||
|
||||
if (data.modulation) {
|
||||
tags.push(data.modulation.toLowerCase());
|
||||
}
|
||||
|
||||
if (data.is_burst) tags.push('burst');
|
||||
if (data.is_continuous) tags.push('continuous');
|
||||
if (data.is_periodic) tags.push('periodic');
|
||||
|
||||
return tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch normalize multiple signals
|
||||
*/
|
||||
function normalizeSignals(signals, type = 'scanner') {
|
||||
const normalizer = type === 'tscm' ? normalizeTscmSignal : normalizeSignal;
|
||||
return signals.map(normalizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create timeline configuration for Listening Post mode
|
||||
*/
|
||||
function getListeningPostConfig() {
|
||||
return {
|
||||
title: 'Signal Activity',
|
||||
mode: 'listening-post',
|
||||
visualMode: 'enriched',
|
||||
collapsed: false,
|
||||
showAnnotations: true,
|
||||
showLegend: true,
|
||||
defaultWindow: '15m',
|
||||
availableWindows: ['5m', '15m', '30m', '1h'],
|
||||
filters: {
|
||||
hideBaseline: { enabled: true, label: 'Hide Known', default: false },
|
||||
showOnlyNew: { enabled: true, label: 'New Only', default: false },
|
||||
showOnlyBurst: { enabled: true, label: 'Bursts', default: false }
|
||||
},
|
||||
customFilters: [
|
||||
{
|
||||
key: 'hideIsm',
|
||||
label: 'Hide ISM',
|
||||
default: false,
|
||||
predicate: (item) => !item.tags.includes('ism')
|
||||
}
|
||||
],
|
||||
maxItems: 50,
|
||||
maxDisplayedLanes: 12
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create timeline configuration for TSCM mode
|
||||
*/
|
||||
function getTscmConfig() {
|
||||
return {
|
||||
title: 'Signal Activity Timeline',
|
||||
mode: 'tscm',
|
||||
visualMode: 'enriched',
|
||||
collapsed: true,
|
||||
showAnnotations: true,
|
||||
showLegend: true,
|
||||
defaultWindow: '30m',
|
||||
availableWindows: ['5m', '15m', '30m', '1h', '2h'],
|
||||
filters: {
|
||||
hideBaseline: { enabled: true, label: 'Hide Known', default: false },
|
||||
showOnlyNew: { enabled: true, label: 'New Only', default: false },
|
||||
showOnlyBurst: { enabled: true, label: 'Bursts', default: false }
|
||||
},
|
||||
customFilters: [],
|
||||
maxItems: 100,
|
||||
maxDisplayedLanes: 15
|
||||
};
|
||||
}
|
||||
|
||||
// Public API
|
||||
return {
|
||||
// Normalization
|
||||
normalizeSignal: normalizeSignal,
|
||||
normalizeTscmSignal: normalizeTscmSignal,
|
||||
normalizeSignals: normalizeSignals,
|
||||
|
||||
// Utilities
|
||||
rssiToStrength: rssiToStrength,
|
||||
categorizeFrequency: categorizeFrequency,
|
||||
|
||||
// Configuration presets
|
||||
getListeningPostConfig: getListeningPostConfig,
|
||||
getTscmConfig: getTscmConfig,
|
||||
|
||||
// Constants
|
||||
RSSI_THRESHOLDS: RSSI_THRESHOLDS,
|
||||
FREQUENCY_BANDS: FREQUENCY_BANDS
|
||||
};
|
||||
})();
|
||||
|
||||
// Export for module systems
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = RFTimelineAdapter;
|
||||
}
|
||||
|
||||
window.RFTimelineAdapter = RFTimelineAdapter;
|
||||
319
static/js/components/timeline-adapters/wifi-adapter.js
Normal file
319
static/js/components/timeline-adapters/wifi-adapter.js
Normal file
@@ -0,0 +1,319 @@
|
||||
/**
|
||||
* WiFi Timeline Adapter
|
||||
* Normalizes WiFi network data for the Activity Timeline component
|
||||
* Used by: WiFi mode, TSCM (WiFi detections)
|
||||
*/
|
||||
|
||||
const WiFiTimelineAdapter = (function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* RSSI to strength category mapping for WiFi
|
||||
*/
|
||||
const RSSI_THRESHOLDS = {
|
||||
EXCELLENT: -50, // 5 - excellent signal
|
||||
GOOD: -60, // 4 - good signal
|
||||
FAIR: -70, // 3 - fair signal
|
||||
WEAK: -80, // 2 - weak signal
|
||||
POOR: -90 // 1 - very weak
|
||||
};
|
||||
|
||||
/**
|
||||
* WiFi channel to frequency band mapping
|
||||
*/
|
||||
const CHANNEL_BANDS = {
|
||||
// 2.4 GHz (channels 1-14)
|
||||
'2.4GHz': { min: 1, max: 14 },
|
||||
// 5 GHz (channels 32-177)
|
||||
'5GHz': { min: 32, max: 177 },
|
||||
// 6 GHz (channels 1-233, WiFi 6E)
|
||||
'6GHz': { min: 1, max: 233, is6e: true }
|
||||
};
|
||||
|
||||
/**
|
||||
* Security type classifications
|
||||
*/
|
||||
const SECURITY_TYPES = {
|
||||
OPEN: 'open',
|
||||
WEP: 'wep',
|
||||
WPA: 'wpa',
|
||||
WPA2: 'wpa2',
|
||||
WPA3: 'wpa3',
|
||||
ENTERPRISE: 'enterprise'
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert RSSI to strength category
|
||||
*/
|
||||
function rssiToStrength(rssi) {
|
||||
if (rssi === null || rssi === undefined) return 3;
|
||||
|
||||
const r = parseFloat(rssi);
|
||||
if (isNaN(r)) return 3;
|
||||
|
||||
if (r > RSSI_THRESHOLDS.EXCELLENT) return 5;
|
||||
if (r > RSSI_THRESHOLDS.GOOD) return 4;
|
||||
if (r > RSSI_THRESHOLDS.FAIR) return 3;
|
||||
if (r > RSSI_THRESHOLDS.WEAK) return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine frequency band from channel
|
||||
*/
|
||||
function getBandFromChannel(channel, frequency) {
|
||||
if (frequency) {
|
||||
const f = parseFloat(frequency);
|
||||
if (f >= 5925) return '6GHz';
|
||||
if (f >= 5000) return '5GHz';
|
||||
if (f >= 2400) return '2.4GHz';
|
||||
}
|
||||
|
||||
const ch = parseInt(channel);
|
||||
if (isNaN(ch)) return 'unknown';
|
||||
|
||||
// This is simplified - in practice 6GHz also uses channels 1+
|
||||
// but typically reported with frequency
|
||||
if (ch <= 14) return '2.4GHz';
|
||||
if (ch >= 32 && ch <= 177) return '5GHz';
|
||||
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Classify security type
|
||||
*/
|
||||
function classifySecurity(network) {
|
||||
const security = (network.security || network.encryption || '').toLowerCase();
|
||||
const auth = (network.auth || '').toLowerCase();
|
||||
|
||||
if (!security || security === 'none' || security === 'open') {
|
||||
return SECURITY_TYPES.OPEN;
|
||||
}
|
||||
if (security.includes('wep')) return SECURITY_TYPES.WEP;
|
||||
if (security.includes('wpa3')) return SECURITY_TYPES.WPA3;
|
||||
if (security.includes('wpa2') || security.includes('rsn')) {
|
||||
if (auth.includes('eap') || auth.includes('802.1x') || auth.includes('enterprise')) {
|
||||
return SECURITY_TYPES.ENTERPRISE;
|
||||
}
|
||||
return SECURITY_TYPES.WPA2;
|
||||
}
|
||||
if (security.includes('wpa')) return SECURITY_TYPES.WPA;
|
||||
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate SSID for display
|
||||
*/
|
||||
function formatSsid(ssid, maxLength = 20) {
|
||||
if (!ssid) return '[Hidden]';
|
||||
if (ssid.length <= maxLength) return ssid;
|
||||
return ssid.substring(0, maxLength - 3) + '...';
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify potentially interesting network characteristics
|
||||
*/
|
||||
function identifyCharacteristics(network) {
|
||||
const characteristics = [];
|
||||
const ssid = (network.ssid || '').toLowerCase();
|
||||
|
||||
// Hidden network
|
||||
if (!network.ssid || network.is_hidden) {
|
||||
characteristics.push('hidden');
|
||||
}
|
||||
|
||||
// Open network
|
||||
if (classifySecurity(network) === SECURITY_TYPES.OPEN) {
|
||||
characteristics.push('open');
|
||||
}
|
||||
|
||||
// Weak security
|
||||
if (classifySecurity(network) === SECURITY_TYPES.WEP) {
|
||||
characteristics.push('weak-security');
|
||||
}
|
||||
|
||||
// Potential hotspot
|
||||
if (/hotspot|mobile|tether|android|iphone/i.test(ssid)) {
|
||||
characteristics.push('hotspot');
|
||||
}
|
||||
|
||||
// Guest network
|
||||
if (/guest|visitor|public/i.test(ssid)) {
|
||||
characteristics.push('guest');
|
||||
}
|
||||
|
||||
// IoT device
|
||||
if (/ring|nest|ecobee|smartthings|wyze|arlo|hue|lifx/i.test(ssid)) {
|
||||
characteristics.push('iot');
|
||||
}
|
||||
|
||||
return characteristics;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a WiFi network detection for the timeline
|
||||
*/
|
||||
function normalizeNetwork(network) {
|
||||
const ssid = network.ssid || network.essid || '';
|
||||
const bssid = network.bssid || network.mac || '';
|
||||
const band = getBandFromChannel(network.channel, network.frequency);
|
||||
const security = classifySecurity(network);
|
||||
const characteristics = identifyCharacteristics(network);
|
||||
|
||||
const tags = [band, security, ...characteristics];
|
||||
|
||||
return {
|
||||
id: bssid || ssid,
|
||||
label: formatSsid(ssid) || formatMac(bssid),
|
||||
strength: rssiToStrength(network.rssi || network.signal),
|
||||
duration: network.duration || 1000,
|
||||
type: 'wifi',
|
||||
tags: tags.filter(Boolean),
|
||||
metadata: {
|
||||
ssid: ssid,
|
||||
bssid: bssid,
|
||||
channel: network.channel,
|
||||
frequency: network.frequency,
|
||||
rssi: network.rssi || network.signal,
|
||||
security: security,
|
||||
band: band,
|
||||
characteristics: characteristics
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize for TSCM context
|
||||
*/
|
||||
function normalizeTscmNetwork(network) {
|
||||
const normalized = normalizeNetwork(network);
|
||||
|
||||
// Add TSCM-specific tags
|
||||
if (network.is_new) normalized.tags.push('new');
|
||||
if (network.threat_level) normalized.tags.push(`threat-${network.threat_level}`);
|
||||
if (network.is_rogue) normalized.tags.push('rogue');
|
||||
if (network.is_deauth_target) normalized.tags.push('targeted');
|
||||
|
||||
normalized.metadata.threat_level = network.threat_level;
|
||||
normalized.metadata.first_seen = network.first_seen;
|
||||
normalized.metadata.client_count = network.client_count;
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format MAC/BSSID for display
|
||||
*/
|
||||
function formatMac(mac) {
|
||||
if (!mac) return 'Unknown';
|
||||
return mac.toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch normalize multiple networks
|
||||
*/
|
||||
function normalizeNetworks(networks, context = 'scan') {
|
||||
const normalizer = context === 'tscm' ? normalizeTscmNetwork : normalizeNetwork;
|
||||
return networks.map(normalizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create timeline configuration for WiFi mode
|
||||
*/
|
||||
function getWiFiConfig() {
|
||||
return {
|
||||
title: 'Network Activity',
|
||||
mode: 'wifi',
|
||||
visualMode: 'enriched',
|
||||
collapsed: false,
|
||||
showAnnotations: true,
|
||||
showLegend: true,
|
||||
defaultWindow: '15m',
|
||||
availableWindows: ['5m', '15m', '30m', '1h'],
|
||||
filters: {
|
||||
hideBaseline: { enabled: true, label: 'Hide Known', default: false },
|
||||
showOnlyNew: { enabled: true, label: 'New Only', default: false },
|
||||
showOnlyBurst: { enabled: false, label: 'Bursts', default: false }
|
||||
},
|
||||
customFilters: [
|
||||
{
|
||||
key: 'showOnlyOpen',
|
||||
label: 'Open Only',
|
||||
default: false,
|
||||
predicate: (item) => item.tags.includes('open')
|
||||
},
|
||||
{
|
||||
key: 'hideHidden',
|
||||
label: 'Hide Hidden',
|
||||
default: false,
|
||||
predicate: (item) => !item.tags.includes('hidden')
|
||||
},
|
||||
{
|
||||
key: 'show5GHz',
|
||||
label: '5GHz Only',
|
||||
default: false,
|
||||
predicate: (item) => item.tags.includes('5GHz')
|
||||
}
|
||||
],
|
||||
maxItems: 100,
|
||||
maxDisplayedLanes: 15,
|
||||
labelGenerator: (id) => formatSsid(id)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create compact configuration for sidebar
|
||||
*/
|
||||
function getCompactConfig() {
|
||||
return {
|
||||
title: 'Networks',
|
||||
mode: 'wifi',
|
||||
visualMode: 'compact',
|
||||
collapsed: false,
|
||||
showAnnotations: false,
|
||||
showLegend: false,
|
||||
defaultWindow: '15m',
|
||||
availableWindows: ['5m', '15m', '30m'],
|
||||
filters: {
|
||||
hideBaseline: { enabled: false },
|
||||
showOnlyNew: { enabled: true, label: 'New', default: false },
|
||||
showOnlyBurst: { enabled: false }
|
||||
},
|
||||
customFilters: [],
|
||||
maxItems: 30,
|
||||
maxDisplayedLanes: 8
|
||||
};
|
||||
}
|
||||
|
||||
// Public API
|
||||
return {
|
||||
// Normalization
|
||||
normalizeNetwork: normalizeNetwork,
|
||||
normalizeTscmNetwork: normalizeTscmNetwork,
|
||||
normalizeNetworks: normalizeNetworks,
|
||||
|
||||
// Utilities
|
||||
rssiToStrength: rssiToStrength,
|
||||
getBandFromChannel: getBandFromChannel,
|
||||
classifySecurity: classifySecurity,
|
||||
formatSsid: formatSsid,
|
||||
identifyCharacteristics: identifyCharacteristics,
|
||||
|
||||
// Configuration presets
|
||||
getWiFiConfig: getWiFiConfig,
|
||||
getCompactConfig: getCompactConfig,
|
||||
|
||||
// Constants
|
||||
RSSI_THRESHOLDS: RSSI_THRESHOLDS,
|
||||
SECURITY_TYPES: SECURITY_TYPES
|
||||
};
|
||||
})();
|
||||
|
||||
// Export for module systems
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = WiFiTimelineAdapter;
|
||||
}
|
||||
|
||||
window.WiFiTimelineAdapter = WiFiTimelineAdapter;
|
||||
Reference in New Issue
Block a user