Fix notifications for a naked ip as proxy, fix snail position, amend pac kitchen

This commit is contained in:
Ilya Ig. Petrov 2017-04-01 18:01:42 +00:00
parent 87b78e0896
commit 76cf8fcd35
3 changed files with 51 additions and 26 deletions

View File

@ -35,6 +35,7 @@
},
ifProxyOrDie: {
dflt: true,
ifDfltMods: true,
label: 'проксируй или умри!',
desc: 'Запрещает соединение с сайтами напрямую без прокси в случаях, когда все прокси отказывают. Например, если все ВАШИ прокси вдруг недоступны, то добавленные вручную сайты открываться не будут совсем.',
index: 3,
@ -109,17 +110,23 @@
const createPacModifiers = function createPacModifiers(mods = {}) {
const defaults = getDefaults();
const ifAllDefaults = Object.keys(defaults)
.every(
(dProp) => !(dProp in mods)
|| Boolean(defaults[dProp]) === Boolean(mods[dProp])
);
mods = mods || {}; // null?
const ifNoMods = Object.keys(configs)
.every((dProp) => {
const ifDflt = (
!(dProp in mods) ||
Boolean(configs[dProp].dflt) === Boolean(mods[dProp])
);
const ifMods = configs[dProp].ifDfltMods;
return ifDflt ? !ifMods : ifMods;
});
console.log('Input mods:', mods);
const self = {};
Object.assign(self, defaults, mods);
self.ifNoMods = ifAllDefaults ? true : false;
Object.assign(self, getDefaults(), mods);
self.ifNoMods = ifNoMods;
let customProxyArray = [];
if (self.customProxyStringRaw) {
@ -136,6 +143,7 @@
customProxyArray.push('SOCKS5 localhost:9050', 'SOCKS5 localhost:9150');
}
self.filteredCustomsString = '';
if (customProxyArray.length) {
self.customProxyArray = customProxyArray;
self.filteredCustomsString = customProxyArray.join('; ');
@ -144,7 +152,6 @@
return [new TypeError('Нет ни одного прокси, удовлетворяющего вашим требованиям!')];
}
self.customProxyArray = false;
self.filteredCustomsString = '';
}
self.included = self.excluded = undefined;
@ -210,7 +217,7 @@
const ifExcluded = pacMods.excluded && pacMods.excluded.length;
const ifExceptions = ifIncluded || ifExcluded;
if (ifExceptions) {
if (ifExceptions && pacMods.filteredCustomsString) {
res += `
/* EXCEPTIONS START */
const dotHost = '.' + host;
@ -251,7 +258,7 @@
pacMods.ifUsePacScriptProxies
) {
return res + `
return pacProxyString;`;
return pacProxyString;`;
}
return res + `

View File

@ -474,6 +474,9 @@
});
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;
@ -534,14 +537,12 @@
}
}
antiCensorRu.pushToStorageAsync(() =>
window.apis.pacKitchen.keepCookedNowAsync(() => {
antiCensorRu.pushToStorageAsync(() => {
console.log('Extension updated.');
resolve();
console.log('Extension updated.');
resolve();
})
);
});
});

View File

@ -227,20 +227,38 @@
_addAsync(hostStr, cb = mandatory()) {
getIpsFor(hostStr, (err, ips, ...warns) => {
new Promise((resolveIps, reject) => {
const ipm = _test.ipv4v6(hostStr);
if (ipm.ifMatched) {
return resolveIps([hostStr]);
}
getIpsFor(hostStr, (err, ips, ...warns) => {
console.log('Got IPs + err?:', ips, err);
if (!err) {
resolveIps(ips);
} else {
reject([err, null, ...warns]);
}
});
}).then(
(ips) => {
console.log('Got IPs + err?:', ips, err);
if (!err) {
this._purgeOldIpsForSync(hostStr);
// Object may be shared, string can't.
const hostObj = _getHostObj(hostStr);
for(const ip of ips) {
privates._ipToHostObj[ip] = hostObj;
}
}
return cb(err, null, ...warns);
cb();
});
},
(args) => cb(...args)
);
},
@ -317,15 +335,14 @@
replaceAllAsync(addrArr, cb = mandatory()) {
console.log('Replacing...');
console.log('Replacing...', addrArr);
const [ipSet, hostSet] = _canonize(addrArr);
for( const ip of ipSet ) {
const host = _getHostObj(ip);
privates._ipToHostObj[ip] = host;
}
const hostArr = Array.from(hostSet);
this._replaceAllAsync(hostArr, (allErr, ...args) => {
this._replaceAllAsync([...ipSet, ...hostSet], (allErr, ...args) => {
if (!allErr) {
this.persistData();