From abfbaa7f47da868ecb1c79009af44ac2dabd2eb6 Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Sat, 4 Jul 2026 23:28:54 -0400 Subject: [PATCH] Fix host identity detection for NetBIOS-truncated hostnames MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unraid truncates the Server Name to 15 chars (NetBIOS limit). HOST2's real hostname is "unRAID-Jayred36" but master.conf's HOST2 (matching what Tailscale shows for this peer, since resolve_tailscale_ip() keys off the same value) is the untruncated "unRAID-Jayred365" — confirmed live, Tailscale's own Self.HostName on that machine is truncated too. vv_detect_host() did a strict case-insensitive match against the bare `hostname -s` output with no tolerance for this, so it always returned 'unknown' on HOST2. That silently broke the first-run wizard (Varaverk.page explicitly excludes 'unknown' from the "needs setup" check) even though host2.conf never existed, plus vv_partner_state() and vv_fallback_active() in monitor.php which independently reimplemented the same hostname comparison instead of calling vv_detect_host(). Fix: vv_detect_host() falls back to a prefix match when the local hostname is exactly 15 chars; vv_partner_state()/vv_fallback_active() now call vv_detect_host() instead of duplicating the comparison. Verified live on HOST2 — vv_detect_host() now returns 'host2', partner state correctly flags HOST2 as is_me, and the wizard-trigger condition now evaluates true. --- Plugin/unraid/include/config.php | 10 ++++++++++ Plugin/unraid/include/monitor.php | 16 ++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Plugin/unraid/include/config.php b/Plugin/unraid/include/config.php index 8ebf9b3..e07252f 100644 --- a/Plugin/unraid/include/config.php +++ b/Plugin/unraid/include/config.php @@ -171,6 +171,16 @@ function vv_detect_host(): string { foreach ($m[1] as $i => $key) { if (strcasecmp($hostname, trim($m[2][$i])) === 0) return strtolower($key); } + // Unraid truncates the Server Name to 15 chars (NetBIOS limit). If the live hostname + // is at that exact limit, the name configured in master.conf (matching what Tailscale + // shows for this peer — resolve_tailscale_ip() keys off the same value) may be a longer, + // untruncated version. Treat a same-prefix match as this host rather than 'unknown'. + if (strlen($hostname) === 15) { + foreach ($m[1] as $i => $key) { + $configured = trim($m[2][$i]); + if (strlen($configured) > 15 && stripos($configured, $hostname) === 0) return strtolower($key); + } + } return 'unknown'; } diff --git a/Plugin/unraid/include/monitor.php b/Plugin/unraid/include/monitor.php index df649b8..588db93 100644 --- a/Plugin/unraid/include/monitor.php +++ b/Plugin/unraid/include/monitor.php @@ -4,8 +4,8 @@ require_once __DIR__ . '/common.php'; // Monitor-page-specific helpers — partner state, fallback state, watchdog summary, scripts status. function vv_partner_state(): array { - $vars = vv_conf_vars(); - $myName = trim(shell_exec('hostname -s') ?: ''); + $vars = vv_conf_vars(); + $myHostId = strtoupper(vv_detect_host()); // Parse Tailscale peer status once $tsData = json_decode(shell_exec('tailscale status --json 2>/dev/null') ?: '{}', true) ?? []; @@ -26,7 +26,7 @@ function vv_partner_state(): array { foreach ($hostIds as $id) { $hostname = $vars[$id] ?? ''; if (!$hostname) continue; - $isMe = strcasecmp($hostname, $myName) === 0; + $isMe = ($id === $myHostId); $isOwner = strcasecmp($id, $vars['PARTNERSHIP_OWNER_HOST'] ?? '') === 0; $online = $isMe ? true : ($tsPeers[strtolower($hostname)] ?? null); $onboardPhase = $isMe ? null @@ -87,17 +87,13 @@ function vv_fallback_state(): array { } function vv_fallback_active(): array { - $vars = vv_conf_vars(); - $myName = trim(shell_exec('hostname -s') ?: ''); + $vars = vv_conf_vars(); // Identify which HOST id we are $allHostIds = array_filter(array_keys($vars), fn($k) => preg_match('/^HOST\d+$/', $k) && ($vars[$k] ?? '') !== ''); sort($allHostIds); - $myId = null; - foreach ($allHostIds as $id) { - if (strcasecmp($vars[$id] ?? '', $myName) === 0) { $myId = $id; break; } - } - if (!$myId) return []; + $myId = strtoupper(vv_detect_host()); + if ($myId === 'UNKNOWN' || !in_array($myId, $allHostIds, true)) return []; // Running containers: name → image $running = [];