Files
wifi-gps-mapper-releases/reports/map_popups.py
T
2026-11-18 00:31:29 +03:00

266 lines
5.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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_class = (
"verified"
if credential["verified"]
else "unverified"
)
verified_label = (
"Проверен"
if credential["verified"]
else "Не проверен"
)
sources = ", ".join(
escape_html(source)
for source in credential["sources"]
) or "—"
items.append(
"<div "
f"class=\"map-popup-password "
f"map-popup-password-{verified_class}\">"
f"<b>{password}</b>"
f"<div class=\"map-popup-password-status "
f"map-popup-password-status-{verified_class}\">"
f"{verified_label}"
"</div>"
f"<div>Source: {sources}</div>"
"</div>"
)
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"<b>{display_value(essid)}</b>",
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:<br>"
+ 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)}"
"<br>"
"<button "
"type=\"button\" "
"class=\"map-popup-copy\" "
f"data-coordinates=\"{escape_html(coordinates)}\" "
"onclick=\"copyMapCoordinates(this)\">"
"Copy"
"</button>"
)
if session_url:
rows.append(
f'<a href="{escape_html(session_url)}">'
"Сессия наблюдения</a>"
)
if access_point_url:
rows.append(
f'<a href="{escape_html(access_point_url)}">'
"Подробнее</a>"
)
return "<br>".join(rows)