diff --git a/auth/lib.php b/auth/lib.php index c0ba89b..5958230 100644 --- a/auth/lib.php +++ b/auth/lib.php @@ -303,7 +303,9 @@ function reflector_ca(string $sub, string $cs): true|string { $sub = strtoupper($sub); if (!in_array($sub, ['SIGN', 'RM'], true)) return 'bad CA subcommand'; if (!node_callsign_path_safe($cs) || preg_match('/\s/', $cs)) return 'bad callsign'; - $cmd = 'sudo -u svxlink /usr/local/sbin/svxreflector-pty CA ' . escapeshellarg($sub) . ' ' . escapeshellarg($cs); + // -w: wait for the reflector's reply so we return only once the command has + // actually been processed (cert files signed/removed), instead of racing it. + $cmd = 'sudo -u svxlink /usr/local/sbin/svxreflector-pty -w CA ' . escapeshellarg($sub) . ' ' . escapeshellarg($cs); exec($cmd . ' 2>&1', $out, $rc); return $rc === 0 ? true : (implode("\n", $out) ?: 'PTY write failed'); } diff --git a/auth/node_auth_api.php b/auth/node_auth_api.php index 5440f29..611abfc 100644 --- a/auth/node_auth_api.php +++ b/auth/node_auth_api.php @@ -236,14 +236,20 @@ switch ($action) { if ($r !== true) json_out(['ok' => false, 'error' => 'revoke_failed', 'detail' => $r], 502); json_out(['ok' => true, 'node' => $cs]); - // ---- Delete certificate — PERMANENT full removal (lvl2-3 site admins only, - // NOT callsign-admins). Removes the signed cert + any pending CSR, resets the - // renewal counters and clears node-admin membership so nothing can re-issue. ---- + // ---- Delete certificate — PERMANENT full removal. Allowed for a site admin + // (lvl >= 2) OR the node's own owner (callsign match, node-admin membership, + // verified cert email) so a user can clean up a cert they no longer use. + // Removes the signed cert + any pending CSR, resets the renewal counters and + // clears node-admin membership so nothing can re-issue. ---- case 'delete_cert': $cs = require_node($in); - if (acct_admin_level($uuid) < 2) json_out(['ok' => false, 'error' => 'admin2_required'], 403); + if (acct_admin_level($uuid) < 2 && !$view_owns($cs)) + json_out(['ok' => false, 'error' => 'not_your_cert'], 403); $ce = node_cert_email($cs); if (is_file(pki_certs_dir() . "/{$cs}.crt")) { + // reflector_ca() now blocks until the reflector confirms removal on + // the PTY ("OK"), so the cert files are already gone when it returns + // — no need to poll the filesystem. $r = reflector_ca('RM', $cs); if ($r !== true) json_out(['ok' => false, 'error' => 'delete_failed', 'detail' => $r], 502); } @@ -311,10 +317,12 @@ switch ($action) { } json_out(['ok' => true, 'node' => $cs, 'linked_via' => $linked_via, 'account' => $account]); - // ---- Remove a password node (site admin only) ---- + // ---- Remove a password node — site admin OR the node's own owner, so a + // user can delete a reflector login they no longer use. ---- case 'del': - if (!$is_admin) json_out(['ok' => false, 'error' => 'forbidden'], 403); $cs = require_node($in); + if (!$is_admin && !$view_owns($cs)) + json_out(['ok' => false, 'error' => 'not_your_node'], 403); [$rc, $out] = users_ctl('del', $cs); if ($rc !== 0) json_out(['ok' => false, 'error' => 'del_failed', 'detail' => $out], 502); // Keep the admin list if the node still exists via a cert. diff --git a/auth/profile_nodes.js b/auth/profile_nodes.js index 065ca25..0f276ea 100644 --- a/auth/profile_nodes.js +++ b/auth/profile_nodes.js @@ -393,6 +393,25 @@ function loadNodeAuth() { }); actCell.appendChild(btn); } + + // Delete — permanently remove EVERYTHING for this node you no longer use: + // the certificate (including an expired one), any pending request, the + // renewal history, node admins and the password login — in one go. + var delBtn = document.createElement('button'); + delBtn.type = 'button'; delBtn.className = 'btn btn-sm btn-outline-danger py-0 ms-1'; + delBtn.style.fontSize = '.75rem'; delBtn.textContent = 'Delete'; + delBtn.addEventListener('click', function () { + if (!confirm('Permanently delete ' + n.node + '?\nThis removes its certificate (even if expired), renewal history, node admins and password login. This cannot be undone.')) return; + delBtn.disabled = true; + var chain = Promise.resolve({ ok: true }); + if (n.password) chain = chain.then(function (r) { return (r && r.ok) ? nauthApi({ action: 'del', node: n.node }) : r; }); + if (n.cert) chain = chain.then(function (r) { return (r && r.ok) ? nauthApi({ action: 'delete_cert', node: n.node }) : r; }); + chain.then(function (r) { + if (r && r.ok) { nodeSecLoaded = false; loadNodeAuth(); } + else { delBtn.disabled = false; alert((r && (r.detail || r.error)) || 'Failed'); } + }); + }); + actCell.appendChild(delBtn); }); // Pending certificate requests — a node reconnecting after its cert was