-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.jsx
More file actions
executable file
·451 lines (408 loc) · 17.1 KB
/
Copy pathapp.jsx
File metadata and controls
executable file
·451 lines (408 loc) · 17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
import Router from 'preact-router';
import { useEffect, useRef, useState } from 'preact/hooks';
import { api } from './api';
import { wsAddListener, wsConnect } from './ws';
import {
addArpHost,
clearArpHosts,
getState,
setArpHosts,
setAttackRunning,
setQuickActions,
setState,
subscribe,
wardriveReset,
wardrivePatch,
antisurvReset,
antisurvPatch,
} from './store';
import { ingestWardriveLine } from './wardriveParse';
import { ToastContainer } from './components/Toast';
import { QUICK_ACTION_OPTIONS } from './quickActions';
import { Home } from './pages/Home';
import { Scan } from './pages/Scan';
import { Deauth } from './pages/Deauth';
import { EvilTwin } from './pages/EvilTwin';
import { RogueAP } from './pages/RogueAP';
import { SaeOverflow } from './pages/SaeOverflow';
import { Handshaker } from './pages/Handshaker';
import { Sniffer } from './pages/Sniffer';
import { GlobalAttacks } from './pages/GlobalAttacks';
import { SDData } from './pages/SDData';
import { Bluetooth } from './pages/Bluetooth';
import { Wardrive } from './pages/Wardrive';
import { MeshRecon } from './pages/MeshRecon';
import { WardriveUpload } from './pages/WardriveUpload';
import { GpsDiag } from './pages/GpsDiag';
import { Karma } from './pages/Karma';
import { DeauthDetector } from './pages/DeauthDetector';
import { Portal } from './pages/Portal';
import { SnifferDog } from './pages/SnifferDog';
import { BeaconSpam } from './pages/BeaconSpam';
import { SubGhz } from './pages/SubGhz';
import { SubGhzListen } from './pages/subghz/Listen';
import { SubGhzTransmit } from './pages/subghz/Transmit';
import { SubGhzManage } from './pages/subghz/Manage';
import { SubGhzJammer } from './pages/subghz/Jammer';
import { SubGhzTesla } from './pages/subghz/Tesla';
function normalizeStatus(value) {
if (!value) return 'idle';
if (value === 'scan') return 'scanning';
return value;
}
/* Device FSM states (mirrors the firmware `cmd_state_name` strings) that count
* as a foreground attack for the global Scan lock. Scanning / listing /
* wardrive / antisurv / subghz are deliberately excluded — they have their own
* UI and run flags. */
const ATTACK_RUNNING_STATES = new Set([
'deauth', 'eviltwin', 'rogueap', 'portal', 'sae', 'handshake',
'sniffer', 'blackout', 'mitm', 'nmap', 'arp', 'arp_ban', 'karma',
]);
/* Don't let the poll clear a just-armed lock during the sliver between an
* optimistic launch and the device reporting the new state. A wrongly-cleared
* lock also self-heals on the next poll (the device is really busy), so this is
* only about avoiding a cosmetic unlock→relock flicker right after Launch. */
const ATTACK_LOCK_GRACE_MS = 5000;
function WifiMetricIcon({ connected }) {
return (
<svg class={`metric-icon ${connected ? 'ok' : 'bad'}`} viewBox="0 0 24 24" aria-hidden="true">
<path d="M3 9a14.5 14.5 0 0 1 18 0" />
<path d="M6.5 12.5a9.5 9.5 0 0 1 11 0" />
<path d="M10.2 16a4.2 4.2 0 0 1 3.6 0" />
<circle cx="12" cy="19.2" r="1.2" />
</svg>
);
}
function SettingsIcon() {
return (
<svg class="metric-icon" viewBox="0 0 24 24" aria-hidden="true">
<path d="M12 8.2a3.8 3.8 0 1 1 0 7.6 3.8 3.8 0 0 1 0-7.6Z" />
<path d="m19.4 15-.9 1.6 1 2.1-2 2-2.1-1-1.7 1H10.3l-1.7-1-2.1 1-2-2 1-2.1L4.6 15V9l.9-1.6-1-2.1 2-2 2.1 1 1.7-1h3.4l1.7 1 2.1-1 2 2-1 2.1.9 1.6v6Z" />
</svg>
);
}
/* Bump this on every web change so the footer confirms which build is loaded.
* If the footer version doesn't match the latest, the browser is serving a
* cached/stale app.js (hard-refresh or open in a private tab). */
export const WEB_VERSION = '0015';
export function App() {
const [, forceUpdate] = useState(0);
const [settingsOpen, setSettingsOpen] = useState(false);
const syncStatusRef = useRef(null);
useEffect(() => {
wsConnect();
const syncStatus = async () => {
try {
const data = await api.status();
if (!data?.ok) return;
setState({
status: normalizeStatus(data.state),
scanCount: data.scan_count || 0,
packetCount: data.packet_count || 0,
c5Connected: !!data.c5_connected,
staConnected: !!data.sta_connected,
staSsid: data.sta_ssid || '',
apClients: data.ap_clients || 0,
heapFree: data.heap_free || 0,
heapInternal: data.heap_internal || 0,
});
/* Reconcile the wardrive/anti-surv run flags from the authoritative
* device state. The WS attack_started/stopped events are the fast
* path but a single dropped frame (or a page reload mid-run) would
* otherwise leave the Engine UI out of sync with the top menu. */
const s = getState();
const wdRun = data.state === 'wardrive_run';
const asRun = data.state === 'antisurv_run';
if (s.wardrive.running !== wdRun) {
if (wdRun) wardriveReset({ running: true, gps: 'waiting' });
else wardrivePatch({ running: false, gps: 'idle' });
}
if (s.antisurv.running !== asRun) antisurvPatch({ running: asRun });
/* Reconcile the global attack lock from the authoritative FSM state.
* This is what un-sticks the Scan page's "Attack running" lock after
* the Monster has gone idle while the web was disconnected (or the
* attack was stopped from the device / auto-completed). Arm on any
* attack state; clear once the device is no longer attacking, honoring
* a short grace window so a launch-time in-flight poll can't wipe the
* freshly-armed lock. */
const attackNow = ATTACK_RUNNING_STATES.has(data.state);
if (attackNow) {
if (!s.attackRunning) setAttackRunning(true);
} else if (
s.attackRunning &&
Date.now() - (s.attackRunningSince || 0) > ATTACK_LOCK_GRACE_MS
) {
setAttackRunning(false);
}
} catch (e) {
/* ignore status polling errors */
}
};
const syncDashboard = async () => {
try {
const data = await api.dashboard();
if (!data?.ok) return;
setState({
c5Connected: !!data.c5_connected,
apClients: data.ap_clients || 0,
heapFree: data.heap_free || 0,
heapInternal: data.heap_internal || 0,
handshakeCount: data.handshake_count || 0,
handshakeLoading: !!data.handshake_loading,
gpsFix: !!data.gps_fix,
gpsLat: data.gps_lat || 0,
gpsLon: data.gps_lon || 0,
sdPresent: data.sd_present ?? -1,
staConnected: !!data.sta_connected,
staSsid: data.sta_ssid || '',
});
} catch (e) {
/* ignore dashboard polling errors */
}
};
syncStatus();
syncDashboard();
/* Poll fairly briskly: /api/status just reads the cached FSM state (no
* UART round-trip), and the WS attack_stopped event is unreliable here, so
* this poll is what clears the top "Current Operation" tile after an attack
* ends. 12s felt like a ~20s lag; 3s keeps it snappy. */
syncStatusRef.current = syncStatus;
const pollStatusId = setInterval(syncStatus, 3000);
/* Refresh dashboard-only fields (handshake count, SD status, GPS) so they
* appear once the C5 link comes up, not just on the very first mount. */
const pollDashboardId = setInterval(syncDashboard, 15000);
const removeWs = wsAddListener((msg) => {
const st = getState();
if (msg.type === 'ws_connected') {
setState({ wsConnected: true });
}
if (msg.type === 'ws_disconnected') {
setState({ wsConnected: false });
}
if (msg.type === 'scan_network') {
const exists = st.networks.some((n) => n.index === msg.network.index);
if (!exists) {
const next = [...st.networks, msg.network];
setState({ networks: next, scanCount: next.length });
}
}
if (msg.type === 'scan_complete') {
setState({ status: 'idle', lastScanAt: Date.now(), scanCount: st.networks.length });
}
if (msg.type === 'attack_started') {
setState({ status: normalizeStatus(msg.attack) });
/* Fast-path arm of the global lock (the 3s poll is the safety net).
* attack_stopped intentionally does NOT clear it here — clearing is
* left to the authoritative /api/status reconcile, which avoids a
* spurious WS-stop event (or an auto-completing attack) flipping the
* Scan button back to Launch mid-session. */
if (ATTACK_RUNNING_STATES.has(msg.attack)) setAttackRunning(true);
/* Only (re)initialize if not already running. This frame can arrive
* AFTER the one-shot "GPS fix obtained" line and the first CSV rows
* (WS vs uart_line are separate transports), so blindly resetting
* would wipe the fix state + table and strand the badge on
* "Waiting for GPS fix". The optimistic startRun() already armed it. */
if (msg.attack === 'wardrive' && !st.wardrive.running) {
wardriveReset({ running: true, gps: 'waiting' });
} else if (msg.attack === 'antisurv' && !st.antisurv.running) {
antisurvReset({ running: true });
}
if (msg.attack === 'wardrive_upload') {
setState({
wardriveUploadRunning: true,
wardriveUploadProvider: msg.provider || '',
wardriveUploadResult: null,
wardriveUploadError: null,
wardriveUploadLast: '',
});
}
if (msg.attack === 'gps_raw') {
setState({ gpsRawRunning: true, gpsRawLines: [] });
}
}
if (msg.type === 'attack_stopped') {
setState({
status: 'idle',
wardriveUploadRunning: false,
gpsRawRunning: false,
});
if (st.wardrive.running) wardrivePatch({ running: false, gps: 'idle' });
if (st.antisurv.running) antisurvPatch({ running: false });
}
if (msg.type === 'gps_nmea' && typeof msg.line === 'string') {
const next = [...st.gpsRawLines, msg.line];
if (next.length > 60) next.splice(0, next.length - 60);
setState({ gpsRawRunning: true, gpsRawLines: next });
}
if (msg.type === 'wardrive_upload_done') {
setState({
status: 'idle',
wardriveUploadRunning: false,
wardriveUploadResult: {
provider: msg.provider || '',
uploaded: msg.uploaded || 0,
skipped: msg.skipped || 0,
failed: msg.failed || 0,
rateLimited: msg.rate_limited || 0,
},
wardriveUploadError: null,
});
}
if (msg.type === 'wardrive_upload_error') {
setState({
status: 'idle',
wardriveUploadRunning: false,
wardriveUploadError: msg.reason || 'error',
});
}
if (msg.type === 'uart_line' && typeof msg.data === 'string' && st.wardriveUploadRunning) {
setState({ wardriveUploadLast: msg.data });
}
if (msg.type === 'sniffer_count') {
setState({ packetCount: msg.count || 0 });
}
if (msg.type === 'wifi_connected') {
setState({ staConnected: true });
}
if (msg.type === 'wifi_disconnected' || msg.type === 'wifi_connect_failed') {
setState({ staConnected: false, staSsid: '' });
}
/* Preferred fast path: the firmware sends a single structured
* `arp_hosts` event when `list_hosts` finishes. One frame is much
* harder to lose than the original 7-line raw burst. */
if (msg.type === 'arp_hosts') {
setArpHosts(msg.hosts || [], Date.now());
}
/* Fallback: capture `list_hosts` raw lines globally in case the
* structured event got dropped (e.g. WS still re-handshaking when
* the burst arrives). The Scan ARP panel reads from
* `getState().arpHosts` regardless of which page is mounted.
* JanOS prints each host as:
* " 192.168.0.1 -> AC:22:05:84:4F:CC [ARP]"
* " 192.168.0.247 -> (MAC unknown) [ICMP]"
* We skip the ICMP-only rows because arp_ban needs a usable MAC. */
if (msg.type === 'uart_line' && typeof msg.data === 'string') {
const line = msg.data;
// Wardrive / anti-surveillance stream (CSV rows, stats, GPS, followers).
if (ingestWardriveLine(line)) return;
if (line.includes('=== Discovered Hosts ===')) {
clearArpHosts();
} else {
const m = line.match(
/^\s*([0-9]{1,3}(?:\.[0-9]{1,3}){3})\s*->\s*([0-9A-Fa-f:]{17})(?:\s+\[[^\]]+\])?\s*$/,
);
if (m) addArpHost(m[1], m[2]);
}
}
});
const removeSub = subscribe(() => forceUpdate((n) => n + 1));
return () => {
clearInterval(pollStatusId);
clearInterval(pollDashboardId);
removeWs();
removeSub();
};
}, []);
const st = getState();
const wifiLabel = st.staConnected ? (st.staSsid || 'Connected') : 'Disconnected';
function updateQuickAction(slot, value) {
const next = [...(st.quickActions || ['scan', 'blackout', 'stop'])];
next[slot] = value;
setQuickActions(next);
}
return (
<div class="app-shell">
<header class="glass-card topbar reveal">
<div class="topbar-main">
<div class="topbar-copy">
<div class="eyebrow">Dashboard</div>
<h1 class="brand-logo">JanOS</h1>
</div>
<button class="settings-btn" onClick={() => setSettingsOpen(true)} aria-label="Open settings">
<SettingsIcon />
</button>
</div>
<div class="topbar-metrics">
<div class="chip chip-graphic">
<span class={`chip-dot ${st.c5Connected ? 'ok' : 'bad'}`} />
<span class="chip-glyph">C5</span>
<span class="chip-value">{st.c5Connected ? 'Connected' : 'No Link'}</span>
</div>
<div class="chip chip-graphic">
<span class="chip-glyph">AP</span>
<span class="chip-value">{st.apClients} clients</span>
</div>
<div class="chip chip-graphic">
<span class="chip-glyph chip-glyph-icon">
<WifiMetricIcon connected={!!st.staConnected} />
</span>
<span class="chip-value">{wifiLabel}</span>
</div>
</div>
</header>
<main class="page-shell">
<Router onChange={() => { window.scrollTo(0, 0); syncStatusRef.current?.(); }}>
<Home path="/" />
<Scan path="/scan" />
<Deauth path="/deauth" />
<EvilTwin path="/eviltwin" />
<RogueAP path="/rogueap" />
<SaeOverflow path="/sae" />
<Handshaker path="/handshaker" />
<Sniffer path="/sniffer" />
<Sniffer path="/observer" />
<GlobalAttacks path="/global" />
<SDData path="/sddata" />
<Bluetooth path="/bluetooth" />
<Wardrive path="/wardrive" />
<MeshRecon path="/mesh" />
<WardriveUpload path="/wardrive/upload" />
<GpsDiag path="/gps/diag" />
<Karma path="/karma" />
<Portal path="/portal" />
<SnifferDog path="/snifferdog" />
<BeaconSpam path="/beaconspam" />
<DeauthDetector path="/detector" />
<SubGhz path="/subghz" />
<SubGhzListen path="/subghz/listen" />
<SubGhzTransmit path="/subghz/transmit" />
<SubGhzManage path="/subghz/manage" />
<SubGhzJammer path="/subghz/jammer" />
<SubGhzTesla path="/subghz/tesla" />
</Router>
</main>
{settingsOpen ? (
<div class="settings-overlay" onClick={() => setSettingsOpen(false)}>
<section class="glass-card settings-panel" onClick={(e) => e.stopPropagation()}>
<div class="section-head">
<h3 class="section-title">Settings</h3>
<button class="soft-btn" onClick={() => setSettingsOpen(false)}>Close</button>
</div>
<div class="field">
<label class="field-label">Quick Action #1</label>
<select class="select" value={st.quickActions?.[0] || 'scan'} onChange={(e) => updateQuickAction(0, e.target.value)}>
{QUICK_ACTION_OPTIONS.map((opt) => <option key={opt.id} value={opt.id}>{opt.label}</option>)}
</select>
</div>
<div class="field">
<label class="field-label">Quick Action #2</label>
<select class="select" value={st.quickActions?.[1] || 'blackout'} onChange={(e) => updateQuickAction(1, e.target.value)}>
{QUICK_ACTION_OPTIONS.map((opt) => <option key={opt.id} value={opt.id}>{opt.label}</option>)}
</select>
</div>
<div class="field">
<label class="field-label">Quick Action #3</label>
<select class="select" value={st.quickActions?.[2] || 'stop'} onChange={(e) => updateQuickAction(2, e.target.value)}>
{QUICK_ACTION_OPTIONS.map((opt) => <option key={opt.id} value={opt.id}>{opt.label}</option>)}
</select>
</div>
</section>
</div>
) : null}
<footer class="app-version">
JanOS Web <span>v{WEB_VERSION}</span>
</footer>
<ToastContainer />
</div>
);
}