mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-21 13:50:29 +08:00
Chore: maintainance
This commit is contained in:
parent
6a7f7cc5e8
commit
d354c5e988
@ -2,7 +2,7 @@ import { parseFelixDnsmasqFromResp } from './lib/parse-dnsmasq';
|
|||||||
import { task } from './trace';
|
import { task } from './trace';
|
||||||
import { SHARED_DESCRIPTION } from './constants/description';
|
import { SHARED_DESCRIPTION } from './constants/description';
|
||||||
import { createMemoizedPromise } from './lib/memo-promise';
|
import { createMemoizedPromise } from './lib/memo-promise';
|
||||||
import { DomainsetOutput } from './lib/create-file';
|
import { DomainsetOutput } from './lib/rules/domainset';
|
||||||
import { $$fetch } from './lib/fetch-retry';
|
import { $$fetch } from './lib/fetch-retry';
|
||||||
|
|
||||||
export const getAppleCdnDomainsPromise = createMemoizedPromise(() => $$fetch('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf').then(parseFelixDnsmasqFromResp));
|
export const getAppleCdnDomainsPromise = createMemoizedPromise(() => $$fetch('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf').then(parseFelixDnsmasqFromResp));
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { task } from './trace';
|
|||||||
import { SHARED_DESCRIPTION } from './constants/description';
|
import { SHARED_DESCRIPTION } from './constants/description';
|
||||||
import { appendArrayInPlace } from './lib/append-array-in-place';
|
import { appendArrayInPlace } from './lib/append-array-in-place';
|
||||||
import { SOURCE_DIR } from './constants/dir';
|
import { SOURCE_DIR } from './constants/dir';
|
||||||
import { DomainsetOutput } from './lib/create-file';
|
import { DomainsetOutput } from './lib/rules/domainset';
|
||||||
import { CRASHLYTICS_WHITELIST } from './constants/reject-data-source';
|
import { CRASHLYTICS_WHITELIST } from './constants/reject-data-source';
|
||||||
import { appendSetElementsToArray } from 'foxts/append-set-elements-to-array';
|
import { appendSetElementsToArray } from 'foxts/append-set-elements-to-array';
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { contains as containsCidr, exclude as excludeCidr } from 'fast-cidr-tool
|
|||||||
import { createMemoizedPromise } from './lib/memo-promise';
|
import { createMemoizedPromise } from './lib/memo-promise';
|
||||||
import { CN_CIDR_MISSING_IN_CHNROUTE, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } from './constants/cidr';
|
import { CN_CIDR_MISSING_IN_CHNROUTE, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } from './constants/cidr';
|
||||||
import { appendArrayInPlace } from './lib/append-array-in-place';
|
import { appendArrayInPlace } from './lib/append-array-in-place';
|
||||||
import { IPListOutput } from './lib/create-file';
|
import { IPListOutput } from './lib/rules/ip';
|
||||||
import { cachedOnlyFail } from './lib/fs-memo';
|
import { cachedOnlyFail } from './lib/fs-memo';
|
||||||
import { createFileDescription } from './constants/description';
|
import { createFileDescription } from './constants/description';
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { DOMAINS, PROCESS_NAMES } from '../Source/non_ip/cloudmounter';
|
import { DOMAINS, PROCESS_NAMES } from '../Source/non_ip/cloudmounter';
|
||||||
import { SHARED_DESCRIPTION } from './constants/description';
|
import { SHARED_DESCRIPTION } from './constants/description';
|
||||||
import { task } from './trace';
|
import { task } from './trace';
|
||||||
import { RulesetOutput } from './lib/create-file';
|
import { RulesetOutput } from './lib/rules/ruleset';
|
||||||
|
|
||||||
export const buildCloudMounterRules = task(require.main === module, __filename)(async (span) => {
|
export const buildCloudMounterRules = task(require.main === module, __filename)(async (span) => {
|
||||||
// AND,((SRC-IP,192.168.1.110), (DOMAIN, example.com))
|
// AND,((SRC-IP,192.168.1.110), (DOMAIN, example.com))
|
||||||
|
|||||||
@ -9,7 +9,8 @@ import { SHARED_DESCRIPTION } from './constants/description';
|
|||||||
import { fdir as Fdir } from 'fdir';
|
import { fdir as Fdir } from 'fdir';
|
||||||
import { appendArrayInPlace } from './lib/append-array-in-place';
|
import { appendArrayInPlace } from './lib/append-array-in-place';
|
||||||
import { SOURCE_DIR } from './constants/dir';
|
import { SOURCE_DIR } from './constants/dir';
|
||||||
import { DomainsetOutput, RulesetOutput } from './lib/create-file';
|
import { DomainsetOutput } from './lib/rules/domainset';
|
||||||
|
import { RulesetOutput } from './lib/rules/ruleset';
|
||||||
|
|
||||||
const MAGIC_COMMAND_SKIP = '# $ custom_build_script';
|
const MAGIC_COMMAND_SKIP = '# $ custom_build_script';
|
||||||
const MAGIC_COMMAND_TITLE = '# $ meta_title ';
|
const MAGIC_COMMAND_TITLE = '# $ meta_title ';
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import { createMemoizedPromise } from './lib/memo-promise';
|
|||||||
import * as yaml from 'yaml';
|
import * as yaml from 'yaml';
|
||||||
import { appendArrayInPlace } from './lib/append-array-in-place';
|
import { appendArrayInPlace } from './lib/append-array-in-place';
|
||||||
import { OUTPUT_INTERNAL_DIR, OUTPUT_MODULES_DIR, OUTPUT_MODULES_RULES_DIR, SOURCE_DIR } from './constants/dir';
|
import { OUTPUT_INTERNAL_DIR, OUTPUT_MODULES_DIR, OUTPUT_MODULES_RULES_DIR, SOURCE_DIR } from './constants/dir';
|
||||||
import { RulesetOutput } from './lib/create-file';
|
import { RulesetOutput } from './lib/rules/ruleset';
|
||||||
import { SurgeOnlyRulesetOutput } from './lib/rules/ruleset';
|
import { SurgeOnlyRulesetOutput } from './lib/rules/ruleset';
|
||||||
|
|
||||||
export function createGetDnsMappingRule(allowWildcard: boolean) {
|
export function createGetDnsMappingRule(allowWildcard: boolean) {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { HostnameSmolTrie } from './lib/trie';
|
|||||||
import { SHARED_DESCRIPTION } from './constants/description';
|
import { SHARED_DESCRIPTION } from './constants/description';
|
||||||
import { createMemoizedPromise } from './lib/memo-promise';
|
import { createMemoizedPromise } from './lib/memo-promise';
|
||||||
import { extractDomainsFromFelixDnsmasq } from './lib/parse-dnsmasq';
|
import { extractDomainsFromFelixDnsmasq } from './lib/parse-dnsmasq';
|
||||||
import { RulesetOutput } from './lib/create-file';
|
import { RulesetOutput } from './lib/rules/ruleset';
|
||||||
import { appendArrayInPlace } from './lib/append-array-in-place';
|
import { appendArrayInPlace } from './lib/append-array-in-place';
|
||||||
|
|
||||||
const PROBE_DOMAINS = ['.microsoft.com', '.windows.net', '.windows.com', '.windowsupdate.com', '.windowssearch.com', '.office.net'];
|
const PROBE_DOMAINS = ['.microsoft.com', '.windows.net', '.windows.com', '.windowsupdate.com', '.windowssearch.com', '.office.net'];
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import { getPhishingDomains } from './lib/get-phishing-domains';
|
|||||||
|
|
||||||
import { addArrayElementsToSet } from 'foxts/add-array-elements-to-set';
|
import { addArrayElementsToSet } from 'foxts/add-array-elements-to-set';
|
||||||
import { OUTPUT_INTERNAL_DIR, SOURCE_DIR } from './constants/dir';
|
import { OUTPUT_INTERNAL_DIR, SOURCE_DIR } from './constants/dir';
|
||||||
import { DomainsetOutput } from './lib/create-file';
|
import { DomainsetOutput } from './lib/rules/domainset';
|
||||||
import { foundDebugDomain } from './lib/parse-filter/shared';
|
import { foundDebugDomain } from './lib/parse-filter/shared';
|
||||||
import { AdGuardHomeOutput } from './lib/rules/domainset';
|
import { AdGuardHomeOutput } from './lib/rules/domainset';
|
||||||
|
|
||||||
|
|||||||
@ -3,12 +3,13 @@ import path from 'node:path';
|
|||||||
import { createReadlineInterfaceFromResponse, readFileIntoProcessedArray } from './lib/fetch-text-by-line';
|
import { createReadlineInterfaceFromResponse, readFileIntoProcessedArray } from './lib/fetch-text-by-line';
|
||||||
import { task } from './trace';
|
import { task } from './trace';
|
||||||
import { SHARED_DESCRIPTION } from './constants/description';
|
import { SHARED_DESCRIPTION } from './constants/description';
|
||||||
import { compareAndWriteFile, RulesetOutput } from './lib/create-file';
|
import { compareAndWriteFile } from './lib/create-file';
|
||||||
import { OUTPUT_INTERNAL_DIR, SOURCE_DIR } from './constants/dir';
|
import { OUTPUT_INTERNAL_DIR, SOURCE_DIR } from './constants/dir';
|
||||||
import { $$fetch } from './lib/fetch-retry';
|
import { $$fetch } from './lib/fetch-retry';
|
||||||
import { fetchAssets } from './lib/fetch-assets';
|
import { fetchAssets } from './lib/fetch-assets';
|
||||||
import { fastIpVersion } from './lib/misc';
|
import { fastIpVersion } from './lib/misc';
|
||||||
import { AUGUST_ASN, HUIZE_ASN } from '../Source/ip/badboy_asn';
|
import { AUGUST_ASN, HUIZE_ASN } from '../Source/ip/badboy_asn';
|
||||||
|
import { RulesetOutput } from './lib/rules/ruleset';
|
||||||
|
|
||||||
const BOGUS_NXDOMAIN_URL = 'https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/bogus-nxdomain.china.conf';
|
const BOGUS_NXDOMAIN_URL = 'https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/bogus-nxdomain.china.conf';
|
||||||
const getBogusNxDomainIPsPromise: Promise<[ipv4: string[], ipv6: string[]]> = $$fetch(BOGUS_NXDOMAIN_URL).then(async (resp) => {
|
const getBogusNxDomainIPsPromise: Promise<[ipv4: string[], ipv6: string[]]> = $$fetch(BOGUS_NXDOMAIN_URL).then(async (resp) => {
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { task } from './trace';
|
|||||||
import { SHARED_DESCRIPTION } from './constants/description';
|
import { SHARED_DESCRIPTION } from './constants/description';
|
||||||
import { readFileIntoProcessedArray } from './lib/fetch-text-by-line';
|
import { readFileIntoProcessedArray } from './lib/fetch-text-by-line';
|
||||||
|
|
||||||
import { DomainsetOutput } from './lib/create-file';
|
import { DomainsetOutput } from './lib/rules/domainset';
|
||||||
import { OUTPUT_SURGE_DIR, SOURCE_DIR } from './constants/dir';
|
import { OUTPUT_SURGE_DIR, SOURCE_DIR } from './constants/dir';
|
||||||
import { newQueue } from '@henrygd/queue';
|
import { newQueue } from '@henrygd/queue';
|
||||||
import { $$fetch } from './lib/fetch-retry';
|
import { $$fetch } from './lib/fetch-retry';
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { task } from './trace';
|
|||||||
|
|
||||||
import { ALL, NORTH_AMERICA, EU, HK, TW, JP, KR } from '../Source/stream';
|
import { ALL, NORTH_AMERICA, EU, HK, TW, JP, KR } from '../Source/stream';
|
||||||
import { SHARED_DESCRIPTION } from './constants/description';
|
import { SHARED_DESCRIPTION } from './constants/description';
|
||||||
import { RulesetOutput } from './lib/create-file';
|
import { RulesetOutput } from './lib/rules/ruleset';
|
||||||
|
|
||||||
function createRulesetForStreamService(
|
function createRulesetForStreamService(
|
||||||
span: Span,
|
span: Span,
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { createReadlineInterfaceFromResponse } from './lib/fetch-text-by-line';
|
|||||||
import { task } from './trace';
|
import { task } from './trace';
|
||||||
import { SHARED_DESCRIPTION } from './constants/description';
|
import { SHARED_DESCRIPTION } from './constants/description';
|
||||||
import { createMemoizedPromise } from './lib/memo-promise';
|
import { createMemoizedPromise } from './lib/memo-promise';
|
||||||
import { RulesetOutput } from './lib/create-file';
|
import { RulesetOutput } from './lib/rules/ruleset';
|
||||||
import { $$fetch } from './lib/fetch-retry';
|
import { $$fetch } from './lib/fetch-retry';
|
||||||
import { fastIpVersion } from './lib/misc';
|
import { fastIpVersion } from './lib/misc';
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,109 @@
|
|||||||
export { DomainsetOutput } from './rules/domainset';
|
import { asyncWriteToStream } from 'foxts/async-write-to-stream';
|
||||||
export { IPListOutput } from './rules/ip';
|
import { fastStringArrayJoin } from 'foxts/fast-string-array-join';
|
||||||
export { RulesetOutput } from './rules/ruleset';
|
import fs from 'node:fs';
|
||||||
export { fileEqual, compareAndWriteFile } from './rules/base';
|
import picocolors from 'picocolors';
|
||||||
|
import type { Span } from '../trace';
|
||||||
|
import { readFileByLine } from './fetch-text-by-line';
|
||||||
|
import { writeFile } from './misc';
|
||||||
|
|
||||||
|
export async function fileEqual(linesA: string[], source: AsyncIterable<string> | Iterable<string>): Promise<boolean> {
|
||||||
|
if (linesA.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const linesABound = linesA.length - 1;
|
||||||
|
|
||||||
|
let index = -1;
|
||||||
|
for await (const lineB of source) {
|
||||||
|
index++;
|
||||||
|
|
||||||
|
if (index > linesABound) {
|
||||||
|
return (index === linesA.length && lineB.length === 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const lineA = linesA[index];
|
||||||
|
|
||||||
|
if (lineA.length === 0) {
|
||||||
|
if (lineB.length === 0) {
|
||||||
|
// both lines are empty, check next line
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// lineA is empty but lineB is not
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// now lineA can not be empty
|
||||||
|
if (lineB.length === 0) {
|
||||||
|
// lineB is empty but lineA is not
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// now both lines can not be empty
|
||||||
|
|
||||||
|
const firstCharA = lineA.charCodeAt(0);
|
||||||
|
const firstCharB = lineB.charCodeAt(0);
|
||||||
|
|
||||||
|
if (firstCharA !== firstCharB) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// now firstCharA is equal to firstCharB, we only need to check the first char
|
||||||
|
if (firstCharA === 35 /* # */) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// adguard conf
|
||||||
|
if (firstCharA === 33 /* ! */) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
firstCharA === 47 /* / */
|
||||||
|
&& lineA[1] === '/' && lineB[1] === '/'
|
||||||
|
&& lineA[3] === '#' && lineB[3] === '#'
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lineA !== lineB) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The file becomes larger
|
||||||
|
return !(index < linesABound);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function compareAndWriteFile(span: Span, linesA: string[], filePath: string) {
|
||||||
|
const linesALen = linesA.length;
|
||||||
|
|
||||||
|
const isEqual = await span.traceChildAsync(`compare ${filePath}`, async () => {
|
||||||
|
if (fs.existsSync(filePath)) {
|
||||||
|
return fileEqual(linesA, readFileByLine(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`${filePath} does not exists, writing...`);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isEqual) {
|
||||||
|
console.log(picocolors.gray(picocolors.dim(`same content, bail out writing: ${filePath}`)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await span.traceChildAsync(`writing ${filePath}`, async () => {
|
||||||
|
// The default highwater mark is normally 16384,
|
||||||
|
// So we make sure direct write to file if the content is
|
||||||
|
// most likely less than 500 lines
|
||||||
|
if (linesALen < 500) {
|
||||||
|
return writeFile(filePath, fastStringArrayJoin(linesA, '\n') + '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
const writeStream = fs.createWriteStream(filePath);
|
||||||
|
for (let i = 0; i < linesALen; i++) {
|
||||||
|
const p = asyncWriteToStream(writeStream, linesA[i] + '\n');
|
||||||
|
// eslint-disable-next-line no-await-in-loop -- stream high water mark
|
||||||
|
if (p) await p;
|
||||||
|
}
|
||||||
|
|
||||||
|
writeStream.end();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@ -1,13 +1,7 @@
|
|||||||
import type { Span } from '../../trace';
|
import type { Span } from '../../trace';
|
||||||
import { HostnameSmolTrie } from '../trie';
|
import { HostnameSmolTrie } from '../trie';
|
||||||
import { invariant, not } from 'foxts/guard';
|
import { invariant, not } from 'foxts/guard';
|
||||||
import picocolors from 'picocolors';
|
|
||||||
import fs from 'node:fs';
|
|
||||||
import { writeFile } from '../misc';
|
|
||||||
import type { MaybePromise } from '../misc';
|
import type { MaybePromise } from '../misc';
|
||||||
import { fastStringArrayJoin } from 'foxts/fast-string-array-join';
|
|
||||||
import { readFileByLine } from '../fetch-text-by-line';
|
|
||||||
import { asyncWriteToStream } from 'foxts/async-write-to-stream';
|
|
||||||
import type { BaseWriteStrategy } from '../writing-strategy/base';
|
import type { BaseWriteStrategy } from '../writing-strategy/base';
|
||||||
import { merge as mergeCidr } from 'fast-cidr-tools';
|
import { merge as mergeCidr } from 'fast-cidr-tools';
|
||||||
import { createRetrieKeywordFilter as createKeywordFilter } from 'foxts/retrie';
|
import { createRetrieKeywordFilter as createKeywordFilter } from 'foxts/retrie';
|
||||||
@ -496,105 +490,3 @@ export class FileOutput {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fileEqual(linesA: string[], source: AsyncIterable<string> | Iterable<string>): Promise<boolean> {
|
|
||||||
if (linesA.length === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const linesABound = linesA.length - 1;
|
|
||||||
|
|
||||||
let index = -1;
|
|
||||||
for await (const lineB of source) {
|
|
||||||
index++;
|
|
||||||
|
|
||||||
if (index > linesABound) {
|
|
||||||
return (index === linesA.length && lineB.length === 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const lineA = linesA[index];
|
|
||||||
|
|
||||||
if (lineA.length === 0) {
|
|
||||||
if (lineB.length === 0) {
|
|
||||||
// both lines are empty, check next line
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// lineA is empty but lineB is not
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// now lineA can not be empty
|
|
||||||
if (lineB.length === 0) {
|
|
||||||
// lineB is empty but lineA is not
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// now both lines can not be empty
|
|
||||||
|
|
||||||
const firstCharA = lineA.charCodeAt(0);
|
|
||||||
const firstCharB = lineB.charCodeAt(0);
|
|
||||||
|
|
||||||
if (firstCharA !== firstCharB) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// now firstCharA is equal to firstCharB, we only need to check the first char
|
|
||||||
if (firstCharA === 35 /* # */) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// adguard conf
|
|
||||||
if (firstCharA === 33 /* ! */) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
firstCharA === 47 /* / */
|
|
||||||
&& lineA[1] === '/' && lineB[1] === '/'
|
|
||||||
&& lineA[3] === '#' && lineB[3] === '#'
|
|
||||||
) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lineA !== lineB) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The file becomes larger
|
|
||||||
return !(index < linesABound);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function compareAndWriteFile(span: Span, linesA: string[], filePath: string) {
|
|
||||||
const linesALen = linesA.length;
|
|
||||||
|
|
||||||
const isEqual = await span.traceChildAsync(`compare ${filePath}`, async () => {
|
|
||||||
if (fs.existsSync(filePath)) {
|
|
||||||
return fileEqual(linesA, readFileByLine(filePath));
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`${filePath} does not exists, writing...`);
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isEqual) {
|
|
||||||
console.log(picocolors.gray(picocolors.dim(`same content, bail out writing: ${filePath}`)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await span.traceChildAsync(`writing ${filePath}`, async () => {
|
|
||||||
// The default highwater mark is normally 16384,
|
|
||||||
// So we make sure direct write to file if the content is
|
|
||||||
// most likely less than 500 lines
|
|
||||||
if (linesALen < 500) {
|
|
||||||
return writeFile(filePath, fastStringArrayJoin(linesA, '\n') + '\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
const writeStream = fs.createWriteStream(filePath);
|
|
||||||
for (let i = 0; i < linesALen; i++) {
|
|
||||||
const p = asyncWriteToStream(writeStream, linesA[i] + '\n');
|
|
||||||
// eslint-disable-next-line no-await-in-loop -- stream high water mark
|
|
||||||
if (p) await p;
|
|
||||||
}
|
|
||||||
|
|
||||||
writeStream.end();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
2
Dist/Build/_get-lum-apex-domains.cjs
Normal file
2
Dist/Build/_get-lum-apex-domains.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),_getLumApexDomains$1=require('./_get-lum-apex-domains2.cjs');var _getLumApexDomainsExports = _getLumApexDomains$1.__require();
|
||||||
|
const _getLumApexDomains = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(_getLumApexDomainsExports);module.exports=_getLumApexDomains;
|
||||||
28
Dist/Build/_get-lum-apex-domains2.cjs
Normal file
28
Dist/Build/_get-lum-apex-domains2.cjs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const _getLumApexDomains=require('../_virtual/_get-lum-apex-domains.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),require$$0=require('tldts');var hasRequired_getLumApexDomains;
|
||||||
|
|
||||||
|
function require_getLumApexDomains () {
|
||||||
|
if (hasRequired_getLumApexDomains) return _getLumApexDomains.__exports;
|
||||||
|
hasRequired_getLumApexDomains = 1;
|
||||||
|
Object.defineProperty(_getLumApexDomains.__exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _tldts = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
(async ()=>{
|
||||||
|
const lines = await Array.fromAsync(await (0, _fetchtextbyline.fetchRemoteTextByLine)('https://raw.githubusercontent.com/durablenapkin/block/master/luminati.txt', true));
|
||||||
|
const set = new Set();
|
||||||
|
lines.forEach((line)=>{
|
||||||
|
const apexDomain = _tldts.default.getDomain(line.slice(8));
|
||||||
|
if (apexDomain) {
|
||||||
|
set.add(apexDomain);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log(Array.from(set).map((line)=>'.' + line).join('\n'));
|
||||||
|
})();
|
||||||
|
return _getLumApexDomains.__exports;
|
||||||
|
}exports.__require=require_getLumApexDomains;
|
||||||
2
Dist/Build/build-apple-cdn.cjs
Normal file
2
Dist/Build/build-apple-cdn.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildAppleCdn$1=require('./build-apple-cdn2.cjs');var buildAppleCdnExports = buildAppleCdn$1.__require();
|
||||||
|
const buildAppleCdn = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildAppleCdnExports);module.exports=buildAppleCdn;
|
||||||
44
Dist/Build/build-apple-cdn2.cjs
Normal file
44
Dist/Build/build-apple-cdn2.cjs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildAppleCdn=require('../_virtual/build-apple-cdn.cjs'),parseDnsmasq=require('./lib/parse-dnsmasq.cjs'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),memoPromise=require('./lib/memo-promise.cjs'),domainset=require('./lib/rules/domainset.cjs'),fetchRetry=require('./lib/fetch-retry.cjs');var hasRequiredBuildAppleCdn;
|
||||||
|
|
||||||
|
function requireBuildAppleCdn () {
|
||||||
|
if (hasRequiredBuildAppleCdn) return buildAppleCdn.__module.exports;
|
||||||
|
hasRequiredBuildAppleCdn = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
buildAppleCdn: function() {
|
||||||
|
return buildAppleCdn;
|
||||||
|
},
|
||||||
|
getAppleCdnDomainsPromise: function() {
|
||||||
|
return getAppleCdnDomainsPromise;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _parsednsmasq = /*@__PURE__*/ parseDnsmasq.__require();
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _description = /*@__PURE__*/ description.__require();
|
||||||
|
const _memopromise = /*@__PURE__*/ memoPromise.__require();
|
||||||
|
const _domainset = /*@__PURE__*/ domainset.__require();
|
||||||
|
const _fetchretry = /*@__PURE__*/ fetchRetry.__require();
|
||||||
|
const getAppleCdnDomainsPromise = (0, _memopromise.createMemoizedPromise)(()=>(0, _fetchretry.$$fetch)('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf').then(_parsednsmasq.parseFelixDnsmasqFromResp));
|
||||||
|
const buildAppleCdn = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const res = await span.traceChildPromise('get apple cdn domains', getAppleCdnDomainsPromise());
|
||||||
|
return new _domainset.DomainsetOutput(span, 'apple_cdn').withTitle('Sukka\'s Ruleset - Apple CDN').withDescription([
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
'This file contains Apple\'s domains using their China mainland CDN servers.',
|
||||||
|
'',
|
||||||
|
'Data from:',
|
||||||
|
' - https://github.com/felixonmars/dnsmasq-china-list'
|
||||||
|
]).bulkAddDomainSuffix(res).write();
|
||||||
|
});
|
||||||
|
} (buildAppleCdn.__module, buildAppleCdn.__module.exports));
|
||||||
|
return buildAppleCdn.__module.exports;
|
||||||
|
}exports.__require=requireBuildAppleCdn;
|
||||||
2
Dist/Build/build-cdn-download-conf.cjs
Normal file
2
Dist/Build/build-cdn-download-conf.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildCdnDownloadConf$1=require('./build-cdn-download-conf2.cjs');var buildCdnDownloadConfExports = buildCdnDownloadConf$1.__require();
|
||||||
|
const buildCdnDownloadConf = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildCdnDownloadConfExports);module.exports=buildCdnDownloadConf;
|
||||||
86
Dist/Build/build-cdn-download-conf2.cjs
Normal file
86
Dist/Build/build-cdn-download-conf2.cjs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildCdnDownloadConf=require('../_virtual/build-cdn-download-conf.cjs'),require$$0$1=require('node:path'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),trie=require('./lib/trie.cjs'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),appendArrayInPlace=require('./lib/append-array-in-place.cjs'),dir=require('./constants/dir.cjs'),domainset=require('./lib/rules/domainset.cjs'),rejectDataSource=require('./constants/reject-data-source.cjs'),require$$0=require('foxts/append-set-elements-to-array');var hasRequiredBuildCdnDownloadConf;
|
||||||
|
|
||||||
|
function requireBuildCdnDownloadConf () {
|
||||||
|
if (hasRequiredBuildCdnDownloadConf) return buildCdnDownloadConf.__module.exports;
|
||||||
|
hasRequiredBuildCdnDownloadConf = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "buildCdnDownloadConf", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return buildCdnDownloadConf;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1);
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _trie = /*@__PURE__*/ trie.__require();
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _description = /*@__PURE__*/ description.__require();
|
||||||
|
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _domainset = /*@__PURE__*/ domainset.__require();
|
||||||
|
const _rejectdatasource = /*@__PURE__*/ rejectDataSource.__require();
|
||||||
|
const _appendsetelementstoarray = require$$0;
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const getS3OSSDomainsPromise = (async ()=>{
|
||||||
|
const trie = new _trie.HostnameTrie();
|
||||||
|
for await (const line of (await (0, _fetchtextbyline.fetchRemoteTextByLine)('https://publicsuffix.org/list/public_suffix_list.dat', true))){
|
||||||
|
trie.add(line);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Extract OSS domain from publicsuffix list
|
||||||
|
*/ const S3OSSDomains = new Set();
|
||||||
|
trie.find('.amazonaws.com').forEach((line)=>{
|
||||||
|
if ((line.startsWith('s3-') || line.startsWith('s3.')) && !line.includes('cn-')) {
|
||||||
|
S3OSSDomains.add('.' + line);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
trie.find('.scw.cloud').forEach((line)=>{
|
||||||
|
if ((line.startsWith('s3-') || line.startsWith('s3.')) && !line.includes('cn-')) {
|
||||||
|
S3OSSDomains.add('.' + line);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
trie.find('sakurastorage.jp').forEach((line)=>{
|
||||||
|
if (line.startsWith('s3-') || line.startsWith('s3.')) {
|
||||||
|
S3OSSDomains.add('.' + line);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return S3OSSDomains;
|
||||||
|
})();
|
||||||
|
const cdnDomainsListPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/cdn.conf'));
|
||||||
|
const downloadDomainSetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/download.conf'));
|
||||||
|
const steamDomainSetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/game-download.conf'));
|
||||||
|
const buildCdnDownloadConf = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const [S3OSSDomains, cdnDomainsList, downloadDomainSet, steamDomainSet] = await Promise.all([
|
||||||
|
getS3OSSDomainsPromise,
|
||||||
|
cdnDomainsListPromise,
|
||||||
|
downloadDomainSetPromise,
|
||||||
|
steamDomainSetPromise
|
||||||
|
]);
|
||||||
|
// Move S3 domains to download domain set, since S3 files may be large
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(downloadDomainSet, S3OSSDomains);
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(downloadDomainSet, steamDomainSet);
|
||||||
|
// we have whitelisted the crashlytics domain, and we also want to put it in CDN policy
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(cdnDomainsList, _rejectdatasource.CRASHLYTICS_WHITELIST);
|
||||||
|
return Promise.all([
|
||||||
|
new _domainset.DomainsetOutput(span, 'cdn').withTitle('Sukka\'s Ruleset - CDN Domains').withDescription([
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
'This file contains object storage and static assets CDN domains.'
|
||||||
|
]).addFromDomainset(cdnDomainsList).write(),
|
||||||
|
new _domainset.DomainsetOutput(span, 'download').withTitle('Sukka\'s Ruleset - Large Files Hosting Domains').withDescription([
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
'This file contains domains for software updating & large file hosting.'
|
||||||
|
]).addFromDomainset(downloadDomainSet).write()
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
} (buildCdnDownloadConf.__module, buildCdnDownloadConf.__module.exports));
|
||||||
|
return buildCdnDownloadConf.__module.exports;
|
||||||
|
}exports.__require=requireBuildCdnDownloadConf;
|
||||||
2
Dist/Build/build-chn-cidr.cjs
Normal file
2
Dist/Build/build-chn-cidr.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildChnCidr$1=require('./build-chn-cidr2.cjs');var buildChnCidrExports = buildChnCidr$1.__require();
|
||||||
|
const buildChnCidr = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildChnCidrExports);module.exports=buildChnCidr;
|
||||||
77
Dist/Build/build-chn-cidr2.cjs
Normal file
77
Dist/Build/build-chn-cidr2.cjs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildChnCidr=require('../_virtual/build-chn-cidr.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),index=require('./trace/index.cjs'),require$$2=require('fast-cidr-tools'),memoPromise=require('./lib/memo-promise.cjs'),cidr=require('./constants/cidr.cjs'),appendArrayInPlace=require('./lib/append-array-in-place.cjs'),ip=require('./lib/rules/ip.cjs'),fsMemo=require('./lib/fs-memo.cjs'),description=require('./constants/description.cjs');var hasRequiredBuildChnCidr;
|
||||||
|
|
||||||
|
function requireBuildChnCidr () {
|
||||||
|
if (hasRequiredBuildChnCidr) return buildChnCidr.__module.exports;
|
||||||
|
hasRequiredBuildChnCidr = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
buildChnCidr: function() {
|
||||||
|
return buildChnCidr;
|
||||||
|
},
|
||||||
|
getChnCidrPromise: function() {
|
||||||
|
return getChnCidrPromise;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _fastcidrtools = require$$2;
|
||||||
|
const _memopromise = /*@__PURE__*/ memoPromise.__require();
|
||||||
|
const _cidr = /*@__PURE__*/ cidr.__require();
|
||||||
|
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
|
||||||
|
const _ip = /*@__PURE__*/ ip.__require();
|
||||||
|
const _fsmemo = /*@__PURE__*/ fsMemo.__require();
|
||||||
|
const _description = /*@__PURE__*/ description.__require();
|
||||||
|
const PROBE_CHN_CIDR_V4 = [
|
||||||
|
// NetEase Hangzhou
|
||||||
|
'223.252.196.38',
|
||||||
|
// Aliyun ShenZhen
|
||||||
|
'120.78.92.171'
|
||||||
|
];
|
||||||
|
const getChnCidrPromise = (0, _memopromise.createMemoizedPromise)((0, _fsmemo.cachedOnlyFail)(async function getChnCidr() {
|
||||||
|
const [_cidr4, cidr6] = await Promise.all([
|
||||||
|
(0, _fetchtextbyline.fetchRemoteTextByLine)('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt', true).then(Array.fromAsync),
|
||||||
|
(0, _fetchtextbyline.fetchRemoteTextByLine)('https://gaoyifan.github.io/china-operator-ip/china6.txt', true).then(Array.fromAsync)
|
||||||
|
]);
|
||||||
|
const cidr4 = (0, _fastcidrtools.exclude)((0, _appendarrayinplace.appendArrayInPlace)(_cidr4, _cidr.CN_CIDR_MISSING_IN_CHNROUTE), _cidr.NON_CN_CIDR_INCLUDED_IN_CHNROUTE, true);
|
||||||
|
for (const probeIp of PROBE_CHN_CIDR_V4){
|
||||||
|
if (!(0, _fastcidrtools.contains)(cidr4, PROBE_CHN_CIDR_V4)) {
|
||||||
|
const err = new TypeError('chnroutes missing probe IP');
|
||||||
|
err.cause = probeIp;
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
cidr4,
|
||||||
|
cidr6
|
||||||
|
];
|
||||||
|
}, {
|
||||||
|
serializer: JSON.stringify,
|
||||||
|
deserializer: JSON.parse
|
||||||
|
}));
|
||||||
|
const buildChnCidr = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const [filteredCidr4, cidr6] = await span.traceChildAsync('download chnroutes2', getChnCidrPromise);
|
||||||
|
// Can not use SHARED_DESCRIPTION here as different license
|
||||||
|
const description = (0, _description.createFileDescription)('CC BY-SA 2.0');
|
||||||
|
return Promise.all([
|
||||||
|
new _ip.IPListOutput(span, 'china_ip', false).withTitle('Sukka\'s Ruleset - Mainland China IPv4 CIDR').withDescription([
|
||||||
|
...description,
|
||||||
|
'Data from https://misaka.io (misakaio @ GitHub)'
|
||||||
|
]).bulkAddCIDR4(filteredCidr4).write(),
|
||||||
|
new _ip.IPListOutput(span, 'china_ip_ipv6', false).withTitle('Sukka\'s Ruleset - Mainland China IPv6 CIDR').withDescription([
|
||||||
|
...description,
|
||||||
|
'Data from https://github.com/gaoyifan/china-operator-ip'
|
||||||
|
]).bulkAddCIDR6(cidr6).write()
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
} (buildChnCidr.__module, buildChnCidr.__module.exports));
|
||||||
|
return buildChnCidr.__module.exports;
|
||||||
|
}exports.__require=requireBuildChnCidr;
|
||||||
2
Dist/Build/build-cloudmounter-rules.cjs
Normal file
2
Dist/Build/build-cloudmounter-rules.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildCloudmounterRules$1=require('./build-cloudmounter-rules2.cjs');var buildCloudmounterRulesExports = buildCloudmounterRules$1.__require();
|
||||||
|
const buildCloudmounterRules = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildCloudmounterRulesExports);module.exports=buildCloudmounterRules;
|
||||||
36
Dist/Build/build-cloudmounter-rules2.cjs
Normal file
36
Dist/Build/build-cloudmounter-rules2.cjs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildCloudmounterRules=require('../_virtual/build-cloudmounter-rules.cjs'),cloudmounter=require('../Source/non_ip/cloudmounter.cjs'),description=require('./constants/description.cjs'),index=require('./trace/index.cjs'),ruleset=require('./lib/rules/ruleset.cjs');var hasRequiredBuildCloudmounterRules;
|
||||||
|
|
||||||
|
function requireBuildCloudmounterRules () {
|
||||||
|
if (hasRequiredBuildCloudmounterRules) return buildCloudmounterRules.__module.exports;
|
||||||
|
hasRequiredBuildCloudmounterRules = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "buildCloudMounterRules", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return buildCloudMounterRules;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _cloudmounter = /*@__PURE__*/ cloudmounter.__require();
|
||||||
|
const _description = /*@__PURE__*/ description.__require();
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _ruleset = /*@__PURE__*/ ruleset.__require();
|
||||||
|
const buildCloudMounterRules = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
// AND,((SRC-IP,192.168.1.110), (DOMAIN, example.com))
|
||||||
|
const results = _cloudmounter.DOMAINS.flatMap((domain)=>_cloudmounter.PROCESS_NAMES.flatMap((process)=>[
|
||||||
|
`AND,((${domain}),(PROCESS-NAME,${process}))`,
|
||||||
|
...[
|
||||||
|
'10.0.0.0/8',
|
||||||
|
// '127.0.0.0/8',
|
||||||
|
'172.16.0.0/12',
|
||||||
|
'192.168.0.0/16'
|
||||||
|
].map((cidr)=>`AND,((${domain}),(SRC-IP,${cidr}))`)
|
||||||
|
]));
|
||||||
|
const description = _description.SHARED_DESCRIPTION;
|
||||||
|
return new _ruleset.RulesetOutput(span, 'cloudmounter', 'non_ip').withTitle('Sukka\'s Ruleset - CloudMounter / RaiDrive').withDescription(description).addFromRuleset(results).write();
|
||||||
|
});
|
||||||
|
} (buildCloudmounterRules.__module, buildCloudmounterRules.__module.exports));
|
||||||
|
return buildCloudmounterRules.__module.exports;
|
||||||
|
}exports.__require=requireBuildCloudmounterRules;
|
||||||
2
Dist/Build/build-common.cjs
Normal file
2
Dist/Build/build-common.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildCommon$1=require('./build-common2.cjs');var buildCommonExports = buildCommon$1.__require();
|
||||||
|
const buildCommon = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildCommonExports);module.exports=buildCommon;
|
||||||
161
Dist/Build/build-common2.cjs
Normal file
161
Dist/Build/build-common2.cjs
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildCommon=require('../_virtual/build-common.cjs'),require$$0=require('node:path'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),processLine=require('./lib/process-line.cjs'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),require$$5=require('fdir'),appendArrayInPlace=require('./lib/append-array-in-place.cjs'),dir=require('./constants/dir.cjs'),domainset=require('./lib/rules/domainset.cjs'),ruleset=require('./lib/rules/ruleset.cjs');var hasRequiredBuildCommon;
|
||||||
|
|
||||||
|
function requireBuildCommon () {
|
||||||
|
if (hasRequiredBuildCommon) return buildCommon.__module.exports;
|
||||||
|
hasRequiredBuildCommon = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "buildCommon", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return buildCommon;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_wildcard(require$$0);
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _processline = /*@__PURE__*/ processLine.__require();
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _description = /*@__PURE__*/ description.__require();
|
||||||
|
const _fdir = require$$5;
|
||||||
|
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _domainset = /*@__PURE__*/ domainset.__require();
|
||||||
|
const _ruleset = /*@__PURE__*/ ruleset.__require();
|
||||||
|
function _getRequireWildcardCache(nodeInterop) {
|
||||||
|
if (typeof WeakMap !== "function") return null;
|
||||||
|
var cacheBabelInterop = new WeakMap();
|
||||||
|
var cacheNodeInterop = new WeakMap();
|
||||||
|
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||||
|
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||||
|
})(nodeInterop);
|
||||||
|
}
|
||||||
|
function _interop_require_wildcard(obj, nodeInterop) {
|
||||||
|
if (obj && obj.__esModule) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||||
|
return {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var cache = _getRequireWildcardCache(nodeInterop);
|
||||||
|
if (cache && cache.has(obj)) {
|
||||||
|
return cache.get(obj);
|
||||||
|
}
|
||||||
|
var newObj = {
|
||||||
|
__proto__: null
|
||||||
|
};
|
||||||
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||||
|
for(var key in obj){
|
||||||
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||||
|
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||||
|
if (desc && (desc.get || desc.set)) {
|
||||||
|
Object.defineProperty(newObj, key, desc);
|
||||||
|
} else {
|
||||||
|
newObj[key] = obj[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newObj.default = obj;
|
||||||
|
if (cache) {
|
||||||
|
cache.set(obj, newObj);
|
||||||
|
}
|
||||||
|
return newObj;
|
||||||
|
}
|
||||||
|
const MAGIC_COMMAND_SKIP = '# $ custom_build_script';
|
||||||
|
const MAGIC_COMMAND_TITLE = '# $ meta_title ';
|
||||||
|
const MAGIC_COMMAND_DESCRIPTION = '# $ meta_description ';
|
||||||
|
const MAGIC_COMMAND_SGMODULE_MITM_HOSTNAMES = '# $ sgmodule_mitm_hostnames ';
|
||||||
|
const clawSourceDirPromise = new _fdir.fdir().withRelativePaths().filter((filepath, isDirectory)=>{
|
||||||
|
if (isDirectory) return true;
|
||||||
|
const extname = _nodepath.extname(filepath);
|
||||||
|
return !(extname === '.js' || extname === '.ts');
|
||||||
|
}).crawl(_dir.SOURCE_DIR).withPromise();
|
||||||
|
const buildCommon = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const promises = [];
|
||||||
|
const paths = await clawSourceDirPromise;
|
||||||
|
for(let i = 0, len = paths.length; i < len; i++){
|
||||||
|
const relativePath = paths[i];
|
||||||
|
const fullPath = _dir.SOURCE_DIR + _nodepath.sep + relativePath;
|
||||||
|
// if (
|
||||||
|
// relativePath.startsWith('ip/')
|
||||||
|
// || relativePath.startsWith('non_ip/')
|
||||||
|
// ) {
|
||||||
|
promises.push(transform(span, fullPath, relativePath));
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// console.error(picocolors.red(`[build-comman] Unknown file: ${relativePath}`));
|
||||||
|
}
|
||||||
|
return Promise.all(promises);
|
||||||
|
});
|
||||||
|
const $skip = Symbol('skip');
|
||||||
|
function processFile(span, sourcePath) {
|
||||||
|
return span.traceChildAsync(`process file: ${sourcePath}`, async ()=>{
|
||||||
|
const lines = [];
|
||||||
|
let title = '';
|
||||||
|
const descriptions = [];
|
||||||
|
let sgmodulePathname = null;
|
||||||
|
try {
|
||||||
|
for await (const line of (0, _fetchtextbyline.readFileByLine)(sourcePath)){
|
||||||
|
if (line.startsWith(MAGIC_COMMAND_SKIP)) {
|
||||||
|
return $skip;
|
||||||
|
}
|
||||||
|
if (line.startsWith(MAGIC_COMMAND_TITLE)) {
|
||||||
|
title = line.slice(MAGIC_COMMAND_TITLE.length).trim();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.startsWith(MAGIC_COMMAND_DESCRIPTION)) {
|
||||||
|
descriptions.push(line.slice(MAGIC_COMMAND_DESCRIPTION.length).trim());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.startsWith(MAGIC_COMMAND_SGMODULE_MITM_HOSTNAMES)) {
|
||||||
|
sgmodulePathname = line.slice(MAGIC_COMMAND_SGMODULE_MITM_HOSTNAMES.length).trim();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const l = (0, _processline.processLine)(line);
|
||||||
|
if (l) {
|
||||||
|
lines.push(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error processing', sourcePath);
|
||||||
|
console.trace(e);
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
title,
|
||||||
|
descriptions,
|
||||||
|
lines,
|
||||||
|
sgmodulePathname
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function transform(parentSpan, sourcePath, relativePath) {
|
||||||
|
const extname = _nodepath.extname(sourcePath);
|
||||||
|
const id = _nodepath.basename(sourcePath, extname);
|
||||||
|
return parentSpan.traceChild(`transform ruleset: ${id}`).traceAsyncFn(async (span)=>{
|
||||||
|
const type = relativePath.split(_nodepath.sep)[0];
|
||||||
|
if (type !== 'ip' && type !== 'non_ip' && type !== 'domainset') {
|
||||||
|
throw new TypeError(`Invalid type: ${type}`);
|
||||||
|
}
|
||||||
|
const res = await processFile(span, sourcePath);
|
||||||
|
if (res === $skip) return;
|
||||||
|
const [title, descriptions, lines, sgmoduleName] = res;
|
||||||
|
let finalDescriptions;
|
||||||
|
if (descriptions.length) {
|
||||||
|
finalDescriptions = _description.SHARED_DESCRIPTION.slice();
|
||||||
|
finalDescriptions.push('');
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(finalDescriptions, descriptions);
|
||||||
|
} else {
|
||||||
|
finalDescriptions = _description.SHARED_DESCRIPTION;
|
||||||
|
}
|
||||||
|
if (type === 'domainset') {
|
||||||
|
return new _domainset.DomainsetOutput(span, id).withTitle(title).withDescription(finalDescriptions).addFromDomainset(lines).write();
|
||||||
|
}
|
||||||
|
return new _ruleset.RulesetOutput(span, id, type).withTitle(title).withDescription(finalDescriptions).withMitmSgmodulePath(sgmoduleName).addFromRuleset(lines).write();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} (buildCommon.__module, buildCommon.__module.exports));
|
||||||
|
return buildCommon.__module.exports;
|
||||||
|
}exports.__require=requireBuildCommon;
|
||||||
2
Dist/Build/build-deprecate-files.cjs
Normal file
2
Dist/Build/build-deprecate-files.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildDeprecateFiles$1=require('./build-deprecate-files2.cjs');var buildDeprecateFilesExports = buildDeprecateFiles$1.__require();
|
||||||
|
const buildDeprecateFiles = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildDeprecateFilesExports);module.exports=buildDeprecateFiles;
|
||||||
67
Dist/Build/build-deprecate-files2.cjs
Normal file
67
Dist/Build/build-deprecate-files2.cjs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildDeprecateFiles=require('../_virtual/build-deprecate-files.cjs'),dir=require('./constants/dir.cjs'),createFile=require('./lib/create-file.cjs'),index=require('./trace/index.cjs'),require$$0=require('node:path'),require$$2=require('node:fs/promises');var hasRequiredBuildDeprecateFiles;
|
||||||
|
|
||||||
|
function requireBuildDeprecateFiles () {
|
||||||
|
if (hasRequiredBuildDeprecateFiles) return buildDeprecateFiles.__module.exports;
|
||||||
|
hasRequiredBuildDeprecateFiles = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "buildDeprecateFiles", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return buildDeprecateFiles;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _createfile = /*@__PURE__*/ createFile.__require();
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _promises = /*#__PURE__*/ _interop_require_default(require$$2);
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const DEPRECATED_FILES = [
|
||||||
|
[
|
||||||
|
'non_ip/global_plus',
|
||||||
|
'This file has been merged with non_ip/global'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'domainset/reject_sukka',
|
||||||
|
'This file has been merged with domainset/reject'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'domainset/reject_phishing',
|
||||||
|
'This file has been merged with domainset/reject'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
const REMOVED_FILES = [
|
||||||
|
'Internal/cdn.txt',
|
||||||
|
'List/internal/appprofile.php',
|
||||||
|
'Clash/domainset/steam.txt',
|
||||||
|
'Clash/non_ip/clash_fake_ip_filter.txt',
|
||||||
|
'sing-box/domainset/steam.json',
|
||||||
|
'Modules/sukka_unlock_abema.sgmodule',
|
||||||
|
'Modules/sukka_exclude_reservered_ip.sgmodule'
|
||||||
|
];
|
||||||
|
const buildDeprecateFiles = (0, _trace.task)(require.main === module, __filename)((span)=>span.traceChildAsync('create deprecated files', async (childSpan)=>{
|
||||||
|
const promises = REMOVED_FILES.map((f)=>_promises.default.rm(_nodepath.default.join(_dir.PUBLIC_DIR, f), {
|
||||||
|
force: true,
|
||||||
|
recursive: true
|
||||||
|
}));
|
||||||
|
for (const [filePath, description] of DEPRECATED_FILES){
|
||||||
|
const content = [
|
||||||
|
'#########################################',
|
||||||
|
'# Sukka\'s Ruleset - Deprecated',
|
||||||
|
`# ${description}`,
|
||||||
|
'################## EOF ##################'
|
||||||
|
];
|
||||||
|
promises.push((0, _createfile.compareAndWriteFile)(childSpan, content, _nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, `${filePath}.conf`)), (0, _createfile.compareAndWriteFile)(childSpan, content, _nodepath.default.resolve(_dir.OUTPUT_CLASH_DIR, `${filePath}.txt`)));
|
||||||
|
}
|
||||||
|
return Promise.all(promises);
|
||||||
|
}));
|
||||||
|
} (buildDeprecateFiles.__module, buildDeprecateFiles.__module.exports));
|
||||||
|
return buildDeprecateFiles.__module.exports;
|
||||||
|
}exports.__require=requireBuildDeprecateFiles;
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildDomesticDirectLanRulesetDnsMappingModule$1=require('./build-domestic-direct-lan-ruleset-dns-mapping-module2.cjs');var buildDomesticDirectLanRulesetDnsMappingModuleExports = buildDomesticDirectLanRulesetDnsMappingModule$1.__require();
|
||||||
|
const buildDomesticDirectLanRulesetDnsMappingModule = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildDomesticDirectLanRulesetDnsMappingModuleExports);module.exports=buildDomesticDirectLanRulesetDnsMappingModule;
|
||||||
@ -0,0 +1,305 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildDomesticDirectLanRulesetDnsMappingModule=require('../_virtual/build-domestic-direct-lan-ruleset-dns-mapping-module.cjs'),require$$0=require('node:path'),domestic=require('../Source/non_ip/domestic.cjs'),direct=require('../Source/non_ip/direct.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),createFile=require('./lib/create-file.cjs'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),memoPromise=require('./lib/memo-promise.cjs'),require$$8=require('yaml'),appendArrayInPlace=require('./lib/append-array-in-place.cjs'),dir=require('./constants/dir.cjs'),ruleset=require('./lib/rules/ruleset.cjs');var hasRequiredBuildDomesticDirectLanRulesetDnsMappingModule;
|
||||||
|
|
||||||
|
function requireBuildDomesticDirectLanRulesetDnsMappingModule () {
|
||||||
|
if (hasRequiredBuildDomesticDirectLanRulesetDnsMappingModule) return buildDomesticDirectLanRulesetDnsMappingModule.__module.exports;
|
||||||
|
hasRequiredBuildDomesticDirectLanRulesetDnsMappingModule = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
buildDomesticRuleset: function() {
|
||||||
|
return buildDomesticRuleset;
|
||||||
|
},
|
||||||
|
createGetDnsMappingRule: function() {
|
||||||
|
return createGetDnsMappingRule;
|
||||||
|
},
|
||||||
|
getDomesticAndDirectDomainsRulesetPromise: function() {
|
||||||
|
return getDomesticAndDirectDomainsRulesetPromise;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _domestic = /*@__PURE__*/ domestic.__require();
|
||||||
|
const _direct = /*@__PURE__*/ direct.__require();
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _createfile = /*@__PURE__*/ createFile.__require();
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _description = /*@__PURE__*/ description.__require();
|
||||||
|
const _memopromise = /*@__PURE__*/ memoPromise.__require();
|
||||||
|
const _yaml = /*#__PURE__*/ _interop_require_wildcard(require$$8);
|
||||||
|
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _ruleset = /*@__PURE__*/ ruleset.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function _getRequireWildcardCache(nodeInterop) {
|
||||||
|
if (typeof WeakMap !== "function") return null;
|
||||||
|
var cacheBabelInterop = new WeakMap();
|
||||||
|
var cacheNodeInterop = new WeakMap();
|
||||||
|
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||||
|
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||||
|
})(nodeInterop);
|
||||||
|
}
|
||||||
|
function _interop_require_wildcard(obj, nodeInterop) {
|
||||||
|
if (obj && obj.__esModule) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||||
|
return {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var cache = _getRequireWildcardCache(nodeInterop);
|
||||||
|
if (cache && cache.has(obj)) {
|
||||||
|
return cache.get(obj);
|
||||||
|
}
|
||||||
|
var newObj = {
|
||||||
|
__proto__: null
|
||||||
|
};
|
||||||
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||||
|
for(var key in obj){
|
||||||
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||||
|
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||||
|
if (desc && (desc.get || desc.set)) {
|
||||||
|
Object.defineProperty(newObj, key, desc);
|
||||||
|
} else {
|
||||||
|
newObj[key] = obj[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newObj.default = obj;
|
||||||
|
if (cache) {
|
||||||
|
cache.set(obj, newObj);
|
||||||
|
}
|
||||||
|
return newObj;
|
||||||
|
}
|
||||||
|
function createGetDnsMappingRule(allowWildcard) {
|
||||||
|
const hasWildcard = (domain)=>{
|
||||||
|
if (domain.includes('*') || domain.includes('?')) {
|
||||||
|
if (!allowWildcard) {
|
||||||
|
throw new TypeError(`Wildcard domain is not supported: ${domain}`);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
return (domain)=>{
|
||||||
|
const results = [];
|
||||||
|
if (domain[0] === '$') {
|
||||||
|
const d = domain.slice(1);
|
||||||
|
if (hasWildcard(domain)) {
|
||||||
|
results.push(`DOMAIN-WILDCARD,${d}`);
|
||||||
|
} else {
|
||||||
|
results.push(`DOMAIN,${d}`);
|
||||||
|
}
|
||||||
|
} else if (domain[0] === '+') {
|
||||||
|
const d = domain.slice(1);
|
||||||
|
if (hasWildcard(domain)) {
|
||||||
|
results.push(`DOMAIN-WILDCARD,*.${d}`);
|
||||||
|
} else {
|
||||||
|
results.push(`DOMAIN-SUFFIX,${d}`);
|
||||||
|
}
|
||||||
|
} else if (hasWildcard(domain)) {
|
||||||
|
results.push(`DOMAIN-WILDCARD,${domain}`, `DOMAIN-WILDCARD,*.${domain}`);
|
||||||
|
} else {
|
||||||
|
results.push(`DOMAIN-SUFFIX,${domain}`);
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const getDomesticAndDirectDomainsRulesetPromise = (0, _memopromise.createMemoizedPromise)(async ()=>{
|
||||||
|
const domestics = await (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/domestic.conf'));
|
||||||
|
const directs = await (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.resolve(_dir.SOURCE_DIR, 'non_ip/direct.conf'));
|
||||||
|
const lans = [];
|
||||||
|
const getDnsMappingRuleWithWildcard = createGetDnsMappingRule(true);
|
||||||
|
[
|
||||||
|
_domestic.DOH_BOOTSTRAP,
|
||||||
|
_domestic.DOMESTICS
|
||||||
|
].forEach((item)=>{
|
||||||
|
Object.values(item).forEach(({ domains })=>{
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(domestics, domains.flatMap(getDnsMappingRuleWithWildcard));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Object.values(_direct.DIRECTS).forEach(({ domains })=>{
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(directs, domains.flatMap(getDnsMappingRuleWithWildcard));
|
||||||
|
});
|
||||||
|
Object.values(_direct.LAN).forEach(({ domains })=>{
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(directs, domains.flatMap(getDnsMappingRuleWithWildcard));
|
||||||
|
});
|
||||||
|
return [
|
||||||
|
domestics,
|
||||||
|
directs,
|
||||||
|
lans
|
||||||
|
];
|
||||||
|
});
|
||||||
|
const buildDomesticRuleset = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const [domestics, directs, lans] = await getDomesticAndDirectDomainsRulesetPromise();
|
||||||
|
const dataset = [
|
||||||
|
_domestic.DOH_BOOTSTRAP,
|
||||||
|
_domestic.DOMESTICS,
|
||||||
|
_direct.DIRECTS,
|
||||||
|
_direct.LAN
|
||||||
|
].flatMap(Object.entries);
|
||||||
|
return Promise.all([
|
||||||
|
new _ruleset.RulesetOutput(span, 'domestic', 'non_ip').withTitle('Sukka\'s Ruleset - Domestic Domains').withDescription([
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
'This file contains known addresses that are avaliable in the Mainland China.'
|
||||||
|
]).addFromRuleset(domestics).write(),
|
||||||
|
new _ruleset.RulesetOutput(span, 'direct', 'non_ip').withTitle('Sukka\'s Ruleset - Direct Rules').withDescription([
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
'This file contains domains and process that should not be proxied.'
|
||||||
|
]).addFromRuleset(directs).write(),
|
||||||
|
new _ruleset.RulesetOutput(span, 'lan', 'non_ip').withTitle('Sukka\'s Ruleset - LAN').withDescription([
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
'This file includes rules for LAN DOMAIN and reserved TLDs.'
|
||||||
|
]).addFromRuleset(lans).write(),
|
||||||
|
...dataset.map(([name, { ruleset, domains }])=>{
|
||||||
|
if (!ruleset) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const output = new _ruleset.SurgeOnlyRulesetOutput(span, name.toLowerCase(), 'sukka_local_dns_mapping', _dir.OUTPUT_MODULES_RULES_DIR).withTitle(`Sukka's Ruleset - Local DNS Mapping (${name})`).withDescription([
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
'This is an internal rule that is only referenced by sukka_local_dns_mapping.sgmodule',
|
||||||
|
'Do not use this file in your Rule section, all rules are included in non_ip/domestic.conf already.'
|
||||||
|
]);
|
||||||
|
domains.forEach((domain)=>{
|
||||||
|
switch(domain[0]){
|
||||||
|
case '$':
|
||||||
|
output.addDomain(domain.slice(1));
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
output.addDomainSuffix(domain.slice(1));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
output.addDomainSuffix(domain);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return output.write();
|
||||||
|
}),
|
||||||
|
(0, _createfile.compareAndWriteFile)(span, [
|
||||||
|
'#!name=[Sukka] Local DNS Mapping',
|
||||||
|
`#!desc=Last Updated: ${new Date().toISOString()}`,
|
||||||
|
'',
|
||||||
|
'[Host]',
|
||||||
|
...Object.entries(// I use an object to deduplicate the domains
|
||||||
|
// Otherwise I could just construct an array directly
|
||||||
|
dataset.reduce((acc, cur)=>{
|
||||||
|
const ruleset_name = cur[0].toLowerCase();
|
||||||
|
const { domains, dns, hosts, ruleset } = cur[1];
|
||||||
|
Object.entries(hosts).forEach(([dns, ips])=>{
|
||||||
|
acc[dns] ||= ips.join(', ');
|
||||||
|
});
|
||||||
|
if (ruleset) {
|
||||||
|
acc[`RULE-SET:https://ruleset.skk.moe/Modules/Rules/sukka_local_dns_mapping/${ruleset_name}.conf`] ||= `server:${dns}`;
|
||||||
|
} else {
|
||||||
|
domains.forEach((domain)=>{
|
||||||
|
switch(domain[0]){
|
||||||
|
case '$':
|
||||||
|
acc[domain.slice(1)] ||= `server:${dns}`;
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
acc[`*.${domain.slice(1)}`] ||= `server:${dns}`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
acc[domain] ||= `server:${dns}`;
|
||||||
|
acc[`*.${domain}`] ||= `server:${dns}`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, {})).map(([dns, ips])=>`${dns} = ${ips}`)
|
||||||
|
], _nodepath.default.resolve(_dir.OUTPUT_MODULES_DIR, 'sukka_local_dns_mapping.sgmodule')),
|
||||||
|
(0, _createfile.compareAndWriteFile)(span, _yaml.stringify(dataset.reduce((acc, cur)=>{
|
||||||
|
const { domains, dns, ...rest } = cur[1];
|
||||||
|
domains.forEach((domain)=>{
|
||||||
|
switch(domain[0]){
|
||||||
|
case '$':
|
||||||
|
domain = domain.slice(1);
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
domain = `*.${domain.slice(1)}`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
domain = `+.${domain}`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
acc.dns['nameserver-policy'][domain] = dns === 'system' ? [
|
||||||
|
'system://',
|
||||||
|
'system',
|
||||||
|
'dhcp://system'
|
||||||
|
] : dns;
|
||||||
|
});
|
||||||
|
if ('hosts' in rest) {
|
||||||
|
Object.assign(acc.hosts, rest.hosts);
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, {
|
||||||
|
dns: {
|
||||||
|
'nameserver-policy': {}
|
||||||
|
},
|
||||||
|
hosts: {}
|
||||||
|
}), {
|
||||||
|
version: '1.1'
|
||||||
|
}).split('\n'), _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'clash_nameserver_policy.yaml')),
|
||||||
|
(0, _createfile.compareAndWriteFile)(span, [
|
||||||
|
'# Local DNS Mapping for AdGuard Home',
|
||||||
|
'tls://1.12.12.12',
|
||||||
|
'tls://120.53.53.53',
|
||||||
|
'https://1.12.12.12/dns-query',
|
||||||
|
'https://120.53.53.53/dns-query',
|
||||||
|
'[//]udp://10.10.1.1:53',
|
||||||
|
...[
|
||||||
|
_domestic.DOMESTICS,
|
||||||
|
_direct.DIRECTS,
|
||||||
|
_direct.LAN
|
||||||
|
].flatMap(Object.values).flatMap(({ domains, dns: _dns })=>domains.flatMap((domain)=>{
|
||||||
|
let dns;
|
||||||
|
if (_dns in _domestic.AdGuardHomeDNSMapping) {
|
||||||
|
dns = _domestic.AdGuardHomeDNSMapping[_dns].join(' ');
|
||||||
|
} else {
|
||||||
|
console.warn(`Unknown DNS "${_dns}" not in AdGuardHomeDNSMapping`);
|
||||||
|
dns = _dns;
|
||||||
|
}
|
||||||
|
// if (
|
||||||
|
// // AdGuard Home has built-in AS112 / private PTR handling
|
||||||
|
// domain.endsWith('.arpa')
|
||||||
|
// // Ignore simple hostname
|
||||||
|
// || !domain.includes('.')
|
||||||
|
// ) {
|
||||||
|
// return [];
|
||||||
|
// }
|
||||||
|
if (domain[0] === '$') {
|
||||||
|
return [
|
||||||
|
`[/${domain.slice(1)}/]${dns}`
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if (domain[0] === '+') {
|
||||||
|
return [
|
||||||
|
`[/${domain.slice(1)}/]${dns}`
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
`[/${domain}/]${dns}`
|
||||||
|
];
|
||||||
|
}))
|
||||||
|
], _nodepath.default.resolve(_dir.OUTPUT_INTERNAL_DIR, 'dns_mapping_adguardhome.conf'))
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
} (buildDomesticDirectLanRulesetDnsMappingModule.__module, buildDomesticDirectLanRulesetDnsMappingModule.__module.exports));
|
||||||
|
return buildDomesticDirectLanRulesetDnsMappingModule.__module.exports;
|
||||||
|
}exports.__require=requireBuildDomesticDirectLanRulesetDnsMappingModule;
|
||||||
2
Dist/Build/build-internal-reverse-chn-cidr.cjs
Normal file
2
Dist/Build/build-internal-reverse-chn-cidr.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildInternalReverseChnCidr$1=require('./build-internal-reverse-chn-cidr2.cjs');var buildInternalReverseChnCidrExports = buildInternalReverseChnCidr$1.__require();
|
||||||
|
const buildInternalReverseChnCidr = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildInternalReverseChnCidrExports);module.exports=buildInternalReverseChnCidr;
|
||||||
77
Dist/Build/build-internal-reverse-chn-cidr2.cjs
Normal file
77
Dist/Build/build-internal-reverse-chn-cidr2.cjs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildInternalReverseChnCidr=require('../_virtual/build-internal-reverse-chn-cidr.cjs'),require$$0$1=require('node:path'),index=require('./trace/index.cjs'),buildChnCidr=require('./build-chn-cidr2.cjs'),require$$1=require('node:fs'),dir=require('./constants/dir.cjs'),require$$0=require('foxts/async-write-to-stream'),misc=require('./lib/misc.cjs'),require$$7=require('worktank'),require$$8=require('url');var hasRequiredBuildInternalReverseChnCidr;
|
||||||
|
|
||||||
|
function requireBuildInternalReverseChnCidr () {
|
||||||
|
if (hasRequiredBuildInternalReverseChnCidr) return buildInternalReverseChnCidr.__module.exports;
|
||||||
|
hasRequiredBuildInternalReverseChnCidr = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "buildInternalReverseChnCIDR", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return buildInternalReverseChnCIDR;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1);
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _buildchncidr = buildChnCidr.__require();
|
||||||
|
const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1);
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _asyncwritetostream = require$$0;
|
||||||
|
const _misc = /*@__PURE__*/ misc.__require();
|
||||||
|
const _worktank = /*#__PURE__*/ _interop_require_default(require$$7);
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const pool = new _worktank.default({
|
||||||
|
name: 'build-internal-reverse-chn-cidr',
|
||||||
|
size: 1,
|
||||||
|
timeout: 10000,
|
||||||
|
warmup: true,
|
||||||
|
autoterminate: 30000,
|
||||||
|
env: {},
|
||||||
|
methods: {
|
||||||
|
// eslint-disable-next-line object-shorthand -- workertank
|
||||||
|
getreversedCidr: async function(cidr, importMetaUrl) {
|
||||||
|
// TODO: createRequire is a temporary workaround for https://github.com/nodejs/node/issues/51956
|
||||||
|
const { default: module1 } = await import('node:module');
|
||||||
|
const __require = module1.createRequire(importMetaUrl);
|
||||||
|
const { exclude, merge } = __require('fast-cidr-tools');
|
||||||
|
const { RESERVED_IPV4_CIDR, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } = __require('./constants/cidr');
|
||||||
|
const { appendArrayInPlace } = __require('./lib/append-array-in-place');
|
||||||
|
return merge(appendArrayInPlace(exclude([
|
||||||
|
'0.0.0.0/0'
|
||||||
|
], RESERVED_IPV4_CIDR.concat(cidr), true), // https://github.com/misakaio/chnroutes2/issues/25
|
||||||
|
NON_CN_CIDR_INCLUDED_IN_CHNROUTE), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const buildInternalReverseChnCIDR = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const [cidr] = await span.traceChildPromise('download chnroutes2', (0, _buildchncidr.getChnCidrPromise)());
|
||||||
|
const reversedCidr = await span.traceChildAsync('build reversed chn cidr', async ()=>{
|
||||||
|
const reversedCidr = await pool.exec('getreversedCidr', [
|
||||||
|
cidr,
|
||||||
|
require$$8.pathToFileURL(__filename).toString()
|
||||||
|
]);
|
||||||
|
pool.terminate();
|
||||||
|
return reversedCidr;
|
||||||
|
});
|
||||||
|
const outputFile = _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'reversed-chn-cidr.txt');
|
||||||
|
await (0, _misc.mkdirp)(_dir.OUTPUT_INTERNAL_DIR);
|
||||||
|
const writeStream = _nodefs.default.createWriteStream(outputFile);
|
||||||
|
for (const line of reversedCidr){
|
||||||
|
const p = (0, _asyncwritetostream.asyncWriteToStream)(writeStream, line + '\n');
|
||||||
|
if (p) {
|
||||||
|
// eslint-disable-next-line no-await-in-loop -- stream high water mark
|
||||||
|
await p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await (0, _asyncwritetostream.asyncWriteToStream)(writeStream, '\n');
|
||||||
|
writeStream.end();
|
||||||
|
});
|
||||||
|
} (buildInternalReverseChnCidr.__module, buildInternalReverseChnCidr.__module.exports));
|
||||||
|
return buildInternalReverseChnCidr.__module.exports;
|
||||||
|
}exports.__require=requireBuildInternalReverseChnCidr;
|
||||||
2
Dist/Build/build-microsoft-cdn.cjs
Normal file
2
Dist/Build/build-microsoft-cdn.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildMicrosoftCdn$1=require('./build-microsoft-cdn2.cjs');var buildMicrosoftCdnExports = buildMicrosoftCdn$1.__require();
|
||||||
|
const buildMicrosoftCdn = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildMicrosoftCdnExports);module.exports=buildMicrosoftCdn;
|
||||||
84
Dist/Build/build-microsoft-cdn2.cjs
Normal file
84
Dist/Build/build-microsoft-cdn2.cjs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildMicrosoftCdn=require('../_virtual/build-microsoft-cdn.cjs'),index=require('./trace/index.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),trie=require('./lib/trie.cjs'),description=require('./constants/description.cjs'),memoPromise=require('./lib/memo-promise.cjs'),parseDnsmasq=require('./lib/parse-dnsmasq.cjs'),ruleset=require('./lib/rules/ruleset.cjs'),appendArrayInPlace=require('./lib/append-array-in-place.cjs');var hasRequiredBuildMicrosoftCdn;
|
||||||
|
|
||||||
|
function requireBuildMicrosoftCdn () {
|
||||||
|
if (hasRequiredBuildMicrosoftCdn) return buildMicrosoftCdn.__module.exports;
|
||||||
|
hasRequiredBuildMicrosoftCdn = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
buildMicrosoftCdn: function() {
|
||||||
|
return buildMicrosoftCdn;
|
||||||
|
},
|
||||||
|
getMicrosoftCdnRulesetPromise: function() {
|
||||||
|
return getMicrosoftCdnRulesetPromise;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _trie = /*@__PURE__*/ trie.__require();
|
||||||
|
const _description = /*@__PURE__*/ description.__require();
|
||||||
|
const _memopromise = /*@__PURE__*/ memoPromise.__require();
|
||||||
|
const _parsednsmasq = /*@__PURE__*/ parseDnsmasq.__require();
|
||||||
|
const _ruleset = /*@__PURE__*/ ruleset.__require();
|
||||||
|
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
|
||||||
|
const PROBE_DOMAINS = [
|
||||||
|
'.microsoft.com',
|
||||||
|
'.windows.net',
|
||||||
|
'.windows.com',
|
||||||
|
'.windowsupdate.com',
|
||||||
|
'.windowssearch.com',
|
||||||
|
'.office.net'
|
||||||
|
];
|
||||||
|
const DOMAINS = [
|
||||||
|
'res.cdn.office.net',
|
||||||
|
'res-1.cdn.office.net',
|
||||||
|
'statics.teams.cdn.office.net'
|
||||||
|
];
|
||||||
|
const DOMAIN_SUFFIXES = [
|
||||||
|
'download.prss.microsoft.com'
|
||||||
|
];
|
||||||
|
const BLACKLIST = [
|
||||||
|
'www.microsoft.com',
|
||||||
|
'windowsupdate.com'
|
||||||
|
];
|
||||||
|
const getMicrosoftCdnRulesetPromise = (0, _memopromise.createMemoizedPromise)(async ()=>{
|
||||||
|
// First trie is to find the microsoft domains that matches probe domains
|
||||||
|
const trie = new _trie.HostnameSmolTrie();
|
||||||
|
for await (const line of (await (0, _fetchtextbyline.fetchRemoteTextByLine)('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf'))){
|
||||||
|
const domain = (0, _parsednsmasq.extractDomainsFromFelixDnsmasq)(line);
|
||||||
|
if (domain) {
|
||||||
|
trie.add(domain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// remove blacklist domain from trie, to prevent them from being included in the later dump
|
||||||
|
BLACKLIST.forEach((black)=>trie.whitelist(black));
|
||||||
|
const domains = DOMAINS;
|
||||||
|
const domainSuffixes = (0, _appendarrayinplace.appendArrayInPlace)(PROBE_DOMAINS.flatMap((domain)=>trie.find(domain)), DOMAIN_SUFFIXES);
|
||||||
|
return [
|
||||||
|
domains,
|
||||||
|
domainSuffixes
|
||||||
|
];
|
||||||
|
});
|
||||||
|
const buildMicrosoftCdn = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const description = [
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
'This file contains Microsoft\'s domains using their China mainland CDN servers.',
|
||||||
|
'',
|
||||||
|
'Data from:',
|
||||||
|
' - https://github.com/felixonmars/dnsmasq-china-list'
|
||||||
|
];
|
||||||
|
const [domains, domainSuffixes] = await span.traceChildPromise('get microsoft cdn domains', getMicrosoftCdnRulesetPromise());
|
||||||
|
return new _ruleset.RulesetOutput(span, 'microsoft_cdn', 'non_ip').withTitle('Sukka\'s Ruleset - Microsoft CDN').withDescription(description).bulkAddDomain(domains).bulkAddDomainSuffix(domainSuffixes).write();
|
||||||
|
});
|
||||||
|
} (buildMicrosoftCdn.__module, buildMicrosoftCdn.__module.exports));
|
||||||
|
return buildMicrosoftCdn.__module.exports;
|
||||||
|
}exports.__require=requireBuildMicrosoftCdn;
|
||||||
2
Dist/Build/build-public.cjs
Normal file
2
Dist/Build/build-public.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildPublic$1=require('./build-public2.cjs');var buildPublicExports = buildPublic$1.__require();
|
||||||
|
const buildPublic = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildPublicExports);module.exports=buildPublic;
|
||||||
158
Dist/Build/build-public2.cjs
Normal file
158
Dist/Build/build-public2.cjs
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildPublic=require('../_virtual/build-public.cjs'),require$$0$1=require('node:path'),require$$1=require('node:fs'),require$$2=require('node:fs/promises'),index=require('./trace/index.cjs'),treeDir=require('./lib/tree-dir.cjs'),dir=require('./constants/dir.cjs'),misc=require('./lib/misc.cjs'),require$$0=require('picocolors'),require$$8=require('foxts/tagged'),createFile=require('./lib/create-file.cjs');var hasRequiredBuildPublic;
|
||||||
|
|
||||||
|
function requireBuildPublic () {
|
||||||
|
if (hasRequiredBuildPublic) return buildPublic.__module.exports;
|
||||||
|
hasRequiredBuildPublic = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "buildPublic", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return buildPublic;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1);
|
||||||
|
const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1);
|
||||||
|
const _promises = /*#__PURE__*/ _interop_require_default(require$$2);
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _treedir = /*@__PURE__*/ treeDir.__require();
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _misc = /*@__PURE__*/ misc.__require();
|
||||||
|
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _tagged = require$$8;
|
||||||
|
const _createfile = /*@__PURE__*/ createFile.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const mockDir = _nodepath.default.join(_dir.ROOT_DIR, 'Mock');
|
||||||
|
const modulesDir = _nodepath.default.join(_dir.ROOT_DIR, 'Modules');
|
||||||
|
async function copyDirContents(srcDir, destDir) {
|
||||||
|
const promises = [];
|
||||||
|
for await (const entry of (await _promises.default.opendir(srcDir))){
|
||||||
|
const src = _nodepath.default.join(srcDir, entry.name);
|
||||||
|
const dest = _nodepath.default.join(destDir, entry.name);
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
console.warn(_picocolors.default.red('[build public] cant copy directory'), src);
|
||||||
|
} else {
|
||||||
|
promises.push(_promises.default.copyFile(src, dest, _nodefs.default.constants.COPYFILE_FICLONE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.all(promises);
|
||||||
|
}
|
||||||
|
const buildPublic = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
await span.traceChildAsync('copy rest of the files', async ()=>{
|
||||||
|
await Promise.all([
|
||||||
|
// mkdirp(OUTPUT_MODULES_DIR),
|
||||||
|
(0, _misc.mkdirp)(_dir.OUTPUT_MODULES_RULES_DIR),
|
||||||
|
(0, _misc.mkdirp)(_dir.OUTPUT_MOCK_DIR)
|
||||||
|
]);
|
||||||
|
await Promise.all([
|
||||||
|
copyDirContents(modulesDir, _dir.OUTPUT_MODULES_DIR),
|
||||||
|
copyDirContents(mockDir, _dir.OUTPUT_MOCK_DIR)
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
const html = await span.traceChild('generate index.html').traceAsyncFn(()=>(0, _treedir.treeDir)(_dir.PUBLIC_DIR).then(generateHtml));
|
||||||
|
await (0, _createfile.compareAndWriteFile)(span, [
|
||||||
|
'/*',
|
||||||
|
' cache-control: public, max-age=240, stale-while-revalidate=60, stale-if-error=15',
|
||||||
|
'https://:project.pages.dev/*',
|
||||||
|
' X-Robots-Tag: noindex',
|
||||||
|
'/Modules/*',
|
||||||
|
' content-type: text/plain; charset=utf-8',
|
||||||
|
'/List/*',
|
||||||
|
' content-type: text/plain; charset=utf-8'
|
||||||
|
], _nodepath.default.join(_dir.PUBLIC_DIR, '_headers'));
|
||||||
|
await (0, _createfile.compareAndWriteFile)(span, [
|
||||||
|
'# <pre>',
|
||||||
|
'#########################################',
|
||||||
|
'# Sukka\'s Ruleset - 404 Not Found',
|
||||||
|
'################## EOF ##################</pre>'
|
||||||
|
], _nodepath.default.join(_dir.PUBLIC_DIR, '404.html'));
|
||||||
|
return (0, _misc.writeFile)(_nodepath.default.join(_dir.PUBLIC_DIR, 'index.html'), html);
|
||||||
|
});
|
||||||
|
const priorityOrder = {
|
||||||
|
domainset: 1,
|
||||||
|
non_ip: 2,
|
||||||
|
ip: 3,
|
||||||
|
List: 10,
|
||||||
|
Surge: 11,
|
||||||
|
Clash: 12,
|
||||||
|
'sing-box': 13,
|
||||||
|
Modules: 20,
|
||||||
|
Script: 30,
|
||||||
|
Mock: 40,
|
||||||
|
Assets: 50,
|
||||||
|
Internal: 60,
|
||||||
|
LICENSE: 70,
|
||||||
|
default: Number.MAX_VALUE
|
||||||
|
};
|
||||||
|
const prioritySorter = (a, b)=>(priorityOrder[a.name] || priorityOrder.default) - (priorityOrder[b.name] || priorityOrder.default) || (0, _misc.fastStringCompare)(a.name, b.name);
|
||||||
|
function walk(tree) {
|
||||||
|
let result = '';
|
||||||
|
tree.sort(prioritySorter);
|
||||||
|
for(let i = 0, len = tree.length; i < len; i++){
|
||||||
|
const entry = tree[i];
|
||||||
|
if (entry.type === _treedir.TreeFileType.DIRECTORY) {
|
||||||
|
result += (0, _tagged.tagged)`
|
||||||
|
<li class="folder">
|
||||||
|
${entry.name}
|
||||||
|
<ul>
|
||||||
|
${walk(entry.children)}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
`;
|
||||||
|
} else if (/* entry.type === 'file' && */ entry.name !== 'index.html') {
|
||||||
|
result += (0, _tagged.tagged)`<li><a class="file directory-list-file" href="${entry.path}">${entry.name}</a></li>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
function generateHtml(tree) {
|
||||||
|
return (0, _tagged.tagged)`
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Surge Ruleset Server | Sukka (@SukkaW)</title>
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
|
||||||
|
<link href="https://cdn.skk.moe/favicon.ico" rel="icon" type="image/ico">
|
||||||
|
<link href="https://cdn.skk.moe/favicon/apple-touch-icon.png" rel="apple-touch-icon" sizes="180x180">
|
||||||
|
<link href="https://cdn.skk.moe/favicon/android-chrome-192x192.png" rel="icon" type="image/png" sizes="192x192">
|
||||||
|
<link href="https://cdn.skk.moe/favicon/favicon-32x32.png" rel="icon" type="image/png" sizes="32x32">
|
||||||
|
<link href="https://cdn.skk.moe/favicon/favicon-16x16.png" rel="icon" type="image/png" sizes="16x16">
|
||||||
|
<meta name="description" content="Sukka 自用的 Surge / Clash Premium 规则组">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="https://cdn.skk.moe/ruleset/css/21d8777a.css" />
|
||||||
|
|
||||||
|
<meta property="og:title" content="Surge Ruleset | Sukka (@SukkaW)">
|
||||||
|
<meta property="og:type" content="Website">
|
||||||
|
<meta property="og:url" content="https://ruleset.skk.moe/">
|
||||||
|
<meta property="og:image" content="https://cdn.skk.moe/favicon/android-chrome-192x192.png">
|
||||||
|
<meta property="og:description" content="Sukka 自用的 Surge / Clash Premium 规则组">
|
||||||
|
<meta name="twitter:card" content="summary">
|
||||||
|
<link rel="canonical" href="https://ruleset.skk.moe/">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="container">
|
||||||
|
<h1>Sukka Ruleset Server</h1>
|
||||||
|
<p>
|
||||||
|
Made by <a href="https://skk.moe">Sukka</a> | <a href="https://github.com/SukkaW/Surge/">Source @ GitHub</a> | Licensed under <a href="/LICENSE" target="_blank">AGPL-3.0</a>
|
||||||
|
</p>
|
||||||
|
<p>Last Build: ${new Date().toISOString()}</p>
|
||||||
|
<br>
|
||||||
|
<ul class="directory-list">
|
||||||
|
${walk(tree)}
|
||||||
|
</ul>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
} (buildPublic.__module, buildPublic.__module.exports));
|
||||||
|
return buildPublic.__module.exports;
|
||||||
|
}exports.__require=requireBuildPublic;
|
||||||
2
Dist/Build/build-reject-domainset.cjs
Normal file
2
Dist/Build/build-reject-domainset.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildRejectDomainset$1=require('./build-reject-domainset2.cjs');var buildRejectDomainsetExports = buildRejectDomainset$1.__require();
|
||||||
|
const buildRejectDomainset = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildRejectDomainsetExports);module.exports=buildRejectDomainset;
|
||||||
141
Dist/Build/build-reject-domainset2.cjs
Normal file
141
Dist/Build/build-reject-domainset2.cjs
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildRejectDomainset=require('../_virtual/build-reject-domainset.cjs'),require$$0=require('node:path'),require$$1=require('node:process'),hosts=require('./lib/parse-filter/hosts.cjs'),domainlists=require('./lib/parse-filter/domainlists.cjs'),filters=require('./lib/parse-filter/filters.cjs'),rejectDataSource=require('./constants/reject-data-source.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),getPhishingDomains=require('./lib/get-phishing-domains.cjs'),require$$10=require('foxts/add-array-elements-to-set'),dir=require('./constants/dir.cjs'),domainset=require('./lib/rules/domainset.cjs'),shared=require('./lib/parse-filter/shared.cjs');var hasRequiredBuildRejectDomainset;
|
||||||
|
|
||||||
|
function requireBuildRejectDomainset () {
|
||||||
|
if (hasRequiredBuildRejectDomainset) return buildRejectDomainset.__module.exports;
|
||||||
|
hasRequiredBuildRejectDomainset = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "buildRejectDomainSet", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return buildRejectDomainSet;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1);
|
||||||
|
const _hosts = /*@__PURE__*/ hosts.__require();
|
||||||
|
const _domainlists = /*@__PURE__*/ domainlists.__require();
|
||||||
|
const _filters = /*@__PURE__*/ filters.__require();
|
||||||
|
const _rejectdatasource = /*@__PURE__*/ rejectDataSource.__require();
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _description = /*@__PURE__*/ description.__require();
|
||||||
|
const _getphishingdomains = /*@__PURE__*/ getPhishingDomains.__require();
|
||||||
|
const _addarrayelementstoset = require$$10;
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _domainset = /*@__PURE__*/ domainset.__require();
|
||||||
|
const _shared = /*@__PURE__*/ shared.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const readLocalRejectDomainsetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/reject_sukka.conf'));
|
||||||
|
const readLocalRejectExtraDomainsetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/reject_sukka_extra.conf'));
|
||||||
|
const readLocalRejectRulesetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/reject.conf'));
|
||||||
|
const readLocalRejectDropRulesetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/reject-drop.conf'));
|
||||||
|
const readLocalRejectNoDropRulesetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/reject-no-drop.conf'));
|
||||||
|
const readLocalMyRejectRulesetPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'non_ip/my_reject.conf'));
|
||||||
|
const hostsDownloads = _rejectdatasource.HOSTS.map((entry)=>(0, _hosts.processHostsWithPreload)(...entry));
|
||||||
|
const hostsExtraDownloads = _rejectdatasource.HOSTS_EXTRA.map((entry)=>(0, _hosts.processHostsWithPreload)(...entry));
|
||||||
|
const domainListsDownloads = _rejectdatasource.DOMAIN_LISTS.map((entry)=>(0, _domainlists.processDomainListsWithPreload)(...entry));
|
||||||
|
const domainListsExtraDownloads = _rejectdatasource.DOMAIN_LISTS_EXTRA.map((entry)=>(0, _domainlists.processDomainListsWithPreload)(...entry));
|
||||||
|
const adguardFiltersDownloads = _rejectdatasource.ADGUARD_FILTERS.map((entry)=>(0, _filters.processFilterRulesWithPreload)(...entry));
|
||||||
|
const adguardFiltersExtraDownloads = _rejectdatasource.ADGUARD_FILTERS_EXTRA.map((entry)=>(0, _filters.processFilterRulesWithPreload)(...entry));
|
||||||
|
const adguardFiltersWhitelistsDownloads = _rejectdatasource.ADGUARD_FILTERS_WHITELIST.map((entry)=>(0, _filters.processFilterRulesWithPreload)(...entry));
|
||||||
|
const buildRejectDomainSet = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const rejectBaseDescription = [
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
'The domainset supports AD blocking, tracking protection, privacy protection, anti-phishing, anti-mining',
|
||||||
|
'',
|
||||||
|
'Build from:',
|
||||||
|
..._rejectdatasource.HOSTS.map((host)=>` - ${host[0]}`),
|
||||||
|
..._rejectdatasource.DOMAIN_LISTS.map((domainList)=>` - ${domainList[0]}`),
|
||||||
|
..._rejectdatasource.ADGUARD_FILTERS.map((filter)=>` - ${Array.isArray(filter) ? filter[0] : filter}`)
|
||||||
|
];
|
||||||
|
const rejectOutput = new _domainset.DomainsetOutput(span, 'reject').withTitle('Sukka\'s Ruleset - Reject Base').withDescription(rejectBaseDescription);
|
||||||
|
const rejectExtraOutput = new _domainset.DomainsetOutput(span, 'reject_extra').withTitle('Sukka\'s Ruleset - Reject Extra').withDescription([
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
'The domainset supports AD blocking, tracking protection, privacy protection, anti-phishing, anti-mining',
|
||||||
|
'',
|
||||||
|
'Build from:',
|
||||||
|
..._rejectdatasource.HOSTS_EXTRA.map((host)=>` - ${host[0]}`),
|
||||||
|
..._rejectdatasource.DOMAIN_LISTS_EXTRA.map((domainList)=>` - ${domainList[0]}`),
|
||||||
|
..._rejectdatasource.ADGUARD_FILTERS_EXTRA.map((filter)=>` - ${Array.isArray(filter) ? filter[0] : filter}`),
|
||||||
|
..._rejectdatasource.PHISHING_DOMAIN_LISTS_EXTRA.map((domainList)=>` - ${domainList[0]}`)
|
||||||
|
]);
|
||||||
|
const appendArrayToRejectOutput = rejectOutput.addFromDomainset.bind(rejectOutput);
|
||||||
|
const appendArrayToRejectExtraOutput = rejectExtraOutput.addFromDomainset.bind(rejectExtraOutput);
|
||||||
|
/** Whitelists */ const filterRuleWhitelistDomainSets = new Set(_rejectdatasource.PREDEFINED_WHITELIST);
|
||||||
|
// Parse from AdGuard Filters
|
||||||
|
await span.traceChild('download and process hosts / adblock filter rules').traceAsyncFn((childSpan)=>Promise.all([
|
||||||
|
// Parse from remote hosts & domain lists
|
||||||
|
hostsDownloads.map((task)=>task(childSpan).then(appendArrayToRejectOutput)),
|
||||||
|
hostsExtraDownloads.map((task)=>task(childSpan).then(appendArrayToRejectExtraOutput)),
|
||||||
|
domainListsDownloads.map((task)=>task(childSpan).then(appendArrayToRejectOutput)),
|
||||||
|
domainListsExtraDownloads.map((task)=>task(childSpan).then(appendArrayToRejectExtraOutput)),
|
||||||
|
adguardFiltersDownloads.map((task)=>task(childSpan).then(({ whiteDomains, whiteDomainSuffixes, blackDomains, blackDomainSuffixes })=>{
|
||||||
|
(0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomains);
|
||||||
|
(0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomainSuffixes, (suffix)=>'.' + suffix);
|
||||||
|
rejectOutput.bulkAddDomain(blackDomains);
|
||||||
|
rejectOutput.bulkAddDomainSuffix(blackDomainSuffixes);
|
||||||
|
})),
|
||||||
|
adguardFiltersExtraDownloads.map((task)=>task(childSpan).then(({ whiteDomains, whiteDomainSuffixes, blackDomains, blackDomainSuffixes })=>{
|
||||||
|
(0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomains);
|
||||||
|
(0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomainSuffixes, (suffix)=>'.' + suffix);
|
||||||
|
rejectExtraOutput.bulkAddDomain(blackDomains);
|
||||||
|
rejectExtraOutput.bulkAddDomainSuffix(blackDomainSuffixes);
|
||||||
|
})),
|
||||||
|
adguardFiltersWhitelistsDownloads.map((task)=>task(childSpan).then(({ whiteDomains, whiteDomainSuffixes, blackDomains, blackDomainSuffixes })=>{
|
||||||
|
(0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomains);
|
||||||
|
(0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, whiteDomainSuffixes, (suffix)=>'.' + suffix);
|
||||||
|
(0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, blackDomains);
|
||||||
|
(0, _addarrayelementstoset.addArrayElementsToSet)(filterRuleWhitelistDomainSets, blackDomainSuffixes, (suffix)=>'.' + suffix);
|
||||||
|
})),
|
||||||
|
(0, _getphishingdomains.getPhishingDomains)(childSpan).then(appendArrayToRejectExtraOutput),
|
||||||
|
readLocalRejectDomainsetPromise.then(appendArrayToRejectOutput),
|
||||||
|
readLocalRejectDomainsetPromise.then(appendArrayToRejectExtraOutput),
|
||||||
|
readLocalRejectExtraDomainsetPromise.then(appendArrayToRejectExtraOutput),
|
||||||
|
// Dedupe domainSets
|
||||||
|
// span.traceChildAsync('collect black keywords/suffixes', async () =>
|
||||||
|
/**
|
||||||
|
* Collect DOMAIN, DOMAIN-SUFFIX, and DOMAIN-KEYWORD from non_ip/reject.conf for deduplication
|
||||||
|
* DOMAIN-WILDCARD is not really useful for deduplication, it is only included in AdGuardHome output
|
||||||
|
*/ rejectOutput.addFromRuleset(readLocalRejectRulesetPromise),
|
||||||
|
rejectExtraOutput.addFromRuleset(readLocalRejectRulesetPromise)
|
||||||
|
].flat()));
|
||||||
|
if (_shared.foundDebugDomain.value) {
|
||||||
|
// eslint-disable-next-line sukka/unicorn/no-process-exit -- cli App
|
||||||
|
_nodeprocess.default.exit(1);
|
||||||
|
}
|
||||||
|
await Promise.all([
|
||||||
|
rejectOutput.done(),
|
||||||
|
rejectExtraOutput.done()
|
||||||
|
]);
|
||||||
|
// whitelist
|
||||||
|
span.traceChildSync('whitelist', ()=>{
|
||||||
|
for (const domain of filterRuleWhitelistDomainSets){
|
||||||
|
rejectOutput.whitelistDomain(domain);
|
||||||
|
rejectExtraOutput.whitelistDomain(domain);
|
||||||
|
}
|
||||||
|
rejectOutput.domainTrie.dump(rejectExtraOutput.whitelistDomain.bind(rejectExtraOutput));
|
||||||
|
});
|
||||||
|
await Promise.all([
|
||||||
|
rejectOutput.write(),
|
||||||
|
rejectExtraOutput.write()
|
||||||
|
]);
|
||||||
|
// we are going to re-use rejectOutput's domainTrie and mutate it
|
||||||
|
// so we must wait until we write rejectOutput to disk after we can mutate its trie
|
||||||
|
const rejectOutputAdGuardHome = new _domainset.AdGuardHomeOutput(span, 'reject-adguardhome', _dir.OUTPUT_INTERNAL_DIR).withTitle('Sukka\'s Ruleset - Blocklist for AdGuardHome').withDescription([
|
||||||
|
'The domainset supports AD blocking, tracking protection, privacy protection, anti-phishing, anti-mining'
|
||||||
|
]);
|
||||||
|
rejectOutputAdGuardHome.domainTrie = rejectOutput.domainTrie;
|
||||||
|
await rejectOutputAdGuardHome.addFromRuleset(readLocalMyRejectRulesetPromise).addFromRuleset(readLocalRejectRulesetPromise).addFromRuleset(readLocalRejectDropRulesetPromise).addFromRuleset(readLocalRejectNoDropRulesetPromise).write();
|
||||||
|
});
|
||||||
|
} (buildRejectDomainset.__module, buildRejectDomainset.__module.exports));
|
||||||
|
return buildRejectDomainset.__module.exports;
|
||||||
|
}exports.__require=requireBuildRejectDomainset;
|
||||||
2
Dist/Build/build-reject-ip-list.cjs
Normal file
2
Dist/Build/build-reject-ip-list.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildRejectIpList$1=require('./build-reject-ip-list2.cjs');var buildRejectIpListExports = buildRejectIpList$1.__require();
|
||||||
|
const buildRejectIpList = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildRejectIpListExports);module.exports=buildRejectIpList;
|
||||||
96
Dist/Build/build-reject-ip-list2.cjs
Normal file
96
Dist/Build/build-reject-ip-list2.cjs
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildRejectIpList=require('../_virtual/build-reject-ip-list.cjs'),require$$0=require('node:path'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),createFile=require('./lib/create-file.cjs'),dir=require('./constants/dir.cjs'),fetchRetry=require('./lib/fetch-retry.cjs'),fetchAssets=require('./lib/fetch-assets.cjs'),misc=require('./lib/misc.cjs'),badboy_asn=require('../Source/ip/badboy_asn.cjs'),ruleset=require('./lib/rules/ruleset.cjs');var hasRequiredBuildRejectIpList;
|
||||||
|
|
||||||
|
function requireBuildRejectIpList () {
|
||||||
|
if (hasRequiredBuildRejectIpList) return buildRejectIpList.__module.exports;
|
||||||
|
hasRequiredBuildRejectIpList = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "buildRejectIPList", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return buildRejectIPList;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _description = /*@__PURE__*/ description.__require();
|
||||||
|
const _createfile = /*@__PURE__*/ createFile.__require();
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _fetchretry = /*@__PURE__*/ fetchRetry.__require();
|
||||||
|
const _fetchassets = /*@__PURE__*/ fetchAssets.__require();
|
||||||
|
const _misc = /*@__PURE__*/ misc.__require();
|
||||||
|
const _badboy_asn = /*@__PURE__*/ badboy_asn.__require();
|
||||||
|
const _ruleset = /*@__PURE__*/ ruleset.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const BOGUS_NXDOMAIN_URL = 'https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/bogus-nxdomain.china.conf';
|
||||||
|
const getBogusNxDomainIPsPromise = (0, _fetchretry.$$fetch)(BOGUS_NXDOMAIN_URL).then(async (resp)=>{
|
||||||
|
const ipv4 = [];
|
||||||
|
const ipv6 = [];
|
||||||
|
for await (const line of (0, _fetchtextbyline.createReadlineInterfaceFromResponse)(resp, true)){
|
||||||
|
if (line.startsWith('bogus-nxdomain=')) {
|
||||||
|
const ip = line.slice(15).trim();
|
||||||
|
const v = (0, _misc.fastIpVersion)(ip);
|
||||||
|
if (v === 4) {
|
||||||
|
ipv4.push(ip);
|
||||||
|
} else if (v === 6) {
|
||||||
|
ipv6.push(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
ipv4,
|
||||||
|
ipv6
|
||||||
|
];
|
||||||
|
});
|
||||||
|
const BOTNET_FILTER_URL = 'https://malware-filter.pages.dev/botnet-filter-dnscrypt-blocked-ips.txt';
|
||||||
|
const BOTNET_FILTER_MIRROR_URL = [
|
||||||
|
'https://botnet-filter.pages.dev/botnet-filter-dnscrypt-blocked-ips.txt',
|
||||||
|
'https://malware-filter.gitlab.io/malware-filter/botnet-filter-dnscrypt-blocked-ips.txt',
|
||||||
|
'https://malware-filter.gitlab.io/botnet-filter/botnet-filter-dnscrypt-blocked-ips.txt'
|
||||||
|
];
|
||||||
|
const getBotNetFilterIPsPromise = (0, _fetchassets.fetchAssets)(BOTNET_FILTER_URL, BOTNET_FILTER_MIRROR_URL, true).then((arr)=>arr.reduce((acc, ip)=>{
|
||||||
|
const v = (0, _misc.fastIpVersion)(ip);
|
||||||
|
if (v === 4) {
|
||||||
|
acc[0].push(ip);
|
||||||
|
} else if (v === 6) {
|
||||||
|
acc[1].push(ip);
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, [
|
||||||
|
[],
|
||||||
|
[]
|
||||||
|
]));
|
||||||
|
const readLocalRejectIpListPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.resolve(_dir.SOURCE_DIR, 'ip/reject.conf'));
|
||||||
|
const buildRejectIPList = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const [bogusNxDomainIPs, botNetIPs] = await Promise.all([
|
||||||
|
span.traceChildPromise('get bogus nxdomain ips', getBogusNxDomainIPsPromise),
|
||||||
|
span.traceChildPromise('get botnet ips', getBotNetFilterIPsPromise)
|
||||||
|
]);
|
||||||
|
return Promise.all([
|
||||||
|
new _ruleset.RulesetOutput(span, 'reject', 'ip').withTitle('Sukka\'s Ruleset - Anti Bogus Domain').withDescription([
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
'This file contains known addresses that are hijacking NXDOMAIN results returned by DNS servers, and botnet controller IPs.',
|
||||||
|
'',
|
||||||
|
'Data from:',
|
||||||
|
' - https://github.com/felixonmars/dnsmasq-china-list',
|
||||||
|
' - https://github.com/curbengh/botnet-filter'
|
||||||
|
]).addFromRuleset(readLocalRejectIpListPromise).bulkAddCIDR4NoResolve(bogusNxDomainIPs[0]).bulkAddCIDR6NoResolve(bogusNxDomainIPs[1]).bulkAddCIDR4NoResolve(botNetIPs[0]).bulkAddCIDR6NoResolve(botNetIPs[1]).bulkAddIPASN(_badboy_asn.AUGUST_ASN).bulkAddIPASN(_badboy_asn.HUIZE_ASN).write(),
|
||||||
|
(0, _createfile.compareAndWriteFile)(span, [
|
||||||
|
_badboy_asn.AUGUST_ASN.join(' ')
|
||||||
|
], _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'august_asn.txt')),
|
||||||
|
(0, _createfile.compareAndWriteFile)(span, [
|
||||||
|
_badboy_asn.HUIZE_ASN.join(' ')
|
||||||
|
], _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'huize_asn.txt'))
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
} (buildRejectIpList.__module, buildRejectIpList.__module.exports));
|
||||||
|
return buildRejectIpList.__module.exports;
|
||||||
|
}exports.__require=requireBuildRejectIpList;
|
||||||
2
Dist/Build/build-sgmodule-always-realip.cjs
Normal file
2
Dist/Build/build-sgmodule-always-realip.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildSgmoduleAlwaysRealip$1=require('./build-sgmodule-always-realip2.cjs');var buildSgmoduleAlwaysRealipExports = buildSgmoduleAlwaysRealip$1.__require();
|
||||||
|
const buildSgmoduleAlwaysRealip = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildSgmoduleAlwaysRealipExports);module.exports=buildSgmoduleAlwaysRealip;
|
||||||
136
Dist/Build/build-sgmodule-always-realip2.cjs
Normal file
136
Dist/Build/build-sgmodule-always-realip2.cjs
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildSgmoduleAlwaysRealip=require('../_virtual/build-sgmodule-always-realip.cjs'),require$$0=require('node:path'),index=require('./trace/index.cjs'),createFile=require('./lib/create-file.cjs'),direct=require('../Source/non_ip/direct.cjs'),domestic=require('../Source/non_ip/domestic.cjs'),require$$8=require('yaml'),dir=require('./constants/dir.cjs'),appendArrayInPlace=require('./lib/append-array-in-place.cjs'),description=require('./constants/description.cjs'),buildDomesticDirectLanRulesetDnsMappingModule=require('./build-domestic-direct-lan-ruleset-dns-mapping-module2.cjs'),clash=require('./lib/writing-strategy/clash.cjs'),base=require('./lib/rules/base.cjs');var hasRequiredBuildSgmoduleAlwaysRealip;
|
||||||
|
|
||||||
|
function requireBuildSgmoduleAlwaysRealip () {
|
||||||
|
if (hasRequiredBuildSgmoduleAlwaysRealip) return buildSgmoduleAlwaysRealip.__module.exports;
|
||||||
|
hasRequiredBuildSgmoduleAlwaysRealip = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "buildAlwaysRealIPModule", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return buildAlwaysRealIPModule;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _createfile = /*@__PURE__*/ createFile.__require();
|
||||||
|
const _direct = /*@__PURE__*/ direct.__require();
|
||||||
|
const _domestic = /*@__PURE__*/ domestic.__require();
|
||||||
|
const _yaml = /*#__PURE__*/ _interop_require_wildcard(require$$8);
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
|
||||||
|
const _description = /*@__PURE__*/ description.__require();
|
||||||
|
const _builddomesticdirectlanrulesetdnsmappingmodule = buildDomesticDirectLanRulesetDnsMappingModule.__require();
|
||||||
|
const _clash = /*@__PURE__*/ clash.__require();
|
||||||
|
const _base = /*@__PURE__*/ base.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function _getRequireWildcardCache(nodeInterop) {
|
||||||
|
if (typeof WeakMap !== "function") return null;
|
||||||
|
var cacheBabelInterop = new WeakMap();
|
||||||
|
var cacheNodeInterop = new WeakMap();
|
||||||
|
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||||
|
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||||
|
})(nodeInterop);
|
||||||
|
}
|
||||||
|
function _interop_require_wildcard(obj, nodeInterop) {
|
||||||
|
if (obj && obj.__esModule) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||||
|
return {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var cache = _getRequireWildcardCache(nodeInterop);
|
||||||
|
if (cache && cache.has(obj)) {
|
||||||
|
return cache.get(obj);
|
||||||
|
}
|
||||||
|
var newObj = {
|
||||||
|
__proto__: null
|
||||||
|
};
|
||||||
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||||
|
for(var key in obj){
|
||||||
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||||
|
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||||
|
if (desc && (desc.get || desc.set)) {
|
||||||
|
Object.defineProperty(newObj, key, desc);
|
||||||
|
} else {
|
||||||
|
newObj[key] = obj[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newObj.default = obj;
|
||||||
|
if (cache) {
|
||||||
|
cache.set(obj, newObj);
|
||||||
|
}
|
||||||
|
return newObj;
|
||||||
|
}
|
||||||
|
const HOSTNAMES = [
|
||||||
|
// Network Detection, Captive Portal
|
||||||
|
'dns.msftncsi.com',
|
||||||
|
// '*.msftconnecttest.com',
|
||||||
|
// 'network-test.debian.org',
|
||||||
|
// 'detectportal.firefox.com',
|
||||||
|
// Handle SNAT conversation properly
|
||||||
|
'*.srv.nintendo.net',
|
||||||
|
'*.stun.playstation.net',
|
||||||
|
'xbox.*.microsoft.com',
|
||||||
|
'*.xboxlive.com',
|
||||||
|
'*.turn.twilio.com',
|
||||||
|
'*.stun.twilio.com',
|
||||||
|
'stun.syncthing.net',
|
||||||
|
'stun.*'
|
||||||
|
];
|
||||||
|
const buildAlwaysRealIPModule = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const surge = [];
|
||||||
|
const clashFakeIpFilter = new _base.FileOutput(span, 'clash_fake_ip_filter').withTitle('Sukka\'s Ruleset - Always Real IP Plus').withDescription([
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
'Clash.Meta fake-ip-filter as ruleset'
|
||||||
|
]).withStrategies([
|
||||||
|
new _clash.ClashDomainSet('domainset')
|
||||||
|
]);
|
||||||
|
// Intranet, Router Setup, and mant more
|
||||||
|
const dataset = [
|
||||||
|
_direct.DIRECTS,
|
||||||
|
_direct.LAN,
|
||||||
|
_domestic.DOMESTICS,
|
||||||
|
_domestic.DOH_BOOTSTRAP
|
||||||
|
].reduce((acc, item)=>{
|
||||||
|
Object.values(item).forEach((i)=>{
|
||||||
|
if (i.realip) {
|
||||||
|
acc.push(i);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
const getDnsMappingRuleWithoutWildcard = (0, _builddomesticdirectlanrulesetdnsmappingmodule.createGetDnsMappingRule)(false);
|
||||||
|
for (const { domains } of dataset){
|
||||||
|
clashFakeIpFilter.addFromRuleset(domains.flatMap(getDnsMappingRuleWithoutWildcard));
|
||||||
|
}
|
||||||
|
return Promise.all([
|
||||||
|
(0, _createfile.compareAndWriteFile)(span, [
|
||||||
|
'#!name=[Sukka] Always Real IP Plus',
|
||||||
|
`#!desc=Last Updated: ${new Date().toISOString()}`,
|
||||||
|
'',
|
||||||
|
'[General]',
|
||||||
|
`always-real-ip = %APPEND% ${HOSTNAMES.concat(surge).join(', ')}`
|
||||||
|
], _nodepath.default.resolve(_dir.OUTPUT_MODULES_DIR, 'sukka_common_always_realip.sgmodule')),
|
||||||
|
(0, _createfile.compareAndWriteFile)(span, _yaml.stringify({
|
||||||
|
dns: {
|
||||||
|
'fake-ip-filter': (0, _appendarrayinplace.appendArrayInPlace)(/** clash */ dataset.flatMap(({ domains })=>domains.map((domain)=>`+.${domain}`)), HOSTNAMES)
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
version: '1.1'
|
||||||
|
}).split('\n'), _nodepath.default.join(_dir.OUTPUT_INTERNAL_DIR, 'clash_fake_ip_filter.yaml'))
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
} (buildSgmoduleAlwaysRealip.__module, buildSgmoduleAlwaysRealip.__module.exports));
|
||||||
|
return buildSgmoduleAlwaysRealip.__module.exports;
|
||||||
|
}exports.__require=requireBuildSgmoduleAlwaysRealip;
|
||||||
2
Dist/Build/build-sgmodule-redirect.cjs
Normal file
2
Dist/Build/build-sgmodule-redirect.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildSgmoduleRedirect$1=require('./build-sgmodule-redirect2.cjs');var buildSgmoduleRedirectExports = buildSgmoduleRedirect$1.__require();
|
||||||
|
const buildSgmoduleRedirect = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildSgmoduleRedirectExports);module.exports=buildSgmoduleRedirect;
|
||||||
508
Dist/Build/build-sgmodule-redirect2.cjs
Normal file
508
Dist/Build/build-sgmodule-redirect2.cjs
Normal file
@ -0,0 +1,508 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildSgmoduleRedirect=require('../_virtual/build-sgmodule-redirect.cjs'),require$$0=require('node:path'),index=require('./trace/index.cjs'),createFile=require('./lib/create-file.cjs'),require$$5=require('tldts-experimental'),require$$6=require('foxts/guard'),dir=require('./constants/dir.cjs');var hasRequiredBuildSgmoduleRedirect;
|
||||||
|
|
||||||
|
function requireBuildSgmoduleRedirect () {
|
||||||
|
if (hasRequiredBuildSgmoduleRedirect) return buildSgmoduleRedirect.__module.exports;
|
||||||
|
hasRequiredBuildSgmoduleRedirect = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "buildRedirectModule", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return buildRedirectModule;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _createfile = /*@__PURE__*/ createFile.__require();
|
||||||
|
const _tldtsexperimental = require$$5;
|
||||||
|
const _guard = require$$6;
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function escapeRegExp(string = '') {
|
||||||
|
const reRegExpChar = /[$()*+.?[\\\]^{|}]/g;
|
||||||
|
const reHasRegExpChar = new RegExp(reRegExpChar.source);
|
||||||
|
return string && reHasRegExpChar.test(string) ? string.replaceAll(reRegExpChar, String.raw`\$&`) : string;
|
||||||
|
}
|
||||||
|
const REDIRECT_MIRROR_HEADER = [
|
||||||
|
// Gravatar
|
||||||
|
[
|
||||||
|
'gravatar.neworld.org/',
|
||||||
|
'https://secure.gravatar.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdn.v2ex.com/gravatar/',
|
||||||
|
'https://secure.gravatar.com/avatar/'
|
||||||
|
],
|
||||||
|
// U.SB
|
||||||
|
[
|
||||||
|
'cdnjs.loli.net/',
|
||||||
|
'https://cdnjs.cloudflare.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'fonts.loli.net/',
|
||||||
|
'https://fonts.googleapis.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'gstatic.loli.net/',
|
||||||
|
'https://fonts.gstatic.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'themes.loli.net/',
|
||||||
|
'https://themes.googleusercontent.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'ajax.loli.net/',
|
||||||
|
'https://ajax.googleapis.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'gravatar.loli.net/',
|
||||||
|
'https://secure.gravatar.com/'
|
||||||
|
],
|
||||||
|
// Geekzu
|
||||||
|
[
|
||||||
|
'gapis.geekzu.org/ajax/',
|
||||||
|
'https://ajax.googleapis.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'fonts.geekzu.org/',
|
||||||
|
'https://fonts.googleapis.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'gapis.geekzu.org/g-fonts/',
|
||||||
|
'https://fonts.gstatic.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'gapis.geekzu.org/g-themes/',
|
||||||
|
'https://themes.googleusercontent.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'sdn.geekzu.org/',
|
||||||
|
'https://secure.gravatar.com/'
|
||||||
|
],
|
||||||
|
// libravatar
|
||||||
|
[
|
||||||
|
'seccdn.libravatar.org/gravatarproxy/',
|
||||||
|
'https://secure.gravatar.com/'
|
||||||
|
],
|
||||||
|
// gh-proxy
|
||||||
|
[
|
||||||
|
'github.moeyy.xyz/',
|
||||||
|
'https://'
|
||||||
|
],
|
||||||
|
// 7ED Services
|
||||||
|
[
|
||||||
|
'use.sevencdn.com/css',
|
||||||
|
'https://fonts.googleapis.com/css'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'use.sevencdn.com/ajax/libs/',
|
||||||
|
'https://cdnjs.cloudflare.com/ajax/libs/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'use.sevencdn.com/gajax/',
|
||||||
|
'https://ajax.googleapis.com/ajax/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'use.sevencdn.com/chart',
|
||||||
|
'https://chart.googleapis.com/chart'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'use.sevencdn.com/avatar',
|
||||||
|
'https://secure.gravatar.com/avatar'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'raw.gitmirror.com/',
|
||||||
|
'https://raw.githubusercontent.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'gist.gitmirror.com/',
|
||||||
|
'https://gist.githubusercontent.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'raw.githubusercontents.com/',
|
||||||
|
'https://raw.githubusercontent.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'gist.githubusercontents.com/',
|
||||||
|
'https://gist.githubusercontent.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdn.gitmirror.com/',
|
||||||
|
'https://cdn.statically.io/'
|
||||||
|
],
|
||||||
|
// FastGit
|
||||||
|
[
|
||||||
|
'raw.fastgit.org/',
|
||||||
|
'https://raw.githubusercontent.com/'
|
||||||
|
],
|
||||||
|
// ['assets.fastgit.org/', 'https://github.githubassets.com/'],
|
||||||
|
// jsDelivr
|
||||||
|
[
|
||||||
|
'fastly.jsdelivr.net/',
|
||||||
|
'https://cdn.jsdelivr.net/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'gcore.jsdelivr.net/',
|
||||||
|
'https://cdn.jsdelivr.net/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'testingcf.jsdelivr.net/',
|
||||||
|
'https://cdn.jsdelivr.net/'
|
||||||
|
],
|
||||||
|
// JSDMirror
|
||||||
|
[
|
||||||
|
'cdn.jsdmirror.com/',
|
||||||
|
'https://cdn.jsdelivr.net/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdn.jsdmirror.cn/',
|
||||||
|
'https://cdn.jsdelivr.net/'
|
||||||
|
],
|
||||||
|
// onmicrosoft.cn
|
||||||
|
[
|
||||||
|
'jsd.onmicrosoft.cn/',
|
||||||
|
'https://cdn.jsdelivr.net/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'npm.onmicrosoft.cn/',
|
||||||
|
'https://unpkg.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdnjs.onmicrosoft.cn/',
|
||||||
|
'https://cdnjs.cloudflare.com/ajax/libs/'
|
||||||
|
],
|
||||||
|
// KGitHub
|
||||||
|
[
|
||||||
|
'raw.kgithub.com/',
|
||||||
|
'https://raw.githubusercontent.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'raw.kkgithub.com/',
|
||||||
|
'https://raw.githubusercontent.com/'
|
||||||
|
],
|
||||||
|
// cdn.iocdn.cc
|
||||||
|
[
|
||||||
|
'cdn.iocdn.cc/avatar/',
|
||||||
|
'https://secure.gravatar.com/avatar/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdn.iocdn.cc/css',
|
||||||
|
'https://fonts.googleapis.com/css'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdn.iocdn.cc/icon',
|
||||||
|
'https://fonts.googleapis.com/icon'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdn.iocdn.cc/earlyaccess',
|
||||||
|
'https://fonts.googleapis.com/earlyaccess'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdn.iocdn.cc/s',
|
||||||
|
'fonts.gstatic.com/s'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdn.iocdn.cc/static',
|
||||||
|
'themes.googleusercontent.com/static'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdn.iocdn.cc/ajax',
|
||||||
|
'ajax.googleapis.com/ajax'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdn.iocdn.cc/',
|
||||||
|
'https://cdn.jsdelivr.net/'
|
||||||
|
],
|
||||||
|
// wp-china-yes
|
||||||
|
[
|
||||||
|
'googlefonts.admincdn.com/',
|
||||||
|
'https://fonts.googleapis.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'googleajax.admincdn.com/',
|
||||||
|
'https://ajax.googleapis.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdnjs.admincdn.com/',
|
||||||
|
'https://cdnjs.cloudflare.com/ajax/libs/'
|
||||||
|
],
|
||||||
|
// Polyfill
|
||||||
|
[
|
||||||
|
'polyfill.io/',
|
||||||
|
'https://cdnjs.cloudflare.com/polyfill/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'polyfill.top/',
|
||||||
|
'https://cdnjs.cloudflare.com/polyfill/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'polyfill-js.cn/',
|
||||||
|
'https://cdnjs.cloudflare.com/polyfill/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdn.polyfill.io/',
|
||||||
|
'https://cdnjs.cloudflare.com/polyfill/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'fastly-polyfill.io/',
|
||||||
|
'https://cdnjs.cloudflare.com/polyfill/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'fastly-polyfill.net/',
|
||||||
|
'https://cdnjs.cloudflare.com/polyfill/'
|
||||||
|
],
|
||||||
|
// BootCDN has been controlled by a malicious actor and being used to spread malware
|
||||||
|
[
|
||||||
|
'cdn.bootcss.com/',
|
||||||
|
'https://cdnjs.cloudflare.com/ajax/libs/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdn.bootcdn.net/',
|
||||||
|
'https://cdnjs.cloudflare.com/ajax/libs/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdn.staticfile.net/',
|
||||||
|
'https://cdnjs.cloudflare.com/ajax/libs/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cdn.staticfile.org/',
|
||||||
|
'https://cdnjs.cloudflare.com/ajax/libs/'
|
||||||
|
],
|
||||||
|
// Misc
|
||||||
|
[
|
||||||
|
'pics.javbus.com/',
|
||||||
|
'https://i0.wp.com/pics.javbus.com/'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
const REDIRECT_MIRROR_307 = [
|
||||||
|
// Redirect Google
|
||||||
|
[
|
||||||
|
'google.cn/',
|
||||||
|
'https://google.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'www.google.cn/',
|
||||||
|
'https://www.google.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'g.cn/',
|
||||||
|
'https://google.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'ditu.google.cn/',
|
||||||
|
'https://maps.google.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'maps.google.cn/',
|
||||||
|
'https://maps.google.com/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'www.g.cn/',
|
||||||
|
'https://www.google.com/'
|
||||||
|
],
|
||||||
|
// avg.tv/sm114514 -> https://www.nicovideo.jp/watch/sm114514
|
||||||
|
[
|
||||||
|
'acg.tv/sm',
|
||||||
|
'https://www.nicovideo.jp/watch/sm'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'acg.tv/',
|
||||||
|
'https://b23.tv/'
|
||||||
|
],
|
||||||
|
// Minecraft Wiki
|
||||||
|
[
|
||||||
|
'minecraft.fandom.com/wiki/',
|
||||||
|
'https://minecraft.wiki/w/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'minecraft.fandom.com/',
|
||||||
|
'https://minecraft.wiki/'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'missav.com/',
|
||||||
|
'https://missav.ws/'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
const REDIRECT_FAKEWEBSITES = [
|
||||||
|
// IGN China to IGN Global
|
||||||
|
[
|
||||||
|
'ign.xn--fiqs8s',
|
||||||
|
'https://cn.ign.com/ccpref/us'
|
||||||
|
],
|
||||||
|
// Fuck Makeding
|
||||||
|
[
|
||||||
|
'abbyychina.com',
|
||||||
|
'https://www.abbyy.cn'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'bartender.cc',
|
||||||
|
'https://cn.seagullscientific.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'betterzip.net',
|
||||||
|
'https://macitbetter.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'beyondcompare.cc',
|
||||||
|
'https://www.scootersoftware.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'bingdianhuanyuan.cn',
|
||||||
|
'https://www.faronics.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'chemdraw.com.cn',
|
||||||
|
'https://revvitysignals.com/products/research/chemdraw'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codesoftchina.com',
|
||||||
|
'https://www.teklynx.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'coreldrawchina.com',
|
||||||
|
'https://www.coreldraw.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'crossoverchina.com',
|
||||||
|
'https://www.codeweavers.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'easyrecoverychina.com',
|
||||||
|
'https://www.ontrack.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'ediuschina.com',
|
||||||
|
'https://www.grassvalley.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'flstudiochina.com',
|
||||||
|
'https://www.image-line.com/fl-studio'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'formysql.com',
|
||||||
|
'https://www.navicat.com.cn'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'guitarpro.cc',
|
||||||
|
'https://www.guitar-pro.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'huishenghuiying.com.cn',
|
||||||
|
'https://www.corel.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'iconworkshop.cn',
|
||||||
|
'https://www.axialis.com/iconworkshop'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'imindmap.cc',
|
||||||
|
'https://imindmap.com/zh-cn'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'jihehuaban.com.cn',
|
||||||
|
'https://sketch.io'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'keyshot.cc',
|
||||||
|
'https://www.keyshot.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'mathtype.cn',
|
||||||
|
'https://www.wiris.com/en/mathtype'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'mindmanager.cc',
|
||||||
|
'https://www.mindjet.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'mindmapper.cc',
|
||||||
|
'https://mindmapper.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'mycleanmymac.com',
|
||||||
|
'https://macpaw.com/cleanmymac'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'nicelabel.cc',
|
||||||
|
'https://www.nicelabel.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'ntfsformac.cc',
|
||||||
|
'https://www.tuxera.com/products/tuxera-ntfs-for-mac-cn'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'ntfsformac.cn',
|
||||||
|
'https://www.paragon-software.com/ufsdhome/zh/ntfs-mac'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'overturechina.com',
|
||||||
|
'https://sonicscores.com/overture'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'passwordrecovery.cn',
|
||||||
|
'https://cn.elcomsoft.com/aopr.html'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'pdfexpert.cc',
|
||||||
|
'https://pdfexpert.com/zh'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'ultraiso.net',
|
||||||
|
'https://cn.ezbsystems.com/ultraiso'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'vegaschina.cn',
|
||||||
|
'https://www.vegas.com'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'xmindchina.net',
|
||||||
|
'https://www.xmind.cn'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'xshellcn.com',
|
||||||
|
'https://www.netsarang.com/products/xsh_overview.html'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'yuanchengxiezuo.com',
|
||||||
|
'https://www.teamviewer.com/zhcn'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'zbrushcn.com',
|
||||||
|
'https://www.maxon.net/en/zbrush'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
const buildRedirectModule = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const domains = Array.from(new Set([
|
||||||
|
...REDIRECT_MIRROR_HEADER.map(([from])=>(0, _tldtsexperimental.getHostname)(from, {
|
||||||
|
detectIp: false
|
||||||
|
})),
|
||||||
|
...REDIRECT_FAKEWEBSITES.flatMap(([from])=>[
|
||||||
|
from,
|
||||||
|
`*.${from}`
|
||||||
|
]),
|
||||||
|
...REDIRECT_MIRROR_307.map(([from])=>(0, _tldtsexperimental.getHostname)(from, {
|
||||||
|
detectIp: false
|
||||||
|
}))
|
||||||
|
])).filter(_guard.isTruthy);
|
||||||
|
return (0, _createfile.compareAndWriteFile)(span, [
|
||||||
|
'#!name=[Sukka] URL Redirect',
|
||||||
|
`#!desc=Last Updated: ${new Date().toISOString()} Size: ${domains.length}`,
|
||||||
|
'',
|
||||||
|
'[MITM]',
|
||||||
|
`hostname = %APPEND% ${domains.join(', ')}`,
|
||||||
|
'',
|
||||||
|
'[URL Rewrite]',
|
||||||
|
...REDIRECT_MIRROR_HEADER.map(([from, to])=>`^https?://${escapeRegExp(from)}(.*) ${to}$1 header`),
|
||||||
|
...REDIRECT_FAKEWEBSITES.map(([from, to])=>`^https?://(www.)?${escapeRegExp(from)} ${to} 307`),
|
||||||
|
...REDIRECT_MIRROR_307.map(([from, to])=>`^https?://${escapeRegExp(from)}(.*) ${to}$1 307`)
|
||||||
|
], _nodepath.default.join(_dir.OUTPUT_MODULES_DIR, 'sukka_url_redirect.sgmodule'));
|
||||||
|
});
|
||||||
|
} (buildSgmoduleRedirect.__module, buildSgmoduleRedirect.__module.exports));
|
||||||
|
return buildSgmoduleRedirect.__module.exports;
|
||||||
|
}exports.__require=requireBuildSgmoduleRedirect;
|
||||||
2
Dist/Build/build-speedtest-domainset.cjs
Normal file
2
Dist/Build/build-speedtest-domainset.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildSpeedtestDomainset$1=require('./build-speedtest-domainset2.cjs');var buildSpeedtestDomainsetExports = buildSpeedtestDomainset$1.__require();
|
||||||
|
const buildSpeedtestDomainset = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildSpeedtestDomainsetExports);module.exports=buildSpeedtestDomainset;
|
||||||
113
Dist/Build/build-speedtest-domainset2.cjs
Normal file
113
Dist/Build/build-speedtest-domainset2.cjs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildSpeedtestDomainset=require('../_virtual/build-speedtest-domainset.cjs'),require$$0=require('node:path'),require$$5=require('tldts-experimental'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),domainset=require('./lib/rules/domainset.cjs'),dir=require('./constants/dir.cjs'),require$$7=require('@henrygd/queue'),fetchRetry=require('./lib/fetch-retry.cjs');var hasRequiredBuildSpeedtestDomainset;
|
||||||
|
|
||||||
|
function requireBuildSpeedtestDomainset () {
|
||||||
|
if (hasRequiredBuildSpeedtestDomainset) return buildSpeedtestDomainset.__module.exports;
|
||||||
|
hasRequiredBuildSpeedtestDomainset = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "buildSpeedtestDomainSet", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return buildSpeedtestDomainSet;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _tldtsexperimental = /*#__PURE__*/ _interop_require_default(require$$5);
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _description = /*@__PURE__*/ description.__require();
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _domainset = /*@__PURE__*/ domainset.__require();
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _queue = require$$7;
|
||||||
|
const _fetchretry = /*@__PURE__*/ fetchRetry.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const KEYWORDS = [
|
||||||
|
'Hong Kong',
|
||||||
|
'Taiwan',
|
||||||
|
'China Telecom',
|
||||||
|
'China Mobile',
|
||||||
|
'China Unicom',
|
||||||
|
'Japan',
|
||||||
|
'Tokyo',
|
||||||
|
'Singapore',
|
||||||
|
'Korea',
|
||||||
|
'Seoul',
|
||||||
|
'Canada',
|
||||||
|
'Toronto',
|
||||||
|
'Montreal',
|
||||||
|
'Los Ang',
|
||||||
|
'San Jos',
|
||||||
|
'Seattle',
|
||||||
|
'New York',
|
||||||
|
'Dallas',
|
||||||
|
'Miami',
|
||||||
|
'Berlin',
|
||||||
|
'Frankfurt',
|
||||||
|
'London',
|
||||||
|
'Paris',
|
||||||
|
'Amsterdam',
|
||||||
|
'Moscow',
|
||||||
|
'Australia',
|
||||||
|
'Sydney',
|
||||||
|
'Brazil',
|
||||||
|
'Turkey'
|
||||||
|
];
|
||||||
|
const s = (0, _queue.newQueue)(2);
|
||||||
|
const latestTopUserAgentsPromise = (0, _fetchretry.$$fetch)('https://raw.githubusercontent.com/microlinkhq/top-user-agents/master/src/desktop.json').then((res)=>res.json()).then((userAgents)=>userAgents.filter((ua)=>ua.startsWith('Mozilla/5.0 ')));
|
||||||
|
const getSpeedtestHostsGroupsPromise = Promise.all(KEYWORDS.flatMap(querySpeedtestApi));
|
||||||
|
const buildSpeedtestDomainSet = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const output = new _domainset.DomainsetOutput(span, 'speedtest').withTitle('Sukka\'s Ruleset - Speedtest Domains').withDescription([
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
'This file contains common speedtest endpoints.'
|
||||||
|
]).addFromDomainset((0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.resolve(_dir.SOURCE_DIR, 'domainset/speedtest.conf'))).addFromDomainset((0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.resolve(_dir.OUTPUT_SURGE_DIR, 'domainset/speedtest.conf')));
|
||||||
|
const hostnameGroup = await span.traceChildPromise('get speedtest hosts groups', getSpeedtestHostsGroupsPromise);
|
||||||
|
hostnameGroup.forEach(output.bulkAddDomain.bind(output));
|
||||||
|
return output.write();
|
||||||
|
});
|
||||||
|
async function querySpeedtestApi(keyword) {
|
||||||
|
const topUserAgents = await latestTopUserAgentsPromise;
|
||||||
|
const url = `https://www.speedtest.net/api/js/servers?engine=js&search=${keyword}&limit=100`;
|
||||||
|
try {
|
||||||
|
const randomUserAgent = topUserAgents[Math.floor(Math.random() * topUserAgents.length)];
|
||||||
|
const data = await s.add(()=>(0, _fetchretry.$$fetch)(url, {
|
||||||
|
headers: {
|
||||||
|
dnt: '1',
|
||||||
|
Referer: 'https://www.speedtest.net/',
|
||||||
|
accept: 'application/json, text/plain, */*',
|
||||||
|
'User-Agent': randomUserAgent,
|
||||||
|
'Accept-Language': 'en-US,en;q=0.9',
|
||||||
|
...randomUserAgent.includes('Chrome') ? {
|
||||||
|
'Sec-Ch-Ua-Mobile': '?0',
|
||||||
|
'Sec-Fetch-Dest': 'empty',
|
||||||
|
'Sec-Fetch-Mode': 'cors',
|
||||||
|
'Sec-Fetch-Site': 'same-origin',
|
||||||
|
'Sec-Gpc': '1'
|
||||||
|
} : {}
|
||||||
|
},
|
||||||
|
signal: AbortSignal.timeout(1000 * 60)
|
||||||
|
}).then((res)=>res.json()));
|
||||||
|
return data.reduce((prev, cur)=>{
|
||||||
|
const hn = _tldtsexperimental.default.getHostname(cur.host || cur.url, {
|
||||||
|
detectIp: false,
|
||||||
|
validateHostname: true
|
||||||
|
});
|
||||||
|
if (hn) {
|
||||||
|
prev.push(hn);
|
||||||
|
}
|
||||||
|
return prev;
|
||||||
|
}, []);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} (buildSpeedtestDomainset.__module, buildSpeedtestDomainset.__module.exports));
|
||||||
|
return buildSpeedtestDomainset.__module.exports;
|
||||||
|
}exports.__require=requireBuildSpeedtestDomainset;
|
||||||
2
Dist/Build/build-sspanel-appprofile.cjs
Normal file
2
Dist/Build/build-sspanel-appprofile.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildSspanelAppprofile$1=require('./build-sspanel-appprofile2.cjs');var buildSspanelAppprofileExports = buildSspanelAppprofile$1.__require();
|
||||||
|
const buildSspanelAppprofile = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildSspanelAppprofileExports);module.exports=buildSspanelAppprofile;
|
||||||
217
Dist/Build/build-sspanel-appprofile2.cjs
Normal file
217
Dist/Build/build-sspanel-appprofile2.cjs
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildSspanelAppprofile=require('../_virtual/build-sspanel-appprofile.cjs'),buildAppleCdn=require('./build-apple-cdn2.cjs'),buildDomesticDirectLanRulesetDnsMappingModule=require('./build-domestic-direct-lan-ruleset-dns-mapping-module2.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),index=require('./trace/index.cjs'),require$$0=require('node:path'),stream=require('../Source/stream.cjs'),buildChnCidr=require('./build-chn-cidr2.cjs'),buildTelegramCidr=require('./build-telegram-cidr2.cjs'),createFile=require('./lib/create-file.cjs'),buildMicrosoftCdn=require('./build-microsoft-cdn2.cjs'),require$$6=require('foxts/guard'),appendArrayInPlace=require('./lib/append-array-in-place.cjs'),dir=require('./constants/dir.cjs'),ruleset=require('./lib/rules/ruleset.cjs');var hasRequiredBuildSspanelAppprofile;
|
||||||
|
|
||||||
|
function requireBuildSspanelAppprofile () {
|
||||||
|
if (hasRequiredBuildSspanelAppprofile) return buildSspanelAppprofile.__module.exports;
|
||||||
|
hasRequiredBuildSspanelAppprofile = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "buildSSPanelUIMAppProfile", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return buildSSPanelUIMAppProfile;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _buildapplecdn = buildAppleCdn.__require();
|
||||||
|
const _builddomesticdirectlanrulesetdnsmappingmodule = buildDomesticDirectLanRulesetDnsMappingModule.__require();
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _stream = /*@__PURE__*/ stream.__require();
|
||||||
|
const _buildchncidr = buildChnCidr.__require();
|
||||||
|
const _buildtelegramcidr = buildTelegramCidr.__require();
|
||||||
|
const _createfile = /*@__PURE__*/ createFile.__require();
|
||||||
|
const _buildmicrosoftcdn = buildMicrosoftCdn.__require();
|
||||||
|
const _guard = require$$6;
|
||||||
|
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _ruleset = /*@__PURE__*/ ruleset.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const POLICY_GROUPS = [
|
||||||
|
[
|
||||||
|
'Default Proxy',
|
||||||
|
true,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Global',
|
||||||
|
true,
|
||||||
|
true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Microsoft & Apple',
|
||||||
|
true,
|
||||||
|
true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Stream',
|
||||||
|
true,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Steam Download',
|
||||||
|
true,
|
||||||
|
true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Domestic',
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Final Match',
|
||||||
|
true,
|
||||||
|
true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
const steamDomainsPromise = (0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.SOURCE_DIR, 'domainset/game-download.conf'));
|
||||||
|
const buildSSPanelUIMAppProfile = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const [[domesticRules, directRules, lanRules], appleCdnDomains, [microsoftCdnDomains, microsoftCdnDomainSuffixes], appleCnRules, neteaseMusicRules, microsoftRules, appleRules, streamRules, steamDomainset, globalRules, telegramRules, [domesticCidrs4, domesticCidrs6], [streamCidrs4, streamCidrs6], { ipcidr: telegramCidrs4, ipcidr6: telegramCidrs6 }, rawLanCidrs] = await Promise.all([
|
||||||
|
// domestic - domains
|
||||||
|
(0, _builddomesticdirectlanrulesetdnsmappingmodule.getDomesticAndDirectDomainsRulesetPromise)(),
|
||||||
|
(0, _buildapplecdn.getAppleCdnDomainsPromise)(),
|
||||||
|
(0, _buildmicrosoftcdn.getMicrosoftCdnRulesetPromise)(),
|
||||||
|
(0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/apple_cn.conf')),
|
||||||
|
(0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/neteasemusic.conf')),
|
||||||
|
// microsoft & apple - domains
|
||||||
|
(0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/microsoft.conf')),
|
||||||
|
(0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/apple_services.conf')),
|
||||||
|
// stream - domains
|
||||||
|
_stream.ALL.flatMap((i)=>i.rules),
|
||||||
|
// steam - domains
|
||||||
|
steamDomainsPromise,
|
||||||
|
// global - domains
|
||||||
|
(0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/global.conf')),
|
||||||
|
(0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'non_ip/telegram.conf')),
|
||||||
|
// domestic - ip cidr
|
||||||
|
(0, _buildchncidr.getChnCidrPromise)(),
|
||||||
|
_stream.ALL.reduce((acc, i)=>{
|
||||||
|
if (i.ip) {
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(acc[0], i.ip.v4);
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(acc[1], i.ip.v6);
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, [
|
||||||
|
[],
|
||||||
|
[]
|
||||||
|
]),
|
||||||
|
// global - ip cidr
|
||||||
|
(0, _buildtelegramcidr.getTelegramCIDRPromise)(),
|
||||||
|
// lan - ip cidr
|
||||||
|
(0, _fetchtextbyline.readFileIntoProcessedArray)(_nodepath.default.join(_dir.OUTPUT_SURGE_DIR, 'ip/lan.conf'))
|
||||||
|
]);
|
||||||
|
const domestic = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(domesticRules).bulkAddDomainSuffix(appleCdnDomains).bulkAddDomain(microsoftCdnDomains).bulkAddDomainSuffix(microsoftCdnDomainSuffixes).addFromRuleset(appleCnRules).addFromRuleset(neteaseMusicRules);
|
||||||
|
const microsoftApple = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(microsoftRules).addFromRuleset(appleRules);
|
||||||
|
const stream = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(streamRules);
|
||||||
|
const steam = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromDomainset(steamDomainset);
|
||||||
|
const global = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(globalRules).addFromRuleset(telegramRules);
|
||||||
|
const direct = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'non_ip').addFromRuleset(directRules).addFromRuleset(lanRules);
|
||||||
|
const domesticCidr = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'ip').bulkAddCIDR4(domesticCidrs4).bulkAddCIDR6(domesticCidrs6);
|
||||||
|
const streamCidr = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'ip').bulkAddCIDR4(streamCidrs4).bulkAddCIDR6(streamCidrs6);
|
||||||
|
const telegramCidr = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'ip').bulkAddCIDR4(telegramCidrs4).bulkAddCIDR6(telegramCidrs6);
|
||||||
|
const lanCidrs = new _ruleset.ClashOnlyRulesetOutput(span, '_', 'ip').addFromRuleset(rawLanCidrs);
|
||||||
|
const output = generateAppProfile(...(await Promise.all([
|
||||||
|
domestic.compile(),
|
||||||
|
microsoftApple.compile(),
|
||||||
|
stream.compile(),
|
||||||
|
steam.compile(),
|
||||||
|
global.compile(),
|
||||||
|
direct.compile(),
|
||||||
|
domesticCidr.compile(),
|
||||||
|
streamCidr.compile(),
|
||||||
|
telegramCidr.compile(),
|
||||||
|
lanCidrs.compile()
|
||||||
|
])).map((output)=>(0, _guard.nullthrow)(output[0])));
|
||||||
|
await (0, _createfile.compareAndWriteFile)(span, output, _nodepath.default.resolve(_dir.OUTPUT_INTERNAL_DIR, 'appprofile.php'));
|
||||||
|
});
|
||||||
|
function generateAppProfile(directDomains, microsoftAppleDomains, streamDomains, steamDomains, globalDomains, lanDomains, directCidrs, streamCidrs, globalCidrs, lanCidrs) {
|
||||||
|
const redults = [
|
||||||
|
'<?php',
|
||||||
|
'',
|
||||||
|
`// # Build ${new Date().toISOString()}`,
|
||||||
|
'',
|
||||||
|
'declare(strict_types=1);',
|
||||||
|
'',
|
||||||
|
'$_ENV[\'Clash_Config\'] = [',
|
||||||
|
' \'port\' => 7890,',
|
||||||
|
' \'socks-port\' => 7891,',
|
||||||
|
' \'allow-lan\' => false,',
|
||||||
|
' \'mode\' => \'Rule\',',
|
||||||
|
' \'ipv6\' => true,',
|
||||||
|
' \'log-level\' => \'error\',',
|
||||||
|
' \'external-controller\' => \'0.0.0.0:9090\',',
|
||||||
|
' \'tun\' => [',
|
||||||
|
' \'enable\' => true,',
|
||||||
|
' \'stack\' => \'system\',',
|
||||||
|
' \'auto-route\' => true,',
|
||||||
|
' \'auto-redir\' => true,',
|
||||||
|
' \'auto-detect-interface\' => true,',
|
||||||
|
' \'dns-hijack\' => [',
|
||||||
|
' \'8.8.8.8:53\',',
|
||||||
|
' \'any:53\',',
|
||||||
|
' \'tcp://8.8.8.8:53\',',
|
||||||
|
' \'tcp://any:53\',',
|
||||||
|
' ]',
|
||||||
|
' ]',
|
||||||
|
'];',
|
||||||
|
'',
|
||||||
|
`$_ENV['Clash_Group_Indexes'] = [${JSON.stringify(POLICY_GROUPS.reduce((acc, [, insertProxy], index)=>{
|
||||||
|
if (insertProxy) {
|
||||||
|
acc.push(index);
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, [])).slice(1, -1)}];`,
|
||||||
|
'$_ENV[\'Clash_Group_Config\'] = [',
|
||||||
|
' \'proxy-groups\' => ['
|
||||||
|
];
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(redults, POLICY_GROUPS.flatMap(([name, insertProxy, insertDirect])=>[
|
||||||
|
' [',
|
||||||
|
` 'name' => '${name}',`,
|
||||||
|
' \'type\' => \'select\',',
|
||||||
|
' \'proxies\' => [',
|
||||||
|
insertProxy && name !== 'Default Proxy' && ' \'Default Proxy\',',
|
||||||
|
insertDirect && ' \'DIRECT\',',
|
||||||
|
' ],',
|
||||||
|
' ],'
|
||||||
|
].filter(_guard.isTruthy)));
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(redults, [
|
||||||
|
' ],',
|
||||||
|
' \'rules\' => ['
|
||||||
|
]);
|
||||||
|
// domestic - domains
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(redults, directDomains.map((line)=>` '${line},Domestic',`));
|
||||||
|
// microsoft & apple - domains
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(redults, microsoftAppleDomains.map((line)=>` '${line},Microsoft & Apple',`));
|
||||||
|
// stream - domains
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(redults, streamDomains.map((line)=>` '${line},Stream',`));
|
||||||
|
// steam download - domains
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(redults, steamDomains.map((line)=>` '${line},Steam Download',`));
|
||||||
|
// global - domains
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(redults, globalDomains.map((line)=>` '${line},Global',`));
|
||||||
|
// microsoft & apple - ip cidr (nope)
|
||||||
|
// lan - domains
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(redults, lanDomains.map((line)=>` '${line},DIRECT',`));
|
||||||
|
// stream - ip cidr
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(redults, streamCidrs.map((line)=>` '${line},Stream',`));
|
||||||
|
// global - ip cidr
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(redults, globalCidrs.map((line)=>` '${line},Global',`));
|
||||||
|
// domestic - ip cidr
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(redults, directCidrs.map((line)=>` '${line},Domestic',`));
|
||||||
|
// lan - ip cidr
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(redults, lanCidrs.map((line)=>` '${line},DIRECT',`));
|
||||||
|
// match
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(redults, [
|
||||||
|
' \'MATCH,Final Match\',',
|
||||||
|
' ],',
|
||||||
|
'];'
|
||||||
|
]);
|
||||||
|
return redults;
|
||||||
|
}
|
||||||
|
} (buildSspanelAppprofile.__module, buildSspanelAppprofile.__module.exports));
|
||||||
|
return buildSspanelAppprofile.__module.exports;
|
||||||
|
}exports.__require=requireBuildSspanelAppprofile;
|
||||||
2
Dist/Build/build-stream-service.cjs
Normal file
2
Dist/Build/build-stream-service.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildStreamService$1=require('./build-stream-service2.cjs');var buildStreamServiceExports = buildStreamService$1.__require();
|
||||||
|
const buildStreamService = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildStreamServiceExports);module.exports=buildStreamService;
|
||||||
48
Dist/Build/build-stream-service2.cjs
Normal file
48
Dist/Build/build-stream-service2.cjs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildStreamService=require('../_virtual/build-stream-service.cjs'),index=require('./trace/index.cjs'),stream=require('../Source/stream.cjs'),description=require('./constants/description.cjs'),ruleset=require('./lib/rules/ruleset.cjs');var hasRequiredBuildStreamService;
|
||||||
|
|
||||||
|
function requireBuildStreamService () {
|
||||||
|
if (hasRequiredBuildStreamService) return buildStreamService.__module.exports;
|
||||||
|
hasRequiredBuildStreamService = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "buildStreamService", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return buildStreamService;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _stream = /*@__PURE__*/ stream.__require();
|
||||||
|
const _description = /*@__PURE__*/ description.__require();
|
||||||
|
const _ruleset = /*@__PURE__*/ ruleset.__require();
|
||||||
|
function createRulesetForStreamService(span, fileId, title, streamServices) {
|
||||||
|
return [
|
||||||
|
// Domains
|
||||||
|
new _ruleset.RulesetOutput(span, fileId, 'non_ip').withTitle(`Sukka's Ruleset - Stream Services: ${title}`).withDescription([
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
...streamServices.map((i)=>`- ${i.name}`)
|
||||||
|
]).addFromRuleset(streamServices.flatMap((i)=>i.rules)).write(),
|
||||||
|
// IP
|
||||||
|
new _ruleset.RulesetOutput(span, fileId, 'ip').withTitle(`Sukka's Ruleset - Stream Services IPs: ${title}`).withDescription([
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
...streamServices.map((i)=>`- ${i.name}`)
|
||||||
|
]).bulkAddCIDR4NoResolve(streamServices.flatMap((i)=>i.ip?.v4 ?? [])).bulkAddCIDR6NoResolve(streamServices.flatMap((i)=>i.ip?.v6 ?? [])).write()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
const buildStreamService = (0, _trace.task)(require.main === module, __filename)(async (span)=>Promise.all([
|
||||||
|
createRulesetForStreamService(span, 'stream', 'All', _stream.ALL),
|
||||||
|
createRulesetForStreamService(span, 'stream_us', 'North America', _stream.NORTH_AMERICA),
|
||||||
|
createRulesetForStreamService(span, 'stream_eu', 'Europe', _stream.EU),
|
||||||
|
createRulesetForStreamService(span, 'stream_hk', 'Hong Kong', _stream.HK),
|
||||||
|
createRulesetForStreamService(span, 'stream_tw', 'Taiwan', _stream.TW),
|
||||||
|
createRulesetForStreamService(span, 'stream_jp', 'Japan', _stream.JP),
|
||||||
|
// createRulesetForStreamService('stream_au', 'Oceania', AU),
|
||||||
|
createRulesetForStreamService(span, 'stream_kr', 'Korean', _stream.KR)
|
||||||
|
].flat()));
|
||||||
|
} (buildStreamService.__module, buildStreamService.__module.exports));
|
||||||
|
return buildStreamService.__module.exports;
|
||||||
|
}exports.__require=requireBuildStreamService;
|
||||||
2
Dist/Build/build-telegram-cidr.cjs
Normal file
2
Dist/Build/build-telegram-cidr.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),buildTelegramCidr$1=require('./build-telegram-cidr2.cjs');var buildTelegramCidrExports = buildTelegramCidr$1.__require();
|
||||||
|
const buildTelegramCidr = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(buildTelegramCidrExports);module.exports=buildTelegramCidr;
|
||||||
69
Dist/Build/build-telegram-cidr2.cjs
Normal file
69
Dist/Build/build-telegram-cidr2.cjs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const buildTelegramCidr=require('../_virtual/build-telegram-cidr.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),index=require('./trace/index.cjs'),description=require('./constants/description.cjs'),memoPromise=require('./lib/memo-promise.cjs'),ruleset=require('./lib/rules/ruleset.cjs'),fetchRetry=require('./lib/fetch-retry.cjs'),misc=require('./lib/misc.cjs');var hasRequiredBuildTelegramCidr;
|
||||||
|
|
||||||
|
function requireBuildTelegramCidr () {
|
||||||
|
if (hasRequiredBuildTelegramCidr) return buildTelegramCidr.__module.exports;
|
||||||
|
hasRequiredBuildTelegramCidr = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
buildTelegramCIDR: function() {
|
||||||
|
return buildTelegramCIDR;
|
||||||
|
},
|
||||||
|
getTelegramCIDRPromise: function() {
|
||||||
|
return getTelegramCIDRPromise;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _description = /*@__PURE__*/ description.__require();
|
||||||
|
const _memopromise = /*@__PURE__*/ memoPromise.__require();
|
||||||
|
const _ruleset = /*@__PURE__*/ ruleset.__require();
|
||||||
|
const _fetchretry = /*@__PURE__*/ fetchRetry.__require();
|
||||||
|
const _misc = /*@__PURE__*/ misc.__require();
|
||||||
|
const getTelegramCIDRPromise = (0, _memopromise.createMemoizedPromise)(async ()=>{
|
||||||
|
const resp = await (0, _fetchretry.$$fetch)('https://core.telegram.org/resources/cidr.txt');
|
||||||
|
const lastModified = resp.headers.get('last-modified');
|
||||||
|
const date = lastModified ? new Date(lastModified) : new Date();
|
||||||
|
const ipcidr = [
|
||||||
|
// Telegram secret backup CIDR, announced by AS62041
|
||||||
|
// see also https://github.com/Telegram-FOSS-Team/Telegram-FOSS/blob/10da5406ed92d30c6add3b25d40b2b3b6995d873/TMessagesProj/src/main/java/org/telegram/tgnet/ConnectionsManager.java#L1157
|
||||||
|
'95.161.64.0/20'
|
||||||
|
];
|
||||||
|
const ipcidr6 = [];
|
||||||
|
for await (const cidr of (0, _fetchtextbyline.createReadlineInterfaceFromResponse)(resp, true)){
|
||||||
|
const v = (0, _misc.fastIpVersion)(cidr);
|
||||||
|
if (v === 4) {
|
||||||
|
ipcidr.push(cidr);
|
||||||
|
} else if (v === 6) {
|
||||||
|
ipcidr6.push(cidr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
date,
|
||||||
|
ipcidr,
|
||||||
|
ipcidr6
|
||||||
|
};
|
||||||
|
});
|
||||||
|
const buildTelegramCIDR = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const { date, ipcidr, ipcidr6 } = await span.traceChildAsync('get telegram cidr', getTelegramCIDRPromise);
|
||||||
|
if (ipcidr.length + ipcidr6.length === 0) {
|
||||||
|
throw new Error('Failed to fetch data!');
|
||||||
|
}
|
||||||
|
const description = [
|
||||||
|
..._description.SHARED_DESCRIPTION,
|
||||||
|
'Data from:',
|
||||||
|
' - https://core.telegram.org/resources/cidr.txt'
|
||||||
|
];
|
||||||
|
return new _ruleset.RulesetOutput(span, 'telegram', 'ip').withTitle('Sukka\'s Ruleset - Telegram IP CIDR').withDescription(description).withDate(date).bulkAddCIDR4NoResolve(ipcidr).bulkAddCIDR6NoResolve(ipcidr6).write();
|
||||||
|
});
|
||||||
|
} (buildTelegramCidr.__module, buildTelegramCidr.__module.exports));
|
||||||
|
return buildTelegramCidr.__module.exports;
|
||||||
|
}exports.__require=requireBuildTelegramCidr;
|
||||||
92
Dist/Build/constants/cidr.cjs
Normal file
92
Dist/Build/constants/cidr.cjs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const cidr=require('../../_virtual/cidr.cjs');var hasRequiredCidr;
|
||||||
|
|
||||||
|
function requireCidr () {
|
||||||
|
if (hasRequiredCidr) return cidr.__exports;
|
||||||
|
hasRequiredCidr = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
CN_CIDR_MISSING_IN_CHNROUTE: function() {
|
||||||
|
return CN_CIDR_MISSING_IN_CHNROUTE;
|
||||||
|
},
|
||||||
|
NON_CN_CIDR_INCLUDED_IN_CHNROUTE: function() {
|
||||||
|
return NON_CN_CIDR_INCLUDED_IN_CHNROUTE;
|
||||||
|
},
|
||||||
|
RESERVED_IPV4_CIDR: function() {
|
||||||
|
return RESERVED_IPV4_CIDR;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const RESERVED_IPV4_CIDR = [
|
||||||
|
'0.0.0.0/8',
|
||||||
|
'10.0.0.0/8',
|
||||||
|
'100.64.0.0/10',
|
||||||
|
'127.0.0.0/8',
|
||||||
|
'169.254.0.0/16',
|
||||||
|
'172.16.0.0/12',
|
||||||
|
'192.0.0.0/24',
|
||||||
|
'192.0.2.0/24',
|
||||||
|
// 192.88.99.0 // is currently being broadcast by HE and Comcast
|
||||||
|
'192.168.0.0/16',
|
||||||
|
'198.18.0.0/15',
|
||||||
|
'198.51.100.0/24',
|
||||||
|
'203.0.113.0/24',
|
||||||
|
'224.0.0.0/4',
|
||||||
|
'233.252.0.0/24',
|
||||||
|
'240.0.0.0/4'
|
||||||
|
];
|
||||||
|
const NON_CN_CIDR_INCLUDED_IN_CHNROUTE = [
|
||||||
|
'223.118.0.0/15',
|
||||||
|
'223.120.0.0/15'
|
||||||
|
];
|
||||||
|
const CN_CIDR_MISSING_IN_CHNROUTE = [
|
||||||
|
// Baidu Public DNS
|
||||||
|
'180.76.76.0/24',
|
||||||
|
// Ali Public DNS
|
||||||
|
'223.5.5.0/24',
|
||||||
|
'223.6.6.0/24',
|
||||||
|
// Tencent DNSPod Public DNS
|
||||||
|
'119.29.29.0/24',
|
||||||
|
'119.28.28.0/24',
|
||||||
|
'120.53.53.0/24',
|
||||||
|
'1.12.12.0/24',
|
||||||
|
'1.12.34.0/24',
|
||||||
|
// ByteDance Public DNS
|
||||||
|
'180.184.1.0/24',
|
||||||
|
'180.184.2.0/24',
|
||||||
|
// 360 Public DNS
|
||||||
|
'101.198.198.0/24',
|
||||||
|
'101.198.199.0/24',
|
||||||
|
// ChinaTelecom
|
||||||
|
'103.7.141.0/24',
|
||||||
|
// Aliyun Shenzhen
|
||||||
|
'120.78.0.0/16',
|
||||||
|
// wy.com.cn
|
||||||
|
'211.99.96.0/19',
|
||||||
|
// AS58593, Azure China
|
||||||
|
'40.72.0.0/15',
|
||||||
|
'42.159.0.0/16',
|
||||||
|
'52.130.0.0/17',
|
||||||
|
'52.131.0.0/16',
|
||||||
|
'103.9.8.0/22',
|
||||||
|
'139.217.0.0/16',
|
||||||
|
'139.219.0.0/16',
|
||||||
|
'143.64.0.0/16',
|
||||||
|
'159.27.0.0/16',
|
||||||
|
'163.228.0.0/16',
|
||||||
|
// NetEase
|
||||||
|
'223.252.194.0/24',
|
||||||
|
'223.252.196.0/24',
|
||||||
|
// Xiamen Kuaikuai
|
||||||
|
'180.188.36.0/22' // no route globally
|
||||||
|
];
|
||||||
|
} (cidr.__exports));
|
||||||
|
return cidr.__exports;
|
||||||
|
}exports.__require=requireCidr;
|
||||||
34
Dist/Build/constants/description.cjs
Normal file
34
Dist/Build/constants/description.cjs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const description=require('../../_virtual/description.cjs');var hasRequiredDescription;
|
||||||
|
|
||||||
|
function requireDescription () {
|
||||||
|
if (hasRequiredDescription) return description.__exports;
|
||||||
|
hasRequiredDescription = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
SHARED_DESCRIPTION: function() {
|
||||||
|
return SHARED_DESCRIPTION;
|
||||||
|
},
|
||||||
|
createFileDescription: function() {
|
||||||
|
return createFileDescription;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
function createFileDescription(license = 'AGPL 3.0') {
|
||||||
|
return [
|
||||||
|
`License: ${license}`,
|
||||||
|
'Homepage: https://ruleset.skk.moe',
|
||||||
|
'GitHub: https://github.com/SukkaW/Surge'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
const SHARED_DESCRIPTION = createFileDescription('AGPL 3.0');
|
||||||
|
} (description.__exports));
|
||||||
|
return description.__exports;
|
||||||
|
}exports.__require=requireDescription;
|
||||||
71
Dist/Build/constants/dir.cjs
Normal file
71
Dist/Build/constants/dir.cjs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const dir=require('../../_virtual/dir.cjs'),require$$0=require('node:path'),require$$1=require('node:process');var hasRequiredDir;
|
||||||
|
|
||||||
|
function requireDir () {
|
||||||
|
if (hasRequiredDir) return dir.__exports;
|
||||||
|
hasRequiredDir = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
CACHE_DIR: function() {
|
||||||
|
return CACHE_DIR;
|
||||||
|
},
|
||||||
|
OUTPUT_CLASH_DIR: function() {
|
||||||
|
return OUTPUT_CLASH_DIR;
|
||||||
|
},
|
||||||
|
OUTPUT_INTERNAL_DIR: function() {
|
||||||
|
return OUTPUT_INTERNAL_DIR;
|
||||||
|
},
|
||||||
|
OUTPUT_MOCK_DIR: function() {
|
||||||
|
return OUTPUT_MOCK_DIR;
|
||||||
|
},
|
||||||
|
OUTPUT_MODULES_DIR: function() {
|
||||||
|
return OUTPUT_MODULES_DIR;
|
||||||
|
},
|
||||||
|
OUTPUT_MODULES_RULES_DIR: function() {
|
||||||
|
return OUTPUT_MODULES_RULES_DIR;
|
||||||
|
},
|
||||||
|
OUTPUT_SINGBOX_DIR: function() {
|
||||||
|
return OUTPUT_SINGBOX_DIR;
|
||||||
|
},
|
||||||
|
OUTPUT_SURGE_DIR: function() {
|
||||||
|
return OUTPUT_SURGE_DIR;
|
||||||
|
},
|
||||||
|
PUBLIC_DIR: function() {
|
||||||
|
return PUBLIC_DIR;
|
||||||
|
},
|
||||||
|
ROOT_DIR: function() {
|
||||||
|
return ROOT_DIR;
|
||||||
|
},
|
||||||
|
SOURCE_DIR: function() {
|
||||||
|
return SOURCE_DIR;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1);
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const ROOT_DIR = _nodepath.default.resolve(__dirname, '../..');
|
||||||
|
const CACHE_DIR = _nodepath.default.resolve(ROOT_DIR, '.cache');
|
||||||
|
const SOURCE_DIR = _nodepath.default.join(ROOT_DIR, 'Source');
|
||||||
|
const PUBLIC_DIR = _nodeprocess.default.env.PUBLIC_DIR || _nodepath.default.resolve(ROOT_DIR, 'public');
|
||||||
|
const OUTPUT_SURGE_DIR = _nodepath.default.join(PUBLIC_DIR, 'List');
|
||||||
|
const OUTPUT_CLASH_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'Clash');
|
||||||
|
const OUTPUT_SINGBOX_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'sing-box');
|
||||||
|
const OUTPUT_MODULES_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'Modules');
|
||||||
|
const OUTPUT_MODULES_RULES_DIR = _nodepath.default.resolve(OUTPUT_MODULES_DIR, 'Rules');
|
||||||
|
const OUTPUT_INTERNAL_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'Internal');
|
||||||
|
const OUTPUT_MOCK_DIR = _nodepath.default.resolve(PUBLIC_DIR, 'Mock');
|
||||||
|
} (dir.__exports));
|
||||||
|
return dir.__exports;
|
||||||
|
}exports.__require=requireDir;
|
||||||
148
Dist/Build/constants/domains.cjs
Normal file
148
Dist/Build/constants/domains.cjs
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const domains=require('../../_virtual/domains.cjs');var hasRequiredDomains;
|
||||||
|
|
||||||
|
function requireDomains () {
|
||||||
|
if (hasRequiredDomains) return domains.__exports;
|
||||||
|
hasRequiredDomains = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "ICP_TLD", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return ICP_TLD;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const ICP_TLD = [
|
||||||
|
'ren',
|
||||||
|
'wang',
|
||||||
|
'citic',
|
||||||
|
'top',
|
||||||
|
'sohu',
|
||||||
|
'xin',
|
||||||
|
'com',
|
||||||
|
'net',
|
||||||
|
'club',
|
||||||
|
'xyz',
|
||||||
|
'site',
|
||||||
|
'shop',
|
||||||
|
'info',
|
||||||
|
'mobi',
|
||||||
|
'red',
|
||||||
|
'pro',
|
||||||
|
'kim',
|
||||||
|
'ltd',
|
||||||
|
'group',
|
||||||
|
'biz',
|
||||||
|
'link',
|
||||||
|
'store',
|
||||||
|
'tech',
|
||||||
|
'fun',
|
||||||
|
'online',
|
||||||
|
'art',
|
||||||
|
'design',
|
||||||
|
'love',
|
||||||
|
'center',
|
||||||
|
'video',
|
||||||
|
'social',
|
||||||
|
'team',
|
||||||
|
'show',
|
||||||
|
'cool',
|
||||||
|
'zone',
|
||||||
|
'world',
|
||||||
|
'today',
|
||||||
|
'city',
|
||||||
|
'chat',
|
||||||
|
'company',
|
||||||
|
'live',
|
||||||
|
'fund',
|
||||||
|
'gold',
|
||||||
|
'plus',
|
||||||
|
'guru',
|
||||||
|
'run',
|
||||||
|
'pub',
|
||||||
|
'email',
|
||||||
|
'life',
|
||||||
|
'co',
|
||||||
|
'baidu',
|
||||||
|
'cloud',
|
||||||
|
'host',
|
||||||
|
'space',
|
||||||
|
'press',
|
||||||
|
'website',
|
||||||
|
'archi',
|
||||||
|
'asia',
|
||||||
|
'bio',
|
||||||
|
'black',
|
||||||
|
'blue',
|
||||||
|
'green',
|
||||||
|
'lotto',
|
||||||
|
'organic',
|
||||||
|
'pet',
|
||||||
|
'pink',
|
||||||
|
'poker',
|
||||||
|
'promo',
|
||||||
|
'ski',
|
||||||
|
'vote',
|
||||||
|
'voto',
|
||||||
|
'icu',
|
||||||
|
'fans',
|
||||||
|
'unicom',
|
||||||
|
'jpmorgan',
|
||||||
|
'chase',
|
||||||
|
'cc',
|
||||||
|
'band',
|
||||||
|
'cab',
|
||||||
|
'cafe',
|
||||||
|
'cash',
|
||||||
|
'fan',
|
||||||
|
'fyi',
|
||||||
|
'games',
|
||||||
|
'market',
|
||||||
|
'mba',
|
||||||
|
'news',
|
||||||
|
'media',
|
||||||
|
'sale',
|
||||||
|
'shopping',
|
||||||
|
'studio',
|
||||||
|
'tax',
|
||||||
|
'technology',
|
||||||
|
'vin',
|
||||||
|
'baby',
|
||||||
|
'college',
|
||||||
|
'monster',
|
||||||
|
'protection',
|
||||||
|
'rent',
|
||||||
|
'security',
|
||||||
|
'storage',
|
||||||
|
'theatre',
|
||||||
|
'bond',
|
||||||
|
'cyou',
|
||||||
|
'uno',
|
||||||
|
'school',
|
||||||
|
'global',
|
||||||
|
'me',
|
||||||
|
'pw',
|
||||||
|
'hk',
|
||||||
|
'tv',
|
||||||
|
'saxo',
|
||||||
|
'click',
|
||||||
|
'auto',
|
||||||
|
'autos',
|
||||||
|
'beauty',
|
||||||
|
'boats',
|
||||||
|
'car',
|
||||||
|
'cars',
|
||||||
|
'hair',
|
||||||
|
'homes',
|
||||||
|
'makeup',
|
||||||
|
'motorcycles',
|
||||||
|
'quest',
|
||||||
|
'skin',
|
||||||
|
'tickets',
|
||||||
|
'yachts',
|
||||||
|
'kids'
|
||||||
|
];
|
||||||
|
} (domains.__exports));
|
||||||
|
return domains.__exports;
|
||||||
|
}exports.__require=requireDomains;
|
||||||
47
Dist/Build/constants/loose-tldts-opt.cjs
Normal file
47
Dist/Build/constants/loose-tldts-opt.cjs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const looseTldtsOpt=require('../../_virtual/loose-tldts-opt.cjs');var hasRequiredLooseTldtsOpt;
|
||||||
|
|
||||||
|
function requireLooseTldtsOpt () {
|
||||||
|
if (hasRequiredLooseTldtsOpt) return looseTldtsOpt.__exports;
|
||||||
|
hasRequiredLooseTldtsOpt = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
loosTldOptWithPrivateDomains: function() {
|
||||||
|
return loosTldOptWithPrivateDomains;
|
||||||
|
},
|
||||||
|
looseTldtsOpt: function() {
|
||||||
|
return looseTldtsOpt;
|
||||||
|
},
|
||||||
|
normalizeTldtsOpt: function() {
|
||||||
|
return normalizeTldtsOpt;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const looseTldtsOpt = {
|
||||||
|
allowPrivateDomains: false,
|
||||||
|
extractHostname: false,
|
||||||
|
validateHostname: false,
|
||||||
|
detectIp: false,
|
||||||
|
mixedInputs: false
|
||||||
|
};
|
||||||
|
const loosTldOptWithPrivateDomains = {
|
||||||
|
...looseTldtsOpt,
|
||||||
|
allowPrivateDomains: true
|
||||||
|
};
|
||||||
|
const normalizeTldtsOpt = {
|
||||||
|
allowPrivateDomains: true,
|
||||||
|
// in normalizeDomain, we only care if it contains IP, we don't care if we need to extract it
|
||||||
|
// by setting detectIp to false and manually check ip outside tldts.parse, we can skip the tldts
|
||||||
|
// inner "extractHostname" call
|
||||||
|
detectIp: false
|
||||||
|
};
|
||||||
|
} (looseTldtsOpt.__exports));
|
||||||
|
return looseTldtsOpt.__exports;
|
||||||
|
}exports.__require=requireLooseTldtsOpt;
|
||||||
584
Dist/Build/constants/reject-data-source.cjs
Normal file
584
Dist/Build/constants/reject-data-source.cjs
Normal file
@ -0,0 +1,584 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const rejectDataSource=require('../../_virtual/reject-data-source.cjs');var hasRequiredRejectDataSource;
|
||||||
|
|
||||||
|
function requireRejectDataSource () {
|
||||||
|
if (hasRequiredRejectDataSource) return rejectDataSource.__exports;
|
||||||
|
hasRequiredRejectDataSource = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
ADGUARD_FILTERS: function() {
|
||||||
|
return ADGUARD_FILTERS;
|
||||||
|
},
|
||||||
|
ADGUARD_FILTERS_EXTRA: function() {
|
||||||
|
return ADGUARD_FILTERS_EXTRA;
|
||||||
|
},
|
||||||
|
ADGUARD_FILTERS_WHITELIST: function() {
|
||||||
|
return ADGUARD_FILTERS_WHITELIST;
|
||||||
|
},
|
||||||
|
CRASHLYTICS_WHITELIST: function() {
|
||||||
|
return CRASHLYTICS_WHITELIST;
|
||||||
|
},
|
||||||
|
DEBUG_DOMAIN_TO_FIND: function() {
|
||||||
|
return DEBUG_DOMAIN_TO_FIND;
|
||||||
|
},
|
||||||
|
DOMAIN_LISTS: function() {
|
||||||
|
return DOMAIN_LISTS;
|
||||||
|
},
|
||||||
|
DOMAIN_LISTS_EXTRA: function() {
|
||||||
|
return DOMAIN_LISTS_EXTRA;
|
||||||
|
},
|
||||||
|
HOSTS: function() {
|
||||||
|
return HOSTS;
|
||||||
|
},
|
||||||
|
HOSTS_EXTRA: function() {
|
||||||
|
return HOSTS_EXTRA;
|
||||||
|
},
|
||||||
|
PHISHING_DOMAIN_LISTS_EXTRA: function() {
|
||||||
|
return PHISHING_DOMAIN_LISTS_EXTRA;
|
||||||
|
},
|
||||||
|
PHISHING_HOSTS_EXTRA: function() {
|
||||||
|
return PHISHING_HOSTS_EXTRA;
|
||||||
|
},
|
||||||
|
PREDEFINED_WHITELIST: function() {
|
||||||
|
return PREDEFINED_WHITELIST;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const DEBUG_DOMAIN_TO_FIND = null; // example.com | null
|
||||||
|
const HOSTS = [
|
||||||
|
[
|
||||||
|
// WindowsSpyBlocker hasn't been updated since 2022-06-16, let's use jsDelivr as primary URL
|
||||||
|
'https://cdn.jsdelivr.net/gh/crazy-max/WindowsSpyBlocker@master/data/hosts/spy.txt',
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt'
|
||||||
|
],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/jerryn70/GoodbyeAds/master/Extension/GoodbyeAds-Xiaomi-Extension.txt',
|
||||||
|
null,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/jerryn70/GoodbyeAds/master/Extension/GoodbyeAds-Huawei-AdBlock.txt',
|
||||||
|
null,
|
||||||
|
false
|
||||||
|
]
|
||||||
|
];
|
||||||
|
const HOSTS_EXTRA = [
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/durablenapkin/block/master/tvstream.txt',
|
||||||
|
null,
|
||||||
|
true
|
||||||
|
],
|
||||||
|
// This stupid hosts blocks t.co, so we determine that this is also bullshit, so it is extra
|
||||||
|
[
|
||||||
|
'https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext',
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/thirdparties/pgl.yoyo.org/as/serverlist'
|
||||||
|
],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
// Dan Pollock's hosts file, 0.0.0.0 version is 30 KiB smaller
|
||||||
|
[
|
||||||
|
'https://someonewhocares.org/hosts/zero/hosts',
|
||||||
|
[
|
||||||
|
'https://proxy.cdn.skk.moe/https/someonewhocares.org/hosts/zero/hosts'
|
||||||
|
],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
// ad-wars is not actively maintained since 2023.11, so we use jsDelivr as primary URL
|
||||||
|
[
|
||||||
|
'https://cdn.jsdelivr.net/gh/jdlingyu/ad-wars@master/hosts',
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/jdlingyu/ad-wars/master/hosts'
|
||||||
|
],
|
||||||
|
false
|
||||||
|
]
|
||||||
|
];
|
||||||
|
const DOMAIN_LISTS = [];
|
||||||
|
const DOMAIN_LISTS_EXTRA = [
|
||||||
|
// CoinBlockerList - Full
|
||||||
|
// The CoinBlockerList is no longer maintained and even close-source, so we no longer trust it
|
||||||
|
// instead we maintain a list of our own
|
||||||
|
// BarbBlock
|
||||||
|
// The barbblock list has never been updated since 2019-05, so we set a 14 days cache ttl
|
||||||
|
[
|
||||||
|
'https://paulgb.github.io/BarbBlock/blacklists/domain-list.txt',
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/paulgb/BarbBlock/refs/heads/main/blacklists/domain-list.txt'
|
||||||
|
],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
// DigitalSide Threat-Intel - OSINT Hub
|
||||||
|
// Update once per day
|
||||||
|
[
|
||||||
|
'https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt',
|
||||||
|
[],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
// AdGuard CNAME Filter Combined
|
||||||
|
// Update on a 7 days basis, so we can also use jsDelivr as primary URL
|
||||||
|
[
|
||||||
|
'https://cdn.jsdelivr.net/gh/AdguardTeam/cname-trackers@master/data/combined_disguised_ads_justdomains.txt',
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_ads_justdomains.txt'
|
||||||
|
],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://cdn.jsdelivr.net/gh/AdguardTeam/cname-trackers@master/data/combined_disguised_trackers_justdomains.txt',
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_trackers_justdomains.txt'
|
||||||
|
],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://cdn.jsdelivr.net/gh/AdguardTeam/cname-trackers@master/data/combined_disguised_clickthroughs_justdomains.txt',
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_clickthroughs_justdomains.txt'
|
||||||
|
],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://cdn.jsdelivr.net/gh/AdguardTeam/cname-trackers@master/data/combined_disguised_microsites_justdomains.txt',
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_microsites_justdomains.txt'
|
||||||
|
],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
// ['https://raw.githubusercontent.com/AdguardTeam/cname-trackers/master/data/combined_disguised_mail_trackers_justdomains.txt', [], true],
|
||||||
|
// Curben's PUP Domains Blocklist
|
||||||
|
// The PUP filter has paused the update since 2023-05, so we set a 14 days cache ttl, and move it to extra
|
||||||
|
// [
|
||||||
|
// 'https://pup-filter.pages.dev/pup-filter-domains.txt',
|
||||||
|
// [
|
||||||
|
// // 'https://malware-filter.pages.dev/pup-filter-domains.txt',
|
||||||
|
// // 'https://malware-filter.gitlab.io/malware-filter/pup-filter-domains.txt',
|
||||||
|
// 'https://malware-filter.gitlab.io/pup-filter/pup-filter-domains.txt'
|
||||||
|
// // 'https://curbengh.github.io/pup-filter/pup-filter-domains.txt',
|
||||||
|
// // 'https://malware-filter.pages.dev/pup-filter-domains.txt'
|
||||||
|
// ],
|
||||||
|
// true
|
||||||
|
// ],
|
||||||
|
// Curben's UrlHaus Malicious URL Blocklist
|
||||||
|
[
|
||||||
|
'https://urlhaus-filter.pages.dev/urlhaus-filter-domains.txt',
|
||||||
|
[
|
||||||
|
'https://malware-filter.pages.dev/urlhaus-filter-domains.txt',
|
||||||
|
'https://malware-filter.gitlab.io/urlhaus-filter/urlhaus-filter-domains.txt',
|
||||||
|
'https://malware-filter.gitlab.io/malware-filter/urlhaus-filter-domains.txt',
|
||||||
|
'https://curbengh.github.io/urlhaus-filter/urlhaus-filter-domains.txt'
|
||||||
|
],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
// Spam404
|
||||||
|
// Not actively maintained, let's use jsDelivr as primary URL
|
||||||
|
[
|
||||||
|
'https://cdn.jsdelivr.net/gh/Spam404/lists@master/main-blacklist.txt',
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt'
|
||||||
|
],
|
||||||
|
true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
const PHISHING_HOSTS_EXTRA = [
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/durablenapkin/scamblocklist/master/hosts.txt',
|
||||||
|
[],
|
||||||
|
true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
const PHISHING_DOMAIN_LISTS_EXTRA = [
|
||||||
|
[
|
||||||
|
'https://phishing-filter.pages.dev/phishing-filter-domains.txt',
|
||||||
|
[
|
||||||
|
'https://malware-filter.pages.dev/phishing-filter-domains.txt',
|
||||||
|
'https://malware-filter.gitlab.io/phishing-filter/phishing-filter-domains.txt',
|
||||||
|
'https://malware-filter.gitlab.io/malware-filter/phishing-filter-domains.txt',
|
||||||
|
'https://curbengh.github.io/phishing-filter/phishing-filter-domains.txt'
|
||||||
|
],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://phishing.army/download/phishing_army_blocklist.txt',
|
||||||
|
[],
|
||||||
|
true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
const ADGUARD_FILTERS = [
|
||||||
|
// EasyList
|
||||||
|
[
|
||||||
|
'https://easylist.to/easylist/easylist.txt',
|
||||||
|
[
|
||||||
|
'https://easylist-downloads.adblockplus.org/easylist.txt',
|
||||||
|
'https://secure.fanboy.co.nz/easylist.txt',
|
||||||
|
'https://ublockorigin.github.io/uAssetsCDN/thirdparties/easylist.txt',
|
||||||
|
'https://ublockorigin.pages.dev/thirdparties/easylist.txt',
|
||||||
|
'https://raw.githubusercontent.com/easylist/easylist/gh-pages/easylist.txt',
|
||||||
|
'https://filters.adtidy.org/extension/ublock/filters/101_optimized.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// EasyPrivacy
|
||||||
|
[
|
||||||
|
'https://easylist.to/easylist/easyprivacy.txt',
|
||||||
|
[
|
||||||
|
'https://easylist-downloads.adblockplus.org/easyprivacy.txt',
|
||||||
|
'https://secure.fanboy.co.nz/easyprivacy.txt',
|
||||||
|
'https://ublockorigin.github.io/uAssetsCDN/thirdparties/easyprivacy.txt',
|
||||||
|
'https://ublockorigin.pages.dev/thirdparties/easyprivacy.txt',
|
||||||
|
'https://raw.githubusercontent.com/easylist/easylist/gh-pages/easyprivacy.txt',
|
||||||
|
'https://filters.adtidy.org/extension/ublock/filters/118_optimized.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// AdGuard Base Filter
|
||||||
|
[
|
||||||
|
'https://filters.adtidy.org/extension/ublock/filters/2_without_easylist.txt',
|
||||||
|
[
|
||||||
|
'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/2_without_easylist.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// AdGuard Mobile AD
|
||||||
|
[
|
||||||
|
'https://filters.adtidy.org/extension/ublock/filters/11_optimized.txt',
|
||||||
|
[
|
||||||
|
'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/2_without_easylist.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// AdGuard Tracking Protection
|
||||||
|
[
|
||||||
|
'https://filters.adtidy.org/extension/ublock/filters/3_optimized.txt',
|
||||||
|
[
|
||||||
|
'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/3_optimized.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// AdGuard Chinese filter (EasyList China + AdGuard Chinese filter)
|
||||||
|
[
|
||||||
|
'https://filters.adtidy.org/extension/ublock/filters/224_optimized.txt',
|
||||||
|
[
|
||||||
|
'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/224_optimized.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// GameConsoleAdblockList
|
||||||
|
// Update almost once per 1 to 3 months, let's set a 10 days cache ttl
|
||||||
|
[
|
||||||
|
'https://cdn.jsdelivr.net/gh/DandelionSprout/adfilt@master/GameConsoleAdblockList.txt',
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/DandelionSprout/adfilt/master/GameConsoleAdblockList.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// PiHoleBlocklist
|
||||||
|
// Update almost once per 3 months, let's set a 10 days cache ttl
|
||||||
|
[
|
||||||
|
'https://perflyst.github.io/PiHoleBlocklist/SmartTV-AGH.txt',
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/SmartTV-AGH.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// uBlock Origin Unbreak
|
||||||
|
[
|
||||||
|
'https://ublockorigin.github.io/uAssetsCDN/filters/unbreak.min.txt',
|
||||||
|
[
|
||||||
|
'https://ublockorigin.pages.dev/filters/unbreak.min.txt'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
const ADGUARD_FILTERS_WHITELIST = [
|
||||||
|
[
|
||||||
|
'https://adguardteam.github.io/AdGuardSDNSFilter/Filters/exceptions.txt',
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/Filters/exceptions.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://adguardteam.github.io/AdGuardSDNSFilter/Filters/exclusions.txt',
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/Filters/exclusions.txt'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
const ADGUARD_FILTERS_EXTRA = [
|
||||||
|
// AdGuard DNS Filter
|
||||||
|
// way too many other countries' domains (JP, Spanish, RU, VN, Turkish, Ukarainian, Dutch, etc.)
|
||||||
|
// EasyList, EasyPrivacy, Chinese and general filters are already included in base data source
|
||||||
|
[
|
||||||
|
'https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt',
|
||||||
|
[
|
||||||
|
'https://filters.adtidy.org/extension/ublock/filters/15_optimized.txt',
|
||||||
|
'https://adguardteam.github.io/HostlistsRegistry/assets/filter_1.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// no coin list adguard list is more maintained than its hosts
|
||||||
|
[
|
||||||
|
'https://raw.githubusercontent.com/hoshsadiq/adblock-nocoin-list/master/nocoin.txt',
|
||||||
|
[],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
// AdGuard Annoyances filter
|
||||||
|
[
|
||||||
|
'https://filters.adtidy.org/extension/ublock/filters/14_optimized.txt',
|
||||||
|
[
|
||||||
|
'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/14_optimized.txt'
|
||||||
|
],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
// AdGuard Cookie Notices, included in Annoyances filter
|
||||||
|
// ['https://filters.adtidy.org/extension/ublock/filters/18_optimized.txt', null, true],
|
||||||
|
// EasyList Germany filter, not even included in extra for now
|
||||||
|
// [
|
||||||
|
// 'https://easylist.to/easylistgermany/easylistgermany.txt',
|
||||||
|
// [
|
||||||
|
// 'https://easylist-downloads.adblockplus.org/easylistgermany.txt'
|
||||||
|
// ],
|
||||||
|
//
|
||||||
|
// ],
|
||||||
|
// AdGuard Japanese filter
|
||||||
|
[
|
||||||
|
'https://filters.adtidy.org/extension/ublock/filters/7_optimized.txt',
|
||||||
|
[
|
||||||
|
'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/7_optimized.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// uBlock Origin Filter List
|
||||||
|
[
|
||||||
|
'https://ublockorigin.github.io/uAssetsCDN/filters/filters.min.txt',
|
||||||
|
[
|
||||||
|
'https://ublockorigin.pages.dev/filters/filters.min.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// AdGuard Popup Overlay - included in Annoyances filter
|
||||||
|
// ['https://filters.adtidy.org/extension/ublock/filters/19_optimized.txt', null, true],
|
||||||
|
// AdGuard Mobile Banner
|
||||||
|
// almost all generic rule
|
||||||
|
// ['https://filters.adtidy.org/extension/ublock/filters/20_optimized.txt', null],
|
||||||
|
// uBlock Origin Badware Risk List
|
||||||
|
[
|
||||||
|
'https://ublockorigin.github.io/uAssetsCDN/filters/badware.min.txt',
|
||||||
|
[
|
||||||
|
'https://ublockorigin.pages.dev/filters/badware.min.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// uBlock Origin Privacy List
|
||||||
|
[
|
||||||
|
'https://ublockorigin.github.io/uAssetsCDN/filters/privacy.min.txt',
|
||||||
|
[
|
||||||
|
'https://ublockorigin.pages.dev/filters/privacy.min.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// uBlock Origin Resource Abuse: merged in uBlock Origin Privacy List
|
||||||
|
// [
|
||||||
|
// 'https://ublockorigin.github.io/uAssetsCDN/filters/resource-abuse.txt',
|
||||||
|
// ['https://ublockorigin.pages.dev/filters/resource-abuse.txt']
|
||||||
|
// ],
|
||||||
|
// uBlock Origin Annoyances (the un-merged of Fanboy Annoyances List)
|
||||||
|
[
|
||||||
|
'https://ublockorigin.github.io/uAssetsCDN/filters/annoyances.min.txt',
|
||||||
|
[
|
||||||
|
'https://ublockorigin.pages.dev/filters/annoyances.min.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// EasyList Annoyances
|
||||||
|
[
|
||||||
|
'https://ublockorigin.github.io/uAssetsCDN/thirdparties/easylist-annoyances.txt',
|
||||||
|
[
|
||||||
|
'https://ublockorigin.pages.dev/thirdparties/easylist-annoyances.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// EasyList - Newsletters
|
||||||
|
[
|
||||||
|
'https://ublockorigin.github.io/uAssetsCDN/thirdparties/easylist-newsletters.txt',
|
||||||
|
[
|
||||||
|
'https://ublockorigin.pages.dev/thirdparties/easylist-newsletters.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// EasyList - Notifications
|
||||||
|
[
|
||||||
|
'https://ublockorigin.github.io/uAssets/thirdparties/easylist-notifications.txt',
|
||||||
|
[
|
||||||
|
'https://ublockorigin.pages.dev/thirdparties/easylist-notifications.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// Fanboy Cookie Monster (EasyList Cookie List)
|
||||||
|
[
|
||||||
|
'https://ublockorigin.github.io/uAssets/thirdparties/easylist-cookies.txt',
|
||||||
|
[
|
||||||
|
'https://ublockorigin.pages.dev/thirdparties/easylist-cookies.txt',
|
||||||
|
'https://secure.fanboy.co.nz/fanboy-cookiemonster_ubo.txt'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// Dandelion Sprout's Annoyances
|
||||||
|
[
|
||||||
|
'https://filters.adtidy.org/extension/ublock/filters/250_optimized.txt',
|
||||||
|
[
|
||||||
|
'https://proxy.cdn.skk.moe/https/filters.adtidy.org/extension/ublock/filters/250_optimized.txt'
|
||||||
|
],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
// Adblock Warning Removal List
|
||||||
|
[
|
||||||
|
'https://easylist-downloads.adblockplus.org/antiadblockfilters.txt',
|
||||||
|
[
|
||||||
|
'https://filters.adtidy.org/extension/ublock/filters/207_optimized.txt'
|
||||||
|
],
|
||||||
|
true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
const CRASHLYTICS_WHITELIST = [
|
||||||
|
// VSCode Telemetry, see https://sts.online.visualstudio.com/api/swagger/index.html
|
||||||
|
'sts.online.visualstudio.com',
|
||||||
|
// Sentry
|
||||||
|
'.ingest.sentry.io',
|
||||||
|
'.ingest.us.sentry.io',
|
||||||
|
'.ingest.de.sentry.io',
|
||||||
|
// bugsnag
|
||||||
|
'.sessions.bugsnag.com',
|
||||||
|
'.notify.bugsnag.com',
|
||||||
|
// influxdata
|
||||||
|
'.cloud.influxdata.com',
|
||||||
|
'.cloud1.influxdata.com',
|
||||||
|
'.cloud2.influxdata.com',
|
||||||
|
// split.io A/B flag
|
||||||
|
'streaming.split.io',
|
||||||
|
'telemetry.split.io',
|
||||||
|
'sdk.split.io',
|
||||||
|
// Google
|
||||||
|
// -ds.metric.gstatic.com are specifically exempted from reject, but it could use secondary proxy policy
|
||||||
|
'.metric.gstatic.com',
|
||||||
|
// Misc
|
||||||
|
'telemetry.1passwordservices.com',
|
||||||
|
'events.tableplus.com',
|
||||||
|
'telemetry.nextjs.org',
|
||||||
|
'telemetry.vercel.com',
|
||||||
|
'stats.setapp.com',
|
||||||
|
'stats.setapp.macpaw.dev',
|
||||||
|
'.app-analytics-services.com',
|
||||||
|
'.telemetry.services.yofi.ai',
|
||||||
|
'.cdn.pubnub.com',
|
||||||
|
'.data.debugbear.com',
|
||||||
|
'.cdn.applicationinsights.io',
|
||||||
|
'.applicationinsights.azure.com',
|
||||||
|
'.applicationinsights.azure.cn',
|
||||||
|
'.api.loganalytics.io',
|
||||||
|
'.bugly.qcloud.com',
|
||||||
|
'.cdn.signalfx.com',
|
||||||
|
'.crash-reports.browser.yandex.net',
|
||||||
|
'.crashlytics2.l.google.com',
|
||||||
|
'.crashlyticsreports-pa.googleapis.com',
|
||||||
|
'.e.crashlytics.com',
|
||||||
|
'.events.backtrace.io',
|
||||||
|
'auth.split.io',
|
||||||
|
'events.split.io',
|
||||||
|
'streaming.split.io',
|
||||||
|
'.in.appcenter.ms',
|
||||||
|
'.loggly.com',
|
||||||
|
'.logz.io',
|
||||||
|
'.opentelemetry.io',
|
||||||
|
'.raygun.io',
|
||||||
|
'.rum.cronitor.io',
|
||||||
|
'.settings.crashlytics.com',
|
||||||
|
'.sny.monosnap.com',
|
||||||
|
'.lr-ingest.com',
|
||||||
|
'.cdn.rollbar.com',
|
||||||
|
'.api.instabug.com',
|
||||||
|
'.ensighten.com',
|
||||||
|
'api.crashguard.me'
|
||||||
|
];
|
||||||
|
const PREDEFINED_WHITELIST = [
|
||||||
|
...CRASHLYTICS_WHITELIST,
|
||||||
|
'.localhost',
|
||||||
|
'.local',
|
||||||
|
'.localdomain',
|
||||||
|
'.broadcasthost',
|
||||||
|
'.ip6-loopback',
|
||||||
|
'.ip6-localnet',
|
||||||
|
'.ip6-mcastprefix',
|
||||||
|
'.ip6-allnodes',
|
||||||
|
'.ip6-allrouters',
|
||||||
|
'.ip6-allhosts',
|
||||||
|
'.mcastprefix',
|
||||||
|
'.skk.moe',
|
||||||
|
'analytics.google.com',
|
||||||
|
'.cloud.answerhub.com',
|
||||||
|
'ae01.alicdn.com',
|
||||||
|
'.whoami.akamai.net',
|
||||||
|
'.whoami.ds.akahelp.net',
|
||||||
|
'.instant.page',
|
||||||
|
'.piwik.pro',
|
||||||
|
'mixpanel.com',
|
||||||
|
'cdn.mxpnl.com',
|
||||||
|
'.heapanalytics.com',
|
||||||
|
'.segment.com',
|
||||||
|
'.segmentify.com',
|
||||||
|
'.t.co',
|
||||||
|
'.survicate.com',
|
||||||
|
'.perfops.io',
|
||||||
|
'.d2axgrpnciinw7.cloudfront.net',
|
||||||
|
'.sb-cd.com',
|
||||||
|
'.storage.yandexcloud.net',
|
||||||
|
'.login.microsoftonline.com',
|
||||||
|
'api.xiaomi.com',
|
||||||
|
'api.io.mi.com',
|
||||||
|
'.cdn.userreport.com',
|
||||||
|
'.ip-api.com',
|
||||||
|
'.fastly-analytics.com',
|
||||||
|
'.digitaloceanspaces.com',
|
||||||
|
's3.nl-ams.scw.cloud',
|
||||||
|
'.geolocation-db.com',
|
||||||
|
'.uploads.codesandbox.io',
|
||||||
|
'.vlscppe.microsoft.com',
|
||||||
|
'.statsig.com',
|
||||||
|
'.pstmrk.it',
|
||||||
|
'.clicks.mlsend.com',
|
||||||
|
'email.accounts.bitly.com',
|
||||||
|
'adsense.google.com',
|
||||||
|
'api.vip.miui.com',
|
||||||
|
'api.comm.miui.com',
|
||||||
|
'.ai.api.xiaomi.com',
|
||||||
|
'm.stripe.com',
|
||||||
|
// yet stupid AdGuardDNSFilter blocks all of it. Stupid AdGuard
|
||||||
|
'.w3s.link',
|
||||||
|
'.r2.dev',
|
||||||
|
'mlsend.com',
|
||||||
|
'ab.chatgpt.com',
|
||||||
|
'jnn-pa.googleapis.com',
|
||||||
|
'imasdk.googleapis.com',
|
||||||
|
'.l.qq.com',
|
||||||
|
'.in-addr.arpa',
|
||||||
|
'.ip6.arpa',
|
||||||
|
'.clients.your-server.de',
|
||||||
|
'.bc.googleusercontent.com',
|
||||||
|
'.host.secureserver.net',
|
||||||
|
'.ip.linodeusercontent.com',
|
||||||
|
'.static.akamaitechnologies.com',
|
||||||
|
'.compute.amazonaws.com',
|
||||||
|
'.shoppy.gg',
|
||||||
|
'transcend-cdn.com',
|
||||||
|
'store1.gofile.io',
|
||||||
|
'ad.12306.cn',
|
||||||
|
'.ib.snssdk.com',
|
||||||
|
'.nstool.netease.com',
|
||||||
|
'.wns.windows.com',
|
||||||
|
'.lon.llnw.net',
|
||||||
|
'.lcy.llnw.net',
|
||||||
|
'repo.huaweicloud.com',
|
||||||
|
'.hubspotlinks.com',
|
||||||
|
'cldup.com',
|
||||||
|
// Doesn't make sense: CNAME domains
|
||||||
|
'.cdn.cloudflare.net',
|
||||||
|
'.apple-dns.net',
|
||||||
|
'.data.microsoft.com.akadns.net',
|
||||||
|
// Expired domains
|
||||||
|
'.expobarrio.com',
|
||||||
|
'.hamdandates.com',
|
||||||
|
'.amzone.co.jp'
|
||||||
|
];
|
||||||
|
} (rejectDataSource.__exports));
|
||||||
|
return rejectDataSource.__exports;
|
||||||
|
}exports.__require=requireRejectDataSource;
|
||||||
2
Dist/Build/download-mock-assets.cjs
Normal file
2
Dist/Build/download-mock-assets.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),downloadMockAssets$1=require('./download-mock-assets2.cjs');var downloadMockAssetsExports = downloadMockAssets$1.__require();
|
||||||
|
const downloadMockAssets = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(downloadMockAssetsExports);module.exports=downloadMockAssets;
|
||||||
58
Dist/Build/download-mock-assets2.cjs
Normal file
58
Dist/Build/download-mock-assets2.cjs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const downloadMockAssets=require('../_virtual/download-mock-assets.cjs'),index=require('./trace/index.cjs'),require$$0=require('node:path'),require$$1=require('node:fs'),require$$2=require('node:stream/promises'),dir=require('./constants/dir.cjs'),misc=require('./lib/misc.cjs'),fetchRetry=require('./lib/fetch-retry.cjs');var hasRequiredDownloadMockAssets;
|
||||||
|
|
||||||
|
function requireDownloadMockAssets () {
|
||||||
|
if (hasRequiredDownloadMockAssets) return downloadMockAssets.__module.exports;
|
||||||
|
hasRequiredDownloadMockAssets = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "downloadMockAssets", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return downloadMockAssets;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1);
|
||||||
|
const _promises = require$$2;
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _misc = /*@__PURE__*/ misc.__require();
|
||||||
|
const _fetchretry = /*@__PURE__*/ fetchRetry.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const ASSETS_LIST = {
|
||||||
|
'www-google-analytics-com_ga.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/google-analytics-ga.js',
|
||||||
|
'www-googletagservices-com_gpt.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/googletagservices-gpt.js',
|
||||||
|
'www-google-analytics-com_analytics.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/google-analytics.js',
|
||||||
|
'www-googlesyndication-com_adsbygoogle.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/googlesyndication-adsbygoogle.js',
|
||||||
|
'amazon-adsystem-com_amazon-apstag.js': 'https://unpkg.com/@adguard/scriptlets@latest/dist/redirect-files/amazon-apstag.js'
|
||||||
|
};
|
||||||
|
const downloadMockAssets = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
const p = (0, _misc.mkdirp)(_dir.OUTPUT_MOCK_DIR);
|
||||||
|
if (p) {
|
||||||
|
await p;
|
||||||
|
}
|
||||||
|
return Promise.all(Object.entries(ASSETS_LIST).map(([filename, url])=>span.traceChildAsync(url, async ()=>{
|
||||||
|
const res = await (0, _fetchretry.$$fetch)(url);
|
||||||
|
if (!res.ok) {
|
||||||
|
console.error(`Failed to download ${url}`);
|
||||||
|
// we can safely skip this since we can always use previous version
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!res.body) {
|
||||||
|
console.error(`Empty body from ${url}`);
|
||||||
|
// we can safely skip this since we can always use previous version
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const src = _nodepath.default.join(_dir.OUTPUT_MOCK_DIR, filename);
|
||||||
|
return (0, _promises.pipeline)(res.body, _nodefs.default.createWriteStream(src, 'utf-8'));
|
||||||
|
})));
|
||||||
|
});
|
||||||
|
} (downloadMockAssets.__module, downloadMockAssets.__module.exports));
|
||||||
|
return downloadMockAssets.__module.exports;
|
||||||
|
}exports.__require=requireDownloadMockAssets;
|
||||||
2
Dist/Build/download-previous-build.cjs
Normal file
2
Dist/Build/download-previous-build.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),downloadPreviousBuild$1=require('./download-previous-build2.cjs');var downloadPreviousBuildExports = downloadPreviousBuild$1.__require();
|
||||||
|
const downloadPreviousBuild = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(downloadPreviousBuildExports);module.exports=downloadPreviousBuild;
|
||||||
99
Dist/Build/download-previous-build2.cjs
Normal file
99
Dist/Build/download-previous-build2.cjs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const downloadPreviousBuild=require('../_virtual/download-previous-build.cjs'),require$$0$1=require('node:path'),require$$1$1=require('node:fs'),require$$2=require('node:stream/promises'),index=require('./trace/index.cjs'),require$$4=require('tar-fs'),require$$5=require('node:zlib'),require$$1=require('undici'),require$$0=require('picocolors'),dir=require('./constants/dir.cjs'),fetchRetry=require('./lib/fetch-retry.cjs'),misc=require('./lib/misc.cjs'),require$$11=require('ci-info');var hasRequiredDownloadPreviousBuild;
|
||||||
|
|
||||||
|
function requireDownloadPreviousBuild () {
|
||||||
|
if (hasRequiredDownloadPreviousBuild) return downloadPreviousBuild.__module.exports;
|
||||||
|
hasRequiredDownloadPreviousBuild = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "downloadPreviousBuild", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return downloadPreviousBuild;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1);
|
||||||
|
const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1$1);
|
||||||
|
const _promises = require$$2;
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _tarfs = require$$4;
|
||||||
|
const _nodezlib = /*#__PURE__*/ _interop_require_default(require$$5);
|
||||||
|
const _undici = /*#__PURE__*/ _interop_require_default(require$$1);
|
||||||
|
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _fetchretry = /*@__PURE__*/ fetchRetry.__require();
|
||||||
|
const _misc = /*@__PURE__*/ misc.__require();
|
||||||
|
const _ciinfo = require$$11;
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const GITHUB_CODELOAD_URL = 'https://codeload.github.com/sukkalab/ruleset.skk.moe/tar.gz/master';
|
||||||
|
const GITLAB_CODELOAD_URL = 'https://gitlab.com/SukkaW/ruleset.skk.moe/-/archive/master/ruleset.skk.moe-master.tar.gz';
|
||||||
|
const downloadPreviousBuild = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
||||||
|
if (_nodefs.default.existsSync(_dir.PUBLIC_DIR) && !(0, _misc.isDirectoryEmptySync)(_dir.PUBLIC_DIR)) {
|
||||||
|
console.log(_picocolors.default.blue('Public directory exists, skip downloading previous build'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// we uses actions/checkout to download the previous build now, so we should throw if the directory is empty
|
||||||
|
if (_ciinfo.isCI) {
|
||||||
|
throw new Error('CI environment detected, but public directory is empty');
|
||||||
|
}
|
||||||
|
const tarGzUrl = await span.traceChildAsync('get tar.gz url', async ()=>{
|
||||||
|
const resp = await (0, _fetchretry.requestWithLog)(GITHUB_CODELOAD_URL, {
|
||||||
|
method: 'HEAD'
|
||||||
|
});
|
||||||
|
if (resp.statusCode !== 200) {
|
||||||
|
console.warn('Download previous build from GitHub failed! Status:', resp.statusCode);
|
||||||
|
console.warn('Switch to GitLab');
|
||||||
|
return GITLAB_CODELOAD_URL;
|
||||||
|
}
|
||||||
|
return GITHUB_CODELOAD_URL;
|
||||||
|
});
|
||||||
|
return span.traceChildAsync('download & extract previoud build', async ()=>{
|
||||||
|
const respBody = _undici.default.pipeline(tarGzUrl, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'curl/8.9.1',
|
||||||
|
// https://github.com/unjs/giget/issues/97
|
||||||
|
// https://gitlab.com/gitlab-org/gitlab/-/commit/50c11f278d18fe1f3fb12eb595067216bb58ade2
|
||||||
|
'sec-fetch-mode': 'same-origin'
|
||||||
|
},
|
||||||
|
// Allow redirects by default
|
||||||
|
maxRedirections: 5
|
||||||
|
}, ({ statusCode, body })=>{
|
||||||
|
if (statusCode !== 200) {
|
||||||
|
console.warn('Download previous build failed! Status:', statusCode);
|
||||||
|
if (statusCode === 404) {
|
||||||
|
throw new Error('Download previous build failed! 404');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return body;
|
||||||
|
}).end();
|
||||||
|
const pathPrefix = 'ruleset.skk.moe-master/';
|
||||||
|
const gunzip = _nodezlib.default.createGunzip();
|
||||||
|
const extract = (0, _tarfs.extract)(_dir.PUBLIC_DIR, {
|
||||||
|
ignore (_, header) {
|
||||||
|
if (header) {
|
||||||
|
if (header.type !== 'file' && header.type !== 'directory') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (header.type === 'file' && _nodepath.default.extname(header.name) === '.ts') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
map (header) {
|
||||||
|
header.name = header.name.replace(pathPrefix, '');
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return (0, _promises.pipeline)(respBody, gunzip, extract);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} (downloadPreviousBuild.__module, downloadPreviousBuild.__module.exports));
|
||||||
|
return downloadPreviousBuild.__module.exports;
|
||||||
|
}exports.__require=requireDownloadPreviousBuild;
|
||||||
2
Dist/Build/index.cjs
Normal file
2
Dist/Build/index.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),index$1=require('./index2.cjs');var BuildExports = index$1.__require();
|
||||||
|
const index = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(BuildExports);module.exports=index;
|
||||||
107
Dist/Build/index2.cjs
Normal file
107
Dist/Build/index2.cjs
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const index=require('../_virtual/index.cjs'),require$$1$2=require('node:process'),require$$1=require('node:os'),require$$1$1=require('node:fs'),downloadPreviousBuild=require('./download-previous-build2.cjs'),buildCommon=require('./build-common2.cjs'),buildRejectIpList=require('./build-reject-ip-list2.cjs'),buildAppleCdn=require('./build-apple-cdn2.cjs'),buildCdnDownloadConf=require('./build-cdn-download-conf2.cjs'),buildRejectDomainset=require('./build-reject-domainset2.cjs'),buildTelegramCidr=require('./build-telegram-cidr2.cjs'),buildChnCidr=require('./build-chn-cidr2.cjs'),buildSpeedtestDomainset=require('./build-speedtest-domainset2.cjs'),buildInternalReverseChnCidr=require('./build-internal-reverse-chn-cidr2.cjs'),buildDomesticDirectLanRulesetDnsMappingModule=require('./build-domestic-direct-lan-ruleset-dns-mapping-module2.cjs'),buildStreamService=require('./build-stream-service2.cjs'),buildSgmoduleRedirect=require('./build-sgmodule-redirect2.cjs'),buildSgmoduleAlwaysRealip=require('./build-sgmodule-always-realip2.cjs'),buildMicrosoftCdn=require('./build-microsoft-cdn2.cjs'),buildSspanelAppprofile=require('./build-sspanel-appprofile2.cjs'),buildPublic=require('./build-public2.cjs'),downloadMockAssets=require('./download-mock-assets2.cjs'),buildCloudmounterRules=require('./build-cloudmounter-rules2.cjs'),index$1=require('./trace/index.cjs'),buildDeprecateFiles=require('./build-deprecate-files2.cjs'),require$$0=require('node:path'),dir=require('./constants/dir.cjs');var hasRequiredBuild;
|
||||||
|
|
||||||
|
function requireBuild () {
|
||||||
|
if (hasRequiredBuild) return index.__exports;
|
||||||
|
hasRequiredBuild = 1;
|
||||||
|
Object.defineProperty(index.__exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1$2);
|
||||||
|
const _nodeos = /*#__PURE__*/ _interop_require_default(require$$1);
|
||||||
|
const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1$1);
|
||||||
|
const _downloadpreviousbuild = downloadPreviousBuild.__require();
|
||||||
|
const _buildcommon = buildCommon.__require();
|
||||||
|
const _buildrejectiplist = buildRejectIpList.__require();
|
||||||
|
const _buildapplecdn = buildAppleCdn.__require();
|
||||||
|
const _buildcdndownloadconf = buildCdnDownloadConf.__require();
|
||||||
|
const _buildrejectdomainset = buildRejectDomainset.__require();
|
||||||
|
const _buildtelegramcidr = buildTelegramCidr.__require();
|
||||||
|
const _buildchncidr = buildChnCidr.__require();
|
||||||
|
const _buildspeedtestdomainset = buildSpeedtestDomainset.__require();
|
||||||
|
const _buildinternalreversechncidr = buildInternalReverseChnCidr.__require();
|
||||||
|
const _builddomesticdirectlanrulesetdnsmappingmodule = buildDomesticDirectLanRulesetDnsMappingModule.__require();
|
||||||
|
const _buildstreamservice = buildStreamService.__require();
|
||||||
|
const _buildsgmoduleredirect = buildSgmoduleRedirect.__require();
|
||||||
|
const _buildsgmodulealwaysrealip = buildSgmoduleAlwaysRealip.__require();
|
||||||
|
const _buildmicrosoftcdn = buildMicrosoftCdn.__require();
|
||||||
|
const _buildsspanelappprofile = buildSspanelAppprofile.__require();
|
||||||
|
const _buildpublic = buildPublic.__require();
|
||||||
|
const _downloadmockassets = downloadMockAssets.__require();
|
||||||
|
const _buildcloudmounterrules = buildCloudmounterRules.__require();
|
||||||
|
const _trace = /*@__PURE__*/ index$1.__require();
|
||||||
|
const _builddeprecatefiles = buildDeprecateFiles.__require();
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
_nodeprocess.default.on('uncaughtException', (error)=>{
|
||||||
|
console.error('Uncaught exception:', error);
|
||||||
|
_nodeprocess.default.exit(1);
|
||||||
|
});
|
||||||
|
_nodeprocess.default.on('unhandledRejection', (reason)=>{
|
||||||
|
console.error('Unhandled rejection:', reason);
|
||||||
|
_nodeprocess.default.exit(1);
|
||||||
|
});
|
||||||
|
const buildFinishedLock = _nodepath.default.join(_dir.ROOT_DIR, '.BUILD_FINISHED');
|
||||||
|
(async ()=>{
|
||||||
|
console.log('Version:', _nodeprocess.default.version);
|
||||||
|
console.log(`OS: ${_nodeos.default.type()} ${_nodeos.default.release()} ${_nodeos.default.arch()}`);
|
||||||
|
console.log(`Node.js: ${_nodeprocess.default.versions.node}`);
|
||||||
|
console.log(`V8: ${_nodeprocess.default.versions.v8}`);
|
||||||
|
const cpus = _nodeos.default.cpus().reduce((o, cpu)=>{
|
||||||
|
o[cpu.model] = (o[cpu.model] || 0) + 1;
|
||||||
|
return o;
|
||||||
|
}, {});
|
||||||
|
console.log(`CPU: ${Object.keys(cpus).map((key)=>`${key} x ${cpus[key]}`).join('\n')}`);
|
||||||
|
console.log(`Memory: ${_nodeos.default.totalmem() / (1024 * 1024)} MiB`);
|
||||||
|
const rootSpan = (0, _trace.createSpan)('root');
|
||||||
|
if (_nodefs.default.existsSync(buildFinishedLock)) {
|
||||||
|
_nodefs.default.unlinkSync(buildFinishedLock);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await import('why-is-node-running');
|
||||||
|
const downloadPreviousBuildPromise = (0, _downloadpreviousbuild.downloadPreviousBuild)(rootSpan);
|
||||||
|
const buildCommonPromise = downloadPreviousBuildPromise.then(()=>(0, _buildcommon.buildCommon)(rootSpan));
|
||||||
|
await Promise.all([
|
||||||
|
downloadPreviousBuildPromise,
|
||||||
|
buildCommonPromise,
|
||||||
|
downloadPreviousBuildPromise.then(()=>(0, _buildrejectiplist.buildRejectIPList)(rootSpan)),
|
||||||
|
downloadPreviousBuildPromise.then(()=>(0, _buildapplecdn.buildAppleCdn)(rootSpan)),
|
||||||
|
downloadPreviousBuildPromise.then(()=>(0, _buildcdndownloadconf.buildCdnDownloadConf)(rootSpan)),
|
||||||
|
downloadPreviousBuildPromise.then(()=>(0, _buildrejectdomainset.buildRejectDomainSet)(rootSpan)),
|
||||||
|
downloadPreviousBuildPromise.then(()=>(0, _buildtelegramcidr.buildTelegramCIDR)(rootSpan)),
|
||||||
|
downloadPreviousBuildPromise.then(()=>(0, _buildchncidr.buildChnCidr)(rootSpan)),
|
||||||
|
downloadPreviousBuildPromise.then(()=>(0, _buildspeedtestdomainset.buildSpeedtestDomainSet)(rootSpan)),
|
||||||
|
(0, _buildinternalreversechncidr.buildInternalReverseChnCIDR)(rootSpan),
|
||||||
|
downloadPreviousBuildPromise.then(()=>(0, _builddomesticdirectlanrulesetdnsmappingmodule.buildDomesticRuleset)(rootSpan)),
|
||||||
|
downloadPreviousBuildPromise.then(()=>(0, _buildsgmoduleredirect.buildRedirectModule)(rootSpan)),
|
||||||
|
downloadPreviousBuildPromise.then(()=>(0, _buildsgmodulealwaysrealip.buildAlwaysRealIPModule)(rootSpan)),
|
||||||
|
downloadPreviousBuildPromise.then(()=>(0, _buildstreamservice.buildStreamService)(rootSpan)),
|
||||||
|
downloadPreviousBuildPromise.then(()=>(0, _buildmicrosoftcdn.buildMicrosoftCdn)(rootSpan)),
|
||||||
|
Promise.all([
|
||||||
|
downloadPreviousBuildPromise,
|
||||||
|
buildCommonPromise
|
||||||
|
]).then(()=>(0, _buildsspanelappprofile.buildSSPanelUIMAppProfile)(rootSpan)),
|
||||||
|
downloadPreviousBuildPromise.then(()=>(0, _buildcloudmounterrules.buildCloudMounterRules)(rootSpan)),
|
||||||
|
(0, _downloadmockassets.downloadMockAssets)(rootSpan)
|
||||||
|
]);
|
||||||
|
await (0, _builddeprecatefiles.buildDeprecateFiles)(rootSpan);
|
||||||
|
await (0, _buildpublic.buildPublic)(rootSpan);
|
||||||
|
rootSpan.stop();
|
||||||
|
(0, _trace.printTraceResult)(rootSpan.traceResult);
|
||||||
|
// write a file to demonstrate that the build is finished
|
||||||
|
_nodefs.default.writeFileSync(buildFinishedLock, 'BUILD_FINISHED\n');
|
||||||
|
// Finish the build to avoid leaking timer/fetch ref
|
||||||
|
await (0, _trace.whyIsNodeRunning)();
|
||||||
|
_nodeprocess.default.exit(0);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Something went wrong!');
|
||||||
|
console.trace(e);
|
||||||
|
_nodeprocess.default.exit(1);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return index.__exports;
|
||||||
|
}exports.__require=requireBuild;
|
||||||
46
Dist/Build/lib/append-array-in-place.cjs
Normal file
46
Dist/Build/lib/append-array-in-place.cjs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const appendArrayInPlace=require('../../_virtual/append-array-in-place.cjs');var hasRequiredAppendArrayInPlace;
|
||||||
|
|
||||||
|
function requireAppendArrayInPlace () {
|
||||||
|
if (hasRequiredAppendArrayInPlace) return appendArrayInPlace.__exports;
|
||||||
|
hasRequiredAppendArrayInPlace = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
appendArrayInPlace: function() {
|
||||||
|
return appendArrayInPlace;
|
||||||
|
},
|
||||||
|
appendArrayInPlaceCurried: function() {
|
||||||
|
return appendArrayInPlaceCurried;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const MAX_BLOCK_SIZE = 65535; // max parameter array size for use in Webkit
|
||||||
|
function appendArrayInPlace(dest, source) {
|
||||||
|
let offset = 0;
|
||||||
|
let itemsLeft = source.length;
|
||||||
|
if (itemsLeft <= MAX_BLOCK_SIZE) {
|
||||||
|
// eslint-disable-next-line prefer-spread -- performance
|
||||||
|
dest.push.apply(dest, source);
|
||||||
|
} else {
|
||||||
|
while(itemsLeft > 0){
|
||||||
|
const pushCount = itemsLeft > MAX_BLOCK_SIZE ? MAX_BLOCK_SIZE : itemsLeft;
|
||||||
|
const subSource = source.slice(offset, offset + pushCount);
|
||||||
|
// eslint-disable-next-line prefer-spread -- performance
|
||||||
|
dest.push.apply(dest, subSource);
|
||||||
|
itemsLeft -= pushCount;
|
||||||
|
offset += pushCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
const appendArrayInPlaceCurried = (dest)=>(source)=>appendArrayInPlace(dest, source);
|
||||||
|
} (appendArrayInPlace.__exports));
|
||||||
|
return appendArrayInPlace.__exports;
|
||||||
|
}exports.__require=requireAppendArrayInPlace;
|
||||||
134
Dist/Build/lib/cache-filesystem.cjs
Normal file
134
Dist/Build/lib/cache-filesystem.cjs
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const cacheFilesystem=require('../../_virtual/cache-filesystem.cjs'),require$$0=require('better-sqlite3'),require$$1$1=require('node:os'),require$$0$2=require('node:path'),require$$1=require('node:fs'),require$$0$1=require('picocolors'),require$$3=require('foxts/fast-string-array-join'),require$$6=require('node:perf_hooks');var hasRequiredCacheFilesystem;
|
||||||
|
|
||||||
|
function requireCacheFilesystem () {
|
||||||
|
if (hasRequiredCacheFilesystem) return cacheFilesystem.__exports;
|
||||||
|
hasRequiredCacheFilesystem = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
Cache: function() {
|
||||||
|
return Cache;
|
||||||
|
},
|
||||||
|
deserializeArray: function() {
|
||||||
|
return deserializeArray;
|
||||||
|
},
|
||||||
|
serializeArray: function() {
|
||||||
|
return serializeArray;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _bettersqlite3 = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _nodeos = /*#__PURE__*/ _interop_require_default(require$$1$1);
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$2);
|
||||||
|
const _nodefs = require$$1;
|
||||||
|
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1);
|
||||||
|
const _faststringarrayjoin = require$$3;
|
||||||
|
const _nodeperf_hooks = require$$6;
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
class Cache {
|
||||||
|
db;
|
||||||
|
/** Time before deletion */ tbd = 60 * 1000;
|
||||||
|
/** SQLite file path */ cachePath;
|
||||||
|
/** Table name */ tableName;
|
||||||
|
type;
|
||||||
|
statement;
|
||||||
|
constructor({ cachePath = _nodepath.default.join(_nodeos.default.tmpdir() || '/tmp', 'hdc'), tbd, tableName = 'cache', type } = {}){
|
||||||
|
const start = _nodeperf_hooks.performance.now();
|
||||||
|
this.cachePath = cachePath;
|
||||||
|
(0, _nodefs.mkdirSync)(this.cachePath, {
|
||||||
|
recursive: true
|
||||||
|
});
|
||||||
|
if (tbd != null) this.tbd = tbd;
|
||||||
|
this.tableName = tableName;
|
||||||
|
if (type) {
|
||||||
|
this.type = type;
|
||||||
|
} else {
|
||||||
|
// @ts-expect-error -- fallback type
|
||||||
|
this.type = 'string';
|
||||||
|
}
|
||||||
|
const db = (0, _bettersqlite3.default)(_nodepath.default.join(this.cachePath, 'cache.db'));
|
||||||
|
db.pragma('journal_mode = WAL');
|
||||||
|
db.pragma('synchronous = normal');
|
||||||
|
db.pragma('temp_store = memory');
|
||||||
|
db.pragma('optimize');
|
||||||
|
db.prepare(`CREATE TABLE IF NOT EXISTS ${this.tableName} (key TEXT PRIMARY KEY, value ${this.type === 'string' ? 'TEXT' : 'BLOB'}, ttl REAL NOT NULL);`).run();
|
||||||
|
db.prepare(`CREATE INDEX IF NOT EXISTS cache_ttl ON ${this.tableName} (ttl);`).run();
|
||||||
|
/** cache stmt */ this.statement = {
|
||||||
|
updateTtl: db.prepare(`UPDATE ${this.tableName} SET ttl = ? WHERE key = ?;`),
|
||||||
|
del: db.prepare(`DELETE FROM ${this.tableName} WHERE key = ?`),
|
||||||
|
insert: db.prepare(`INSERT INTO ${this.tableName} (key, value, ttl) VALUES ($key, $value, $valid) ON CONFLICT(key) DO UPDATE SET value = $value, ttl = $valid`),
|
||||||
|
get: db.prepare(`SELECT ttl, value FROM ${this.tableName} WHERE key = ? LIMIT 1`)
|
||||||
|
};
|
||||||
|
const date = new Date();
|
||||||
|
// perform purge on startup
|
||||||
|
// ttl + tbd < now => ttl < now - tbd
|
||||||
|
const now = date.getTime() - this.tbd;
|
||||||
|
db.prepare(`DELETE FROM ${this.tableName} WHERE ttl < ?`).run(now);
|
||||||
|
this.db = db;
|
||||||
|
const dateString = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
||||||
|
const lastVaccum = this.get('__LAST_VACUUM');
|
||||||
|
if (lastVaccum === undefined || lastVaccum !== dateString && date.getUTCDay() === 6) {
|
||||||
|
console.log(_picocolors.default.magenta('[cache] vacuuming'));
|
||||||
|
this.set('__LAST_VACUUM', dateString, 10 * 365 * 60 * 60 * 24 * 1000);
|
||||||
|
this.db.exec('VACUUM;');
|
||||||
|
}
|
||||||
|
const end = _nodeperf_hooks.performance.now();
|
||||||
|
console.log(`${_picocolors.default.gray(`[${(end - start).toFixed(3)}ns]`)} cache initialized from ${this.tableName} @ ${this.cachePath}`);
|
||||||
|
}
|
||||||
|
set(key, value, ttl = 60 * 1000) {
|
||||||
|
const valid = Date.now() + ttl;
|
||||||
|
this.statement.insert.run({
|
||||||
|
$key: key,
|
||||||
|
key,
|
||||||
|
$value: value,
|
||||||
|
value,
|
||||||
|
$valid: valid,
|
||||||
|
valid
|
||||||
|
});
|
||||||
|
}
|
||||||
|
get(key) {
|
||||||
|
const rv = this.statement.get.get(key);
|
||||||
|
if (!rv) return null;
|
||||||
|
if (rv.ttl < Date.now()) {
|
||||||
|
this.del(key);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (rv.value == null) {
|
||||||
|
this.del(key);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return rv.value;
|
||||||
|
}
|
||||||
|
updateTtl(key, ttl) {
|
||||||
|
this.statement.updateTtl.run(Date.now() + ttl, key);
|
||||||
|
}
|
||||||
|
del(key) {
|
||||||
|
this.statement.del.run(key);
|
||||||
|
}
|
||||||
|
destroy() {
|
||||||
|
this.db.close();
|
||||||
|
}
|
||||||
|
deleteTable(tableName) {
|
||||||
|
this.db.exec(`DROP TABLE IF EXISTS ${tableName};`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// process.on('exit', () => {
|
||||||
|
// fsFetchCache.destroy();
|
||||||
|
// });
|
||||||
|
const separator = '\u0000';
|
||||||
|
const serializeArray = (arr)=>(0, _faststringarrayjoin.fastStringArrayJoin)(arr, separator);
|
||||||
|
const deserializeArray = (str)=>str.split(separator);
|
||||||
|
} (cacheFilesystem.__exports));
|
||||||
|
return cacheFilesystem.__exports;
|
||||||
|
}exports.__require=requireCacheFilesystem;
|
||||||
114
Dist/Build/lib/create-file.cjs
Normal file
114
Dist/Build/lib/create-file.cjs
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const createFile=require('../../_virtual/create-file.cjs'),require$$0=require('foxts/async-write-to-stream'),require$$3=require('foxts/fast-string-array-join'),require$$1=require('node:fs'),require$$0$1=require('picocolors'),fetchTextByLine=require('./fetch-text-by-line.cjs'),misc=require('./misc.cjs');var hasRequiredCreateFile;
|
||||||
|
|
||||||
|
function requireCreateFile () {
|
||||||
|
if (hasRequiredCreateFile) return createFile.__exports;
|
||||||
|
hasRequiredCreateFile = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
compareAndWriteFile: function() {
|
||||||
|
return compareAndWriteFile;
|
||||||
|
},
|
||||||
|
fileEqual: function() {
|
||||||
|
return fileEqual;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _asyncwritetostream = require$$0;
|
||||||
|
const _faststringarrayjoin = require$$3;
|
||||||
|
const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1);
|
||||||
|
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1);
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _misc = /*@__PURE__*/ misc.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
async function fileEqual(linesA, source) {
|
||||||
|
if (linesA.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const linesABound = linesA.length - 1;
|
||||||
|
let index = -1;
|
||||||
|
for await (const lineB of source){
|
||||||
|
index++;
|
||||||
|
if (index > linesABound) {
|
||||||
|
return index === linesA.length && lineB.length === 0;
|
||||||
|
}
|
||||||
|
const lineA = linesA[index];
|
||||||
|
if (lineA.length === 0) {
|
||||||
|
if (lineB.length === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// lineA is empty but lineB is not
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// now lineA can not be empty
|
||||||
|
if (lineB.length === 0) {
|
||||||
|
// lineB is empty but lineA is not
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// now both lines can not be empty
|
||||||
|
const firstCharA = lineA.charCodeAt(0);
|
||||||
|
const firstCharB = lineB.charCodeAt(0);
|
||||||
|
if (firstCharA !== firstCharB) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// now firstCharA is equal to firstCharB, we only need to check the first char
|
||||||
|
if (firstCharA === 35 /* # */ ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// adguard conf
|
||||||
|
if (firstCharA === 33 /* ! */ ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (firstCharA === 47 /* / */ && lineA[1] === '/' && lineB[1] === '/' && lineA[3] === '#' && lineB[3] === '#') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (lineA !== lineB) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The file becomes larger
|
||||||
|
return !(index < linesABound);
|
||||||
|
}
|
||||||
|
async function compareAndWriteFile(span, linesA, filePath) {
|
||||||
|
const linesALen = linesA.length;
|
||||||
|
const isEqual = await span.traceChildAsync(`compare ${filePath}`, async ()=>{
|
||||||
|
if (_nodefs.default.existsSync(filePath)) {
|
||||||
|
return fileEqual(linesA, (0, _fetchtextbyline.readFileByLine)(filePath));
|
||||||
|
}
|
||||||
|
console.log(`${filePath} does not exists, writing...`);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
if (isEqual) {
|
||||||
|
console.log(_picocolors.default.gray(_picocolors.default.dim(`same content, bail out writing: ${filePath}`)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await span.traceChildAsync(`writing ${filePath}`, async ()=>{
|
||||||
|
// The default highwater mark is normally 16384,
|
||||||
|
// So we make sure direct write to file if the content is
|
||||||
|
// most likely less than 500 lines
|
||||||
|
if (linesALen < 500) {
|
||||||
|
return (0, _misc.writeFile)(filePath, (0, _faststringarrayjoin.fastStringArrayJoin)(linesA, '\n') + '\n');
|
||||||
|
}
|
||||||
|
const writeStream = _nodefs.default.createWriteStream(filePath);
|
||||||
|
for(let i = 0; i < linesALen; i++){
|
||||||
|
const p = (0, _asyncwritetostream.asyncWriteToStream)(writeStream, linesA[i] + '\n');
|
||||||
|
// eslint-disable-next-line no-await-in-loop -- stream high water mark
|
||||||
|
if (p) await p;
|
||||||
|
}
|
||||||
|
writeStream.end();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} (createFile.__exports));
|
||||||
|
return createFile.__exports;
|
||||||
|
}exports.__require=requireCreateFile;
|
||||||
81
Dist/Build/lib/fetch-assets.cjs
Normal file
81
Dist/Build/lib/fetch-assets.cjs
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const fetchAssets=require('../../_virtual/fetch-assets.cjs'),require$$0=require('picocolors'),fetchRetry=require('./fetch-retry.cjs'),require$$2=require('foxts/wait'),require$$6=require('foxts/guard'),textLineTransformStream=require('./text-line-transform-stream.cjs'),processLine=require('./process-line.cjs');var hasRequiredFetchAssets;
|
||||||
|
|
||||||
|
function requireFetchAssets () {
|
||||||
|
if (hasRequiredFetchAssets) return fetchAssets.__exports;
|
||||||
|
hasRequiredFetchAssets = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
CustomAbortError: function() {
|
||||||
|
return CustomAbortError;
|
||||||
|
},
|
||||||
|
fetchAssets: function() {
|
||||||
|
return fetchAssets;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _fetchretry = /*@__PURE__*/ fetchRetry.__require();
|
||||||
|
const _wait = require$$2;
|
||||||
|
const _guard = require$$6;
|
||||||
|
const _textlinetransformstream = /*@__PURE__*/ textLineTransformStream.__require();
|
||||||
|
const _processline = /*@__PURE__*/ processLine.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
class CustomAbortError extends Error {
|
||||||
|
name = 'AbortError';
|
||||||
|
digest = 'AbortError';
|
||||||
|
}
|
||||||
|
const reusedCustomAbortError = new CustomAbortError();
|
||||||
|
async function fetchAssets(url, fallbackUrls, processLine = false) {
|
||||||
|
const controller = new AbortController();
|
||||||
|
const createFetchFallbackPromise = async (url, index)=>{
|
||||||
|
if (index >= 0) {
|
||||||
|
// Most assets can be downloaded within 250ms. To avoid wasting bandwidth, we will wait for 500ms before downloading from the fallback URL.
|
||||||
|
try {
|
||||||
|
await (0, _wait.waitWithAbort)(50 + (index + 1) * 100, controller.signal);
|
||||||
|
} catch {
|
||||||
|
console.log(_picocolors.default.gray('[fetch cancelled early]'), _picocolors.default.gray(url));
|
||||||
|
throw reusedCustomAbortError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (controller.signal.aborted) {
|
||||||
|
console.log(_picocolors.default.gray('[fetch cancelled]'), _picocolors.default.gray(url));
|
||||||
|
throw reusedCustomAbortError;
|
||||||
|
}
|
||||||
|
const res = await (0, _fetchretry.$$fetch)(url, {
|
||||||
|
signal: controller.signal,
|
||||||
|
..._fetchretry.defaultRequestInit
|
||||||
|
});
|
||||||
|
let stream = (0, _guard.nullthrow)(res.body).pipeThrough(new TextDecoderStream()).pipeThrough(new _textlinetransformstream.TextLineStream());
|
||||||
|
if (processLine) {
|
||||||
|
stream = stream.pipeThrough(new _processline.ProcessLineStream());
|
||||||
|
}
|
||||||
|
const arr = await Array.fromAsync(stream);
|
||||||
|
if (arr.length < 1) {
|
||||||
|
throw new _fetchretry.ResponseError(res, url, 'empty response w/o 304');
|
||||||
|
}
|
||||||
|
controller.abort();
|
||||||
|
return arr;
|
||||||
|
};
|
||||||
|
if (!fallbackUrls || fallbackUrls.length === 0) {
|
||||||
|
return createFetchFallbackPromise(url, -1);
|
||||||
|
}
|
||||||
|
return Promise.any([
|
||||||
|
createFetchFallbackPromise(url, -1),
|
||||||
|
...fallbackUrls.map(createFetchFallbackPromise)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} (fetchAssets.__exports));
|
||||||
|
return fetchAssets.__exports;
|
||||||
|
}exports.__require=requireFetchAssets;
|
||||||
235
Dist/Build/lib/fetch-retry.cjs
Normal file
235
Dist/Build/lib/fetch-retry.cjs
Normal file
@ -0,0 +1,235 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const fetchRetry=require('../../_virtual/fetch-retry.cjs'),require$$0$1=require('picocolors'),require$$1=require('undici'),require$$2=require('undici-cache-store-better-sqlite3'),require$$1$2=require('node:util'),require$$0=require('node:path'),require$$1$1=require('node:fs'),dir=require('../constants/dir.cjs');var hasRequiredFetchRetry;
|
||||||
|
|
||||||
|
function requireFetchRetry () {
|
||||||
|
if (hasRequiredFetchRetry) return fetchRetry.__exports;
|
||||||
|
hasRequiredFetchRetry = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
$$fetch: function() {
|
||||||
|
return $$fetch;
|
||||||
|
},
|
||||||
|
ResponseError: function() {
|
||||||
|
return ResponseError;
|
||||||
|
},
|
||||||
|
defaultRequestInit: function() {
|
||||||
|
return defaultRequestInit;
|
||||||
|
},
|
||||||
|
requestWithLog: function() {
|
||||||
|
return requestWithLog;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1);
|
||||||
|
const _undici = /*#__PURE__*/ _interop_require_wildcard(require$$1);
|
||||||
|
const _undicicachestorebettersqlite3 = require$$2;
|
||||||
|
const _nodeutil = require$$1$2;
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1$1);
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function _getRequireWildcardCache(nodeInterop) {
|
||||||
|
if (typeof WeakMap !== "function") return null;
|
||||||
|
var cacheBabelInterop = new WeakMap();
|
||||||
|
var cacheNodeInterop = new WeakMap();
|
||||||
|
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||||
|
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||||
|
})(nodeInterop);
|
||||||
|
}
|
||||||
|
function _interop_require_wildcard(obj, nodeInterop) {
|
||||||
|
if (obj && obj.__esModule) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||||
|
return {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var cache = _getRequireWildcardCache(nodeInterop);
|
||||||
|
if (cache && cache.has(obj)) {
|
||||||
|
return cache.get(obj);
|
||||||
|
}
|
||||||
|
var newObj = {
|
||||||
|
__proto__: null
|
||||||
|
};
|
||||||
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||||
|
for(var key in obj){
|
||||||
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||||
|
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||||
|
if (desc && (desc.get || desc.set)) {
|
||||||
|
Object.defineProperty(newObj, key, desc);
|
||||||
|
} else {
|
||||||
|
newObj[key] = obj[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newObj.default = obj;
|
||||||
|
if (cache) {
|
||||||
|
cache.set(obj, newObj);
|
||||||
|
}
|
||||||
|
return newObj;
|
||||||
|
}
|
||||||
|
if (!_nodefs.default.existsSync(_dir.CACHE_DIR)) {
|
||||||
|
_nodefs.default.mkdirSync(_dir.CACHE_DIR, {
|
||||||
|
recursive: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const agent = new _undici.Agent({
|
||||||
|
allowH2: true
|
||||||
|
});
|
||||||
|
(0, _undici.setGlobalDispatcher)(agent.compose(_undici.interceptors.dns({
|
||||||
|
// disable IPv6
|
||||||
|
dualStack: false,
|
||||||
|
affinity: 4
|
||||||
|
}), _undici.interceptors.retry({
|
||||||
|
maxRetries: 5,
|
||||||
|
minTimeout: 500,
|
||||||
|
maxTimeout: 10 * 1000,
|
||||||
|
// TODO: this part of code is only for allow more errors to be retried by default
|
||||||
|
// This should be removed once https://github.com/nodejs/undici/issues/3728 is implemented
|
||||||
|
retry (err, { state, opts }, cb) {
|
||||||
|
const errorCode = 'code' in err ? err.code : undefined;
|
||||||
|
// Any code that is not a Undici's originated and allowed to retry
|
||||||
|
if (errorCode === 'ERR_UNESCAPED_CHARACTERS' || err.message === 'Request path contains unescaped characters' || err.name === 'AbortError') {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
const statusCode = 'statusCode' in err && typeof err.statusCode === 'number' ? err.statusCode : null;
|
||||||
|
// bail out if the status code matches one of the following
|
||||||
|
if (statusCode != null && (statusCode === 401 // Unauthorized, should check credentials instead of retrying
|
||||||
|
|| statusCode === 403 // Forbidden, should check permissions instead of retrying
|
||||||
|
|| statusCode === 404 // Not Found, should check URL instead of retrying
|
||||||
|
|| statusCode === 405 // Method Not Allowed, should check method instead of retrying
|
||||||
|
)) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
// if (errorCode === 'UND_ERR_REQ_RETRY') {
|
||||||
|
// return cb(err);
|
||||||
|
// }
|
||||||
|
const { maxRetries = 5, minTimeout = 500, maxTimeout = 10 * 1000, timeoutFactor = 2, methods = [
|
||||||
|
'GET',
|
||||||
|
'HEAD',
|
||||||
|
'OPTIONS',
|
||||||
|
'PUT',
|
||||||
|
'DELETE',
|
||||||
|
'TRACE'
|
||||||
|
] } = opts.retryOptions || {};
|
||||||
|
// If we reached the max number of retries
|
||||||
|
if (state.counter > maxRetries) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
// If a set of method are provided and the current method is not in the list
|
||||||
|
if (Array.isArray(methods) && !methods.includes(opts.method)) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
const headers = 'headers' in err && typeof err.headers === 'object' ? err.headers : undefined;
|
||||||
|
const retryAfterHeader = headers?.['retry-after'];
|
||||||
|
let retryAfter = -1;
|
||||||
|
if (retryAfterHeader) {
|
||||||
|
retryAfter = Number(retryAfterHeader);
|
||||||
|
retryAfter = Number.isNaN(retryAfter) ? calculateRetryAfterHeader(retryAfterHeader) : retryAfter * 1e3; // Retry-After is in seconds
|
||||||
|
}
|
||||||
|
const retryTimeout = retryAfter > 0 ? Math.min(retryAfter, maxTimeout) : Math.min(minTimeout * timeoutFactor ** (state.counter - 1), maxTimeout);
|
||||||
|
console.log('[fetch retry]', 'schedule retry', {
|
||||||
|
statusCode,
|
||||||
|
retryTimeout,
|
||||||
|
errorCode,
|
||||||
|
url: opts.origin
|
||||||
|
});
|
||||||
|
// eslint-disable-next-line sukka/prefer-timer-id -- won't leak
|
||||||
|
setTimeout(()=>cb(null), retryTimeout);
|
||||||
|
}
|
||||||
|
}), _undici.interceptors.redirect({
|
||||||
|
maxRedirections: 5
|
||||||
|
}), _undici.interceptors.cache({
|
||||||
|
store: new _undicicachestorebettersqlite3.BetterSqlite3CacheStore({
|
||||||
|
location: _nodepath.default.join(_dir.CACHE_DIR, 'undici-better-sqlite3-cache-store.db'),
|
||||||
|
maxEntrySize: 1024 * 1024 * 100 // 100 MiB
|
||||||
|
})
|
||||||
|
})));
|
||||||
|
function calculateRetryAfterHeader(retryAfter) {
|
||||||
|
const current = Date.now();
|
||||||
|
return new Date(retryAfter).getTime() - current;
|
||||||
|
}
|
||||||
|
class ResponseError extends Error {
|
||||||
|
res;
|
||||||
|
url;
|
||||||
|
code;
|
||||||
|
statusCode;
|
||||||
|
constructor(res, url, ...args){
|
||||||
|
const statusCode = 'statusCode' in res ? res.statusCode : res.status;
|
||||||
|
super('HTTP ' + statusCode + ' ' + args.map((_)=>(0, _nodeutil.inspect)(_)).join(' ')), this.res = res, this.url = url;
|
||||||
|
if ('captureStackTrace' in Error) {
|
||||||
|
Error.captureStackTrace(this, ResponseError);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line sukka/unicorn/custom-error-definition -- deliberatly use previous name
|
||||||
|
this.name = this.constructor.name;
|
||||||
|
this.res = res;
|
||||||
|
this.code = statusCode;
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const defaultRequestInit = {
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'curl/8.9.1 (https://github.com/SukkaW/Surge)'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
async function $$fetch(url, init) {
|
||||||
|
try {
|
||||||
|
const res = await _undici.default.fetch(url, init);
|
||||||
|
if (res.status >= 400) {
|
||||||
|
throw new ResponseError(res, url);
|
||||||
|
}
|
||||||
|
if (!(res.status >= 200 && res.status <= 299) && res.status !== 304) {
|
||||||
|
throw new ResponseError(res, url);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
} catch (err) {
|
||||||
|
if (typeof err === 'object' && err !== null && 'name' in err) {
|
||||||
|
if (err.name === 'AbortError' || 'digest' in err && err.digest === 'AbortError') {
|
||||||
|
console.log(_picocolors.default.gray('[fetch abort]'), url);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(_picocolors.default.gray('[fetch fail]'), url, {
|
||||||
|
name: err.name
|
||||||
|
}, err);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function requestWithLog(url, opt) {
|
||||||
|
try {
|
||||||
|
const res = await _undici.default.request(url, opt);
|
||||||
|
if (res.statusCode >= 400) {
|
||||||
|
throw new ResponseError(res, url);
|
||||||
|
}
|
||||||
|
if (!(res.statusCode >= 200 && res.statusCode <= 299) && res.statusCode !== 304) {
|
||||||
|
throw new ResponseError(res, url);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
} catch (err) {
|
||||||
|
if (typeof err === 'object' && err !== null && 'name' in err) {
|
||||||
|
if (err.name === 'AbortError' || 'digest' in err && err.digest === 'AbortError') {
|
||||||
|
console.log(_picocolors.default.gray('[fetch abort]'), url);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(_picocolors.default.gray('[fetch fail]'), url, {
|
||||||
|
name: err.name
|
||||||
|
}, err);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} (fetchRetry.__exports));
|
||||||
|
return fetchRetry.__exports;
|
||||||
|
}exports.__require=requireFetchRetry;
|
||||||
79
Dist/Build/lib/fetch-text-by-line.cjs
Normal file
79
Dist/Build/lib/fetch-text-by-line.cjs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const fetchTextByLine=require('../../_virtual/fetch-text-by-line.cjs'),require$$1=require('node:fs'),require$$1$1=require('node:readline'),textLineTransformStream=require('./text-line-transform-stream.cjs'),require$$0=require('node:stream/web'),processLine=require('./process-line.cjs'),fetchRetry=require('./fetch-retry.cjs'),require$$6=require('foxts/guard');var hasRequiredFetchTextByLine;
|
||||||
|
|
||||||
|
function requireFetchTextByLine () {
|
||||||
|
if (hasRequiredFetchTextByLine) return fetchTextByLine.__exports;
|
||||||
|
hasRequiredFetchTextByLine = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
createReadlineInterfaceFromResponse: function() {
|
||||||
|
return createReadlineInterfaceFromResponse;
|
||||||
|
},
|
||||||
|
fetchRemoteTextByLine: function() {
|
||||||
|
return fetchRemoteTextByLine;
|
||||||
|
},
|
||||||
|
readFileByLine: function() {
|
||||||
|
return readFileByLine;
|
||||||
|
},
|
||||||
|
readFileIntoProcessedArray: function() {
|
||||||
|
return readFileIntoProcessedArray;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1);
|
||||||
|
const _nodereadline = /*#__PURE__*/ _interop_require_default(require$$1$1);
|
||||||
|
const _textlinetransformstream = /*@__PURE__*/ textLineTransformStream.__require();
|
||||||
|
const _web = require$$0;
|
||||||
|
const _processline = /*@__PURE__*/ processLine.__require();
|
||||||
|
const _fetchretry = /*@__PURE__*/ fetchRetry.__require();
|
||||||
|
const _guard = require$$6;
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function readFileByLine(file) {
|
||||||
|
return _nodereadline.default.createInterface({
|
||||||
|
input: _nodefs.default.createReadStream(file /* , { encoding: 'utf-8' } */ ),
|
||||||
|
crlfDelay: Infinity
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const createReadlineInterfaceFromResponse = (resp, processLine = false)=>{
|
||||||
|
(0, _guard.invariant)(resp.body, 'Failed to fetch remote text');
|
||||||
|
if ('bodyUsed' in resp && resp.bodyUsed) {
|
||||||
|
throw new Error('Body has already been consumed.');
|
||||||
|
}
|
||||||
|
let webStream;
|
||||||
|
if ('pipeThrough' in resp.body) {
|
||||||
|
webStream = resp.body;
|
||||||
|
} else {
|
||||||
|
throw new TypeError('Invalid response body!');
|
||||||
|
}
|
||||||
|
const resultStream = webStream.pipeThrough(new _web.TextDecoderStream()).pipeThrough(new _textlinetransformstream.TextLineStream());
|
||||||
|
if (processLine) {
|
||||||
|
return resultStream.pipeThrough(new _processline.ProcessLineStream());
|
||||||
|
}
|
||||||
|
return resultStream;
|
||||||
|
};
|
||||||
|
function fetchRemoteTextByLine(url, processLine = false) {
|
||||||
|
return (0, _fetchretry.$$fetch)(url).then((resp)=>createReadlineInterfaceFromResponse(resp, processLine));
|
||||||
|
}
|
||||||
|
async function readFileIntoProcessedArray(file/* | FileHandle */ ) {
|
||||||
|
const results = [];
|
||||||
|
for await (const line of readFileByLine(file)){
|
||||||
|
if ((0, _processline.processLine)(line)) {
|
||||||
|
results.push(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
} (fetchTextByLine.__exports));
|
||||||
|
return fetchTextByLine.__exports;
|
||||||
|
}exports.__require=requireFetchTextByLine;
|
||||||
89
Dist/Build/lib/fs-memo.cjs
Normal file
89
Dist/Build/lib/fs-memo.cjs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const fsMemo=require('../../_virtual/fs-memo.cjs'),require$$0$1=require('node:path'),require$$11=require('ci-info'),require$$0=require('picocolors'),cacheFilesystem=require('./cache-filesystem.cjs'),require$$4=require('foxts/serialized-memo'),dir=require('../constants/dir.cjs');var hasRequiredFsMemo;
|
||||||
|
|
||||||
|
function requireFsMemo () {
|
||||||
|
if (hasRequiredFsMemo) return fsMemo.__exports;
|
||||||
|
hasRequiredFsMemo = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
cache: function() {
|
||||||
|
return cache;
|
||||||
|
},
|
||||||
|
cachedOnlyFail: function() {
|
||||||
|
return cachedOnlyFail;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1);
|
||||||
|
const _ciinfo = require$$11;
|
||||||
|
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _cachefilesystem = /*@__PURE__*/ cacheFilesystem.__require();
|
||||||
|
const _serializedmemo = require$$4;
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const fsMemoCache = new _cachefilesystem.Cache({
|
||||||
|
cachePath: _nodepath.default.join(_dir.ROOT_DIR, '.cache'),
|
||||||
|
tableName: 'fs_memo_cache'
|
||||||
|
});
|
||||||
|
const fsMemoCacheProvider = {
|
||||||
|
has (key) {
|
||||||
|
return fsMemoCache.get(key) !== null;
|
||||||
|
},
|
||||||
|
delete () {
|
||||||
|
// noop
|
||||||
|
},
|
||||||
|
get (key) {
|
||||||
|
return fsMemoCache.get(key) ?? undefined;
|
||||||
|
},
|
||||||
|
set (key, value, ttl) {
|
||||||
|
fsMemoCache.set(key, value, ttl);
|
||||||
|
},
|
||||||
|
updateTtl (key, ttl) {
|
||||||
|
fsMemoCache.updateTtl(key, ttl);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const TTL = _ciinfo.isCI ? 1.5 * 86400 * 1000 : 7 * 86400 * 1000;
|
||||||
|
const cache = (0, _serializedmemo.createMemoize)(fsMemoCacheProvider, {
|
||||||
|
defaultTtl: TTL,
|
||||||
|
onCacheMiss (key, { humanReadableName, isUseCachedIfFail }) {
|
||||||
|
const cacheName = _picocolors.default.gray(humanReadableName);
|
||||||
|
if (isUseCachedIfFail) {
|
||||||
|
console.log(_picocolors.default.red('[fail] and no cache, throwing'), cacheName);
|
||||||
|
} else {
|
||||||
|
console.log(_picocolors.default.yellow('[cache] miss'), cacheName);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onCacheUpdate (key, { humanReadableName, isUseCachedIfFail }) {
|
||||||
|
const cacheName = _picocolors.default.gray(humanReadableName);
|
||||||
|
if (isUseCachedIfFail) {
|
||||||
|
console.log(_picocolors.default.gray('[cache] update'), cacheName);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onCacheHit (key, { humanReadableName, isUseCachedIfFail }) {
|
||||||
|
const cacheName = _picocolors.default.gray(humanReadableName);
|
||||||
|
if (isUseCachedIfFail) {
|
||||||
|
console.log(_picocolors.default.yellow('[fail] try cache'), cacheName);
|
||||||
|
} else {
|
||||||
|
console.log(_picocolors.default.green('[cache] hit'), cacheName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const cachedOnlyFail = (0, _serializedmemo.createMemoize)(fsMemoCacheProvider, {
|
||||||
|
defaultTtl: TTL,
|
||||||
|
onlyUseCachedIfFail: true
|
||||||
|
}); // export const cache = createCache(false);
|
||||||
|
// export const cachedOnlyFail = createCache(true);
|
||||||
|
} (fsMemo.__exports));
|
||||||
|
return fsMemo.__exports;
|
||||||
|
}exports.__require=requireFsMemo;
|
||||||
376
Dist/Build/lib/get-phishing-domains.cjs
Normal file
376
Dist/Build/lib/get-phishing-domains.cjs
Normal file
@ -0,0 +1,376 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const getPhishingDomains=require('../../_virtual/get-phishing-domains.cjs'),hosts=require('./parse-filter/hosts.cjs'),domainlists=require('./parse-filter/domainlists.cjs'),require$$5=require('tldts-experimental'),index=require('../trace/index.cjs'),appendArrayInPlace=require('./append-array-in-place.cjs'),rejectDataSource=require('../constants/reject-data-source.cjs'),looseTldtsOpt=require('../constants/loose-tldts-opt.cjs'),require$$0=require('picocolors'),require$$3=require('foxts/retrie'),cacheFilesystem=require('./cache-filesystem.cjs'),fsMemo=require('./fs-memo.cjs'),require$$11=require('ci-info');var hasRequiredGetPhishingDomains;
|
||||||
|
|
||||||
|
function requireGetPhishingDomains () {
|
||||||
|
if (hasRequiredGetPhishingDomains) return getPhishingDomains.__module.exports;
|
||||||
|
hasRequiredGetPhishingDomains = 1;
|
||||||
|
(function (module, exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
calcDomainAbuseScore: function() {
|
||||||
|
return calcDomainAbuseScore;
|
||||||
|
},
|
||||||
|
getPhishingDomains: function() {
|
||||||
|
return getPhishingDomains;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _hosts = /*@__PURE__*/ hosts.__require();
|
||||||
|
const _domainlists = /*@__PURE__*/ domainlists.__require();
|
||||||
|
const _tldtsexperimental = /*#__PURE__*/ _interop_require_wildcard(require$$5);
|
||||||
|
const _trace = /*@__PURE__*/ index.__require();
|
||||||
|
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
|
||||||
|
const _rejectdatasource = /*@__PURE__*/ rejectDataSource.__require();
|
||||||
|
const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.__require();
|
||||||
|
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _retrie = require$$3;
|
||||||
|
const _cachefilesystem = /*@__PURE__*/ cacheFilesystem.__require();
|
||||||
|
const _fsmemo = /*@__PURE__*/ fsMemo.__require();
|
||||||
|
const _ciinfo = require$$11;
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function _getRequireWildcardCache(nodeInterop) {
|
||||||
|
if (typeof WeakMap !== "function") return null;
|
||||||
|
var cacheBabelInterop = new WeakMap();
|
||||||
|
var cacheNodeInterop = new WeakMap();
|
||||||
|
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||||
|
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||||
|
})(nodeInterop);
|
||||||
|
}
|
||||||
|
function _interop_require_wildcard(obj, nodeInterop) {
|
||||||
|
if (obj && obj.__esModule) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||||
|
return {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var cache = _getRequireWildcardCache(nodeInterop);
|
||||||
|
if (cache && cache.has(obj)) {
|
||||||
|
return cache.get(obj);
|
||||||
|
}
|
||||||
|
var newObj = {
|
||||||
|
__proto__: null
|
||||||
|
};
|
||||||
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||||
|
for(var key in obj){
|
||||||
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||||
|
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||||
|
if (desc && (desc.get || desc.set)) {
|
||||||
|
Object.defineProperty(newObj, key, desc);
|
||||||
|
} else {
|
||||||
|
newObj[key] = obj[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newObj.default = obj;
|
||||||
|
if (cache) {
|
||||||
|
cache.set(obj, newObj);
|
||||||
|
}
|
||||||
|
return newObj;
|
||||||
|
}
|
||||||
|
const BLACK_TLD = new Set([
|
||||||
|
'accountant',
|
||||||
|
'art',
|
||||||
|
'autos',
|
||||||
|
'bar',
|
||||||
|
'beauty',
|
||||||
|
'bid',
|
||||||
|
'bio',
|
||||||
|
'biz',
|
||||||
|
'bond',
|
||||||
|
'business',
|
||||||
|
'buzz',
|
||||||
|
'cc',
|
||||||
|
'cf',
|
||||||
|
'cfd',
|
||||||
|
'click',
|
||||||
|
'cloud',
|
||||||
|
'club',
|
||||||
|
'cn',
|
||||||
|
'codes',
|
||||||
|
'co.uk',
|
||||||
|
'co.in',
|
||||||
|
'com.br',
|
||||||
|
'com.cn',
|
||||||
|
'com.pl',
|
||||||
|
'com.vn',
|
||||||
|
'cool',
|
||||||
|
'cricket',
|
||||||
|
'cyou',
|
||||||
|
'date',
|
||||||
|
'design',
|
||||||
|
'digital',
|
||||||
|
'download',
|
||||||
|
'faith',
|
||||||
|
'fit',
|
||||||
|
'fun',
|
||||||
|
'ga',
|
||||||
|
'gd',
|
||||||
|
'gives',
|
||||||
|
'gq',
|
||||||
|
'group',
|
||||||
|
'host',
|
||||||
|
'icu',
|
||||||
|
'id',
|
||||||
|
'info',
|
||||||
|
'ink',
|
||||||
|
'lat',
|
||||||
|
'life',
|
||||||
|
'live',
|
||||||
|
'link',
|
||||||
|
'loan',
|
||||||
|
'lol',
|
||||||
|
'ltd',
|
||||||
|
'me',
|
||||||
|
'men',
|
||||||
|
'ml',
|
||||||
|
'mobi',
|
||||||
|
'mom',
|
||||||
|
'monster',
|
||||||
|
'net.pl',
|
||||||
|
'one',
|
||||||
|
'online',
|
||||||
|
'party',
|
||||||
|
'pro',
|
||||||
|
'pl',
|
||||||
|
'pw',
|
||||||
|
'racing',
|
||||||
|
'rest',
|
||||||
|
'review',
|
||||||
|
'rf.gd',
|
||||||
|
'sa.com',
|
||||||
|
'sbs',
|
||||||
|
'science',
|
||||||
|
'shop',
|
||||||
|
'site',
|
||||||
|
'skin',
|
||||||
|
'space',
|
||||||
|
'store',
|
||||||
|
'stream',
|
||||||
|
'su',
|
||||||
|
'surf',
|
||||||
|
'tech',
|
||||||
|
'tk',
|
||||||
|
'tokyo',
|
||||||
|
'top',
|
||||||
|
'trade',
|
||||||
|
'vip',
|
||||||
|
'vn',
|
||||||
|
'webcam',
|
||||||
|
'website',
|
||||||
|
'win',
|
||||||
|
'xyz',
|
||||||
|
'za.com'
|
||||||
|
]);
|
||||||
|
const WHITELIST_MAIN_DOMAINS = new Set([
|
||||||
|
// 'w3s.link', // ipfs gateway
|
||||||
|
// 'dweb.link', // ipfs gateway
|
||||||
|
// 'nftstorage.link', // ipfs gateway
|
||||||
|
'fleek.cool',
|
||||||
|
'flk-ipfs.xyz',
|
||||||
|
'business.site',
|
||||||
|
'page.link',
|
||||||
|
// 'notion.site',
|
||||||
|
// 'vercel.app',
|
||||||
|
'gitbook.io',
|
||||||
|
'zendesk.com',
|
||||||
|
'ipfs.eth.aragon.network',
|
||||||
|
'wordpress.com'
|
||||||
|
]);
|
||||||
|
const leathalKeywords = (0, _retrie.createRetrieKeywordFilter)([
|
||||||
|
'vinted-',
|
||||||
|
'inpost-pl',
|
||||||
|
'vlnted-'
|
||||||
|
]);
|
||||||
|
const sensitiveKeywords = (0, _retrie.createRetrieKeywordFilter)([
|
||||||
|
'.amazon-',
|
||||||
|
'-amazon',
|
||||||
|
'fb-com',
|
||||||
|
'facebook-com',
|
||||||
|
'-facebook',
|
||||||
|
'facebook-',
|
||||||
|
'focebaak',
|
||||||
|
'.facebook.',
|
||||||
|
'metamask',
|
||||||
|
'www.apple',
|
||||||
|
'-coinbase',
|
||||||
|
'coinbase-',
|
||||||
|
'booking-com',
|
||||||
|
'booking.com-',
|
||||||
|
'booking-eu',
|
||||||
|
'vinted-',
|
||||||
|
'inpost-pl',
|
||||||
|
'login.microsoft',
|
||||||
|
'login-microsoft',
|
||||||
|
'microsoftonline',
|
||||||
|
'google.com-',
|
||||||
|
'minecraft',
|
||||||
|
'staemco',
|
||||||
|
'oferta'
|
||||||
|
]);
|
||||||
|
const lowKeywords = (0, _retrie.createRetrieKeywordFilter)([
|
||||||
|
'transactions-',
|
||||||
|
'payment',
|
||||||
|
'wallet',
|
||||||
|
'-transactions',
|
||||||
|
'-faceb',
|
||||||
|
'.faceb',
|
||||||
|
'facebook',
|
||||||
|
'virus-',
|
||||||
|
'icloud-',
|
||||||
|
'apple-',
|
||||||
|
'-roblox',
|
||||||
|
'-co-jp',
|
||||||
|
'customer.',
|
||||||
|
'customer-',
|
||||||
|
'.www-',
|
||||||
|
'.www.',
|
||||||
|
'.www2',
|
||||||
|
'instagram',
|
||||||
|
'microsof',
|
||||||
|
'passwordreset',
|
||||||
|
'.google-',
|
||||||
|
'recover',
|
||||||
|
'banking'
|
||||||
|
]);
|
||||||
|
const processPhihsingDomains = (0, _fsmemo.cache)(function processPhihsingDomains(domainArr) {
|
||||||
|
const domainCountMap = new Map();
|
||||||
|
const domainScoreMap = {};
|
||||||
|
let line = '';
|
||||||
|
let tld = '';
|
||||||
|
let apexDomain = '';
|
||||||
|
let subdomain = '';
|
||||||
|
// const set = new Set<string>();
|
||||||
|
// let duplicateCount = 0;
|
||||||
|
for(let i = 0, len = domainArr.length; i < len; i++){
|
||||||
|
line = domainArr[i];
|
||||||
|
// if (set.has(line)) {
|
||||||
|
// duplicateCount++;
|
||||||
|
// } else {
|
||||||
|
// set.add(line);
|
||||||
|
// }
|
||||||
|
const parsed = _tldtsexperimental.parse(line, _loosetldtsopt.loosTldOptWithPrivateDomains);
|
||||||
|
if (parsed.isPrivate) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tld = parsed.publicSuffix;
|
||||||
|
apexDomain = parsed.domain;
|
||||||
|
if (!tld) {
|
||||||
|
console.log(_picocolors.default.yellow('[phishing domains] E0001'), 'missing tld', {
|
||||||
|
line,
|
||||||
|
tld
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!apexDomain) {
|
||||||
|
console.log(_picocolors.default.yellow('[phishing domains] E0002'), 'missing domain', {
|
||||||
|
line,
|
||||||
|
apexDomain
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
domainCountMap.set(apexDomain, domainCountMap.has(apexDomain) ? domainCountMap.get(apexDomain) + 1 : 1);
|
||||||
|
if (!(apexDomain in domainScoreMap)) {
|
||||||
|
domainScoreMap[apexDomain] = 0;
|
||||||
|
if (BLACK_TLD.has(tld)) {
|
||||||
|
domainScoreMap[apexDomain] += 3;
|
||||||
|
} else if (tld.length > 6) {
|
||||||
|
domainScoreMap[apexDomain] += 2;
|
||||||
|
}
|
||||||
|
if (apexDomain.length >= 18) {
|
||||||
|
domainScoreMap[apexDomain] += 0.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subdomain = parsed.subdomain;
|
||||||
|
if (subdomain && !WHITELIST_MAIN_DOMAINS.has(apexDomain)) {
|
||||||
|
domainScoreMap[apexDomain] += calcDomainAbuseScore(subdomain, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
domainCountMap.forEach((count, apexDomain)=>{
|
||||||
|
if (// !WHITELIST_MAIN_DOMAINS.has(apexDomain)
|
||||||
|
domainScoreMap[apexDomain] >= 24 || domainScoreMap[apexDomain] >= 16 && count >= 7 || domainScoreMap[apexDomain] >= 13 && count >= 11 || domainScoreMap[apexDomain] >= 5 && count >= 14 || domainScoreMap[apexDomain] >= 3 && count >= 21 || domainScoreMap[apexDomain] >= 1 && count >= 60) {
|
||||||
|
domainArr.push('.' + apexDomain);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// console.log({
|
||||||
|
// score: domainScoreMap['awicksin.com'],
|
||||||
|
// count: domainCountMap.get('awicksin.com')
|
||||||
|
// });
|
||||||
|
// console.log({ duplicateCount, domainArrLen: domainArr.length });
|
||||||
|
return domainArr;
|
||||||
|
}, {
|
||||||
|
serializer: _cachefilesystem.serializeArray,
|
||||||
|
deserializer: _cachefilesystem.deserializeArray,
|
||||||
|
temporaryBypass: !_ciinfo.isCI || _rejectdatasource.DEBUG_DOMAIN_TO_FIND !== null
|
||||||
|
});
|
||||||
|
const downloads = [
|
||||||
|
..._rejectdatasource.PHISHING_DOMAIN_LISTS_EXTRA.map((entry)=>(0, _domainlists.processDomainListsWithPreload)(...entry)),
|
||||||
|
..._rejectdatasource.PHISHING_HOSTS_EXTRA.map((entry)=>(0, _hosts.processHostsWithPreload)(...entry))
|
||||||
|
];
|
||||||
|
function getPhishingDomains(parentSpan) {
|
||||||
|
return parentSpan.traceChild('get phishing domains').traceAsyncFn(async (span)=>{
|
||||||
|
const domainArr = await span.traceChildAsync('download/parse/merge phishing domains', async (curSpan)=>{
|
||||||
|
const domainArr = [];
|
||||||
|
const domainGroups = await Promise.all(downloads.map((task)=>task(curSpan)));
|
||||||
|
domainGroups.forEach((0, _appendarrayinplace.appendArrayInPlaceCurried)(domainArr));
|
||||||
|
return domainArr;
|
||||||
|
});
|
||||||
|
return span.traceChildAsync('process phishing domain set', ()=>processPhihsingDomains(domainArr));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function calcDomainAbuseScore(subdomain, fullDomain = subdomain) {
|
||||||
|
if (leathalKeywords(fullDomain)) {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
let weight = 0;
|
||||||
|
const hitLowKeywords = lowKeywords(fullDomain);
|
||||||
|
const sensitiveKeywordsHit = sensitiveKeywords(fullDomain);
|
||||||
|
if (sensitiveKeywordsHit) {
|
||||||
|
weight += 10;
|
||||||
|
if (hitLowKeywords) {
|
||||||
|
weight += 6;
|
||||||
|
}
|
||||||
|
} else if (hitLowKeywords) {
|
||||||
|
weight += 1.7;
|
||||||
|
}
|
||||||
|
const subdomainLength = subdomain.length;
|
||||||
|
if (subdomainLength > 6) {
|
||||||
|
weight += 0.015;
|
||||||
|
if (subdomainLength > 13) {
|
||||||
|
weight += 0.2;
|
||||||
|
if (subdomainLength > 20) {
|
||||||
|
weight += 1;
|
||||||
|
if (subdomainLength > 30) {
|
||||||
|
weight += 5;
|
||||||
|
if (subdomainLength > 40) {
|
||||||
|
weight += 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (subdomain.indexOf('.', 1) > 1) {
|
||||||
|
weight += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
if (require.main === module) {
|
||||||
|
getPhishingDomains(_trace.dummySpan).catch(console.error).finally(()=>{
|
||||||
|
_trace.dummySpan.stop();
|
||||||
|
(0, _trace.printTraceResult)(_trace.dummySpan.traceResult);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} (getPhishingDomains.__module, getPhishingDomains.__module.exports));
|
||||||
|
return getPhishingDomains.__module.exports;
|
||||||
|
}exports.__require=requireGetPhishingDomains;
|
||||||
396
Dist/Build/lib/is-domain-alive.cjs
Normal file
396
Dist/Build/lib/is-domain-alive.cjs
Normal file
@ -0,0 +1,396 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const isDomainAlive=require('../../_virtual/is-domain-alive.cjs'),require$$5=require('tldts-experimental'),looseTldtsOpt=require('../constants/loose-tldts-opt.cjs'),require$$0=require('picocolors'),require$$3$1=require('dns2'),require$$4=require('async-retry'),require$$5$1=require('whoiser'),require$$3=require('foxts/retrie'),require$$1=require('node:process');var hasRequiredIsDomainAlive;
|
||||||
|
|
||||||
|
function requireIsDomainAlive () {
|
||||||
|
if (hasRequiredIsDomainAlive) return isDomainAlive.__exports;
|
||||||
|
hasRequiredIsDomainAlive = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
isDomainAlive: function() {
|
||||||
|
return isDomainAlive;
|
||||||
|
},
|
||||||
|
keyedAsyncMutexWithQueue: function() {
|
||||||
|
return keyedAsyncMutexWithQueue;
|
||||||
|
},
|
||||||
|
noWhois: function() {
|
||||||
|
return noWhois;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _tldtsexperimental = /*#__PURE__*/ _interop_require_default(require$$5);
|
||||||
|
const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.__require();
|
||||||
|
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _dns2 = /*#__PURE__*/ _interop_require_default(require$$3$1);
|
||||||
|
const _asyncretry = /*#__PURE__*/ _interop_require_default(require$$4);
|
||||||
|
const _whoiser = /*#__PURE__*/ _interop_require_wildcard(require$$5$1);
|
||||||
|
const _retrie = require$$3;
|
||||||
|
const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1);
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function _getRequireWildcardCache(nodeInterop) {
|
||||||
|
if (typeof WeakMap !== "function") return null;
|
||||||
|
var cacheBabelInterop = new WeakMap();
|
||||||
|
var cacheNodeInterop = new WeakMap();
|
||||||
|
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||||
|
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||||
|
})(nodeInterop);
|
||||||
|
}
|
||||||
|
function _interop_require_wildcard(obj, nodeInterop) {
|
||||||
|
if (obj && obj.__esModule) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||||
|
return {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var cache = _getRequireWildcardCache(nodeInterop);
|
||||||
|
if (cache && cache.has(obj)) {
|
||||||
|
return cache.get(obj);
|
||||||
|
}
|
||||||
|
var newObj = {
|
||||||
|
__proto__: null
|
||||||
|
};
|
||||||
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||||
|
for(var key in obj){
|
||||||
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||||
|
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||||
|
if (desc && (desc.get || desc.set)) {
|
||||||
|
Object.defineProperty(newObj, key, desc);
|
||||||
|
} else {
|
||||||
|
newObj[key] = obj[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newObj.default = obj;
|
||||||
|
if (cache) {
|
||||||
|
cache.set(obj, newObj);
|
||||||
|
}
|
||||||
|
return newObj;
|
||||||
|
}
|
||||||
|
const mutex = new Map();
|
||||||
|
function keyedAsyncMutexWithQueue(key, fn) {
|
||||||
|
if (mutex.has(key)) {
|
||||||
|
return mutex.get(key);
|
||||||
|
}
|
||||||
|
const promise = fn();
|
||||||
|
mutex.set(key, promise);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
class DnsError extends Error {
|
||||||
|
message;
|
||||||
|
server;
|
||||||
|
name;
|
||||||
|
constructor(message, server){
|
||||||
|
super(message), this.message = message, this.server = server, this.name = 'DnsError';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const dohServers = [
|
||||||
|
'8.8.8.8',
|
||||||
|
'8.8.4.4',
|
||||||
|
'1.0.0.1',
|
||||||
|
'1.1.1.1',
|
||||||
|
'162.159.36.1',
|
||||||
|
'162.159.46.1',
|
||||||
|
'101.101.101.101',
|
||||||
|
'185.222.222.222',
|
||||||
|
'45.11.45.11',
|
||||||
|
'dns10.quad9.net',
|
||||||
|
'doh.sandbox.opendns.com',
|
||||||
|
'unfiltered.adguard-dns.com',
|
||||||
|
// '0ms.dev', // Proxy Cloudflare
|
||||||
|
// '76.76.2.0', // ControlD unfiltered, path not /dns-query
|
||||||
|
// '76.76.10.0', // ControlD unfiltered, path not /dns-query
|
||||||
|
// 'dns.bebasid.com', // BebasID, path not /dns-query but /unfiltered
|
||||||
|
// '193.110.81.0', // dns0.eu
|
||||||
|
// '185.253.5.0', // dns0.eu
|
||||||
|
// 'zero.dns0.eu',
|
||||||
|
'dns.nextdns.io',
|
||||||
|
'anycast.dns.nextdns.io',
|
||||||
|
'wikimedia-dns.org',
|
||||||
|
// 'ordns.he.net',
|
||||||
|
// 'dns.mullvad.net',
|
||||||
|
'basic.rethinkdns.com',
|
||||||
|
'198.54.117.10' // NameCheap DNS, supports DoT, DoH, UDP53
|
||||||
|
].map((dns)=>[
|
||||||
|
dns,
|
||||||
|
_dns2.default.DOHClient({
|
||||||
|
dns,
|
||||||
|
http: false
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
const domesticDohServers = [
|
||||||
|
'223.5.5.5',
|
||||||
|
'223.6.6.6',
|
||||||
|
'120.53.53.53',
|
||||||
|
'1.12.12.12'
|
||||||
|
].map((dns)=>[
|
||||||
|
dns,
|
||||||
|
_dns2.default.DOHClient({
|
||||||
|
dns,
|
||||||
|
http: false
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
function createResolve(server) {
|
||||||
|
return async (...args)=>{
|
||||||
|
try {
|
||||||
|
return await (0, _asyncretry.default)(async ()=>{
|
||||||
|
const [dohServer, dohClient] = server[Math.floor(Math.random() * server.length)];
|
||||||
|
try {
|
||||||
|
return {
|
||||||
|
...await dohClient(...args),
|
||||||
|
dns: dohServer
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
// console.error(e);
|
||||||
|
throw new DnsError(e.message, dohServer);
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
retries: 5
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.log('[doh error]', ...args, e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const resolve = createResolve(dohServers);
|
||||||
|
const domesticResolve = createResolve(domesticDohServers);
|
||||||
|
async function getWhois(domain) {
|
||||||
|
return (0, _asyncretry.default)(()=>_whoiser.domain(domain, {
|
||||||
|
raw: true
|
||||||
|
}), {
|
||||||
|
retries: 5
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const domainAliveMap = new Map();
|
||||||
|
function onDomainAlive(domain) {
|
||||||
|
domainAliveMap.set(domain, true);
|
||||||
|
return [
|
||||||
|
domain,
|
||||||
|
true
|
||||||
|
];
|
||||||
|
}
|
||||||
|
function onDomainDead(domain) {
|
||||||
|
domainAliveMap.set(domain, false);
|
||||||
|
return [
|
||||||
|
domain,
|
||||||
|
false
|
||||||
|
];
|
||||||
|
}
|
||||||
|
async function isDomainAlive(domain, isSuffix) {
|
||||||
|
if (domainAliveMap.has(domain)) {
|
||||||
|
return [
|
||||||
|
domain,
|
||||||
|
domainAliveMap.get(domain)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
const apexDomain = _tldtsexperimental.default.getDomain(domain, _loosetldtsopt.looseTldtsOpt);
|
||||||
|
if (!apexDomain) {
|
||||||
|
console.log(_picocolors.default.gray('[domain invalid]'), _picocolors.default.gray('no apex domain'), {
|
||||||
|
domain
|
||||||
|
});
|
||||||
|
return onDomainAlive(domain);
|
||||||
|
}
|
||||||
|
const apexDomainAlive = await keyedAsyncMutexWithQueue(apexDomain, ()=>isApexDomainAlive(apexDomain));
|
||||||
|
if (isSuffix) {
|
||||||
|
return apexDomainAlive;
|
||||||
|
}
|
||||||
|
if (!apexDomainAlive[1]) {
|
||||||
|
return apexDomainAlive;
|
||||||
|
}
|
||||||
|
const $domain = domain[0] === '.' ? domain.slice(1) : domain;
|
||||||
|
const aDns = [];
|
||||||
|
const aaaaDns = [];
|
||||||
|
// test 2 times before make sure record is empty
|
||||||
|
for(let i = 0; i < 2; i++){
|
||||||
|
// eslint-disable-next-line no-await-in-loop -- sequential
|
||||||
|
const aRecords = await resolve($domain, 'A');
|
||||||
|
if (aRecords.answers.length > 0) {
|
||||||
|
return onDomainAlive(domain);
|
||||||
|
}
|
||||||
|
aDns.push(aRecords.dns);
|
||||||
|
}
|
||||||
|
for(let i = 0; i < 2; i++){
|
||||||
|
// eslint-disable-next-line no-await-in-loop -- sequential
|
||||||
|
const aaaaRecords = await resolve($domain, 'AAAA');
|
||||||
|
if (aaaaRecords.answers.length > 0) {
|
||||||
|
return onDomainAlive(domain);
|
||||||
|
}
|
||||||
|
aaaaDns.push(aaaaRecords.dns);
|
||||||
|
}
|
||||||
|
// only then, let's test once with domesticDohServers
|
||||||
|
const aRecords = await domesticResolve($domain, 'A');
|
||||||
|
if (aRecords.answers.length > 0) {
|
||||||
|
return onDomainAlive(domain);
|
||||||
|
}
|
||||||
|
aDns.push(aRecords.dns);
|
||||||
|
const aaaaRecords = await domesticResolve($domain, 'AAAA');
|
||||||
|
if (aaaaRecords.answers.length > 0) {
|
||||||
|
return onDomainAlive(domain);
|
||||||
|
}
|
||||||
|
aaaaDns.push(aaaaRecords.dns);
|
||||||
|
console.log(_picocolors.default.red('[domain dead]'), 'no A/AAAA records', {
|
||||||
|
domain,
|
||||||
|
a: aDns,
|
||||||
|
aaaa: aaaaDns
|
||||||
|
});
|
||||||
|
return onDomainDead($domain);
|
||||||
|
}
|
||||||
|
const apexDomainNsResolvePromiseMap = new Map();
|
||||||
|
async function isApexDomainAlive(apexDomain) {
|
||||||
|
if (domainAliveMap.has(apexDomain)) {
|
||||||
|
return [
|
||||||
|
apexDomain,
|
||||||
|
domainAliveMap.get(apexDomain)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
let resp;
|
||||||
|
if (apexDomainNsResolvePromiseMap.has(apexDomain)) {
|
||||||
|
resp = await apexDomainNsResolvePromiseMap.get(apexDomain);
|
||||||
|
} else {
|
||||||
|
const promise = resolve(apexDomain, 'NS');
|
||||||
|
apexDomainNsResolvePromiseMap.set(apexDomain, promise);
|
||||||
|
resp = await promise;
|
||||||
|
}
|
||||||
|
if (resp.answers.length > 0) {
|
||||||
|
return onDomainAlive(apexDomain);
|
||||||
|
}
|
||||||
|
let whois;
|
||||||
|
try {
|
||||||
|
whois = await getWhois(apexDomain);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(_picocolors.default.red('[whois error]'), {
|
||||||
|
domain: apexDomain
|
||||||
|
}, e);
|
||||||
|
return onDomainAlive(apexDomain);
|
||||||
|
}
|
||||||
|
if (_nodeprocess.default.env.DEBUG) {
|
||||||
|
console.log(JSON.stringify(whois, null, 2));
|
||||||
|
}
|
||||||
|
const whoisError = noWhois(whois);
|
||||||
|
if (!whoisError) {
|
||||||
|
console.log(_picocolors.default.gray('[domain alive]'), _picocolors.default.gray('whois found'), {
|
||||||
|
domain: apexDomain
|
||||||
|
});
|
||||||
|
return onDomainAlive(apexDomain);
|
||||||
|
}
|
||||||
|
console.log(_picocolors.default.red('[domain dead]'), 'whois not found', {
|
||||||
|
domain: apexDomain,
|
||||||
|
err: whoisError
|
||||||
|
});
|
||||||
|
return onDomainDead(apexDomain);
|
||||||
|
}
|
||||||
|
// TODO: this is a workaround for https://github.com/LayeredStudio/whoiser/issues/117
|
||||||
|
const whoisNotFoundKeywordTest = (0, _retrie.createRetrieKeywordFilter)([
|
||||||
|
'no match for',
|
||||||
|
'does not exist',
|
||||||
|
'not found',
|
||||||
|
'no found',
|
||||||
|
'no entries',
|
||||||
|
'no data found',
|
||||||
|
'is available for registration',
|
||||||
|
'currently available for application',
|
||||||
|
'no matching record',
|
||||||
|
'no information available about domain name',
|
||||||
|
'not been registered',
|
||||||
|
'no match!!',
|
||||||
|
'status: available',
|
||||||
|
' is free',
|
||||||
|
'no object found',
|
||||||
|
'nothing found',
|
||||||
|
'status: free',
|
||||||
|
'pendingdelete',
|
||||||
|
' has been blocked by '
|
||||||
|
]);
|
||||||
|
function noWhois(whois) {
|
||||||
|
let empty = true;
|
||||||
|
for(const key in whois){
|
||||||
|
if (Object.hasOwn(whois, key)) {
|
||||||
|
empty = false;
|
||||||
|
// if (key === 'error') {
|
||||||
|
// // if (
|
||||||
|
// // (typeof whois.error === 'string' && whois.error)
|
||||||
|
// // || (Array.isArray(whois.error) && whois.error.length > 0)
|
||||||
|
// // ) {
|
||||||
|
// // console.error(whois);
|
||||||
|
// // return true;
|
||||||
|
// // }
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// if (key === 'text') {
|
||||||
|
// if (Array.isArray(whois.text)) {
|
||||||
|
// for (const value of whois.text) {
|
||||||
|
// if (whoisNotFoundKeywordTest(value.toLowerCase())) {
|
||||||
|
// return value;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// if (key === 'Name Server') {
|
||||||
|
// // if (Array.isArray(whois[key]) && whois[key].length === 0) {
|
||||||
|
// // return false;
|
||||||
|
// // }
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// if (key === 'Domain Status') {
|
||||||
|
// if (Array.isArray(whois[key])) {
|
||||||
|
// for (const status of whois[key]) {
|
||||||
|
// if (status === 'free' || status === 'AVAILABLE') {
|
||||||
|
// return key + ': ' + status;
|
||||||
|
// }
|
||||||
|
// if (whoisNotFoundKeywordTest(status.toLowerCase())) {
|
||||||
|
// return key + ': ' + status;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// if (typeof whois[key] === 'string' && whois[key]) {
|
||||||
|
// if (whoisNotFoundKeywordTest(whois[key].toLowerCase())) {
|
||||||
|
// return key + ': ' + whois[key];
|
||||||
|
// }
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
if (key === '__raw' && typeof whois.__raw === 'string') {
|
||||||
|
const lines = whois.__raw.trim().toLowerCase().replaceAll(/[\t ]+/g, ' ').split(/\r?\n/);
|
||||||
|
if (_nodeprocess.default.env.DEBUG) {
|
||||||
|
console.log({
|
||||||
|
lines
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (const line of lines){
|
||||||
|
if (whoisNotFoundKeywordTest(line)) {
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (typeof whois[key] === 'object' && !Array.isArray(whois[key])) {
|
||||||
|
const tmp = noWhois(whois[key]);
|
||||||
|
if (tmp) {
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty) {
|
||||||
|
return 'whois is empty';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} (isDomainAlive.__exports));
|
||||||
|
return isDomainAlive.__exports;
|
||||||
|
}exports.__require=requireIsDomainAlive;
|
||||||
35
Dist/Build/lib/memo-promise.cjs
Normal file
35
Dist/Build/lib/memo-promise.cjs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const memoPromise=require('../../_virtual/memo-promise.cjs');var hasRequiredMemoPromise;
|
||||||
|
|
||||||
|
function requireMemoPromise () {
|
||||||
|
if (hasRequiredMemoPromise) return memoPromise.__exports;
|
||||||
|
hasRequiredMemoPromise = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "createMemoizedPromise", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return createMemoizedPromise;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const notError = Symbol('notError');
|
||||||
|
function createMemoizedPromise(fn, /** whether to create promise immediately or only create after first access */ preload = true) {
|
||||||
|
let error = notError;
|
||||||
|
let promise = preload ? fn().catch((e)=>{
|
||||||
|
// Here we record the error so that we can throw it later when the function is called
|
||||||
|
error = e;
|
||||||
|
// Here we make sure the Promise still returns the never type
|
||||||
|
throw e;
|
||||||
|
}) : null;
|
||||||
|
return ()=>{
|
||||||
|
if (error !== notError) {
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
promise ??= fn();
|
||||||
|
return promise;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} (memoPromise.__exports));
|
||||||
|
return memoPromise.__exports;
|
||||||
|
}exports.__require=requireMemoPromise;
|
||||||
122
Dist/Build/lib/misc.cjs
Normal file
122
Dist/Build/lib/misc.cjs
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const misc=require('../../_virtual/misc.cjs'),require$$0=require('node:path'),require$$1=require('node:fs'),require$$2=require('node:fs/promises');var hasRequiredMisc;
|
||||||
|
|
||||||
|
function requireMisc () {
|
||||||
|
if (hasRequiredMisc) return misc.__exports;
|
||||||
|
hasRequiredMisc = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
fastIpVersion: function() {
|
||||||
|
return fastIpVersion;
|
||||||
|
},
|
||||||
|
fastStringCompare: function() {
|
||||||
|
return fastStringCompare;
|
||||||
|
},
|
||||||
|
isDirectoryEmptySync: function() {
|
||||||
|
return isDirectoryEmptySync;
|
||||||
|
},
|
||||||
|
mkdirp: function() {
|
||||||
|
return mkdirp;
|
||||||
|
},
|
||||||
|
notSupported: function() {
|
||||||
|
return notSupported;
|
||||||
|
},
|
||||||
|
removeFiles: function() {
|
||||||
|
return removeFiles;
|
||||||
|
},
|
||||||
|
withBannerArray: function() {
|
||||||
|
return withBannerArray;
|
||||||
|
},
|
||||||
|
withIdentityContent: function() {
|
||||||
|
return withIdentityContent;
|
||||||
|
},
|
||||||
|
writeFile: function() {
|
||||||
|
return writeFile;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _nodepath = require$$0;
|
||||||
|
const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1);
|
||||||
|
const _promises = /*#__PURE__*/ _interop_require_default(require$$2);
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function fastStringCompare(a, b) {
|
||||||
|
const lenA = a.length;
|
||||||
|
const lenB = b.length;
|
||||||
|
const minLen = lenA < lenB ? lenA : lenB;
|
||||||
|
for(let i = 0; i < minLen; ++i){
|
||||||
|
const ca = a.charCodeAt(i);
|
||||||
|
const cb = b.charCodeAt(i);
|
||||||
|
if (ca > cb) return 1;
|
||||||
|
if (ca < cb) return -1;
|
||||||
|
}
|
||||||
|
if (lenA === lenB) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return lenA > lenB ? 1 : -1;
|
||||||
|
}
|
||||||
|
function mkdirp(dir) {
|
||||||
|
if (_nodefs.default.existsSync(dir)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return _promises.default.mkdir(dir, {
|
||||||
|
recursive: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const writeFile = async (destination, input, dir = (0, _nodepath.dirname)(destination))=>{
|
||||||
|
const p = mkdirp(dir);
|
||||||
|
if (p) {
|
||||||
|
await p;
|
||||||
|
}
|
||||||
|
return _promises.default.writeFile(destination, input, {
|
||||||
|
encoding: 'utf-8'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const removeFiles = async (files)=>Promise.all(files.map((file)=>_promises.default.rm(file, {
|
||||||
|
force: true
|
||||||
|
})));
|
||||||
|
function withBannerArray(title, description, date, content) {
|
||||||
|
return [
|
||||||
|
'#########################################',
|
||||||
|
`# ${title}`,
|
||||||
|
`# Last Updated: ${date.toISOString()}`,
|
||||||
|
`# Size: ${content.length}`,
|
||||||
|
...description.map((line)=>line ? `# ${line}` : '#'),
|
||||||
|
'#########################################',
|
||||||
|
...content,
|
||||||
|
'################## EOF ##################'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
function notSupported(name) {
|
||||||
|
return (...args)=>{
|
||||||
|
console.error(`${name}: not supported.`, args);
|
||||||
|
throw new Error(`${name}: not implemented.`);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function withIdentityContent(title, description, date, content) {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
function isDirectoryEmptySync(path) {
|
||||||
|
const directoryHandle = _nodefs.default.opendirSync(path);
|
||||||
|
try {
|
||||||
|
return directoryHandle.readSync() === null;
|
||||||
|
} finally{
|
||||||
|
directoryHandle.closeSync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function fastIpVersion(ip) {
|
||||||
|
return ip.includes(':') ? 6 : ip.includes('.') ? 4 : 0;
|
||||||
|
}
|
||||||
|
} (misc.__exports));
|
||||||
|
return misc.__exports;
|
||||||
|
}exports.__require=requireMisc;
|
||||||
79
Dist/Build/lib/normalize-domain.cjs
Normal file
79
Dist/Build/lib/normalize-domain.cjs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const normalizeDomain=require('../../_virtual/normalize-domain.cjs'),require$$0=require('tldts'),looseTldtsOpt=require('../constants/loose-tldts-opt.cjs'),require$$2=require('foxts/is-probably-ip');var hasRequiredNormalizeDomain;
|
||||||
|
|
||||||
|
function requireNormalizeDomain () {
|
||||||
|
if (hasRequiredNormalizeDomain) return normalizeDomain.__exports;
|
||||||
|
hasRequiredNormalizeDomain = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
fastNormalizeDomain: function() {
|
||||||
|
return fastNormalizeDomain;
|
||||||
|
},
|
||||||
|
fastNormalizeDomainWithoutWww: function() {
|
||||||
|
return fastNormalizeDomainWithoutWww;
|
||||||
|
},
|
||||||
|
normalizeDomain: function() {
|
||||||
|
return normalizeDomain;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _tldts = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.__require();
|
||||||
|
const _isprobablyip = require$$2;
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function fastNormalizeDomainWithoutWww(domain, parsed = null) {
|
||||||
|
// We don't want tldts to call its own "extractHostname" on ip, bail out ip first.
|
||||||
|
// Now ip has been bailed out, we can safely set normalizeTldtsOpt.detectIp to false.
|
||||||
|
if ((0, _isprobablyip.isProbablyIpv4)(domain) || (0, _isprobablyip.isProbablyIpv6)(domain)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
parsed ??= _tldts.default.parse(domain, _loosetldtsopt.normalizeTldtsOpt);
|
||||||
|
// Private invalid domain (things like .tor, .dn42, etc)
|
||||||
|
if (!parsed.isIcann && !parsed.isPrivate) return null;
|
||||||
|
if (parsed.subdomain) {
|
||||||
|
if (parsed.subdomain === 'www') {
|
||||||
|
return parsed.domain;
|
||||||
|
}
|
||||||
|
if (parsed.subdomain.startsWith('www.')) {
|
||||||
|
return parsed.subdomain.slice(4) + '.' + parsed.domain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parsed.hostname;
|
||||||
|
}
|
||||||
|
function fastNormalizeDomain(domain, parsed = null) {
|
||||||
|
// We don't want tldts to call its own "extractHostname" on ip, bail out ip first.
|
||||||
|
// Now ip has been bailed out, we can safely set normalizeTldtsOpt.detectIp to false.
|
||||||
|
if ((0, _isprobablyip.isProbablyIpv4)(domain) || (0, _isprobablyip.isProbablyIpv6)(domain)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
parsed ??= _tldts.default.parse(domain, _loosetldtsopt.normalizeTldtsOpt);
|
||||||
|
// Private invalid domain (things like .tor, .dn42, etc)
|
||||||
|
if (!parsed.isIcann && !parsed.isPrivate) return null;
|
||||||
|
return parsed.hostname;
|
||||||
|
}
|
||||||
|
function normalizeDomain(domain, parsed = null) {
|
||||||
|
if (domain.length === 0) return null;
|
||||||
|
if ((0, _isprobablyip.isProbablyIpv4)(domain) || (0, _isprobablyip.isProbablyIpv6)(domain)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
parsed ??= _tldts.default.parse(domain, _loosetldtsopt.normalizeTldtsOpt);
|
||||||
|
// Private invalid domain (things like .tor, .dn42, etc)
|
||||||
|
if (!parsed.isIcann && !parsed.isPrivate) return null;
|
||||||
|
// const h = parsed.hostname;
|
||||||
|
// if (h === null) return null;
|
||||||
|
return parsed.hostname;
|
||||||
|
}
|
||||||
|
} (normalizeDomain.__exports));
|
||||||
|
return normalizeDomain.__exports;
|
||||||
|
}exports.__require=requireNormalizeDomain;
|
||||||
44
Dist/Build/lib/parse-dnsmasq.cjs
Normal file
44
Dist/Build/lib/parse-dnsmasq.cjs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const parseDnsmasq=require('../../_virtual/parse-dnsmasq.cjs'),fetchTextByLine=require('./fetch-text-by-line.cjs'),normalizeDomain=require('./normalize-domain.cjs');var hasRequiredParseDnsmasq;
|
||||||
|
|
||||||
|
function requireParseDnsmasq () {
|
||||||
|
if (hasRequiredParseDnsmasq) return parseDnsmasq.__exports;
|
||||||
|
hasRequiredParseDnsmasq = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
extractDomainsFromFelixDnsmasq: function() {
|
||||||
|
return extractDomainsFromFelixDnsmasq;
|
||||||
|
},
|
||||||
|
parseFelixDnsmasqFromResp: function() {
|
||||||
|
return parseFelixDnsmasqFromResp;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _normalizedomain = /*@__PURE__*/ normalizeDomain.__require();
|
||||||
|
function extractDomainsFromFelixDnsmasq(line) {
|
||||||
|
if (line.startsWith('server=/') && line.endsWith('/114.114.114.114')) {
|
||||||
|
return line.slice(8, -16);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
async function parseFelixDnsmasqFromResp(resp) {
|
||||||
|
const results = [];
|
||||||
|
for await (const line of (0, _fetchtextbyline.createReadlineInterfaceFromResponse)(resp, true)){
|
||||||
|
const domain = extractDomainsFromFelixDnsmasq(line);
|
||||||
|
if (domain && (0, _normalizedomain.fastNormalizeDomain)(domain)) {
|
||||||
|
results.push(domain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
} (parseDnsmasq.__exports));
|
||||||
|
return parseDnsmasq.__exports;
|
||||||
|
}exports.__require=requireParseDnsmasq;
|
||||||
71
Dist/Build/lib/parse-filter/domainlists.cjs
Normal file
71
Dist/Build/lib/parse-filter/domainlists.cjs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const domainlists=require('../../../_virtual/domainlists.cjs'),normalizeDomain=require('../normalize-domain.cjs'),processLine=require('../process-line.cjs'),shared=require('./shared.cjs'),fetchAssets=require('../fetch-assets.cjs');var hasRequiredDomainlists;
|
||||||
|
|
||||||
|
function requireDomainlists () {
|
||||||
|
if (hasRequiredDomainlists) return domainlists.__exports;
|
||||||
|
hasRequiredDomainlists = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
processDomainLists: function() {
|
||||||
|
return processDomainLists;
|
||||||
|
},
|
||||||
|
processDomainListsWithPreload: function() {
|
||||||
|
return processDomainListsWithPreload;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _normalizedomain = /*@__PURE__*/ normalizeDomain.__require();
|
||||||
|
const _processline = /*@__PURE__*/ processLine.__require();
|
||||||
|
const _shared = /*@__PURE__*/ shared.__require();
|
||||||
|
const _fetchassets = /*@__PURE__*/ fetchAssets.__require();
|
||||||
|
function domainListLineCb(l, set, meta, normalizeDomain = _normalizedomain.fastNormalizeDomain) {
|
||||||
|
const line = (0, _processline.processLine)(l);
|
||||||
|
if (!line) return;
|
||||||
|
const domain = normalizeDomain(line);
|
||||||
|
if (!domain) return;
|
||||||
|
(0, _shared.onBlackFound)(domain, meta);
|
||||||
|
set.push(domain);
|
||||||
|
}
|
||||||
|
function domainListLineCbIncludeAllSubdomain(line, set, meta, normalizeDomain = _normalizedomain.fastNormalizeDomain) {
|
||||||
|
const domain = normalizeDomain(line);
|
||||||
|
if (!domain) return;
|
||||||
|
(0, _shared.onBlackFound)(domain, meta);
|
||||||
|
set.push('.' + domain);
|
||||||
|
}
|
||||||
|
function processDomainLists(span, domainListsUrl, mirrors, includeAllSubDomain = false) {
|
||||||
|
const lineCb = includeAllSubDomain ? domainListLineCbIncludeAllSubdomain : domainListLineCb;
|
||||||
|
return span.traceChildAsync(`process domainlist: ${domainListsUrl}`, async (span)=>{
|
||||||
|
const filterRules = await span.traceChildAsync('download', ()=>(0, _fetchassets.fetchAssets)(domainListsUrl, mirrors, true));
|
||||||
|
const domainSets = [];
|
||||||
|
span.traceChildSync('parse domain list', ()=>{
|
||||||
|
for(let i = 0, len = filterRules.length; i < len; i++){
|
||||||
|
lineCb(filterRules[i], domainSets, domainListsUrl, _normalizedomain.fastNormalizeDomainWithoutWww);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return domainSets;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function processDomainListsWithPreload(domainListsUrl, mirrors, includeAllSubDomain = false) {
|
||||||
|
const downloadPromise = (0, _fetchassets.fetchAssets)(domainListsUrl, mirrors, true);
|
||||||
|
const lineCb = includeAllSubDomain ? domainListLineCbIncludeAllSubdomain : domainListLineCb;
|
||||||
|
return (span)=>span.traceChildAsync(`process domainlist: ${domainListsUrl}`, async (span)=>{
|
||||||
|
const filterRules = await span.traceChildPromise('download', downloadPromise);
|
||||||
|
const domainSets = [];
|
||||||
|
span.traceChildSync('parse domain list', ()=>{
|
||||||
|
for(let i = 0, len = filterRules.length; i < len; i++){
|
||||||
|
lineCb(filterRules[i], domainSets, domainListsUrl, _normalizedomain.fastNormalizeDomainWithoutWww);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return domainSets;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} (domainlists.__exports));
|
||||||
|
return domainlists.__exports;
|
||||||
|
}exports.__require=requireDomainlists;
|
||||||
372
Dist/Build/lib/parse-filter/filters.cjs
Normal file
372
Dist/Build/lib/parse-filter/filters.cjs
Normal file
@ -0,0 +1,372 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const filters=require('../../../_virtual/filters.cjs'),require$$0=require('picocolors'),fetchAssets=require('../fetch-assets.cjs'),shared=require('./shared.cjs'),require$$3=require('foxts/retrie'),looseTldtsOpt=require('../../constants/loose-tldts-opt.cjs'),require$$5=require('tldts-experimental'),require$$6=require('@ghostery/adblocker'),normalizeDomain=require('../normalize-domain.cjs');var hasRequiredFilters;
|
||||||
|
|
||||||
|
function requireFilters () {
|
||||||
|
if (hasRequiredFilters) return filters.__exports;
|
||||||
|
hasRequiredFilters = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
parse: function() {
|
||||||
|
return parse;
|
||||||
|
},
|
||||||
|
processFilterRulesWithPreload: function() {
|
||||||
|
return processFilterRulesWithPreload;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _fetchassets = /*@__PURE__*/ fetchAssets.__require();
|
||||||
|
const _shared = /*@__PURE__*/ shared.__require();
|
||||||
|
const _retrie = require$$3;
|
||||||
|
const _loosetldtsopt = /*@__PURE__*/ looseTldtsOpt.__require();
|
||||||
|
const _tldtsexperimental = /*#__PURE__*/ _interop_require_default(require$$5);
|
||||||
|
const _adblocker = require$$6;
|
||||||
|
const _normalizedomain = /*@__PURE__*/ normalizeDomain.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function processFilterRulesWithPreload(filterRulesUrl, fallbackUrls, includeThirdParty = false) {
|
||||||
|
const downloadPromise = (0, _fetchassets.fetchAssets)(filterRulesUrl, fallbackUrls);
|
||||||
|
return (span)=>span.traceChildAsync(`process filter rules: ${filterRulesUrl}`, async (span)=>{
|
||||||
|
const filterRules = await span.traceChildPromise('download', downloadPromise);
|
||||||
|
const whiteDomains = new Set();
|
||||||
|
const whiteDomainSuffixes = new Set();
|
||||||
|
const blackDomains = new Set();
|
||||||
|
const blackDomainSuffixes = new Set();
|
||||||
|
const warningMessages = [];
|
||||||
|
const MUTABLE_PARSE_LINE_RESULT = [
|
||||||
|
'',
|
||||||
|
2000
|
||||||
|
];
|
||||||
|
/**
|
||||||
|
* @param {string} line
|
||||||
|
*/ const lineCb = (line)=>{
|
||||||
|
const result = parse(line, MUTABLE_PARSE_LINE_RESULT, includeThirdParty);
|
||||||
|
const flag = result[1];
|
||||||
|
if (flag === 2000) {
|
||||||
|
throw new Error(`Didn't parse line: ${line}`);
|
||||||
|
}
|
||||||
|
if (flag === 1000) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const hostname = result[0];
|
||||||
|
if (flag === 0 || flag === -1) {
|
||||||
|
(0, _shared.onWhiteFound)(hostname, filterRulesUrl);
|
||||||
|
} else {
|
||||||
|
(0, _shared.onBlackFound)(hostname, filterRulesUrl);
|
||||||
|
}
|
||||||
|
switch(flag){
|
||||||
|
case 0:
|
||||||
|
whiteDomainSuffixes.add(hostname);
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
whiteDomains.add(hostname);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
blackDomainSuffixes.add(hostname);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
blackDomains.add(hostname);
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
warningMessages.push(hostname);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
span.traceChild('parse adguard filter').traceSyncFn(()=>{
|
||||||
|
for(let i = 0, len = filterRules.length; i < len; i++){
|
||||||
|
lineCb(filterRules[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for(let i = 0, len = warningMessages.length; i < len; i++){
|
||||||
|
console.warn(_picocolors.default.yellow(warningMessages[i]), _picocolors.default.gray(_picocolors.default.underline(filterRulesUrl)));
|
||||||
|
}
|
||||||
|
console.log(_picocolors.default.gray('[process filter]'), _picocolors.default.gray(filterRulesUrl), _picocolors.default.gray(`white: ${whiteDomains.size + whiteDomainSuffixes.size}`), _picocolors.default.gray(`black: ${blackDomains.size + blackDomainSuffixes.size}`));
|
||||||
|
return {
|
||||||
|
whiteDomains: Array.from(whiteDomains),
|
||||||
|
whiteDomainSuffixes: Array.from(whiteDomainSuffixes),
|
||||||
|
blackDomains: Array.from(blackDomains),
|
||||||
|
blackDomainSuffixes: Array.from(blackDomainSuffixes)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// many filter that has modifiers can not work on Surge/Clash because browser context is required
|
||||||
|
// we can early bail out those rules
|
||||||
|
const kwfilter = (0, _retrie.createRetrieKeywordFilter)([
|
||||||
|
'!',
|
||||||
|
'?',
|
||||||
|
'*',
|
||||||
|
'[',
|
||||||
|
'(',
|
||||||
|
']',
|
||||||
|
')',
|
||||||
|
',',
|
||||||
|
'#',
|
||||||
|
'%',
|
||||||
|
'&',
|
||||||
|
'=',
|
||||||
|
'~',
|
||||||
|
// special modifier
|
||||||
|
'$popup',
|
||||||
|
'$removeparam',
|
||||||
|
'$redirect',
|
||||||
|
'$popunder',
|
||||||
|
'$cname',
|
||||||
|
'$frame',
|
||||||
|
'$domain',
|
||||||
|
'$from',
|
||||||
|
'$to',
|
||||||
|
'$csp',
|
||||||
|
'$replace',
|
||||||
|
'$urlskip',
|
||||||
|
// some bad syntax
|
||||||
|
'^popup'
|
||||||
|
]);
|
||||||
|
function parse($line, result, includeThirdParty) {
|
||||||
|
if (// doesn't include
|
||||||
|
!$line.includes('.') // rule with out dot can not be a domain
|
||||||
|
|| kwfilter($line)) {
|
||||||
|
result[1] = 1000;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
const line = $line.trim();
|
||||||
|
if (line.length === 0) {
|
||||||
|
result[1] = 1000;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
const firstCharCode = line.charCodeAt(0);
|
||||||
|
const lastCharCode = line.charCodeAt(line.length - 1);
|
||||||
|
if (firstCharCode === 47 // 47 `/`
|
||||||
|
|| lastCharCode === 46 // 46 `.`, line.endsWith('.')
|
||||||
|
|| lastCharCode === 45 // 45 `-`, line.endsWith('-')
|
||||||
|
|| lastCharCode === 95 // 95 `_`, line.endsWith('_')
|
||||||
|
) {
|
||||||
|
result[1] = 1000;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if ((line.includes('/') || line.includes(':')) && !line.includes('://')) {
|
||||||
|
result[1] = 1000;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
const filter = _adblocker.NetworkFilter.parse(line);
|
||||||
|
if (filter) {
|
||||||
|
if (// filter.isCosmeticFilter() // always false
|
||||||
|
// filter.isNetworkFilter() // always true
|
||||||
|
filter.isElemHide() || filter.isGenericHide() || filter.isSpecificHide() || filter.isRedirect() || filter.isRedirectRule() || filter.hasDomains() || filter.isCSP() // must not be csp rule
|
||||||
|
|| !filter.fromHttp() && !filter.fromHttps()) {
|
||||||
|
// not supported type
|
||||||
|
result[1] = 1000;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (!filter.fromAny() && !filter.fromDocument() // $document, $doc
|
||||||
|
) {
|
||||||
|
result[1] = 1000;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (filter.hostname // filter.hasHostname() // must have
|
||||||
|
&& filter.isPlain() // isPlain() === !isRegex()
|
||||||
|
&& !filter.isFullRegex()) {
|
||||||
|
const hostname = (0, _normalizedomain.fastNormalizeDomainWithoutWww)(filter.hostname);
|
||||||
|
if (!hostname) {
|
||||||
|
result[1] = 1000;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
// |: filter.isHostnameAnchor(),
|
||||||
|
// |: filter.isLeftAnchor(),
|
||||||
|
// |https://: !filter.isHostnameAnchor() && (filter.fromHttps() || filter.fromHttp())
|
||||||
|
const isIncludeAllSubDomain = filter.isHostnameAnchor();
|
||||||
|
if (filter.isException() || filter.isBadFilter()) {
|
||||||
|
result[0] = hostname;
|
||||||
|
result[1] = isIncludeAllSubDomain ? 0 : -1;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
const _1p = filter.firstParty();
|
||||||
|
const _3p = filter.thirdParty();
|
||||||
|
if (_1p) {
|
||||||
|
if (_3p) {
|
||||||
|
result[0] = hostname;
|
||||||
|
result[1] = isIncludeAllSubDomain ? 2 : 1;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result[1] = 1000;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (_3p) {
|
||||||
|
if (includeThirdParty) {
|
||||||
|
result[0] = hostname;
|
||||||
|
result[1] = isIncludeAllSubDomain ? 2 : 1;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result[1] = 1000;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* From now on, we are mostly facing non-standard domain rules (some are regex like)
|
||||||
|
*
|
||||||
|
* We can still salvage some of them by removing modifiers
|
||||||
|
*/ let sliceStart = 0;
|
||||||
|
let sliceEnd = 0;
|
||||||
|
// After NetworkFilter.parse, it means the line can not be parsed by cliqz NetworkFilter
|
||||||
|
// We now need to "salvage" the line as much as possible
|
||||||
|
let white = false;
|
||||||
|
let includeAllSubDomain = false;
|
||||||
|
if (firstCharCode === 64 // 64 `@`
|
||||||
|
&& line.charCodeAt(1) === 64 // 64 `@`
|
||||||
|
) {
|
||||||
|
sliceStart += 2;
|
||||||
|
white = true;
|
||||||
|
includeAllSubDomain = true;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Some "malformed" regex-based filters can not be parsed by NetworkFilter
|
||||||
|
* "$genericblock`" is also not supported by NetworkFilter, see:
|
||||||
|
* https://github.com/ghostery/adblocker/blob/62caf7786ba10ef03beffecd8cd4eec111bcd5ec/packages/adblocker/test/parsing.test.ts#L950
|
||||||
|
*
|
||||||
|
* `@@||cmechina.net^$genericblock`
|
||||||
|
* `@@|ftp.bmp.ovh^|`
|
||||||
|
* `@@|adsterra.com^|`
|
||||||
|
* `@@.atlassian.net$document`
|
||||||
|
* `@@||ad.alimama.com^$genericblock`
|
||||||
|
*/ switch(line.charCodeAt(sliceStart)){
|
||||||
|
case 124:
|
||||||
|
/** | */ // line.startsWith('@@|') || line.startsWith('|')
|
||||||
|
sliceStart += 1;
|
||||||
|
includeAllSubDomain = false;
|
||||||
|
if (line[sliceStart] === '|') {
|
||||||
|
sliceStart += 1;
|
||||||
|
includeAllSubDomain = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 46:
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* `.ay.delivery^`
|
||||||
|
* `.m.bookben.com^`
|
||||||
|
* `.wap.x4399.com^`
|
||||||
|
*/ sliceStart += 1;
|
||||||
|
includeAllSubDomain = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch(line.charCodeAt(sliceStart)){
|
||||||
|
case 58:
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* `@@://googleadservices.com^|`
|
||||||
|
* `@@://www.googleadservices.com^|`
|
||||||
|
* `://mine.torrent.pw^`
|
||||||
|
* `://say.ac^`
|
||||||
|
*/ if (line[sliceStart + 1] === '/' && line[sliceStart + 2] === '/') {
|
||||||
|
includeAllSubDomain = false;
|
||||||
|
sliceStart += 3;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 104:
|
||||||
|
{
|
||||||
|
/** |http://x.o2.pl^ */ if (line.startsWith('http://', sliceStart)) {
|
||||||
|
includeAllSubDomain = false;
|
||||||
|
sliceStart += 7;
|
||||||
|
} else if (line.startsWith('https://', sliceStart)) {
|
||||||
|
includeAllSubDomain = false;
|
||||||
|
sliceStart += 8;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const indexOfDollar = line.indexOf('$', sliceStart);
|
||||||
|
if (indexOfDollar > -1) {
|
||||||
|
sliceEnd = indexOfDollar - line.length;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* We skip third-party and frame rules, as Surge / Clash can't handle them
|
||||||
|
*
|
||||||
|
* `.sharecounter.$third-party`
|
||||||
|
* `.bbelements.com^$third-party`
|
||||||
|
* `://o0e.ru^$third-party`
|
||||||
|
* `.1.1.1.l80.js^$third-party`
|
||||||
|
*/ if (!includeThirdParty && (line.includes('third-party', indexOfDollar + 1) || line.includes('3p', indexOfDollar + 1))) {
|
||||||
|
result[1] = 1000;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (line.includes('badfilter', indexOfDollar + 1)) {
|
||||||
|
white = true;
|
||||||
|
}
|
||||||
|
if (line.includes('all', indexOfDollar + 1)) {
|
||||||
|
includeAllSubDomain = true;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* `_vmind.qqvideo.tc.qq.com^`
|
||||||
|
* `arketing.indianadunes.com^`
|
||||||
|
* `charlestownwyllie.oaklawnnonantum.com^`
|
||||||
|
* `-telemetry.officeapps.live.com^`
|
||||||
|
* `-tracker.biliapi.net`
|
||||||
|
* `-logging.nextmedia.com`
|
||||||
|
* `_social_tracking.js^`
|
||||||
|
*/ if (line.charCodeAt(line.length + sliceEnd - 1) === 94) {
|
||||||
|
/** line.endsWith('^') */ sliceEnd -= 1;
|
||||||
|
} else if (line.charCodeAt(line.length + sliceEnd - 1) === 124) {
|
||||||
|
/** line.endsWith('|') */ sliceEnd -= 1;
|
||||||
|
if (line.charCodeAt(line.length + sliceEnd - 1) === 94) {
|
||||||
|
/** line.endsWith('^|') */ sliceEnd -= 1;
|
||||||
|
}
|
||||||
|
} else if (line.charCodeAt(line.length + sliceEnd - 1) === 46) {
|
||||||
|
/** line.endsWith('.') */ sliceEnd -= 1;
|
||||||
|
}
|
||||||
|
const sliced = sliceStart > 0 || sliceEnd < 0 ? line.slice(sliceStart, sliceEnd === 0 ? undefined : sliceEnd) : line;
|
||||||
|
if (sliced.length === 0 || sliced.includes('/')) {
|
||||||
|
result[1] = 1000;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (sliced.charCodeAt(0) === 45 /* - */ ) {
|
||||||
|
// line.startsWith('-') is not a valid domain
|
||||||
|
result[1] = 10;
|
||||||
|
result[0] = `[parse-filter E0001] (${white ? 'white' : 'black'}) invalid domain: ${JSON.stringify({
|
||||||
|
line,
|
||||||
|
sliced,
|
||||||
|
sliceStart,
|
||||||
|
sliceEnd
|
||||||
|
})}`;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
const suffix = _tldtsexperimental.default.getPublicSuffix(sliced, _loosetldtsopt.looseTldtsOpt);
|
||||||
|
if (!suffix) {
|
||||||
|
// This exclude domain-like resource like `_social_tracking.js^`
|
||||||
|
result[1] = 1000;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
const domain = (0, _normalizedomain.fastNormalizeDomainWithoutWww)(sliced);
|
||||||
|
if (domain && domain === sliced) {
|
||||||
|
result[0] = domain;
|
||||||
|
if (white) {
|
||||||
|
result[1] = includeAllSubDomain ? 0 : -1;
|
||||||
|
} else {
|
||||||
|
result[1] = includeAllSubDomain ? 2 : 1;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result[0] = `[parse-filter E0010] (${white ? 'white' : 'black'}) invalid domain: ${JSON.stringify({
|
||||||
|
line,
|
||||||
|
domain,
|
||||||
|
suffix,
|
||||||
|
sliced,
|
||||||
|
sliceStart,
|
||||||
|
sliceEnd
|
||||||
|
})}`;
|
||||||
|
result[1] = 10;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} (filters.__exports));
|
||||||
|
return filters.__exports;
|
||||||
|
}exports.__require=requireFilters;
|
||||||
66
Dist/Build/lib/parse-filter/hosts.cjs
Normal file
66
Dist/Build/lib/parse-filter/hosts.cjs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const hosts=require('../../../_virtual/hosts.cjs'),fetchAssets=require('../fetch-assets.cjs'),normalizeDomain=require('../normalize-domain.cjs'),shared=require('./shared.cjs');var hasRequiredHosts;
|
||||||
|
|
||||||
|
function requireHosts () {
|
||||||
|
if (hasRequiredHosts) return hosts.__exports;
|
||||||
|
hasRequiredHosts = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
processHosts: function() {
|
||||||
|
return processHosts;
|
||||||
|
},
|
||||||
|
processHostsWithPreload: function() {
|
||||||
|
return processHostsWithPreload;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _fetchassets = /*@__PURE__*/ fetchAssets.__require();
|
||||||
|
const _normalizedomain = /*@__PURE__*/ normalizeDomain.__require();
|
||||||
|
const _shared = /*@__PURE__*/ shared.__require();
|
||||||
|
function hostsLineCb(line, set, includeAllSubDomain, meta) {
|
||||||
|
const _domain = line.split(/\s/)[1]?.trim();
|
||||||
|
if (!_domain) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const domain = (0, _normalizedomain.fastNormalizeDomainWithoutWww)(_domain);
|
||||||
|
if (!domain) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
(0, _shared.onBlackFound)(domain, meta);
|
||||||
|
set.push(includeAllSubDomain ? `.${domain}` : domain);
|
||||||
|
}
|
||||||
|
function processHosts(span, hostsUrl, mirrors, includeAllSubDomain = false) {
|
||||||
|
return span.traceChildAsync(`process hosts: ${hostsUrl}`, async (span)=>{
|
||||||
|
const filterRules = await span.traceChild('download').traceAsyncFn(()=>(0, _fetchassets.fetchAssets)(hostsUrl, mirrors, true));
|
||||||
|
const domainSets = [];
|
||||||
|
span.traceChild('parse hosts').traceSyncFn(()=>{
|
||||||
|
for(let i = 0, len = filterRules.length; i < len; i++){
|
||||||
|
hostsLineCb(filterRules[i], domainSets, includeAllSubDomain, hostsUrl);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return domainSets;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function processHostsWithPreload(hostsUrl, mirrors, includeAllSubDomain = false) {
|
||||||
|
const downloadPromise = (0, _fetchassets.fetchAssets)(hostsUrl, mirrors, true);
|
||||||
|
return (span)=>span.traceChildAsync(`process hosts: ${hostsUrl}`, async (span)=>{
|
||||||
|
const filterRules = await span.traceChild('download').tracePromise(downloadPromise);
|
||||||
|
const domainSets = [];
|
||||||
|
span.traceChild('parse hosts').traceSyncFn(()=>{
|
||||||
|
for(let i = 0, len = filterRules.length; i < len; i++){
|
||||||
|
hostsLineCb(filterRules[i], domainSets, includeAllSubDomain, hostsUrl);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return domainSets;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} (hosts.__exports));
|
||||||
|
return hosts.__exports;
|
||||||
|
}exports.__require=requireHosts;
|
||||||
52
Dist/Build/lib/parse-filter/shared.cjs
Normal file
52
Dist/Build/lib/parse-filter/shared.cjs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const shared=require('../../../_virtual/shared.cjs'),require$$0=require('picocolors'),rejectDataSource=require('../../constants/reject-data-source.cjs'),require$$2=require('foxts/noop');var hasRequiredShared;
|
||||||
|
|
||||||
|
function requireShared () {
|
||||||
|
if (hasRequiredShared) return shared.__exports;
|
||||||
|
hasRequiredShared = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
foundDebugDomain: function() {
|
||||||
|
return foundDebugDomain;
|
||||||
|
},
|
||||||
|
onBlackFound: function() {
|
||||||
|
return onBlackFound;
|
||||||
|
},
|
||||||
|
onWhiteFound: function() {
|
||||||
|
return onWhiteFound;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _rejectdatasource = /*@__PURE__*/ rejectDataSource.__require();
|
||||||
|
const _noop = require$$2;
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const foundDebugDomain = {
|
||||||
|
value: false
|
||||||
|
};
|
||||||
|
const onBlackFound = _rejectdatasource.DEBUG_DOMAIN_TO_FIND ? (line, meta)=>{
|
||||||
|
if (line.includes(_rejectdatasource.DEBUG_DOMAIN_TO_FIND)) {
|
||||||
|
console.warn(_picocolors.default.red(meta), '(black)', line.replaceAll(_rejectdatasource.DEBUG_DOMAIN_TO_FIND, _picocolors.default.bold(_rejectdatasource.DEBUG_DOMAIN_TO_FIND)));
|
||||||
|
foundDebugDomain.value = true;
|
||||||
|
}
|
||||||
|
} : _noop.noop;
|
||||||
|
const onWhiteFound = _rejectdatasource.DEBUG_DOMAIN_TO_FIND ? (line, meta)=>{
|
||||||
|
if (line.includes(_rejectdatasource.DEBUG_DOMAIN_TO_FIND)) {
|
||||||
|
console.warn(_picocolors.default.red(meta), '(white)', line.replaceAll(_rejectdatasource.DEBUG_DOMAIN_TO_FIND, _picocolors.default.bold(_rejectdatasource.DEBUG_DOMAIN_TO_FIND)));
|
||||||
|
foundDebugDomain.value = true;
|
||||||
|
}
|
||||||
|
} : _noop.noop;
|
||||||
|
} (shared.__exports));
|
||||||
|
return shared.__exports;
|
||||||
|
}exports.__require=requireShared;
|
||||||
79
Dist/Build/lib/process-line.cjs
Normal file
79
Dist/Build/lib/process-line.cjs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const processLine=require('../../_virtual/process-line.cjs'),require$$0=require('node:stream/web');var hasRequiredProcessLine;
|
||||||
|
|
||||||
|
function requireProcessLine () {
|
||||||
|
if (hasRequiredProcessLine) return processLine.__exports;
|
||||||
|
hasRequiredProcessLine = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
ProcessLineStream: function() {
|
||||||
|
return ProcessLineStream;
|
||||||
|
},
|
||||||
|
processLine: function() {
|
||||||
|
return processLine;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _web = require$$0;
|
||||||
|
function processLine(line) {
|
||||||
|
const trimmed = line.trim();
|
||||||
|
if (trimmed.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const line_0 = trimmed.charCodeAt(0);
|
||||||
|
if (// line_0 === 32 /** [space] */
|
||||||
|
// || line_0 === 13 /** \r */
|
||||||
|
// || line_0 === 10 /** \n */
|
||||||
|
line_0 === 33 /** ! */ || line_0 === 47 /** / */ && trimmed.charCodeAt(1) === 47 /** / */ ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (line_0 === 35 /** # */ ) {
|
||||||
|
if (trimmed.charCodeAt(1) !== 35 /** # */ ) {
|
||||||
|
// # Comment
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (trimmed.charCodeAt(2) === 35 /** # */ && trimmed.charCodeAt(3) === 35) {
|
||||||
|
// ################## EOF ##################
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* AdGuard Filter can be:
|
||||||
|
*
|
||||||
|
* ##.class
|
||||||
|
* ##tag.class
|
||||||
|
* ###id
|
||||||
|
*/ }
|
||||||
|
return trimmed;
|
||||||
|
}
|
||||||
|
class ProcessLineStream extends _web.TransformStream {
|
||||||
|
// private __buf = '';
|
||||||
|
constructor(){
|
||||||
|
super({
|
||||||
|
transform (l, controller) {
|
||||||
|
const line = processLine(l);
|
||||||
|
if (line) {
|
||||||
|
controller.enqueue(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} // export class ProcessLineNodeStream extends Transform {
|
||||||
|
// _transform(chunk: string, encoding: BufferEncoding, callback: TransformCallback) {
|
||||||
|
// // Convert chunk to string and then to uppercase
|
||||||
|
// const upperCased = chunk.toUpperCase();
|
||||||
|
// // Push transformed data to readable side
|
||||||
|
// this.push(upperCased);
|
||||||
|
// // Call callback when done
|
||||||
|
// callback();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
} (processLine.__exports));
|
||||||
|
return processLine.__exports;
|
||||||
|
}exports.__require=requireProcessLine;
|
||||||
469
Dist/Build/lib/rules/base.cjs
Normal file
469
Dist/Build/lib/rules/base.cjs
Normal file
@ -0,0 +1,469 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const base=require('../../../_virtual/base.cjs'),trie=require('../trie.cjs'),require$$6=require('foxts/guard'),require$$2=require('fast-cidr-tools'),require$$3=require('foxts/retrie'),require$$0=require('node:path'),surge=require('../writing-strategy/surge.cjs');var hasRequiredBase;
|
||||||
|
|
||||||
|
function requireBase () {
|
||||||
|
if (hasRequiredBase) return base.__exports;
|
||||||
|
hasRequiredBase = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "FileOutput", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return FileOutput;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _trie = /*@__PURE__*/ trie.__require();
|
||||||
|
const _guard = require$$6;
|
||||||
|
const _fastcidrtools = require$$2;
|
||||||
|
const _retrie = require$$3;
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _surge = /*@__PURE__*/ surge.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
class FileOutput {
|
||||||
|
id;
|
||||||
|
strategies;
|
||||||
|
domainTrie;
|
||||||
|
domainKeywords;
|
||||||
|
domainWildcard;
|
||||||
|
userAgent;
|
||||||
|
processName;
|
||||||
|
processPath;
|
||||||
|
urlRegex;
|
||||||
|
ipcidr;
|
||||||
|
ipcidrNoResolve;
|
||||||
|
ipasn;
|
||||||
|
ipasnNoResolve;
|
||||||
|
ipcidr6;
|
||||||
|
ipcidr6NoResolve;
|
||||||
|
geoip;
|
||||||
|
groipNoResolve;
|
||||||
|
sourceIpOrCidr;
|
||||||
|
sourcePort;
|
||||||
|
destPort;
|
||||||
|
otherRules;
|
||||||
|
pendingPromise;
|
||||||
|
whitelistDomain;
|
||||||
|
span;
|
||||||
|
constructor($span, id){
|
||||||
|
this.id = id;
|
||||||
|
this.strategies = [];
|
||||||
|
this.domainTrie = new _trie.HostnameSmolTrie(null);
|
||||||
|
this.domainKeywords = new Set();
|
||||||
|
this.domainWildcard = new Set();
|
||||||
|
this.userAgent = new Set();
|
||||||
|
this.processName = new Set();
|
||||||
|
this.processPath = new Set();
|
||||||
|
this.urlRegex = new Set();
|
||||||
|
this.ipcidr = new Set();
|
||||||
|
this.ipcidrNoResolve = new Set();
|
||||||
|
this.ipasn = new Set();
|
||||||
|
this.ipasnNoResolve = new Set();
|
||||||
|
this.ipcidr6 = new Set();
|
||||||
|
this.ipcidr6NoResolve = new Set();
|
||||||
|
this.geoip = new Set();
|
||||||
|
this.groipNoResolve = new Set();
|
||||||
|
this.sourceIpOrCidr = new Set();
|
||||||
|
this.sourcePort = new Set();
|
||||||
|
this.destPort = new Set();
|
||||||
|
this.otherRules = [];
|
||||||
|
this.pendingPromise = null;
|
||||||
|
this.whitelistDomain = (domain)=>{
|
||||||
|
this.domainTrie.whitelist(domain);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
this.title = null;
|
||||||
|
this.description = null;
|
||||||
|
this.date = new Date();
|
||||||
|
this.strategiesWritten = false;
|
||||||
|
this.span = $span.traceChild('RuleOutput#' + id);
|
||||||
|
}
|
||||||
|
title;
|
||||||
|
withTitle(title) {
|
||||||
|
this.title = title;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
withStrategies(strategies) {
|
||||||
|
this.strategies = strategies;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
withExtraStrategies(strategy) {
|
||||||
|
if (strategy) {
|
||||||
|
this.strategies.push(strategy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
description;
|
||||||
|
withDescription(description) {
|
||||||
|
this.description = description;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
date;
|
||||||
|
withDate(date) {
|
||||||
|
this.date = date;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
addDomain(domain) {
|
||||||
|
this.domainTrie.add(domain);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
bulkAddDomain(domains) {
|
||||||
|
let d;
|
||||||
|
for(let i = 0, len = domains.length; i < len; i++){
|
||||||
|
d = domains[i];
|
||||||
|
if (d !== null) {
|
||||||
|
this.domainTrie.add(d, false, null, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
addDomainSuffix(domain, lineFromDot = domain[0] === '.') {
|
||||||
|
this.domainTrie.add(domain, true, lineFromDot ? 1 : 0);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
bulkAddDomainSuffix(domains) {
|
||||||
|
for(let i = 0, len = domains.length; i < len; i++){
|
||||||
|
this.addDomainSuffix(domains[i]);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
addDomainKeyword(keyword) {
|
||||||
|
this.domainKeywords.add(keyword);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
addIPASN(asn) {
|
||||||
|
this.ipasn.add(asn);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
bulkAddIPASN(asns) {
|
||||||
|
for(let i = 0, len = asns.length; i < len; i++){
|
||||||
|
this.ipasn.add(asns[i]);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
async addFromDomainsetPromise(source) {
|
||||||
|
for await (const line of source){
|
||||||
|
if (line[0] === '.') {
|
||||||
|
this.addDomainSuffix(line, true);
|
||||||
|
} else {
|
||||||
|
this.domainTrie.add(line, false, null, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addFromDomainset(source) {
|
||||||
|
if (this.pendingPromise) {
|
||||||
|
if ('then' in source) {
|
||||||
|
this.pendingPromise = this.pendingPromise.then(()=>source).then((src)=>this.addFromDomainsetPromise(src));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
this.pendingPromise = this.pendingPromise.then(()=>this.addFromDomainsetPromise(source));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
if ('then' in source) {
|
||||||
|
this.pendingPromise = source.then((src)=>this.addFromDomainsetPromise(src));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
this.pendingPromise = this.addFromDomainsetPromise(source);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
async addFromRulesetPromise(source) {
|
||||||
|
for await (const line of source){
|
||||||
|
const splitted = line.split(',');
|
||||||
|
const type = splitted[0];
|
||||||
|
const value = splitted[1];
|
||||||
|
const arg = splitted[2];
|
||||||
|
switch(type){
|
||||||
|
case 'DOMAIN':
|
||||||
|
this.domainTrie.add(value, false, null, 0);
|
||||||
|
break;
|
||||||
|
case 'DOMAIN-SUFFIX':
|
||||||
|
this.addDomainSuffix(value, false);
|
||||||
|
break;
|
||||||
|
case 'DOMAIN-KEYWORD':
|
||||||
|
this.addDomainKeyword(value);
|
||||||
|
break;
|
||||||
|
case 'DOMAIN-WILDCARD':
|
||||||
|
this.domainWildcard.add(value);
|
||||||
|
break;
|
||||||
|
case 'USER-AGENT':
|
||||||
|
this.userAgent.add(value);
|
||||||
|
break;
|
||||||
|
case 'PROCESS-NAME':
|
||||||
|
if (value.includes('/') || value.includes('\\')) {
|
||||||
|
this.processPath.add(value);
|
||||||
|
} else {
|
||||||
|
this.processName.add(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'URL-REGEX':
|
||||||
|
{
|
||||||
|
const [, ...rest] = splitted;
|
||||||
|
this.urlRegex.add(rest.join(','));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'IP-CIDR':
|
||||||
|
(arg === 'no-resolve' ? this.ipcidrNoResolve : this.ipcidr).add(value);
|
||||||
|
break;
|
||||||
|
case 'IP-CIDR6':
|
||||||
|
(arg === 'no-resolve' ? this.ipcidr6NoResolve : this.ipcidr6).add(value);
|
||||||
|
break;
|
||||||
|
case 'IP-ASN':
|
||||||
|
(arg === 'no-resolve' ? this.ipasnNoResolve : this.ipasn).add(value);
|
||||||
|
break;
|
||||||
|
case 'GEOIP':
|
||||||
|
(arg === 'no-resolve' ? this.groipNoResolve : this.geoip).add(value);
|
||||||
|
break;
|
||||||
|
case 'SRC-IP':
|
||||||
|
this.sourceIpOrCidr.add(value);
|
||||||
|
break;
|
||||||
|
case 'SRC-PORT':
|
||||||
|
this.sourcePort.add(value);
|
||||||
|
break;
|
||||||
|
case 'DEST-PORT':
|
||||||
|
this.destPort.add(value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.otherRules.push(line);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addFromRuleset(source) {
|
||||||
|
if (this.pendingPromise) {
|
||||||
|
if ('then' in source) {
|
||||||
|
this.pendingPromise = this.pendingPromise.then(()=>source).then((src)=>this.addFromRulesetPromise(src));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
this.pendingPromise = this.pendingPromise.then(()=>this.addFromRulesetPromise(source));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
if ('then' in source) {
|
||||||
|
this.pendingPromise = source.then((src)=>this.addFromRulesetPromise(src));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
this.pendingPromise = this.addFromRulesetPromise(source);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
static ipToCidr = (ip, version)=>{
|
||||||
|
if (ip.includes('/')) return ip;
|
||||||
|
if (version === 4) {
|
||||||
|
return ip + '/32';
|
||||||
|
}
|
||||||
|
return ip + '/128';
|
||||||
|
};
|
||||||
|
bulkAddCIDR4(cidrs) {
|
||||||
|
for(let i = 0, len = cidrs.length; i < len; i++){
|
||||||
|
this.ipcidr.add(FileOutput.ipToCidr(cidrs[i], 4));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
bulkAddCIDR4NoResolve(cidrs) {
|
||||||
|
for(let i = 0, len = cidrs.length; i < len; i++){
|
||||||
|
this.ipcidrNoResolve.add(FileOutput.ipToCidr(cidrs[i], 4));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
bulkAddCIDR6(cidrs) {
|
||||||
|
for(let i = 0, len = cidrs.length; i < len; i++){
|
||||||
|
this.ipcidr6.add(FileOutput.ipToCidr(cidrs[i], 6));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
bulkAddCIDR6NoResolve(cidrs) {
|
||||||
|
for(let i = 0, len = cidrs.length; i < len; i++){
|
||||||
|
this.ipcidr6NoResolve.add(FileOutput.ipToCidr(cidrs[i], 6));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
async done() {
|
||||||
|
await this.pendingPromise;
|
||||||
|
this.pendingPromise = null;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
// private guardPendingPromise() {
|
||||||
|
// // reverse invariant
|
||||||
|
// if (this.pendingPromise !== null) {
|
||||||
|
// console.trace('Pending promise:', this.pendingPromise);
|
||||||
|
// throw new Error('You should call done() before calling this method');
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// async writeClash(outputDir?: null | string) {
|
||||||
|
// await this.done();
|
||||||
|
// invariant(this.title, 'Missing title');
|
||||||
|
// invariant(this.description, 'Missing description');
|
||||||
|
// return compareAndWriteFile(
|
||||||
|
// this.span,
|
||||||
|
// withBannerArray(
|
||||||
|
// this.title,
|
||||||
|
// this.description,
|
||||||
|
// this.date,
|
||||||
|
// this.clash()
|
||||||
|
// ),
|
||||||
|
// path.join(outputDir ?? OUTPUT_CLASH_DIR, this.type, this.id + '.txt')
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
strategiesWritten;
|
||||||
|
writeToStrategies() {
|
||||||
|
if (this.pendingPromise) {
|
||||||
|
throw new Error('You should call done() before calling writeToStrategies()');
|
||||||
|
}
|
||||||
|
if (this.strategiesWritten) {
|
||||||
|
throw new Error('Strategies already written');
|
||||||
|
}
|
||||||
|
this.strategiesWritten = true;
|
||||||
|
const kwfilter = (0, _retrie.createRetrieKeywordFilter)(Array.from(this.domainKeywords));
|
||||||
|
if (this.strategies.filter((0, _guard.not)(false)).length === 0) {
|
||||||
|
throw new Error('No strategies to write ' + this.id);
|
||||||
|
}
|
||||||
|
this.domainTrie.dumpWithoutDot((domain, includeAllSubdomain)=>{
|
||||||
|
if (kwfilter(domain)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(let i = 0, len = this.strategies.length; i < len; i++){
|
||||||
|
const strategy = this.strategies[i];
|
||||||
|
if (strategy) {
|
||||||
|
if (includeAllSubdomain) {
|
||||||
|
strategy.writeDomainSuffix(domain);
|
||||||
|
} else {
|
||||||
|
strategy.writeDomain(domain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
for(let i = 0, len = this.strategies.length; i < len; i++){
|
||||||
|
const strategy = this.strategies[i];
|
||||||
|
if (!strategy) continue;
|
||||||
|
if (this.domainKeywords.size) {
|
||||||
|
strategy.writeDomainKeywords(this.domainKeywords);
|
||||||
|
}
|
||||||
|
if (this.domainWildcard.size) {
|
||||||
|
strategy.writeDomainWildcards(this.domainWildcard);
|
||||||
|
}
|
||||||
|
if (this.userAgent.size) {
|
||||||
|
strategy.writeUserAgents(this.userAgent);
|
||||||
|
}
|
||||||
|
if (this.processName.size) {
|
||||||
|
strategy.writeProcessNames(this.processName);
|
||||||
|
}
|
||||||
|
if (this.processPath.size) {
|
||||||
|
strategy.writeProcessPaths(this.processPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.sourceIpOrCidr.size) {
|
||||||
|
const sourceIpOrCidr = Array.from(this.sourceIpOrCidr);
|
||||||
|
for(let i = 0, len = this.strategies.length; i < len; i++){
|
||||||
|
const strategy = this.strategies[i];
|
||||||
|
if (strategy) {
|
||||||
|
strategy.writeSourceIpCidrs(sourceIpOrCidr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(let i = 0, len = this.strategies.length; i < len; i++){
|
||||||
|
const strategy = this.strategies[i];
|
||||||
|
if (strategy) {
|
||||||
|
if (this.sourcePort.size) {
|
||||||
|
strategy.writeSourcePorts(this.sourcePort);
|
||||||
|
}
|
||||||
|
if (this.destPort.size) {
|
||||||
|
strategy.writeDestinationPorts(this.destPort);
|
||||||
|
}
|
||||||
|
if (this.otherRules.length) {
|
||||||
|
strategy.writeOtherRules(this.otherRules);
|
||||||
|
}
|
||||||
|
if (this.urlRegex.size) {
|
||||||
|
strategy.writeUrlRegexes(this.urlRegex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let ipcidr = null;
|
||||||
|
let ipcidrNoResolve = null;
|
||||||
|
let ipcidr6 = null;
|
||||||
|
let ipcidr6NoResolve = null;
|
||||||
|
if (this.ipcidr.size) {
|
||||||
|
ipcidr = (0, _fastcidrtools.merge)(Array.from(this.ipcidr), true);
|
||||||
|
}
|
||||||
|
if (this.ipcidrNoResolve.size) {
|
||||||
|
ipcidrNoResolve = (0, _fastcidrtools.merge)(Array.from(this.ipcidrNoResolve), true);
|
||||||
|
}
|
||||||
|
if (this.ipcidr6.size) {
|
||||||
|
ipcidr6 = Array.from(this.ipcidr6);
|
||||||
|
}
|
||||||
|
if (this.ipcidr6NoResolve.size) {
|
||||||
|
ipcidr6NoResolve = Array.from(this.ipcidr6NoResolve);
|
||||||
|
}
|
||||||
|
for(let i = 0, len = this.strategies.length; i < len; i++){
|
||||||
|
const strategy = this.strategies[i];
|
||||||
|
if (strategy) {
|
||||||
|
// no-resolve
|
||||||
|
if (ipcidrNoResolve?.length) {
|
||||||
|
strategy.writeIpCidrs(ipcidrNoResolve, true);
|
||||||
|
}
|
||||||
|
if (ipcidr6NoResolve?.length) {
|
||||||
|
strategy.writeIpCidr6s(ipcidr6NoResolve, true);
|
||||||
|
}
|
||||||
|
if (this.ipasnNoResolve.size) {
|
||||||
|
strategy.writeIpAsns(this.ipasnNoResolve, true);
|
||||||
|
}
|
||||||
|
if (this.groipNoResolve.size) {
|
||||||
|
strategy.writeGeoip(this.groipNoResolve, true);
|
||||||
|
}
|
||||||
|
// triggers DNS resolution
|
||||||
|
if (ipcidr?.length) {
|
||||||
|
strategy.writeIpCidrs(ipcidr, false);
|
||||||
|
}
|
||||||
|
if (ipcidr6?.length) {
|
||||||
|
strategy.writeIpCidr6s(ipcidr6, false);
|
||||||
|
}
|
||||||
|
if (this.ipasn.size) {
|
||||||
|
strategy.writeIpAsns(this.ipasn, false);
|
||||||
|
}
|
||||||
|
if (this.geoip.size) {
|
||||||
|
strategy.writeGeoip(this.geoip, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
write() {
|
||||||
|
return this.span.traceChildAsync('write all', async (childSpan)=>{
|
||||||
|
await this.done();
|
||||||
|
childSpan.traceChildSync('write to strategies', this.writeToStrategies.bind(this));
|
||||||
|
return childSpan.traceChildAsync('output to disk', (childSpan)=>{
|
||||||
|
const promises = [];
|
||||||
|
(0, _guard.invariant)(this.title, 'Missing title');
|
||||||
|
(0, _guard.invariant)(this.description, 'Missing description');
|
||||||
|
for(let i = 0, len = this.strategies.length; i < len; i++){
|
||||||
|
const strategy = this.strategies[i];
|
||||||
|
if (strategy) {
|
||||||
|
const basename = (strategy.overwriteFilename || this.id) + '.' + strategy.fileExtension;
|
||||||
|
promises.push(strategy.output(childSpan, this.title, this.description, this.date, _nodepath.default.join(strategy.outputDir, strategy.type ? _nodepath.default.join(strategy.type, basename) : basename)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.all(promises);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async compile() {
|
||||||
|
await this.done();
|
||||||
|
this.writeToStrategies();
|
||||||
|
return this.strategies.reduce((acc, strategy)=>{
|
||||||
|
if (strategy) {
|
||||||
|
acc.push(strategy.content);
|
||||||
|
} else {
|
||||||
|
acc.push(null);
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
withMitmSgmodulePath(moduleName) {
|
||||||
|
if (moduleName) {
|
||||||
|
this.withExtraStrategies(new _surge.SurgeMitmSgmodule(moduleName));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} (base.__exports));
|
||||||
|
return base.__exports;
|
||||||
|
}exports.__require=requireBase;
|
||||||
47
Dist/Build/lib/rules/domainset.cjs
Normal file
47
Dist/Build/lib/rules/domainset.cjs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const domainset=require('../../../_virtual/domainset.cjs'),adguardhome=require('../writing-strategy/adguardhome.cjs'),clash=require('../writing-strategy/clash.cjs'),singbox=require('../writing-strategy/singbox.cjs'),surge=require('../writing-strategy/surge.cjs'),base=require('./base.cjs');var hasRequiredDomainset;
|
||||||
|
|
||||||
|
function requireDomainset () {
|
||||||
|
if (hasRequiredDomainset) return domainset.__exports;
|
||||||
|
hasRequiredDomainset = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
AdGuardHomeOutput: function() {
|
||||||
|
return AdGuardHomeOutput;
|
||||||
|
},
|
||||||
|
DomainsetOutput: function() {
|
||||||
|
return DomainsetOutput;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _adguardhome = /*@__PURE__*/ adguardhome.__require();
|
||||||
|
const _clash = /*@__PURE__*/ clash.__require();
|
||||||
|
const _singbox = /*@__PURE__*/ singbox.__require();
|
||||||
|
const _surge = /*@__PURE__*/ surge.__require();
|
||||||
|
const _base = /*@__PURE__*/ base.__require();
|
||||||
|
class DomainsetOutput extends _base.FileOutput {
|
||||||
|
strategies = [
|
||||||
|
new _surge.SurgeDomainSet(),
|
||||||
|
new _clash.ClashDomainSet(),
|
||||||
|
new _singbox.SingboxSource('domainset')
|
||||||
|
];
|
||||||
|
}
|
||||||
|
class AdGuardHomeOutput extends _base.FileOutput {
|
||||||
|
strategies;
|
||||||
|
constructor(span, id, outputDir){
|
||||||
|
super(span, id);
|
||||||
|
this.strategies = [
|
||||||
|
new _adguardhome.AdGuardHome(outputDir)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} (domainset.__exports));
|
||||||
|
return domainset.__exports;
|
||||||
|
}exports.__require=requireDomainset;
|
||||||
34
Dist/Build/lib/rules/ip.cjs
Normal file
34
Dist/Build/lib/rules/ip.cjs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const ip=require('../../../_virtual/ip.cjs'),clash=require('../writing-strategy/clash.cjs'),singbox=require('../writing-strategy/singbox.cjs'),surge=require('../writing-strategy/surge.cjs'),base=require('./base.cjs');var hasRequiredIp;
|
||||||
|
|
||||||
|
function requireIp () {
|
||||||
|
if (hasRequiredIp) return ip.__exports;
|
||||||
|
hasRequiredIp = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "IPListOutput", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return IPListOutput;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _clash = /*@__PURE__*/ clash.__require();
|
||||||
|
const _singbox = /*@__PURE__*/ singbox.__require();
|
||||||
|
const _surge = /*@__PURE__*/ surge.__require();
|
||||||
|
const _base = /*@__PURE__*/ base.__require();
|
||||||
|
class IPListOutput extends _base.FileOutput {
|
||||||
|
clashUseRule;
|
||||||
|
strategies;
|
||||||
|
constructor(span, id, clashUseRule = true){
|
||||||
|
super(span, id), this.clashUseRule = clashUseRule;
|
||||||
|
this.strategies = [
|
||||||
|
new _surge.SurgeRuleSet('ip'),
|
||||||
|
this.clashUseRule ? new _clash.ClashClassicRuleSet('ip') : new _clash.ClashIPSet(),
|
||||||
|
new _singbox.SingboxSource('ip')
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} (ip.__exports));
|
||||||
|
return ip.__exports;
|
||||||
|
}exports.__require=requireIp;
|
||||||
59
Dist/Build/lib/rules/ruleset.cjs
Normal file
59
Dist/Build/lib/rules/ruleset.cjs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const ruleset=require('../../../_virtual/ruleset.cjs'),clash=require('../writing-strategy/clash.cjs'),singbox=require('../writing-strategy/singbox.cjs'),surge=require('../writing-strategy/surge.cjs'),base=require('./base.cjs');var hasRequiredRuleset;
|
||||||
|
|
||||||
|
function requireRuleset () {
|
||||||
|
if (hasRequiredRuleset) return ruleset.__exports;
|
||||||
|
hasRequiredRuleset = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
ClashOnlyRulesetOutput: function() {
|
||||||
|
return ClashOnlyRulesetOutput;
|
||||||
|
},
|
||||||
|
RulesetOutput: function() {
|
||||||
|
return RulesetOutput;
|
||||||
|
},
|
||||||
|
SurgeOnlyRulesetOutput: function() {
|
||||||
|
return SurgeOnlyRulesetOutput;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _clash = /*@__PURE__*/ clash.__require();
|
||||||
|
const _singbox = /*@__PURE__*/ singbox.__require();
|
||||||
|
const _surge = /*@__PURE__*/ surge.__require();
|
||||||
|
const _base = /*@__PURE__*/ base.__require();
|
||||||
|
class RulesetOutput extends _base.FileOutput {
|
||||||
|
constructor(span, id, type){
|
||||||
|
super(span, id);
|
||||||
|
this.strategies = [
|
||||||
|
new _surge.SurgeRuleSet(type),
|
||||||
|
new _clash.ClashClassicRuleSet(type),
|
||||||
|
new _singbox.SingboxSource(type)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class SurgeOnlyRulesetOutput extends _base.FileOutput {
|
||||||
|
constructor(span, id, type, overrideOutputDir){
|
||||||
|
super(span, id);
|
||||||
|
this.strategies = [
|
||||||
|
new _surge.SurgeRuleSet(type, overrideOutputDir)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class ClashOnlyRulesetOutput extends _base.FileOutput {
|
||||||
|
constructor(span, id, type){
|
||||||
|
super(span, id);
|
||||||
|
this.strategies = [
|
||||||
|
new _clash.ClashClassicRuleSet(type)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} (ruleset.__exports));
|
||||||
|
return ruleset.__exports;
|
||||||
|
}exports.__require=requireRuleset;
|
||||||
65
Dist/Build/lib/text-line-transform-stream.cjs
Normal file
65
Dist/Build/lib/text-line-transform-stream.cjs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const textLineTransformStream=require('../../_virtual/text-line-transform-stream.cjs'),require$$0=require('node:stream/web');var hasRequiredTextLineTransformStream;
|
||||||
|
|
||||||
|
function requireTextLineTransformStream () {
|
||||||
|
if (hasRequiredTextLineTransformStream) return textLineTransformStream.__exports;
|
||||||
|
hasRequiredTextLineTransformStream = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "TextLineStream", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return TextLineStream;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _web = require$$0;
|
||||||
|
class TextLineStream extends _web.TransformStream {
|
||||||
|
// private __buf = '';
|
||||||
|
constructor({ allowCR = false } = {}){
|
||||||
|
let __buf = '';
|
||||||
|
let chunkIndex = 0;
|
||||||
|
super({
|
||||||
|
transform (chunk, controller) {
|
||||||
|
chunk = __buf + chunk;
|
||||||
|
chunkIndex = 0;
|
||||||
|
for(;;){
|
||||||
|
const lfIndex = chunk.indexOf('\n', chunkIndex);
|
||||||
|
if (allowCR) {
|
||||||
|
const crIndex = chunk.indexOf('\r', chunkIndex);
|
||||||
|
if (crIndex !== -1 && crIndex !== chunk.length - 1 && (lfIndex === -1 || lfIndex - 1 > crIndex)) {
|
||||||
|
controller.enqueue(chunk.slice(chunkIndex, crIndex));
|
||||||
|
chunkIndex = crIndex + 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lfIndex === -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// enqueue current line, and loop again to find next line
|
||||||
|
let crOrLfIndex = lfIndex;
|
||||||
|
if (chunk[lfIndex - 1] === '\r') {
|
||||||
|
crOrLfIndex--;
|
||||||
|
}
|
||||||
|
controller.enqueue(chunk.slice(chunkIndex, crOrLfIndex));
|
||||||
|
chunkIndex = lfIndex + 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
__buf = chunk.slice(chunkIndex);
|
||||||
|
},
|
||||||
|
flush (controller) {
|
||||||
|
if (__buf.length > 0) {
|
||||||
|
// eslint-disable-next-line sukka/string/prefer-string-starts-ends-with -- performance
|
||||||
|
if (allowCR && __buf[__buf.length - 1] === '\r') {
|
||||||
|
controller.enqueue(__buf.slice(0, -1));
|
||||||
|
} else {
|
||||||
|
controller.enqueue(__buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} (textLineTransformStream.__exports));
|
||||||
|
return textLineTransformStream.__exports;
|
||||||
|
}exports.__require=requireTextLineTransformStream;
|
||||||
75
Dist/Build/lib/tree-dir.cjs
Normal file
75
Dist/Build/lib/tree-dir.cjs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const treeDir=require('../../_virtual/tree-dir.cjs'),require$$2=require('node:fs/promises'),require$$0=require('node:path');var hasRequiredTreeDir;
|
||||||
|
|
||||||
|
function requireTreeDir () {
|
||||||
|
if (hasRequiredTreeDir) return treeDir.__exports;
|
||||||
|
hasRequiredTreeDir = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
TreeFileType: function() {
|
||||||
|
return TreeFileType;
|
||||||
|
},
|
||||||
|
treeDir: function() {
|
||||||
|
return treeDir;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _promises = /*#__PURE__*/ _interop_require_default(require$$2);
|
||||||
|
const _nodepath = require$$0;
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var TreeFileType = /*#__PURE__*/ function(TreeFileType) {
|
||||||
|
TreeFileType[TreeFileType["FILE"] = 1] = "FILE";
|
||||||
|
TreeFileType[TreeFileType["DIRECTORY"] = 2] = "DIRECTORY";
|
||||||
|
return TreeFileType;
|
||||||
|
}({});
|
||||||
|
async function treeDir(rootPath) {
|
||||||
|
const tree = [];
|
||||||
|
const walk = async (dir, node, dirRelativeToRoot = '')=>{
|
||||||
|
const promises = [];
|
||||||
|
for await (const child of (await _promises.default.opendir(dir))){
|
||||||
|
// Ignore hidden files
|
||||||
|
if (child.name[0] === '.' || child.name === 'CNAME') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const childFullPath = child.parentPath + _nodepath.sep + child.name;
|
||||||
|
const childRelativeToRoot = dirRelativeToRoot + _nodepath.sep + child.name;
|
||||||
|
if (child.isDirectory()) {
|
||||||
|
const newNode = {
|
||||||
|
type: 2,
|
||||||
|
name: child.name,
|
||||||
|
path: childRelativeToRoot,
|
||||||
|
children: []
|
||||||
|
};
|
||||||
|
node.push(newNode);
|
||||||
|
promises.push(walk(childFullPath, newNode.children, childRelativeToRoot));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (child.isFile()) {
|
||||||
|
const newNode = {
|
||||||
|
type: 1,
|
||||||
|
name: child.name,
|
||||||
|
path: childRelativeToRoot
|
||||||
|
};
|
||||||
|
node.push(newNode);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.all(promises);
|
||||||
|
};
|
||||||
|
await walk(rootPath, tree);
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
} (treeDir.__exports));
|
||||||
|
return treeDir.__exports;
|
||||||
|
}exports.__require=requireTreeDir;
|
||||||
540
Dist/Build/lib/trie.cjs
Normal file
540
Dist/Build/lib/trie.cjs
Normal file
@ -0,0 +1,540 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const trie=require('../../_virtual/trie.cjs'),misc=require('./misc.cjs'),require$$1=require('node:util'),require$$2=require('foxts/noop'),require$$3=require('foxts/fast-string-array-join'),require$$4=require('foxts/bitwise');/**
|
||||||
|
* Hostbane-Optimized Trie based on Mnemonist Trie
|
||||||
|
*/
|
||||||
|
|
||||||
|
var hasRequiredTrie;
|
||||||
|
|
||||||
|
function requireTrie () {
|
||||||
|
if (hasRequiredTrie) return trie.__exports;
|
||||||
|
hasRequiredTrie = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
HostnameSmolTrie: function() {
|
||||||
|
return HostnameSmolTrie;
|
||||||
|
},
|
||||||
|
HostnameTrie: function() {
|
||||||
|
return HostnameTrie;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _misc = /*@__PURE__*/ misc.__require();
|
||||||
|
const _nodeutil = /*#__PURE__*/ _interop_require_default(require$$1);
|
||||||
|
const _noop = require$$2;
|
||||||
|
const _faststringarrayjoin = require$$3;
|
||||||
|
const _bitwise = require$$4;
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var _computedKey;
|
||||||
|
const START = 1 << 1;
|
||||||
|
const INCLUDE_ALL_SUBDOMAIN = 1 << 2;
|
||||||
|
function deepTrieNodeToJSON(node, unpackMeta) {
|
||||||
|
const obj = {};
|
||||||
|
obj['[start]'] = (0, _bitwise.getBit)(node[0], START);
|
||||||
|
obj['[subdomain]'] = (0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN);
|
||||||
|
if (node[3] != null) {
|
||||||
|
if (unpackMeta) {
|
||||||
|
obj['[meta]'] = unpackMeta(node[3]);
|
||||||
|
} else {
|
||||||
|
obj['[meta]'] = node[3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node[2].forEach((value, key)=>{
|
||||||
|
obj[key] = deepTrieNodeToJSON(value, unpackMeta);
|
||||||
|
});
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
const createNode = (parent = null)=>[
|
||||||
|
1,
|
||||||
|
parent,
|
||||||
|
new Map(),
|
||||||
|
null
|
||||||
|
];
|
||||||
|
function hostnameToTokens(hostname, hostnameFromIndex) {
|
||||||
|
const tokens = hostname.split('.');
|
||||||
|
const results = [];
|
||||||
|
let token = '';
|
||||||
|
for(let i = hostnameFromIndex, l = tokens.length; i < l; i++){
|
||||||
|
token = tokens[i];
|
||||||
|
if (token.length > 0) {
|
||||||
|
results.push(token);
|
||||||
|
} else {
|
||||||
|
throw new TypeError(JSON.stringify({
|
||||||
|
hostname,
|
||||||
|
hostnameFromIndex
|
||||||
|
}, null, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
function walkHostnameTokens(hostname, onToken, hostnameFromIndex) {
|
||||||
|
const tokens = hostname.split('.');
|
||||||
|
const l = tokens.length - 1;
|
||||||
|
// we are at the first of hostname, no splitor there
|
||||||
|
let token = '';
|
||||||
|
for(let i = l; i >= hostnameFromIndex; i--){
|
||||||
|
token = tokens[i];
|
||||||
|
if (token.length > 0) {
|
||||||
|
const t = onToken(token);
|
||||||
|
if (t === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// if the callback returns true, we should skip the rest
|
||||||
|
if (t) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_computedKey = _nodeutil.default.inspect.custom;
|
||||||
|
class Triebase {
|
||||||
|
$root = createNode();
|
||||||
|
$size = 0;
|
||||||
|
get root() {
|
||||||
|
return this.$root;
|
||||||
|
}
|
||||||
|
constructor(from){
|
||||||
|
// Actually build trie
|
||||||
|
if (Array.isArray(from)) {
|
||||||
|
for(let i = 0, l = from.length; i < l; i++){
|
||||||
|
this.add(from[i]);
|
||||||
|
}
|
||||||
|
} else if (from) {
|
||||||
|
from.forEach((value)=>this.add(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
walkIntoLeafWithTokens(tokens, onLoop = _noop.noop) {
|
||||||
|
let node = this.$root;
|
||||||
|
let parent = node;
|
||||||
|
let token;
|
||||||
|
let child = node[2];
|
||||||
|
// reverse lookup from end to start
|
||||||
|
for(let i = tokens.length - 1; i >= 0; i--){
|
||||||
|
token = tokens[i];
|
||||||
|
// if (token === '') {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
parent = node;
|
||||||
|
child = node[2];
|
||||||
|
// cache node index access is 20% faster than direct access when doing twice
|
||||||
|
if (child.has(token)) {
|
||||||
|
node = child.get(token);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
onLoop(node, parent, token);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
node,
|
||||||
|
parent
|
||||||
|
};
|
||||||
|
}
|
||||||
|
walkIntoLeafWithSuffix(suffix, hostnameFromIndex, onLoop = _noop.noop) {
|
||||||
|
let node = this.$root;
|
||||||
|
let parent = node;
|
||||||
|
let child = node[2];
|
||||||
|
const onToken = (token)=>{
|
||||||
|
// if (token === '') {
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
parent = node;
|
||||||
|
child = node[2];
|
||||||
|
if (child.has(token)) {
|
||||||
|
node = child.get(token);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
onLoop(node, parent, token);
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
if (walkHostnameTokens(suffix, onToken, hostnameFromIndex) === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
node,
|
||||||
|
parent
|
||||||
|
};
|
||||||
|
}
|
||||||
|
contains(suffix, includeAllSubdomain = suffix[0] === '.') {
|
||||||
|
const hostnameFromIndex = suffix[0] === '.' ? 1 : 0;
|
||||||
|
const res = this.walkIntoLeafWithSuffix(suffix, hostnameFromIndex);
|
||||||
|
if (!res) return false;
|
||||||
|
if (includeAllSubdomain) return (0, _bitwise.getBit)(res.node[0], INCLUDE_ALL_SUBDOMAIN);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
static bfsResults = [
|
||||||
|
null,
|
||||||
|
[]
|
||||||
|
];
|
||||||
|
static dfs(nodeStack, suffixStack) {
|
||||||
|
const node = nodeStack.pop();
|
||||||
|
const suffix = suffixStack.pop();
|
||||||
|
node[2].forEach((childNode, k)=>{
|
||||||
|
// Pushing the child node to the stack for next iteration of DFS
|
||||||
|
nodeStack.push(childNode);
|
||||||
|
suffixStack.push([
|
||||||
|
k,
|
||||||
|
...suffix
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
Triebase.bfsResults[0] = node;
|
||||||
|
Triebase.bfsResults[1] = suffix;
|
||||||
|
return Triebase.bfsResults;
|
||||||
|
}
|
||||||
|
static dfsWithSort(nodeStack, suffixStack) {
|
||||||
|
const node = nodeStack.pop();
|
||||||
|
const suffix = suffixStack.pop();
|
||||||
|
const child = node[2];
|
||||||
|
if (child.size) {
|
||||||
|
const keys = Array.from(child.keys()).sort(Triebase.compare);
|
||||||
|
for(let i = 0, l = keys.length; i < l; i++){
|
||||||
|
const key = keys[i];
|
||||||
|
const childNode = child.get(key);
|
||||||
|
// Pushing the child node to the stack for next iteration of DFS
|
||||||
|
nodeStack.push(childNode);
|
||||||
|
suffixStack.push([
|
||||||
|
key,
|
||||||
|
...suffix
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Triebase.bfsResults[0] = node;
|
||||||
|
Triebase.bfsResults[1] = suffix;
|
||||||
|
return Triebase.bfsResults;
|
||||||
|
}
|
||||||
|
walk(onMatches, initialNode = this.$root, initialSuffix = [], withSort = false) {
|
||||||
|
const bfsImpl = withSort ? Triebase.dfsWithSort : Triebase.dfs;
|
||||||
|
const nodeStack = [];
|
||||||
|
nodeStack.push(initialNode);
|
||||||
|
// Resolving initial string (begin the start of the stack)
|
||||||
|
const suffixStack = [];
|
||||||
|
suffixStack.push(initialSuffix);
|
||||||
|
let node = initialNode;
|
||||||
|
let r;
|
||||||
|
do {
|
||||||
|
r = bfsImpl(nodeStack, suffixStack);
|
||||||
|
node = r[0];
|
||||||
|
const suffix = r[1];
|
||||||
|
// If the node is a sentinel, we push the suffix to the results
|
||||||
|
if ((0, _bitwise.getBit)(node[0], START)) {
|
||||||
|
onMatches(suffix, (0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN), node[3]);
|
||||||
|
}
|
||||||
|
}while (nodeStack.length)
|
||||||
|
}
|
||||||
|
static compare(a, b) {
|
||||||
|
if (a === b) return 0;
|
||||||
|
return a.length - b.length || (0, _misc.fastStringCompare)(a, b);
|
||||||
|
}
|
||||||
|
walkWithSort(onMatches, initialNode = this.$root, initialSuffix = []) {
|
||||||
|
const nodeStack = [];
|
||||||
|
nodeStack.push(initialNode);
|
||||||
|
// Resolving initial string (begin the start of the stack)
|
||||||
|
const suffixStack = [];
|
||||||
|
suffixStack.push(initialSuffix);
|
||||||
|
let node = initialNode;
|
||||||
|
let child = node[2];
|
||||||
|
do {
|
||||||
|
node = nodeStack.pop();
|
||||||
|
const suffix = suffixStack.pop();
|
||||||
|
child = node[2];
|
||||||
|
if (child.size) {
|
||||||
|
const keys = Array.from(child.keys()).sort(Triebase.compare);
|
||||||
|
for(let i = 0, l = keys.length; i < l; i++){
|
||||||
|
const key = keys[i];
|
||||||
|
const childNode = child.get(key);
|
||||||
|
// Pushing the child node to the stack for next iteration of DFS
|
||||||
|
nodeStack.push(childNode);
|
||||||
|
suffixStack.push([
|
||||||
|
key,
|
||||||
|
...suffix
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If the node is a sentinel, we push the suffix to the results
|
||||||
|
if ((0, _bitwise.getBit)(node[0], START)) {
|
||||||
|
onMatches(suffix, (0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN), node[3]);
|
||||||
|
}
|
||||||
|
}while (nodeStack.length)
|
||||||
|
}
|
||||||
|
getSingleChildLeaf(tokens) {
|
||||||
|
let toPrune = null;
|
||||||
|
let tokenToPrune = null;
|
||||||
|
const onLoop = (node, parent, token)=>{
|
||||||
|
// Keeping track of a potential branch to prune
|
||||||
|
const child = node[2];
|
||||||
|
// console.log({
|
||||||
|
// child, parent, token
|
||||||
|
// });
|
||||||
|
// console.log(this.inspect(0));
|
||||||
|
if (toPrune !== null) {
|
||||||
|
if (child.size > 1) {
|
||||||
|
// The branch has some children, the branch need retain.
|
||||||
|
// And we need to abort prune that parent branch, so we set it to null
|
||||||
|
toPrune = null;
|
||||||
|
tokenToPrune = null;
|
||||||
|
}
|
||||||
|
} else if (child.size < 1) {
|
||||||
|
// There is only one token child, or no child at all, we can prune it safely
|
||||||
|
// It is now the top-est branch that could potentially being pruned
|
||||||
|
toPrune = parent;
|
||||||
|
tokenToPrune = token;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const res = this.walkIntoLeafWithTokens(tokens, onLoop);
|
||||||
|
if (res === null) return null;
|
||||||
|
return {
|
||||||
|
node: res.node,
|
||||||
|
toPrune,
|
||||||
|
tokenToPrune,
|
||||||
|
parent: res.parent
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Method used to retrieve every item in the trie with the given prefix.
|
||||||
|
*/ find(inputSuffix, subdomainOnly = inputSuffix[0] === '.', hostnameFromIndex = inputSuffix[0] === '.' ? 1 : 0) {
|
||||||
|
const inputTokens = hostnameToTokens(inputSuffix, hostnameFromIndex);
|
||||||
|
const res = this.walkIntoLeafWithTokens(inputTokens);
|
||||||
|
if (res === null) return [];
|
||||||
|
const results = [];
|
||||||
|
const onMatches = subdomainOnly ? (suffix, subdomain)=>{
|
||||||
|
const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.');
|
||||||
|
if (!subdomain && subStringEqual(inputSuffix, d, 1)) return;
|
||||||
|
results.push(subdomain ? '.' + d : d);
|
||||||
|
} : (suffix, subdomain)=>{
|
||||||
|
const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.');
|
||||||
|
results.push(subdomain ? '.' + d : d);
|
||||||
|
};
|
||||||
|
this.walk(onMatches, res.node, inputTokens);
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Method used to delete a prefix from the trie.
|
||||||
|
*/ remove(suffix) {
|
||||||
|
const res = this.getSingleChildLeaf(hostnameToTokens(suffix, 0));
|
||||||
|
if (res === null) return false;
|
||||||
|
if ((0, _bitwise.missingBit)(res.node[0], START)) return false;
|
||||||
|
this.$size--;
|
||||||
|
const { node, toPrune, tokenToPrune } = res;
|
||||||
|
if (tokenToPrune && toPrune) {
|
||||||
|
toPrune[2].delete(tokenToPrune);
|
||||||
|
} else {
|
||||||
|
node[0] = (0, _bitwise.deleteBit)(node[0], START);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/unbound-method -- safe
|
||||||
|
delete = this.remove;
|
||||||
|
/**
|
||||||
|
* Method used to assert whether the given prefix exists in the Trie.
|
||||||
|
*/ has(suffix, includeAllSubdomain = suffix[0] === '.') {
|
||||||
|
const hostnameFromIndex = suffix[0] === '.' ? 1 : 0;
|
||||||
|
const res = this.walkIntoLeafWithSuffix(suffix, hostnameFromIndex);
|
||||||
|
if (res === null) return false;
|
||||||
|
if ((0, _bitwise.missingBit)(res.node[0], START)) return false;
|
||||||
|
if (includeAllSubdomain) return (0, _bitwise.getBit)(res.node[0], INCLUDE_ALL_SUBDOMAIN);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
dumpWithoutDot(onSuffix, withSort = false) {
|
||||||
|
const handleSuffix = (suffix, subdomain)=>{
|
||||||
|
onSuffix((0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'), subdomain);
|
||||||
|
};
|
||||||
|
if (withSort) {
|
||||||
|
this.walkWithSort(handleSuffix);
|
||||||
|
} else {
|
||||||
|
this.walk(handleSuffix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dump(onSuffix, withSort = false) {
|
||||||
|
const results = [];
|
||||||
|
const handleSuffix = onSuffix ? (suffix, subdomain)=>{
|
||||||
|
const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.');
|
||||||
|
onSuffix(subdomain ? '.' + d : d);
|
||||||
|
} : (suffix, subdomain)=>{
|
||||||
|
const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.');
|
||||||
|
results.push(subdomain ? '.' + d : d);
|
||||||
|
};
|
||||||
|
if (withSort) {
|
||||||
|
this.walkWithSort(handleSuffix);
|
||||||
|
} else {
|
||||||
|
this.walk(handleSuffix);
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
dumpMeta(onMeta, withSort = false) {
|
||||||
|
const results = [];
|
||||||
|
const handleMeta = onMeta ? (_suffix, _subdomain, meta)=>onMeta(meta) : (_suffix, _subdomain, meta)=>results.push(meta);
|
||||||
|
if (withSort) {
|
||||||
|
this.walkWithSort(handleMeta);
|
||||||
|
} else {
|
||||||
|
this.walk(handleMeta);
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
dumpWithMeta(onSuffix, withSort = false) {
|
||||||
|
const results = [];
|
||||||
|
const handleSuffix = onSuffix ? (suffix, subdomain, meta)=>{
|
||||||
|
const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.');
|
||||||
|
return onSuffix(subdomain ? '.' + d : d, meta);
|
||||||
|
} : (suffix, subdomain, meta)=>{
|
||||||
|
const d = (0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.');
|
||||||
|
results.push([
|
||||||
|
subdomain ? '.' + d : d,
|
||||||
|
meta
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
if (withSort) {
|
||||||
|
this.walkWithSort(handleSuffix);
|
||||||
|
} else {
|
||||||
|
this.walk(handleSuffix);
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
inspect(depth, unpackMeta) {
|
||||||
|
return (0, _faststringarrayjoin.fastStringArrayJoin)(JSON.stringify(deepTrieNodeToJSON(this.$root, unpackMeta), null, 2).split('\n').map((line)=>' '.repeat(depth) + line), '\n');
|
||||||
|
}
|
||||||
|
[_computedKey](depth) {
|
||||||
|
return this.inspect(depth);
|
||||||
|
}
|
||||||
|
merge(trie) {
|
||||||
|
const handleSuffix = (suffix, subdomain, meta)=>{
|
||||||
|
this.add((0, _faststringarrayjoin.fastStringArrayJoin)(suffix, '.'), subdomain, meta);
|
||||||
|
};
|
||||||
|
trie.walk(handleSuffix);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class HostnameSmolTrie extends Triebase {
|
||||||
|
smolTree = true;
|
||||||
|
add(suffix, includeAllSubdomain = suffix[0] === '.', meta, hostnameFromIndex = suffix[0] === '.' ? 1 : 0) {
|
||||||
|
let node = this.$root;
|
||||||
|
let curNodeChildren = node[2];
|
||||||
|
const onToken = (token)=>{
|
||||||
|
curNodeChildren = node[2];
|
||||||
|
if (curNodeChildren.has(token)) {
|
||||||
|
node = curNodeChildren.get(token);
|
||||||
|
// During the adding of `[start]blog|.skk.moe` and find out that there is a `[start].skk.moe` in the trie, skip adding the rest of the node
|
||||||
|
if ((0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const newNode = createNode(node);
|
||||||
|
curNodeChildren.set(token, newNode);
|
||||||
|
node = newNode;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
// When walkHostnameTokens returns true, we should skip the rest
|
||||||
|
if (walkHostnameTokens(suffix, onToken, hostnameFromIndex)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// If we are in smolTree mode, we need to do something at the end of the loop
|
||||||
|
if (includeAllSubdomain) {
|
||||||
|
// Trying to add `[.]sub.example.com` where there is already a `blog.sub.example.com` in the trie
|
||||||
|
// Make sure parent `[start]sub.example.com` (without dot) is removed (SETINEL to false)
|
||||||
|
// (/** parent */ node[2]!)[0] = false;
|
||||||
|
// Removing the rest of the parent's child nodes
|
||||||
|
node[2].clear();
|
||||||
|
// The SENTINEL of this node will be set to true at the end of the function, so we don't need to set it here
|
||||||
|
// we can use else-if here, because the children is now empty, we don't need to check the leading "."
|
||||||
|
} else if ((0, _bitwise.getBit)(node[0], INCLUDE_ALL_SUBDOMAIN)) {
|
||||||
|
// Trying to add `example.com` when there is already a `.example.com` in the trie
|
||||||
|
// No need to increment size and set SENTINEL to true (skip this "new" item)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
node[0] = (0, _bitwise.setBit)(node[0], START);
|
||||||
|
if (includeAllSubdomain) {
|
||||||
|
node[0] = (0, _bitwise.setBit)(node[0], INCLUDE_ALL_SUBDOMAIN);
|
||||||
|
} else {
|
||||||
|
node[0] = (0, _bitwise.deleteBit)(node[0], INCLUDE_ALL_SUBDOMAIN);
|
||||||
|
}
|
||||||
|
node[3] = meta;
|
||||||
|
}
|
||||||
|
whitelist(suffix, includeAllSubdomain = suffix[0] === '.', hostnameFromIndex = suffix[0] === '.' ? 1 : 0) {
|
||||||
|
const tokens = hostnameToTokens(suffix, hostnameFromIndex);
|
||||||
|
const res = this.getSingleChildLeaf(tokens);
|
||||||
|
if (res === null) return;
|
||||||
|
const { node, toPrune, tokenToPrune } = res;
|
||||||
|
// Trying to whitelist `[start].sub.example.com` where there might already be a `[start]blog.sub.example.com` in the trie
|
||||||
|
if (includeAllSubdomain) {
|
||||||
|
// If there is a `[start]sub.example.com` here, remove it
|
||||||
|
node[0] = (0, _bitwise.deleteBit)(node[0], INCLUDE_ALL_SUBDOMAIN);
|
||||||
|
node[0] = (0, _bitwise.deleteBit)(node[0], START);
|
||||||
|
// Removing all the child nodes by empty the children
|
||||||
|
node[2].clear();
|
||||||
|
} else {
|
||||||
|
// Trying to whitelist `example.com` when there is already a `.example.com` in the trie
|
||||||
|
node[0] = (0, _bitwise.deleteBit)(node[0], INCLUDE_ALL_SUBDOMAIN);
|
||||||
|
}
|
||||||
|
// return early if not found
|
||||||
|
if ((0, _bitwise.missingBit)(node[0], START)) return;
|
||||||
|
if (toPrune && tokenToPrune) {
|
||||||
|
toPrune[2].delete(tokenToPrune);
|
||||||
|
} else {
|
||||||
|
node[0] = (0, _bitwise.deleteBit)(node[0], START);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class HostnameTrie extends Triebase {
|
||||||
|
get size() {
|
||||||
|
return this.$size;
|
||||||
|
}
|
||||||
|
add(suffix, includeAllSubdomain = suffix[0] === '.', meta, hostnameFromIndex = suffix[0] === '.' ? 1 : 0) {
|
||||||
|
let node = this.$root;
|
||||||
|
let child = node[2];
|
||||||
|
const onToken = (token)=>{
|
||||||
|
child = node[2];
|
||||||
|
if (child.has(token)) {
|
||||||
|
node = child.get(token);
|
||||||
|
} else {
|
||||||
|
const newNode = createNode(node);
|
||||||
|
child.set(token, newNode);
|
||||||
|
node = newNode;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
// When walkHostnameTokens returns true, we should skip the rest
|
||||||
|
if (walkHostnameTokens(suffix, onToken, hostnameFromIndex)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// if same entry has been added before, skip
|
||||||
|
if ((0, _bitwise.getBit)(node[0], START)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.$size++;
|
||||||
|
node[0] = (0, _bitwise.setBit)(node[0], START);
|
||||||
|
if (includeAllSubdomain) {
|
||||||
|
node[0] = (0, _bitwise.setBit)(node[0], INCLUDE_ALL_SUBDOMAIN);
|
||||||
|
} else {
|
||||||
|
node[0] = (0, _bitwise.deleteBit)(node[0], INCLUDE_ALL_SUBDOMAIN);
|
||||||
|
}
|
||||||
|
node[3] = meta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// function deepEqualArray(a: string[], b: string[]) {
|
||||||
|
// let len = a.length;
|
||||||
|
// if (len !== b.length) return false;
|
||||||
|
// while (len--) {
|
||||||
|
// if (a[len] !== b[len]) return false;
|
||||||
|
// }
|
||||||
|
// return true;
|
||||||
|
// };
|
||||||
|
function subStringEqual(needle, haystack, needleIndex = 0) {
|
||||||
|
for(let i = 0, l = haystack.length; i < l; i++){
|
||||||
|
if (needle[i + needleIndex] !== haystack[i]) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} (trie.__exports));
|
||||||
|
return trie.__exports;
|
||||||
|
}exports.__require=requireTrie;
|
||||||
113
Dist/Build/lib/writing-strategy/adguardhome.cjs
Normal file
113
Dist/Build/lib/writing-strategy/adguardhome.cjs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const adguardhome=require('../../../_virtual/adguardhome.cjs'),require$$0=require('foxts/escape-string-regexp'),base=require('./base.cjs'),require$$2=require('foxts/noop'),misc=require('../misc.cjs');var hasRequiredAdguardhome;
|
||||||
|
|
||||||
|
function requireAdguardhome () {
|
||||||
|
if (hasRequiredAdguardhome) return adguardhome.__exports;
|
||||||
|
hasRequiredAdguardhome = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "AdGuardHome", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return AdGuardHome;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _escapestringregexp = require$$0;
|
||||||
|
const _base = /*@__PURE__*/ base.__require();
|
||||||
|
const _noop = require$$2;
|
||||||
|
const _misc = /*@__PURE__*/ misc.__require();
|
||||||
|
class AdGuardHome extends _base.BaseWriteStrategy {
|
||||||
|
// readonly type = 'domainset';
|
||||||
|
fileExtension = 'txt';
|
||||||
|
type = '';
|
||||||
|
result = [];
|
||||||
|
// eslint-disable-next-line @typescript-eslint/class-methods-use-this -- abstract method
|
||||||
|
withPadding(title, description, date, content) {
|
||||||
|
return [
|
||||||
|
`! Title: ${title}`,
|
||||||
|
'! Last modified: ' + date.toUTCString(),
|
||||||
|
'! Expires: 6 hours',
|
||||||
|
'! License: https://github.com/SukkaW/Surge/blob/master/LICENSE',
|
||||||
|
'! Homepage: https://github.com/SukkaW/Surge',
|
||||||
|
`! Description: ${description.join(' ')}`,
|
||||||
|
'!',
|
||||||
|
...content,
|
||||||
|
'! EOF'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
writeDomain(domain) {
|
||||||
|
this.result.push(`|${domain}^`);
|
||||||
|
}
|
||||||
|
// const whitelistArray = sortDomains(Array.from(whitelist));
|
||||||
|
// for (let i = 0, len = whitelistArray.length; i < len; i++) {
|
||||||
|
// const domain = whitelistArray[i];
|
||||||
|
// if (domain[0] === '.') {
|
||||||
|
// results.push(`@@||${domain.slice(1)}^`);
|
||||||
|
// } else {
|
||||||
|
// results.push(`@@|${domain}^`);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
writeDomainSuffix(domain) {
|
||||||
|
this.result.push(`||${domain}^`);
|
||||||
|
}
|
||||||
|
writeDomainKeywords(keywords) {
|
||||||
|
for (const keyword of keywords){
|
||||||
|
// Use regex to match keyword
|
||||||
|
this.result.push(`/${(0, _escapestringregexp.escapeStringRegexp)(keyword)}/`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeDomainWildcards(wildcards) {
|
||||||
|
for (const wildcard of wildcards){
|
||||||
|
const processed = wildcard.replaceAll('?', '*');
|
||||||
|
if (processed.startsWith('*.')) {
|
||||||
|
this.result.push(`||${processed.slice(2)}^`);
|
||||||
|
} else {
|
||||||
|
this.result.push(`|${processed}^`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeUserAgents = _noop.noop;
|
||||||
|
writeProcessNames = _noop.noop;
|
||||||
|
writeProcessPaths = _noop.noop;
|
||||||
|
writeUrlRegexes = _noop.noop;
|
||||||
|
writeIpCidrs(ipGroup, noResolve) {
|
||||||
|
if (noResolve) {
|
||||||
|
// When IP is provided to AdGuardHome, any domain resolve to those IP will be blocked
|
||||||
|
// So we can't do noResolve
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const ipcidr of ipGroup){
|
||||||
|
if (ipcidr.endsWith('/32')) {
|
||||||
|
this.result.push(`||${ipcidr.slice(0, -3)}`);
|
||||||
|
/* else if (ipcidr.endsWith('.0/24')) {
|
||||||
|
results.push(`||${ipcidr.slice(0, -6)}.*`);
|
||||||
|
} */ } else {
|
||||||
|
this.result.push(`||${ipcidr}^`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeIpCidr6s(ipGroup, noResolve) {
|
||||||
|
if (noResolve) {
|
||||||
|
// When IP is provided to AdGuardHome, any domain resolve to those IP will be blocked
|
||||||
|
// So we can't do noResolve
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const ipcidr of ipGroup){
|
||||||
|
if (ipcidr.endsWith('/128')) {
|
||||||
|
this.result.push(`||${ipcidr.slice(0, -4)}`);
|
||||||
|
} else {
|
||||||
|
this.result.push(`||${ipcidr}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeGeoip = (0, _misc.notSupported)('writeGeoip');
|
||||||
|
writeIpAsns = (0, _misc.notSupported)('writeIpAsns');
|
||||||
|
writeSourceIpCidrs = (0, _misc.notSupported)('writeSourceIpCidrs');
|
||||||
|
writeSourcePorts = (0, _misc.notSupported)('writeSourcePorts');
|
||||||
|
writeDestinationPorts = _noop.noop;
|
||||||
|
writeOtherRules = _noop.noop;
|
||||||
|
}
|
||||||
|
} (adguardhome.__exports));
|
||||||
|
return adguardhome.__exports;
|
||||||
|
}exports.__require=requireAdguardhome;
|
||||||
63
Dist/Build/lib/writing-strategy/base.cjs
Normal file
63
Dist/Build/lib/writing-strategy/base.cjs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const base=require('../../../_virtual/base2.cjs'),createFile=require('../create-file.cjs');var hasRequiredBase;
|
||||||
|
|
||||||
|
function requireBase () {
|
||||||
|
if (hasRequiredBase) return base.__exports;
|
||||||
|
hasRequiredBase = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "BaseWriteStrategy", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return BaseWriteStrategy;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _createfile = /*@__PURE__*/ createFile.__require();
|
||||||
|
class BaseWriteStrategy {
|
||||||
|
outputDir;
|
||||||
|
/**
|
||||||
|
* Sometimes a ruleset will create extra files (e.g. reject-url-regex w/ mitm.sgmodule),
|
||||||
|
* and doesn't share the same filename and id. This property is used to overwrite the filename.
|
||||||
|
*/ overwriteFilename;
|
||||||
|
withFilename(filename) {
|
||||||
|
this.overwriteFilename = filename;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
constructor(outputDir){
|
||||||
|
this.outputDir = outputDir;
|
||||||
|
this.overwriteFilename = null;
|
||||||
|
}
|
||||||
|
static domainWildCardToRegex = (domain)=>{
|
||||||
|
let result = '^';
|
||||||
|
for(let i = 0, len = domain.length; i < len; i++){
|
||||||
|
switch(domain[i]){
|
||||||
|
case '.':
|
||||||
|
result += String.raw`\.`;
|
||||||
|
break;
|
||||||
|
case '*':
|
||||||
|
result += String.raw`[\w.-]*?`;
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
result += String.raw`[\w.-]`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result += domain[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result += '$';
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
output(span, title, description, date, filePath) {
|
||||||
|
if (!this.result) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return (0, _createfile.compareAndWriteFile)(span, this.withPadding(title, description, date, this.result), filePath);
|
||||||
|
}
|
||||||
|
get content() {
|
||||||
|
return this.result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} (base.__exports));
|
||||||
|
return base.__exports;
|
||||||
|
}exports.__require=requireBase;
|
||||||
172
Dist/Build/lib/writing-strategy/clash.cjs
Normal file
172
Dist/Build/lib/writing-strategy/clash.cjs
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const clash=require('../../../_virtual/clash.cjs'),require$$0=require('foxts/append-set-elements-to-array'),base=require('./base.cjs'),require$$2=require('foxts/noop'),misc=require('../misc.cjs'),dir=require('../../constants/dir.cjs'),appendArrayInPlace=require('../append-array-in-place.cjs');var hasRequiredClash;
|
||||||
|
|
||||||
|
function requireClash () {
|
||||||
|
if (hasRequiredClash) return clash.__exports;
|
||||||
|
hasRequiredClash = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
ClashClassicRuleSet: function() {
|
||||||
|
return ClashClassicRuleSet;
|
||||||
|
},
|
||||||
|
ClashDomainSet: function() {
|
||||||
|
return ClashDomainSet;
|
||||||
|
},
|
||||||
|
ClashIPSet: function() {
|
||||||
|
return ClashIPSet;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _appendsetelementstoarray = require$$0;
|
||||||
|
const _base = /*@__PURE__*/ base.__require();
|
||||||
|
const _noop = require$$2;
|
||||||
|
const _misc = /*@__PURE__*/ misc.__require();
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
|
||||||
|
class ClashDomainSet extends _base.BaseWriteStrategy {
|
||||||
|
outputDir;
|
||||||
|
// readonly type = 'domainset';
|
||||||
|
fileExtension;
|
||||||
|
type;
|
||||||
|
result;
|
||||||
|
constructor(outputDir = _dir.OUTPUT_CLASH_DIR){
|
||||||
|
super(outputDir), this.outputDir = outputDir, this.fileExtension = 'txt', this.type = 'domainset', this.result = [
|
||||||
|
'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'
|
||||||
|
], this.withPadding = _misc.withBannerArray, this.writeDomainKeywords = _noop.noop, this.writeDomainWildcards = _noop.noop, this.writeUserAgents = _noop.noop, this.writeProcessNames = _noop.noop, this.writeProcessPaths = _noop.noop, this.writeUrlRegexes = _noop.noop, this.writeIpCidrs = _noop.noop, this.writeIpCidr6s = _noop.noop, this.writeGeoip = _noop.noop, this.writeIpAsns = _noop.noop, this.writeSourceIpCidrs = _noop.noop, this.writeSourcePorts = _noop.noop, this.writeDestinationPorts = _noop.noop, this.writeOtherRules = _noop.noop;
|
||||||
|
}
|
||||||
|
withPadding;
|
||||||
|
writeDomain(domain) {
|
||||||
|
this.result.push(domain);
|
||||||
|
}
|
||||||
|
writeDomainSuffix(domain) {
|
||||||
|
this.result.push('+.' + domain);
|
||||||
|
}
|
||||||
|
writeDomainKeywords;
|
||||||
|
writeDomainWildcards;
|
||||||
|
writeUserAgents;
|
||||||
|
writeProcessNames;
|
||||||
|
writeProcessPaths;
|
||||||
|
writeUrlRegexes;
|
||||||
|
writeIpCidrs;
|
||||||
|
writeIpCidr6s;
|
||||||
|
writeGeoip;
|
||||||
|
writeIpAsns;
|
||||||
|
writeSourceIpCidrs;
|
||||||
|
writeSourcePorts;
|
||||||
|
writeDestinationPorts;
|
||||||
|
writeOtherRules;
|
||||||
|
}
|
||||||
|
class ClashIPSet extends _base.BaseWriteStrategy {
|
||||||
|
outputDir;
|
||||||
|
// readonly type = 'domainset';
|
||||||
|
fileExtension;
|
||||||
|
type;
|
||||||
|
result;
|
||||||
|
constructor(outputDir = _dir.OUTPUT_CLASH_DIR){
|
||||||
|
super(outputDir), this.outputDir = outputDir, this.fileExtension = 'txt', this.type = 'ip', this.result = [], this.withPadding = _misc.withBannerArray, this.writeDomain = (0, _misc.notSupported)('writeDomain'), this.writeDomainSuffix = (0, _misc.notSupported)('writeDomainSuffix'), this.writeDomainKeywords = (0, _misc.notSupported)('writeDomainKeywords'), this.writeDomainWildcards = (0, _misc.notSupported)('writeDomainWildcards'), this.writeUserAgents = (0, _misc.notSupported)('writeUserAgents'), this.writeProcessNames = (0, _misc.notSupported)('writeProcessNames'), this.writeProcessPaths = (0, _misc.notSupported)('writeProcessPaths'), this.writeUrlRegexes = (0, _misc.notSupported)('writeUrlRegexes'), this.writeGeoip = (0, _misc.notSupported)('writeGeoip'), this.writeIpAsns = (0, _misc.notSupported)('writeIpAsns'), this.writeSourceIpCidrs = (0, _misc.notSupported)('writeSourceIpCidrs'), this.writeSourcePorts = (0, _misc.notSupported)('writeSourcePorts'), this.writeDestinationPorts = _noop.noop, this.writeOtherRules = _noop.noop;
|
||||||
|
}
|
||||||
|
withPadding;
|
||||||
|
writeDomain;
|
||||||
|
writeDomainSuffix;
|
||||||
|
writeDomainKeywords;
|
||||||
|
writeDomainWildcards;
|
||||||
|
writeUserAgents;
|
||||||
|
writeProcessNames;
|
||||||
|
writeProcessPaths;
|
||||||
|
writeUrlRegexes;
|
||||||
|
writeIpCidrs(ipCidr) {
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(this.result, ipCidr);
|
||||||
|
}
|
||||||
|
writeIpCidr6s(ipCidr6) {
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(this.result, ipCidr6);
|
||||||
|
}
|
||||||
|
writeGeoip;
|
||||||
|
writeIpAsns;
|
||||||
|
writeSourceIpCidrs;
|
||||||
|
writeSourcePorts;
|
||||||
|
writeDestinationPorts;
|
||||||
|
writeOtherRules;
|
||||||
|
}
|
||||||
|
class ClashClassicRuleSet extends _base.BaseWriteStrategy {
|
||||||
|
type;
|
||||||
|
outputDir;
|
||||||
|
fileExtension;
|
||||||
|
result;
|
||||||
|
constructor(type/* | (string & {}) */ , outputDir = _dir.OUTPUT_CLASH_DIR){
|
||||||
|
super(outputDir), this.type = type, this.outputDir = outputDir, this.fileExtension = 'txt', this.result = [
|
||||||
|
'DOMAIN,this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'
|
||||||
|
], this.withPadding = _misc.withBannerArray, this.writeUserAgents = _noop.noop, this.writeUrlRegexes = _noop.noop, this.writeOtherRules = _noop.noop;
|
||||||
|
}
|
||||||
|
withPadding;
|
||||||
|
writeDomain(domain) {
|
||||||
|
this.result.push('DOMAIN,' + domain);
|
||||||
|
}
|
||||||
|
writeDomainSuffix(domain) {
|
||||||
|
this.result.push('DOMAIN-SUFFIX,' + domain);
|
||||||
|
}
|
||||||
|
writeDomainKeywords(keyword) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, keyword, (i)=>`DOMAIN-KEYWORD,${i}`);
|
||||||
|
}
|
||||||
|
writeDomainWildcards(wildcard) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, wildcard, (i)=>`DOMAIN-REGEX,${ClashClassicRuleSet.domainWildCardToRegex(i)}`);
|
||||||
|
}
|
||||||
|
writeUserAgents;
|
||||||
|
writeProcessNames(processName) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processName, (i)=>`PROCESS-NAME,${i}`);
|
||||||
|
}
|
||||||
|
writeProcessPaths(processPath) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processPath, (i)=>`PROCESS-PATH,${i}`);
|
||||||
|
}
|
||||||
|
writeUrlRegexes;
|
||||||
|
writeIpCidrs(ipCidr, noResolve) {
|
||||||
|
for(let i = 0, len = ipCidr.length; i < len; i++){
|
||||||
|
this.result.push(`IP-CIDR,${ipCidr[i]}${noResolve ? ',no-resolve' : ''}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeIpCidr6s(ipCidr6, noResolve) {
|
||||||
|
for(let i = 0, len = ipCidr6.length; i < len; i++){
|
||||||
|
this.result.push(`IP-CIDR6,${ipCidr6[i]}${noResolve ? ',no-resolve' : ''}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeGeoip(geoip, noResolve) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, geoip, (i)=>`GEOIP,${i}${noResolve ? ',no-resolve' : ''}`);
|
||||||
|
}
|
||||||
|
writeIpAsns(asns, noResolve) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, asns, (i)=>`IP-ASN,${i}${noResolve ? ',no-resolve' : ''}`);
|
||||||
|
}
|
||||||
|
writeSourceIpCidrs(sourceIpCidr) {
|
||||||
|
for(let i = 0, len = sourceIpCidr.length; i < len; i++){
|
||||||
|
const value = sourceIpCidr[i];
|
||||||
|
if (value.includes('/')) {
|
||||||
|
this.result.push(`SRC-IP-CIDR,${value}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const v = (0, _misc.fastIpVersion)(value);
|
||||||
|
if (v === 4) {
|
||||||
|
this.result.push(`SRC-IP-CIDR,${value}/32`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (v === 6) {
|
||||||
|
this.result.push(`SRC-IP-CIDR6,${value}/128`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeSourcePorts(port) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`SRC-PORT,${i}`);
|
||||||
|
}
|
||||||
|
writeDestinationPorts(port) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`DST-PORT,${i}`);
|
||||||
|
}
|
||||||
|
writeOtherRules;
|
||||||
|
}
|
||||||
|
} (clash.__exports));
|
||||||
|
return clash.__exports;
|
||||||
|
}exports.__require=requireClash;
|
||||||
121
Dist/Build/lib/writing-strategy/singbox.cjs
Normal file
121
Dist/Build/lib/writing-strategy/singbox.cjs
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const singbox=require('../../../_virtual/singbox.cjs'),base=require('./base.cjs'),appendArrayInPlace=require('../append-array-in-place.cjs'),require$$2=require('foxts/noop'),misc=require('../misc.cjs'),require$$4=require('json-stringify-pretty-compact'),dir=require('../../constants/dir.cjs');var hasRequiredSingbox;
|
||||||
|
|
||||||
|
function requireSingbox () {
|
||||||
|
if (hasRequiredSingbox) return singbox.__exports;
|
||||||
|
hasRequiredSingbox = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "SingboxSource", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return SingboxSource;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _base = /*@__PURE__*/ base.__require();
|
||||||
|
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
|
||||||
|
const _noop = require$$2;
|
||||||
|
const _misc = /*@__PURE__*/ misc.__require();
|
||||||
|
const _jsonstringifyprettycompact = /*#__PURE__*/ _interop_require_default(require$$4);
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
class SingboxSource extends _base.BaseWriteStrategy {
|
||||||
|
type;
|
||||||
|
outputDir;
|
||||||
|
fileExtension;
|
||||||
|
static jsonToLines = (json)=>(0, _jsonstringifyprettycompact.default)(json).split('\n');
|
||||||
|
singbox;
|
||||||
|
get result() {
|
||||||
|
return SingboxSource.jsonToLines({
|
||||||
|
version: 2,
|
||||||
|
rules: [
|
||||||
|
this.singbox
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
constructor(/** Since sing-box only have one format that does not reflect type, we need to specify it */ type/* | (string & {}) */ , outputDir = _dir.OUTPUT_SINGBOX_DIR){
|
||||||
|
super(outputDir), this.type = type, this.outputDir = outputDir, this.fileExtension = 'json', this.singbox = {
|
||||||
|
domain: [
|
||||||
|
'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'
|
||||||
|
],
|
||||||
|
domain_suffix: [
|
||||||
|
'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'
|
||||||
|
]
|
||||||
|
}, this.withPadding = _misc.withIdentityContent, this.writeUserAgents = _noop.noop, this.writeUrlRegexes = _noop.noop, this.writeGeoip = _noop.noop, this.writeIpAsns = _noop.noop, this.writeOtherRules = _noop.noop;
|
||||||
|
}
|
||||||
|
withPadding;
|
||||||
|
writeDomain(domain) {
|
||||||
|
this.singbox.domain.push(domain);
|
||||||
|
}
|
||||||
|
writeDomainSuffix(domain) {
|
||||||
|
this.singbox.domain_suffix.push(domain);
|
||||||
|
}
|
||||||
|
writeDomainKeywords(keyword) {
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.domain_keyword ??= [], Array.from(keyword));
|
||||||
|
}
|
||||||
|
writeDomainWildcards(wildcard) {
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.domain_regex ??= [], Array.from(wildcard, SingboxSource.domainWildCardToRegex));
|
||||||
|
}
|
||||||
|
writeUserAgents;
|
||||||
|
writeProcessNames(processName) {
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.process_name ??= [], Array.from(processName));
|
||||||
|
}
|
||||||
|
writeProcessPaths(processPath) {
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.process_path ??= [], Array.from(processPath));
|
||||||
|
}
|
||||||
|
writeUrlRegexes;
|
||||||
|
writeIpCidrs(ipCidr) {
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.ip_cidr ??= [], ipCidr);
|
||||||
|
}
|
||||||
|
writeIpCidr6s(ipCidr6) {
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.ip_cidr ??= [], ipCidr6);
|
||||||
|
}
|
||||||
|
writeGeoip;
|
||||||
|
writeIpAsns;
|
||||||
|
writeSourceIpCidrs(sourceIpCidr) {
|
||||||
|
this.singbox.source_ip_cidr ??= [];
|
||||||
|
for(let i = 0, len = sourceIpCidr.length; i < len; i++){
|
||||||
|
const value = sourceIpCidr[i];
|
||||||
|
if (value.includes('/')) {
|
||||||
|
this.singbox.source_ip_cidr.push(value);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const v = (0, _misc.fastIpVersion)(value);
|
||||||
|
if (v === 4) {
|
||||||
|
this.singbox.source_ip_cidr.push(`${value}/32`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (v === 6) {
|
||||||
|
this.singbox.source_ip_cidr.push(`${value}/128`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeSourcePorts(port) {
|
||||||
|
this.singbox.source_port ??= [];
|
||||||
|
for (const i of port){
|
||||||
|
const tmp = Number(i);
|
||||||
|
if (!Number.isNaN(tmp)) {
|
||||||
|
this.singbox.source_port.push(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeDestinationPorts(port) {
|
||||||
|
this.singbox.port ??= [];
|
||||||
|
for (const i of port){
|
||||||
|
const tmp = Number(i);
|
||||||
|
if (!Number.isNaN(tmp)) {
|
||||||
|
this.singbox.port.push(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeOtherRules;
|
||||||
|
}
|
||||||
|
} (singbox.__exports));
|
||||||
|
return singbox.__exports;
|
||||||
|
}exports.__require=requireSingbox;
|
||||||
246
Dist/Build/lib/writing-strategy/surge.cjs
Normal file
246
Dist/Build/lib/writing-strategy/surge.cjs
Normal file
@ -0,0 +1,246 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const surge=require('../../../_virtual/surge.cjs'),require$$0=require('foxts/append-set-elements-to-array'),base=require('./base.cjs'),appendArrayInPlace=require('../append-array-in-place.cjs'),require$$2=require('foxts/noop'),require$$2$1=require('foxts/is-probably-ip'),require$$0$1=require('picocolors'),normalizeDomain=require('../normalize-domain.cjs'),dir=require('../../constants/dir.cjs'),misc=require('../misc.cjs');var hasRequiredSurge;
|
||||||
|
|
||||||
|
function requireSurge () {
|
||||||
|
if (hasRequiredSurge) return surge.__exports;
|
||||||
|
hasRequiredSurge = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
SurgeDomainSet: function() {
|
||||||
|
return SurgeDomainSet;
|
||||||
|
},
|
||||||
|
SurgeMitmSgmodule: function() {
|
||||||
|
return SurgeMitmSgmodule;
|
||||||
|
},
|
||||||
|
SurgeRuleSet: function() {
|
||||||
|
return SurgeRuleSet;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _appendsetelementstoarray = require$$0;
|
||||||
|
const _base = /*@__PURE__*/ base.__require();
|
||||||
|
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
|
||||||
|
const _noop = require$$2;
|
||||||
|
const _isprobablyip = require$$2$1;
|
||||||
|
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1);
|
||||||
|
const _normalizedomain = /*@__PURE__*/ normalizeDomain.__require();
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _misc = /*@__PURE__*/ misc.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
class SurgeDomainSet extends _base.BaseWriteStrategy {
|
||||||
|
// readonly type = 'domainset';
|
||||||
|
fileExtension = 'conf';
|
||||||
|
type = 'domainset';
|
||||||
|
result = [
|
||||||
|
'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'
|
||||||
|
];
|
||||||
|
constructor(outputDir = _dir.OUTPUT_SURGE_DIR){
|
||||||
|
super(outputDir);
|
||||||
|
}
|
||||||
|
withPadding = _misc.withBannerArray;
|
||||||
|
writeDomain(domain) {
|
||||||
|
this.result.push(domain);
|
||||||
|
}
|
||||||
|
writeDomainSuffix(domain) {
|
||||||
|
this.result.push('.' + domain);
|
||||||
|
}
|
||||||
|
writeDomainKeywords = _noop.noop;
|
||||||
|
writeDomainWildcards = _noop.noop;
|
||||||
|
writeUserAgents = _noop.noop;
|
||||||
|
writeProcessNames = _noop.noop;
|
||||||
|
writeProcessPaths = _noop.noop;
|
||||||
|
writeUrlRegexes = _noop.noop;
|
||||||
|
writeIpCidrs = _noop.noop;
|
||||||
|
writeIpCidr6s = _noop.noop;
|
||||||
|
writeGeoip = _noop.noop;
|
||||||
|
writeIpAsns = _noop.noop;
|
||||||
|
writeSourceIpCidrs = _noop.noop;
|
||||||
|
writeSourcePorts = _noop.noop;
|
||||||
|
writeDestinationPorts = _noop.noop;
|
||||||
|
writeOtherRules = _noop.noop;
|
||||||
|
}
|
||||||
|
class SurgeRuleSet extends _base.BaseWriteStrategy {
|
||||||
|
type;
|
||||||
|
outputDir;
|
||||||
|
fileExtension;
|
||||||
|
result;
|
||||||
|
constructor(/** Surge RULE-SET can be both ip or non_ip, so this needs to be specified */ type, outputDir = _dir.OUTPUT_SURGE_DIR){
|
||||||
|
super(outputDir), this.type = type, this.outputDir = outputDir, this.fileExtension = 'conf', this.result = [
|
||||||
|
'DOMAIN,this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'
|
||||||
|
], this.withPadding = _misc.withBannerArray;
|
||||||
|
}
|
||||||
|
withPadding;
|
||||||
|
writeDomain(domain) {
|
||||||
|
this.result.push('DOMAIN,' + domain);
|
||||||
|
}
|
||||||
|
writeDomainSuffix(domain) {
|
||||||
|
this.result.push('DOMAIN-SUFFIX,' + domain);
|
||||||
|
}
|
||||||
|
writeDomainKeywords(keyword) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, keyword, (i)=>`DOMAIN-KEYWORD,${i}`);
|
||||||
|
}
|
||||||
|
writeDomainWildcards(wildcard) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, wildcard, (i)=>`DOMAIN-WILDCARD,${i}`);
|
||||||
|
}
|
||||||
|
writeUserAgents(userAgent) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, userAgent, (i)=>`USER-AGENT,${i}`);
|
||||||
|
}
|
||||||
|
writeProcessNames(processName) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processName, (i)=>`PROCESS-NAME,${i}`);
|
||||||
|
}
|
||||||
|
writeProcessPaths(processPath) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processPath, (i)=>`PROCESS-NAME,${i}`);
|
||||||
|
}
|
||||||
|
writeUrlRegexes(urlRegex) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, urlRegex, (i)=>`URL-REGEX,${i}`);
|
||||||
|
}
|
||||||
|
writeIpCidrs(ipCidr, noResolve) {
|
||||||
|
for(let i = 0, len = ipCidr.length; i < len; i++){
|
||||||
|
this.result.push(`IP-CIDR,${ipCidr[i]}${noResolve ? ',no-resolve' : ''}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeIpCidr6s(ipCidr6, noResolve) {
|
||||||
|
for(let i = 0, len = ipCidr6.length; i < len; i++){
|
||||||
|
this.result.push(`IP-CIDR6,${ipCidr6[i]}${noResolve ? ',no-resolve' : ''}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeGeoip(geoip, noResolve) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, geoip, (i)=>`GEOIP,${i}${noResolve ? ',no-resolve' : ''}`);
|
||||||
|
}
|
||||||
|
writeIpAsns(asns, noResolve) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, asns, (i)=>`IP-ASN,${i}${noResolve ? ',no-resolve' : ''}`);
|
||||||
|
}
|
||||||
|
writeSourceIpCidrs(sourceIpCidr) {
|
||||||
|
for(let i = 0, len = sourceIpCidr.length; i < len; i++){
|
||||||
|
this.result.push(`SRC-IP,${sourceIpCidr[i]}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeSourcePorts(port) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`SRC-PORT,${i}`);
|
||||||
|
}
|
||||||
|
writeDestinationPorts(port) {
|
||||||
|
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`DEST-PORT,${i}`);
|
||||||
|
}
|
||||||
|
writeOtherRules(rule) {
|
||||||
|
(0, _appendarrayinplace.appendArrayInPlace)(this.result, rule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class SurgeMitmSgmodule extends _base.BaseWriteStrategy {
|
||||||
|
// readonly type = 'domainset';
|
||||||
|
fileExtension = 'sgmodule';
|
||||||
|
type = '';
|
||||||
|
rules = new Set();
|
||||||
|
get result() {
|
||||||
|
if (this.rules.size === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
'#!name=[Sukka] Surge Reject MITM',
|
||||||
|
`#!desc=为 URL Regex 规则组启用 MITM (size: ${this.rules.size})`,
|
||||||
|
'',
|
||||||
|
'[MITM]',
|
||||||
|
'hostname = %APPEND% ' + Array.from(this.rules).join(', ')
|
||||||
|
];
|
||||||
|
}
|
||||||
|
withPadding = _misc.withIdentityContent;
|
||||||
|
constructor(moduleName, outputDir = _dir.OUTPUT_MODULES_DIR){
|
||||||
|
super(outputDir);
|
||||||
|
this.withFilename(moduleName);
|
||||||
|
}
|
||||||
|
writeDomain = _noop.noop;
|
||||||
|
writeDomainSuffix = _noop.noop;
|
||||||
|
writeDomainKeywords = _noop.noop;
|
||||||
|
writeDomainWildcards = _noop.noop;
|
||||||
|
writeUserAgents = _noop.noop;
|
||||||
|
writeProcessNames = _noop.noop;
|
||||||
|
writeProcessPaths = _noop.noop;
|
||||||
|
writeUrlRegexes(urlRegexes) {
|
||||||
|
const urlRegexResults = [];
|
||||||
|
const parsedFailures = [];
|
||||||
|
const parsed = [];
|
||||||
|
for (let urlRegex of urlRegexes){
|
||||||
|
if (urlRegex.startsWith('http://') || urlRegex.startsWith('^http://')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (urlRegex.startsWith('^https?://')) {
|
||||||
|
urlRegex = urlRegex.slice(10);
|
||||||
|
}
|
||||||
|
if (urlRegex.startsWith('^https://')) {
|
||||||
|
urlRegex = urlRegex.slice(9);
|
||||||
|
}
|
||||||
|
const potentialHostname = urlRegex.split('/')[0]// pre process regex
|
||||||
|
.replaceAll(String.raw`\.`, '.').replaceAll('.+', '*').replaceAll(/([a-z])\?/g, '($1|)')// convert regex to surge hostlist syntax
|
||||||
|
.replaceAll('([a-z])', '?').replaceAll(String.raw`\d`, '?').replaceAll(/\*+/g, '*');
|
||||||
|
let processed = [
|
||||||
|
potentialHostname
|
||||||
|
];
|
||||||
|
const matches = [
|
||||||
|
...potentialHostname.matchAll(/\((?:([^()|]+)\|)+([^()|]*)\)/g)
|
||||||
|
];
|
||||||
|
if (matches.length > 0) {
|
||||||
|
const replaceVariant = (combinations, fullMatch, options)=>{
|
||||||
|
const newCombinations = [];
|
||||||
|
combinations.forEach((combination)=>{
|
||||||
|
options.forEach((option)=>{
|
||||||
|
newCombinations.push(combination.replace(fullMatch, option));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return newCombinations;
|
||||||
|
};
|
||||||
|
for(let i = 0; i < matches.length; i++){
|
||||||
|
const match = matches[i];
|
||||||
|
const [_, ...options] = match;
|
||||||
|
processed = replaceVariant(processed, _, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
urlRegexResults.push({
|
||||||
|
origin: potentialHostname,
|
||||||
|
processed
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (const i of urlRegexResults){
|
||||||
|
for (const processed of i.processed){
|
||||||
|
if ((0, _normalizedomain.normalizeDomain)(processed.replaceAll('*', 'a').replaceAll('?', 'b'))) {
|
||||||
|
parsed.push([
|
||||||
|
i.origin,
|
||||||
|
processed
|
||||||
|
]);
|
||||||
|
} else if (!(0, _isprobablyip.isProbablyIpv4)(processed)) {
|
||||||
|
parsedFailures.push([
|
||||||
|
i.origin,
|
||||||
|
processed
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (parsedFailures.length > 0) {
|
||||||
|
console.error(_picocolors.default.bold('Parsed Failed'));
|
||||||
|
console.table(parsedFailures);
|
||||||
|
}
|
||||||
|
for(let i = 0, len = parsed.length; i < len; i++){
|
||||||
|
this.rules.add(parsed[i][1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeIpCidrs = _noop.noop;
|
||||||
|
writeIpCidr6s = _noop.noop;
|
||||||
|
writeGeoip = _noop.noop;
|
||||||
|
writeIpAsns = _noop.noop;
|
||||||
|
writeSourceIpCidrs = _noop.noop;
|
||||||
|
writeSourcePorts = _noop.noop;
|
||||||
|
writeDestinationPorts = _noop.noop;
|
||||||
|
writeOtherRules = _noop.noop;
|
||||||
|
}
|
||||||
|
} (surge.__exports));
|
||||||
|
return surge.__exports;
|
||||||
|
}exports.__require=requireSurge;
|
||||||
182
Dist/Build/trace/index.cjs
Normal file
182
Dist/Build/trace/index.cjs
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const index=require('../../_virtual/index2.cjs'),require$$2=require('foxts/noop'),require$$0=require('node:path'),require$$1=require('node:process'),require$$0$1=require('picocolors');var hasRequiredTrace;
|
||||||
|
|
||||||
|
function requireTrace () {
|
||||||
|
if (hasRequiredTrace) return index.__exports;
|
||||||
|
hasRequiredTrace = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
createSpan: function() {
|
||||||
|
return createSpan;
|
||||||
|
},
|
||||||
|
dummySpan: function() {
|
||||||
|
return dummySpan;
|
||||||
|
},
|
||||||
|
printTraceResult: function() {
|
||||||
|
return printTraceResult;
|
||||||
|
},
|
||||||
|
task: function() {
|
||||||
|
return task;
|
||||||
|
},
|
||||||
|
whyIsNodeRunning: function() {
|
||||||
|
return whyIsNodeRunning;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _noop = require$$2;
|
||||||
|
const _nodepath = require$$0;
|
||||||
|
const _nodeprocess = /*#__PURE__*/ _interop_require_default(require$$1);
|
||||||
|
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1);
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const SPAN_STATUS_START = 0;
|
||||||
|
const SPAN_STATUS_END = 1;
|
||||||
|
const spanTag = Symbol('span');
|
||||||
|
const rootTraceResult = {
|
||||||
|
name: 'root',
|
||||||
|
start: 0,
|
||||||
|
end: 0,
|
||||||
|
children: []
|
||||||
|
};
|
||||||
|
function createSpan(name, parentTraceResult) {
|
||||||
|
const start = performance.now();
|
||||||
|
let curTraceResult;
|
||||||
|
if (parentTraceResult == null) {
|
||||||
|
curTraceResult = rootTraceResult;
|
||||||
|
} else {
|
||||||
|
curTraceResult = {
|
||||||
|
name,
|
||||||
|
start,
|
||||||
|
end: 0,
|
||||||
|
children: []
|
||||||
|
};
|
||||||
|
parentTraceResult.children.push(curTraceResult);
|
||||||
|
}
|
||||||
|
let status = SPAN_STATUS_START;
|
||||||
|
const stop = (time)=>{
|
||||||
|
if (status === SPAN_STATUS_END) {
|
||||||
|
throw new Error(`span already stopped: ${name}`);
|
||||||
|
}
|
||||||
|
const end = time ?? performance.now();
|
||||||
|
curTraceResult.end = end;
|
||||||
|
status = SPAN_STATUS_END;
|
||||||
|
};
|
||||||
|
const traceChild = (name)=>createSpan(name, curTraceResult);
|
||||||
|
const span = {
|
||||||
|
[spanTag]: true,
|
||||||
|
stop,
|
||||||
|
traceChild,
|
||||||
|
traceSyncFn (fn) {
|
||||||
|
const res = fn(span);
|
||||||
|
span.stop();
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
async traceAsyncFn (fn) {
|
||||||
|
const res = await fn(span);
|
||||||
|
span.stop();
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
traceResult: curTraceResult,
|
||||||
|
async tracePromise (promise) {
|
||||||
|
const res = await promise;
|
||||||
|
span.stop();
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
traceChildSync: (name, fn)=>traceChild(name).traceSyncFn(fn),
|
||||||
|
traceChildAsync: (name, fn)=>traceChild(name).traceAsyncFn(fn),
|
||||||
|
traceChildPromise: (name, promise)=>traceChild(name).tracePromise(promise)
|
||||||
|
};
|
||||||
|
// eslint-disable-next-line sukka/no-redundant-variable -- self reference
|
||||||
|
return span;
|
||||||
|
}
|
||||||
|
const dummySpan = createSpan('');
|
||||||
|
function task(importMetaMain, importMetaPath) {
|
||||||
|
return (fn, customName)=>{
|
||||||
|
const taskName = customName ?? (0, _nodepath.basename)(importMetaPath, (0, _nodepath.extname)(importMetaPath));
|
||||||
|
let cleanup = _noop.noop;
|
||||||
|
const onCleanup = (cb)=>{
|
||||||
|
cleanup = cb;
|
||||||
|
};
|
||||||
|
const dummySpan = createSpan(taskName);
|
||||||
|
if (importMetaMain) {
|
||||||
|
_nodeprocess.default.on('uncaughtException', (error)=>{
|
||||||
|
console.error('Uncaught exception:', error);
|
||||||
|
_nodeprocess.default.exit(1);
|
||||||
|
});
|
||||||
|
_nodeprocess.default.on('unhandledRejection', (reason)=>{
|
||||||
|
console.error('Unhandled rejection:', reason);
|
||||||
|
_nodeprocess.default.exit(1);
|
||||||
|
});
|
||||||
|
dummySpan.traceChildAsync('dummy', (childSpan)=>fn(childSpan, onCleanup)).finally(()=>{
|
||||||
|
dummySpan.stop();
|
||||||
|
printTraceResult(dummySpan.traceResult);
|
||||||
|
_nodeprocess.default.nextTick(whyIsNodeRunning);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return async (span)=>{
|
||||||
|
if (span) {
|
||||||
|
return span.traceChildAsync(taskName, (childSpan)=>fn(childSpan, onCleanup).finally(()=>cleanup()));
|
||||||
|
}
|
||||||
|
return fn(dummySpan, onCleanup).finally(()=>cleanup());
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
async function whyIsNodeRunning() {
|
||||||
|
const mod = await import('why-is-node-running');
|
||||||
|
return mod.default();
|
||||||
|
}
|
||||||
|
function printTraceResult(traceResult = rootTraceResult) {
|
||||||
|
printStats(traceResult.children);
|
||||||
|
printTree(traceResult, (node)=>{
|
||||||
|
if (node.end - node.start < 0) {
|
||||||
|
return node.name;
|
||||||
|
}
|
||||||
|
return `${node.name} ${_picocolors.default.bold(`${(node.end - node.start).toFixed(3)}ms`)}`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function printTree(initialTree, printNode) {
|
||||||
|
function printBranch(tree, branch, isGraphHead, isChildOfLastBranch) {
|
||||||
|
const children = tree.children;
|
||||||
|
let branchHead = '';
|
||||||
|
if (!isGraphHead) {
|
||||||
|
branchHead = children.length > 0 ? '┬ ' : '─ ';
|
||||||
|
}
|
||||||
|
const toPrint = printNode(tree, `${branch}${branchHead}`);
|
||||||
|
if (typeof toPrint === 'string') {
|
||||||
|
console.log(`${branch}${branchHead}${toPrint}`);
|
||||||
|
}
|
||||||
|
let baseBranch = branch;
|
||||||
|
if (!isGraphHead) {
|
||||||
|
baseBranch = branch.slice(0, -2) + (isChildOfLastBranch ? ' ' : '│ ');
|
||||||
|
}
|
||||||
|
const nextBranch = `${baseBranch}├─`;
|
||||||
|
const lastBranch = `${baseBranch}└─`;
|
||||||
|
children.forEach((child, index)=>{
|
||||||
|
const last = children.length - 1 === index;
|
||||||
|
printBranch(child, last ? lastBranch : nextBranch, false, last);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
printBranch(initialTree, '', true, false);
|
||||||
|
}
|
||||||
|
function printStats(stats) {
|
||||||
|
const longestTaskName = Math.max(...stats.map((i)=>i.name.length));
|
||||||
|
const realStart = Math.min(...stats.map((i)=>i.start));
|
||||||
|
const realEnd = Math.max(...stats.map((i)=>i.end));
|
||||||
|
const statsStep = (realEnd - realStart) / 120 | 0;
|
||||||
|
stats.sort((a, b)=>a.start - b.start).forEach((stat)=>{
|
||||||
|
console.log(`[${stat.name}]${' '.repeat(longestTaskName - stat.name.length)}`, ' '.repeat((stat.start - realStart) / statsStep | 0), '='.repeat(Math.max((stat.end - stat.start) / statsStep | 0, 1)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} (index.__exports));
|
||||||
|
return index.__exports;
|
||||||
|
}exports.__require=requireTrace;
|
||||||
2
Dist/Build/trim-source.cjs
Normal file
2
Dist/Build/trim-source.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),trimSource$1=require('./trim-source2.cjs');var trimSourceExports = trimSource$1.__require();
|
||||||
|
const trimSource = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(trimSourceExports);module.exports=trimSource;
|
||||||
47
Dist/Build/trim-source2.cjs
Normal file
47
Dist/Build/trim-source2.cjs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const trimSource=require('../_virtual/trim-source.cjs'),require$$0=require('node:path'),require$$2=require('node:fs/promises'),require$$5=require('fdir'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),dir=require('./constants/dir.cjs');var hasRequiredTrimSource;
|
||||||
|
|
||||||
|
function requireTrimSource () {
|
||||||
|
if (hasRequiredTrimSource) return trimSource.__exports;
|
||||||
|
hasRequiredTrimSource = 1;
|
||||||
|
Object.defineProperty(trimSource.__exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _promises = /*#__PURE__*/ _interop_require_default(require$$2);
|
||||||
|
const _fdir = require$$5;
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
(async ()=>{
|
||||||
|
const promises = [];
|
||||||
|
const paths = await new _fdir.fdir().withFullPaths()// .exclude((dirName, dirPath) => {
|
||||||
|
// if (dirName === 'domainset' || dirName === 'ip' || dirName === 'non_ip') {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// console.error(picocolors.red(`[build-comman] Unknown dir: ${dirPath}`));
|
||||||
|
// return true;
|
||||||
|
// })
|
||||||
|
.filter((filepath, isDirectory)=>{
|
||||||
|
if (isDirectory) return true;
|
||||||
|
const extname = _nodepath.default.extname(filepath);
|
||||||
|
return !(extname === '.js' || extname === '.ts');
|
||||||
|
}).crawl(_dir.SOURCE_DIR).withPromise();
|
||||||
|
for(let i = 0, len = paths.length; i < len; i++){
|
||||||
|
const fullPath = paths[i];
|
||||||
|
promises.push(trimFileLines(fullPath));
|
||||||
|
}
|
||||||
|
return Promise.all(promises);
|
||||||
|
})();
|
||||||
|
async function trimFileLines(file) {
|
||||||
|
let result = '';
|
||||||
|
for await (const line of (0, _fetchtextbyline.readFileByLine)(file)){
|
||||||
|
result += line.trim() + '\n';
|
||||||
|
}
|
||||||
|
return _promises.default.writeFile(file, result);
|
||||||
|
}
|
||||||
|
return trimSource.__exports;
|
||||||
|
}exports.__require=requireTrimSource;
|
||||||
2
Dist/Build/validate-domain-alive.cjs
Normal file
2
Dist/Build/validate-domain-alive.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),validateDomainAlive$1=require('./validate-domain-alive2.cjs');var validateDomainAliveExports = validateDomainAlive$1.__require();
|
||||||
|
const validateDomainAlive = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(validateDomainAliveExports);module.exports=validateDomainAlive;
|
||||||
94
Dist/Build/validate-domain-alive2.cjs
Normal file
94
Dist/Build/validate-domain-alive2.cjs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const validateDomainAlive=require('../_virtual/validate-domain-alive.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),processLine=require('./lib/process-line.cjs'),dir=require('./constants/dir.cjs'),require$$0=require('node:path'),require$$7=require('@henrygd/queue'),isDomainAlive=require('./lib/is-domain-alive.cjs'),require$$5=require('fdir');var hasRequiredValidateDomainAlive;
|
||||||
|
|
||||||
|
function requireValidateDomainAlive () {
|
||||||
|
if (hasRequiredValidateDomainAlive) return validateDomainAlive.__exports;
|
||||||
|
hasRequiredValidateDomainAlive = 1;
|
||||||
|
(function (exports) {
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
function _export(target, all) {
|
||||||
|
for(var name in all)Object.defineProperty(target, name, {
|
||||||
|
enumerable: true,
|
||||||
|
get: all[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_export(exports, {
|
||||||
|
runAgainstDomainset: function() {
|
||||||
|
return runAgainstDomainset;
|
||||||
|
},
|
||||||
|
runAgainstRuleset: function() {
|
||||||
|
return runAgainstRuleset;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
||||||
|
const _processline = /*@__PURE__*/ processLine.__require();
|
||||||
|
const _dir = /*@__PURE__*/ dir.__require();
|
||||||
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
||||||
|
const _queue = require$$7;
|
||||||
|
const _isdomainalive = /*@__PURE__*/ isDomainAlive.__require();
|
||||||
|
const _fdir = require$$5;
|
||||||
|
function _interop_require_default(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const queue = (0, _queue.newQueue)(24);
|
||||||
|
const deadDomains = [];
|
||||||
|
function onDomain(args) {
|
||||||
|
if (!args[1]) {
|
||||||
|
deadDomains.push(args[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(async ()=>{
|
||||||
|
const domainSets = await new _fdir.fdir().withFullPaths().crawl(_dir.SOURCE_DIR + _nodepath.default.sep + 'domainset').withPromise();
|
||||||
|
const domainRules = await new _fdir.fdir().withFullPaths().crawl(_dir.SOURCE_DIR + _nodepath.default.sep + 'non_ip').withPromise();
|
||||||
|
await Promise.all([
|
||||||
|
...domainSets.map(runAgainstDomainset),
|
||||||
|
...domainRules.map(runAgainstRuleset)
|
||||||
|
]);
|
||||||
|
console.log();
|
||||||
|
console.log();
|
||||||
|
console.log(JSON.stringify(deadDomains));
|
||||||
|
})();
|
||||||
|
async function runAgainstRuleset(filepath) {
|
||||||
|
const extname = _nodepath.default.extname(filepath);
|
||||||
|
if (extname !== '.conf') {
|
||||||
|
console.log('[skip]', filepath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const promises = [];
|
||||||
|
for await (const l of (0, _fetchtextbyline.readFileByLine)(filepath)){
|
||||||
|
const line = (0, _processline.processLine)(l);
|
||||||
|
if (!line) continue;
|
||||||
|
const [type, domain] = line.split(',');
|
||||||
|
switch(type){
|
||||||
|
case 'DOMAIN-SUFFIX':
|
||||||
|
case 'DOMAIN':
|
||||||
|
{
|
||||||
|
promises.push(queue.add(()=>(0, _isdomainalive.keyedAsyncMutexWithQueue)(domain, ()=>(0, _isdomainalive.isDomainAlive)(domain, type === 'DOMAIN-SUFFIX'))).then(onDomain));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await Promise.all(promises);
|
||||||
|
console.log('[done]', filepath);
|
||||||
|
}
|
||||||
|
async function runAgainstDomainset(filepath) {
|
||||||
|
const extname = _nodepath.default.extname(filepath);
|
||||||
|
if (extname !== '.conf') {
|
||||||
|
console.log('[skip]', filepath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const promises = [];
|
||||||
|
for await (const l of (0, _fetchtextbyline.readFileByLine)(filepath)){
|
||||||
|
const line = (0, _processline.processLine)(l);
|
||||||
|
if (!line) continue;
|
||||||
|
promises.push(queue.add(()=>(0, _isdomainalive.keyedAsyncMutexWithQueue)(line, ()=>(0, _isdomainalive.isDomainAlive)(line, line[0] === '.'))).then(onDomain));
|
||||||
|
}
|
||||||
|
await Promise.all(promises);
|
||||||
|
console.log('[done]', filepath);
|
||||||
|
}
|
||||||
|
} (validateDomainAlive.__exports));
|
||||||
|
return validateDomainAlive.__exports;
|
||||||
|
}exports.__require=requireValidateDomainAlive;
|
||||||
2
Dist/Build/validate-domestic.cjs
Normal file
2
Dist/Build/validate-domestic.cjs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';const _commonjsHelpers=require('../_virtual/_commonjsHelpers.cjs'),validateDomestic$1=require('./validate-domestic2.cjs');var validateDomesticExports = validateDomestic$1.__require();
|
||||||
|
const validateDomestic = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(validateDomesticExports);module.exports=validateDomestic;
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user