feat: refactor admin panel to banlist panel and update related routes and templates

This commit is contained in:
Lorenzo Venerandi
2026-03-08 12:49:55 +01:00
parent 6117824c19
commit 4e34b4b80a
5 changed files with 18 additions and 18 deletions

View File

@@ -412,11 +412,11 @@ async def htmx_search(
) )
# ── Protected Admin Panel ─────────────────────────────────────────── # ── Protected Banlist Panel ───────────────────────────────────────────
@router.get("/htmx/admin") @router.get("/htmx/banlist")
async def htmx_admin(request: Request): async def htmx_banlist(request: Request):
if not verify_auth(request): if not verify_auth(request):
return HTMLResponse( return HTMLResponse(
'<div class="table-container" style="text-align:center;padding:80px 20px;">' '<div class="table-container" style="text-align:center;padding:80px 20px;">'
@@ -428,7 +428,7 @@ async def htmx_admin(request: Request):
) )
templates = get_templates() templates = get_templates()
return templates.TemplateResponse( return templates.TemplateResponse(
"dashboard/partials/admin_panel.html", "dashboard/partials/banlist_panel.html",
{ {
"request": request, "request": request,
"dashboard_path": _dashboard_path(request), "dashboard_path": _dashboard_path(request),

View File

@@ -129,7 +129,7 @@
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<h1>Admin Panel</h1> <h1>Krawl Login</h1>
<p class="subtitle">Please log in to continue</p> <p class="subtitle">Please log in to continue</p>
<form action="/admin/login" method="post"> <form action="/admin/login" method="post">

View File

@@ -59,7 +59,7 @@
<a class="tab-button" :class="{ active: tab === 'ip-insight', disabled: !insightIp }" @click.prevent="insightIp && switchToIpInsight()" href="#ip-insight"> <a class="tab-button" :class="{ active: tab === 'ip-insight', disabled: !insightIp }" @click.prevent="insightIp && switchToIpInsight()" href="#ip-insight">
IP Insight<span x-show="insightIp" x-text="' (' + insightIp + ')'"></span> IP Insight<span x-show="insightIp" x-text="' (' + insightIp + ')'"></span>
</a> </a>
<a class="tab-button tab-right" :class="{ active: tab === 'admin' }" x-show="authenticated" x-cloak @click.prevent="switchToAdmin()" href="#admin">IP Banlist</a> <a class="tab-button tab-right" :class="{ active: tab === 'banlist' }" x-show="authenticated" x-cloak @click.prevent="switchToBanlist()" href="#banlist">IP Banlist</a>
{# Lock icon (not authenticated) #} {# Lock icon (not authenticated) #}
<a class="tab-button tab-lock-btn" :class="{ 'tab-right': !authenticated }" @click.prevent="promptAuth()" x-show="!authenticated" href="#" title="Unlock protected panels"> <a class="tab-button tab-lock-btn" :class="{ 'tab-right': !authenticated }" @click.prevent="promptAuth()" x-show="!authenticated" href="#" title="Unlock protected panels">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" fill="currentColor"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" fill="currentColor">
@@ -198,8 +198,8 @@
</div> </div>
{# ==================== IP BANLIST TAB (protected, loaded via HTMX with server-side auth) ==================== #} {# ==================== IP BANLIST TAB (protected, loaded via HTMX with server-side auth) ==================== #}
<div x-show="tab === 'admin'" x-cloak> <div x-show="tab === 'banlist'" x-cloak>
<div id="admin-htmx-container"></div> <div id="banlist-htmx-container"></div>
</div> </div>
{# Raw request modal - Alpine.js #} {# Raw request modal - Alpine.js #}

View File

@@ -46,8 +46,8 @@ document.addEventListener('alpine:init', () => {
const h = window.location.hash.slice(1); const h = window.location.hash.slice(1);
if (h === 'ip-stats' || h === 'attacks') { if (h === 'ip-stats' || h === 'attacks') {
this.switchToAttacks(); this.switchToAttacks();
} else if (h === 'admin') { } else if (h === 'banlist') {
if (this.authenticated) this.switchToAdmin(); if (this.authenticated) this.switchToBanlist();
} else if (h !== 'ip-insight') { } else if (h !== 'ip-insight') {
if (this.tab !== 'ip-insight') { if (this.tab !== 'ip-insight') {
this.switchToOverview(); this.switchToOverview();
@@ -76,15 +76,15 @@ document.addEventListener('alpine:init', () => {
window.location.hash = '#overview'; window.location.hash = '#overview';
}, },
switchToAdmin() { switchToBanlist() {
if (!this.authenticated) return; if (!this.authenticated) return;
this.tab = 'admin'; this.tab = 'banlist';
window.location.hash = '#admin'; window.location.hash = '#banlist';
this.$nextTick(() => { this.$nextTick(() => {
const container = document.getElementById('admin-htmx-container'); const container = document.getElementById('banlist-htmx-container');
if (container && typeof htmx !== 'undefined') { if (container && typeof htmx !== 'undefined') {
htmx.ajax('GET', `${this.dashboardPath}/htmx/admin`, { htmx.ajax('GET', `${this.dashboardPath}/htmx/banlist`, {
target: '#admin-htmx-container', target: '#banlist-htmx-container',
swap: 'innerHTML' swap: 'innerHTML'
}); });
} }
@@ -99,7 +99,7 @@ document.addEventListener('alpine:init', () => {
}); });
} catch {} } catch {}
this.authenticated = false; this.authenticated = false;
if (this.tab === 'admin') this.switchToOverview(); if (this.tab === 'banlist') this.switchToOverview();
}, },
promptAuth() { promptAuth() {
@@ -138,7 +138,7 @@ document.addEventListener('alpine:init', () => {
if (resp.ok) { if (resp.ok) {
this.authenticated = true; this.authenticated = true;
this.closeAuthModal(); this.closeAuthModal();
this.switchToAdmin(); this.switchToBanlist();
} else { } else {
const data = await resp.json().catch(() => ({})); const data = await resp.json().catch(() => ({}));
this.authModal.error = data.error || 'Invalid password'; this.authModal.error = data.error || 'Invalid password';