From c17be8d0171ce731a934b019b5686bb6c9b6fa19 Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Sun, 24 May 2026 11:36:23 -0400 Subject: [PATCH] =?UTF-8?q?varaverk:=20add=20Partner=20card=20=E2=80=94=20?= =?UTF-8?q?known=20hosts,=20owner=20tags,=20Tailscale=20online=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../emhttp/plugins/varaverk/api/monitor.php | 1 + .../plugins/varaverk/include/monitor.php | 39 +++++++++++++++++++ .../emhttp/plugins/varaverk/pages/monitor.php | 33 ++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/Plugin/usr/local/emhttp/plugins/varaverk/api/monitor.php b/Plugin/usr/local/emhttp/plugins/varaverk/api/monitor.php index 6c6e8d6..318a745 100644 --- a/Plugin/usr/local/emhttp/plugins/varaverk/api/monitor.php +++ b/Plugin/usr/local/emhttp/plugins/varaverk/api/monitor.php @@ -4,6 +4,7 @@ require_once dirname(__DIR__) . '/include/monitor.php'; echo json_encode([ 'fallback' => vv_fallback_state(), + 'partner' => vv_partner_state(), 'resources' => vv_system_resources(), 'cpu' => vv_cpu_per_core(), 'mem' => vv_memory_breakdown(), diff --git a/Plugin/usr/local/emhttp/plugins/varaverk/include/monitor.php b/Plugin/usr/local/emhttp/plugins/varaverk/include/monitor.php index 9bb7645..6443dea 100644 --- a/Plugin/usr/local/emhttp/plugins/varaverk/include/monitor.php +++ b/Plugin/usr/local/emhttp/plugins/varaverk/include/monitor.php @@ -249,6 +249,45 @@ function vv_network_stats(): array { ]; } +function vv_partner_state(): array { + $vars = vv_conf_vars(); + $myName = trim(shell_exec('hostname -s') ?: ''); + + // Parse Tailscale peer status once + $tsData = json_decode(shell_exec('tailscale status --json 2>/dev/null') ?: '{}', true) ?? []; + $tsPeers = []; + foreach ($tsData['Peer'] ?? [] as $peer) { + // DNSName is "hostname.tailnet.ts.net." — take the first label (full, not truncated) + $dns = $peer['DNSName'] ?? ''; + $h = $dns ? strtolower(explode('.', $dns)[0]) : strtolower($peer['HostName'] ?? ''); + if ($h) $tsPeers[$h] = (bool)($peer['Online'] ?? false); + } + + $hosts = []; + foreach (['HOST1', 'HOST2', 'HOST3', 'HOST4'] as $id) { + $hostname = $vars[$id] ?? ''; + if (!$hostname) continue; + $isMe = strcasecmp($hostname, $myName) === 0; + $isOwner = strcasecmp($id, $vars['PARTNERSHIP_OWNER_HOST'] ?? '') === 0; + $online = $isMe ? true : ($tsPeers[strtolower($hostname)] ?? null); + $hosts[] = [ + 'id' => $id, + 'hostname' => $hostname, + 'owner' => $vars[$id . '_OWNER'] ?? '', + 'is_me' => $isMe, + 'is_owner' => $isOwner, + 'online' => $online, + ]; + } + + return [ + 'enabled' => ($vars['PARTNERSHIP_ENABLED'] ?? 'false') === 'true', + 'owner_host' => $vars['PARTNERSHIP_OWNER_HOST'] ?? '', + 'sync_min' => (int)($vars['PARTNERSHIP_SYNC_INTERVAL'] ?? 15), + 'hosts' => $hosts, + ]; +} + function vv_fallback_state(): array { // State file written by fallback.sh $stateFile = '/tmp/fallback_state.db'; diff --git a/Plugin/usr/local/emhttp/plugins/varaverk/pages/monitor.php b/Plugin/usr/local/emhttp/plugins/varaverk/pages/monitor.php index 168cc23..7944978 100644 --- a/Plugin/usr/local/emhttp/plugins/varaverk/pages/monitor.php +++ b/Plugin/usr/local/emhttp/plugins/varaverk/pages/monitor.php @@ -9,6 +9,11 @@
+
+

Partner

+
Loading...
+
+

CPU

Loading...
@@ -318,6 +323,34 @@ function vvPollMonitor() { } document.getElementById('vv-fallback-desc').innerHTML = descHtml; + // ── Partner ───────────────────────────────────────────────────────────── + const pt = d.partner ?? {}; + const ptHosts = pt.hosts ?? []; + const ptStatus = pt.enabled + ? `enabled · sync every ${pt.sync_min}min` + : `disabled`; + let ptHtml = `
${ptStatus}
`; + ptHosts.forEach(h => { + const dot = h.online === null ? '#555' : h.online ? '#4caf50' : '#f44336'; + const label = h.online === null ? 'unknown' : h.online ? 'online' : 'offline'; + const tags = [ + h.is_me ? `US` : '', + h.is_owner ? `OWNER` : '', + ].join(''); + ptHtml += `
+
+ ${h.id} + ${h.owner || h.hostname} + ${tags} +
${h.hostname}
+
+
+ ● ${label} +
+
`; + }); + document.getElementById('vv-partner-body').innerHTML = ptHtml; + // ── CPU ───────────────────────────────────────────────────────────────── const cpu = d.cpu ?? {}; document.getElementById('vv-cpu-body').innerHTML = vvRenderCpu(cpu);