diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js index bf50d34..101b802 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js @@ -298,7 +298,8 @@ self.included = []; self.excluded = []; for(const host of Object.keys(self.exceptions)) { - if (self.exceptions[host]) { + const ifProxy = self.exceptions[host] || false; + if (ifProxy) { self.included.push(host); } else { self.excluded.push(host); @@ -307,9 +308,9 @@ ['included', 'excluded'].forEach((who) => { self[who] = self[who] - .map( (s) => s.split('').reverse() ) + .map( (domain) => domain.split('').reverse() ) .sort() - .map( (a) => a.reverse().join('') ); + .map( (rDomain) => rDomain.reverse().join('') ); }); if (self.included.length && !self.filteredCustomsString) { @@ -386,11 +387,11 @@ const ifIncluded = pacMods.included && pacMods.included.length; const ifExcluded = pacMods.excluded && pacMods.excluded.length; const ifManualExceptions = ifIncluded || ifExcluded; - const finalExceptions = {}; + let finalExceptions = {}; if (pacMods.ifProxyMoreDomains) { - pacMods.moreDomains.reduce((acc, tld) => { + finalExceptions = pacMods.moreDomains.reduce((acc, tld) => { - acc[tld] = true; + acc['*.' + tld] = true; return acc; }, finalExceptions); @@ -405,17 +406,30 @@ /******/ /******/ /* EXCEPTIONS START */ /******/ const dotHost = '.' + host; -/******/ const isHostInDomain = (domain) => dotHost.endsWith('.' + domain); -/******/ const domainReducer = (maxWeight, [domain, ifIncluded]) => { + // TODO: handle wildcards. +/******/ const isHostInDomain = (domain, ifWild) => { + if (ifWild) { + return dotHost.endsWith(domain.substr(1)); + } + return domain === host; + } +/******/ const domainReducer = (maxWeight, [domain, ifProxy]) => { /******/ -/******/ if (!isHostInDomain(domain)) { + const ifWild = domain.startsWith('*.'); +/******/ if (!isHostInDomain(domain, ifWild)) { /******/ return maxWeight; /******/ } -/******/ const newWeightAbs = domain.length; + let len = domain.length; + if (ifWild) { + len = len === 0 ? len : (len - 2)*2 - 1; + } else { + len = len*2; + } +/******/ const newWeightAbs = len; /******/ if (newWeightAbs < Math.abs(maxWeight)) { /******/ return maxWeight; /******/ } -/******/ return newWeightAbs*(ifIncluded ? 1 : -1); +/******/ return newWeightAbs*(ifProxy ? 1 : -1); /******/ /******/ }; /******/ diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/37-sync-pac-script-with-pac-provider-api.tmpl.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/37-sync-pac-script-with-pac-provider-api.tmpl.js index 04f5409..2569c19 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/37-sync-pac-script-with-pac-provider-api.tmpl.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/37-sync-pac-script-with-pac-provider-api.tmpl.js @@ -525,16 +525,41 @@ // ON EACH LAUNCH, STARTUP, RELOAD, UPDATE, ENABLE (async () => { - let oldStorage = await window.utils.promisedLocalStorage.get('antiCensorRu') || {}; + let oldAntiCensorRu = await window.utils.promisedLocalStorage.get('antiCensorRu') || {}; - if (!Object.keys(oldStorage).length) { + const otherKeys = [ + 'pac-kitchen-if-incontinence', + 'pac-kitchen-mods', + 'ip-to-host', + 'handlers-pac-error', + 'handlers-ext-error', + 'handlers-no-control', + ]; + + if (!Object.keys(oldAntiCensorRu).length) { const storage = await window.utils.promisedLocalStorage.get(null); if (storage.version && window.apis.version.isLeq(storage.version, '0.0.1.48')) { const ffxPacData = storage['firefox-only-pac-data']; delete storage['firefox-only-pac-data']; await window.utils.promisedLocalStorage.clear(); + for(const key of otherKeys) { + await window.utils.promisedLocalStorage.set({ [key]: storage[key] }); + delete storage[key]; + } await window.utils.promisedLocalStorage.set({ antiCensorRu: storage }); - oldStorage = storage; + oldAntiCensorRu = storage; + } + } + if (oldAntiCensorRu.version && window.apis.version.isLeq(oldAntiCensorRu.version, '0.0.1.49')) { + const modsMutated = window.apis.pacKitchen.getPacModsRaw(); + if (modsMutated) { + modsMutated.exceptions = Object.entries(modsMutated.exceptions).reduce((acc, [host, ifProxy]) => { + acc[\`*.\${host}\`] = ifProxy; + return acc; + }, {}); + await new Promise( + (resolve) => window.apis.pacKitchen.keepCookedNowAsync(modsMutated, resolve), + ); } } @@ -571,8 +596,8 @@ console.log('Keep cooked...'); await new Promise((resolve) => window.apis.pacKitchen.keepCookedNowAsync(resolve)); - //console.log('Storage on init:', oldStorage); - antiCensorRu.ifFirstInstall = Object.keys(oldStorage).length === 0; + //console.log('Storage on init:', oldAntiCensorRu); + antiCensorRu.ifFirstInstall = Object.keys(oldAntiCensorRu).length === 0; if (antiCensorRu.ifFirstInstall) { // INSTALL @@ -585,11 +610,11 @@ // LAUNCH, RELOAD, UPDATE // Use old or migrate to default. antiCensorRu._currentPacProviderKey = - oldStorage._currentPacProviderKey || null; + oldAntiCensorRu._currentPacProviderKey || null; antiCensorRu.lastPacUpdateStamp = - oldStorage.lastPacUpdateStamp || antiCensorRu.lastPacUpdateStamp; + oldAntiCensorRu.lastPacUpdateStamp || antiCensorRu.lastPacUpdateStamp; antiCensorRu._currentPacProviderLastModified = - oldStorage._currentPacProviderLastModified + oldAntiCensorRu._currentPacProviderLastModified || antiCensorRu._currentPacProviderLastModified; console.log( 'Last PAC update was on', @@ -607,11 +632,11 @@ await new Promise(async (resolve) => { - const ifUpdating = antiCensorRu.version !== oldStorage.version; + const ifUpdating = antiCensorRu.version !== oldAntiCensorRu.version; if (!ifUpdating) { // LAUNCH, RELOAD, ENABLE - antiCensorRu.pacProviders = oldStorage.pacProviders; + antiCensorRu.pacProviders = oldAntiCensorRu.pacProviders; console.log('Extension launched, reloaded or enabled.'); return resolve(); @@ -626,9 +651,9 @@ }); - console.log('Updating from', oldStorage.version, 'to', antiCensorRu.version); + console.log('Updating from', oldAntiCensorRu.version, 'to', antiCensorRu.version); try { - if (window.apis.version.isLeq(oldStorage.version, '0.0.1.5')) { + if (window.apis.version.isLeq(oldAntiCensorRu.version, '0.0.1.5')) { // Change semicolons to semicolons followed by newlines in proxy string (raw). const migrateProxies = (oldStr) => oldStr.replace(/;\\r?\\n?/g, ';\\n'); @@ -641,7 +666,7 @@ } } - if (window.apis.version.isLeq(oldStorage.version, '0.0.1.25')) { + if (window.apis.version.isLeq(oldAntiCensorRu.version, '0.0.1.25')) { console.log('Switch to Antizapret automatically, only from Anitcensority without own proxies.'); const provKey = antiCensorRu.getCurrentPacProviderKey(); diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ExcEditor.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ExcEditor.js index 13959fb..f33a340 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ExcEditor.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ExcEditor.js @@ -79,14 +79,14 @@ export default function getExcEditor(theState) { props.currentTab && props.currentTab.url && !props.currentTab.url.startsWith('chrome') - ? new URL(props.currentTab.url).hostname.replace(/^www\./g, '') + ? '*.' + (new URL(props.currentTab.url).hostname.replace(/^www\./g, '')) : ''; const pacMods = props.apis.pacKitchen.getPacMods(); this.state = { trimmedInputValueOrSpace, sortedListOfOptions: this.modsToOpts(pacMods), - isHostHidden: {} + hostToIfHidden: {}, }; this.handleRadioClick = this.handleRadioClick.bind(this); this.handleInputOrClick = this.handleInputOrClick.bind(this); @@ -96,11 +96,11 @@ export default function getExcEditor(theState) { hideAllOptions() { this.setState({ - isHostHidden: this.state.sortedListOfOptions.reduce( - (isHostHidden, [excHost]) => { + hostToIfHidden: this.state.sortedListOfOptions.reduce( + (hostToIfHidden, [excHost]) => { - isHostHidden[excHost] = true; - return isHostHidden; + hostToIfHidden[excHost] = true; + return hostToIfHidden; }, {}), @@ -110,7 +110,7 @@ export default function getExcEditor(theState) { isHostValid(host) { - const ValidHostnameRegex = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/; + const ValidHostnameRegex = /^(?:\*\.)?(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/; if(!ValidHostnameRegex.test(host)) { this.props.funs.showErrors(new TypeError('Должно быть только доменное имя, без протокола, порта и пути. Попробуйте ещё раз.')); return false; @@ -210,7 +210,9 @@ export default function getExcEditor(theState) { const ifInit = !event; const currentHost = ifTriangleClicked ? '' : (trimmedInput || (ifInit ? '' : ' ')); setInputValue(currentHost); - this.setState({trimmedInputValueOrSpace: currentHost}); + this.setState({ + trimmedInputValueOrSpace: currentHost, + }); // Episode 2. @@ -279,7 +281,7 @@ export default function getExcEditor(theState) { })(); this.setState({ - isHostHidden: hidden, + hostToIfHidden: hidden, sortedListOfOptions: options, }); @@ -301,7 +303,7 @@ export default function getExcEditor(theState) {