Update public source

This commit is contained in:
2026-10-21 13:07:48 +03:00
parent d5594ace92
commit 05f83fd186
+193 -6
View File
@@ -413,6 +413,188 @@ map.on(
} }
); );
let wifiConnectionBusy = false;
const wifiInterfaceSelect = document.getElementById(
"wifi-connections-interface"
);
const wifiConnectionMessage = document.getElementById(
"wifi-connections-message"
);
const wifiConnectionWarning = document.getElementById(
"wifi-connections-warning"
);
function setWifiConnectionMessage(text, isError = false) {
if (!wifiConnectionMessage) {
return;
}
wifiConnectionMessage.textContent = text || "";
wifiConnectionMessage.style.color = isError
? "var(--red)"
: "var(--muted)";
}
function updateWifiConnectButtons() {
const interfaceReady = Boolean(
wifiInterfaceSelect
&& wifiInterfaceSelect.value
);
document.querySelectorAll(
"[data-wifi-connect]"
).forEach(function(button) {
button.disabled =
wifiConnectionBusy || !interfaceReady;
});
}
if (wifiInterfaceSelect) {
wifiInterfaceSelect.addEventListener(
"change",
updateWifiConnectButtons
);
}
updateWifiConnectButtons();
document.addEventListener(
"click",
async function(event) {
const target = event.target;
if (!(target instanceof Element)) {
return;
}
const button = target.closest(
"[data-wifi-connect]"
);
if (!button || wifiConnectionBusy) {
return;
}
event.preventDefault();
const interfaceName = wifiInterfaceSelect
? wifiInterfaceSelect.value
: "";
if (!interfaceName) {
setWifiConnectionMessage(
"Выберите доступный Wi-Fi интерфейс.",
true
);
return;
}
const bssid = button.dataset.bssid;
const isOpen = button.dataset.open === "true";
if (!bssid) {
setWifiConnectionMessage(
"Не указан BSSID точки доступа.",
true
);
return;
}
let password = null;
if (!isOpen) {
const action = button.closest(
".wifi-connection-action"
);
const passwordSelect = action
? action.querySelector("[data-wifi-password]")
: null;
password = passwordSelect
? passwordSelect.value
: "";
if (!password) {
setWifiConnectionMessage(
"Выберите проверенный пароль.",
true
);
return;
}
}
wifiConnectionBusy = true;
updateWifiConnectButtons();
setWifiConnectionMessage(
"Выполняется подключение к " + bssid + "..."
);
try {
const payload = {
interface: interfaceName,
bssid: bssid
};
if (!isOpen) {
payload.password = password;
}
const response = await fetch(
"/api/network/connect",
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
}
);
const data = await response.json();
if (
!response.ok
|| !data.ok
|| data.success === false
) {
throw new Error(
data.error || "Не удалось подключиться."
);
}
setWifiConnectionMessage(
"Подключение успешно: "
+ (data.ssid || bssid)
);
if (
data.wireguard_warning
&& wifiConnectionWarning
) {
wifiConnectionWarning.textContent =
data.wireguard_warning;
wifiConnectionWarning.hidden = false;
}
} catch (error) {
setWifiConnectionMessage(
error.message
|| "Ошибка подключения к точке доступа.",
true
);
} finally {
wifiConnectionBusy = false;
updateWifiConnectButtons();
}
}
);
const allFeatures = const allFeatures =
verifiedWpaFeatures.concat(openFeatures); verifiedWpaFeatures.concat(openFeatures);
@@ -621,19 +803,24 @@ def render_wifi_connections_page(conn, context=None):
interfaceSelect.appendChild(option); interfaceSelect.appendChild(option);
}); });
if ( const availableDevices = devices.filter(
device => device.available
);
if (availableDevices.length === 1) {
interfaceSelect.value =
availableDevices[0].device;
} else if (
data.selected_device data.selected_device
&& devices.some(device => && availableDevices.some(device =>
device.device === data.selected_device device.device === data.selected_device
&& device.available
) )
) { ) {
interfaceSelect.value = data.selected_device; interfaceSelect.value = data.selected_device;
} }
interfaceSelect.disabled = interfaceSelect.disabled =
!devices.some(device => device.available) availableDevices.length <= 1;
|| devices.filter(device => device.available).length <= 1;
if (!devices.length) { if (!devices.length) {
setMessage( setMessage(
@@ -651,7 +838,7 @@ def render_wifi_connections_page(conn, context=None):
).join("; "), ).join("; "),
true true
); );
} else if (devices.length > 1) { } else if (availableDevices.length > 1) {
setMessage( setMessage(
"Выберите доступный Wi-Fi интерфейс." "Выберите доступный Wi-Fi интерфейс."
); );