#!/usr/bin/env python3 """ Dashboard template for viewing honeypot statistics. Customize this template to change the dashboard appearance. """ import html from datetime import datetime from zoneinfo import ZoneInfo # imports for the __init_subclass__ method, do not remove pls from firewall import fwtype from firewall.iptables import Iptables from firewall.raw import Raw def _escape(value) -> str: """Escape HTML special characters to prevent XSS attacks.""" if value is None: return "" return html.escape(str(value)) def format_timestamp(iso_timestamp: str, time_only: bool = False) -> str: """Format ISO timestamp for display with timezone conversion Args: iso_timestamp: ISO format timestamp string (UTC) time_only: If True, return only HH:MM:SS, otherwise full datetime """ try: # Parse UTC timestamp dt = datetime.fromisoformat(iso_timestamp) if time_only: return dt.strftime("%H:%M:%S") return dt.strftime("%Y-%m-%d %H:%M:%S") except Exception: # Fallback for old format return ( iso_timestamp.split("T")[1][:8] if "T" in iso_timestamp else iso_timestamp ) def generate_dashboard(stats: dict, dashboard_path: str = "") -> str: """Generate dashboard HTML with access statistics Args: stats: Statistics dictionary dashboard_path: The secret dashboard path for generating API URLs """ # Generate suspicious accesses rows with clickable IPs suspicious_rows = ( "\n".join([f"""
| IP Address | Path | User-Agent | Time |
|---|
| # | IP Address | Accessed Paths | Count |
|---|---|---|---|
| Loading... | |||
| # | IP Address | Access Count |
|---|---|---|
| Loading... | ||
| # | User-Agent | Count |
|---|---|---|
| Loading... | ||
| # | IP Address | Total Requests | First Seen | Last Seen | Location |
|---|
| # | IP Address | Username | Password | Path | Time |
|---|---|---|---|---|---|
| Loading... | |||||
| # | IP Address | Path | Attack Types | User-Agent | Time |
|---|---|---|---|---|---|
| Loading... | |||||