(options = {})
| 4853 | if (el && t && t.beacon_ssids) el.value = t.beacon_ssids; |
| 4854 | }).catch(() => {}); |
| 4855 | // Restore the remembered scan options and keep them saved on change. |
| 4856 | const opts = _wifidefLoadOpts(); |
| 4857 | [['wifidef-deep', 'deep'], ['wifidef-hh-subghz', 'subghz']].forEach(([id, key]) => { |
| 4858 | const el = document.getElementById(id); |
| 4859 | if (!el) return; |
| 4860 | el.checked = !!opts[key]; |
| 4861 | if (!el._persist) { el._persist = true; el.addEventListener('change', _wifidefSaveOpts); } |
| 4862 | }); |
| 4863 | const auto = document.getElementById('wifidef-auto'); |
| 4864 | if (auto && !auto._wired) { |
| 4865 | auto._wired = true; |
| 4866 | auto.addEventListener('change', (e) => { |
| 4867 | if (e.target.checked) _wifidefStartContinuous(); |
| 4868 | else wifidefStopContinuous(); |
| 4869 | }); |
| 4870 | } |
| 4871 | // Resume continuous scanning if it was left running before the refresh |
| 4872 | // (wifidefScan() no-ops until the adapter list resolves, then the loop |
| 4873 | // picks up on its own). |
| 4874 | if (auto && opts.auto && !_wifidef.continuous) { |
| 4875 | auto.checked = true; |
| 4876 | _wifidefStartContinuous(); |
| 4877 | } |
| 4878 | _wifidefUpdateRunUI(); |
| 4879 | } |
| 4880 | |
| 4881 | // Continuous mode chains scans: the next capture starts only after the previous |
| 4882 | // one finishes (each capture already runs for `seconds`), instead of a fixed |
| 4883 | // interval that would stack overlapping captures. |
| 4884 | function _wifidefStartContinuous() { |
| 4885 | if (_wifidef.continuous) return; |
| 4886 | _wifidef.continuous = true; |
| 4887 | const cb = document.getElementById('wifidef-auto'); if (cb) cb.checked = true; |
| 4888 | _wifidefSaveOpts(); |
| 4889 | _wifidefUpdateRunUI(); |
| 4890 | _wifidefLoop(); |
| 4891 | } |
| 4892 | |
| 4893 | function _wifidefLoop() { |
| 4894 | if (!_wifidef.continuous) return; |
| 4895 | wifidefScan().finally(() => { |
| 4896 | if (_wifidef.continuous) _wifidef.timer = setTimeout(_wifidefLoop, 800); |
| 4897 | }); |
| 4898 | } |
| 4899 | |
| 4900 | // Printable WIDS incident report from the latest capture. |
| 4901 | function wifidefExportReport() { |
| 4902 | _openScanReport('/api/wifidef/report', _wifidef.data, |
| 4903 | 'Run a WiFi Defense scan first, then export the report.', |
| 4904 | { ai: _wifidef.ai || null }); |
| 4905 | } |
| 4906 | |
| 4907 | // One professional AI read across all three WiFi Defense modules (WIDS + |
| 4908 | // airtime + client isolation) for whatever the panel currently holds. Stashes |
| 4909 | // the result so the report can embed it. |
| 4910 | async function wifidefAnalyzeAI() { |
| 4911 | const panel = document.getElementById('wifidef-ai-panel'); |
| 4912 | const content = document.getElementById('wifidef-ai-content'); |
no test coverage detected