This commit is contained in:
Mateusz Gruszczyński committed 2026-11-26 15:19:21 +01:00
1 parent a75893d428
commit bfbeedfad7
43 files changed
+5834 -125

No files matched your search

+131
View File
@@ -0,0 +1,131 @@
#!/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": '''<svg viewBox="0 0 120 106" aria-hidden="true" focusable="false"><rect x="13" y="16" width="94" height="69" rx="4" fill="#aaa"/><rect x="21" y="33" width="78" height="44" fill="#f1f1f1"/><circle cx="23" cy="24" r="3" fill="#f1f1f1"/><circle cx="34" cy="24" r="3" fill="#f1f1f1"/><path d="M14 31h93" stroke="#f1f1f1" stroke-width="2"/></svg>''',
"proxy": '''<svg viewBox="0 0 120 106" aria-hidden="true" focusable="false"><path d="M60 9 103 33v45L60 101 17 78V33Z" fill="#aaa"/><path d="M60 21 91 39v32L60 88 29 71V39Z" fill="#f1f1f1"/><text x="60" y="67" text-anchor="middle" font-size="37" font-weight="700" font-family="Arial,sans-serif" fill="#888">RP</text></svg>''',
"origin": '''<svg viewBox="0 0 120 106" aria-hidden="true" focusable="false"><rect x="22" y="13" width="76" height="27" rx="4" fill="#aaa"/><rect x="22" y="46" width="76" height="27" rx="4" fill="#aaa"/><circle cx="34" cy="27" r="4" fill="#f1f1f1"/><circle cx="34" cy="60" r="4" fill="#f1f1f1"/><path d="M48 27h38M48 60h38" stroke="#d9d9d9" stroke-width="4" stroke-linecap="round"/><path d="M60 73v14m-21 0h42" stroke="#aaa" stroke-width="7" stroke-linecap="round"/></svg>''',
}
def node(icon: str, location: str, title: str, state: str, indicator: str) -> str:
indicator_glyph = {"ok": "&#10003;", "error": "&#215;", "unknown": "&#8211;"}[indicator]
return (
f'<div class="node"><div class="symbol">{ICONS[icon]}'
f'<span class="ind {indicator}" aria-hidden="true">{indicator_glyph}</span></div>'
f'<p class="location">{escape(location)}</p><h2>{escape(title)}</h2>'
f'<p class="state {indicator}">{escape(state)}</p></div>'
)
def make_page(code: int, title: str, happened: str, advice: str, gateway: str, origin: str,
gateway_indicator: str, origin_indicator: str) -> str:
arrow = '<div class="connector" aria-hidden="true"><svg viewBox="0 0 100 30"><path d="M8 15h84m-74-10L8 15l10 10M82 5l10 10-10 10"/></svg></div>'
return f'''<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex,nofollow">
<title>Error {code}: {escape(title)} | RustProxy</title>
<style>{CSS}</style>
</head>
<body>
<header class="container intro"><h1>{escape(title)} <span class="error-code">Error {code}</span></h1><p class="subtitle">Error code {code}</p></header>
<section class="diagnostics-band" aria-label="Request status"><div class="container diagnostics">
{node('browser', 'You', 'Browser', 'Working', 'ok')}
{arrow}
{node('proxy', 'Gateway', 'RustProxy', gateway, gateway_indicator)}
{arrow}
{node('origin', 'Origin', 'Host', origin, origin_indicator)}
</div></section>
<main class="container"><section class="help" aria-label="Error information">
<div><h2>What happened?</h2><p>{escape(happened)}</p></div>
<div><h2>What can I do?</h2><p>{escape(advice)}</p></div>
</section><footer class="bottom"><span class="brand">RustProxy</span><span class="signature">Performance &amp; security by RustProxy</span></footer>
</main>
</body>
</html>
'''
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()