API keys: Varaverk_HOST1 registered on all machines, keys in host*.conf, cross-host GraphQL direct access
This commit is contained in:
@@ -95,7 +95,10 @@ if ($action === 'detect' && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
exit;
|
||||
}
|
||||
|
||||
// ── Unraid API key status — all hosts ────────────────────────────────────────
|
||||
// ── Unraid API key status ─────────────────────────────────────────────────────
|
||||
// Keys live in host*.conf (private, not master.conf):
|
||||
// host1.conf: HOST1_UNRAID_API_KEY (own) + HOST2_UNRAID_API_KEY (HOST1's access to HOST2)
|
||||
// host2.conf: HOST2_UNRAID_API_KEY (own) + HOST1_UNRAID_API_KEY (HOST2's access to HOST1)
|
||||
if ($action === 'api_status') {
|
||||
require_once dirname(__DIR__) . '/include/unraid_api.php';
|
||||
$localStatus = vv_api_get_status();
|
||||
@@ -103,7 +106,6 @@ if ($action === 'api_status') {
|
||||
$myHost = vv_detect_host();
|
||||
$myId = strtoupper($myHost);
|
||||
|
||||
// Collect status for every configured host
|
||||
$hosts = [];
|
||||
foreach ($vars as $k => $v) {
|
||||
if (!preg_match('/^HOST(\d+)$/', $k, $m) || !$v) continue;
|
||||
@@ -111,11 +113,14 @@ if ($action === 'api_status') {
|
||||
$keyVar = $id . '_UNRAID_API_KEY';
|
||||
$key = $vars[$keyVar] ?? '';
|
||||
$isLocal = ($id === $myId);
|
||||
// For local: key is Varaverk_HOST1 registered on own machine
|
||||
// For remote: key is Varaverk_HOST1 registered on HOST2's machine (stored in host1.conf)
|
||||
$hosts[] = [
|
||||
'host_id' => $id,
|
||||
'hostname' => $v,
|
||||
'is_local' => $isLocal,
|
||||
'key_var' => $keyVar,
|
||||
'key_name' => 'Varaverk_' . ($isLocal ? $myId : $myId), // Varaverk_HOST1 on that registry
|
||||
'key_present' => !empty($key),
|
||||
'key_preview' => $key ? substr($key, 0, 8) . '...' . substr($key, -4) : null,
|
||||
'api_ok' => $isLocal
|
||||
@@ -123,7 +128,7 @@ if ($action === 'api_status') {
|
||||
: !empty($key),
|
||||
];
|
||||
}
|
||||
usort($hosts, fn($a,$b) => strcmp($a['host_id'], $b['host_id']));
|
||||
usort($hosts, fn($a, $b) => strcmp($a['host_id'], $b['host_id']));
|
||||
|
||||
echo json_encode([
|
||||
'ok' => true,
|
||||
|
||||
@@ -152,10 +152,12 @@ $_apiPreview = $_apiKey ? substr($_apiKey, 0, 8) . '...' . substr($_apiKey, -4)
|
||||
<div id="vv-api-hosts" style="margin-bottom:12px;"></div>
|
||||
|
||||
<div style="font-size:11px;color:#444;margin-bottom:12px;line-height:1.6;">
|
||||
Each host registers a key named <code style="font-size:10px;color:#4a7a4a;background:#080808;padding:1px 4px;border-radius:2px;">Varaverk_HOST1</code>,
|
||||
<code style="font-size:10px;color:#4a7a4a;background:#080808;padding:1px 4px;border-radius:2px;">Varaverk_HOST2</code>, etc.
|
||||
Keys are stored in <code style="font-size:10px;color:#4a7a4a;background:#080808;padding:1px 4px;border-radius:2px;">master.conf</code>
|
||||
so every host can query every other host's GraphQL API directly — no SSH needed for remote monitoring.
|
||||
Each host registers
|
||||
<code style="font-size:10px;color:#4a7a4a;background:#080808;padding:1px 4px;border-radius:2px;">Varaverk_HOST1</code>
|
||||
in <em>every</em> machine's local Unraid registry — own machine plus all partners.
|
||||
The key values are stored in the private <code style="font-size:10px;color:#4a7a4a;background:#080808;padding:1px 4px;border-radius:2px;">host*.conf</code>
|
||||
so each host can query every other host's GraphQL API directly — real-time monitoring, no SSH.
|
||||
During offboard, partner keys are removed from each registry automatically.
|
||||
</div>
|
||||
|
||||
<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap;">
|
||||
@@ -349,16 +351,22 @@ function vvApiCheck() {
|
||||
badge.className = 'vv-set-badge ' + (allOk ? 'internal' : 'flash');
|
||||
|
||||
if (hosts) hosts.innerHTML = d.hosts.map(h => {
|
||||
const local = h.is_local ? ' <span style="color:#2a3a2a;font-size:9px;">local</span>' : '';
|
||||
const tag = h.is_local
|
||||
? `<span style="color:#2a3a2a;font-size:9px;margin-left:4px;">own</span>`
|
||||
: `<span style="color:#2a2a3a;font-size:9px;margin-left:4px;">${d.my_id}'s key on ${h.host_id}</span>`;
|
||||
const keyBit = h.key_present
|
||||
? `<code style="font-size:9px;color:#4a6a4a;">${h.key_preview}</code>`
|
||||
: `<span style="color:#8b2a2a;font-size:10px;">not set</span>`;
|
||||
const dot = h.api_ok ? '#4caf50' : '#555';
|
||||
const name = `Varaverk_${h.host_id}`;
|
||||
return `<div style="display:flex;align-items:baseline;gap:8px;padding:3px 0;border-bottom:1px solid #111;">
|
||||
<span style="width:6px;height:6px;border-radius:50%;background:${dot};flex-shrink:0;margin-top:3px;display:inline-block;"></span>
|
||||
<span style="font-size:11px;color:#666;width:60px;flex-shrink:0;">${h.host_id}${local}</span>
|
||||
<code style="font-size:9px;color:#2a3a2a;flex-shrink:0;">${name}</code>
|
||||
: `<span style="color:#8b2a2a;font-size:10px;">not set — click Setup</span>`;
|
||||
const dot = h.api_ok ? '#4caf50' : (h.key_present ? '#ffb74d' : '#444');
|
||||
// Key name in that machine's registry: always Varaverk_<MY_ID>
|
||||
const keyName = `Varaverk_${d.my_id}`;
|
||||
const registry = h.is_local ? h.host_id : h.host_id;
|
||||
return `<div style="display:flex;align-items:center;gap:8px;padding:4px 0;border-bottom:1px solid #111;">
|
||||
<span style="width:6px;height:6px;border-radius:50%;background:${dot};flex-shrink:0;display:inline-block;"></span>
|
||||
<span style="font-size:11px;color:#666;flex-shrink:0;min-width:50px;">${h.host_id}</span>
|
||||
<code style="font-size:9px;color:#2a3a2a;flex-shrink:0;">${keyName}</code>
|
||||
<span style="font-size:9px;color:#2a2a2a;flex-shrink:0;">on ${registry}</span>
|
||||
${tag}
|
||||
<span style="flex:1;text-align:right;">${keyBit}</span>
|
||||
</div>`;
|
||||
}).join('');
|
||||
|
||||
Reference in New Issue
Block a user