Files
svc-proxy/internal/httpsrv/static/index.html
T
claude-timemachine f823c05aa3
CI / validate (push) Successful in 24s
CI / docker (push) Failing after 1m49s
initial: svc-proxy — UDP valve for Simple Voice Chat
Standalone Go service that routes SVC client traffic to per-server
backend voice endpoints, configured via pg LISTEN/NOTIFY (same channel
mc-router subscribes to). Each pg `servers` row with both
`voice_address` and `voice_proxy_port` set spawns a Valve: a public
UDP listener that maintains per-client ephemeral bridges to the
backend's SVC port.

Pieces:
  cmd/svc-proxy/main.go     entry; wires config, log fan-out,
                            bridge.Manager, pgsync, httpsrv
  internal/config/          DATABASE_URL + BIND_HOST +
                            BRIDGE_IDLE_TTL (default 1m) +
                            HTTP_ADDR (default :8081)
  internal/pgsync/          LISTEN automc_routes_changed; diff
                            desired/actual routes; emit Apply()
  internal/bridge/          Valve per public port; per-client
                            bridge with atomic up/down byte counters;
                            idle eviction every 15s against TTL
  internal/httpsrv/         operator UI — embedded single-page HTML
                            with active-connections table polled
                            every 1s + SSE log stream
                            (last 500 lines backlog on connect)

Reverse-proxied behind server-manager at /infra/svc-proxy/* — bind
internal-only addresses for production; auth is the dashboard's
Basic gate.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-10 18:01:04 +02:00

202 lines
7.2 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>svc-proxy</title>
<style>
:root {
--bg: #0f1115;
--panel: #161922;
--panel-2: #1c2030;
--border: #2a2f42;
--text: #d6d9e0;
--muted: #7a8194;
--accent: #6aa9ff;
--up: #4ade80;
--down: #f59e0b;
--err: #f87171;
--warn: #fbbf24;
--info: #93c5fd;
--dbg: #6b7280;
}
* { box-sizing: border-box; }
body {
margin: 0; padding: 0;
font: 13px/1.4 ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
background: var(--bg); color: var(--text);
display: grid; grid-template-rows: auto 1fr 1fr; height: 100vh;
}
header {
padding: 10px 16px;
border-bottom: 1px solid var(--border);
background: var(--panel);
display: flex; justify-content: space-between; align-items: center;
}
h1 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: 0.5px; }
h1 .meta { color: var(--muted); margin-left: 12px; font-weight: normal; }
.status { color: var(--muted); font-size: 12px; }
.status.ok { color: var(--up); }
.status.err { color: var(--err); }
section { padding: 12px 16px; overflow: auto; border-bottom: 1px solid var(--border); }
section h2 {
margin: 0 0 10px; font-size: 12px; text-transform: uppercase;
letter-spacing: 0.7px; color: var(--muted); font-weight: 600;
}
section.logs { font-size: 12.5px; }
section.logs h2 { display: flex; justify-content: space-between; align-items: center; }
section.logs h2 .clear {
background: transparent; color: var(--muted); border: 1px solid var(--border);
padding: 2px 8px; cursor: pointer; font: inherit; border-radius: 3px;
}
section.logs h2 .clear:hover { color: var(--text); border-color: var(--accent); }
table { width: 100%; border-collapse: collapse; }
th, td {
text-align: left; padding: 6px 10px;
border-bottom: 1px solid var(--border);
font-variant-numeric: tabular-nums;
}
th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
tbody tr:hover { background: var(--panel-2); }
td.num { text-align: right; }
td.up { color: var(--up); }
td.down { color: var(--down); }
td.idle.stale { color: var(--warn); }
td.idle.dead { color: var(--err); }
.empty { color: var(--muted); padding: 20px; text-align: center; }
pre.logbox {
margin: 0; white-space: pre-wrap; word-break: break-word;
max-height: 100%;
}
.log-line { padding: 1px 0; }
.log-line .ts { color: var(--muted); margin-right: 8px; }
.log-line .lvl { margin-right: 6px; font-weight: 600; }
.log-line.lvl-DEBUG .lvl { color: var(--dbg); }
.log-line.lvl-INFO .lvl { color: var(--info); }
.log-line.lvl-WARN .lvl { color: var(--warn); }
.log-line.lvl-ERROR .lvl { color: var(--err); }
.log-line .attrs { color: var(--muted); margin-left: 8px; }
</style>
</head>
<body>
<header>
<h1>svc-proxy <span class="meta" id="meta">— connecting…</span></h1>
<span class="status" id="status">log stream: connecting</span>
</header>
<section class="conns">
<h2>Active connections <span id="conn-count" style="color:var(--muted);"></span></h2>
<table>
<thead>
<tr>
<th>Server</th>
<th>Port</th>
<th>Client</th>
<th>Backend</th>
<th class="num">Up</th>
<th class="num">Down</th>
<th class="num">Idle</th>
<th class="num">Age</th>
</tr>
</thead>
<tbody id="conn-rows"></tbody>
</table>
<div id="conn-empty" class="empty">no active bridges</div>
</section>
<section class="logs">
<h2>
<span>Logs</span>
<button class="clear" onclick="document.getElementById('logbox').innerHTML=''">clear</button>
</h2>
<pre class="logbox" id="logbox"></pre>
</section>
<script>
const fmtBytes = n => {
if (n < 1024) return n + ' B';
if (n < 1024*1024) return (n/1024).toFixed(1) + ' KiB';
if (n < 1024*1024*1024) return (n/(1024*1024)).toFixed(2) + ' MiB';
return (n/(1024*1024*1024)).toFixed(2) + ' GiB';
};
const fmtAgo = secs => {
if (secs < 60) return secs.toFixed(0) + 's';
if (secs < 3600) return Math.floor(secs/60) + 'm' + Math.floor(secs%60) + 's';
const h = Math.floor(secs/3600);
const m = Math.floor((secs % 3600) / 60);
return h + 'h' + m + 'm';
};
async function refreshConnections() {
try {
const r = await fetch('/api/connections');
const j = await r.json();
const rows = document.getElementById('conn-rows');
const empty = document.getElementById('conn-empty');
const count = document.getElementById('conn-count');
rows.innerHTML = '';
const now = new Date(j.at).getTime();
if (!j.connections || j.connections.length === 0) {
empty.style.display = '';
count.textContent = '';
} else {
empty.style.display = 'none';
count.textContent = '(' + j.connections.length + ')';
for (const c of j.connections) {
const opened = new Date(c.opened_at).getTime();
const ageSecs = (now - opened) / 1000;
const idleCls = c.idle_seconds > 60 ? 'dead' : c.idle_seconds > 30 ? 'stale' : '';
const tr = document.createElement('tr');
tr.innerHTML =
'<td>' + c.server + '</td>' +
'<td>:' + c.port + '</td>' +
'<td>' + c.client + '</td>' +
'<td>' + c.backend + '</td>' +
'<td class="num up">↑ ' + fmtBytes(c.bytes_up) + '</td>' +
'<td class="num down">↓ ' + fmtBytes(c.bytes_down) + '</td>' +
'<td class="num idle ' + idleCls + '">' + fmtAgo(c.idle_seconds) + '</td>' +
'<td class="num">' + fmtAgo(ageSecs) + '</td>';
rows.appendChild(tr);
}
}
document.getElementById('meta').textContent = '— ' + j.connections.length + ' bridges';
} catch (e) {
document.getElementById('meta').textContent = '— api error';
}
}
setInterval(refreshConnections, 1000);
refreshConnections();
function startLogStream() {
const status = document.getElementById('status');
const box = document.getElementById('logbox');
const es = new EventSource('/api/logs');
es.onopen = () => { status.textContent = 'log stream: live'; status.className = 'status ok'; };
es.onerror = () => { status.textContent = 'log stream: reconnecting'; status.className = 'status err'; };
es.onmessage = ev => {
let e;
try { e = JSON.parse(ev.data); } catch { return; }
const ts = e.time ? e.time.split('T')[1].split('.')[0] : '';
const div = document.createElement('div');
div.className = 'log-line lvl-' + (e.level || 'INFO');
div.innerHTML =
'<span class="ts">' + ts + '</span>' +
'<span class="lvl">' + (e.level || 'INFO') + '</span>' +
(e.msg || '') +
(e.attrs ? '<span class="attrs">' + e.attrs + '</span>' : '');
box.appendChild(div);
// Auto-scroll if near the bottom
const parent = box.parentElement;
if (parent.scrollHeight - parent.scrollTop - parent.clientHeight < 60) {
parent.scrollTop = parent.scrollHeight;
}
while (box.children.length > 1000) box.removeChild(box.firstChild);
};
}
startLogStream();
</script>
</body>
</html>