mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +08:00
Refactor: domestic, direct, dns mapping, real ip
This commit is contained in:
@@ -1,45 +1,59 @@
|
||||
// @ts-check
|
||||
import path from 'path';
|
||||
import { DOMESTICS } from '../Source/non_ip/domestic';
|
||||
import { DIRECTS } from '../Source/non_ip/direct';
|
||||
import { readFileIntoProcessedArray } from './lib/fetch-text-by-line';
|
||||
import { compareAndWriteFile, createRuleset } from './lib/create-file';
|
||||
import { task } from './trace';
|
||||
import { SHARED_DESCRIPTION } from './lib/constants';
|
||||
import { createMemoizedPromise } from './lib/memo-promise';
|
||||
|
||||
export const getDomesticDomainsRulesetPromise = createMemoizedPromise(async () => {
|
||||
const results = await readFileIntoProcessedArray(path.resolve(import.meta.dir, '../Source/non_ip/domestic.conf'));
|
||||
export const getDomesticAndDirectDomainsRulesetPromise = createMemoizedPromise(async () => {
|
||||
const domestics = await readFileIntoProcessedArray(path.resolve(import.meta.dir, '../Source/non_ip/domestic.conf'));
|
||||
const directs = await readFileIntoProcessedArray(path.resolve(import.meta.dir, '../Source/non_ip/direct.conf'));
|
||||
|
||||
results.push(
|
||||
...Object.entries(DOMESTICS).reduce<string[]>((acc, [key, { domains }]) => {
|
||||
if (key === 'SYSTEM') return acc;
|
||||
return [...acc, ...domains];
|
||||
}, []).map((domain) => `DOMAIN-SUFFIX,${domain}`)
|
||||
);
|
||||
Object.entries(DOMESTICS).forEach(([, { domains }]) => {
|
||||
domestics.push(...domains.map((domain) => `DOMAIN-SUFFIX,${domain}`));
|
||||
});
|
||||
Object.entries(DIRECTS).forEach(([, { domains }]) => {
|
||||
directs.push(...domains.map((domain) => `DOMAIN-SUFFIX,${domain}`));
|
||||
});
|
||||
|
||||
return results;
|
||||
return [domestics, directs] as const;
|
||||
});
|
||||
|
||||
export const buildDomesticRuleset = task(import.meta.main, import.meta.path)(async (span) => {
|
||||
const rulesetDescription = [
|
||||
...SHARED_DESCRIPTION,
|
||||
'',
|
||||
'This file contains known addresses that are avaliable in the Mainland China.'
|
||||
];
|
||||
|
||||
const res = await getDomesticDomainsRulesetPromise();
|
||||
const res = await getDomesticAndDirectDomainsRulesetPromise();
|
||||
|
||||
return Promise.all([
|
||||
createRuleset(
|
||||
span,
|
||||
'Sukka\'s Ruleset - Domestic Domains',
|
||||
rulesetDescription,
|
||||
[
|
||||
...SHARED_DESCRIPTION,
|
||||
'',
|
||||
'This file contains known addresses that are avaliable in the Mainland China.'
|
||||
],
|
||||
new Date(),
|
||||
res,
|
||||
res[0],
|
||||
'ruleset',
|
||||
path.resolve(import.meta.dir, '../List/non_ip/domestic.conf'),
|
||||
path.resolve(import.meta.dir, '../Clash/non_ip/domestic.txt')
|
||||
),
|
||||
createRuleset(
|
||||
span,
|
||||
'Sukka\'s Ruleset - Direct Rules',
|
||||
[
|
||||
...SHARED_DESCRIPTION,
|
||||
'',
|
||||
'This file contains domains and process that should not be proxied.'
|
||||
],
|
||||
new Date(),
|
||||
res[1],
|
||||
'ruleset',
|
||||
path.resolve(import.meta.dir, '../List/non_ip/direct.conf'),
|
||||
path.resolve(import.meta.dir, '../Clash/non_ip/direct.txt')
|
||||
),
|
||||
compareAndWriteFile(
|
||||
span,
|
||||
[
|
||||
@@ -47,20 +61,18 @@ export const buildDomesticRuleset = task(import.meta.main, import.meta.path)(asy
|
||||
`#!desc=Last Updated: ${new Date().toISOString()}`,
|
||||
'',
|
||||
'[Host]',
|
||||
...Object.entries(DOMESTICS)
|
||||
.flatMap(
|
||||
([, { domains, dns, ...rest }]) => [
|
||||
...(
|
||||
'hosts' in rest
|
||||
? Object.entries(rest.hosts).flatMap(([dns, ips]: [dns: string, ips: string[]]) => `${dns} = ${ips.join(', ')}`)
|
||||
: []
|
||||
),
|
||||
...domains.flatMap((domain) => [
|
||||
`${domain} = server:${dns}`,
|
||||
`*.${domain} = server:${dns}`
|
||||
])
|
||||
]
|
||||
)
|
||||
...([...Object.entries(DOMESTICS), ...Object.entries(DIRECTS)])
|
||||
.flatMap(([, { domains, dns, ...rest }]) => [
|
||||
...(
|
||||
'hosts' in rest
|
||||
? Object.entries(rest.hosts).flatMap(([dns, ips]: [dns: string, ips: string[]]) => `${dns} = ${ips.join(', ')}`)
|
||||
: []
|
||||
),
|
||||
...domains.flatMap((domain) => [
|
||||
`${domain} = server:${dns}`,
|
||||
`*.${domain} = server:${dns}`
|
||||
])
|
||||
])
|
||||
],
|
||||
path.resolve(import.meta.dir, '../Modules/sukka_local_dns_mapping.sgmodule')
|
||||
)
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import path from 'path';
|
||||
import { task } from './trace';
|
||||
import { compareAndWriteFile } from './lib/create-file';
|
||||
import { DIRECTS } from '../Source/non_ip/direct';
|
||||
|
||||
const HOSTNAMES = [
|
||||
// Intranet
|
||||
'*.lan',
|
||||
'*.localdomain',
|
||||
'*.localhost',
|
||||
'*.home.arpa',
|
||||
// Intranet, Router Setup, and mant more
|
||||
...(Object.entries(DIRECTS)).flatMap(([, { domains }]) => domains.flatMap((domain) => [`*.${domain}`, domain])),
|
||||
// Network Detection, Captive Portal
|
||||
'msftncsi.com',
|
||||
'msftconnecttest.com',
|
||||
@@ -27,14 +25,10 @@ const HOSTNAMES = [
|
||||
'stun.twilio.com',
|
||||
'*.stun.twilio.com',
|
||||
'stun.syncthing.net',
|
||||
'stun.*.*',
|
||||
'stun.*.*.*',
|
||||
'stun.*',
|
||||
'controlplane.tailscale.com',
|
||||
// NTP
|
||||
'time.*.com', 'time.*.gov, time.*.edu.cn, time.*.apple.com', 'time1.*.com', 'time2.*.com', 'time3.*.com', 'time4.*.com', 'time5.*.com', 'time6.*.com', 'time7.*.com', 'time8.*.com', 'time9.*.com, ntp.*.com, ntp1.*.com, ntp2.*.com, ntp3.*.com, ntp4.*.com, ntp5.*.com, ntp6.*.com, ntp7.*.com', 'time1.*.com', 'time2.*.com', 'time3.*.com', 'time4.*.com', 'time5.*.com', 'time6.*.com', 'time7.*.com', 'time8.*.com', 'ti me9.*.com', '*.time.edu.cn', '*.ntp.org.cn', '*.pool.ntp.org', 'time1.cloud.tencent.com',
|
||||
// AdGuard
|
||||
'local.adguard.org',
|
||||
'injections.adguard.org',
|
||||
'time.*.com', 'time.*.gov, time.*.edu.cn, time.*.apple.com', 'time?.*.com', 'ntp.*.com', 'ntp?.*.com', '*.time.edu.cn', '*.ntp.org.cn', '*.pool.ntp.org', 'time*.cloud.tencent.com',
|
||||
// QQ Login
|
||||
'localhost.ptlogin2.qq.com',
|
||||
'localhost.sec.qq.com',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getAppleCdnDomainsPromise } from './build-apple-cdn';
|
||||
import { getDomesticDomainsRulesetPromise } from './build-domestic-ruleset';
|
||||
import { getDomesticAndDirectDomainsRulesetPromise } from './build-domestic-ruleset';
|
||||
import { surgeRulesetToClashClassicalTextRuleset, surgeDomainsetToClashRuleset } from './lib/clash';
|
||||
import { readFileIntoProcessedArray } from './lib/fetch-text-by-line';
|
||||
import { task } from './trace';
|
||||
@@ -46,7 +46,8 @@ export const buildSSPanelUIMAppProfile = task(import.meta.main, import.meta.path
|
||||
lanCidrs
|
||||
] = await Promise.all([
|
||||
// domestic - domains
|
||||
getDomesticDomainsRulesetPromise().then(surgeRulesetToClashClassicalTextRuleset),
|
||||
getDomesticAndDirectDomainsRulesetPromise()
|
||||
.then(data => data.flatMap(surgeRulesetToClashClassicalTextRuleset)),
|
||||
getAppleCdnDomainsPromise().then(domains => domains.map(domain => `DOMAIN-SUFFIX,${domain}`)),
|
||||
getMicrosoftCdnRulesetPromise().then(surgeRulesetToClashClassicalTextRuleset),
|
||||
readFileIntoProcessedArray(path.resolve(import.meta.dir, '../Source/non_ip/apple_cn.conf')),
|
||||
|
||||
Reference in New Issue
Block a user