add optional web UI: busybox httpd + shell CGI, dark theme
- /etc/init.d/wirecon-web supervises `busybox httpd` on WEB_PORT (8080).
- /var/www/wirecon: single-page UI with Status / Config / Logs tabs.
- Status auto-refreshes every 5s: service states + wg0 endpoint,
handshake age, MTU, rx/tx.
- Config edits wg0.conf + wirecon.conf, saves atomically, restarts
dependents, surfaces their output.
- Logs tails /var/log/wirecon-{watchdog,monitor}.log.
- CGI returns plain text (key=value or raw) — no JSON-escape pain.
- HTTP Basic Auth template in /etc/wirecon/httpd.conf.
- Disable via `rc-service wirecon-web stop && rc-update del wirecon-web`.
This commit is contained in:
1 parent
2d07a590e2
commit
4e7e0f34ba
12 files changed
+543
-4
No files matched your search
@@ -6,6 +6,7 @@ WireGuard **client** tooling for an unprivileged Alpine LXC on Proxmox. Connects
|
|||||||
- an OpenRC **watchdog** that detects stale handshakes / ping loss and re-dials fast
|
- an OpenRC **watchdog** that detects stale handshakes / ping loss and re-dials fast
|
||||||
- a continuous **monitor** that emits structured logs for post-mortem analysis
|
- a continuous **monitor** that emits structured logs for post-mortem analysis
|
||||||
- an **MTU probe** that finds the real path MTU via DF-ping binary search
|
- an **MTU probe** that finds the real path MTU via DF-ping binary search
|
||||||
|
- an optional **web UI** (busybox httpd + CGI, dark theme) for status, config editing, and log viewing — switch off anytime to save resources
|
||||||
|
|
||||||
The server side is intentionally out of scope — point the LXC at any existing WireGuard endpoint.
|
The server side is intentionally out of scope — point the LXC at any existing WireGuard endpoint.
|
||||||
|
|
||||||
@@ -46,24 +47,29 @@ vi /etc/wirecon/wirecon.conf # PEER_IP + watchdog thresholds (optional)
|
|||||||
rc-update add wg-quick.wg0 default && rc-service wg-quick.wg0 start
|
rc-update add wg-quick.wg0 default && rc-service wg-quick.wg0 start
|
||||||
rc-update add wirecon-watchdog default && rc-service wirecon-watchdog start
|
rc-update add wirecon-watchdog default && rc-service wirecon-watchdog start
|
||||||
rc-update add wirecon-monitor default && rc-service wirecon-monitor start
|
rc-update add wirecon-monitor default && rc-service wirecon-monitor start
|
||||||
|
rc-update add wirecon-web default && rc-service wirecon-web start # optional
|
||||||
|
|
||||||
tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log
|
tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Then open **`http://<lxc-ip>:8080/`** in a browser.
|
||||||
|
|
||||||
## Layout
|
## Layout
|
||||||
|
|
||||||
```
|
```
|
||||||
lxc/
|
lxc/
|
||||||
install.sh idempotent apk + OpenRC installer (runs inside the LXC)
|
install.sh idempotent apk + OpenRC installer (runs inside the LXC)
|
||||||
bootstrap.sh clones repo into /opt/wirecon then calls install.sh
|
bootstrap.sh clones repo into /opt/wirecon then calls install.sh
|
||||||
etc/init.d/ OpenRC services: wirecon-watchdog, wirecon-monitor
|
etc/init.d/ OpenRC services: wirecon-watchdog, wirecon-monitor, wirecon-web
|
||||||
etc/wirecon/wirecon.conf tunable thresholds (peer IP, handshake age, MTU bounds…)
|
etc/wirecon/wirecon.conf tunable thresholds (peer IP, handshake age, MTU bounds, WEB_PORT…)
|
||||||
|
etc/wirecon/httpd.conf busybox httpd config (HTTP Basic Auth template)
|
||||||
etc/wireguard/wg0.conf.example
|
etc/wireguard/wg0.conf.example
|
||||||
usr/local/bin/
|
usr/local/bin/
|
||||||
wirecon-watchdog.sh one tick: handshake age + in-tunnel ping → reconnect if needed
|
wirecon-watchdog.sh one tick: handshake age + in-tunnel ping → reconnect if needed
|
||||||
wirecon-watchdog-loop.sh supervise-daemon target that re-runs the tick every WATCHDOG_INTERVAL
|
wirecon-watchdog-loop.sh supervise-daemon target that re-runs the tick every WATCHDOG_INTERVAL
|
||||||
wirecon-monitor.sh long-running structured-log emitter
|
wirecon-monitor.sh long-running structured-log emitter
|
||||||
wirecon-mtu-probe.sh DF-ping binary search → recommended WG MTU
|
wirecon-mtu-probe.sh DF-ping binary search → recommended WG MTU
|
||||||
|
var/www/wirecon/ web UI assets + CGI scripts (status / config / logs)
|
||||||
|
|
||||||
proxmox/
|
proxmox/
|
||||||
create-lxc.sh host-side LXC provisioner (the one-liner above)
|
create-lxc.sh host-side LXC provisioner (the one-liner above)
|
||||||
@@ -97,3 +103,27 @@ tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log
|
|||||||
grep event=reconnect /var/log/wirecon-watchdog.log
|
grep event=reconnect /var/log/wirecon-watchdog.log
|
||||||
awk -F'rtt_ms=' '/rtt_ms=/{split($2,a," "); print $0}' /var/log/wirecon-monitor.log
|
awk -F'rtt_ms=' '/rtt_ms=/{split($2,a," "); print $0}' /var/log/wirecon-monitor.log
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Web UI
|
||||||
|
|
||||||
|
Optional. Serves at `http://<lxc-ip>:8080/` — dark theme, three tabs:
|
||||||
|
|
||||||
|
- **Status** — running/stopped state for each service, live wg0 endpoint + handshake age + rx/tx (auto-refresh every 5s).
|
||||||
|
- **Config** — edit `/etc/wireguard/wg0.conf` and `/etc/wirecon/wirecon.conf` in-browser; saving triggers a restart of the affected services and returns their stdout.
|
||||||
|
- **Logs** — tail of `wirecon-watchdog.log` and `wirecon-monitor.log`.
|
||||||
|
|
||||||
|
Runs on **busybox httpd** (~2 MiB RSS) with shell CGI — no Python/Go runtime needed. Disable anytime:
|
||||||
|
|
||||||
|
```
|
||||||
|
rc-service wirecon-web stop
|
||||||
|
rc-update del wirecon-web
|
||||||
|
```
|
||||||
|
|
||||||
|
**Security:** the UI edits `wg0.conf` (contains private keys) and restarts services, so expose it on the LAN only. Enable HTTP Basic Auth by adding a line to `/etc/wirecon/httpd.conf`:
|
||||||
|
|
||||||
|
```
|
||||||
|
# generate hash: openssl passwd -1 'your-password'
|
||||||
|
/:admin:$1$salt$hash
|
||||||
|
```
|
||||||
|
|
||||||
|
Change `WEB_PORT` / `WEB_BIND` in `/etc/wirecon/wirecon.conf` and restart `wirecon-web` to move it.
|
||||||
Executable
+26
@@ -0,0 +1,26 @@
|
|||||||
|
#!/sbin/openrc-run
|
||||||
|
# wirecon web UI — busybox httpd serving /var/www/wirecon with CGI.
|
||||||
|
# Disable to save resources:
|
||||||
|
# rc-service wirecon-web stop && rc-update del wirecon-web
|
||||||
|
|
||||||
|
name="wirecon-web"
|
||||||
|
description="wirecon web UI (busybox httpd)"
|
||||||
|
|
||||||
|
# Pull WEB_PORT from wirecon.conf if present.
|
||||||
|
: "${WIRECON_CONF:=/etc/wirecon/wirecon.conf}"
|
||||||
|
[ -r "$WIRECON_CONF" ] && . "$WIRECON_CONF"
|
||||||
|
: "${WEB_PORT:=8080}"
|
||||||
|
: "${WEB_BIND:=0.0.0.0}"
|
||||||
|
: "${WEB_ROOT:=/var/www/wirecon}"
|
||||||
|
|
||||||
|
supervisor="supervise-daemon"
|
||||||
|
command="/bin/busybox"
|
||||||
|
command_args="httpd -f -v -p ${WEB_BIND}:${WEB_PORT} -h ${WEB_ROOT} -c /etc/wirecon/httpd.conf"
|
||||||
|
respawn_delay=5
|
||||||
|
respawn_max=0
|
||||||
|
output_log="/var/log/wirecon-web.log"
|
||||||
|
error_log="/var/log/wirecon-web.log"
|
||||||
|
|
||||||
|
depend() {
|
||||||
|
need net
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# busybox httpd config for wirecon web UI.
|
||||||
|
#
|
||||||
|
# HTTP Basic Auth (recommended — the UI can edit wg0.conf):
|
||||||
|
# /:admin:$1$salt$hash
|
||||||
|
# Generate the hash with: openssl passwd -1 'your-password'
|
||||||
|
# Uncomment the line below and paste your hash. Restart: rc-service wirecon-web restart
|
||||||
|
#
|
||||||
|
# /:admin:REPLACE_WITH_HASH
|
||||||
|
|
||||||
|
# Treat scripts under /cgi-bin/ as CGI (busybox httpd does this by default,
|
||||||
|
# but being explicit doesn't hurt).
|
||||||
|
*.sh:/bin/sh
|
||||||
@@ -30,8 +30,13 @@ MONITOR_INTERVAL=10
|
|||||||
# Watchdog cadence (seconds between tick invocations by the loop wrapper)
|
# Watchdog cadence (seconds between tick invocations by the loop wrapper)
|
||||||
WATCHDOG_INTERVAL=20
|
WATCHDOG_INTERVAL=20
|
||||||
|
|
||||||
# Log tag (shows up as SYSLOG_IDENTIFIER in journald)
|
# Log tag (used by scripts when emitting structured lines)
|
||||||
LOG_TAG=wirecon
|
LOG_TAG=wirecon
|
||||||
|
|
||||||
# Runtime state dir
|
# Runtime state dir
|
||||||
STATE_DIR=/run/wirecon
|
STATE_DIR=/run/wirecon
|
||||||
|
|
||||||
|
# Web UI (busybox httpd). Disable to save resources:
|
||||||
|
# rc-service wirecon-web stop && rc-update del wirecon-web
|
||||||
|
WEB_PORT=8080
|
||||||
|
WEB_BIND=0.0.0.0
|
||||||
+17
-1
@@ -59,8 +59,20 @@ install -m 0755 "$SRC/usr/local/bin/wirecon-mtu-probe.sh" /usr/local/bin/
|
|||||||
log "deploying OpenRC init scripts"
|
log "deploying OpenRC init scripts"
|
||||||
install -m 0755 "$SRC/etc/init.d/wirecon-watchdog" /etc/init.d/
|
install -m 0755 "$SRC/etc/init.d/wirecon-watchdog" /etc/init.d/
|
||||||
install -m 0755 "$SRC/etc/init.d/wirecon-monitor" /etc/init.d/
|
install -m 0755 "$SRC/etc/init.d/wirecon-monitor" /etc/init.d/
|
||||||
|
install -m 0755 "$SRC/etc/init.d/wirecon-web" /etc/init.d/
|
||||||
install -m 0644 "$SRC/etc/conf.d/wg-quick" /etc/conf.d/wg-quick
|
install -m 0644 "$SRC/etc/conf.d/wg-quick" /etc/conf.d/wg-quick
|
||||||
|
|
||||||
|
log "deploying web UI"
|
||||||
|
install -d -m 0755 /var/www/wirecon /var/www/wirecon/cgi-bin
|
||||||
|
install -m 0644 "$SRC/var/www/wirecon/index.html" /var/www/wirecon/
|
||||||
|
install -m 0644 "$SRC/var/www/wirecon/style.css" /var/www/wirecon/
|
||||||
|
install -m 0644 "$SRC/var/www/wirecon/app.js" /var/www/wirecon/
|
||||||
|
install -m 0755 "$SRC/var/www/wirecon/cgi-bin/status.sh" /var/www/wirecon/cgi-bin/
|
||||||
|
install -m 0755 "$SRC/var/www/wirecon/cgi-bin/config-get.sh" /var/www/wirecon/cgi-bin/
|
||||||
|
install -m 0755 "$SRC/var/www/wirecon/cgi-bin/config-save.sh" /var/www/wirecon/cgi-bin/
|
||||||
|
install -m 0755 "$SRC/var/www/wirecon/cgi-bin/logs.sh" /var/www/wirecon/cgi-bin/
|
||||||
|
install -m 0644 "$SRC/etc/wirecon/httpd.conf" /etc/wirecon/httpd.conf
|
||||||
|
|
||||||
# Per-interface wg-quick symlink so the init script knows which iface to bring up.
|
# Per-interface wg-quick symlink so the init script knows which iface to bring up.
|
||||||
if [[ ! -L /etc/init.d/wg-quick.wg0 ]]; then
|
if [[ ! -L /etc/init.d/wg-quick.wg0 ]]; then
|
||||||
ln -s wg-quick /etc/init.d/wg-quick.wg0
|
ln -s wg-quick /etc/init.d/wg-quick.wg0
|
||||||
@@ -95,9 +107,11 @@ NEXT STEPS:
|
|||||||
rc-update add wg-quick.wg0 default
|
rc-update add wg-quick.wg0 default
|
||||||
rc-update add wirecon-watchdog default
|
rc-update add wirecon-watchdog default
|
||||||
rc-update add wirecon-monitor default
|
rc-update add wirecon-monitor default
|
||||||
|
rc-update add wirecon-web default # optional, http://<lxc>:8080
|
||||||
rc-service wg-quick.wg0 start
|
rc-service wg-quick.wg0 start
|
||||||
rc-service wirecon-watchdog start
|
rc-service wirecon-watchdog start
|
||||||
rc-service wirecon-monitor start
|
rc-service wirecon-monitor start
|
||||||
|
rc-service wirecon-web start
|
||||||
4. Watch the logs:
|
4. Watch the logs:
|
||||||
tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log
|
tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log
|
||||||
EOF
|
EOF
|
||||||
@@ -106,8 +120,10 @@ else
|
|||||||
rc-update add wg-quick.wg0 default 2>/dev/null || true
|
rc-update add wg-quick.wg0 default 2>/dev/null || true
|
||||||
rc-update add wirecon-watchdog default 2>/dev/null || true
|
rc-update add wirecon-watchdog default 2>/dev/null || true
|
||||||
rc-update add wirecon-monitor default 2>/dev/null || true
|
rc-update add wirecon-monitor default 2>/dev/null || true
|
||||||
|
rc-update add wirecon-web default 2>/dev/null || true
|
||||||
rc-service wg-quick.wg0 restart
|
rc-service wg-quick.wg0 restart
|
||||||
rc-service wirecon-watchdog restart
|
rc-service wirecon-watchdog restart
|
||||||
rc-service wirecon-monitor restart
|
rc-service wirecon-monitor restart
|
||||||
log "done. tail logs: tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log"
|
rc-service wirecon-web restart
|
||||||
|
log "done. UI: http://<lxc-ip>:${WEB_PORT:-8080}/ | logs: tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log"
|
||||||
fi
|
fi
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
// 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).
|
||||||
|
|
||||||
|
const $ = s => document.querySelector(s);
|
||||||
|
const $$ = s => document.querySelectorAll(s);
|
||||||
|
|
||||||
|
// --- tabs ------------------------------------------------------------------
|
||||||
|
$$('nav button').forEach(btn => btn.addEventListener('click', () => {
|
||||||
|
$$('nav button').forEach(b => b.classList.toggle('active', b === btn));
|
||||||
|
const tab = btn.dataset.tab;
|
||||||
|
$$('.tab').forEach(s => s.classList.toggle('active', s.id === `tab-${tab}`));
|
||||||
|
if (tab === 'config') loadConfigs();
|
||||||
|
if (tab === 'logs') loadLogs();
|
||||||
|
}));
|
||||||
|
|
||||||
|
// --- helpers ---------------------------------------------------------------
|
||||||
|
const parseKV = txt => Object.fromEntries(
|
||||||
|
txt.trim().split('\n').filter(Boolean).map(l => {
|
||||||
|
const i = l.indexOf('=');
|
||||||
|
return [l.slice(0, i), l.slice(i + 1)];
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const setOverall = ok => {
|
||||||
|
const el = $('#overall');
|
||||||
|
el.textContent = ok ? 'all systems ok' : 'attention';
|
||||||
|
el.className = 'pill ' + (ok ? 'ok' : 'err');
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- status ----------------------------------------------------------------
|
||||||
|
async function refreshStatus() {
|
||||||
|
try {
|
||||||
|
const r = await fetch('cgi-bin/status.sh', { cache: 'no-store' });
|
||||||
|
const kv = parseKV(await r.text());
|
||||||
|
|
||||||
|
const services = ['wg-quick.wg0', 'wirecon-watchdog', 'wirecon-monitor', 'wirecon-web'];
|
||||||
|
const tbody = $('#svc-table tbody');
|
||||||
|
tbody.innerHTML = '';
|
||||||
|
let allOk = true;
|
||||||
|
for (const s of services) {
|
||||||
|
const state = kv[`svc.${s}`] || 'unknown';
|
||||||
|
if (state !== 'running') allOk = false;
|
||||||
|
tbody.insertAdjacentHTML('beforeend',
|
||||||
|
`<tr><td>${s}</td><td class="state-${state}">${state}</td></tr>`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const age = kv['wg0.handshake_age_s'];
|
||||||
|
const stale = age && parseInt(age, 10) > 180;
|
||||||
|
if (stale) allOk = false;
|
||||||
|
|
||||||
|
const dl = $('#wg-info');
|
||||||
|
dl.innerHTML = '';
|
||||||
|
const fields = [
|
||||||
|
['interface', kv['wg0.iface'] || '—'],
|
||||||
|
['endpoint', kv['wg0.endpoint'] || '—'],
|
||||||
|
['MTU', kv['wg0.mtu'] || '—'],
|
||||||
|
['last handshake', age === undefined ? '—' : age === '-1' ? 'never' : `${age}s ago`],
|
||||||
|
['rx / tx', `${kv['wg0.rx_bytes'] || '—'} / ${kv['wg0.tx_bytes'] || '—'}`],
|
||||||
|
];
|
||||||
|
for (const [k, v] of fields) {
|
||||||
|
dl.insertAdjacentHTML('beforeend', `<dt>${k}</dt><dd>${v}</dd>`);
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#status-updated').textContent = `updated ${new Date().toLocaleTimeString()}`;
|
||||||
|
setOverall(allOk);
|
||||||
|
} catch (e) {
|
||||||
|
setOverall(false);
|
||||||
|
$('#status-updated').textContent = `error: ${e.message}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- config ----------------------------------------------------------------
|
||||||
|
async function loadConfig(which) {
|
||||||
|
const r = await fetch(`cgi-bin/config-get.sh?file=${which}`, { cache: 'no-store' });
|
||||||
|
if (!r.ok) { $(`#cfg-${which}`).value = `[failed to load: HTTP ${r.status}]`; return; }
|
||||||
|
$(`#cfg-${which}`).value = await r.text();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadConfigs() { await Promise.all([loadConfig('wg0'), loadConfig('wirecon')]); }
|
||||||
|
|
||||||
|
$$('button[data-save]').forEach(btn => btn.addEventListener('click', async () => {
|
||||||
|
const which = btn.dataset.save;
|
||||||
|
const res = $(`#res-${which}`);
|
||||||
|
res.className = 'result';
|
||||||
|
res.textContent = 'saving…';
|
||||||
|
try {
|
||||||
|
const body = $(`#cfg-${which}`).value;
|
||||||
|
const r = await fetch(`cgi-bin/config-save.sh?file=${which}`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'text/plain' },
|
||||||
|
body,
|
||||||
|
});
|
||||||
|
const txt = await r.text();
|
||||||
|
res.textContent = txt;
|
||||||
|
res.className = 'result ' + (r.ok ? 'ok' : 'err');
|
||||||
|
if (r.ok) refreshStatus();
|
||||||
|
} catch (e) {
|
||||||
|
res.className = 'result err';
|
||||||
|
res.textContent = `error: ${e.message}`;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
// --- logs ------------------------------------------------------------------
|
||||||
|
async function loadLog(which) {
|
||||||
|
const r = await fetch(`cgi-bin/logs.sh?service=${which}&lines=200`, { cache: 'no-store' });
|
||||||
|
$(`#log-${which}`).textContent = await r.text();
|
||||||
|
// scroll to bottom
|
||||||
|
const el = $(`#log-${which}`);
|
||||||
|
el.scrollTop = el.scrollHeight;
|
||||||
|
}
|
||||||
|
async function loadLogs() { await Promise.all([loadLog('watchdog'), loadLog('monitor')]); }
|
||||||
|
|
||||||
|
$$('button[data-reload]').forEach(btn => btn.addEventListener('click', () => loadLog(btn.dataset.reload)));
|
||||||
|
|
||||||
|
// --- boot ------------------------------------------------------------------
|
||||||
|
refreshStatus();
|
||||||
|
setInterval(refreshStatus, 5000);
|
||||||
Executable
+26
@@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# CGI: return a config file's contents as text/plain.
|
||||||
|
# file=wg0 → /etc/wireguard/wg0.conf
|
||||||
|
# file=wirecon → /etc/wirecon/wirecon.conf
|
||||||
|
set -u
|
||||||
|
|
||||||
|
file=""
|
||||||
|
case "${QUERY_STRING:-}" in
|
||||||
|
*file=wg0*) file=/etc/wireguard/wg0.conf ;;
|
||||||
|
*file=wirecon*) file=/etc/wirecon/wirecon.conf ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [[ -z "$file" ]]; then
|
||||||
|
printf 'Status: 400 Bad Request\r\nContent-Type: text/plain\r\n\r\n'
|
||||||
|
echo "bad file parameter"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -r "$file" ]]; then
|
||||||
|
printf 'Status: 404 Not Found\r\nContent-Type: text/plain\r\n\r\n'
|
||||||
|
echo "not readable: $file"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf 'Content-Type: text/plain\r\n\r\n'
|
||||||
|
cat "$file"
|
||||||
Executable
+62
@@ -0,0 +1,62 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# CGI: accept POST body as the new contents of a config file, write it
|
||||||
|
# atomically, then restart the services that depend on it.
|
||||||
|
# Query: file=wg0|wirecon
|
||||||
|
# Body: raw text
|
||||||
|
set -u
|
||||||
|
|
||||||
|
file=""; label=""; restart=()
|
||||||
|
case "${QUERY_STRING:-}" in
|
||||||
|
*file=wg0*)
|
||||||
|
file=/etc/wireguard/wg0.conf
|
||||||
|
label="wg0.conf"
|
||||||
|
restart=(wg-quick.wg0 wirecon-watchdog wirecon-monitor)
|
||||||
|
mode=0600
|
||||||
|
;;
|
||||||
|
*file=wirecon*)
|
||||||
|
file=/etc/wirecon/wirecon.conf
|
||||||
|
label="wirecon.conf"
|
||||||
|
restart=(wirecon-watchdog wirecon-monitor)
|
||||||
|
mode=0644
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf 'Status: 400 Bad Request\r\nContent-Type: text/plain\r\n\r\n'
|
||||||
|
echo "bad file parameter"; 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
|
||||||
|
|
||||||
|
# Read body (CONTENT_LENGTH bytes; fallback to EOF).
|
||||||
|
len="${CONTENT_LENGTH:-0}"
|
||||||
|
tmp=$(mktemp "${file}.XXXXXX")
|
||||||
|
trap 'rm -f "$tmp"' EXIT
|
||||||
|
|
||||||
|
if [[ "$len" -gt 0 ]]; then
|
||||||
|
head -c "$len" > "$tmp"
|
||||||
|
else
|
||||||
|
cat > "$tmp"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Refuse empty writes — likely a bug, not intent.
|
||||||
|
if [[ ! -s "$tmp" ]]; then
|
||||||
|
printf 'Status: 400 Bad Request\r\nContent-Type: text/plain\r\n\r\n'
|
||||||
|
echo "refusing empty body"; exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
chmod "$mode" "$tmp"
|
||||||
|
mv -f "$tmp" "$file"
|
||||||
|
trap - EXIT
|
||||||
|
|
||||||
|
# Restart dependents, collect output for the UI.
|
||||||
|
printf 'Content-Type: text/plain\r\n\r\n'
|
||||||
|
echo "saved $file ($(wc -c < "$file") bytes)"
|
||||||
|
|
||||||
|
for svc in "${restart[@]}"; do
|
||||||
|
echo ""
|
||||||
|
echo "--- restart $svc ---"
|
||||||
|
rc-service "$svc" restart 2>&1 || echo "(restart of $svc returned non-zero)"
|
||||||
|
done
|
||||||
Executable
+29
@@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# CGI: return the tail of a log file as text/plain.
|
||||||
|
# Query: service=watchdog|monitor lines=N (capped to 1000)
|
||||||
|
set -u
|
||||||
|
|
||||||
|
service=""; lines=100
|
||||||
|
case "${QUERY_STRING:-}" in
|
||||||
|
*service=watchdog*) service=watchdog ;;
|
||||||
|
*service=monitor*) service=monitor ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# pull lines= from query string
|
||||||
|
if [[ "${QUERY_STRING:-}" =~ lines=([0-9]+) ]]; then
|
||||||
|
lines="${BASH_REMATCH[1]}"
|
||||||
|
(( lines > 1000 )) && lines=1000
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$service" ]]; then
|
||||||
|
printf 'Status: 400 Bad Request\r\nContent-Type: text/plain\r\n\r\n'
|
||||||
|
echo "service must be watchdog or monitor"; exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
file="/var/log/wirecon-${service}.log"
|
||||||
|
printf 'Content-Type: text/plain\r\n\r\n'
|
||||||
|
if [[ -r "$file" ]]; then
|
||||||
|
tail -n "$lines" "$file"
|
||||||
|
else
|
||||||
|
echo "(no log yet at $file)"
|
||||||
|
fi
|
||||||
Executable
+40
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# CGI: emit service + tunnel state as key=value lines.
|
||||||
|
set -u
|
||||||
|
|
||||||
|
printf 'Content-Type: text/plain\r\n\r\n'
|
||||||
|
|
||||||
|
for svc in wg-quick.wg0 wirecon-watchdog wirecon-monitor wirecon-web; do
|
||||||
|
if rc-service "$svc" status >/dev/null 2>&1; then
|
||||||
|
state=running
|
||||||
|
else
|
||||||
|
state=stopped
|
||||||
|
fi
|
||||||
|
printf 'svc.%s=%s\n' "$svc" "$state"
|
||||||
|
done
|
||||||
|
|
||||||
|
IFACE="${WG_INTERFACE:-wg0}"
|
||||||
|
|
||||||
|
if ip link show "$IFACE" >/dev/null 2>&1; then
|
||||||
|
printf 'wg0.iface=up\n'
|
||||||
|
mtu=$(ip -o link show "$IFACE" | awk '{for(i=1;i<=NF;i++) if($i=="mtu"){print $(i+1); exit}}')
|
||||||
|
printf 'wg0.mtu=%s\n' "${mtu:-?}"
|
||||||
|
|
||||||
|
# peer dump: pub psk endpoint allowed_ips last_handshake rx tx keepalive
|
||||||
|
dump=$(wg show "$IFACE" dump 2>/dev/null | awk 'NR==2')
|
||||||
|
if [[ -n "$dump" ]]; then
|
||||||
|
endpoint=$(awk '{print $3}' <<<"$dump")
|
||||||
|
hs_ts=$(awk '{print $5}' <<<"$dump")
|
||||||
|
rx=$(awk '{print $6}' <<<"$dump")
|
||||||
|
tx=$(awk '{print $7}' <<<"$dump")
|
||||||
|
now=$(date +%s)
|
||||||
|
age=-1
|
||||||
|
[[ "$hs_ts" != "0" && -n "$hs_ts" ]] && age=$((now - hs_ts))
|
||||||
|
printf 'wg0.endpoint=%s\n' "${endpoint:-none}"
|
||||||
|
printf 'wg0.handshake_age_s=%s\n' "$age"
|
||||||
|
printf 'wg0.rx_bytes=%s\n' "${rx:-0}"
|
||||||
|
printf 'wg0.tx_bytes=%s\n' "${tx:-0}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
printf 'wg0.iface=down\n'
|
||||||
|
fi
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
<title>wirecon</title>
|
||||||
|
<link rel="stylesheet" href="style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<h1>wirecon</h1>
|
||||||
|
<div id="overall" class="pill">checking…</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<nav>
|
||||||
|
<button data-tab="status" class="active">Status</button>
|
||||||
|
<button data-tab="config">Config</button>
|
||||||
|
<button data-tab="logs">Logs</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<!-- STATUS ------------------------------------------------------------ -->
|
||||||
|
<section id="tab-status" class="tab active">
|
||||||
|
<div class="row">
|
||||||
|
<h2>services</h2>
|
||||||
|
<span class="muted" id="status-updated"></span>
|
||||||
|
</div>
|
||||||
|
<table id="svc-table">
|
||||||
|
<thead><tr><th>name</th><th>state</th></tr></thead>
|
||||||
|
<tbody></tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2>tunnel</h2>
|
||||||
|
<dl id="wg-info" class="kv"></dl>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- CONFIG ------------------------------------------------------------ -->
|
||||||
|
<section id="tab-config" class="tab">
|
||||||
|
<div class="config-block">
|
||||||
|
<div class="row">
|
||||||
|
<h2>/etc/wireguard/wg0.conf</h2>
|
||||||
|
<button data-save="wg0">save + restart tunnel</button>
|
||||||
|
</div>
|
||||||
|
<textarea id="cfg-wg0" spellcheck="false" rows="18"></textarea>
|
||||||
|
<pre class="result" id="res-wg0"></pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="config-block">
|
||||||
|
<div class="row">
|
||||||
|
<h2>/etc/wirecon/wirecon.conf</h2>
|
||||||
|
<button data-save="wirecon">save + restart watchdog/monitor</button>
|
||||||
|
</div>
|
||||||
|
<textarea id="cfg-wirecon" spellcheck="false" rows="18"></textarea>
|
||||||
|
<pre class="result" id="res-wirecon"></pre>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- LOGS -------------------------------------------------------------- -->
|
||||||
|
<section id="tab-logs" class="tab">
|
||||||
|
<div class="row">
|
||||||
|
<h2>watchdog</h2>
|
||||||
|
<button data-reload="watchdog">reload</button>
|
||||||
|
</div>
|
||||||
|
<pre id="log-watchdog" class="log"></pre>
|
||||||
|
<div class="row">
|
||||||
|
<h2>monitor</h2>
|
||||||
|
<button data-reload="monitor">reload</button>
|
||||||
|
</div>
|
||||||
|
<pre id="log-monitor" class="log"></pre>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<script src="app.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
:root {
|
||||||
|
--bg: #0e0e11;
|
||||||
|
--panel: #17171c;
|
||||||
|
--panel-2: #1f1f27;
|
||||||
|
--border: #2a2a33;
|
||||||
|
--text: #e7e7ea;
|
||||||
|
--muted: #8b8b95;
|
||||||
|
--accent: #2dd4bf;
|
||||||
|
--ok: #4ade80;
|
||||||
|
--warn: #fbbf24;
|
||||||
|
--err: #f87171;
|
||||||
|
--mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
|
||||||
|
--sans: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
* { box-sizing: border-box; }
|
||||||
|
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; line-height: 1.45; }
|
||||||
|
h1, h2 { margin: 0; font-weight: 600; }
|
||||||
|
h1 { font-size: 18px; letter-spacing: 0.02em; }
|
||||||
|
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
|
||||||
|
|
||||||
|
header {
|
||||||
|
display: flex; align-items: center; justify-content: space-between;
|
||||||
|
padding: 14px 22px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
background: var(--panel);
|
||||||
|
}
|
||||||
|
|
||||||
|
nav {
|
||||||
|
display: flex; gap: 4px;
|
||||||
|
padding: 10px 18px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
background: var(--panel);
|
||||||
|
}
|
||||||
|
nav button {
|
||||||
|
appearance: none; border: 0; background: transparent;
|
||||||
|
color: var(--muted); font-family: var(--sans); font-size: 13px;
|
||||||
|
padding: 6px 14px; border-radius: 6px; cursor: pointer;
|
||||||
|
}
|
||||||
|
nav button:hover { color: var(--text); background: var(--panel-2); }
|
||||||
|
nav button.active { color: var(--text); background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--accent); }
|
||||||
|
|
||||||
|
main { padding: 22px; max-width: 960px; margin: 0 auto; }
|
||||||
|
.tab { display: none; }
|
||||||
|
.tab.active { display: block; }
|
||||||
|
|
||||||
|
.row { display: flex; align-items: center; justify-content: space-between; margin: 22px 0 10px; }
|
||||||
|
.row h2 { margin: 0; }
|
||||||
|
|
||||||
|
.pill {
|
||||||
|
padding: 3px 10px; border-radius: 999px;
|
||||||
|
font-family: var(--mono); font-size: 12px;
|
||||||
|
background: var(--panel-2); color: var(--muted);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }
|
||||||
|
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
|
||||||
|
.pill.err { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--border)); }
|
||||||
|
|
||||||
|
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
|
||||||
|
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); font-family: var(--mono); font-size: 13px; }
|
||||||
|
th { color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: 11px; letter-spacing: 0.08em; }
|
||||||
|
tr:last-child td { border-bottom: 0; }
|
||||||
|
td.state-running { color: var(--ok); }
|
||||||
|
td.state-stopped { color: var(--err); }
|
||||||
|
td.state-unknown { color: var(--muted); }
|
||||||
|
|
||||||
|
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px;
|
||||||
|
margin: 0; padding: 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
|
||||||
|
font-family: var(--mono); font-size: 13px; }
|
||||||
|
.kv dt { color: var(--muted); }
|
||||||
|
.kv dd { margin: 0; }
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
width: 100%; display: block;
|
||||||
|
background: #0a0a0d; color: var(--text); border: 1px solid var(--border); border-radius: 8px;
|
||||||
|
font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
|
||||||
|
padding: 12px; resize: vertical; tab-size: 2;
|
||||||
|
}
|
||||||
|
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
|
||||||
|
|
||||||
|
button[data-save], button[data-reload] {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
button[data-save]:hover, button[data-reload]:hover { border-color: var(--accent); color: var(--accent); }
|
||||||
|
|
||||||
|
.config-block + .config-block { margin-top: 28px; }
|
||||||
|
|
||||||
|
.result { margin-top: 10px; min-height: 0; padding: 0; background: transparent; border: 0;
|
||||||
|
font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: pre-wrap; }
|
||||||
|
.result.ok { color: var(--ok); }
|
||||||
|
.result.err { color: var(--err); }
|
||||||
|
|
||||||
|
.log {
|
||||||
|
background: #0a0a0d; border: 1px solid var(--border); border-radius: 8px;
|
||||||
|
padding: 12px; max-height: 360px; overflow: auto;
|
||||||
|
font-family: var(--mono); font-size: 12px; white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.muted { color: var(--muted); font-size: 12px; font-family: var(--mono); }
|
||||||
Reference in new issue
Block a user