Исправил баг с загрузкой конфигурации AP сети в Settings. Добавил возможность изменять из в админ панели. Применил их к AP сети. Изменил функциональность endpoint'ов и удалил лишние. Обновил README

This commit is contained in:
2026-09-30 18:29:00 +07:00
parent 371cdfb6c5
commit 940695f6aa
9 changed files with 615 additions and 292 deletions
+71 -39
View File
@@ -1,30 +1,53 @@
async function ap_update()
{
const ssid = document.querySelector('#ap-ssid');
const pass = document.querySelector('#ap-password');
const ssid = document.getElementById('ap-ssid');
const pass = document.getElementById('ap-password');
const ip = document.getElementById('ap-ip');
const gateway = document.getElementById('ap-gateway');
const mask = document.getElementById('ap-mask');
const response = await fetch("/settings/ap_update", {
let body = {};
if (ssid.value != "")
{
body.ssid = ssid.value;
if (pass.value === "")
body.pass = "";
else
body.pass = pass.value;
}
if (ip.value != "")
body.ip = ip.value;
if (gateway.value != "")
body.gateway = gateway.value;
if (mask.value != "")
body.mask = mask.value;
const res = await fetch("/settings/ap_update",{
method: "POST",
headers: {
'Content-Type': 'application/json;charset=utf-8'
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify({ssid: ssid.value, pass: pass.value})
body: JSON.stringify(body)
});
if (!response.ok)
alert("Fail set AP settings");
if (res.ok)
init();
else
alert("Неудплось обновить параметры AP сети");
}
async function sta_update()
{
const ssid = document.querySelector('#sta-ssid');
const pass = document.querySelector('#sta-password');
const ssid = document.getElementById('sta-ssid');
const pass = document.getElementById('sta-password');
const checkbox = document.getElementById('connection-out');
const response = await fetch("/settings/sta_update", {
method: "POST",
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify({ssid: ssid.value, pass: pass.value})
body: JSON.stringify({ssid: ssid.value, pass: pass.value, is_conn_out: checkbox.checked})
});
if (!response.ok)
@@ -53,40 +76,52 @@ async function admin_update()
alert("Ошибка! Пароль не обновился");
}
async function set_conn_out()
{
const checkbox = document.getElementById('connection-out');
function updateConnectionStatus(isConnected/*, networkName = ''*/) {
const statusElem = document.getElementById('connection-status');
const response = await fetch("/settings/set_conn_out", {
method: "POST",
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify({is_conn_out: checkbox.checked})
});
if (!response.ok)
alert("Fail set CONN_TO_OUT settings");
if (isConnected) {
statusElem.textContent = 'Подключено';
statusElem.className = 'info-value status-connected';
} else {
statusElem.textContent = 'Отключено';
statusElem.className = 'info-value status-disconnected';
ssidElem.textContent = '—';
}
}
async function init()
{
try {
const res = await fetch("/settings/is_conn_out", {
method: "GET"
});
const res = await fetch("/settings/current_settings");
if (res.ok)
{
const json = await res.json();
if (res.ok) {
const data = await res.json();
const conn_out = document.getElementById('connection-out');
const current_sta = document.getElementById('current-sta-ssid');
current_sta.textContent = json["sta_ssid"];
conn_out.checked = data.is_conn_out;
} else {
console.warn("Сервер вернул ошибку:", res.status);
const current_ap = document.getElementById('current-ap-ssid');
current_ap.textContent = json["ap_ssid"];
const current_ip = document.getElementById('current-ip');
current_ip.textContent = json["ip"];
const current_gateway = document.getElementById('current-gateway');
current_gateway.textContent = json["gateway"];
const current_mask = document.getElementById('current-mask');
current_mask.textContent = json["mask"];
updateConnectionStatus(json["is_conn_out"]);
}
} catch (error) {
console.error("Ошибка при выполнении запроса:", error);
else
{
alert("Неудалось получть текущие настройки");
}
}
catch (error) {
console.log("Ошибка во время запроса настроек: ", error);
}
}
@@ -100,7 +135,4 @@ button = document.querySelector('#sta_update');
button.addEventListener('click', sta_update);
button = document.querySelector('#admin_update');
button.addEventListener('click', admin_update);
const checkbox = document.getElementById('connection-out');
checkbox.addEventListener('change', set_conn_out);
button.addEventListener('click', admin_update);