Files
kit-busrouter/hub/dashboard.html
T
kitadmin c8bb08ed35 feat: fleet hub dashboard + /api/fleet endpoint with direct access links
server.py:
- GET / serves dashboard.html (dark-themed fleet console)
- GET /api/fleet returns all registered devices with tunnel status,
  SSH commands, and web dashboard access instructions
- Static file serving via serve_file()

dashboard.html:
- Shows all registered devices from port-registry.json
- Live tunnel status (port-open check on VPS)
- Platform badges (Synology vs GL-XE3000)
- Copy-to-clipboard SSH commands per device
- Web dashboard access via SSH port-forwarding instructions
- Auto-refreshes every 15s

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 16:11:10 +00:00

138 lines
6.9 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pioneer Bus Fleet — Console</title>
<style>
:root { --bg: #0d1117; --card: #161b22; --border: #30363d; --text: #c9d1d9;
--dim: #8b949e; --green: #3fb950; --amber: #d29922; --red: #f85149;
--blue: #58a6ff; --accent: #2563EB; }
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: var(--bg); color: var(--text); padding: 20px; }
.header { background: linear-gradient(135deg, var(--accent), #1d4ed8);
margin: -20px -20px 20px -20px; padding: 20px 24px; }
.header h1 { font-size: 22px; margin: 0; color: #fff; }
.header h1 span { color: #93c5fd; }
.header .sub { color: #bfdbfe; font-size: 12px; letter-spacing: 1px; margin-top: 4px; }
.stats { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-card { background: var(--card); border: 1px solid var(--border);
border-radius: 8px; padding: 12px 20px; text-align: center; min-width: 100px; }
.stat-card .num { font-size: 28px; font-weight: 700; color: var(--accent); }
.stat-card .lbl { font-size: 10px; color: var(--dim); text-transform: uppercase; margin-top: 2px; }
.stat-card .num.online { color: var(--green); }
.stat-card .num.offline { color: var(--red); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.card h2 { font-size: 16px; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 12px; font-weight: 600; }
.badge-gl { background: rgba(88,166,255,0.15); color: var(--blue); }
.badge-synology { background: rgba(210,153,34,0.15); color: var(--amber); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot-up { background: var(--green); }
.dot-down { background: var(--red); }
.row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13px; border-bottom: 1px solid rgba(255,255,255,0.04); }
.row .label { color: var(--dim); }
.row .val { font-family: monospace; font-size: 12px; }
.access { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.access .title { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
.cmd { background: #0d1117; padding: 6px 10px; border-radius: 4px; font-family: monospace;
font-size: 12px; color: var(--green); margin-bottom: 4px; word-break: break-all; }
.cmd a { color: var(--blue); text-decoration: none; }
.cmd a:hover { text-decoration: underline; }
.empty { color: var(--dim); text-align: center; padding: 60px 20px; font-size: 14px; }
.refresh { color: var(--dim); font-size: 11px; text-align: right; margin-top: 20px; }
</style>
</head>
<body>
<div class="header">
<h1>PIONEER <span>BUS FLEET</span></h1>
<div class="sub">Keylink IT Fleet Connectivity Console</div>
</div>
<div class="stats" id="stats"></div>
<div class="grid" id="fleet"></div>
<div class="refresh" id="refresh">Loading…</div>
<script>
var HUB = window.location.origin;
function loadFleet() {
fetch(HUB + '/api/fleet')
.then(function(r) { return r.ok ? r.json() : Promise.reject(r.status); })
.then(function(data) { render(data); })
.catch(function(e) {
document.getElementById('fleet').innerHTML =
'<div class="empty">Hub unreachable — ' + e + '</div>';
});
document.getElementById('refresh').textContent = 'Last updated: ' + new Date().toLocaleTimeString();
}
function render(data) {
var devices = data.devices || [];
var online = devices.filter(function(d) { return d.tunnel_up; }).length;
document.getElementById('stats').innerHTML =
'<div class="stat-card"><div class="num">' + devices.length +
'</div><div class="lbl">Registered</div></div>' +
'<div class="stat-card"><div class="num online">' + online +
'</div><div class="lbl">Online</div></div>' +
'<div class="stat-card"><div class="num offline">' + (devices.length - online) +
'</div><div class="lbl">Offline</div></div>' +
'<div class="stat-card"><div class="num">' + (data.hub || '') +
'</div><div class="lbl">Hub</div></div>';
var el = document.getElementById('fleet');
if (!devices.length) {
el.innerHTML = '<div class="empty">No devices registered yet.<br><br>Install kit-connect on a router and it will appear here.</div>';
return;
}
el.innerHTML = devices.map(function(d) {
var isSynology = d.device_id.startsWith('x');
var badge = isSynology
? '<span class="badge badge-synology">Synology</span>'
: '<span class="badge badge-gl">GL-XE3000</span>';
var status = d.tunnel_up
? '<span><span class="dot dot-up"></span>ONLINE</span>'
: '<span><span class="dot dot-down"></span>OFFLINE</span>';
var ssh = 'ssh -p ' + d.tunnel_port + ' kitadmin@' + data.hub;
var web = d.dashboard_url;
return '<div class="card">' +
'<h2>' + esc(d.device_id) + ' ' + badge + ' <span style="font-size:13px">' + status + '</span></h2>' +
'<div class="row"><span class="label">Tunnel Port</span><span class="val">' + d.tunnel_port + '</span></div>' +
'<div class="row"><span class="label">Assigned</span><span class="val">' + (d.assigned || '--') + '</span></div>' +
(d.tunnel_up
? '<div class="access">' +
'<div class="title">Direct Access</div>' +
'<div class="cmd">$ <a href="#" onclick="copySSH(\'' + esc(ssh) + '\');return false">' + esc(ssh) + '</a></div>' +
(web ? '<div class="cmd">→ <a href="' + web + '" target="_blank">' + web + '</a> (direct — only works when SSH tunnel forwards HTTP)</div>' : '') +
'<div class="cmd" style="color:var(--dim);font-size:11px">' +
'For web dashboard: <code>ssh -L 8089:127.0.0.1:8089 -p ' + d.tunnel_port + ' kitadmin@' + data.hub + '</code><br>' +
'then open <a href="http://localhost:8089/">http://localhost:8089/</a></div>' +
'</div>'
: '<div class="row"><span class="label">Status</span><span class="val" style="color:var(--red)">Tunnel not connected — restart daemon on router</span></div>'
) +
'</div>';
}).join('');
}
function esc(s) { return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
function copySSH(cmd) {
navigator.clipboard.writeText(cmd).then(function() {
alert('Copied: ' + cmd);
}).catch(function() {
prompt('Copy this command:', cmd);
});
}
loadFleet();
setInterval(loadFleet, 15000);
</script>
</body>
</html>