From f7416518fe72293ab13ea53cbde206d5005c98a5 Mon Sep 17 00:00:00 2001 From: carnivuth Date: Sun, 22 Feb 2026 21:53:18 +0100 Subject: [PATCH] added first version of single ip page breakdiwn --- src/database.py | 31 +++++++++++++++++-------------- src/routes/dashboard.py | 4 ++-- src/routes/htmx.py | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/database.py b/src/database.py index ba34cb5..179dab0 100644 --- a/src/database.py +++ b/src/database.py @@ -888,31 +888,34 @@ class DatabaseManager: logs = query.offset(offset).limit(page_size).all() # Get total count of attackers total_access_logs = ( - session.query(AccessLog).filter(AccessLog.ip == sanitize_ip(ip_filter)).count() + session.query(AccessLog) + .filter(AccessLog.ip == sanitize_ip(ip_filter)) + .count() ) total_pages = (total_access_logs + page_size - 1) // page_size return { - "access_logs": [ + "access_logs": [ { - "id": log.id, - "ip": log.ip, - "path": log.path, - "user_agent": log.user_agent, - "method": log.method, - "is_suspicious": log.is_suspicious, - "is_honeypot_trigger": log.is_honeypot_trigger, - "timestamp": log.timestamp.isoformat(), - "attack_types": [d.attack_type for d in log.attack_detections], - } - for log in logs ], + "id": log.id, + "ip": log.ip, + "path": log.path, + "user_agent": log.user_agent, + "method": log.method, + "is_suspicious": log.is_suspicious, + "is_honeypot_trigger": log.is_honeypot_trigger, + "timestamp": log.timestamp.isoformat(), + "attack_types": [d.attack_type for d in log.attack_detections], + } + for log in logs + ], "pagination": { "page": page, "page_size": page_size, "total_logs": total_access_logs, "total_pages": total_pages, }, - } + } finally: self.close_session() diff --git a/src/routes/dashboard.py b/src/routes/dashboard.py index c8c482e..da6846b 100644 --- a/src/routes/dashboard.py +++ b/src/routes/dashboard.py @@ -40,6 +40,7 @@ async def dashboard_page(request: Request): }, ) + @router.get("/ip/{ip_address:path}") async def ip_page(ip_address: str, request: Request): db = get_db() @@ -57,7 +58,7 @@ async def ip_page(ip_address: str, request: Request): "request": request, "dashboard_path": dashboard_path, "stats": stats, - "ip_address": ip_address + "ip_address": ip_address, }, ) else: @@ -67,4 +68,3 @@ async def ip_page(ip_address: str, request: Request): except Exception as e: get_app_logger().error(f"Error fetching IP stats: {e}") return JSONResponse(content={"error": str(e)}) - diff --git a/src/routes/htmx.py b/src/routes/htmx.py index ddf08f6..28de8cd 100644 --- a/src/routes/htmx.py +++ b/src/routes/htmx.py @@ -180,7 +180,7 @@ async def htmx_access_logs_by_ip( ): db = get_db() result = db.get_access_logs_paginated( - page=max(1, page),page_size=25, ip_filter=ip_filter + page=max(1, page), page_size=25, ip_filter=ip_filter ) # Normalize pagination key (DB returns total_attackers, template expects total)