mirror of
https://github.com/andrey271192/amnezia_web-PRO.git
synced 2026-09-20 14:42:00 +00:00
feat: import clients from amnezia configs
This commit is contained in:
@@ -658,6 +658,11 @@ if (directForm) {
|
||||
directForm.addEventListener("submit", (ev) => void downloadDirectConf(ev));
|
||||
}
|
||||
|
||||
const importForm = document.querySelector("#import-form");
|
||||
if (importForm) {
|
||||
importForm.addEventListener("submit", (ev) => void importClientConfig(ev));
|
||||
}
|
||||
|
||||
const instanceForm = document.querySelector("#instance-form");
|
||||
if (instanceForm) {
|
||||
instanceForm.addEventListener("submit", (ev) => void createInstance(ev));
|
||||
@@ -1424,6 +1429,36 @@ async function downloadDirectConf(ev) {
|
||||
}
|
||||
}
|
||||
|
||||
async function importClientConfig(ev) {
|
||||
ev.preventDefault();
|
||||
const nameEl = document.querySelector("#import-name");
|
||||
const configEl = document.querySelector("#import-config");
|
||||
const configText = configEl?.value.trim() || "";
|
||||
if (!configText) {
|
||||
setStatus("Вставьте .conf или JSON backup для импорта.", true);
|
||||
return;
|
||||
}
|
||||
const body = { configText };
|
||||
const nm = nameEl?.value.trim();
|
||||
if (nm) body.clientName = nm;
|
||||
const pid = currentProfileIdValue();
|
||||
if (pid) body.profileId = pid;
|
||||
try {
|
||||
setStatus("Импортирую клиента в текущий инстанс…", false);
|
||||
const data = await api("/api/clients/import-config", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const count = Array.isArray(data.imported) ? data.imported.length : 0;
|
||||
if (configEl) configEl.value = "";
|
||||
if (nameEl) nameEl.value = "";
|
||||
setStatus(`Импортировано клиентов: ${count}. Таблица обновлена.`, false);
|
||||
await loadClients();
|
||||
} catch (e) {
|
||||
setStatus(String(e.message || e), true);
|
||||
}
|
||||
}
|
||||
|
||||
const VARIANT_META = {
|
||||
awg2: { icon: "✨", title: "AmneziaWG 2.0", badge: "NEW" },
|
||||
awg: { icon: "🔮", title: "AmneziaWG", badge: "" },
|
||||
|
||||
Reference in New Issue
Block a user