mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Replace validate:cdn-conf with validate:domainset
This commit is contained in:
parent
12bb3bf83a
commit
f5564613f6
@ -1,8 +1,10 @@
|
|||||||
|
// Surge Domain Set can not include root domain from public suffix list.
|
||||||
|
|
||||||
const tldts = require('tldts');
|
const tldts = require('tldts');
|
||||||
const picocolors = require('picocolors');
|
const picocolors = require('picocolors');
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const listDir = require('@sukka/listdir');
|
||||||
|
|
||||||
const SPECIAL_SUFFIXES = new Set([
|
const SPECIAL_SUFFIXES = new Set([
|
||||||
'linodeobjects.com', // only *.linodeobjects.com are public suffix
|
'linodeobjects.com', // only *.linodeobjects.com are public suffix
|
||||||
@ -10,12 +12,11 @@ const SPECIAL_SUFFIXES = new Set([
|
|||||||
'dweb.link' // only *.dweb.link are public suffix
|
'dweb.link' // only *.dweb.link are public suffix
|
||||||
]);
|
]);
|
||||||
|
|
||||||
(async () => {
|
const validateDomainSet = async (filePath) => {
|
||||||
const domainSetContent = await fs.promises.readFile(
|
const domainSetContent = await fs.promises.readFile(
|
||||||
path.resolve(__dirname, '../List/domainset/cdn.conf'),
|
path.resolve(__dirname, '../List/domainset', filePath),
|
||||||
{ encoding: 'utf-8' }
|
{ encoding: 'utf-8' }
|
||||||
);
|
);
|
||||||
|
|
||||||
const domainSetLines = domainSetContent.split('\n');
|
const domainSetLines = domainSetContent.split('\n');
|
||||||
for (let i = 0, len = domainSetLines.length; i < len; i++) {
|
for (let i = 0, len = domainSetLines.length; i < len; i++) {
|
||||||
const line = domainSetLines[i];
|
const line = domainSetLines[i];
|
||||||
@ -36,16 +37,20 @@ const SPECIAL_SUFFIXES = new Set([
|
|||||||
|| parsed.isIcann
|
|| parsed.isIcann
|
||||||
) && domain === parsed.publicSuffix
|
) && domain === parsed.publicSuffix
|
||||||
) {
|
) {
|
||||||
console.error('Domain', picocolors.yellow(domain), picocolors.red('is in public suffix list!'));
|
console.error(`[${filePath}]`, picocolors.yellow(domain), picocolors.red('is in public suffix list!'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const validateRuleset = async (filePath) => {
|
||||||
const rulesetContent = await fs.promises.readFile(
|
const rulesetContent = await fs.promises.readFile(
|
||||||
path.resolve(__dirname, '../List/non_ip/cdn.conf'),
|
path.resolve(__dirname, '../List/non_ip', filePath),
|
||||||
{ encoding: 'utf-8' }
|
{ encoding: 'utf-8' }
|
||||||
);
|
);
|
||||||
const rulesetLines = rulesetContent.split('\n');
|
const rulesetLines = rulesetContent.split('\n');
|
||||||
|
|
||||||
|
console.log(`[${filePath}]`);
|
||||||
|
|
||||||
for (let i = 0, len = rulesetLines.length; i < len; i++) {
|
for (let i = 0, len = rulesetLines.length; i < len; i++) {
|
||||||
const line = rulesetLines[i];
|
const line = rulesetLines[i];
|
||||||
// starts with #
|
// starts with #
|
||||||
@ -55,16 +60,30 @@ const SPECIAL_SUFFIXES = new Set([
|
|||||||
if (line.trim().length === 0) {
|
if (line.trim().length === 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!line.startsWith('DOMAIN-SUFFIX,')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const domain = line.slice(14);
|
||||||
|
const parsed = tldts.parse(domain, { allowPrivateDomains: true, detectIp: false });
|
||||||
|
|
||||||
if (line.startsWith('DOMAIN-SUFFIX')) {
|
if (domain !== parsed.publicSuffix) {
|
||||||
const domain = line.slice(14);
|
if (!SPECIAL_SUFFIXES.has(domain)) {
|
||||||
const parsed = tldts.parse(domain, { allowPrivateDomains: true, detectIp: false });
|
console.warn(picocolors.yellow(domain), picocolors.green('is not in public suffix list!'));
|
||||||
|
|
||||||
if (domain !== parsed.publicSuffix) {
|
|
||||||
if (!SPECIAL_SUFFIXES.has(domain)) {
|
|
||||||
console.error('Domain', picocolors.yellow(domain), picocolors.green('is not in public suffix list!'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const [domainsetFiles, rulesetFiles] = await Promise.all([
|
||||||
|
listDir(path.resolve(__dirname, '../List/domainset')),
|
||||||
|
listDir(path.resolve(__dirname, '../List/non_ip'))
|
||||||
|
]);
|
||||||
|
await Promise.all(
|
||||||
|
domainsetFiles.map(file => validateDomainSet(file))
|
||||||
|
);
|
||||||
|
// await Promise.all(
|
||||||
|
// rulesetFiles.map(file => validateRuleset(file))
|
||||||
|
// );
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@ -1,10 +1,10 @@
|
|||||||
# > Telegram
|
# > Telegram
|
||||||
DOMAIN-SUFFIX,t.me
|
DOMAIN-SUFFIX,t.me
|
||||||
DOMAIN-SUFFIX,tx.me
|
DOMAIN-SUFFIX,tx.me
|
||||||
DOMAIN-SUFFIX,tdesktop.com
|
DOMAIN-SUFFIX,tdesktop.com
|
||||||
DOMAIN-SUFFIX,telegra.ph
|
DOMAIN-SUFFIX,telegra.ph
|
||||||
DOMAIN-SUFFIX,telegram.me
|
DOMAIN-SUFFIX,telegram.me
|
||||||
DOMAIN-SUFFIX,telegram.org
|
DOMAIN-SUFFIX,telegram.org
|
||||||
DOMAIN-SUFFIX,graph.org
|
DOMAIN-SUFFIX,graph.org
|
||||||
DOMAIN-SUFFIX,legra.ph
|
DOMAIN-SUFFIX,legra.ph
|
||||||
DOMAIN-SUFFIX,telesco.pe
|
DOMAIN-SUFFIX,telesco.pe
|
||||||
|
|||||||
11
package.json
11
package.json
@ -13,7 +13,7 @@
|
|||||||
"build:phishing-domainset": "wireit",
|
"build:phishing-domainset": "wireit",
|
||||||
"build:telegram-cidr": "wireit",
|
"build:telegram-cidr": "wireit",
|
||||||
"build:chn-cidr": "wireit",
|
"build:chn-cidr": "wireit",
|
||||||
"validate:cdn-conf": "wireit"
|
"validate:domainset": "wireit"
|
||||||
},
|
},
|
||||||
"wireit": {
|
"wireit": {
|
||||||
"build:anti-bogus-domain": {
|
"build:anti-bogus-domain": {
|
||||||
@ -50,9 +50,12 @@
|
|||||||
"build:telegram-cidr"
|
"build:telegram-cidr"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"validate:cdn-conf": {
|
"validate:domainset": {
|
||||||
"command": "node ./Build/validate-cdn-conf.js",
|
"command": "node ./Build/validate-domainset.js",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
|
"build:apple-cdn",
|
||||||
|
"build:phishing-domainset",
|
||||||
|
"build:reject-domainset",
|
||||||
"build:cdn-conf"
|
"build:cdn-conf"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -65,7 +68,7 @@
|
|||||||
"build:telegram-cidr",
|
"build:telegram-cidr",
|
||||||
"build:chn-cidr",
|
"build:chn-cidr",
|
||||||
"build:public",
|
"build:public",
|
||||||
"validate:cdn-conf"
|
"validate:domainset"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user