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,
|
||||
|
||||
Reference in New Issue
Block a user