feat: redesign 429 Too Many Requests page with live countdown timer

This commit is contained in:
2026-06-14 07:44:08 -04:00
parent a5eb101d98
commit 142fe304c9

View File

@@ -74,7 +74,211 @@ class RateLimitMiddleware
http_response_code(429);
header("Retry-After: {$retryAfter}");
echo '<h1>429 Too Many Requests</h1><p>Please wait ' . ceil($retryAfter / 60) . ' minutes before trying again.</p>';
$retryMinutes = (int) ceil($retryAfter / 60);
$retryAfterMs = $retryAfter * 1000;
$requestUri = htmlspecialchars($_SERVER['REQUEST_URI'] ?? '/', ENT_QUOTES, 'UTF-8');
echo <<<HTML
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>429 Too Many Requests — ServerManager</title>
<link rel="icon" type="image/svg+xml" href="/assets/img/server.svg">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
--bg-primary: #0a0c10;
--bg-secondary: #111318;
--accent: #6366f1;
--accent-hover: #818cf8;
--text-primary: #e1e4ed;
--text-muted: #7a7f8e;
--border-color: #1e2030;
--warning: #f59e0b;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
padding: 1rem;
overflow: hidden;
}
.rate-limit-card {
text-align: center;
max-width: 440px;
width: 100%;
animation: fadeIn 0.5s ease-out;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.icon-shield {
width: 80px; height: 80px;
margin: 0 auto 1.5rem;
background: radial-gradient(circle, rgba(245,158,11,0.12) 0%, transparent 70%);
display: flex; align-items: center; justify-content: center;
border-radius: 50%;
font-size: 2.4rem;
color: var(--warning);
animation: pulse 2s infinite ease-in-out;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.error-code {
font-size: 5rem;
font-weight: 800;
background: linear-gradient(135deg, var(--warning), #f97316);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
line-height: 1;
margin-bottom: 0.5rem;
}
.error-title {
font-size: 1.3rem;
font-weight: 600;
margin-bottom: 0.75rem;
}
.error-desc {
color: var(--text-muted);
font-size: 0.92rem;
line-height: 1.6;
margin-bottom: 1.5rem;
}
.countdown-box {
background: var(--bg-secondary);
border: 1px solid var(--border-color);
border-radius: 12px;
padding: 1.25rem;
margin-bottom: 1.5rem;
}
.countdown-label {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--text-muted);
margin-bottom: 0.5rem;
}
.countdown-timer {
font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
font-size: 2.4rem;
font-weight: 700;
color: var(--warning);
letter-spacing: 0.04em;
}
.countdown-bar {
width: 100%;
height: 4px;
background: var(--border-color);
border-radius: 2px;
margin-top: 0.75rem;
overflow: hidden;
}
.countdown-bar-fill {
height: 100%;
background: linear-gradient(90deg, var(--warning), #f97316);
border-radius: 2px;
width: 100%;
transition: width 1s linear;
}
.btn-primary {
display: inline-flex;
align-items: center;
gap: 0.5rem;
padding: 0.75rem 2rem;
background: linear-gradient(135deg, var(--accent), #818cf8);
color: #fff;
border: none;
border-radius: 8px;
font-size: 0.9rem;
font-weight: 600;
cursor: pointer;
text-decoration: none;
transition: all 0.2s ease;
opacity: 0.4;
pointer-events: none;
}
.btn-primary.active {
opacity: 1;
pointer-events: auto;
}
.btn-primary.active:hover {
transform: translateY(-1px);
box-shadow: 0 4px 20px rgba(99,102,241,0.3);
}
.btn-secondary {
display: inline-flex;
align-items: center;
gap: 0.5rem;
padding: 0.75rem 1.5rem;
background: transparent;
color: var(--text-muted);
border: 1px solid var(--border-color);
border-radius: 8px;
font-size: 0.85rem;
cursor: pointer;
text-decoration: none;
transition: all 0.2s ease;
margin-top: 1rem;
}
.btn-secondary:hover {
color: var(--text-primary);
border-color: var(--text-muted);
}
</style>
</head>
<body>
<div class="rate-limit-card">
<div class="icon-shield"><i class="fas fa-shield-halved"></i></div>
<div class="error-code">429</div>
<div class="error-title">Too Many Requests</div>
<div class="error-desc">You have made too many requests in a short period. Please wait before trying again.</div>
<div class="countdown-box">
<div class="countdown-label">Retry in</div>
<div class="countdown-timer" id="countdown">{$retryMinutes}:00</div>
<div class="countdown-bar"><div class="countdown-bar-fill" id="progressBar"></div></div>
</div>
<a href="{$requestUri}" class="btn-primary" id="retryBtn"><i class="fas fa-rotate-right"></i> Try Again</a>
<br>
<a href="/dashboard" class="btn-secondary"><i class="fas fa-gauge-high"></i> Go to Dashboard</a>
</div>
<script>
(function() {
var total = {$retryAfterMs};
var remaining = total;
var el = document.getElementById('countdown');
var bar = document.getElementById('progressBar');
var btn = document.getElementById('retryBtn');
var start = Date.now();
function tick() {
var elapsed = Date.now() - start;
remaining = Math.max(0, total - elapsed);
var secs = Math.ceil(remaining / 1000);
var m = Math.floor(secs / 60);
var s = secs % 60;
el.textContent = m + ':' + (s < 10 ? '0' : '') + s;
bar.style.width = (remaining / total * 100) + '%';
if (remaining <= 0) {
el.textContent = '0:00';
bar.style.width = '0%';
btn.classList.add('active');
return;
}
requestAnimationFrame(tick);
}
requestAnimationFrame(tick);
})();
</script>
</body>
</html>
HTML;
exit;
}