Add simple domain validation

This commit is contained in:
SukkaW 2022-04-17 18:21:40 +08:00
parent 18a8eafd04
commit 42302b0310
3 changed files with 7362 additions and 4132 deletions

View File

@ -6,6 +6,7 @@ const { cpus } = require('os');
const threads = Math.max(cpus().length, 12); const threads = Math.max(cpus().length, 12);
const rIPv4 = /((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/; const rIPv4 = /((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/;
const rDomain = /^(((?!\-))(xn\-\-)?[a-z0-9\-_]{0,61}[a-z0-9]{1,1}\.)*(xn\-\-)?([a-z0-9\-]{1,61}|[a-z0-9\-]{1,30})\.[a-z]{2,}$/m
const Piscina = require('piscina'); const Piscina = require('piscina');
@ -59,10 +60,13 @@ async function processHosts(hostsUrl, includeAllSubDomain = false) {
return; return;
} }
const [, ...domains] = line.split(' '); const [, ...domains] = line.split(' ');
if (includeAllSubDomain) { const domain = domains.join(' ').trim();
domainSets.add(`.${domains.join(' ')}`.trim()); if (rDomain.test(domain)) {
} else { if (includeAllSubDomain) {
domainSets.add(domains.join(' ').trim()); domainSets.add(`.${domain}`);
} else {
domainSets.add(domain);
}
} }
}); });
@ -136,7 +140,10 @@ async function processFilterRules(filterRulesUrl) {
|| line.endsWith('^|') || line.endsWith('^|')
) )
) { ) {
whitelistDomainSets.add(`${line.replaceAll('@@||', '').replaceAll('^|', '').replaceAll('^', '')}`.trim()); const domain = `${line.replaceAll('@@||', '').replaceAll('^|', '').replaceAll('^', '')}`.trim();
if (rDomain.test(domain)) {
whitelistDomainSets.add(domain);
}
} else if ( } else if (
line.startsWith('||') line.startsWith('||')
&& ( && (
@ -144,14 +151,20 @@ async function processFilterRules(filterRulesUrl) {
|| line.endsWith('^|') || line.endsWith('^|')
) )
) { ) {
blacklistDomainSets.add(`.${line.replaceAll('||', '').replaceAll('^|', '').replaceAll('^', '')}`.trim()); const domain = `${line.replaceAll('||', '').replaceAll('^|', '').replaceAll('^', '')}`.trim();
if (rDomain.test(domain)) {
blacklistDomainSets.add(`.${domain}`);
}
} else if (line.startsWith('://') } else if (line.startsWith('://')
&& ( && (
line.endsWith('^') line.endsWith('^')
|| line.endsWith('^|') || line.endsWith('^|')
) )
) { ) {
blacklistDomainSets.add(`${line.replaceAll('://', '').replaceAll('^|', '').replaceAll('^', '')}`.trim()); const domain = `${line.replaceAll('://', '').replaceAll('^|', '').replaceAll('^', '')}`.trim();
if (rDomain.test(domain)) {
blacklistDomainSets.add(domain);
}
} }
}); });

File diff suppressed because it is too large Load Diff

View File

@ -350,7 +350,6 @@ xy-log.tagtic.cn
.talkingdata.com .talkingdata.com
.tango-deg.com .tango-deg.com
.tanv.com .tanv.com
.tanx.com
.taplytics.com .taplytics.com
.taptica.com .taptica.com
.testplus.cn .testplus.cn