(normalized)
| 4615 | if (e && e.name === 'AbortError') { st.textContent = 'Stopped.'; return; } |
| 4616 | st.textContent = 'Scan failed'; |
| 4617 | }).finally(() => { |
| 4618 | prog.done(); |
| 4619 | if (_wifidef.abort === ctrl) _wifidef.abort = null; |
| 4620 | if (btn) btn.disabled = false; |
| 4621 | }); |
| 4622 | } |
| 4623 | |
| 4624 | function wifidefTrust() { |
| 4625 | const st = document.getElementById('wifidef-status'); |
| 4626 | // Prefer trusting exactly what the last scan showed (accumulates into the |
| 4627 | // baseline, no separate capture that would see a different set of BSSIDs). |
| 4628 | const aps = (_wifidef.data && _wifidef.data.aps) || []; |
| 4629 | let body, prog = { done: () => {} }; |
| 4630 | if (aps.length) { |
| 4631 | st.textContent = `Trusting ${aps.length} shown AP(s)…`; |
| 4632 | body = { aps: aps.map(a => ({ ssid: a.ssid, bssid: a.bssid })) }; |
| 4633 | } else { |
| 4634 | const iface = _wifidef.iface || document.getElementById('wifidef-iface').value; |
| 4635 | if (!iface) { st.textContent = 'Run a scan first, then Trust.'; return; } |
| 4636 | prog = _wifidefProgress(st, 20, 'Learning trusted APs'); |
| 4637 | body = { interface: iface, seconds: 20 }; |
| 4638 | } |
| 4639 | fetch('/api/wifidef/baseline', { method: 'POST', headers: { 'Content-Type': 'application/json' }, |
| 4640 | body: JSON.stringify(body) }) |
| 4641 | .then(r => r.json()).then(d => { |
| 4642 | prog.done(); |
| 4643 | st.textContent = d.error ? ('⚠ ' + d.error) |
| 4644 | : (`✓ Trusted — baseline now covers ${d.ssids} SSID(s)` + (d.added ? ` (+${d.added} added)` : '') + '. Hit Scan to re-check.'); |
| 4645 | }).catch(() => { prog.done(); st.textContent = 'Baseline failed'; }); |
| 4646 | } |
| 4647 | |
| 4648 | function wifidefSetThreshold() { |
| 4649 | const el = document.getElementById('wifidef-flood-ssids'); |
| 4650 | const st = document.getElementById('wifidef-status'); |
| 4651 | const v = parseInt(el.value); |
| 4652 | if (!v || v < 10) return; |
| 4653 | fetch('/api/wifidef/thresholds', { method: 'POST', headers: { 'Content-Type': 'application/json' }, |
| 4654 | body: JSON.stringify({ beacon_ssids: v }) }) |
| 4655 | .then(r => r.json()).then(t => { |
| 4656 | if (t && t.beacon_ssids) el.value = t.beacon_ssids; |
| 4657 | if (st) st.textContent = `Beacon-flood threshold = ${t.beacon_ssids} SSIDs (applies on next scan)`; |
| 4658 | }).catch(() => {}); |
no test coverage detected