diff --git a/templates/index.html b/templates/index.html index 73904a5..ba6b9ba 100644 --- a/templates/index.html +++ b/templates/index.html @@ -113,13 +113,32 @@ font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted); border-bottom: 1px solid var(--border); } - td { padding: 10px 12px; border-bottom: 1px solid rgba(45,49,72,0.5); } + td { padding: 8px 12px; border-bottom: 1px solid rgba(45,49,72,0.5); vertical-align: middle; } tr:last-child td { border-bottom: none; } - tr:hover td { background: var(--surface2); } + tr.device-row:hover td { background: var(--surface2); } .status-up { color: var(--green); font-weight: 600; } - .ping { font-family: monospace; } - .ip-cell { font-family: monospace; color: var(--accent); } - .mac-cell { font-family: monospace; font-size: 11px; color: var(--muted); } + .ip-cell { font-family: monospace; color: var(--accent); white-space: nowrap; } + + /* Port chips */ + .port-chips { display: flex; flex-wrap: wrap; gap: 4px; } + .port-chip { + font-size: 11px; font-family: monospace; font-weight: 600; + padding: 2px 7px; border-radius: 4px; + background: rgba(91,110,232,0.15); color: #a5b4fc; + border: 1px solid rgba(91,110,232,0.25); + cursor: default; white-space: nowrap; + } + .port-chip:hover { background: rgba(91,110,232,0.28); } + .port-chip title { display: none; } + .ports-scanning { + font-size: 11px; color: var(--muted); + display: flex; align-items: center; gap: 6px; + } + .spinner-sm { + display: inline-block; width: 10px; height: 10px; + border: 1.5px solid var(--border); border-top-color: var(--accent); + border-radius: 50%; animation: spin 0.7s linear infinite; flex-shrink: 0; + } /* Empty / loading states */ .empty-state { @@ -315,7 +334,7 @@ function ensureScanUI() {
LAN Devices
- +
IPHostnamePingMACVendorStatusPortsIPStatusOpen Ports
@@ -381,14 +400,10 @@ function runScan() { const tbody = document.getElementById('device-tbody'); if (isNew) { - // Insert row in sorted IP order const row = document.createElement('tr'); row.id = `row-${key}`; + row.className = 'device-row'; row.innerHTML = deviceRowHTML(d); - const portRow = document.createElement('tr'); - portRow.id = `ports-${key}`; - portRow.style.display = 'none'; - portRow.innerHTML = ''; // Insert sorted by IP const rows = tbody.querySelectorAll('tr[id^="row-"]'); @@ -396,17 +411,13 @@ function runScan() { for (const r of rows) { const rip = r.id.replace('row-','').replace(/-/g,'.'); if (ipNum(d.ip) < ipNum(rip)) { - tbody.insertBefore(portRow, r); - tbody.insertBefore(row, portRow); + tbody.insertBefore(row, r); inserted = true; break; } } - if (!inserted) { tbody.appendChild(row); tbody.appendChild(portRow); } - } else { - // Update hostname/ping if changed (don't touch ports row) - const row = document.getElementById(`row-${key}`); - if (row) row.innerHTML = deviceRowHTML(d); + if (!inserted) tbody.appendChild(row); } + // (don't touch existing rows on refresh — port data stays) const title = document.getElementById('device-card-title'); if (title) title.textContent = @@ -428,7 +439,6 @@ function runScan() { if (!seenIPs.has(ip)) { const key = ip.replace(/\./g, '-'); document.getElementById(`row-${key}`)?.remove(); - document.getElementById(`ports-${key}`)?.remove(); delete knownDevices[ip]; } } @@ -444,12 +454,11 @@ function runScan() { resetCountdown(); - // Auto port scan: queue IPs that don't have port data yet + // Auto port scan: queue IPs showing "queued" spinner (not yet scanned) const newIPs = [...seenIPs].filter(ip => { const key = ip.replace(/\./g, '-'); - const portRow = document.getElementById(`ports-${key}`); - // Only queue if not already scanned (port row still hidden = not yet done) - return portRow && portRow.style.display === 'none'; + const cell = document.getElementById(`ports-inline-${key}`); + return cell && cell.querySelector('.ports-scanning'); }); if (newIPs.length) { portScanQueue.push(...newIPs); @@ -467,16 +476,12 @@ function runScan() { } function deviceRowHTML(d) { + const key = d.ip.replace(/\./g, '-'); return ` ${escHtml(d.ip)} - ${escHtml(d.hostname)} - ${d.ping_ms != null ? d.ping_ms + ' ms' : '—'} - ${escHtml(d.mac)} - ${escHtml(d.vendor)} ● up - - + +
queued
`; } @@ -489,7 +494,6 @@ function ipNum(ip) { // ── Port scan ──────────────────────────────────────────────────────────────── function portScanManual(ip) { - // Remove from auto queue if pending, then scan immediately portScanQueue = portScanQueue.filter(q => q !== ip); portScan(ip); } @@ -499,7 +503,6 @@ async function drainPortScanQueue() { portScanRunning = true; while (portScanQueue.length > 0) { const ip = portScanQueue.shift(); - // Skip if row was removed (device disappeared) if (!document.getElementById(`row-${ip.replace(/\./g,'-')}`)) continue; await portScan(ip); } @@ -508,48 +511,31 @@ async function drainPortScanQueue() { async function portScan(ip) { const key = ip.replace(/\./g, '-'); - const row = document.getElementById(`ports-${key}`); - const btnCell = document.getElementById(`port-btn-${key}`); - if (!row) return; + const cell = document.getElementById(`ports-inline-${key}`); + if (!cell) return; - row.style.display = ''; - row.querySelector('td').innerHTML = ` -
-
Scanning ${escHtml(ip)}... -
`; - if (btnCell) btnCell.innerHTML = `scanning...`; + cell.innerHTML = `
scanning...
`; try { const r = await fetch(`/api/port-scan?ip=${encodeURIComponent(ip)}`); const d = await r.json(); if (d.error) { - row.querySelector('td').innerHTML = - `
⚠ ${escHtml(d.error)}
`; + cell.innerHTML = `⚠ ${escHtml(d.error)}`; } else { const ports = d.open_ports || []; - const os = d.os_guess || ''; - const portHtml = ports.length - ? ports.map(p => ` -
- ${p.port}/${p.proto} - ${escHtml(p.service)} -
`).join('') - : '
No common ports open
'; - row.querySelector('td').innerHTML = ` -
- ${os ? `
OS: ${escHtml(os)}
` : ''} -
Open Ports
- ${portHtml} -
`; + if (ports.length === 0) { + cell.innerHTML = `none`; + } else { + // Chips with tooltip showing service name + const chips = ports.map(p => + `${p.port}` + ).join(''); + cell.innerHTML = `
${chips}
`; + } } } catch(e) { - row.querySelector('td').innerHTML = - `
Scan failed
`; + cell.innerHTML = `failed`; } - - if (btnCell) btnCell.innerHTML = - ``; } // ── Auto-refresh ─────────────────────────────────────────────────────────────