Compare commits
18 Commits
v20241005.
...
v20241204.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74e6d0aa47 | ||
|
|
509f516d1d | ||
|
|
4ae3541f20 | ||
|
|
58d793c13c | ||
|
|
340754f759 | ||
|
|
d36a5097f5 | ||
|
|
03998c2db0 | ||
|
|
bc33e69e7d | ||
|
|
fcd1ce19aa | ||
|
|
d923c54720 | ||
|
|
16f2713aa1 | ||
|
|
07a9e9773b | ||
|
|
f827e221e7 | ||
|
|
357bbd09bd | ||
|
|
a283940216 | ||
|
|
4a64f36f5c | ||
|
|
34b4cd9097 | ||
|
|
812b8e7d4c |
16
.github/workflows/auto-generate-pac.yml
vendored
16
.github/workflows/auto-generate-pac.yml
vendored
@@ -4,12 +4,14 @@ on:
|
||||
schedule:
|
||||
- cron: '10 0 * * 4'
|
||||
push:
|
||||
paths-ignore:
|
||||
- 'README.md'
|
||||
- 'LICENSE'
|
||||
- 'gfw.pac'
|
||||
- '.gitignore'
|
||||
- '.github/**'
|
||||
paths:
|
||||
- 'gfw-pac.py'
|
||||
- 'pac-template'
|
||||
- 'local-tlds.txt'
|
||||
- 'direct-domains.txt'
|
||||
- 'proxy-domains.txt'
|
||||
- 'cidrs-cn.txt'
|
||||
- '!gfw.pac'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
@@ -28,7 +30,7 @@ jobs:
|
||||
- name: Commit and push changes
|
||||
run: |
|
||||
last_commit_message=$(git log -1 --pretty=%B)
|
||||
$GITHUB_EVENT_NAME == 'schedule' && commit_message="定期更新数据并生成 gfw.pac" || commit_message="自动生成 gfw.pac: $last_commit_message"
|
||||
commit_message=$([[ "${{ github.event_name }}" == "schedule" ]] && echo "定期更新数据并生成 gfw.pac" || echo "自动生成 gfw.pac: $last_commit_message")
|
||||
git config --local user.email "action@github.com"
|
||||
git config --local user.name "GitHub Action"
|
||||
git add -A
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -43,3 +43,5 @@ $RECYCLE.BIN/
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
test.js
|
||||
1594
cidrs-cn.txt
1594
cidrs-cn.txt
File diff suppressed because it is too large
Load Diff
@@ -69,8 +69,18 @@ douyinstatic.com
|
||||
douyinvod.com
|
||||
supercachenode.com
|
||||
bytedance.com
|
||||
bytedanceapi.com
|
||||
bytescm.com
|
||||
bytecdn.cn
|
||||
byteoc.com
|
||||
bytednsdoc.com
|
||||
bytetcc.com
|
||||
feishu.cn
|
||||
feishucdn.com
|
||||
toutiao.com
|
||||
toutiaoimg.com
|
||||
toutiaostatic.com
|
||||
yhgfb-cn-static.com
|
||||
cmbchina.com
|
||||
mi.com
|
||||
xiaomi.com
|
||||
@@ -83,6 +93,8 @@ dianping.com
|
||||
quark.cn
|
||||
wps.cn
|
||||
wpscdn.cn
|
||||
xiaohongshu.com
|
||||
xhscdn.com
|
||||
push.apple.com
|
||||
setup.icloud.com
|
||||
appldnld.apple.com
|
||||
@@ -118,3 +130,9 @@ ocsp.globalsign.com
|
||||
ocsp2.globalsign.com
|
||||
ocsp.digicert.cn
|
||||
ocsp.dcocsp.cn
|
||||
api.onedrive.com
|
||||
storage.live.com
|
||||
skyapi.live.net
|
||||
roaming.officeapps.live.com
|
||||
blob.core.windows.net
|
||||
default.exp-tas.com
|
||||
@@ -27,16 +27,11 @@ def parse_args():
|
||||
def convert_cidr(cidr):
|
||||
if '/' in cidr:
|
||||
network = ipaddress.ip_network(cidr.strip(), strict=False)
|
||||
network_address = network.network_address
|
||||
prefixlen = network.prefixlen
|
||||
network_address = int(network.network_address) >> (network.max_prefixlen - network.prefixlen)
|
||||
else:
|
||||
network = ipaddress.ip_address(cidr.strip())
|
||||
network_address = network
|
||||
prefixlen = network.max_prefixlen
|
||||
if network.version == 4:
|
||||
return hex(int(network_address))[2:] + '/' + str(prefixlen)
|
||||
else:
|
||||
return network.compressed
|
||||
return hex(int(network_address))[2:]
|
||||
|
||||
def generate_cnip_cidrs():
|
||||
""" 从文件中读取CIDR地址 """
|
||||
|
||||
66
pac-template
66
pac-template
@@ -10,35 +10,45 @@ var localTlds = __LOCAL_TLDS__;
|
||||
|
||||
var cidrs = __CIDRS__;
|
||||
|
||||
var hasOwnProperty = Object.hasOwnProperty;
|
||||
|
||||
function isIpAddress(ip) {
|
||||
return /^\d{1,3}(\.\d{1,3}){3}$/.test(ip) || /^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$/.test(ip);
|
||||
}
|
||||
|
||||
function RadixTree() {
|
||||
this.root = {};
|
||||
this.root = new Map();
|
||||
}
|
||||
|
||||
RadixTree.prototype.insert = function(string) {
|
||||
var node = this.root;
|
||||
for (var i = 0; i < string.length; i++) {
|
||||
var char = string[i];
|
||||
if (!node[char]) {
|
||||
node[char] = {};
|
||||
if (!node.has(char)) {
|
||||
node.set(char, new Map());
|
||||
}
|
||||
node = node[char];
|
||||
node = node.get(char);
|
||||
}
|
||||
};
|
||||
|
||||
RadixTree.prototype.to_list = function() {
|
||||
return this.root;
|
||||
};
|
||||
RadixTree.prototype.search = function(string) {
|
||||
var currentNode = this.root;
|
||||
var isLastNode = false;
|
||||
for (var i=0; i < string.length; i++) {
|
||||
var char = string[i];
|
||||
if (currentNode.has(char)) {
|
||||
currentNode = currentNode.get(char);
|
||||
isLastNode = currentNode.size === 0;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isLastNode;
|
||||
}
|
||||
|
||||
function ipToBinary(ip) {
|
||||
var bin = ''
|
||||
// Check if it's IPv4
|
||||
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(ip)) {
|
||||
return ip.split('.').map(function(num) {
|
||||
bin = ip.split('.').map(function(num) {
|
||||
return ("00000000" + parseInt(num, 10).toString(2)).slice(-8);
|
||||
}).join('');
|
||||
} else if (/^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$/.test(ip)) {
|
||||
@@ -54,25 +64,11 @@ function ipToBinary(ip) {
|
||||
var fullAddress = left.concat(Array(zeroGroups + 1).join('0').split('')).concat(right);
|
||||
|
||||
// Convert each group to binary and pad to 16 bits
|
||||
return fullAddress.map(function(group) {
|
||||
bin = fullAddress.map(function(group) {
|
||||
return ("0000000000000000" + parseInt(group || '0', 16).toString(2)).slice(-16);
|
||||
}).join('');
|
||||
}
|
||||
}
|
||||
|
||||
function searchRadixTree(bits) {
|
||||
var currentNode = radixTree;
|
||||
var isLastNode = false;
|
||||
for (var i=0; i<bits.length; i++) {
|
||||
var char = bits[i];
|
||||
if (currentNode[char]) {
|
||||
currentNode = currentNode[char];
|
||||
isLastNode = Object.keys(currentNode).length === 0;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isLastNode;
|
||||
return bin.replace(/^0+/, '');
|
||||
}
|
||||
|
||||
function isInDirectDomain(host) {
|
||||
@@ -142,7 +138,7 @@ function FindProxyForURL(url, host) {
|
||||
} else if (isPrivateIp(ip)) {
|
||||
debug('域名解析后命中私有 IP 地址', host, ip);
|
||||
return direct;
|
||||
} else if (searchRadixTree(ipToBinary(ip))) {
|
||||
} else if (radixTree.search(ipToBinary(ip))) {
|
||||
debug('匹配到直连IP', host, ip);
|
||||
return direct;
|
||||
}
|
||||
@@ -152,7 +148,7 @@ function FindProxyForURL(url, host) {
|
||||
}
|
||||
|
||||
var allowAlert = true
|
||||
function debug(msg, host, ip) {
|
||||
function debug(msg, host='', ip='') {
|
||||
if (!allowAlert) {
|
||||
return
|
||||
}
|
||||
@@ -166,19 +162,11 @@ function debug(msg, host, ip) {
|
||||
var radixTree = new RadixTree();
|
||||
|
||||
(function () {
|
||||
var startTime = new Date().getMilliseconds();
|
||||
debug('开始生成 Radix Tree', 'PAC文件载入开始', startTime.toString());
|
||||
debug('开始生成 Radix Tree', 'PAC文件载入开始');
|
||||
for (let i=0; i<cidrs.length; i++) {
|
||||
var cidr = cidrs[i];
|
||||
var [ip, prefixLen] = cidr.split('/');
|
||||
if (!cidr.includes(':')) {
|
||||
var ip = ip.match(/.{1,2}/g).map(function(byte) {
|
||||
return parseInt(byte, 16);
|
||||
}).join('.');
|
||||
}
|
||||
var bits = ipToBinary(ip).slice(0, prefixLen);
|
||||
var prefix = cidrs[i];
|
||||
var bits = (parseInt(prefix, 16)).toString(2);
|
||||
radixTree.insert(bits);
|
||||
}
|
||||
radixTree = radixTree.to_list();
|
||||
debug('Radix Tree 已生成', 'PAC文件载入完毕', cidrs.length.toString()+'个CIDR条目');
|
||||
})();
|
||||
@@ -27,3 +27,9 @@ segment.io
|
||||
unpkg.com
|
||||
jsdelivr.com
|
||||
tv.apple.com
|
||||
instagram.com
|
||||
cdninstagram.com
|
||||
reddit.com
|
||||
redd.it
|
||||
whatsapp.com
|
||||
whatsapp.net
|
||||
Reference in New Issue
Block a user