from __future__ import annotations from .html_utils import SafeHtml, attr, escape, join_html, trusted 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('DocsAPI') account_html += 'Generate' theme_toggle = '' return trusted( f""" """ ) 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'' if is_secret else "" ) return trusted( f"""
{safe_label}{badge} {value_field} {reveal_button}
""" ) def _copy_button(label: str, value: str) -> SafeHtml: safe_label = escape(label) safe_value = attr(value) return trusted(f'') 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}'", ] ) def _manual_update_panel(commands: str) -> SafeHtml: safe_commands = escape(commands) return trusted( f"""

Manual updates

FRITZ!Box replaces <ipaddr> and <ip6addr>, then sends a GET request to the Update-URL. Scripts and other routers can do the same with curl. If no IP parameter is sent, KarlDNS uses the request source IP.

{safe_commands}
{_copy_button("Copy curl examples", commands)}
""" ) 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 status page: {management_url}") return "\n".join(lines) def _secret_notice() -> SafeHtml: return trusted( """
Public: Domainnamen and CNAME target can be shared in DNS. Secret: Update-URL, one-box update URL, optional Kennwort, private dashboard URL, and domain claim links control the hostname. Secrets are hidden by default on screen; Copy still copies the real value.
""" ) def _one_time_secret_notice() -> SafeHtml: return trusted( """ """ ) def _message_band(message: str | None) -> SafeHtml: if not message: return trusted("") return trusted( f"""
{escape(message)}
""" ) def _site_footer() -> SafeHtml: return trusted( """ """ ) def _page(title: str, body: SafeHtml) -> str: if not isinstance(body, SafeHtml): raise TypeError("body must be a SafeHtml fragment built by a template helper") return f""" {escape(title)} {body}{_site_footer()} """ __all__ = [ "SafeHtml", "_copy_button", "_copy_row", "_fritzbox_fields", "_manual_update_commands", "_manual_update_panel", "_message_band", "_one_time_secret_notice", "_page", "_secret_notice", "_top_nav", "join_html", "trusted", ]