(force)
| 2004 | const ifs = (d && d.interfaces) || []; |
| 2005 | if (!ifs.length) { sel.innerHTML = '<option value="">No wireless interface</option>'; return; } |
| 2006 | // Order the survey radios. A passive survey needs a MANAGED radio, so a |
| 2007 | // monitor VIF (e.g. ragmon0, held by WiFi Defense) must never be the |
| 2008 | // default — it sinks to the bottom. Among managed radios: wlan1 is the |
| 2009 | // preferred primary, then wlan0, then any other radio by band count |
| 2010 | // (keeps the Alfa 6E auto-pick), then name. |
| 2011 | const _ifaceRank = i => (i.type === 'monitor') ? 900 |
| 2012 | : i.iface === 'wlan1' ? 0 |
| 2013 | : i.iface === 'wlan0' ? 1 : 10; |
| 2014 | ifs.sort((a, b) => _ifaceRank(a) - _ifaceRank(b) |
| 2015 | || (b.bands || []).length - (a.bands || []).length |
| 2016 | || String(a.iface).localeCompare(String(b.iface))); |
| 2017 | sel.innerHTML = ifs.map(i => |
| 2018 | `<option value="${i.iface}">${i.iface} (${(i.bands || []).join('/') || '?'} GHz)${i.type === 'monitor' ? ' — monitor' : ''}</option>`).join(''); |
| 2019 | if (!_wifiState.iface || !ifs.some(i => i.iface === _wifiState.iface)) _wifiState.iface = ifs[0].iface; |
| 2020 | sel.value = _wifiState.iface; |
| 2021 | sel.onchange = () => { _wifiState.iface = sel.value; wifiScan(); }; |
| 2022 | if (!_wifiState.data) wifiScan(); |
| 2023 | }).catch(() => {}); |
| 2024 | } |
| 2025 | |
| 2026 | function wifiScan() { |
| 2027 | const iface = _wifiState.iface || document.getElementById('wifi-iface').value; |
| 2028 | if (!iface) return; |
| 2029 | const btn = document.getElementById('wifi-scan-btn'); |
| 2030 | const fsBtn = document.getElementById('wifi-fs-scan'); |
| 2031 | const busy = (on) => { if (btn) btn.disabled = on; if (fsBtn) fsBtn.disabled = on; }; |
| 2032 | _wifiSetStatus('Scanning (passive)…'); busy(true); |
| 2033 | fetch(`/api/net/wifi/scan?interface=${encodeURIComponent(iface)}&band=${_wifiState.band}`) |
| 2034 | .then(r => r.json()).then(d => { |
| 2035 | busy(false); |
| 2036 | if (d.error) { _wifiState.scanError = d.error; _wifiSetStatus('⚠ ' + d.error); _wifiFlagBanner(); return; } |
| 2037 | _wifiState.scanError = null; |
| 2038 | _wifiState.data = d; |
| 2039 | // A fresh scan invalidates any earlier AI read, so it isn't embedded |
nothing calls this directly
no test coverage detected