from __future__ import annotations
import json
from .html_utils import SafeHtml, attr, escape, join_html, trusted
def _svg_icon(name: str, css_class: str = "copy-icon") -> SafeHtml:
if name == "check":
path = ' '
elif name == "more":
path = (
' '
)
else:
path = (
' '
)
return trusted(
f'{path} '
)
def _top_nav(label: str | None = None, links: SafeHtml | None = None) -> SafeHtml:
account_html = ""
if label:
account_html = f'{escape(label)} '
if links is None:
links = trusted('Docs API ')
theme_toggle = """
"""
return trusted(
f"""
Skip to content
KarlDNS
{links}
{account_html}
{theme_toggle}
"""
)
def _copy_row(label: str, value: str, sensitivity: str | None = None) -> SafeHtml:
safe_label = escape(label)
safe_value = escape(value)
badge = ""
is_secret = bool(sensitivity and sensitivity.lower() == "secret")
if sensitivity:
safe_sensitivity = escape(sensitivity)
badge_class = "text-bg-warning" if is_secret else "text-bg-secondary"
badge = f'{safe_sensitivity} '
value_field = (
f' '
if is_secret
else f'{safe_value}'
)
reveal_button = (
f'View '
if is_secret
else ""
)
return trusted(
f"""
{_copy_icon_button(copy_label, commands)}
{code_lines}
"""
)
def _manual_update_commands(update_url: str) -> str:
update_base = update_url.split("?", 1)[0]
return "\n".join(
[
f"curl -sS '{update_base}?myip=203.0.113.10'",
f"curl -sS '{update_base}?myipv6=2001:db8::10'",
f"curl -sS '{update_base}' # use request IP",
]
)
def _manual_update_panel(commands: str) -> SafeHtml:
return trusted(
f"""
Manual updates
FRITZ!Box fills in the IP placeholders automatically. Scripts can use curl. If no IP is sent, KarlDNS uses the request IP.
{_code_window(commands, copy_label="manual update commands", class_name="manual-code")}
"""
)
def _fritzbox_fields(
update_url: str,
hostname: str,
username: str,
password: str,
management_url: str | None = None,
) -> str:
lines = [
f"Update-URL: {update_url}",
f"Domainnamen: {hostname}",
f"CNAME target: {hostname}",
f"Benutzername: {username}",
f"Kennwort: {password}",
]
if management_url:
lines.append(f"Private dashboard: {management_url}")
return "\n".join(lines)
def _secret_notice() -> SafeHtml:
return trusted(
"""
Copy the router password and full update URL now. They are only shown when created or rotated.
"""
)
def _message_band(message: str | None) -> SafeHtml:
if not message:
return trusted("")
return trusted(
f"""