Fix linking existing VPN clients (WireGuard/service protocols and API errors).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
orohi
2026-07-26 00:31:57 +03:00
co-authored by Cursor
parent 69886f130c
commit e612a7bc34
8 changed files with 109 additions and 46 deletions
+23 -10
View File
@@ -586,6 +586,7 @@
const select = document.getElementById(selectId);
const group = groupId ? document.getElementById(groupId) : null;
select.innerHTML = '';
const vpnBases = new Set(['awg', 'awg2', 'awg_legacy', 'xray', 'telemt', 'wireguard']);
if (serverId === '') {
if (group) group.style.display = 'none';
@@ -597,13 +598,14 @@
let count = 0;
for (const [key, info] of Object.entries(protocols)) {
if (info.installed) {
const opt = document.createElement('option');
opt.value = key;
opt.textContent = key === 'awg' ? 'AmneziaWG' : (key === 'awg2' ? 'AmneziaWG 2.0' : (key === 'awg_legacy' ? 'AWG Legacy' : (key === 'xray' ? 'Xray' : key.toUpperCase())));
select.appendChild(opt);
count++;
}
if (!info.installed) continue;
const base = key.split('__')[0];
if (!vpnBases.has(base)) continue;
const opt = document.createElement('option');
opt.value = key;
opt.textContent = key === 'awg' ? 'AmneziaWG' : (key === 'awg2' ? 'AmneziaWG 2.0' : (key === 'awg_legacy' ? 'AWG Legacy' : (key === 'xray' ? 'Xray' : (key === 'wireguard' ? 'WireGuard' : (key === 'telemt' ? 'Telemt' : key.toUpperCase())))));
select.appendChild(opt);
count++;
}
if (count > 0) {
@@ -765,15 +767,26 @@
const select = document.getElementById('ucExistingClient');
select.innerHTML = `<option value="">${_('loading')}</option>`;
if (!protocol) {
select.innerHTML = `<option value="">${_('no_protocols')}</option>`;
return;
}
try {
const data = await apiCall(`/api/servers/${serverId}/${protocol}/clients`);
const data = await apiCall(`/api/servers/${serverId}/${encodeURIComponent(protocol)}/clients`);
if (!data.clients || data.clients.length === 0) {
select.innerHTML = `<option value="">${_('no_free_conns')}</option>`;
return;
}
select.innerHTML = '';
select.innerHTML = '<option value="">' + _('select_existing_conn') + '</option>';
data.clients.forEach(c => {
select.innerHTML += `<option value="${c.id}">${c.name || 'Unnamed'} (${c.id.substring(0, 8)}...)</option>`;
const id = c.id || '';
const short = id ? (id.length > 8 ? id.substring(0, 8) + '...' : id) : '';
const label = `${c.name || 'Unnamed'}${short ? ' (' + short + ')' : ''}`;
const opt = document.createElement('option');
opt.value = id;
opt.textContent = label;
select.appendChild(opt);
});
} catch (err) {
select.innerHTML = `<option value="">${_('error')}: ${err.message}</option>`;