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
+20 -39
View File
@@ -13,10 +13,6 @@ $_enableLogging = ($_vars['ENABLE_LOGGING'] ?? 'false') === 'true';
$_discordKey = $_myId . '_DISCORD_WEBHOOK';
$_discordHook = $_vars[$_discordKey] ?? '';
// API key
$_apiKeyVar = $_myId . '_UNRAID_API_KEY';
$_apiKey = $_vars[$_apiKeyVar] ?? '';
$_apiPreview = $_apiKey ? substr($_apiKey, 0, 8) . '...' . substr($_apiKey, -4) : '';
?>
<style>
.vv-set-card { background:#161616;border:1px solid #2a2a2a;border-radius:6px;padding:14px 16px;margin-bottom:14px; }
@@ -152,18 +148,15 @@ $_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
<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>
Each host registers its key in the local Unraid registry and pushes it to all partners over SSH.
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;">
<button class="vv-set-btn" onclick="vvApiCheck()" id="vv-api-check-btn">↻ Check status</button>
<button class="vv-set-btn" onclick="vvApiRenew(false)" id="vv-api-local-btn">Renew local</button>
<button class="vv-set-btn primary" onclick="vvApiRenew(true)" id="vv-api-all-btn">Setup all host keys</button>
<button class="vv-set-btn primary" onclick="vvApiRenew()" id="vv-api-renew-btn">Renew</button>
<span id="vv-api-fb" style="font-size:11px;color:#444;"></span>
</div>
<pre class="vv-set-out" id="vv-api-out"></pre>
@@ -345,7 +338,7 @@ function vvApiCheck() {
.then(d => {
btn.disabled = false; btn.textContent = '↻ Check status';
if (!d.ok) return;
const allOk = d.hosts.every(h => h.api_ok);
const allOk = d.hosts.every(h => h.api_ok);
const anyMissing = d.hosts.some(h => !h.key_present);
badge.textContent = allOk ? 'all ok' : anyMissing ? 'keys missing' : 'partial';
badge.className = 'vv-set-badge ' + (allOk ? 'internal' : 'flash');
@@ -356,16 +349,12 @@ function vvApiCheck() {
: `<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 — 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;
: `<span style="color:#8b2a2a;font-size:10px;">not set — click Renew</span>`;
const dot = h.api_ok ? '#4caf50' : (h.key_present ? '#ffb74d' : '#444');
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>
<code style="font-size:9px;color:#2a3a2a;flex-shrink:0;">${h.is_local ? d.key_name : h.key_var}</code>
${tag}
<span style="flex:1;text-align:right;">${keyBit}</span>
</div>`;
@@ -374,36 +363,28 @@ function vvApiCheck() {
.catch(() => { btn.disabled = false; btn.textContent = '↻ Check status'; });
}
function vvApiRenew(allHosts) {
const localBtn = document.getElementById('vv-api-local-btn');
const allBtn = document.getElementById('vv-api-all-btn');
const out = document.getElementById('vv-api-out');
const fb = document.getElementById('vv-api-fb');
const badge = document.getElementById('vv-api-badge');
const activeBtn = allHosts ? allBtn : localBtn;
[localBtn, allBtn].forEach(b => { if(b) b.disabled = true; });
activeBtn.textContent = allHosts ? 'Setting up…' : 'Renewing…';
function vvApiRenew() {
const btn = document.getElementById('vv-api-renew-btn');
const out = document.getElementById('vv-api-out');
const fb = document.getElementById('vv-api-fb');
const badge = document.getElementById('vv-api-badge');
btn.disabled = true; btn.textContent = 'Renewing…';
fb.textContent = ''; out.textContent = ''; out.style.display = '';
const fd = new FormData();
fd.append('action', 'setup_apikeys');
fd.append('all_hosts', allHosts ? '1' : '0');
fd.append('action', 'setup_apikeys');
fetch('/plugins/varaverk/api/storage.php', { method: 'POST', body: fd })
.then(r => r.json())
.then(d => {
localBtn.disabled = false; localBtn.textContent = 'Renew local';
allBtn.disabled = false; allBtn.textContent = 'Setup all host keys';
out.textContent = d.output || '(no output)';
out.scrollTop = out.scrollHeight;
fb.style.color = d.ok ? '#4caf50' : '#ef5350';
fb.textContent = d.ok ? '✓ Done' : 'Failed — see output';
btn.disabled = false; btn.textContent = 'Renew';
out.textContent = d.output || '(no output)';
out.scrollTop = out.scrollHeight;
fb.style.color = d.ok ? '#4caf50' : '#ef5350';
fb.textContent = d.ok ? '✓ Done' : 'Failed — see output';
if (d.ok) { badge.textContent = ''; vvApiCheck(); }
})
.catch(() => {
localBtn.disabled = false; localBtn.textContent = 'Renew local';
allBtn.disabled = false; allBtn.textContent = 'Setup all host keys';
btn.disabled = false; btn.textContent = 'Renew';
fb.style.color = '#ef5350'; fb.textContent = 'Request failed';
});
}