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>
This commit is contained in:
+94
-74
@@ -5,113 +5,133 @@
|
||||
<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; }
|
||||
: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; }
|
||||
h1 { font-size: 24px; margin-bottom: 4px; }
|
||||
.subtitle { color: var(--dim); font-size: 14px; margin-bottom: 24px; }
|
||||
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 16px; }
|
||||
.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); }
|
||||
.online { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green); margin-right: 4px; }
|
||||
.offline { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--red); margin-right: 4px; }
|
||||
.row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
|
||||
.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); }
|
||||
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
|
||||
.metric { text-align: center; padding: 8px; background: rgba(255,255,255,0.03); border-radius: 6px; }
|
||||
.metric .val { font-size: 20px; font-weight: 700; }
|
||||
.metric .lbl { font-size: 10px; color: var(--dim); text-transform: uppercase; margin-top: 2px; }
|
||||
.score-bar { height: 4px; border-radius: 2px; margin-top: 4px; transition: width 0.5s; }
|
||||
.score-high { background: var(--green); }
|
||||
.score-mid { background: var(--amber); }
|
||||
.score-low { background: var(--red); }
|
||||
.wan-row { display: flex; gap: 8px; margin-top: 8px; }
|
||||
.wan-box { flex: 1; padding: 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; }
|
||||
.wan-box.active { border-color: var(--green); }
|
||||
.wan-box .wan-name { font-weight: 600; margin-bottom: 4px; }
|
||||
.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; }
|
||||
.empty { color: var(--dim); text-align: center; padding: 40px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Pioneer Bus Fleet</h1>
|
||||
<div class="subtitle">Single-pane console — GL-XE3000 + Synology RT2600ac routers</div>
|
||||
<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">Last updated: --</div>
|
||||
<div class="refresh" id="refresh">Loading…</div>
|
||||
|
||||
<script>
|
||||
const HUB = 'http://167.172.237.162:8080';
|
||||
var HUB = window.location.origin;
|
||||
|
||||
async function loadFleet() {
|
||||
try {
|
||||
const resp = await fetch(`${HUB}/api/status`);
|
||||
const data = await resp.json();
|
||||
renderFleet(data.devices || []);
|
||||
} catch(e) {
|
||||
document.getElementById('fleet').innerHTML = '<div class="empty">Hub unreachable — fleet console offline</div>';
|
||||
}
|
||||
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 renderFleet(devices) {
|
||||
const el = document.getElementById('fleet');
|
||||
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 reporting yet</div>';
|
||||
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(d => {
|
||||
const platform = d.platform || 'openwrt';
|
||||
const badge = platform === 'synology'
|
||||
|
||||
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>';
|
||||
const online = d.last_seen && (Date.now()/1000 - d.timestamp) < 120
|
||||
? '<span class="online"></span>Online'
|
||||
: '<span class="offline"></span>Offline';
|
||||
var status = d.tunnel_up
|
||||
? '<span><span class="dot dot-up"></span>ONLINE</span>'
|
||||
: '<span><span class="dot dot-down"></span>OFFLINE</span>';
|
||||
|
||||
const w1 = (d.wan && d.wan.wan1) || {};
|
||||
const w2 = (d.wan && d.wan.wan2) || {};
|
||||
var ssh = 'ssh -p ' + d.tunnel_port + ' kitadmin@' + data.hub;
|
||||
var web = d.dashboard_url;
|
||||
|
||||
return `
|
||||
<div class="card">
|
||||
<h2>${d.device_id} ${badge} <span>${online}</span></h2>
|
||||
<div class="row"><span class="label">Uptime</span><span>${fmtUptime(d.uptime)}</span></div>
|
||||
<div class="row"><span class="label">Active WAN</span><span>${d.sel_primary || '--'}</span></div>
|
||||
${d.gps && d.gps.fix ? `
|
||||
<div class="row"><span class="label">GPS</span><span>${d.gps.lat}, ${d.gps.lon}</span></div>
|
||||
` : ''}
|
||||
<div class="wan-row">
|
||||
<div class="wan-box ${d.sel_primary === 'wan1' ? 'active' : ''}">
|
||||
<div class="wan-name">WAN1</div>
|
||||
<div>Score: ${w1.score || '--'} | Lat: ${w1.latency_ms || '--'}ms</div>
|
||||
${w1.rsrp_dbm ? `<div>RSRP: ${w1.rsrp_dbm} dBm</div>` : ''}
|
||||
</div>
|
||||
<div class="wan-box ${d.sel_primary === 'wan2' ? 'active' : ''}">
|
||||
<div class="wan-name">WAN2</div>
|
||||
<div>Score: ${w2.score || '--'} | Lat: ${w2.latency_ms || '--'}ms</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="metric-grid">
|
||||
<div class="metric"><div class="val">${w1.score || 0}</div><div class="lbl">WAN1 Score</div></div>
|
||||
<div class="metric"><div class="val">${w2.score || 0}</div><div class="lbl">WAN2 Score</div></div>
|
||||
<div class="metric"><div class="val">${d.sim_slot || '--'}</div><div class="lbl">SIM Slot</div></div>
|
||||
</div>
|
||||
</div>`;
|
||||
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 fmtUptime(s) {
|
||||
if (!s) return '--';
|
||||
const h = Math.floor(s/3600), m = Math.floor((s%3600)/60);
|
||||
return h > 24 ? `${Math.floor(h/24)}d ${h%24}h` : `${h}h ${m}m`;
|
||||
function esc(s) { return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); }
|
||||
|
||||
function copySSH(cmd) {
|
||||
navigator.clipboard.writeText(cmd).then(function() {
|
||||
alert('Copied: ' + cmd);
|
||||
}).catch(function() {
|
||||
prompt('Copy this command:', cmd);
|
||||
});
|
||||
}
|
||||
|
||||
loadFleet();
|
||||
setInterval(loadFleet, 10000);
|
||||
setInterval(loadFleet, 15000);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user