- /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`.
41 lines
1.2 KiB
Bash
Executable File
41 lines
1.2 KiB
Bash
Executable File
#!/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
|