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 0aa70fb..b554265 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 @@ -58,7 +58,7 @@ }; const setPacAsync = function setPacAsync( - pacData = mandatory(), cb = throwIfError + pacData = mandatory(), cb = throwIfError, ) { const config = { @@ -80,7 +80,7 @@ console.warn('Failed, other extension is in control.'); return cb( - new Error( window.utils.messages.whichExtensionHtml() ) + new Error( window.utils.messages.whichExtensionHtml() ), ); } @@ -99,20 +99,20 @@ cb = asyncLogGroup( 'Getting IPs for PAC hosts...', - cb + cb, ); window.utils.fireRequest('ip-to-host-update-all', cb); }; const setPacScriptFromProviderAsync = function setPacScriptFromProviderAsync( - provider, lastModifiedStr = mandatory(), cb = throwIfError + provider, lastModifiedStr = mandatory(), cb = throwIfError, ) { const pacUrl = provider.pacUrls[0]; cb = asyncLogGroup( 'Getting PAC script from provider...', pacUrl, - cb + cb, ); const warnings = []; @@ -127,9 +127,8 @@ addWarning( \` Не найдено СВОИХ прокси. Этот PAC-скрипт - теперь работает только со СВОИМИ прокси - (по умолчанию используется локальный TOR и прокси "Антизапрет", для их отключения: Свои прокси -> откл. "Использовать прокси PAC-скрипта"). + (по умолчанию будет использоваться локальный Tor). \`, ); } @@ -139,15 +138,14 @@ httpLib.ifModifiedSince(pacUrl, lastModifiedStr, (err, newLastModifiedStr) => { if (!newLastModifiedStr) { - const res = {lastModified: lastModifiedStr}; const ifWasEverModified = lastModifiedStr !== new Date(0).toUTCString(); if (ifWasEverModified) { addWarning( 'Ваш PAC-скрипт не нуждается в обновлении. Его дата: ' + - lastModifiedStr + lastModifiedStr, ); - + const res = {lastModified: lastModifiedStr}; return cb(null, res); } } @@ -158,11 +156,11 @@ () => new Promise( (resolve, reject) => httpLib.get( url, - (newErr, pacData) => newErr ? reject(newErr) : resolve(pacData) - ) - ) + (newErr, pacData) => newErr ? reject(newErr) : resolve(pacData), + ), + ), ), - Promise.reject() + Promise.reject(), ); pacDataPromise.then( @@ -174,7 +172,7 @@ (err, res) => cb( err, Object.assign(res || {}, {lastModified: newLastModifiedStr}), - ) + ), ); }, @@ -231,7 +229,7 @@ order: 99, pacUrls: [ 'data:application/x-ns-proxy-autoconfig,' + escape('function FindProxyForURL(){ return "DIRECT"; }'), - ] + ], } }, @@ -247,6 +245,12 @@ Do something, e.g. initiate PAC sync. */ ifFirstInstall: false, + /* We have .lastPacUpdateStamp and ._currentPacProviderLastModified. + LastModified is received from a server, we kind of don't trust it, + just use it for cache and maybe show to the user. + UpdateStamp is got from client and we base our timers on it, + malicious server can't interfere with it. + */ lastPacUpdateStamp: 0, setTitle() { @@ -259,7 +263,7 @@ }, - _currentPacProviderLastModified: 0, // Not initialized. + _currentPacProviderLastModified: 0, getLastModifiedForKey(key = mandatory()) { @@ -292,7 +296,7 @@ setCurrentPacProviderKey( newKey = mandatory(), - lastModified = new Date().toUTCString() + lastModified = new Date().toUTCString(), ) { this.mustBeKey(newKey); @@ -332,7 +336,7 @@ chrome.storage.local.clear( () => chrome.storage.local.set( onlySettable, - chromified(cb) + chromified(cb), ) ); @@ -376,8 +380,8 @@ const ipsErrorPromise = new Promise( (resolve, reject) => updatePacProxyIps( - resolve - ) + resolve, + ), ); Promise.all([pacSetPromise, ipsErrorPromise]).then( @@ -391,7 +395,7 @@ warns.push(ipsErr); } this.pushToStorageAsync( - (pushErr) => cb(pacErr || pushErr, null, ...warns) + (pushErr) => cb(pacErr || pushErr, null, ...warns), ); }, @@ -418,7 +422,7 @@ console.log( 'Next PAC update is scheduled on', - new Date(nextUpdateMoment).toLocaleString('ru-RU') + new Date(nextUpdateMoment).toLocaleString('ru-RU'), ); chrome.alarms.create( @@ -461,11 +465,11 @@ } this.setCurrentPacProviderKey(null); this.pushToStorageAsync( - () => handlers.updateControlState(cb) + () => handlers.updateControlState(cb), ); - }) - ) + }), + ), ); }, @@ -493,7 +497,7 @@ if (alarm.name === antiCensorRu._periodicUpdateAlarmReason) { console.log( 'Periodic PAC update triggered:', - new Date().toLocaleString('ru-RU') + new Date().toLocaleString('ru-RU'), ); antiCensorRu.syncWithPacProviderAsync(() => {/* swallow */}); } @@ -533,7 +537,7 @@ || antiCensorRu._currentPacProviderLastModified; console.log( 'Last PAC update was on', - new Date(antiCensorRu.lastPacUpdateStamp).toLocaleString('ru-RU') + new Date(antiCensorRu.lastPacUpdateStamp).toLocaleString('ru-RU'), );