Archived
1.0.6 - interfejs mobilny i potwierdzenie
Wydanie WGTools-Extended / release (push) Successful in 9s
Wydanie WGTools-Extended / release (push) Successful in 9s
This commit is contained in:
1 parent
f4929c7cac
commit
97f73a6277
8 files changed
+49
-10
No files matched your search
@@ -1105,12 +1105,18 @@
|
||||
$('forward-service-confirmation').required=on;
|
||||
};
|
||||
$('forward-service-select').addEventListener('change',syncService);
|
||||
const reset=()=>{editing='';$('extended-forward-form').reset();$('extended-forward-restrict').checked=false;syncSources();$('extended-forward-submit').textContent='Dodaj przekierowanie';$('extended-forward-cancel').hidden=true;syncService();};
|
||||
const confirmation=$('forward-service-confirmation');
|
||||
const example=$('forward-confirmation-example');
|
||||
const validateConfirmation=()=>confirmation.setCustomValidity(confirmation.value && confirmation.value!==example.textContent?'Przepisz dokładnie podany tekst.':'');
|
||||
confirmation.addEventListener('input',validateConfirmation);
|
||||
['paste','drop'].forEach(name=>confirmation.addEventListener(name,e=>e.preventDefault()));
|
||||
['copy','cut','dragstart','contextmenu'].forEach(name=>example.addEventListener(name,e=>e.preventDefault()));
|
||||
const reset=()=>{editing='';$('extended-forward-form').reset();confirmation.setCustomValidity('');$('extended-forward-restrict').checked=false;syncSources();$('extended-forward-submit').textContent='Dodaj przekierowanie';$('extended-forward-cancel').hidden=true;syncService();};
|
||||
const syncSources=()=>{const enabled=$('extended-forward-restrict').checked;$('extended-forward-sources-wrap').hidden=!enabled;$('extended-forward-sources').required=enabled;};
|
||||
const loadForwards=async()=>{const r=await fetch(appUrl('/api/extended/forwardings'));const d=await r.json();if(!r.ok)throw new Error(d.error);forwards=d.forwards||[];servicePolicy=d.service_policy||servicePolicy;const sel=$('forward-service-select');sel.innerHTML='<option value="">Wybierz usługę</option>'+servicePolicy.services.map(x=>`<option value="${esc(x)}">${esc(x)}</option>`).join('')+(servicePolicy.mode==='combo'?'<option value="__other__">Inna</option>':'');syncService();const current=$('extended-forward-public').value;$('extended-forward-public').innerHTML=(d.addresses||[]).map(ip=>`<option value="${esc(ip)}">${esc(ip)}</option>`).join('');if((d.addresses||[]).includes(current))$('extended-forward-public').value=current;$('extended-forward-list').innerHTML=forwards.map(f=>`<div class="group-row"><div><span>${esc(f.public_ip)}:${Number(f.public_port)} / ${esc(f.protocol)} → ${esc(f.target_ip)}:${Number(f.target_port)}</span><p>${f.allowed_sources?.length?'Dozwolone adresy: '+esc(f.allowed_sources.join(', ')):'Dostęp ze wszystkich adresów'}</p></div><div class="action-row"><button class="btn small" type="button" data-ext-forward-edit="${esc(f.id)}">Edytuj</button><button class="btn small danger" type="button" data-ext-forward-delete="${esc(f.id)}">Usuń</button></div></div>`).join('')||'<p>Brak przekierowań.</p>';};
|
||||
$('extended-forward-restrict').addEventListener('change',syncSources);$('extended-forward-cancel').addEventListener('click',reset);
|
||||
$('extended-forward-form').addEventListener('submit',async e=>{e.preventDefault();const restricted=$('extended-forward-restrict').checked;const payload={public_ip:$('extended-forward-public').value,public_port:Number($('extended-forward-public-port').value),target_ip:$('extended-forward-target').value,target_port:Number($('extended-forward-target-port').value),protocol:$('extended-forward-protocol').value,service:servicePolicy.enabled?(servicePolicy.mode==='custom'||$('forward-service-select').value==='__other__' ? $('forward-service-custom').value : $('forward-service-select').value):'',confirmation:servicePolicy.enabled?$('forward-service-confirmation').value:'',restrict_sources:restricted,allowed_sources:restricted?$('extended-forward-sources').value.split(',').map(x=>x.trim()).filter(Boolean):[]};if(editing)payload.id=editing;const button=$('extended-forward-submit');button.disabled=true;try{const r=await fetch(appUrl(editing?'/api/extended/forwardings/update':'/api/extended/forwardings'),{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(payload)});const d=await r.json();if(!r.ok)throw new Error(d.error);reset();await loadForwards();operationStatus('extended-forward-status','Zapisano przekierowanie.','success');}catch(err){operationStatus('extended-forward-status',err.message,'error');}finally{button.disabled=false;}});
|
||||
$('extended-forward-list').addEventListener('click',async e=>{const edit=e.target.closest('[data-ext-forward-edit]'),del=e.target.closest('[data-ext-forward-delete]');if(edit){const f=forwards.find(x=>x.id===edit.dataset.extForwardEdit);if(!f)return;editing=f.id;$('extended-forward-public').value=f.public_ip;$('extended-forward-public-port').value=f.public_port;$('extended-forward-target').value=f.target_ip;$('extended-forward-target-port').value=f.target_port;$('extended-forward-protocol').value=f.protocol;const custom=servicePolicy.mode==='custom'||!servicePolicy.services.includes(f.service);$('forward-service-select').value=custom?'__other__':(f.service||'');$('forward-service-custom').value=custom?(f.service||''):'';$('forward-service-confirmation').value='';syncService();$('extended-forward-restrict').checked=Boolean(f.allowed_sources?.length);$('extended-forward-sources').value=(f.allowed_sources||[]).join(', ');syncSources();$('extended-forward-submit').textContent='Zapisz zmiany';$('extended-forward-cancel').hidden=false;operationStatus('extended-forward-status','Edytujesz przekierowanie.','working');$('extended-forward-form').scrollIntoView({behavior:'smooth',block:'center'});return;}if(!del||!confirm('Usunąć przekierowanie?'))return;try{const r=await fetch(appUrl('/api/extended/forwardings/delete'),{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({id:del.dataset.extForwardDelete})});const d=await r.json();if(!r.ok)throw new Error(d.error);if(editing===del.dataset.extForwardDelete)reset();await loadForwards();}catch(err){operationStatus('extended-forward-status',err.message,'error');}});
|
||||
$('extended-forward-list').addEventListener('click',async e=>{const edit=e.target.closest('[data-ext-forward-edit]'),del=e.target.closest('[data-ext-forward-delete]');if(edit){const f=forwards.find(x=>x.id===edit.dataset.extForwardEdit);if(!f)return;editing=f.id;$('extended-forward-public').value=f.public_ip;$('extended-forward-public-port').value=f.public_port;$('extended-forward-target').value=f.target_ip;$('extended-forward-target-port').value=f.target_port;$('extended-forward-protocol').value=f.protocol;const custom=servicePolicy.mode==='custom'||!servicePolicy.services.includes(f.service);$('forward-service-select').value=custom?'__other__':(f.service||'');$('forward-service-custom').value=custom?(f.service||''):'';$('forward-service-confirmation').value='';confirmation.setCustomValidity('');syncService();$('extended-forward-restrict').checked=Boolean(f.allowed_sources?.length);$('extended-forward-sources').value=(f.allowed_sources||[]).join(', ');syncSources();$('extended-forward-submit').textContent='Zapisz zmiany';$('extended-forward-cancel').hidden=false;operationStatus('extended-forward-status','Edytujesz przekierowanie.','working');$('extended-forward-form').scrollIntoView({behavior:'smooth',block:'center'});return;}if(!del||!confirm('Usunąć przekierowanie?'))return;try{const r=await fetch(appUrl('/api/extended/forwardings/delete'),{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({id:del.dataset.extForwardDelete})});const d=await r.json();if(!r.ok)throw new Error(d.error);if(editing===del.dataset.extForwardDelete)reset();await loadForwards();}catch(err){operationStatus('extended-forward-status',err.message,'error');}});
|
||||
loadForwards().catch(err=>operationStatus('extended-forward-status',err.message,'error'));
|
||||
}
|
||||
if(page==='server' && $('extended-listen-form')){
|
||||
|
||||
Reference in new issue
Block a user