diff --git a/drb-frontend/app/settings/nodes/page.tsx b/drb-frontend/app/settings/nodes/page.tsx index 1bebcf0..88b5814 100644 --- a/drb-frontend/app/settings/nodes/page.tsx +++ b/drb-frontend/app/settings/nodes/page.tsx @@ -41,19 +41,26 @@ function EnrollmentTokensPanel() { const [justMinted, setJustMinted] = useState(null); const [cmdCopied, setCmdCopied] = useState(false); const [tokenCopied, setTokenCopied] = useState(false); + // The label the operator typed for the token that was just minted — used as + // the node id in the install command below. Captured on mint because `label` + // itself is cleared afterward. + const [mintedLabel, setMintedLabel] = useState(null); - // The paste-ready one-shot install command for a fresh Pi. node id and the - // MQTT broker host aren't known here — left as placeholders the operator - // edits. C2 URL comes from this deployment's own config; the broker is the - // documented mqtt. sibling of the api host (install.sh header). + // The paste-ready one-shot install command for a fresh Pi. The node id comes + // from the label just entered (spaces → dashes; install.sh requires + // [A-Za-z0-9_-]); if that yields nothing it falls back to a node-XXX + // placeholder. The MQTT broker host is the documented mqtt. sibling + // of the api host (install.sh header) — a DNS assumption the operator checks. const c2Url = (process.env.NEXT_PUBLIC_C2_URL ?? "https://api.example.net").replace(/\/$/, ""); const mqttBroker = (() => { try { return `mqtt.${new URL(c2Url).hostname.replace(/^api\./, "")}`; } catch { return "mqtt.example.net"; } })(); + const nodeIdForCmd = + (mintedLabel ?? "").trim().replace(/\s+/g, "-").replace(/[^A-Za-z0-9_-]/g, "") || "node-XXX"; const installCmd = justMinted ? `curl -fsSL https://git.vpn.cusano.net/logan/node-26/raw/tag/v1/install.sh \\ - | sudo bash -s -- --token ${justMinted} --node-id node-XXX \\ + | sudo bash -s -- --token ${justMinted} --node-id ${nodeIdForCmd} \\ --c2-url ${c2Url} --mqtt-broker ${mqttBroker}` : ""; @@ -74,6 +81,7 @@ function EnrollmentTokensPanel() { try { const result = await c2api.mintEnrollmentToken(label.trim()); setJustMinted(result.token); + setMintedLabel(label.trim()); setLabel(""); load(); } catch (err) { @@ -119,7 +127,10 @@ function EnrollmentTokensPanel() {

- …or run this on a fresh Pi (edit node-XXX and the broker host): + …or run this on a fresh Pi{" "} + {nodeIdForCmd === "node-XXX" + ? <>(edit node-XXX and check the broker host) + : <>(check the broker host)}:

{installCmd}
@@ -136,7 +147,7 @@ function EnrollmentTokensPanel() {