mirror of
				https://github.com/anticensority/runet-censorship-bypass.git
				synced 2025-10-31 16:07:31 +03:00 
			
		
		
		
	Don't purge ips on changing exceptions, decrease custom porxies' priority, fix exceptions UI, fix GoogleDNS
This commit is contained in:
		
							parent
							
								
									c997689c30
								
							
						
					
					
						commit
						f22a3468b2
					
				|  | @ -2,7 +2,7 @@ | |||
| 
 | ||||
| { | ||||
| 
 | ||||
|   const IF_DEBUG = true; | ||||
|   const IF_DEBUG = false; | ||||
| 
 | ||||
|   if (!IF_DEBUG) { | ||||
|     // I believe logging objects precludes them from being GCed.
 | ||||
|  |  | |||
|  | @ -76,8 +76,7 @@ | |||
| 
 | ||||
|   const getCurrentConfigs = function getCurrentConfigs() { | ||||
| 
 | ||||
|     const mods = kitchenState(modsKey); | ||||
|     return new PacModifiers(mods || {}); | ||||
|     return kitchenState(modsKey) || getDefaults(); | ||||
| 
 | ||||
|   }; | ||||
| 
 | ||||
|  | @ -98,68 +97,66 @@ | |||
| 
 | ||||
|   }; | ||||
| 
 | ||||
|   class PacModifiers { | ||||
|   const createPacModifiers = function createPacModifiers(mods = {}) { | ||||
| 
 | ||||
|     constructor(mods = {}) { | ||||
|     const defaults = getDefaults(); | ||||
|     const ifAllDefaults = Object.keys(defaults) | ||||
|       .every( | ||||
|         (prop) => !(prop in mods) | ||||
|           || Boolean(defaults[prop]) === Boolean(mods[prop]) | ||||
|       ); | ||||
| 
 | ||||
|       const defaults = getDefaults(); | ||||
|       const ifAllDefaults = Object.keys(defaults) | ||||
|         .every( | ||||
|           (prop) => !(prop in mods) | ||||
|             || Boolean(defaults[prop]) === Boolean(mods[prop]) | ||||
|         ); | ||||
|     console.log('Input mods:', mods); | ||||
|     const self = {}; | ||||
|     Object.assign(self, defaults, mods); | ||||
|     self.ifNoMods = ifAllDefaults ? true : false; | ||||
| 
 | ||||
|       console.log('MODS', mods); | ||||
|       Object.assign(this, defaults, mods); | ||||
|       this.ifNoMods = ifAllDefaults ? true : false; | ||||
| 
 | ||||
|       let customProxyArray = []; | ||||
|       if (this.customProxyStringRaw) { | ||||
|         customProxyArray = this.customProxyStringRaw | ||||
|           .replace(/#.*$/mg, '') // Strip comments.
 | ||||
|           .split( /(?:[^\S\r\n]*(?:;|\r?\n)+[^\S\r\n]*)+/g ) | ||||
|           .map( (p) => p.trim() ) | ||||
|           .filter( (p) => p && /\s+/g.test(p) ); | ||||
|         if (this.ifUseSecureProxiesOnly) { | ||||
|           customProxyArray = customProxyArray.filter( (p) => !p.startsWith('HTTP ') ); | ||||
|         } | ||||
|     let customProxyArray = []; | ||||
|     if (self.customProxyStringRaw) { | ||||
|       customProxyArray = self.customProxyStringRaw | ||||
|         .replace(/#.*$/mg, '') // Strip comments.
 | ||||
|         .split( /(?:[^\S\r\n]*(?:;|\r?\n)+[^\S\r\n]*)+/g ) | ||||
|         .map( (p) => p.trim() ) | ||||
|         .filter( (p) => p && /\s+/g.test(p) ); | ||||
|       if (self.ifUseSecureProxiesOnly) { | ||||
|         customProxyArray = customProxyArray.filter( (p) => !p.startsWith('HTTP ') ); | ||||
|       } | ||||
|       if (this.ifUseLocalTor) { | ||||
|         customProxyArray.push('SOCKS5 localhost:9050', 'SOCKS5 localhost:9150'); | ||||
|       } | ||||
| 
 | ||||
|       if (customProxyArray.length) { | ||||
|         this.customProxyArray = customProxyArray; | ||||
|         this.filteredCustomsString = customProxyArray.join('; '); | ||||
|       } else { | ||||
|         if (!this.ifUsePacScriptProxies) { | ||||
|           throw new TypeError('Нет ни одного прокси, удовлетворяющего вашим требованиям!'); | ||||
|         } | ||||
|         this.customProxyArray = false; | ||||
|         this.filteredCustomsString = ''; | ||||
|       } | ||||
| 
 | ||||
|       this.included = this.excluded = undefined; | ||||
|       if (this.ifMindExceptions && this.exceptions) { | ||||
|         this.included = []; | ||||
|         this.excluded = []; | ||||
|         for(const host of Object.keys(this.exceptions)) { | ||||
|           if (this.exceptions[host]) { | ||||
|             this.included.push(host); | ||||
|           } else { | ||||
|             this.excluded.push(host); | ||||
|           } | ||||
|         } | ||||
|         if (this.included.length && !this.filteredCustomsString) { | ||||
|           throw new TypeError( | ||||
|             'Проксировать свои сайты можно только через свои прокси. Нет ни одного своего прокси, удовлетворяющего вашим требованиям!' | ||||
|           ); | ||||
|         } | ||||
|       } | ||||
| 
 | ||||
|     } | ||||
|     if (self.ifUseLocalTor) { | ||||
|       customProxyArray.push('SOCKS5 localhost:9050', 'SOCKS5 localhost:9150'); | ||||
|     } | ||||
| 
 | ||||
|   } | ||||
|     if (customProxyArray.length) { | ||||
|       self.customProxyArray = customProxyArray; | ||||
|       self.filteredCustomsString = customProxyArray.join('; '); | ||||
|     } else { | ||||
|       if (!self.ifUsePacScriptProxies) { | ||||
|         return [new TypeError('Нет ни одного прокси, удовлетворяющего вашим требованиям!')]; | ||||
|       } | ||||
|       self.customProxyArray = false; | ||||
|       self.filteredCustomsString = ''; | ||||
|     } | ||||
| 
 | ||||
|     self.included = self.excluded = undefined; | ||||
|     if (self.ifMindExceptions && self.exceptions) { | ||||
|       self.included = []; | ||||
|       self.excluded = []; | ||||
|       for(const host of Object.keys(self.exceptions)) { | ||||
|         if (self.exceptions[host]) { | ||||
|           self.included.push(host); | ||||
|         } else { | ||||
|           self.excluded.push(host); | ||||
|         } | ||||
|       } | ||||
|       if (self.included.length && !self.filteredCustomsString) { | ||||
|         return [null, self, new TypeError( | ||||
|           'Имеются сайты, добавленные вручную. Они проксироваться не будут, т.к. нет СВОИХ проски, удовлетворяющих вашим запросам!' | ||||
|         )]; | ||||
|       } | ||||
|     } | ||||
|     return [null, self]; | ||||
| 
 | ||||
|   }; | ||||
| 
 | ||||
|   window.apis.pacKitchen = { | ||||
| 
 | ||||
|  | @ -225,7 +222,7 @@ | |||
|       function() { | ||||
| 
 | ||||
|         if (!pacMods.ifUsePacScriptProxies) { | ||||
|           return '"' + pacMods.filteredCustomsString + '"'; | ||||
|           return `"${pacMods.filteredCustomsString}"`; | ||||
|         } | ||||
|         let filteredPacExp = 'pacProxyString'; | ||||
|         if (pacMods.ifUseSecureProxiesOnly) { | ||||
|  | @ -235,7 +232,7 @@ | |||
|         if ( !pacMods.filteredCustomsString ) { | ||||
|           return filteredPacExp; | ||||
|         } | ||||
|         return filteredPacExp + '"; ' + pacMods.filteredCustomsString + '"'; | ||||
|         return `${filteredPacExp} + "; ${pacMods.filteredCustomsString}"`; | ||||
| 
 | ||||
|       }() + ' + "; DIRECT";'; // Without DIRECT you will get 'PROXY CONN FAILED' pac-error.
 | ||||
| 
 | ||||
|  | @ -247,7 +244,7 @@ | |||
| 
 | ||||
|     }, | ||||
| 
 | ||||
|     _tryNowAsync(details, cb = throwIfError) { | ||||
|     setNowAsync(details, cb = throwIfError) { | ||||
| 
 | ||||
|       if (typeof(details) === 'function') { | ||||
|         cb = details; | ||||
|  | @ -288,40 +285,45 @@ | |||
|     checkIncontinence(details) { | ||||
| 
 | ||||
|       if ( kitchenState(ifIncontinence) ) { | ||||
|         this._tryNowAsync(details, () => {/* Swallow. */}); | ||||
|         this.setNowAsync(details, () => {/* Swallow. */}); | ||||
|       } | ||||
| 
 | ||||
|     }, | ||||
| 
 | ||||
|     keepCookedNowAsync(pacMods = mandatory(), cb = throwIfError) { | ||||
| 
 | ||||
|       let ifProxiesChanged = false; | ||||
|       let modsWarns = []; | ||||
|       if (typeof(pacMods) === 'function') { | ||||
|         cb = pacMods; | ||||
|         pacMods = getCurrentConfigs(); | ||||
|       } else { | ||||
|         try { | ||||
|           pacMods = new PacModifiers(pacMods); | ||||
|         } catch(e) { | ||||
|           return cb(e); | ||||
|         let modsErr; | ||||
|         [modsErr, pacMods, ...modsWarns] = createPacModifiers(pacMods); | ||||
|         if (modsErr) { | ||||
|           return cb(modsErr, null, modsWarns); | ||||
|         } | ||||
|         const oldProxies = getCurrentConfigs().filteredCustomsString || ''; | ||||
|         const newProxies = pacMods.filteredCustomsString || ''; | ||||
|         ifProxiesChanged = oldProxies !== newProxies; | ||||
|         console.log('Proxies changed from:', oldProxies, 'to', newProxies); | ||||
|         kitchenState(modsKey, pacMods); | ||||
|       } | ||||
|       console.log('Keep cooked now...', pacMods); | ||||
|       this._tryNowAsync( | ||||
|         (err, res, ...warns) => { | ||||
|       this.setNowAsync( | ||||
|         (err, res, ...setWarns) => { | ||||
| 
 | ||||
|           const accWarns = modsWarns.concat(setWarns); // Acc = accumulated.
 | ||||
|           console.log('Try now err:', err); | ||||
|           if (err) { | ||||
|             return cb(err, res, ...warns); | ||||
|             return cb(err, res, ...accWarns); | ||||
|           } | ||||
| 
 | ||||
|           const par = pacMods.customProxyArray; | ||||
|           if (!(par && par.length)) { | ||||
|             return cb(null, res, ...warns); | ||||
|           if (!ifProxiesChanged) { | ||||
|             return cb(null, res, ...accWarns); | ||||
|           } | ||||
| 
 | ||||
|           const hosts = par.map( (ps) => ps.split(/\s+/)[1] ); | ||||
|           window.utils.fireRequest('ip-to-host-replace-all', hosts, (err, res, ...moreWarns) => cb( err, res, ...warns.concat(moreWarns) )); | ||||
|           const newHosts = (pacMods.customProxyArray || []).map( (ps) => ps.split(/\s+/)[1] ); | ||||
|           window.utils.fireRequest('ip-to-host-replace-all', newHosts, (err, res, ...moreWarns) => cb( err, res, ...accWarns.concat(moreWarns) )); | ||||
| 
 | ||||
|         } | ||||
|       ); | ||||
|  |  | |||
|  | @ -136,7 +136,7 @@ chrome.runtime.getBackgroundPage( (backgroundPage) => | |||
| 
 | ||||
|       }; | ||||
| 
 | ||||
|       const conduct = (beforeStatus, operation, afterStatus, onSuccess) => { | ||||
|       const conduct = (beforeStatus, operation, afterStatus, onSuccess = () => {}, onError = () => {}) => { | ||||
| 
 | ||||
|         setStatusTo(beforeStatus); | ||||
|         switchInputs('off'); | ||||
|  | @ -150,7 +150,9 @@ chrome.runtime.getBackgroundPage( (backgroundPage) => | |||
|           } | ||||
|           switchInputs('on'); | ||||
|           if (!err) { | ||||
|             onSuccess && onSuccess(res); | ||||
|             onSuccess(res); | ||||
|           } else { | ||||
|             onError(err); | ||||
|           } | ||||
|         }); | ||||
| 
 | ||||
|  | @ -275,9 +277,9 @@ chrome.runtime.getBackgroundPage( (backgroundPage) => | |||
| 
 | ||||
|           }; | ||||
| 
 | ||||
|           const ifProxyLabel = '✔'; | ||||
|           const ifNotProxyLabel = '✘'; | ||||
|           const ifAutoLabel = '🔄'; | ||||
|           const labelIfProxied = '✔'; | ||||
|           const labelIfNotProxied = '✘'; | ||||
|           const labelIfAuto = '🔄'; | ||||
| 
 | ||||
|           const addOption = function addOption(host, yesNoUndefined) { | ||||
| 
 | ||||
|  | @ -287,13 +289,13 @@ chrome.runtime.getBackgroundPage( (backgroundPage) => | |||
|             opt.dataset.host = host; | ||||
|             switch(yesNoUndefined) { | ||||
|               case true: | ||||
|                 opt.label = ifProxyLabel; | ||||
|                 opt.label = labelIfProxied; | ||||
|                 break; | ||||
|               case false: | ||||
|                 opt.label = ifNotProxyLabel; | ||||
|                 opt.label = labelIfNotProxied; | ||||
|                 break; | ||||
|               default: | ||||
|                 opt.label = ifAutoLabel; | ||||
|                 opt.label = labelIfAuto; | ||||
|             } | ||||
|             const editorHost = excEditor.value.trim(); | ||||
|             if (host === editorHost) { | ||||
|  | @ -322,7 +324,7 @@ chrome.runtime.getBackgroundPage( (backgroundPage) => | |||
|           } | ||||
| 
 | ||||
|           const hideOpt = (opt) => opt.value = '\n'; | ||||
|           const unhideOpt = (opt) => opt.value = opt.dataset.host + ' '; | ||||
|           const unhideOptAndAddSpace = (opt) => opt.value = opt.dataset.host + ' '; | ||||
| 
 | ||||
|           const excList = document.getElementById('exc-list'); | ||||
| 
 | ||||
|  | @ -337,7 +339,7 @@ chrome.runtime.getBackgroundPage( (backgroundPage) => | |||
| 
 | ||||
|           }; | ||||
| 
 | ||||
|           const renderExceptions = function renderExceptions(event) { | ||||
|           const renderExceptionsPanelFromExcList = function renderExceptionsPanelFromExcList(event) { | ||||
| 
 | ||||
|             // If triangle button on right of datalist input clicked.
 | ||||
| 
 | ||||
|  | @ -376,9 +378,9 @@ chrome.runtime.getBackgroundPage( (backgroundPage) => | |||
|             excList.childNodes.forEach( | ||||
|               (opt) => { | ||||
| 
 | ||||
|                 unhideOpt(opt); | ||||
|                 unhideOptAndAddSpace(opt); | ||||
| 
 | ||||
|                 if(opt.label === ifAutoLabel) { | ||||
|                 if(opt.label === labelIfAuto) { | ||||
|                   editedOpt = opt; | ||||
|                   return; | ||||
|                 } | ||||
|  | @ -392,11 +394,13 @@ chrome.runtime.getBackgroundPage( (backgroundPage) => | |||
|             thisAuto.checked = true; | ||||
|             excEditor.parentNode.classList.remove(noClass, yesClass); | ||||
| 
 | ||||
|             if (ifTriangleClicked || !originalHost) { | ||||
|             const ifInputEmpty = !originalHost; | ||||
|             if (ifTriangleClicked || ifInputEmpty) { | ||||
|               // Show all opts.
 | ||||
|               if (editedOpt) { | ||||
|                 const ifBackspaced = !originalHost && editedOpt.value.length < 3; | ||||
|                 if (ifBackspaced) { | ||||
|                 // Example of editedOpt.value: 'abcde ' <- Mind the space (see unhideOptAndAddSpace)!
 | ||||
|                 const ifBackspacedOneChar = ifInputEmpty && editedOpt.value.length < 3; | ||||
|                 if (ifBackspacedOneChar) { | ||||
|                   editedOpt.remove(); | ||||
|                 } | ||||
|               } | ||||
|  | @ -404,18 +408,16 @@ chrome.runtime.getBackgroundPage( (backgroundPage) => | |||
|             } | ||||
| 
 | ||||
|             if (editedOpt) { | ||||
|               hideOpt(editedOpt); | ||||
|               const ifEditedOptAlreadyExists = editedOpt.dataset.host === originalHost; | ||||
|               if(ifEditedOptAlreadyExists) { | ||||
|                 hideOpt(editedOpt); | ||||
|                 return true; | ||||
|               } | ||||
|               // Not exact! Update!
 | ||||
|               editedOpt.remove(); | ||||
|             } | ||||
| 
 | ||||
|             if (!exactOpt) { | ||||
|               if(editedOpt) { | ||||
|                 const ifExact = editedOpt.dataset.host === originalHost; | ||||
|                 if(ifExact) { | ||||
|                   return true; | ||||
|                 } | ||||
|                 // Not exact! Update!
 | ||||
|                 editedOpt.remove(); | ||||
|               } | ||||
|               editedOpt = addOption(originalHost, undefined); | ||||
|               if (!ifClick) { | ||||
|                 // New value was typed -- don't show tooltip.
 | ||||
|  | @ -426,7 +428,7 @@ chrome.runtime.getBackgroundPage( (backgroundPage) => | |||
| 
 | ||||
|             // Exact found!
 | ||||
|             hideOpt(exactOpt); | ||||
|             if(exactOpt.label === ifProxyLabel) { | ||||
|             if(exactOpt.label === labelIfProxied) { | ||||
|               thisYes.checked = true; | ||||
|               excEditor.parentNode.classList.add(yesClass); | ||||
|             } else { | ||||
|  | @ -437,7 +439,7 @@ chrome.runtime.getBackgroundPage( (backgroundPage) => | |||
| 
 | ||||
|           }; | ||||
| 
 | ||||
|           excEditor.onclick = excEditor.oninput = renderExceptions; | ||||
|           excEditor.onclick = excEditor.oninput = renderExceptionsPanelFromExcList; | ||||
| 
 | ||||
|           if (currentTab && !currentTab.url.startsWith('chrome')) { | ||||
|             excEditor.value = new URL(currentTab.url).hostname; | ||||
|  | @ -452,7 +454,7 @@ chrome.runtime.getBackgroundPage( (backgroundPage) => | |||
|             for(const host of Object.keys(pacMods.exceptions || {}).sort()) { | ||||
|               addOption(host, pacMods.exceptions[host]); | ||||
|             } | ||||
|             renderExceptions(); // Colorize input.
 | ||||
|             renderExceptionsPanelFromExcList(); // Colorize input.
 | ||||
| 
 | ||||
|           } | ||||
| 
 | ||||
|  | @ -469,24 +471,36 @@ chrome.runtime.getBackgroundPage( (backgroundPage) => | |||
|             const pacMods = pacKitchen.getPacMods(); | ||||
|             pacMods.exceptions = pacMods.exceptions || {}; | ||||
| 
 | ||||
|             let fixUi = () => {}; | ||||
|             let fixOptions; | ||||
|             const curOptOrNull = excList.querySelector(`[data-host="${host}"]`); | ||||
| 
 | ||||
|             if (thisAuto.checked) { | ||||
|               delete pacMods.exceptions[host]; | ||||
|               fixUi = () => excEditor.value = ''; | ||||
|               fixOptions = () => { | ||||
|                 curOptOrNull && curOptOrNull.remove(); | ||||
|               } | ||||
|             } else { | ||||
|               // YES or NO.
 | ||||
|               // YES or NO checked.
 | ||||
|               const ifYesClicked = thisYes.checked; | ||||
|               if (!validateHost(host)) { | ||||
|                 return false; | ||||
|               } | ||||
|               if (thisYes.checked && !pacMods.filteredCustomsString) { | ||||
|               if (ifYesClicked && !pacMods.filteredCustomsString) { | ||||
|                 showErrors( new TypeError( | ||||
|                   'Проксировать СВОИ сайты можно только при наличии СВОИХ прокси (см. «Модификаторы» ).' | ||||
|                 )); | ||||
|                 return false; | ||||
|               } | ||||
|               pacMods.exceptions[host] = thisYes.checked; | ||||
|               fixUi = () => addOption(host, thisYes.checked); | ||||
|               //const ifNew = !(host in pacMods.exceptions);
 | ||||
|               pacMods.exceptions[host] = ifYesClicked; | ||||
|                 // Change label.
 | ||||
|               fixOptions = () => { | ||||
|                 if (curOptOrNull) { | ||||
|                   curOptOrNull.label = ifYesClicked ? labelIfProxied : labelIfNotProxied; | ||||
|                 } else { | ||||
|                   addOption(host, ifYesClicked); | ||||
|                 } | ||||
|               }; | ||||
|             } | ||||
| 
 | ||||
|             conduct( | ||||
|  | @ -495,17 +509,13 @@ chrome.runtime.getBackgroundPage( (backgroundPage) => | |||
|               'Исключения применены. Не забывайте о кэше!', | ||||
|               () => { | ||||
| 
 | ||||
|                 excList.childNodes.forEach( | ||||
|                   (opt) => opt.dataset.host === host && opt.remove() | ||||
|                 ); | ||||
|                 fixUi(); | ||||
|                 fixOptions(); | ||||
|                 // Window may be closed before this line executes.
 | ||||
|                 console.log(excEditor, excEditor.oninput); | ||||
|                 renderExceptions(); | ||||
|                 renderExceptionsPanelFromExcList(); | ||||
| 
 | ||||
|               } | ||||
|             ); | ||||
|             return true; | ||||
|             return false; // Don't check before operation is finished.
 | ||||
| 
 | ||||
|           }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -113,7 +113,7 @@ | |||
|     const promises = types.map( | ||||
|       (type) => new Promise((resolve) => | ||||
|         httpLib.get( | ||||
|           'https://dns.google.com/resolve?type=' + type + '&name=' + host, | ||||
|           `https://dns.google.com/resolve?type=${type}&name=${host}&edns_client_subnet=0.0.0.0/0`, | ||||
|           (err, res) => { | ||||
| 
 | ||||
|             if (res) { | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| 'use strict'; | ||||
| 
 | ||||
| const commonContext = { | ||||
|   version: '0.21', | ||||
|   version: '0.24', | ||||
| }; | ||||
| 
 | ||||
| exports.contexts = {}; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user