From 894a36d116b7393662cc5be2068e597b3de65762 Mon Sep 17 00:00:00 2001 From: WildSoft Date: Wed, 14 Oct 2026 06:59:40 +0300 Subject: [PATCH] Update public source --- reports/search.py | 578 +++++++++++++--------------------------------- 1 file changed, 166 insertions(+), 412 deletions(-) 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 = ( + '
' + f'{category_label}' + '
' + ) + + statistics_html = """ +
+ Frequency: + {frequency} +
+ +
+ First seen: + {first_seen} +
+ +
+ Last seen: + {last_seen} +
+ +
+ Times seen: + {times_seen} +
+ """.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 = """ +
+ Capture time: + +
+ {times} +
+
+ """.format( + times="".join( + "
{}
".format( + search_display(timestamp) + ) + for timestamp in capture_times + ) + ) + + return """ +
+ {category} + +
+ {standard_popup} +
+ + {statistics} + + {capture_times} +
+ """.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( - """ -
-
- {password} -
- -
- Verified: {verified} -  ·  - Source: {source} -
-
- """.format( - password=safe( - credential["password"] - ), - verified=verified, - source=safe( - credential["source"] - ) - ) - ) - - if not password_items: - password_items.append( - """ -
- No password details available. -
- """ - ) - - return """ -
-
- {essid} -
- -
- BSSID: - {bssid} -
- -
- Vendor: - {vendor} -
- -
- PASSWORD -
- -
- {passwords} -
- -
- Security: - {security} -
- -
- Channel: - {channel} -  ·  - Frequency: - {frequency} -
- -
- RSSI: - {rssi} -
- -
- First seen: - {first_seen} -
- -
- Last seen: - {last_seen} -
- -
- Times seen: - {times_seen} -
-
- """.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 = """ -
- Capture time: -
- {times} -
-
- """.format( - times="".join( - "
{}
".format( - safe(timestamp) - ) - for timestamp in capture_times - ) - ) - - return """ -
-
- {essid} -
- -
- BSSID: - {bssid} -
- -
- Vendor: - {vendor} -
- -
- HANDSHAKE / PMKID -
- -
- Material: - {summary} -
- - {capture_html} - -
- Security: - {security} -
- -
- Channel: - {channel} -  ·  - Frequency: - {frequency} -
- -
- RSSI: - {rssi} -
- -
- First seen: - {first_seen} -
- -
- Last seen: - {last_seen} -
- -
- Times seen: - {times_seen} -
-
- """.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 """ -
-
- {essid} -
- -
- BSSID: - {bssid} -
- -
- Vendor: - {vendor} -
- -
- OTHER AP -
- -
- Security: - {security} -
- -
- Channel: - {channel} -  ·  - Frequency: - {frequency} -
- -
- RSSI: - {rssi} -
- -
- First seen: - {first_seen} -
- -
- Last seen: - {last_seen} -
- -
- Times seen: - {times_seen} -
-
- """.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(