增加pac文件可读性;增加调试信息输出;完善自定义域名;
This commit is contained in:
81
pac-template
81
pac-template
@@ -1,8 +1,6 @@
|
||||
var proxy = __PROXY__;
|
||||
|
||||
var direct = 'DIRECT;';
|
||||
|
||||
var cnips = __CN_IPS__;
|
||||
var direct = 'DIRECT';
|
||||
|
||||
var directDomains = __DIRECT_DOMAINS__;
|
||||
|
||||
@@ -10,6 +8,8 @@ var domainsUsingProxy = __DOMAINS__;
|
||||
|
||||
var localTlds = __LOCAL_TLDS__;
|
||||
|
||||
var cnips = __CN_IPS__;
|
||||
|
||||
var hasOwnProperty = Object.hasOwnProperty;
|
||||
|
||||
var ipRegExp = new RegExp(/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/);
|
||||
@@ -74,25 +74,28 @@ function match(ip) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function testDomain(target, domains, cnRootIncluded) {
|
||||
var idxA = target.lastIndexOf('.');
|
||||
var idxB = target.lastIndexOf('.', idxA - 1);
|
||||
var hasOwnProperty = Object.hasOwnProperty;
|
||||
var suffix = cnRootIncluded ? target.substring(idxA + 1) : '';
|
||||
while (true) {
|
||||
if (idxB === -1) {
|
||||
if (hasOwnProperty.call(domains, target)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
suffix = target.substring(idxB + 1);
|
||||
if (hasOwnProperty.call(domains, suffix)) {
|
||||
function isInDirectDomain(host) {
|
||||
if (hasOwnProperty.call(directDomains, host)) {
|
||||
return true;
|
||||
}
|
||||
for (var domain in directDomains) {
|
||||
if (host.endsWith('.' + domain)) {
|
||||
return true;
|
||||
}
|
||||
idxB = target.lastIndexOf('.', idxB - 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isInProxyDomain(host) {
|
||||
if (hasOwnProperty.call(domainsUsingProxy, host)) {
|
||||
return true;
|
||||
}
|
||||
for (var domain in domainsUsingProxy) {
|
||||
if (host.endsWith('.' + domain)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isLocalTestDomain(domain) {
|
||||
@@ -106,31 +109,38 @@ function isLocalTestDomain(domain) {
|
||||
|
||||
/* https://github.com/frenchbread/private-ip */
|
||||
function isPrivateIp(ip) {
|
||||
return /^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(ip) ||
|
||||
/^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(ip) ||
|
||||
/^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(ip) ||
|
||||
/^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(ip) ||
|
||||
/^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(ip) ||
|
||||
/^f[cd][0-9a-f]{2}:/i.test(ip) ||
|
||||
/^fe80:/i.test(ip) ||
|
||||
/^::1$/.test(ip) ||
|
||||
/^::$/.test(ip);
|
||||
return /^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(ip) ||
|
||||
/^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(ip) ||
|
||||
/^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(ip) ||
|
||||
/^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(ip) ||
|
||||
/^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(ip) ||
|
||||
/^f[cd][0-9a-f]{2}:/i.test(ip) ||
|
||||
/^fe80:/i.test(ip) ||
|
||||
/^::1$/.test(ip) ||
|
||||
/^::$/.test(ip);
|
||||
}
|
||||
|
||||
function FindProxyForURL(url, host) {
|
||||
if (isPlainHostName(host)
|
||||
|| isPrivateIp(host)
|
||||
|| isLocalTestDomain(host)
|
||||
|| host === 'localhost') {
|
||||
|| isPrivateIp(host)
|
||||
|| isLocalTestDomain(host)
|
||||
|| host === 'localhost') {
|
||||
alert(`${host} MATCHES LOCAL, USING DIRECT`)
|
||||
return direct;
|
||||
}
|
||||
|
||||
if (shExpMatch(url, "http:*")) {
|
||||
alert(`${host} IS USING HTTP, USING DIRECT`)
|
||||
return direct;
|
||||
}
|
||||
|
||||
if (!ipRegExp.test(host)) {
|
||||
if (testDomain(host, domainsUsingProxy)) {
|
||||
if (isInProxyDomain(host)) {
|
||||
alert(`${host} MATCHES PROXY DOMAIN`)
|
||||
return proxy;
|
||||
}
|
||||
|
||||
if (testDomain(host, directDomains, true)) {
|
||||
if (isInDirectDomain(host)) {
|
||||
alert(`${host} MATCHES DIRECT DOMAIN`)
|
||||
return direct
|
||||
}
|
||||
strIp = dnsResolve(host);
|
||||
@@ -143,10 +153,11 @@ function FindProxyForURL(url, host) {
|
||||
}
|
||||
|
||||
intIp = convertAddress(strIp);
|
||||
|
||||
if (match(intIp)) {
|
||||
alert(`${host} MATCHES CNIP`)
|
||||
return direct;
|
||||
}
|
||||
|
||||
alert(`${host} NO RULES WARE MATCHED, USING PROXY`)
|
||||
return proxy;
|
||||
}
|
||||
Reference in New Issue
Block a user