Restrict the AI tab to HOST1 — the only node with the GPU, Ollama and the index

This commit is contained in:
Gmer4Lfe
2026-08-04 17:25:40 -04:00
parent 0cf208b80a
commit b1fdaced9f
4 changed files with 42 additions and 11 deletions
+11 -4
View File
@@ -74,10 +74,17 @@ unset($_master, $_h1m, $_host1_blank, $_my_hostid, $_conf_missing);
$tab = $_GET['tab'] ?? 'monitor';
$validTabs = ['monitor', 'scheduler', 'docker', 'watchdog', 'partnership', 'fallback', 'arrs', 'rsync', 'auth', 'settings'];
// The AI tab exists only while AI_ENABLED is true. Appended to $validTabs rather than filtered
// out of it, so the check below rejects ?tab=ai server-side as well — omitting the link is
// presentation, not access control, and api/ai.php refuses `ask` on the same flag independently.
$_vv_ai = strtolower(trim(vv_conf_vars()['AI_ENABLED'] ?? 'false')) === 'true';
// The AI tab exists only on HOST1, and only while AI_ENABLED is true. Appended to $validTabs
// rather than filtered out of it, so the check below rejects ?tab=ai server-side as well —
// omitting the link is presentation, not access control, and api/ai.php refuses every action
// on the same two conditions independently.
//
// The host half is not a preference: HOST1 owns the GPU, the Ollama process and the index, and
// include/ai.php only ever reads the *local* {HOST}_OLLAMA_URL — there is no Tailscale resolver
// in the PHP layer the way there is in the shell. On any other host the tab could only render
// and then fail its own health check.
$_vv_ai = vv_is_ai_host()
&& strtolower(trim(vv_conf_vars()['AI_ENABLED'] ?? 'false')) === 'true';
if ($_vv_ai) $validTabs[] = 'ai';
if (!in_array($tab, $validTabs)) $tab = 'monitor';