79 lines
7.1 KiB
HTML
79 lines
7.1 KiB
HTML
<!doctype html>
|
||
<html lang="ru"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||
<title>PAC Router</title>
|
||
<style>
|
||
:root{font-family:system-ui,Segoe UI,Arial,sans-serif;color-scheme:dark;background:#101827;color:#e8eef7}
|
||
body{max-width:1050px;margin:32px auto;padding:0 18px}h1{margin-bottom:5px}p,small{color:#aebcd1}
|
||
section{background:#1a2537;border:1px solid #344358;border-radius:14px;padding:20px;margin:18px 0}
|
||
input,select,button{font:inherit;border-radius:8px;padding:9px 12px;border:1px solid #53657d;background:#111c2d;color:#e8eef7}
|
||
button{cursor:pointer;background:#255d9d;border:0}button:hover{filter:brightness(1.2)}button.danger{background:#843d45}
|
||
input[type=checkbox]{width:18px;height:18px}input{max-width:100%}.row{display:flex;gap:10px;align-items:center;flex-wrap:wrap}
|
||
table{width:100%;border-collapse:collapse}td,th{text-align:left;padding:10px;border-bottom:1px solid #344358}th{color:#b4c5dc}
|
||
#message{min-height:22px;color:#8fd9b0}#message.error{color:#ff9b9b}
|
||
code{color:#9cd5ff}a{color:#9cd5ff}
|
||
@media(max-width:650px){table{font-size:13px}td,th{padding:7px 3px}}
|
||
</style></head>
|
||
<body>
|
||
<h1>🧭 PAC Router</h1>
|
||
<p>Маршрутизация браузера через существующий 3proxy. Всё остальное — напрямую, если не изменён маршрут по умолчанию.</p>
|
||
<div id="message" role="status"></div>
|
||
<section><h2>Настройки</h2>
|
||
<div class="row"><label>Адрес 3proxy <input id="proxyHost" value="127.0.0.1"></label>
|
||
<label>Порт <input id="proxyPort" type="number" min="1" max="65535" value="3128"></label>
|
||
<label>По умолчанию <select id="defaultRoute"><option>DIRECT</option><option>PROXY</option></select></label>
|
||
<button onclick="saveSettings()">Сохранить</button></div>
|
||
<p>Адрес PAC: <a href="/proxy.pac" target="_blank" rel="noopener"><code id="pacUrl"></code></a></p>
|
||
</section>
|
||
<section><h2>Правила</h2><p>Точный домен (<code>example.com</code>) или поддомены (<code>*.example.com</code>). Точный домен имеет приоритет, затем наиболее длинная маска. Маска <code>*.example.com</code> не включает сам <code>example.com</code>.</p>
|
||
<div class="row"><input id="newDomain" placeholder="*.example.com" aria-label="Новый домен">
|
||
<select id="newRoute"><option>PROXY</option><option>DIRECT</option></select>
|
||
<button onclick="addRule()">Добавить</button></div>
|
||
<div style="overflow-x:auto"><table><thead><tr><th>Вкл.</th><th>Домен</th><th>Маршрут</th><th>Действия</th></tr></thead><tbody id="ruleRows"></tbody></table></div>
|
||
</section>
|
||
<section><h2>Проверка маршрута</h2>
|
||
<div class="row"><input id="testHost" placeholder="api.example.com"><button onclick="testRoute()">Проверить</button></div>
|
||
<p id="testResult">Проверка показывает результат правил, а не реальное сетевое соединение.</p></section>
|
||
<section><h2>Резервная копия</h2>
|
||
<div class="row"><button onclick="exportConfig()">Экспорт JSON</button>
|
||
<label>Импорт JSON <input type="file" id="importFile" accept=".json,application/json"></label>
|
||
<button class="danger" onclick="importConfig()">Заменить настройки из файла</button></div>
|
||
<p>Импорт полностью заменяет правила и настройки. Перед импортом рекомендуется экспортировать текущие.</p></section>
|
||
<script>
|
||
const $=id=>document.getElementById(id);
|
||
function message(msg,error=false){$('message').textContent=msg;$('message').className=error?'error':''}
|
||
async function api(path,opts={}){
|
||
const response=await fetch(path,{cache:'no-store',...opts});
|
||
let data=await response.json();
|
||
if(!response.ok)throw Error(typeof data.detail==='string'?data.detail:JSON.stringify(data.detail));
|
||
return data;
|
||
}
|
||
async function run(fn){try{await fn();message('Готово')}catch(e){message(e.message,true)}}
|
||
async function load(){
|
||
const data=await api('/api/state');
|
||
$('proxyHost').value=data.settings.proxy_host;
|
||
$('proxyPort').value=data.settings.proxy_port;
|
||
$('defaultRoute').value=data.settings.default_route;
|
||
const body=$('ruleRows');body.replaceChildren();
|
||
for(const rule of data.rules){
|
||
const tr=document.createElement('tr');
|
||
const td1=document.createElement('td'),cb=document.createElement('input');cb.type='checkbox';cb.checked=rule.enabled;td1.append(cb);
|
||
const td2=document.createElement('td'),input=document.createElement('input');input.value=rule.domain;input.setAttribute('aria-label','Домен');td2.append(input);
|
||
const td3=document.createElement('td'),sel=document.createElement('select');
|
||
for(const v of ['PROXY','DIRECT']){const o=document.createElement('option');o.textContent=v;sel.append(o)}sel.value=rule.route;td3.append(sel);
|
||
const td4=document.createElement('td'),save=document.createElement('button'),del=document.createElement('button');
|
||
save.textContent='Сохранить';del.textContent='Удалить';del.className='danger';
|
||
save.onclick=()=>run(async()=>{await api('/api/rules/'+rule.id,{method:'PUT',headers:{'Content-Type':'application/json'},body:JSON.stringify({domain:input.value,route:sel.value,enabled:cb.checked})});await load()});
|
||
del.onclick=()=>run(async()=>{if(!confirm('Удалить '+rule.domain+'?'))return;await api('/api/rules/'+rule.id,{method:'DELETE'});await load()});
|
||
td4.className='row';td4.append(save,del);tr.append(td1,td2,td3,td4);body.append(tr);
|
||
}
|
||
}
|
||
function payload(obj){return {headers:{'Content-Type':'application/json'},body:JSON.stringify(obj)}}
|
||
async function saveSettings(){await run(async()=>{await api('/api/settings',{method:'PUT',...payload({proxy_host:$('proxyHost').value,proxy_port:Number($('proxyPort').value),default_route:$('defaultRoute').value})});await load()})}
|
||
async function addRule(){await run(async()=>{await api('/api/rules',{method:'POST',...payload({domain:$('newDomain').value,route:$('newRoute').value,enabled:true})});$('newDomain').value='';await load()})}
|
||
async function testRoute(){try{const r=await api('/api/test?host='+encodeURIComponent($('testHost').value));$('testResult').textContent=r.route+' — '+(r.rule?'правило '+r.rule.domain:'маршрут по умолчанию')}catch(e){$('testResult').textContent=e.message}}
|
||
async function exportConfig(){await run(async()=>{const d=await api('/api/export');const blob=new Blob([JSON.stringify(d,null,2)],{type:'application/json'});const url=URL.createObjectURL(blob);const a=document.createElement('a');a.href=url;a.download='pac-router-config.json';a.click();setTimeout(()=>URL.revokeObjectURL(url),1000)})}
|
||
async function importConfig(){await run(async()=>{const f=$('importFile').files[0];if(!f)throw Error('Выбери JSON-файл');const d=JSON.parse(await f.text());if(!confirm('Заменить все текущие настройки и правила?'))return;await api('/api/import',{method:'POST',...payload(d)});await load()})}
|
||
$('pacUrl').textContent=location.origin+'/proxy.pac';
|
||
load().catch(e=>message(e.message,true));
|
||
</script></body></html>
|