Update public source
This commit is contained in:
@@ -0,0 +1,253 @@
|
||||
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 = (
|
||||
"Да"
|
||||
if credential["verified"]
|
||||
else "Нет"
|
||||
)
|
||||
|
||||
sources = ", ".join(
|
||||
escape_html(source)
|
||||
for source in credential["sources"]
|
||||
) or "—"
|
||||
|
||||
items.append(
|
||||
"<div class=\"map-popup-password\">"
|
||||
f"<b>{password}</b>"
|
||||
f"<br>Verified: {verified}"
|
||||
f"<br>Source: {sources}"
|
||||
"</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)} "
|
||||
"<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)
|
||||
@@ -199,6 +199,40 @@ function filterTable(id,value)
|
||||
}}
|
||||
}}
|
||||
|
||||
async function copyMapCoordinates(button)
|
||||
{{
|
||||
const coordinates = button.dataset.coordinates;
|
||||
|
||||
if (!coordinates)
|
||||
return;
|
||||
|
||||
const originalText = button.textContent;
|
||||
|
||||
try
|
||||
{{
|
||||
if (!navigator.clipboard || !navigator.clipboard.writeText)
|
||||
throw new Error("Clipboard API unavailable");
|
||||
|
||||
await navigator.clipboard.writeText(coordinates);
|
||||
|
||||
button.textContent = "Скопировано";
|
||||
|
||||
setTimeout(() =>
|
||||
{{
|
||||
button.textContent = originalText;
|
||||
}}, 1500);
|
||||
}}
|
||||
catch (error)
|
||||
{{
|
||||
button.textContent = "Ошибка копирования";
|
||||
|
||||
setTimeout(() =>
|
||||
{{
|
||||
button.textContent = originalText;
|
||||
}}, 2000);
|
||||
}}
|
||||
}}
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
Reference in New Issue
Block a user