diff --git a/reports/search.py b/reports/search.py
index 9f29a39..37f2172 100644
--- a/reports/search.py
+++ b/reports/search.py
@@ -14,7 +14,7 @@ from html import escape
from reports.utils import (
format_datetime as format_report_datetime,
)
-
+from reports.map_popups import build_standard_popup
MAP_STYLE_URL = (
"http://127.0.0.1:8080/styles/server-map/style.json"
@@ -430,446 +430,184 @@ def get_category(
# Popup helpers
# ============================================================
-def safe(value):
- if value is None:
- return "—"
-
- text = str(value)
-
- if not text:
+def search_display(value):
+ if value is None or str(value).strip() == "":
return "—"
return escape(
- text,
+ str(value),
quote=True
)
-def format_security(
+def build_search_popup(
access_point,
+ category_class,
+ category_label,
+ credentials=None,
+ handshakes=None,
+ include_capture_times=False,
):
- parts = []
-
- if access_point["encryption"]:
- parts.append(
- access_point["encryption"]
- )
-
- if access_point["cipher"]:
- parts.append(
- access_point["cipher"]
- )
-
- if access_point["akm"]:
- parts.append(
- access_point["akm"]
- )
-
- if not parts:
- return "—"
-
- return escape(
- " / ".join(
- str(item)
- for item in parts
+ standard_popup = build_standard_popup(
+ essid=access_point["essid"],
+ bssid=access_point["bssid"],
+ vendor=access_point["vendor"],
+ encryption=access_point["encryption"],
+ cipher=access_point["cipher"],
+ akm=access_point["akm"],
+ channel=access_point["channel"],
+ rssi=access_point["last_rssi"],
+ passwords=credentials or [],
+ handshakes=handshakes or [],
+ observed_at=format_report_datetime(
+ access_point["last_seen"]
),
- quote=True
+ latitude=access_point["last_latitude"],
+ longitude=access_point["last_longitude"],
+ access_point_url=(
+ f"/reports/access-points/{access_point['bssid']}"
+ ),
+ )
+
+ category_html = (
+ '
'
+ )
+
+ statistics_html = """
+
+
+
+
+
+
+
+ """.format(
+ frequency=search_display(
+ access_point["frequency"]
+ ),
+ first_seen=search_display(
+ format_report_datetime(
+ access_point["first_seen"]
+ )
+ ),
+ last_seen=search_display(
+ format_report_datetime(
+ access_point["last_seen"]
+ )
+ ),
+ times_seen=search_display(
+ access_point["times_seen"]
+ )
+ )
+
+ capture_times_html = ""
+
+ if include_capture_times:
+
+ capture_times = []
+
+ for handshake in handshakes or []:
+
+ if handshake["captured_at"]:
+ capture_times.append(
+ format_report_datetime(
+ handshake["captured_at"]
+ )
+ )
+
+ if capture_times:
+ capture_times_html = """
+
+ """.format(
+ times="".join(
+ "{}
".format(
+ search_display(timestamp)
+ )
+ for timestamp in capture_times
+ )
+ )
+
+ return """
+
+ """.format(
+ category=category_html,
+ standard_popup=standard_popup,
+ statistics=statistics_html,
+ capture_times=capture_times_html,
)
def popup_password(
access_point,
credentials,
+ handshakes=None,
):
- password_items = []
-
- for credential in credentials:
-
- verified = (
- "Yes"
- if credential["verified"]
- else
- "No"
- )
-
- password_items.append(
- """
-
- """.format(
- password=safe(
- credential["password"]
- ),
- verified=verified,
- source=safe(
- credential["source"]
- )
- )
- )
-
- if not password_items:
- password_items.append(
- """
-
- """
- )
-
- return """
-
- """.format(
- essid=safe(
- access_point["essid"]
- ),
- bssid=safe(
- access_point["bssid"]
- ),
- vendor=safe(
- access_point["vendor"]
- ),
- passwords="".join(
- password_items
- ),
- security=format_security(
- access_point
- ),
- channel=safe(
- access_point["channel"]
- ),
- frequency=safe(
- access_point["frequency"]
- ),
- rssi=safe(
- access_point["last_rssi"]
- ),
- first_seen=format_report_datetime(
- access_point["first_seen"]
- ),
- last_seen=format_report_datetime(
- access_point["last_seen"]
- ),
- times_seen=safe(
- access_point["times_seen"]
- )
+ return build_search_popup(
+ access_point,
+ "password",
+ "PASSWORD",
+ credentials=credentials,
+ handshakes=handshakes,
)
def popup_handshake(
access_point,
handshakes,
+ credentials=None,
):
- eapol_count = 0
- pmkid_count = 0
- capture_times = []
-
- for handshake in handshakes:
-
- handshake_type = (
- str(
- handshake["type"]
- or ""
- ).upper()
- )
-
- if "PMKID" in handshake_type:
- pmkid_count += 1
- else:
- eapol_count += 1
-
- if handshake["captured_at"]:
- capture_times.append(
- format_report_datetime(
- handshake["captured_at"]
- )
- )
-
- summary = []
-
- if eapol_count:
- summary.append(
- f"EAPOL × {eapol_count}"
- )
-
- if pmkid_count:
- summary.append(
- f"PMKID × {pmkid_count}"
- )
-
- if not summary:
- summary.append(
- "Handshake / PMKID"
- )
-
- capture_html = ""
-
- if capture_times:
-
- capture_html = """
-
- """.format(
- times="".join(
- "{}
".format(
- safe(timestamp)
- )
- for timestamp in capture_times
- )
- )
-
- return """
-
- """.format(
- essid=safe(
- access_point["essid"]
- ),
- bssid=safe(
- access_point["bssid"]
- ),
- vendor=safe(
- access_point["vendor"]
- ),
- summary=escape(
- " · ".join(summary)
- ),
- capture_html=capture_html,
- security=format_security(
- access_point
- ),
- channel=safe(
- access_point["channel"]
- ),
- frequency=safe(
- access_point["frequency"]
- ),
- rssi=safe(
- access_point["last_rssi"]
- ),
- first_seen=format_report_datetime(
- access_point["first_seen"]
- ),
- last_seen=format_report_datetime(
- access_point["last_seen"]
- ),
- times_seen=safe(
- access_point["times_seen"]
- )
+ return build_search_popup(
+ access_point,
+ "handshake",
+ "HANDSHAKE / PMKID",
+ credentials=credentials,
+ handshakes=handshakes,
+ include_capture_times=True,
)
def popup_other(
access_point,
+ credentials=None,
+ handshakes=None,
):
- return """
-
- """.format(
- essid=safe(
- access_point["essid"]
- ),
- bssid=safe(
- access_point["bssid"]
- ),
- vendor=safe(
- access_point["vendor"]
- ),
- security=format_security(
- access_point
- ),
- channel=safe(
- access_point["channel"]
- ),
- frequency=safe(
- access_point["frequency"]
- ),
- rssi=safe(
- access_point["last_rssi"]
- ),
- first_seen=format_report_datetime(
- access_point["first_seen"]
- ),
- last_seen=format_report_datetime(
- access_point["last_seen"]
- ),
- times_seen=safe(
- access_point["times_seen"]
- )
+ return build_search_popup(
+ access_point,
+ "other",
+ "OTHER AP",
+ credentials=credentials,
+ handshakes=handshakes,
)
@@ -919,6 +657,10 @@ def build_geojson(
credentials.get(
access_point_id,
[]
+ ),
+ handshakes.get(
+ access_point_id,
+ []
)
)
@@ -929,13 +671,25 @@ def build_geojson(
handshakes.get(
access_point_id,
[]
+ ),
+ credentials.get(
+ access_point_id,
+ []
)
)
else:
popup = popup_other(
- access_point
+ access_point,
+ credentials.get(
+ access_point_id,
+ []
+ ),
+ handshakes.get(
+ access_point_id,
+ []
+ )
)
features.append(