add web UI maintenance toggles: monitor quiet mode + shutdown-web

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
d4nn13andClaude Opus 4.7 committed 2026-04-23 20:19:03 +02:00
1 parent b1085fd23c
commit 0313fb6af8
9 files changed
+197 -6

No files matched your search

+44
View File
@@ -1,3 +1,4 @@
// Edited with Claude Code
// wirecon web UI — vanilla JS. Talks to CGI scripts in /cgi-bin/ that
// return plain text (key=value for status, raw text for config/logs).
@@ -61,6 +62,11 @@ async function refreshStatus() {
dl.insertAdjacentHTML('beforeend', `<dt>${k}</dt><dd>${v}</dd>`);
}
const quiet = (kv['monitor.quiet'] || 'no') === 'yes';
const qb = $('#btn-quiet');
qb.dataset.quiet = quiet ? 'yes' : 'no';
qb.textContent = quiet ? 'enable verbose mode' : 'enable quiet mode';
$('#status-updated').textContent = `updated ${new Date().toLocaleTimeString()}`;
setOverall(allOk);
} catch (e) {
@@ -112,6 +118,44 @@ async function loadLogs() { await Promise.all([loadLog('watchdog'), loadLog('mon
$$('button[data-reload]').forEach(btn => btn.addEventListener('click', () => loadLog(btn.dataset.reload)));
// --- maintenance -----------------------------------------------------------
const maintMsg = (txt, ok) => {
const el = $('#res-maint');
el.textContent = txt;
el.className = 'result ' + (ok ? 'ok' : 'err');
};
$('#btn-quiet').addEventListener('click', async (e) => {
const btn = e.currentTarget;
const next = btn.dataset.quiet === 'yes' ? 'off' : 'on';
maintMsg(`switching quiet mode ${next}…`, true);
try {
const r = await fetch(`cgi-bin/quiet.sh?state=${next}`, { method: 'POST' });
maintMsg(await r.text(), r.ok);
if (r.ok) refreshStatus();
} catch (err) {
maintMsg(`error: ${err.message}`, false);
}
});
$('#btn-shutdown-web').addEventListener('click', async () => {
if (!confirm(
'Shut down the wirecon web UI?\n\n' +
'After this, the UI will be unreachable until you re-enable it from the\n' +
'Proxmox Console (or SSH) with:\n\n' +
' rc-update add wirecon-web default\n' +
' rc-service wirecon-web start'
)) return;
maintMsg('stopping web UI… this connection will drop shortly.', true);
try {
const r = await fetch('cgi-bin/shutdown-web.sh', { method: 'POST' });
maintMsg(await r.text(), r.ok);
} catch (err) {
// Expected: connection drops mid-response when httpd dies.
maintMsg('web UI shut down (connection closed by server).', true);
}
});
// --- boot ------------------------------------------------------------------
refreshStatus();
setInterval(refreshStatus, 5000);
+45
View File
@@ -0,0 +1,45 @@
#!/bin/sh
# Edited with Claude Code
# CGI: toggle MONITOR_QUIET in /etc/wirecon/wirecon.conf, restart monitor.
# Query: state=on|off
# POSIX-sh; busybox httpd may run CGI via ash regardless of shebang.
set -u
CONF=/etc/wirecon/wirecon.conf
state=""
case "${QUERY_STRING:-}" in
*state=on*) state=yes ;;
*state=off*) state=no ;;
*)
printf 'Status: 400 Bad Request\r\nContent-Type: text/plain\r\n\r\n'
echo "state=on|off required"; exit 0
;;
esac
if [ "${REQUEST_METHOD:-}" != "POST" ]; then
printf 'Status: 405 Method Not Allowed\r\nContent-Type: text/plain\r\n\r\n'
echo "POST required"; exit 0
fi
if grep -q '^MONITOR_QUIET=' "$CONF" 2>/dev/null; then
sed -i "s/^MONITOR_QUIET=.*/MONITOR_QUIET=$state/" "$CONF"
else
echo "MONITOR_QUIET=$state" >> "$CONF"
fi
printf 'Content-Type: text/plain\r\n\r\n'
echo "MONITOR_QUIET=$state"
echo "restarting wirecon-monitor in background..."
echo "watch: tail -F /var/log/wirecon-restart.log"
(
ts() { date '+%Y-%m-%dT%H:%M:%S%z'; }
echo "[$(ts)] quiet-toggle: MONITOR_QUIET=$state -> restarting wirecon-monitor"
if ! timeout 20 rc-service wirecon-monitor restart 2>&1; then
echo "[$(ts)] (restart returned non-zero or timed out)"
fi
echo "[$(ts)] quiet-toggle: done"
) </dev/null >>/var/log/wirecon-restart.log 2>&1 &
exit 0
+34
View File
@@ -0,0 +1,34 @@
#!/bin/sh
# Edited with Claude Code
# CGI: stop and disable wirecon-web. After this CGI returns, the web UI is
# unreachable. Re-enable from Console/SSH:
# rc-update add wirecon-web default && rc-service wirecon-web start
# POSIX-sh; busybox httpd may run CGI via ash regardless of shebang.
set -u
if [ "${REQUEST_METHOD:-}" != "POST" ]; then
printf 'Status: 405 Method Not Allowed\r\nContent-Type: text/plain\r\n\r\n'
echo "POST required"; exit 0
fi
printf 'Content-Type: text/plain\r\n\r\n'
echo "wirecon-web shutting down..."
echo ""
echo "to re-enable later (Console or SSH):"
echo " rc-update add wirecon-web default"
echo " rc-service wirecon-web start"
# Detach so the response gets flushed before httpd is killed. Brief sleep
# gives the kernel time to send our buffered body before rc-service stop
# tears the listening socket down.
(
ts() { date '+%Y-%m-%dT%H:%M:%S%z'; }
sleep 1
echo "[$(ts)] shutdown-web: rc-update del wirecon-web default"
rc-update del wirecon-web default 2>&1
echo "[$(ts)] shutdown-web: rc-service wirecon-web stop"
rc-service wirecon-web stop 2>&1
echo "[$(ts)] shutdown-web: done"
) </dev/null >>/var/log/wirecon-restart.log 2>&1 &
exit 0
+7
View File
@@ -1,4 +1,5 @@
#!/bin/sh
# Edited with Claude Code
# CGI: emit service + tunnel state as key=value lines.
# POSIX-sh; busybox httpd may run CGI via ash regardless of shebang.
set -u
@@ -14,6 +15,12 @@ for svc in wg-quick.wg0 wirecon-watchdog wirecon-monitor wirecon-web; do
printf 'svc.%s=%s\n' "$svc" "$state"
done
if grep -q '^MONITOR_QUIET=yes' /etc/wirecon/wirecon.conf 2>/dev/null; then
printf 'monitor.quiet=yes\n'
else
printf 'monitor.quiet=no\n'
fi
IFACE="${WG_INTERFACE:-wg0}"
if ip link show "$IFACE" >/dev/null 2>&1; then
+20
View File
@@ -1,4 +1,5 @@
<!doctype html>
<!-- Edited with Claude Code -->
<html lang="en">
<head>
<meta charset="utf-8">
@@ -32,6 +33,25 @@
<h2>tunnel</h2>
<dl id="wg-info" class="kv"></dl>
<h2>maintenance</h2>
<div class="maint">
<div class="maint-row">
<div>
<div class="maint-label">monitor verbosity</div>
<div class="maint-hint">quiet mode widens the cadence and drops info-level lines once the link is stable</div>
</div>
<button id="btn-quiet" data-quiet="?">…</button>
</div>
<div class="maint-row">
<div>
<div class="maint-label">web UI</div>
<div class="maint-hint">reclaims the busybox httpd footprint; re-enable from Console/SSH</div>
</div>
<button id="btn-shutdown-web" class="danger">shut down web UI</button>
</div>
<pre class="result" id="res-maint"></pre>
</div>
</section>
<!-- CONFIG ------------------------------------------------------------ -->
+14
View File
@@ -1,3 +1,4 @@
/* Edited with Claude Code */
:root {
--bg: #0e0e11;
--panel: #17171c;
@@ -99,3 +100,16 @@ button[data-save]:hover, button[data-reload]:hover { border-color: var(--accent)
}
.muted { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.maint { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 4px 14px; }
.maint-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.maint-row:last-of-type { border-bottom: 0; }
.maint-label { font-family: var(--mono); font-size: 13px; }
.maint-hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.maint button {
appearance: none; border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
padding: 6px 12px; border-radius: 6px; cursor: pointer; font-family: var(--sans); font-size: 12px; white-space: nowrap;
}
.maint button:hover { border-color: var(--accent); color: var(--accent); }
.maint button.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--border)); }
.maint button.danger:hover { background: color-mix(in srgb, var(--err) 12%, var(--panel-2)); color: var(--err); border-color: var(--err); }