-
${escHtml(geo.ip || '—')}
-
${escHtml(geo.city || '—')}
-
${escHtml(geo.region || '—')}
-
${escHtml(geo.country || '—')}
-
${geo.lat ?? '—'}
-
${geo.lon ?? '—'}
-
${escHtml(geo.isp || '—')}
-
${escHtml(geo.timezone || '—')}
+
+
+
+
Connecting...
+
+
+
+
+
+
LAN Devices
+
+
+ | IP | Hostname | Ping | MAC | Vendor | Status | |
+
+
+
-
-
-
-
-
LAN Devices — ${escHtml(d.subnet || 'subnet unknown')} (${devices.length} found)
- ${hasError
- ? `
${escHtml(devices[0].error)}
`
- : devices.length === 0
- ? `
📭
No devices found on subnet ${escHtml(d.subnet || '')}
`
- : `
-
- | IP | Hostname | Ping | MAC | Vendor | Status | |
-
-
- ${devices.map(dev => `
-
- | ${escHtml(dev.ip)} |
- ${escHtml(dev.hostname)} |
- ${dev.ping_ms != null ? dev.ping_ms + ' ms' : '—'} |
- ${escHtml(dev.mac)} |
- ${escHtml(dev.vendor)} |
- ● up |
- |
-
-
- |
-
`).join('')}
-
-
`
- }
`;
+
+ let deviceCount = 0;
+ const src = new EventSource('/api/scan');
+ activeScanSource = src;
+
+ src.onmessage = (e) => {
+ const d = JSON.parse(e.data);
+
+ if (d.type === 'meta') {
+ if (!d.connected) {
+ main.innerHTML = `
🛰️
Not Connected
Select an exit node from the sidebar.
`;
+ src.close(); return;
+ }
+ // Render geo card
+ const geo = d.geo || {};
+ document.getElementById('geo-card').innerHTML = `
+
+
WAN & Location
+
+
${escHtml(geo.ip||'—')}
+
${escHtml(geo.city||'—')}
+
${escHtml(geo.region||'—')}
+
${escHtml(geo.country||'—')}
+
${escHtml(geo.isp||'—')}
+
${escHtml(geo.timezone||'—')}
+
+
`;
+ document.getElementById('scan-status').textContent = `Scanning ${d.subnet}...`;
+ document.getElementById('device-card').style.display = '';
+ document.getElementById('device-card-title').textContent = `LAN Devices — ${d.subnet} (scanning...)`;
+ }
+
+ else if (d.type === 'device') {
+ deviceCount++;
+ const tbody = document.getElementById('device-tbody');
+ const key = d.ip.replace(/\./g, '-');
+ const row = document.createElement('tr');
+ row.id = `row-${key}`;
+ row.innerHTML = `
+
${escHtml(d.ip)} |
+
${escHtml(d.hostname)} |
+
${d.ping_ms != null ? d.ping_ms + ' ms' : '—'} |
+
${escHtml(d.mac)} |
+
${escHtml(d.vendor)} |
+
● up |
+
| `;
+ tbody.appendChild(row);
+ // Expandable ports row
+ const portRow = document.createElement('tr');
+ portRow.id = `ports-${key}`;
+ portRow.style.display = 'none';
+ portRow.innerHTML = '
| ';
+ tbody.appendChild(portRow);
+ // Update title
+ const title = document.getElementById('device-card-title');
+ if (title) title.textContent = `LAN Devices — scanning... (${deviceCount} found)`;
+ }
+
+ else if (d.type === 'error') {
+ const status = document.getElementById('scan-status');
+ if (status) status.innerHTML = `
⚠ ${escHtml(d.message)}`;
+ src.close();
+ }
+
+ else if (d.type === 'done') {
+ src.close();
+ activeScanSource = null;
+ const status = document.getElementById('scan-status');
+ if (status) status.parentElement.innerHTML = `
+
+ ✓ Scan complete
+ Next in 30s
+
+
+
`;
+ const title = document.getElementById('device-card-title');
+ if (title) title.textContent = `LAN Devices — ${d.count} found`;
+ resetCountdown();
+ }
+ };
+
+ src.onerror = () => {
+ src.close();
+ activeScanSource = null;
+ const status = document.getElementById('scan-status');
+ if (status) status.innerHTML = `
Connection lost`;
+ };
}
+
+
// ── Port scan ────────────────────────────────────────────────────────────────
async function portScan(ip) {