v0.42.3
This commit is contained in:
1 parent
bfbeedfad7
commit
385db5dfcf
35 files changed
+1131
-5065
No files matched your search
@@ -9,13 +9,17 @@ from __future__ import annotations
|
||||
from html import escape
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1] / "src/admin/web/cf_page"
|
||||
WEB = Path(__file__).resolve().parents[1] / "src/admin/web"
|
||||
ROOT = WEB / "cf_page"
|
||||
# Use the exact dashboard brand mark: r / p with the same span structure,
|
||||
# typography, dimensions and border styles as css/20-shell.css.
|
||||
LOGO = '<span class="brand-mark" aria-label="RustProxy">r<span>/</span>p</span>'
|
||||
|
||||
# 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"),
|
||||
(200, "Service ready", "RustProxy received and handled the request.", "No further action is required for this response.", "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"),
|
||||
@@ -35,45 +39,49 @@ CSS = """
|
||||
* {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}
|
||||
.intro {padding:54px 24px 44px}
|
||||
h1 {font-size:46px;line-height:1.2;font-weight:300;margin:0;letter-spacing:-1.1px;color:#313131;overflow-wrap:anywhere}
|
||||
.status-code {font-weight:300;color:#737373;white-space:nowrap}
|
||||
.eyebrow {font-size:12px;letter-spacing:.12em;text-transform:uppercase;font-weight:600;color:#686868;margin:0 0 12px}
|
||||
.success .eyebrow {color:#527b24}
|
||||
.placeholder .eyebrow {color:#686868}
|
||||
.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}
|
||||
.diagnostics {display:grid;grid-template-columns:minmax(0,1fr) 76px minmax(0,1fr) 76px minmax(0,1fr);align-items:start;padding:39px 24px 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}
|
||||
/* Dashboard brand mark, matching css/20-shell.css (standalone page colors). */
|
||||
.symbol .brand-mark {font:700 33px ui-monospace,SFMono-Regular,Consolas,monospace;border:1px solid #f69b74;color:#f69b74;place-content:center;position:relative;box-sizing:border-box;padding-right:2px;display:flex;align-items:center;justify-content:center;letter-spacing:-3px;flex-shrink:0;width:47px;height:47px;font-size:29px}
|
||||
.symbol .brand-mark span {font-size:22px;left:29px;top:19px;color:#cfe0ac;position:static}
|
||||
.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}
|
||||
.location {font-size:14px;color:#676767;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 {font-size:16px;font-weight:500;margin:2px 0 0;color:#527b24;overflow-wrap:anywhere}
|
||||
.state.error {color:#c93135}
|
||||
.state.unknown {color:#888}
|
||||
.state.unknown {color:#666}
|
||||
.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}
|
||||
.bottom {border-top:1px solid #e7e7e7;margin-top:7px;padding:22px 0 35px;color:#666;font-size:12px;text-align:center}
|
||||
.brand {color:#454545;font-weight:600;letter-spacing:.02em}
|
||||
@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}
|
||||
.intro {padding:35px 24px 30px}h1{font-size:36px;letter-spacing:-.7px}
|
||||
.diagnostics{grid-template-columns:repeat(3,minmax(0,1fr));padding:25px 14px;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}
|
||||
.help{grid-template-columns:1fr;gap:24px;padding:31px 0}
|
||||
}
|
||||
@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}}
|
||||
@media(max-width:360px){.container{padding-inline: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>''',
|
||||
"proxy": LOGO,
|
||||
"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>''',
|
||||
}
|
||||
|
||||
@@ -88,43 +96,64 @@ def node(icon: str, location: str, title: str, state: str, indicator: str) -> st
|
||||
)
|
||||
|
||||
|
||||
def make_page(code: int, title: str, happened: str, advice: str, gateway: str, origin: str,
|
||||
gateway_indicator: str, origin_indicator: str) -> str:
|
||||
def make_page(code: int | None, title: str, happened: str, advice: str, gateway: str, origin: str,
|
||||
gateway_indicator: str, origin_indicator: str, *, variant: str = "status") -> 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>'
|
||||
is_error = code is not None and code >= 400
|
||||
theme = "error" if is_error else "placeholder" if variant == "placeholder" else "success"
|
||||
status = f"Error {code}" if is_error else f"HTTP {code}" if code is not None else ""
|
||||
code_markup = f' <span class="status-code">{status}</span>' if status else ""
|
||||
eyebrow = {"welcome": "Welcome", "placeholder": "Placeholder", "status": "Request status"}[variant]
|
||||
heading = "What happened?" if is_error else "About this page"
|
||||
next_heading = "What can I do?" if is_error else "What comes next?"
|
||||
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>
|
||||
<title>{escape(title)}{f' | {status}' if status else ''} | 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>
|
||||
<body class="{theme}">
|
||||
<header class="container intro"><p class="eyebrow">{eyebrow}</p><h1>{escape(title)}{code_markup}</h1></header>
|
||||
<section class="diagnostics-band" aria-label="Request status"><div class="container diagnostics">
|
||||
{node('browser', 'You', 'Browser', 'Working', 'ok')}
|
||||
{node('browser', 'You', 'Browser', 'Request sent', '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 & security by RustProxy</span></footer>
|
||||
<main class="container"><section class="help" aria-label="Response information">
|
||||
<div><h2>{heading}</h2><p>{escape(happened)}</p></div>
|
||||
<div><h2>{next_heading}</h2><p>{escape(advice)}</p></div>
|
||||
</section><footer class="bottom">Powered by <span class="brand">RustProxy</span></footer>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
'''
|
||||
|
||||
|
||||
VARIANTS = [
|
||||
("welcome", "Congratulations! RustProxy is running.",
|
||||
"RustProxy is installed and serving this page. This does not verify an upstream application.",
|
||||
"The administrator can configure a domain and backend or publish a local web service.",
|
||||
"Ready", "Not checked", "ok", "unknown"),
|
||||
("placeholder", "Site placeholder",
|
||||
"This address is displaying a RustProxy placeholder instead of application content.",
|
||||
"Check the address or contact the administrator for information about this service.",
|
||||
"Page served", "Not checked", "ok", "unknown"),
|
||||
]
|
||||
|
||||
|
||||
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")
|
||||
for variant, *entry in VARIANTS:
|
||||
(ROOT / f"{variant}.html").write_text(make_page(None, *entry, variant=variant), encoding="utf-8")
|
||||
print(f"Generated {len(STATUSES) + len(VARIANTS)} offline RustProxy-branded pages")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user