feat: refactor admin panel to banlist panel and update related routes and templates
This commit is contained in:
@@ -412,11 +412,11 @@ async def htmx_search(
|
||||
)
|
||||
|
||||
|
||||
# ── Protected Admin Panel ────────────────────────────────────────────
|
||||
# ── Protected Banlist Panel ───────────────────────────────────────────
|
||||
|
||||
|
||||
@router.get("/htmx/admin")
|
||||
async def htmx_admin(request: Request):
|
||||
@router.get("/htmx/banlist")
|
||||
async def htmx_banlist(request: Request):
|
||||
if not verify_auth(request):
|
||||
return HTMLResponse(
|
||||
'<div class="table-container" style="text-align:center;padding:80px 20px;">'
|
||||
@@ -428,7 +428,7 @@ async def htmx_admin(request: Request):
|
||||
)
|
||||
templates = get_templates()
|
||||
return templates.TemplateResponse(
|
||||
"dashboard/partials/admin_panel.html",
|
||||
"dashboard/partials/banlist_panel.html",
|
||||
{
|
||||
"request": request,
|
||||
"dashboard_path": _dashboard_path(request),
|
||||
|
||||
@@ -129,7 +129,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Admin Panel</h1>
|
||||
<h1>Krawl Login</h1>
|
||||
<p class="subtitle">Please log in to continue</p>
|
||||
|
||||
<form action="/admin/login" method="post">
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
<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>
|
||||
</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) #}
|
||||
<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">
|
||||
@@ -198,8 +198,8 @@
|
||||
</div>
|
||||
|
||||
{# ==================== IP BANLIST TAB (protected, loaded via HTMX with server-side auth) ==================== #}
|
||||
<div x-show="tab === 'admin'" x-cloak>
|
||||
<div id="admin-htmx-container"></div>
|
||||
<div x-show="tab === 'banlist'" x-cloak>
|
||||
<div id="banlist-htmx-container"></div>
|
||||
</div>
|
||||
|
||||
{# Raw request modal - Alpine.js #}
|
||||
|
||||
@@ -46,8 +46,8 @@ document.addEventListener('alpine:init', () => {
|
||||
const h = window.location.hash.slice(1);
|
||||
if (h === 'ip-stats' || h === 'attacks') {
|
||||
this.switchToAttacks();
|
||||
} else if (h === 'admin') {
|
||||
if (this.authenticated) this.switchToAdmin();
|
||||
} else if (h === 'banlist') {
|
||||
if (this.authenticated) this.switchToBanlist();
|
||||
} else if (h !== 'ip-insight') {
|
||||
if (this.tab !== 'ip-insight') {
|
||||
this.switchToOverview();
|
||||
@@ -76,15 +76,15 @@ document.addEventListener('alpine:init', () => {
|
||||
window.location.hash = '#overview';
|
||||
},
|
||||
|
||||
switchToAdmin() {
|
||||
switchToBanlist() {
|
||||
if (!this.authenticated) return;
|
||||
this.tab = 'admin';
|
||||
window.location.hash = '#admin';
|
||||
this.tab = 'banlist';
|
||||
window.location.hash = '#banlist';
|
||||
this.$nextTick(() => {
|
||||
const container = document.getElementById('admin-htmx-container');
|
||||
const container = document.getElementById('banlist-htmx-container');
|
||||
if (container && typeof htmx !== 'undefined') {
|
||||
htmx.ajax('GET', `${this.dashboardPath}/htmx/admin`, {
|
||||
target: '#admin-htmx-container',
|
||||
htmx.ajax('GET', `${this.dashboardPath}/htmx/banlist`, {
|
||||
target: '#banlist-htmx-container',
|
||||
swap: 'innerHTML'
|
||||
});
|
||||
}
|
||||
@@ -99,7 +99,7 @@ document.addEventListener('alpine:init', () => {
|
||||
});
|
||||
} catch {}
|
||||
this.authenticated = false;
|
||||
if (this.tab === 'admin') this.switchToOverview();
|
||||
if (this.tab === 'banlist') this.switchToOverview();
|
||||
},
|
||||
|
||||
promptAuth() {
|
||||
@@ -138,7 +138,7 @@ document.addEventListener('alpine:init', () => {
|
||||
if (resp.ok) {
|
||||
this.authenticated = true;
|
||||
this.closeAuthModal();
|
||||
this.switchToAdmin();
|
||||
this.switchToBanlist();
|
||||
} else {
|
||||
const data = await resp.json().catch(() => ({}));
|
||||
this.authModal.error = data.error || 'Invalid password';
|
||||
|
||||
Reference in New Issue
Block a user