diff --git a/templates/server.html b/templates/server.html index 2d1bfc0..7eafd64 100644 --- a/templates/server.html +++ b/templates/server.html @@ -848,13 +848,16 @@
-
+
- +
@@ -2114,8 +2117,9 @@ currentConfig = result.config; currentVpnLink = result.vpn_link || ''; currentConfigName = connName.replace(/\s+/g, '_'); + currentConfigClientId = result.client_id || null; document.getElementById('configModalTitle').textContent = `${_('config')} — ${connName}`; - document.getElementById('configText').textContent = result.config; + const cfgTa = document.getElementById('configText'); cfgTa.value = result.config; cfgTa.readOnly = false; document.getElementById('vpnLinkText').textContent = currentVpnLink; document.getElementById('panel-vpn').style.display = (proto === 'telemt' ? 'none' : ''); document.querySelectorAll('.config-tab')[1].style.display = (proto === 'telemt' ? 'none' : ''); @@ -2240,9 +2244,33 @@ } } + async function saveConnectionConfig() { + const proto = document.getElementById('connProtoSelect').value; + const text = document.getElementById('configText').value; + if (!text.trim()) { + showToast(_('error'), 'error'); + return; + } + try { + const result = await apiCall(`/api/servers/${SERVER_ID}/connections/config/save`, 'POST', { + protocol: proto, client_id: currentConfigClientId, config: text, + }); + currentConfig = text; + currentVpnLink = result.vpn_link || ''; + document.getElementById('vpnLinkText').textContent = currentVpnLink; + generateQR(text); + showToast(_('config_saved'), 'success'); + } catch (err) { + showToast(_('error') + ': ' + err.message, 'error'); + } + } + async function showConnectionConfig(clientId, connName, hasKey) { const proto = document.getElementById('connProtoSelect').value; currentConfigClientId = clientId; + const canEditCfg = ['awg', 'awg2', 'awg_legacy', 'wireguard'].includes(protoBase(proto)); + document.getElementById('saveConnConfigBtn').style.display = canEditCfg ? '' : 'none'; + document.getElementById('configText').readOnly = !canEditCfg; // Restore tabs visibility first document.getElementById('panel-vpn').style.display = (proto === 'telemt' ? 'none' : ''); @@ -2254,9 +2282,10 @@ if (!hasKey) { document.getElementById('configModalTitle').textContent = `${_('config')} — ${connName}`; currentConfig = ''; + document.getElementById('saveConnConfigBtn').style.display = 'none'; currentVpnLink = ''; currentConfigName = connName.replace(/\s+/g, '_'); - document.getElementById('configText').innerHTML = `
⚠️
${_('config_unavailable')}
${_('config_unavailable_desc').replace(/\\n/g, '
')}

${_('client_public_key')}
${escapeHtml(clientId)}
`; + const cfgTa = document.getElementById('configText'); cfgTa.value = `${_('config_unavailable')}\n\n${_('client_public_key')}: ${clientId}`; cfgTa.readOnly = true; document.getElementById('vpnLinkText').textContent = ''; document.getElementById('panel-vpn').style.display = 'none'; document.getElementById('panel-qr').style.display = 'none'; @@ -2277,7 +2306,7 @@ currentVpnLink = result.vpn_link || ''; currentConfigName = connName.replace(/\s+/g, '_'); document.getElementById('configModalTitle').textContent = `${_('config')} — ${connName}`; - document.getElementById('configText').textContent = result.config; + const cfgTa = document.getElementById('configText'); cfgTa.value = result.config; cfgTa.readOnly = false; document.getElementById('vpnLinkText').textContent = currentVpnLink; switchConfigTab('conf'); openModal('configModal');