summaryrefslogtreecommitdiff
path: root/static/js/dns-wizard.js
diff options
context:
space:
mode:
authorAlexander Hunt <me@liz.coffee>2026-06-21 12:43:31 -0700
committerAlexander Hunt <me@liz.coffee>2026-06-21 12:43:31 -0700
commitcfc0d34a584254a9ed76620951c810771aff6f3b (patch)
tree7fba034f7347ce0003e7a3a56adcaf862c834907 /static/js/dns-wizard.js
parentfb653292612eddca5b088ed88466c546d1597107 (diff)
downloadpenguins.lan-cfc0d34a584254a9ed76620951c810771aff6f3b.tar.gz
penguins.lan-cfc0d34a584254a9ed76620951c810771aff6f3b.zip
STUFF
Diffstat (limited to 'static/js/dns-wizard.js')
-rw-r--r--static/js/dns-wizard.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/static/js/dns-wizard.js b/static/js/dns-wizard.js
new file mode 100644
index 0000000..2ee7162
--- /dev/null
+++ b/static/js/dns-wizard.js
@@ -0,0 +1,43 @@
+(function () {
+ const cfg = window.DNS;
+ if (!cfg) return;
+
+ const form = (obj) => {
+ const body = new URLSearchParams(obj);
+ return { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body };
+ };
+ const addRecord = (type, name, content, ttl) =>
+ fetch("/dns", form({ type, name, content, ttl: String(ttl || 300) }));
+ const setPrimary = (mac) => fetch("/profile/primary", form({ mac }));
+
+ // The wizard seeds the basics: <user>.<zone> -> primary device, plus a starter
+ // alias per device you can rename or delete later. The server replaces an
+ // existing CNAME at a name, so re-running this is safe.
+ const wiz = document.getElementById("dns-wizard");
+ if (wiz) {
+ wiz.addEventListener("click", async () => {
+ wiz.disabled = true;
+ wiz.textContent = "wiring things up…";
+ const primary = cfg.devices.find((d) => d.mac === cfg.primaryMac) || cfg.devices[0];
+ if (primary) await addRecord("CNAME", cfg.userDomain, primary.name, 300);
+ let n = 1;
+ for (const d of cfg.devices) {
+ await addRecord("CNAME", "device-" + n + "." + cfg.userDomain, d.name, 300);
+ n++;
+ }
+ location.reload();
+ });
+ }
+
+ // Picking a primary updates the stored choice and repoints <user>.<zone> at it
+ // in one go, all client-side.
+ document.querySelectorAll(".set-primary").forEach((btn) => {
+ btn.addEventListener("click", async (e) => {
+ e.preventDefault();
+ btn.disabled = true;
+ await setPrimary(btn.dataset.mac);
+ await addRecord("CNAME", cfg.userDomain, btn.dataset.name, 300);
+ location.reload();
+ });
+ });
+})();