From 8824530281232adb956b8e90664b00bc36e85123 Mon Sep 17 00:00:00 2001 From: zhiyi Date: Sun, 17 Sep 2023 21:36:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0pac=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=8F=AF=E8=AF=BB=E6=80=A7=EF=BC=9B=E5=A2=9E=E5=8A=A0=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E4=BF=A1=E6=81=AF=E8=BE=93=E5=87=BA=EF=BC=9B=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E8=87=AA=E5=AE=9A=E4=B9=89=E5=9F=9F=E5=90=8D=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom-domains.txt | 30 ++++++--- direct-domains.txt | 8 ++- gfw.pac | 165 ++++++++++++++++++++++++++------------------- pac-template | 81 ++++++++++++---------- 4 files changed, 169 insertions(+), 115 deletions(-) diff --git a/custom-domains.txt b/custom-domains.txt index af384ad..8feb35f 100644 --- a/custom-domains.txt +++ b/custom-domains.txt @@ -1,16 +1,28 @@ google.com google.com.hk -ggpht.com googleapis.com -google-analytics.com -googleadservices.com -googlesyndication.com -googleadsserving.cn -wikipedia.org -stackoverflow.com -githubusercontent.com +gstatic.com +googleusercontent.com +youtube.com +googlevideo.com +ytimg.com github.com +github.io +githubusercontent.com +githubassets.com bing.com bing.cn bing.net -live.com \ No newline at end of file +live.com +stackoverflow.com +wikipedia.org +godaddy.com +cloudflare.com +twitter.com +docker.com +facebook.com +facebook.net +fbcdn.net +segment.io +unpkg.com +jsdelivr.com \ No newline at end of file diff --git a/direct-domains.txt b/direct-domains.txt index 7b25842..b955846 100644 --- a/direct-domains.txt +++ b/direct-domains.txt @@ -3,6 +3,10 @@ baidupcs.com baidustatic.com bdimg.com bdstatic.com -gtimg.com +cdnnode.cn qq.com -qstatic.com \ No newline at end of file +gtimg.com +qstatic.com +cdn-go.cn +qpic.cn +qqmail.com \ No newline at end of file diff --git a/gfw.pac b/gfw.pac index 0ba8a97..ac308d9 100644 --- a/gfw.pac +++ b/gfw.pac @@ -1,6 +1,57 @@ -var proxy = "PROXY 127.0.0.1:3128"; +var proxy = "PROXY 10.0.0.1:3128"; -var direct = 'DIRECT;'; +var direct = 'DIRECT'; + +var directDomains = { + "baidu.com": 1, + "baidupcs.com": 1, + "baidustatic.com": 1, + "bdimg.com": 1, + "bdstatic.com": 1, + "cdn-go.cn": 1, + "cdnnode.cn": 1, + "gtimg.com": 1, + "qpic.cn": 1, + "qq.com": 1, + "qqmail.com": 1, + "qstatic.com": 1 +}; + +var domainsUsingProxy = { + "bing.cn": 1, + "bing.com": 1, + "bing.net": 1, + "cloudflare.com": 1, + "docker.com": 1, + "facebook.com": 1, + "facebook.net": 1, + "fbcdn.net": 1, + "github.com": 1, + "github.io": 1, + "githubassets.com": 1, + "githubusercontent.com": 1, + "godaddy.com": 1, + "google.com": 1, + "google.com.hk": 1, + "googleapis.com": 1, + "googleusercontent.com": 1, + "googlevideo.com": 1, + "gstatic.com": 1, + "jsdelivr.com": 1, + "live.com": 1, + "segment.io": 1, + "stackoverflow.com": 1, + "twitter.com": 1, + "unpkg.com": 1, + "wikipedia.org": 1, + "youtube.com": 1, + "ytimg.com": 1 +}; + +var localTlds = { + ".localhost": 1, + ".test": 1 +}; var cnips = [ [ @@ -10760,41 +10811,6 @@ var cnips = [ ] ]; -var directDomains = { - "baidu.com": 1, - "baidupcs.com": 1, - "baidustatic.com": 1, - "bdimg.com": 1, - "bdstatic.com": 1, - "gtimg.com": 1, - "qq.com": 1, - "qstatic.com": 1 -}; - -var domainsUsingProxy = { - "bing.cn": 1, - "bing.com": 1, - "bing.net": 1, - "ggpht.com": 1, - "github.com": 1, - "githubusercontent.com": 1, - "google-analytics.com": 1, - "google.com": 1, - "google.com.hk": 1, - "googleadservices.com": 1, - "googleadsserving.cn": 1, - "googleapis.com": 1, - "googlesyndication.com": 1, - "live.com": 1, - "stackoverflow.com": 1, - "wikipedia.org": 1 -}; - -var localTlds = { - ".localhost": 1, - ".test": 1 -}; - 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])$/); @@ -10859,25 +10875,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) { @@ -10891,31 +10910,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); @@ -10928,10 +10954,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; } \ No newline at end of file diff --git a/pac-template b/pac-template index 0bb337a..f4d99b2 100644 --- a/pac-template +++ b/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; } \ No newline at end of file