Remove orphaned API key code — correct key name format, collapse duplicate buttons

This commit is contained in:
Gmer4Lfe
2026-06-06 18:17:30 -04:00
parent dab8d62e95
commit a24f9db2ff
2 changed files with 24 additions and 48 deletions
+4 -9
View File
@@ -96,15 +96,14 @@ if ($action === 'detect' && $_SERVER['REQUEST_METHOD'] === 'POST') {
}
// ── 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();
$vars = vv_conf_vars();
$myHost = vv_detect_host();
$myId = strtoupper($myHost);
$hn = trim((string)shell_exec("hostname -s 2>/dev/null | sed 's/^[Uu][Nn][Rr][Aa][Ii][Dd]-//'")) ?: 'Varaverk';
$localKeyName = 'Varaverk ' . $hn;
$hosts = [];
foreach ($vars as $k => $v) {
@@ -113,14 +112,11 @@ 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
@@ -133,6 +129,7 @@ if ($action === 'api_status') {
echo json_encode([
'ok' => true,
'my_id' => $myId,
'key_name' => $localKeyName,
'hosts' => $hosts,
'fallbacks' => $localStatus['fallbacks'],
]);
@@ -145,11 +142,9 @@ if ($action === 'setup_apikeys' && $_SERVER['REQUEST_METHOD'] === 'POST') {
if (!file_exists($script)) {
echo json_encode(['ok' => false, 'error' => 'unraid_api_key_renew.sh not found']); exit;
}
$allHosts = ($_POST['all_hosts'] ?? '0') === '1';
$flags = $allHosts ? ' --all-hosts' : '';
set_time_limit(60);
$output = []; $exit = 0;
exec('bash ' . escapeshellarg($script) . $flags . ' 2>&1', $output, $exit);
exec('bash ' . escapeshellarg($script) . ' 2>&1', $output, $exit);
echo json_encode(['ok' => $exit === 0, 'exit' => $exit, 'output' => implode("\n", $output)]);
exit;
}