From aba6633b1f4ab0d8fca331271b8f6de9e65d7e12 Mon Sep 17 00:00:00 2001 From: WildSoft Date: Wed, 21 Oct 2026 01:48:43 +0300 Subject: [PATCH] Update public source --- reports/wifi_connections.py | 551 ++++++++++++++++++++++++++++++++++++ 1 file changed, 551 insertions(+) create mode 100644 reports/wifi_connections.py diff --git a/reports/wifi_connections.py b/reports/wifi_connections.py new file mode 100644 index 0000000..eb1e75d --- /dev/null +++ b/reports/wifi_connections.py @@ -0,0 +1,551 @@ + +import html +import json + +from reports.access_points import ( + format_popup_datetime, + load_access_points, +) +from reports.map_popups import build_standard_popup +from reports.template import ( + ReportContext, + card, + page_begin, + page_end, +) + + +def verified_passwords(row): + passwords = [] + seen = set() + + for credential in row["passwords"]: + password = credential.get("password") + + if ( + not credential.get("verified") + or not isinstance(password, str) + or not password + or password in seen + ): + continue + + seen.add(password) + passwords.append(password) + + return passwords + + +def classify_access_points(observations): + verified_wpa = [] + open_aps = [] + + for row in observations: + latitude = row.get("latitude") + longitude = row.get("longitude") + + if latitude is None or longitude is None: + continue + + encryption = str( + row.get("encryption") or "" + ).strip().upper() + + if encryption == "OPEN": + open_aps.append(row) + elif verified_passwords(row): + verified_wpa.append(row) + + return verified_wpa, open_aps + + +def build_connection_popup(row, is_open): + popup = build_standard_popup( + essid=row["essid"], + bssid=row["bssid"], + vendor=row["vendor"], + encryption=row["encryption"], + cipher=row["cipher"], + akm=row["akm"], + channel=row["channel"], + rssi=row["rssi"], + passwords=row["passwords"], + handshakes=row["handshakes"], + observed_at=format_popup_datetime( + row["observed_at"] + ), + latitude=row["latitude"], + longitude=row["longitude"], + access_point_url=( + f"/reports/access-points/{row['bssid']}" + ), + ) + + if is_open: + connect_control = """ +
+ +
+""".format( + html.escape(str(row["bssid"]), quote=True) + ) + + else: + passwords = verified_passwords(row) + + options = "".join( + ''.format( + html.escape(password, quote=True), + html.escape(password), + ) + for password in passwords + ) + + connect_control = """ +
+ + +
+""".format( + options, + html.escape(str(row["bssid"]), quote=True), + ) + + return popup + connect_control + + +def build_wifi_connections_marker_js(observations): + verified_wpa, open_aps = classify_access_points( + observations + ) + + def make_features(rows, is_open): + features = [] + + for row in rows: + popup = build_connection_popup( + row, + is_open, + ) + + features.append({ + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [ + float(row["longitude"]), + float(row["latitude"]), + ], + }, + "properties": { + "popup": popup, + }, + }) + + return features + + return ( + "const verifiedWpaFeatures = " + + json.dumps( + make_features(verified_wpa, False), + ensure_ascii=False, + ) + + ";\n" + + "const openFeatures = " + + json.dumps( + make_features(open_aps, True), + ensure_ascii=False, + ) + + ";\n" + ) + + +def render_wifi_connections_map(observations, context): + marker_js = build_wifi_connections_marker_js( + observations + ) + + maplibre_css_url = context.asset_url( + "maplibre/maplibre-gl.css" + ) + + maplibre_js_url = context.asset_url( + "maplibre/maplibre-gl.js" + ) + + map_html = """ +
+ + + + + + +""" + + map_html = map_html.replace( + "__MAPLIBRE_CSS_URL__", + maplibre_css_url, + ) + + map_html = map_html.replace( + "__MAPLIBRE_JS_URL__", + maplibre_js_url, + ) + + map_html = map_html.replace( + "__MARKER_JS__", + marker_js, + ) + + return map_html + + +def render_wifi_connections_page(conn, context=None): + if context is None: + context = ReportContext( + mode="server" + ) + + observations = load_access_points(conn) + + verified_wpa, open_aps = classify_access_points( + observations + ) + + html = page_begin( + "Wi-Fi Connections", + active="wifi_connections", + context=context, + section_title="Reports", + ) + + html += card( + """ + + + 🗺 Wi-Fi Connections + + + + + + + + + + + """.format( + len(verified_wpa), + len(open_aps), + ), + render_wifi_connections_map( + observations, + context, + ), + ) + + html += page_end() + + return html