Update public source

This commit is contained in:
2026-10-19 15:51:15 +03:00
parent e89d4b8651
commit ec584c3d9c
+495
View File
@@ -1161,6 +1161,501 @@ def render_observation_table(observations):
</div> </div>
""" """
def render_wifi_connection_card(ap, credentials):
is_open = ap["encryption"] == "OPEN"
password_states = {}
for credential in credentials:
password = credential["password"]
if not password:
continue
if password not in password_states:
password_states[password] = bool(
credential["verified"]
)
elif credential["verified"]:
password_states[password] = True
credential_rows = []
for password, verified in password_states.items():
if verified:
verify_button = """
<button
type="button"
class="button"
data-wifi-action="verify"
disabled
>
Проверен
</button>
"""
connect_disabled = ""
status_text = "Пароль успешно проверен"
else:
verify_button = """
<button
type="button"
class="button"
data-wifi-action="verify"
>
Проверить пароль
</button>
"""
connect_disabled = "disabled"
status_text = "Пароль ещё не проверен"
credential_rows.append(
f"""
<div
class="wifi-credential-row"
data-password="{esc(password)}"
data-verified="{str(verified).lower()}"
style="
padding:12px;
margin:10px 0;
border:1px solid var(--border);
border-radius:8px;
"
>
<div style="margin-bottom:10px;">
<strong>Password:</strong>
<code>{esc(password)}</code>
</div>
<div
data-verification-status
style="
margin-bottom:10px;
color:var(--muted);
"
>
{status_text}
</div>
<div style="display:flex;gap:8px;flex-wrap:wrap;">
{verify_button}
<button
type="button"
class="button"
data-wifi-action="connect"
{connect_disabled}
>
Подключиться
</button>
</div>
</div>
"""
)
if is_open:
actions_html = """
<div style="margin-top:12px;">
<p>
Эта точка доступа не использует пароль.
Проверка пароля не требуется.
</p>
<button
type="button"
class="button"
data-wifi-action="connect"
>
Подключиться
</button>
</div>
"""
elif credential_rows:
actions_html = "".join(credential_rows)
else:
actions_html = """
<div style="padding:8px 0;">
В базе данных нет сохранённых паролей для этой точки доступа.
</div>
"""
return card(
"Проверка пароля и подключение",
f"""
<div
id="wifi-connection-controls"
data-bssid="{esc(ap["bssid"])}"
data-open="{str(is_open).lower()}"
>
<div style="margin-bottom:14px;">
<label for="wifi-connection-interface">
<strong>Wi-Fi интерфейс:</strong>
</label>
<select
id="wifi-connection-interface"
class="search"
style="display:block;width:100%;max-width:400px;"
disabled
>
<option value="">Загрузка интерфейсов...</option>
</select>
</div>
<div
id="wifi-connection-warning"
role="status"
hidden
style="
margin:12px 0;
padding:12px;
border:1px solid var(--yellow);
border-radius:8px;
line-height:1.5;
"
></div>
<div
id="wifi-connection-message"
role="status"
aria-live="polite"
style="margin:12px 0;"
></div>
<div>
{actions_html}
</div>
</div>
<script>
(function() {{
const root = document.getElementById(
"wifi-connection-controls"
);
if (!root) {{
return;
}}
const interfaceSelect = document.getElementById(
"wifi-connection-interface"
);
const message = document.getElementById(
"wifi-connection-message"
);
const warning = document.getElementById(
"wifi-connection-warning"
);
const isOpen = root.dataset.open === "true";
let devices = [];
let busy = false;
function setMessage(text, isError = false) {{
message.textContent = text || "";
message.style.color = isError
? "var(--red)"
: "var(--muted)";
}}
function setWarning(text) {{
warning.textContent = text || "";
warning.hidden = !text;
}}
function selectedInterface() {{
const device = devices.find(
item => item.device === interfaceSelect.value
);
if (!device || !device.available) {{
return null;
}}
return device.device;
}}
function updateButtons() {{
const interfaceName = selectedInterface();
root.querySelectorAll(
"[data-wifi-action]"
).forEach(button => {{
const action = button.dataset.wifiAction;
const row = button.closest(
".wifi-credential-row"
);
const verified = row
&& row.dataset.verified === "true";
if (busy || !interfaceName) {{
button.disabled = true;
return;
}}
if (action === "verify") {{
button.disabled = verified;
}}
if (action === "connect") {{
button.disabled = !isOpen && !verified;
}}
}});
interfaceSelect.disabled =
busy || devices.length <= 1;
}}
async function loadInterfaces() {{
try {{
const response = await fetch(
"/api/network/wifi-devices",
{{
cache: "no-store"
}}
);
const data = await response.json();
if (!response.ok || !data.ok) {{
throw new Error(
data.error || "Не удалось получить Wi-Fi интерфейсы."
);
}}
devices = data.devices || [];
interfaceSelect.replaceChildren();
const placeholder = document.createElement(
"option"
);
placeholder.value = "";
placeholder.textContent =
devices.length > 1
? "Выберите Wi-Fi интерфейс"
: "Нет доступных интерфейсов";
interfaceSelect.appendChild(placeholder);
devices.forEach(device => {{
const option = document.createElement(
"option"
);
option.value = device.device;
option.textContent = device.available
? device.device + " (" + device.state + ")"
: device.device + " — " + (
device.reason || device.state
);
option.disabled = !device.available;
interfaceSelect.appendChild(option);
}});
if (
data.selected_device
&& devices.some(
device =>
device.device === data.selected_device
&& device.available
)
) {{
interfaceSelect.value = data.selected_device;
}}
if (!devices.length) {{
setMessage(
data.error || "Wi-Fi интерфейсы не найдены.",
true
);
}} else if (
devices.length === 1
&& !devices[0].available
) {{
setMessage(
devices[0].reason || "Wi-Fi интерфейс недоступен.",
true
);
}} else if (devices.length > 1) {{
setMessage(
"Выберите интерфейс, через который выполнять операцию."
);
}}
if (data.wireguard_active) {{
setWarning(
"Обнаружено активное соединение WireGuard. "
+ "При необходимости отключите VPN вручную. "
+ "Приложение не изменяет состояние WireGuard."
);
}} else if (data.wireguard_error) {{
setWarning(
"Не удалось проверить состояние WireGuard: "
+ data.wireguard_error
);
}}
updateButtons();
}} catch (error) {{
setMessage(
error.message || "Ошибка получения Wi-Fi интерфейсов.",
true
);
}}
}}
root.addEventListener("change", function(event) {{
if (event.target === interfaceSelect) {{
updateButtons();
}}
}});
root.addEventListener("click", async function(event) {{
const button = event.target.closest(
"[data-wifi-action]"
);
if (!button || busy || button.disabled) {{
return;
}}
const interfaceName = selectedInterface();
if (!interfaceName) {{
setMessage(
"Выберите доступный Wi-Fi интерфейс.",
true
);
return;
}}
const action = button.dataset.wifiAction;
const row = button.closest(
".wifi-credential-row"
);
const password = row
? row.dataset.password
: null;
const endpoint = action === "verify"
? "/api/network/verify"
: "/api/network/connect";
busy = true;
updateButtons();
setMessage(
action === "verify"
? "Выполняется проверка пароля..."
: "Выполняется подключение..."
);
try {{
const response = await fetch(
endpoint,
{{
method: "POST",
headers: {{
"Content-Type": "application/json"
}},
body: JSON.stringify({{
interface: interfaceName,
bssid: root.dataset.bssid,
password: password
}})
}}
);
const data = await response.json();
if (
!response.ok
|| !data.ok
|| data.success === false
) {{
throw new Error(
data.error || "Операция завершилась ошибкой."
);
}}
if (action === "verify") {{
if (!data.verified) {{
throw new Error(
"Сервер не подтвердил проверку пароля."
);
}}
row.dataset.verified = "true";
const status = row.querySelector(
"[data-verification-status]"
);
status.textContent = "Пароль успешно проверен";
status.style.color = "var(--green)";
button.textContent = "Проверен";
setMessage(
"Пароль успешно проверен. Теперь доступно подключение."
);
}} else {{
setMessage(
"Подключение успешно: "
+ (data.ssid || root.dataset.bssid)
);
}}
if (data.wireguard_warning) {{
setWarning(data.wireguard_warning);
}}
}} catch (error) {{
setMessage(
error.message || "Ошибка выполнения операции.",
true
);
}} finally {{
busy = false;
updateButtons();
}}
}});
loadInterfaces();
}})();
</script>
"""
)
def render_access_point_page( def render_access_point_page(
conn, conn,