diff --git a/karldns/web/scripts.py b/karldns/web/scripts.py index 319d41a..f716672 100644 --- a/karldns/web/scripts.py +++ b/karldns/web/scripts.py @@ -234,10 +234,48 @@ VISITOR_IP_JS = """ replaceInCopyValues(search, replacement); }; + const updateCopyCommand = (button, ipv6Command) => { + const value = button.dataset.copy || ""; + if (!value || value.includes("?myipv6=")) return; + const lines = value.split("\\n"); + const output = []; + let inserted = false; + lines.forEach((line) => { + output.push(line); + if (!inserted && line.includes("/api/v1/router/update/") && line.includes("?myip=")) { + output.push(ipv6Command); + inserted = true; + } + }); + if (inserted) button.dataset.copy = output.join("\\n"); + }; + + const insertIpv6Examples = (ip) => { + if (!ip) return; + document.querySelectorAll(".terminal-card.manual-code").forEach((card) => { + if (card.textContent.includes("?myipv6=")) return; + const lines = [...card.querySelectorAll("code")]; + const ipv4Line = lines.find((line) => line.textContent.includes("/api/v1/router/update/") && line.textContent.includes("?myip=")); + if (!ipv4Line) return; + const base = ipv4Line.textContent.split("?myip=", 1)[0].replace(/'$/, ""); + const ipv6Command = `${base}?myipv6=${ip}'`; + const code = document.createElement("code"); + code.textContent = ipv6Command; + ipv4Line.after(code); + const copyButton = card.querySelector("[data-copy]"); + if (copyButton) updateCopyCommand(copyButton, ipv6Command); + }); + }; + document.addEventListener("DOMContentLoaded", async () => { const tasks = []; if (needsIpv4()) tasks.push(fetchIp("https://api4.ipify.org?format=json").then((ip) => replaceEverywhere(ipv4Placeholder, ip))); - if (needsIpv6()) tasks.push(fetchIp("https://api6.ipify.org?format=json").then((ip) => replaceEverywhere(ipv6Placeholder, ip))); + if (needsIpv6() || document.querySelector(".terminal-card.manual-code")) { + tasks.push(fetchIp("https://api6.ipify.org?format=json").then((ip) => { + replaceEverywhere(ipv6Placeholder, ip); + insertIpv6Examples(ip); + })); + } await Promise.allSettled(tasks); }); })(); diff --git a/karldns/web/templates_management.py b/karldns/web/templates_management.py index 25357c6..7470fda 100644 --- a/karldns/web/templates_management.py +++ b/karldns/web/templates_management.py @@ -210,7 +210,7 @@ def _render_pending_management_page(

Manual updates.

Scripts can send the IP explicitly, or omit it and let KarlDNS use the request IP. Visible examples use your public IP when KarlDNS or your browser can detect it.

- {_code_window(manual_commands, copy_label="manual update commands", class_name="mt-3")} + {_code_window(manual_commands, copy_label="manual update commands", class_name="manual-code mt-3")}

Use your own DNS name.

diff --git a/karldns/web/templates_public.py b/karldns/web/templates_public.py index b4b8203..1f3a0a0 100644 --- a/karldns/web/templates_public.py +++ b/karldns/web/templates_public.py @@ -69,7 +69,7 @@ def _render_public_home(

Update from a router or script.

Works with FRITZ!Box, curl, cron, Home Assistant, OpenWrt, pfSense, OPNsense, UniFi, MikroTik, and custom tools.

- {_code_window(manual_demo, copy_label="manual update examples", class_name="text-start mt-4")} + {_code_window(manual_demo, copy_label="manual update examples", class_name="manual-code text-start mt-4")}
{_linux_installer_section(base_url)}