#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Dashboard HTML report. Главная страница отчета. Содержит только обзорную информацию. Без карты. Без полного списка точек доступа. Вся детальная информация находится на страницах отдельных поездок. """ from pathlib import Path from .config import ( RECENT_SESSIONS_LIMIT, ) from .utils import ( esc, format_datetime, ) from .template import ( page_begin, page_end, card, stat, stats_grid, ) from .statistics import ( database_statistics, top_vendors, top_essid, channel_statistics, encryption_statistics, ) from .sessions import ( recent_sessions, all_sessions, ) # ============================================================ # Helpers # ============================================================ def format_session_folder(capture_file): if not capture_file or not str(capture_file).startswith("captures/"): return "-" folder = Path(capture_file).parent.name try: from datetime import datetime, timezone dt = datetime.strptime( folder, "%Y%m%d_%H%M%S" ).replace( tzinfo=timezone.utc ) return format_datetime( dt.isoformat() ) except ValueError: return folder # ============================================================ # Database statistics # ============================================================ def statistics_block(conn): data = database_statistics(conn) items = [ stat( data["access_points"], "Access Points" ), stat( data["access_points_without_coordinates"], "AP without Coordinates" ), stat( data["sessions"], "Capture Sessions" ), stat( data["vendors"], "Vendors" ), stat( data["handshakes"], "Handshakes" ), stat( data["credentials"], "Handshake Cracked" ), stat( data["pmkid"], "PMKID" ), stat( data["cracked"], "Cracked AP" ), stat( data["database_size"], "Database" ), ] return card( "📊 Database Overview", stats_grid(items) ) # ============================================================ # Information # ============================================================ def information_block(conn): data = database_statistics(conn) html = f"""
Database size {data["database_size"]}
Captures size {data["captures_size"]}
Capture files {data["capture_files"]}
First access point {format_datetime(data["first_seen"])}
Last access point {format_datetime(data["last_seen"])}
""" return card( "ℹ️ Database Information", html, ) # ============================================================ # Top Vendors # ============================================================ def vendors_block(conn): rows = top_vendors( conn, limit=15 ) html = """ """ for vendor, total in rows: if not vendor: vendor = "-" html += f""" """ html += """
Vendor Devices
{vendor} {total}
""" return card( "🏭 Top Vendors", html, ) # ============================================================ # Top ESSID # ============================================================ def essid_block(conn): rows = top_essid( conn, limit=15 ) html = """ """ for essid, total in rows: if not essid: essid = "<hidden>" html += f""" """ html += """
ESSID Count
{essid} {total}
""" return card( "📶 Most Common ESSID", html, ) # ============================================================ # Channels # ============================================================ def channels_block(conn): rows = channel_statistics( conn ) html = """ """ for channel, total in rows: html += f""" """ html += """
Channel Access Points
{channel} {total}
""" return card( "📡 Channel Statistics", html, ) # ============================================================ # Encryption # ============================================================ def encryption_block(conn): rows = encryption_statistics( conn ) html = """ """ for encryption, total in rows: if not encryption: encryption = "-" html += f""" """ html += """
Encryption Networks
{encryption} {total}
""" return card( "🔐 Encryption", html, ) # ============================================================ # Session Card # ============================================================ def session_card( session, context=None, ): session_url = context.session_url( session["id"] ) return f"""

🚗 Session {format_datetime(session.get("trip_start"))}

Trip start {format_datetime(session.get("trip_start"))}
Trip end {format_datetime(session.get("trip_end"))}
Duration {session.get("duration","-")}
Session origin {session.get("origin", "Unknown")}
Capture started {format_datetime(session.get("start_time"))}
Session folder {format_session_folder(session.get("capture_file"))}
Access Points {session.get("access_points","-")}
Coordinates Restored {session.get("coordinates_restored","-")}
AP without Coordinates {session.get("ap_without_coordinates","-")}
Handshake AP {session.get("handshakes","-")}
Handshake Records {session.get("handshake_records","-")}
PMKID AP {session.get("pmkid","-")}
Cracked AP {session.get("cracked","-")}
Directory size {session.get("directory_size","-")}

📄 Open Session Report

""" # ============================================================ # Recent Sessions # ============================================================ def sessions_block( conn, context=None, ): sessions = recent_sessions( conn, limit=RECENT_SESSIONS_LIMIT, ) if not sessions: return card( "🚗 Recent Capture Sessions", """

Capture sessions not found.

""" ) cards = [] for session in sessions: cards.append( session_card( session, context, ) ) capture_sessions_url = ( context.capture_sessions_url() ) html = """
""" html += "\n".join(cards) html += f"""

Show all sessions

""" return card( "🚗 Recent Capture Sessions", html, ) # ============================================================ # Dashboard # ============================================================ def generate_dashboard( conn, context=None, ): html = page_begin( title="Dashboard", description=( "Overview of collected Wi-Fi data, access points, " "capture sessions, and vendors." ), active="dashboard", context=context, section_title="Reports", ) # -------------------------------------------------------- # Database statistics # -------------------------------------------------------- html += statistics_block( conn ) # -------------------------------------------------------- # Information # -------------------------------------------------------- html += information_block( conn ) # -------------------------------------------------------- # Vendors / ESSID # -------------------------------------------------------- html += """
""" html += vendors_block( conn ) html += essid_block( conn ) html += """
""" # -------------------------------------------------------- # Channels / Encryption # -------------------------------------------------------- html += """
""" html += channels_block( conn ) html += encryption_block( conn ) html += """
""" # -------------------------------------------------------- # Sessions # -------------------------------------------------------- html += sessions_block( conn, context, ) # -------------------------------------------------------- # Footer # -------------------------------------------------------- html += page_end() return html # ============================================================ # All Capture Sessions # ============================================================ def generate_capture_sessions( conn, context=None, ): sessions = all_sessions( conn ) html = page_begin( title="🚗 Capture Sessions", description=f""" All capture sessions
Total sessions: {len(sessions)} """, active="capture_sessions", context=context, section_title="Reports", ) cards = [] for session in sessions: session_id = session["id"] trip_start = session.get("trip_start") trip_end = session.get("trip_end") duration_seconds = "" if trip_start and trip_end: from .utils import parse_datetime start = parse_datetime(trip_start) end = parse_datetime(trip_end) if start is not None and end is not None: duration_seconds = max( 0, int((end - start).total_seconds()) ) distance_m = session.get("distance_m") distance_html = "" distance_sort = "" if distance_m is not None: distance_sort = str(distance_m) if distance_m >= 1000: distance_label = ( f"{distance_m / 1000:.2f} km" ) else: distance_label = ( f"{distance_m:.0f} m" ) distance_html = f""" 🛣️ Distance: {distance_label} """ trip_start_html = ( format_datetime(trip_start) if trip_start else "-" ) trip_end_html = ( format_datetime(trip_end) if trip_end else "-" ) duration_html = ( esc(session.get("duration")) if session.get("duration") else "-" ) access_points = session.get("access_points", 0) cards.append(f"""
🚗 Session #{esc(session_id)}
Trip start: {trip_start_html} Trip end: {trip_end_html} Duration: {duration_html}
{distance_html} 📶 Access Points: {esc(access_points)}
View session →
""") html += """
""" html += "\n".join(cards) html += """
""" html += page_end() return html