Dashboard VPN: per-browser VPN toggle with country picker
- manager/vpn-pool.js: free proxy pool from ProxyScrape JSON (no key), live-checked via curl, cached 30 min, grouped by country - server.js: GET /api/vpn/pool, POST /api/vpn/refresh, POST /api/browsers/:id/vpn; vpn state stored in meta.json - generate.js: 5th arg vpnJson, stored in meta.json - index.html: VPN section in Settings (toggle + country + refresh), VPN badge on cells, manual proxy disabled while VPN is on - README: VPN section + file list Verified live on 49.128.189.254: 24 working proxies in 11 countries, b1 VPN on (PH 180.232.127.250) showed the proxy IP, off restored direct
This commit is contained in:
1 parent
df4ae5a17a
commit
26427401db
5 files changed
+426
-13
No files matched your search
+127
-4
@@ -38,6 +38,7 @@
|
||||
.badge.running{background:var(--accent-dark);color:var(--accent)}
|
||||
.badge.stopped{background:#3d1a1a;color:var(--danger)}
|
||||
.badge.master{background:#3b2f0b;color:var(--warn)}
|
||||
.badge.vpn{background:#123a5c;color:#93c5fd}
|
||||
.cell.is-master{border-color:var(--warn)}
|
||||
button.sync-on{background:var(--accent);border-color:var(--accent);color:#06281c;font-weight:600}
|
||||
.identity{margin-top:4px;color:var(--muted);font-size:12px;word-break:break-word}
|
||||
@@ -78,7 +79,7 @@
|
||||
<button id="stopAllBtn" type="button">Stop semua</button>
|
||||
<button id="syncBtn" type="button" title="Saat ON, kendalikan 1 browser dan semua browser lain ikut (klik, scroll, ketik, paste).">Sinkron: OFF</button>
|
||||
</header>
|
||||
<p class="note"><b>Cara pakai:</b> login sekali dengan password farm — semua browser langsung terhubung otomatis. Tiap cell adalah browser Chromium sendiri (profil, cookie, dan IP terpisah). Settings mengubah User-Agent & proxy, lalu browser restart otomatis. <b>Sinkron:</b> nyalakan tombol di atas, lalu klik/ketik/paste di satu browser — semua browser lain ikut melakukan hal yang sama. Browser yang terakhir kamu sentuh jadi Master (badge kuning).</p>
|
||||
<p class="note"><b>Cara pakai:</b> login sekali dengan password farm — semua browser langsung terhubung otomatis. Tiap cell adalah browser Chromium sendiri (profil, cookie, dan IP terpisah). Settings mengubah User-Agent & proxy, lalu browser restart otomatis. <b>VPN:</b> di Settings tiap browser ada saklar VPN — nyalakan, pilih negara, dan browser itu jalan lewat server VPN (IP/nagara berubah) tanpa buka ekstensi Browsec di dalam browser. <b>Sinkron:</b> nyalakan tombol di atas, lalu klik/ketik/paste di satu browser — semua browser lain ikut melakukan hal yang sama. Browser yang terakhir kamu sentuh jadi Master (badge kuning).</p>
|
||||
<div class="banner" id="banner"></div>
|
||||
<main class="grid" id="grid"></main>
|
||||
|
||||
@@ -204,6 +205,11 @@
|
||||
}
|
||||
|
||||
function identityLine(b) {
|
||||
var v = b.vpn || { on: false };
|
||||
if (v.on) {
|
||||
return (b.uaLabel || b.uaKey || '-') + ' · VPN ' + (v.country || v.countryCode || '') +
|
||||
' (' + (v.type || '') + ' ' + (v.host || '') + ':' + (v.port || '') + ')';
|
||||
}
|
||||
var p = b.proxy || { type: 'direct' };
|
||||
var proxyText = 'Direct';
|
||||
if (p.type && p.type !== 'direct') {
|
||||
@@ -228,6 +234,9 @@
|
||||
title.appendChild(el('strong', null, b.name));
|
||||
var badge = el('span', 'badge stopped', 'Stopped');
|
||||
title.appendChild(badge);
|
||||
var vpnBadge = el('span', 'badge vpn', 'VPN');
|
||||
vpnBadge.style.display = 'none';
|
||||
title.appendChild(vpnBadge);
|
||||
var masterBadge = el('span', 'badge master', 'Master');
|
||||
masterBadge.style.display = 'none';
|
||||
title.appendChild(masterBadge);
|
||||
@@ -277,9 +286,23 @@
|
||||
saveSettings(b.id);
|
||||
});
|
||||
form.innerHTML =
|
||||
'<label>VPN (lewat dashboard — tanpa buka Browsec di browser)</label>' +
|
||||
'<div class="row">' +
|
||||
'<div><select name="vpnOn">' +
|
||||
'<option value="off">VPN mati</option>' +
|
||||
'<option value="on">VPN nyala</option>' +
|
||||
'</select></div>' +
|
||||
'<div><select name="vpnCountry">' +
|
||||
'<option value="">Otomatis (negara mana saja)</option>' +
|
||||
'</select></div>' +
|
||||
'</div>' +
|
||||
'<div class="msg vpnmsg"></div>' +
|
||||
'<div class="actions">' +
|
||||
'<button type="button" class="vpnRefreshBtn">Refresh daftar negara VPN</button>' +
|
||||
'</div>' +
|
||||
'<label>User-Agent</label>' +
|
||||
'<select name="ua"></select>' +
|
||||
'<label>Proxy</label>' +
|
||||
'<label>Proxy manual (dipakai kalau VPN mati)</label>' +
|
||||
'<select name="proxyType">' +
|
||||
'<option value="direct">Direct (tanpa proxy)</option>' +
|
||||
'<option value="http">HTTP</option>' +
|
||||
@@ -301,11 +324,27 @@
|
||||
form.querySelector('.cancelBtn').addEventListener('click', function () {
|
||||
form.classList.remove('open');
|
||||
});
|
||||
// VPN on => the manual proxy fields are ignored (the VPN server is
|
||||
// the proxy), so disable them to avoid confusion.
|
||||
form.querySelector('select[name="vpnOn"]').addEventListener('change', function () {
|
||||
var on = form.querySelector('select[name="vpnOn"]').value === 'on';
|
||||
['proxyType', 'host', 'port', 'user', 'pass'].forEach(function (n) {
|
||||
var inp = form.querySelector('[name="' + n + '"]');
|
||||
if (inp) inp.disabled = on;
|
||||
});
|
||||
});
|
||||
form.querySelector('.vpnRefreshBtn').addEventListener('click', function () {
|
||||
setVpnMsg(b.id, 'Me-refresh daftar negara VPN...', false);
|
||||
fetch('/api/vpn/refresh', { method: 'POST' })
|
||||
.then(function () { return loadVpnPool(); })
|
||||
.then(function () { setVpnMsg(b.id, 'Daftar negara VPN diperbarui.', false); })
|
||||
.catch(function () { setVpnMsg(b.id, 'Gagal refresh pool VPN.', true); });
|
||||
});
|
||||
cell.appendChild(form);
|
||||
|
||||
grid.appendChild(cell);
|
||||
cells[b.id] = {
|
||||
el: cell, iframe: frame, overlay: overlay, badge: badge,
|
||||
el: cell, iframe: frame, overlay: overlay, badge: badge, vpnBadge: vpnBadge,
|
||||
identity: identity, form: form, prevStatus: null, iframeLoaded: false,
|
||||
tokenLoaded: false, masterBadge: masterBadge, inputEl: null, inputPoll: null,
|
||||
};
|
||||
@@ -589,6 +628,46 @@
|
||||
syncBtn.addEventListener('click', function () { setSync(!syncOn); });
|
||||
renderSyncBtn();
|
||||
|
||||
// ---- Dashboard VPN pool ----
|
||||
// Countries offered by the VPN toggle come from the manager's pool
|
||||
// (free proxy servers, verified live). Loaded lazily when a Settings
|
||||
// form opens; refreshed on demand via the Refresh button.
|
||||
var vpnPoolCache = null;
|
||||
function fillVpnCountries() {
|
||||
var countries = (vpnPoolCache && vpnPoolCache.countries) || [];
|
||||
Object.keys(cells).forEach(function (id) {
|
||||
var sel = cells[id].form.querySelector('select[name="vpnCountry"]');
|
||||
if (!sel) return;
|
||||
var cur = sel.value;
|
||||
sel.innerHTML = '<option value="">Otomatis (negara mana saja)</option>';
|
||||
countries.forEach(function (c) {
|
||||
var opt = document.createElement('option');
|
||||
opt.value = c.code;
|
||||
opt.textContent = c.name + ' (' + c.count + ')';
|
||||
sel.appendChild(opt);
|
||||
});
|
||||
sel.value = cur || '';
|
||||
});
|
||||
}
|
||||
function loadVpnPool() {
|
||||
return fetch('/api/vpn/pool')
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (j) {
|
||||
vpnPoolCache = j;
|
||||
fillVpnCountries();
|
||||
return j;
|
||||
})
|
||||
.catch(function () { /* pool stays empty; turning VPN on will report it */ });
|
||||
}
|
||||
function setVpnMsg(id, text, isErr) {
|
||||
var c = cells[id];
|
||||
if (!c) return;
|
||||
var m = c.form.querySelector('.vpnmsg');
|
||||
if (!m) return;
|
||||
m.textContent = text;
|
||||
m.classList.toggle('err', !!isErr);
|
||||
}
|
||||
|
||||
function fillUaOptions() {
|
||||
Object.keys(cells).forEach(function (id) {
|
||||
var sel = cells[id].form.querySelector('select[name="ua"]');
|
||||
@@ -606,6 +685,18 @@
|
||||
var c = cells[id];
|
||||
var sel = c.form.querySelector('select[name="ua"]');
|
||||
sel.value = b.uaKey || '';
|
||||
var v = b.vpn || { on: false };
|
||||
var vpnOn = !!v.on;
|
||||
c.form.querySelector('select[name="vpnOn"]').value = vpnOn ? 'on' : 'off';
|
||||
c.form.querySelector('select[name="vpnCountry"]').value = v.countryCode || '';
|
||||
setVpnMsg(id, vpnOn
|
||||
? ('VPN nyala: ' + (v.country || v.countryCode || '') + ' · ' + (v.type || '') + ' ' + (v.host || '') + ':' + (v.port || ''))
|
||||
: 'VPN mati — browser pakai koneksi langsung / proxy manual di bawah.', false);
|
||||
['proxyType', 'host', 'port', 'user', 'pass'].forEach(function (n) {
|
||||
var inp = c.form.querySelector('[name="' + n + '"]');
|
||||
if (inp) inp.disabled = vpnOn;
|
||||
});
|
||||
loadVpnPool();
|
||||
var p = b.proxy || { type: 'direct' };
|
||||
c.form.querySelector('select[name="proxyType"]').value = p.type || 'direct';
|
||||
c.form.querySelector('input[name="host"]').value = p.host || '';
|
||||
@@ -661,6 +752,33 @@
|
||||
function saveSettings(id) {
|
||||
var c = cells[id];
|
||||
var f = c.form;
|
||||
var ua = f.querySelector('select[name="ua"]').value;
|
||||
var vpnOn = f.querySelector('select[name="vpnOn"]').value === 'on';
|
||||
if (vpnOn) {
|
||||
// VPN on: the dashboard picks a working server from the pool for
|
||||
// the chosen country (or any country) and restarts the browser
|
||||
// through it. The manual proxy is ignored while VPN is on.
|
||||
var country = f.querySelector('select[name="vpnCountry"]').value;
|
||||
setMsg(id, 'Menyalakan VPN & restart browser...', false);
|
||||
fetch('/api/browsers/' + encodeURIComponent(id) + '/vpn', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ on: true, country: country, ua: ua }),
|
||||
})
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (j) {
|
||||
if (!j.ok) throw new Error(j.error || 'gagal menyalakan VPN');
|
||||
var v = j.vpn || {};
|
||||
setMsg(id, 'VPN nyala: ' + (v.country || '') + ' · ' + (v.type || '') + ' ' + (v.host || '') + ':' + (v.port || ''), false);
|
||||
return refresh();
|
||||
})
|
||||
.catch(function (e) {
|
||||
setMsg(id, 'Gagal: ' + e.message, true);
|
||||
});
|
||||
return;
|
||||
}
|
||||
// VPN off: manual proxy / direct, as before (this also clears the
|
||||
// dashboard VPN state on the server).
|
||||
var proxyType = f.querySelector('select[name="proxyType"]').value;
|
||||
var proxy = { type: proxyType };
|
||||
if (proxyType !== 'direct') {
|
||||
@@ -670,7 +788,7 @@
|
||||
proxy.pass = f.querySelector('input[name="pass"]').value;
|
||||
}
|
||||
var body = {
|
||||
ua: f.querySelector('select[name="ua"]').value,
|
||||
ua: ua,
|
||||
proxy: proxy,
|
||||
};
|
||||
setMsg(id, 'Menyimpan & restart browser...', false);
|
||||
@@ -697,6 +815,11 @@
|
||||
var running = b.status === 'running';
|
||||
c.badge.textContent = running ? 'Running' : 'Stopped';
|
||||
c.badge.className = 'badge ' + (running ? 'running' : 'stopped');
|
||||
var v = b.vpn || { on: false };
|
||||
if (c.vpnBadge) {
|
||||
c.vpnBadge.style.display = v.on ? '' : 'none';
|
||||
c.vpnBadge.textContent = 'VPN · ' + (v.countryCode || v.country || '');
|
||||
}
|
||||
c.identity.textContent = identityLine(b);
|
||||
c.overlay.style.display = running ? 'none' : 'flex';
|
||||
if (running) {
|
||||
|
||||
Reference in new issue
Block a user