From 35668f620bae4dc4a0e9eb2dad16f4f1783a148e Mon Sep 17 00:00:00 2001 From: ilyaigpetrov Date: Sun, 10 Jan 2021 16:43:47 +0000 Subject: [PATCH 01/10] Fix broken migration for <=0.0.1.48 --- ...c-pac-script-with-pac-provider-api.tmpl.js | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) 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..78c65de 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,18 +525,34 @@ // 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')) { + // TODO: + } /* Event handlers that ALWAYS work (even if installation is not done @@ -571,8 +587,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 +601,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 +623,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 +642,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 +657,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(); From 38e2bb2f3c3ee12c5265c6aa0ba6d394c4527c2f Mon Sep 17 00:00:00 2001 From: ilyaigpetrov Date: Tue, 12 Jan 2021 14:18:46 +0000 Subject: [PATCH 02/10] Refactor one line --- .../src/extension-common/35-pac-kitchen-api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..2e14c71 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 @@ -388,7 +388,7 @@ const ifManualExceptions = ifIncluded || ifExcluded; const finalExceptions = {}; if (pacMods.ifProxyMoreDomains) { - pacMods.moreDomains.reduce((acc, tld) => { + finalExceptions = pacMods.moreDomains.reduce((acc, tld) => { acc[tld] = true; return acc; From df3ea9e6ad8a5996c56a8922e352ee871ffbdb6d Mon Sep 17 00:00:00 2001 From: ilyaigpetrov Date: Tue, 12 Jan 2021 15:46:32 +0000 Subject: [PATCH 03/10] Allow non-wildcard exceptions (no migration or interface yet) --- .../src/extension-common/35-pac-kitchen-api.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 2e14c71..f9851f6 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,7 @@ self.included = []; self.excluded = []; for(const host of Object.keys(self.exceptions)) { - if (self.exceptions[host]) { + if (self.exceptions[host]?.ifIncluded) { self.included.push(host); } else { self.excluded.push(host); @@ -390,7 +390,7 @@ if (pacMods.ifProxyMoreDomains) { finalExceptions = pacMods.moreDomains.reduce((acc, tld) => { - acc[tld] = true; + acc[tld] = { ifIncluded: true, ifWild: true }; return acc; }, finalExceptions); @@ -406,7 +406,7 @@ /******/ /* EXCEPTIONS START */ /******/ const dotHost = '.' + host; /******/ const isHostInDomain = (domain) => dotHost.endsWith('.' + domain); -/******/ const domainReducer = (maxWeight, [domain, ifIncluded]) => { +/******/ const domainReducer = (maxWeight, [domain, { ifIncluded, ifWild }]) => { /******/ /******/ if (!isHostInDomain(domain)) { /******/ return maxWeight; From e95c186de132539d012d92d61d82868668f16146 Mon Sep 17 00:00:00 2001 From: ilyaigpetrov Date: Tue, 12 Jan 2021 16:00:29 +0000 Subject: [PATCH 04/10] Handle *. in UI for exceptions --- .../pages/options/src/components/ExcEditor.js | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) 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..f86dfa8 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: {} + ifHostHiddenMap: {} }; 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]) => { + ifHostHiddenMap: this.state.sortedListOfOptions.reduce( + (ifHostHiddenMap, [excHost]) => { - isHostHidden[excHost] = true; - return isHostHidden; + ifHostHiddenMap[excHost] = true; + return ifHostHiddenMap; }, {}), @@ -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; @@ -121,7 +121,7 @@ export default function getExcEditor(theState) { handleRadioClick(event) { - const host = this.state.trimmedInputValueOrSpace; + let host = this.state.trimmedInputValueOrSpace; (() => { // `return` === `preventDefault`. if(!this.isHostValid(host)) { @@ -147,7 +147,8 @@ export default function getExcEditor(theState) { return false; } - pacMods.exceptions[host] = ifYesClicked; + const ifWild = host.startsWith('*.'); + pacMods.exceptions[host.replace(/^\*\./g, '')] = { ifIncluded: ifYesClicked, ifWild }; break; default: @@ -279,7 +280,7 @@ export default function getExcEditor(theState) { })(); this.setState({ - isHostHidden: hidden, + ifHostHiddenMap: hidden, sortedListOfOptions: options, }); @@ -301,7 +302,7 @@ export default function getExcEditor(theState) {
{chrome.i18n.getMessage('ProxyTheDomainNameBelowQ')}
- *. { this.rawInput = inputNode; }} onKeyDown={this.handleKeyDown.bind(this)} @@ -322,7 +323,7 @@ export default function getExcEditor(theState) { // 1. Option's value may be changed to hide it from the tooltip. // 2. Space is used in matching so even an empty input (replaced with space) has tooltip with prompts. return