Update public source
This commit is contained in:
+61
-21
@@ -75,6 +75,7 @@ def load_access_points(conn):
|
||||
WITH ranked_observations AS (
|
||||
SELECT
|
||||
obs.access_point_id,
|
||||
obs.session_id,
|
||||
obs.latitude,
|
||||
obs.longitude,
|
||||
obs.observed_at,
|
||||
@@ -106,6 +107,7 @@ def load_access_points(conn):
|
||||
ap.is_cracked,
|
||||
obs.latitude,
|
||||
obs.longitude,
|
||||
obs.session_id,
|
||||
obs.observed_at,
|
||||
obs.rssi,
|
||||
obs.channel
|
||||
@@ -119,37 +121,36 @@ def load_access_points(conn):
|
||||
""",
|
||||
)
|
||||
|
||||
if not rows:
|
||||
return []
|
||||
|
||||
access_point_ids = [
|
||||
row["id"]
|
||||
for row in rows
|
||||
]
|
||||
|
||||
placeholders = ",".join(
|
||||
"?" for _ in access_point_ids
|
||||
)
|
||||
|
||||
credentials = query_all(
|
||||
conn,
|
||||
"""
|
||||
f"""
|
||||
SELECT
|
||||
access_point_id,
|
||||
password,
|
||||
source,
|
||||
verified
|
||||
FROM credentials
|
||||
WHERE access_point_id IN ({placeholders})
|
||||
ORDER BY
|
||||
created_at DESC,
|
||||
id DESC
|
||||
""",
|
||||
)
|
||||
|
||||
handshakes = query_all(
|
||||
conn,
|
||||
"""
|
||||
SELECT
|
||||
access_point_id,
|
||||
type,
|
||||
captured_at
|
||||
FROM handshakes
|
||||
ORDER BY
|
||||
captured_at DESC,
|
||||
id DESC
|
||||
""",
|
||||
access_point_ids,
|
||||
)
|
||||
|
||||
credentials_by_ap = {}
|
||||
handshakes_by_ap = {}
|
||||
|
||||
for credential in credentials:
|
||||
|
||||
@@ -164,12 +165,48 @@ def load_access_points(conn):
|
||||
"verified": credential["verified"],
|
||||
})
|
||||
|
||||
session_conditions = []
|
||||
session_parameters = []
|
||||
|
||||
for row in rows:
|
||||
|
||||
session_conditions.append(
|
||||
"(access_point_id = ? AND session_id = ?)"
|
||||
)
|
||||
|
||||
session_parameters.extend([
|
||||
row["id"],
|
||||
row["session_id"],
|
||||
])
|
||||
|
||||
handshakes = query_all(
|
||||
conn,
|
||||
f"""
|
||||
SELECT
|
||||
access_point_id,
|
||||
session_id,
|
||||
type,
|
||||
captured_at
|
||||
FROM handshakes
|
||||
WHERE {" OR ".join(session_conditions)}
|
||||
ORDER BY
|
||||
captured_at DESC,
|
||||
id DESC
|
||||
""",
|
||||
session_parameters,
|
||||
)
|
||||
|
||||
handshakes_by_ap_session = {}
|
||||
|
||||
for handshake in handshakes:
|
||||
|
||||
access_point_id = handshake["access_point_id"]
|
||||
key = (
|
||||
handshake["access_point_id"],
|
||||
handshake["session_id"],
|
||||
)
|
||||
|
||||
handshakes_by_ap.setdefault(
|
||||
access_point_id,
|
||||
handshakes_by_ap_session.setdefault(
|
||||
key,
|
||||
[],
|
||||
).append({
|
||||
"type": handshake["type"],
|
||||
@@ -183,16 +220,19 @@ def load_access_points(conn):
|
||||
observation = dict(row)
|
||||
|
||||
access_point_id = observation["id"]
|
||||
session_id = observation["session_id"]
|
||||
|
||||
observation["passwords"] = credentials_by_ap.get(
|
||||
access_point_id,
|
||||
[],
|
||||
)
|
||||
|
||||
observation["handshakes"] = handshakes_by_ap.get(
|
||||
access_point_id,
|
||||
observation["handshakes"] = (
|
||||
handshakes_by_ap_session.get(
|
||||
(access_point_id, session_id),
|
||||
[],
|
||||
)
|
||||
)
|
||||
|
||||
observations.append(observation)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user