summaryrefslogtreecommitdiff
path: root/web/static
diff options
context:
space:
mode:
Diffstat (limited to 'web/static')
-rw-r--r--web/static/catalog.html14
-rw-r--r--web/static/catalog.js56
2 files changed, 70 insertions, 0 deletions
diff --git a/web/static/catalog.html b/web/static/catalog.html
new file mode 100644
index 0000000..2160612
--- /dev/null
+++ b/web/static/catalog.html
@@ -0,0 +1,14 @@
+<!doctype html>
+<html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
+<title>9web · local sites</title>
+<style>
+:root{color-scheme:light dark;font:16px/1.5 system-ui;background:#151917;color:#e3e9df}body{max-width:1100px;margin:3rem auto;padding:0 1.5rem}h1{font-size:2.5rem;margin-bottom:0}a{color:#b8dfa6}header p{color:#aab8a6}.sites{display:grid;grid-template-columns:repeat(auto-fit,minmax(290px,1fr));gap:1rem}article{background:#212922;border:1px solid #3c4b3c;border-radius:10px;padding:1.2rem}article h2{margin:0 0 .6rem;font-size:1.3rem}code,pre{font:13px/1.5 monospace;overflow-wrap:anywhere}button{background:#324631;color:inherit;border:1px solid #61765a;border-radius:5px;padding:.4rem .7rem;cursor:pointer;margin:.4rem .3rem .1rem 0}button:disabled{opacity:.4}table{width:100%;border-collapse:collapse}td,th{text-align:left;border-bottom:1px solid #354234;padding:.6rem;overflow-wrap:anywhere}th{color:#aab8a6}pre{max-height:35rem;overflow:auto;background:#101410;padding:1rem;white-space:pre-wrap}small{color:#aab8a6}.error{color:#ffb4a9}.toolbar{display:flex;gap:1rem;align-items:center}dialog{width:min(850px,85vw);background:#212922;color:inherit;border:1px solid #61765a}#message{min-height:1.5em}details{margin-top:1.5rem}@media(max-width:650px){td,th{padding:.4rem;font-size:13px}.process{display:none}}
+</style>
+<header><h1>9web</h1><p>Local sites, builds, and listening services.</p></header>
+<p id="message" role="status"></p><main><div id="sites" class="sites"></div>
+<div class="toolbar"><h2>HTTP services</h2><a href="/fs/">9P tree</a></div>
+<p><small>Identified from socket ownership and process arguments. No endpoint probing. Loopback links work only on this computer.</small></p>
+<table><thead><tr><th>Service</th><th>Address</th><th class="process">Process</th><th>Evidence</th></tr></thead><tbody id="services"></tbody></table>
+<details><summary id="unknown-title">Other listeners</summary><table><tbody id="unknown"></tbody></table></details></main>
+<dialog id="logs"><button id="close-log">Close</button><h2 id="log-title"></h2><pre id="log-text"></pre></dialog>
+<script src="/_cloud9/catalog.js"></script></html>
diff --git a/web/static/catalog.js b/web/static/catalog.js
new file mode 100644
index 0000000..f868a16
--- /dev/null
+++ b/web/static/catalog.js
@@ -0,0 +1,56 @@
+const $ = id => document.getElementById(id);
+let activeLog = null;
+const element = (tag, text) => { const e = document.createElement(tag); e.textContent = text; return e; };
+function url(address, port, protocol = 'http') {
+ let host = address;
+ if (!host || host === '0.0.0.0' || host === '::') host = location.hostname;
+ host = host.replace(/^\[|\]$/g, '');
+ return `${protocol}://${host.includes(':') ? `[${host}]` : host}:${port}/`;
+}
+async function control(name, command) {
+ try {
+ const r = await fetch(`/_cloud9/sites/${encodeURIComponent(name)}/ctl`, { method:'POST', headers:{'Content-Type':'text/plain'}, body:command });
+ if (!r.ok) throw new Error(await r.text());
+ $('message').textContent = `${name}: ${command} requested`;
+ await refresh();
+ } catch (e) { $('message').textContent = e.message; }
+}
+function button(text, action, disabled = false) { const b = element('button', text); b.disabled = disabled; b.onclick = action; return b; }
+function listenerRow(item) {
+ const tr = element('tr', '');
+ const name = element('td', '');
+ if (item.protocol !== 'unknown') {
+ const a = element('a', item.service); a.href = url(item.address, item.port, item.protocol); name.append(a);
+ } else name.textContent = item.process || 'Unknown';
+ tr.append(name, element('td', `${item.address}:${item.port}${item.local ? ' · local only' : ''}`));
+ const process = element('td', item.pid ? `PID ${item.pid}` : 'Unavailable'); process.className = 'process'; tr.append(process, element('td', item.evidence));
+ return tr;
+}
+async function refresh() {
+ try {
+ const r = await fetch('/_cloud9/catalog.json'); if (!r.ok) throw new Error(`Dashboard: ${r.status}`);
+ const data = await r.json();
+ $('sites').replaceChildren();
+ for (const site of data.sites) {
+ const card = element('article', ''); const h = element('h2', ''); const a = element('a', site.title); a.href = url('', site.port); h.append(a);
+ const s = site.status;
+ card.append(h, element('code', site.root), element('p', `${s.phase}${s.watching ? ' · watch on' : ''}${s.queued ? ' · build queued' : ''}${s.exit_code !== null ? ` · exit ${s.exit_code}` : ''}`));
+ if (s.finished) card.append(element('small', `Last finished ${new Date(s.finished * 1000).toLocaleString()}`), element('br', ''));
+ card.append(button('Build', () => control(site.name, 'build'), !site.build), button(s.watching ? 'Stop watching' : 'Watch', () => control(site.name, s.watching ? 'watch off' : 'watch on'), !site.watch), button('Cancel', () => control(site.name, 'cancel'), !s.pid && !s.queued), button('Log', () => { activeLog = site.name; $('log-title').textContent = site.title; $('logs').showModal(); refreshLog(); }));
+ $('sites').append(card);
+ }
+ const known = data.listeners.filter(x => x.protocol !== 'unknown');
+ const unknown = data.listeners.filter(x => x.protocol === 'unknown');
+ $('services').replaceChildren(...known.map(listenerRow));
+ $('unknown').replaceChildren(...unknown.map(listenerRow));
+ $('unknown-title').textContent = `Other listeners (${unknown.length})`;
+ if (data.discovery_error) $('message').textContent = data.discovery_error;
+ } catch (e) { $('message').textContent = e.message; }
+}
+async function refreshLog() {
+ if (!activeLog) return;
+ try { const r = await fetch(`/fs/sites/${encodeURIComponent(activeLog)}/log`); $('log-text').textContent = await r.text(); } catch (e) { $('log-text').textContent = e.message; }
+}
+$('close-log').onclick = () => { activeLog = null; $('logs').close(); };
+$('logs').onclose = () => { activeLog = null; };
+refresh(); setInterval(refresh, 5000); setInterval(refreshLog, 1500);