From 1503a1f0430cd3b62aef844297acf93ab561378e Mon Sep 17 00:00:00 2001 From: WildSoft Date: Wed, 14 Oct 2026 05:52:20 +0300 Subject: [PATCH] Update public source --- reports/map_popups.py | 253 ++++++++++++++++++++++++++++++++++++++++++ reports/template.py | 34 ++++++ 2 files changed, 287 insertions(+) create mode 100644 reports/map_popups.py diff --git a/reports/map_popups.py b/reports/map_popups.py new file mode 100644 index 0000000..485caa9 --- /dev/null +++ b/reports/map_popups.py @@ -0,0 +1,253 @@ +import html + + +def escape_html(value): + if value is None: + return "—" + + return html.escape( + str(value), + quote=True, + ) + + +def display_value(value): + if value is None or str(value).strip() == "": + return "—" + + return escape_html(value) + + +def format_security( + encryption=None, + cipher=None, + akm=None, +): + parts = [] + + for value in ( + encryption, + cipher, + akm, + ): + if value is None: + continue + + value = str(value).strip() + + if not value or value == "—": + continue + + if value not in parts: + parts.append(value) + + return " / ".join( + escape_html(value) + for value in parts + ) or "—" + + +def aggregate_credentials(credentials): + """ + Aggregate credentials by exact password value. + + A password is verified if at least one matching + database record has verified=1. + + Sources are combined without duplicates. + """ + + aggregated = {} + + for credential in credentials or []: + + password = credential["password"] + + if password is None or str(password) == "": + continue + + password = str(password) + + if password not in aggregated: + aggregated[password] = { + "password": password, + "verified": False, + "sources": [], + } + + item = aggregated[password] + + if credential["verified"]: + item["verified"] = True + + source = credential["source"] + + if source is not None: + source = str(source).strip() + + if source and source not in item["sources"]: + item["sources"].append(source) + + return list(aggregated.values()) + + +def format_credentials(credentials): + aggregated = aggregate_credentials(credentials) + + if not aggregated: + return "—" + + items = [] + + for credential in aggregated: + + password = escape_html( + credential["password"] + ) + + verified = ( + "Да" + if credential["verified"] + else "Нет" + ) + + sources = ", ".join( + escape_html(source) + for source in credential["sources"] + ) or "—" + + items.append( + "
" + f"{password}" + f"
Verified: {verified}" + f"
Source: {sources}" + "
" + ) + + return "".join(items) + + +def format_capture_materials( + handshakes, +): + """ + Count logical EAPOL and PMKID records. + + This does not count packets or unique hashes. + """ + + counts = { + "EAPOL": 0, + "PMKID": 0, + } + + for handshake in handshakes or []: + + capture_type = str( + handshake["type"] or "" + ).strip().upper() + + if "PMKID" in capture_type: + counts["PMKID"] += 1 + + elif "EAPOL" in capture_type: + counts["EAPOL"] += 1 + + parts = [] + + for capture_type in ("EAPOL", "PMKID"): + + count = counts[capture_type] + + if count: + parts.append( + f"{capture_type} × {count}" + ) + + return ", ".join(parts) if parts else "—" + + +def build_standard_popup( + *, + essid=None, + bssid=None, + vendor=None, + encryption=None, + cipher=None, + akm=None, + channel=None, + rssi=None, + passwords=None, + handshakes=None, + observed_at=None, + latitude=None, + longitude=None, + access_point_url=None, + session_url=None, +): + rows = [ + f"{display_value(essid)}", + f"BSSID: {display_value(bssid)}", + f"Vendor: {display_value(vendor)}", + ( + "Security: " + + format_security( + encryption, + cipher, + akm, + ) + ), + f"Channel: {display_value(channel)}", + ] + + if rssi is not None: + rows.append( + f"RSSI: {escape_html(rssi)} dBm" + ) + + rows.extend([ + ( + "Password:
" + + format_credentials(passwords) + ), + ( + "Материалы захвата: " + + escape_html( + format_capture_materials(handshakes) + ) + ), + f"Дата наблюдения: {display_value(observed_at)}", + ]) + + if latitude is not None and longitude is not None: + + coordinates = ( + f"{float(latitude):.6f}, " + f"{float(longitude):.6f}" + ) + + rows.append( + "Координаты: " + f"{escape_html(coordinates)} " + "" + ) + + if session_url: + rows.append( + f'' + "Сессия наблюдения" + ) + + if access_point_url: + rows.append( + f'' + "Подробнее" + ) + + return "
".join(rows) diff --git a/reports/template.py b/reports/template.py index 17a243e..4098563 100644 --- a/reports/template.py +++ b/reports/template.py @@ -199,6 +199,40 @@ function filterTable(id,value) }} }} +async function copyMapCoordinates(button) +{{ + const coordinates = button.dataset.coordinates; + + if (!coordinates) + return; + + const originalText = button.textContent; + + try + {{ + if (!navigator.clipboard || !navigator.clipboard.writeText) + throw new Error("Clipboard API unavailable"); + + await navigator.clipboard.writeText(coordinates); + + button.textContent = "Скопировано"; + + setTimeout(() => + {{ + button.textContent = originalText; + }}, 1500); + }} + catch (error) + {{ + button.textContent = "Ошибка копирования"; + + setTimeout(() => + {{ + button.textContent = originalText; + }}, 2000); + }} +}} +