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