Template
Fix linking existing VPN clients (WireGuard/service protocols and API errors).
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+23
-10
@@ -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>`;
|
||||
|
||||
Reference in New Issue
Block a user