mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2025-02-07 15:20:36 +03:00
Start adding whitelist capability
This commit is contained in:
parent
e4a936c5f1
commit
d3caee1483
|
@ -105,8 +105,16 @@
|
|||
order: 5,
|
||||
},
|
||||
exceptions: {
|
||||
category: 'exceptions',
|
||||
dflt: null,
|
||||
category: 'exceptions',
|
||||
order: 5.5,
|
||||
},
|
||||
whitelist: {
|
||||
dflt: [],
|
||||
category: 'exceptions',
|
||||
label: 'белый список'
|
||||
desc: 'Разрешить расширению работать только с адресами из белого списка',
|
||||
order: 5.6,
|
||||
},
|
||||
ifMindExceptions: {
|
||||
dflt: true,
|
||||
|
@ -344,18 +352,38 @@
|
|||
/******/
|
||||
/******/ const originalFindProxyForURL = FindProxyForURL;
|
||||
/******/ let tmp = function(url, host) {
|
||||
/******/
|
||||
/******/ const dotHost = '.' + host;
|
||||
${
|
||||
function() {
|
||||
// TODO: STOPPED HERE
|
||||
const wlstr = JSON.stringify(pacMods.whitelist);
|
||||
let generatedPac = `
|
||||
/******/ const ifWhitelisted =
|
||||
/******/ .some((whiteHost) => {
|
||||
/******/ const ifWild = whiteHost.startsWith('*');
|
||||
/******/ if (ifWild) {
|
||||
/******/ return `dotHost.endsWith(whiteHost.substr(1));
|
||||
/******/ }
|
||||
/******/ return host === whiteHost;
|
||||
/******/ })
|
||||
/******/ if (ifWhiteListed) {
|
||||
/******/ return 'DIRECT';
|
||||
/******/ }
|
||||
|
||||
let res = pacMods.ifProhibitDns ? `
|
||||
/******/
|
||||
if (!ifWhitelisted) {
|
||||
return 'DIRECT';
|
||||
}
|
||||
)
|
||||
|
||||
generatedPac += pacMods.ifProhibitDns ? `
|
||||
/******/
|
||||
/******/ global.dnsResolve = function(host) { return null; };
|
||||
/******/
|
||||
/******/` : '';
|
||||
if (pacMods.ifProxyHttpsUrlsOnly) {
|
||||
|
||||
res += `
|
||||
generatedPac += `
|
||||
/******/
|
||||
/******/ if (!url.startsWith("https")) {
|
||||
/******/ return "DIRECT";
|
||||
|
@ -365,7 +393,7 @@
|
|||
}
|
||||
if (pacMods.ifUseLocalTor) {
|
||||
|
||||
res += `
|
||||
generatedPac += `
|
||||
/******/
|
||||
/******/ if (host.endsWith(".onion")) {
|
||||
/******/ return "${pacMods.torPoints.join('; ')}";
|
||||
|
@ -373,12 +401,12 @@
|
|||
/******/
|
||||
/******/ `;
|
||||
}
|
||||
res += `
|
||||
generatedPac += `
|
||||
/******/
|
||||
/******/ const directIfAllowed = ${pacMods.ifProxyOrDie ? '""/* Not allowed. */' : '"DIRECT"'};
|
||||
/******/`;
|
||||
if (pacMods.filteredCustomsString) {
|
||||
res += `
|
||||
generatedPac += `
|
||||
/******/
|
||||
/******/ const filteredCustomProxies = "${pacMods.filteredCustomsString}";
|
||||
/******/`;
|
||||
|
@ -402,10 +430,9 @@
|
|||
const ifExceptions = Object.keys(finalExceptions).length;
|
||||
|
||||
if (ifExceptions) {
|
||||
res += `
|
||||
generatedPac += `
|
||||
/******/
|
||||
/******/ /* EXCEPTIONS START */
|
||||
/******/ const dotHost = '.' + host;
|
||||
// TODO: handle wildcards.
|
||||
/******/ const isHostInDomain = (domain, ifWild) => {
|
||||
if (ifWild) {
|
||||
|
@ -448,7 +475,7 @@ ${ pacMods.filteredCustomsString
|
|||
/******/ /* EXCEPTIONS END */
|
||||
`;
|
||||
}
|
||||
res += `
|
||||
generatedPac += `
|
||||
/******/ const pacScriptProxies = originalFindProxyForURL(url, host)${
|
||||
/******/ pacMods.ifProxyOrDie
|
||||
? '.replace(/DIRECT/g, "")'
|
||||
|
@ -459,12 +486,12 @@ ${ pacMods.filteredCustomsString
|
|||
!pacMods.filteredCustomsString &&
|
||||
pacMods.ifUsePacScriptProxies
|
||||
) {
|
||||
return res + `
|
||||
return generatedPac + `
|
||||
/******/ return [pacScriptProxies, directIfAllowed]
|
||||
.filter((p) => p).join("; ") || "DIRECT";`;
|
||||
}
|
||||
|
||||
return res + `
|
||||
return generatedPac + `
|
||||
/******/ let pacProxyArray = pacScriptProxies.split(/(?:\\s*;\\s*)+/g).filter( (p) => p );
|
||||
/******/ const ifNoProxies = pacProxyArray${pacMods.ifProxyOrDie ? '.length === 0' : '.every( (p) => /^DIRECT$/i.test(p) )'};
|
||||
/******/ if (ifNoProxies) {
|
||||
|
|
|
@ -26,7 +26,16 @@ ${(mods.included || []).join('\n')}
|
|||
===============================
|
||||
# НЕ ПРОКСИРОВАТЬ:
|
||||
|
||||
${(mods.excluded || []).join('\n')}`;
|
||||
${(mods.excluded || []).join('\n')}
|
||||
|
||||
|
||||
===============================
|
||||
# БЕЛЫЙ СПИСОК
|
||||
# Разрешить расширению работать только с этими адресами:
|
||||
|
||||
${(mods.whitelist || []).join('\n')}
|
||||
|
||||
`.trim();
|
||||
|
||||
status.innerText = 'Успешно загружено!';
|
||||
|
||||
|
@ -35,7 +44,7 @@ ${(mods.excluded || []).join('\n')}`;
|
|||
|
||||
saveBtn.onclick = function() {
|
||||
|
||||
let [proxyList, dontProxyList] = editor.value
|
||||
let [proxyList, dontProxyList, whitelist] = editor.value
|
||||
.trim()
|
||||
.replace(/#.*/g, '')
|
||||
.split(/=+/g)
|
||||
|
@ -45,12 +54,14 @@ ${(mods.excluded || []).join('\n')}`;
|
|||
.filter((host) => host)
|
||||
)
|
||||
dontProxyList = dontProxyList || [];
|
||||
whitelist = whitelist || [];
|
||||
|
||||
const exceptions = {};
|
||||
proxyList.forEach((host) => (exceptions[host] = true));
|
||||
dontProxyList.forEach((host) => (exceptions[host] = false));
|
||||
const mods = backgroundPage.apis.pacKitchen.getPacMods();
|
||||
mods.exceptions = exceptions;
|
||||
mods.whitelist = whitelist;
|
||||
backgroundPage.apis.pacKitchen.keepCookedNowAsync(mods, (err) => {
|
||||
if (!err) {
|
||||
status.innerText = 'Успешно сохранено!';
|
||||
|
|
Loading…
Reference in New Issue
Block a user