#!/usr/bin/env python3 """Generate self-contained RustProxy status pages with classic 3-node error layout. Visual reference: donlon/cloudflare-error-page (MIT license), without its Cloudflare logos, links, remote assets or fictitious Cloudflare diagnostics. The generated HTML is consumed using the existing include_str! page mechanism. """ from __future__ import annotations from html import escape from pathlib import Path ROOT = Path(__file__).resolve().parents[1] / "src/admin/web/cf_page" # Code, title, explanation, advice, RustProxy status label, origin status label, # RustProxy indicator, origin indicator. Indicators describe this request only; # they must never claim to have checked the upstream's health. STATUSES = [ (200, "Service ready", "RustProxy received and handled the request.", "You can continue to the requested service.", "Working", "Not checked", "ok", "unknown"), (400, "Bad request", "The request was malformed or could not be understood.", "Check the request and try again.", "Request rejected", "Not contacted", "error", "unknown"), (401, "Authentication required", "This resource requires valid credentials.", "Sign in with an authorized account and retry.", "Authentication required", "Not contacted", "error", "unknown"), (403, "Access forbidden", "Access to the requested resource is not permitted.", "Contact the website administrator if you believe this is an error.", "Access denied", "Not contacted", "error", "unknown"), (404, "Page not found", "The requested resource could not be found.", "Check the address or return to the website homepage.", "Not found", "Not confirmed", "error", "unknown"), (408, "Request timeout", "The request took too long to complete.", "Try again when your connection is stable.", "Timed out", "Not confirmed", "error", "unknown"), (410, "Resource gone", "The requested resource is no longer available.", "Update any saved links to this resource.", "No longer available", "Not contacted", "error", "unknown"), (413, "Content too large", "The request body exceeds the allowed size.", "Reduce the size of the request and try again.", "Request rejected", "Not contacted", "error", "unknown"), (429, "Too many requests", "The request rate limit has been exceeded.", "Wait a moment before trying again.", "Rate limited", "Not contacted", "error", "unknown"), (500, "Internal server error", "An unexpected error occurred while processing this request.", "Try again shortly. If the issue persists, contact the administrator.", "Error", "Not confirmed", "error", "unknown"), (502, "Bad gateway", "The gateway could not obtain a valid response from the upstream service.", "Try again in a few minutes. If the problem continues, contact the administrator.", "Working", "Connection error", "ok", "error"), (503, "Service unavailable", "The service is temporarily unable to handle this request.", "Please try again in a few minutes.", "Temporarily unavailable", "Not confirmed", "error", "unknown"), (504, "Gateway timeout", "The upstream service did not respond in time.", "Try again shortly. If the problem continues, contact the administrator.", "Working", "Timed out", "ok", "error"), ] CSS = """ :root {color-scheme:light;font-family:-apple-system,BlinkMacSystemFont,"Helvetica Neue",Helvetica,Arial,sans-serif;color:#333} * {box-sizing:border-box} body {margin:0;background:#fff;min-height:100vh;font-size:15px;line-height:1.5;-webkit-font-smoothing:antialiased} .container {max-width:1030px;margin:0 auto;padding:0 24px} .intro {padding:54px 0 44px} h1 {font-size:49px;line-height:1.18;font-weight:300;margin:0 0 5px;letter-spacing:-1.1px;color:#313131} .error-code {font-weight:300;color:#8d8d8d} .subtitle {font-weight:300;font-size:25px;line-height:1.4;margin:2px 0;color:#777} .diagnostics-band {background:#f1f1f1;border-top:1px solid #e9e9e9;border-bottom:1px solid #e5e5e5} .diagnostics {display:grid;grid-template-columns:minmax(0,1fr) 76px minmax(0,1fr) 76px minmax(0,1fr);align-items:start;padding:39px 0 36px;text-align:center} .node {min-width:0;text-align:center} .symbol {height:107px;position:relative;margin:0 auto 11px;width:142px;max-width:100%;display:flex;align-items:center;justify-content:center} .symbol svg {width:118px;height:100px;display:block;overflow:visible} .symbol .ind {position:absolute;right:10px;bottom:10px;display:grid;place-items:center;border:3px solid #f1f1f1;border-radius:50%;height:37px;width:37px;font-family:Arial,sans-serif;font-size:24px;font-weight:700;line-height:1;color:white;background:#9bca3e} .symbol .ind.error {background:#c93135} .symbol .ind.unknown {background:#aaa;font-weight:500;font-size:26px} .location {font-size:14px;color:#a2a2a2;margin:0;overflow-wrap:anywhere} .node h2 {font-size:21px;font-weight:400;margin:1px 0 0;color:#545454;overflow-wrap:anywhere} .state {font-size:16px;font-weight:500;margin:2px 0 0;color:#8cbb35;overflow-wrap:anywhere} .state.error {color:#c93135} .state.unknown {color:#888} .connector {padding-top:53px;min-width:0;color:#aaa} .connector svg {height:30px;width:100%;display:block;fill:none;stroke:currentColor;stroke-width:4;stroke-linecap:round;stroke-linejoin:round} .help {display:grid;grid-template-columns:1fr 1fr;gap:58px;padding:41px 0 45px} .help h2 {font-size:20px;line-height:1.35;font-weight:400;color:#333;margin:0 0 12px} .help p {font-size:15px;line-height:1.6;margin:0;color:#555} .bottom {border-top:1px solid #e7e7e7;margin-top:7px;padding:22px 0 35px;display:flex;align-items:center;justify-content:space-between;gap:14px;color:#999;font-size:12px} .brand {color:#858585;font-weight:600;letter-spacing:.02em} .bottom .signature {font-size:12px} @media(max-width:700px) { .intro {padding:35px 0 30px}h1{font-size:36px;letter-spacing:-.7px}.subtitle{font-size:20px} .diagnostics{grid-template-columns:repeat(3,minmax(0,1fr));padding:25px 0;gap:4px} .connector{display:none}.symbol{height:76px;width:86px;margin-bottom:6px}.symbol svg{width:77px;height:70px} .symbol .ind{width:28px;height:28px;font-size:18px;border-width:2px;right:0;bottom:1px} .symbol .ind.unknown{font-size:21px}.location{font-size:12px}.node h2{font-size:15px}.state{font-size:13px} .help{grid-template-columns:1fr;gap:24px;padding:31px 0}.bottom{flex-wrap:wrap} } @media(max-width:360px){.container{padding:0 14px}.intro{padding-top:27px}h1{font-size:31px}.symbol{width:70px}.symbol svg{width:69px}.node h2{font-size:14px}.state{font-size:12px}} """.strip() ICONS = { "browser": '''''', "proxy": '''''', "origin": '''''', } def node(icon: str, location: str, title: str, state: str, indicator: str) -> str: indicator_glyph = {"ok": "✓", "error": "×", "unknown": "–"}[indicator] return ( f'
{ICONS[icon]}' f'
' f'

{escape(location)}

{escape(title)}

' f'

{escape(state)}

' ) def make_page(code: int, title: str, happened: str, advice: str, gateway: str, origin: str, gateway_indicator: str, origin_indicator: str) -> str: arrow = '' return f''' Error {code}: {escape(title)} | RustProxy

{escape(title)} Error {code}

Error code {code}

{node('browser', 'You', 'Browser', 'Working', 'ok')} {arrow} {node('proxy', 'Gateway', 'RustProxy', gateway, gateway_indicator)} {arrow} {node('origin', 'Origin', 'Host', origin, origin_indicator)}

What happened?

{escape(happened)}

What can I do?

{escape(advice)}

''' def main() -> None: ROOT.mkdir(parents=True, exist_ok=True) for entry in STATUSES: path = ROOT / f"error_{entry[0]}.html" path.write_text(make_page(*entry), encoding="utf-8") print(f"Generated {len(STATUSES)} offline RustProxy-branded status pages") if __name__ == "__main__": main()