diff --git a/Plugin/unraid/api/storage.php b/Plugin/unraid/api/storage.php index 4497af8..45248e1 100644 --- a/Plugin/unraid/api/storage.php +++ b/Plugin/unraid/api/storage.php @@ -95,4 +95,37 @@ if ($action === 'detect' && $_SERVER['REQUEST_METHOD'] === 'POST') { exit; } +// ── Unraid API key status ───────────────────────────────────────────────────── +if ($action === 'api_status') { + require_once dirname(__DIR__) . '/include/unraid_api.php'; + $data = vv_api_data(); + $status = vv_api_get_status(); + $vars = vv_conf_vars(); + $myHost = vv_detect_host(); + $keyVar = strtoupper($myHost) . '_UNRAID_API_KEY'; + $key = $vars[$keyVar] ?? ''; + echo json_encode([ + 'ok' => true, + 'key_present' => !empty($key), + 'key_preview' => $key ? substr($key, 0, 8) . '...' . substr($key, -4) : null, + 'api_ok' => !empty($key) && !$status['key_missing'] && $status['available'], + 'key_missing' => $status['key_missing'], + 'fallbacks' => $status['fallbacks'], + ]); + exit; +} + +// ── Renew Unraid API key ────────────────────────────────────────────────────── +if ($action === 'renew_apikey' && $_SERVER['REQUEST_METHOD'] === 'POST') { + $script = SCRIPTS_DIR . '/unRAID_Essentials/unraid_api_key_renew.sh'; + if (!file_exists($script)) { + echo json_encode(['ok' => false, 'error' => 'unraid_api_key_renew.sh not found']); exit; + } + set_time_limit(30); + $output = []; $exit = 0; + exec('bash ' . escapeshellarg($script) . ' 2>&1', $output, $exit); + echo json_encode(['ok' => $exit === 0, 'exit' => $exit, 'output' => implode("\n", $output)]); + exit; +} + echo json_encode(['ok' => false, 'error' => 'Unknown action']); diff --git a/Plugin/unraid/pages/settings.php b/Plugin/unraid/pages/settings.php index e28494a..1ccdbc5 100644 --- a/Plugin/unraid/pages/settings.php +++ b/Plugin/unraid/pages/settings.php @@ -1,8 +1,22 @@
= htmlspecialchars($_apiPreview) ?>
+ · Var: = htmlspecialchars($_apiKeyVar) ?>
+
+ No key found in = htmlspecialchars($_myHost) ?>.conf — click Renew to register one.
+
+ unraid_api_key_renew.sh
+ runs at array start to auto-recover, but if the monitor page shows API errors, renew here.
+