mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +08:00
Feat: merge IP CIDR in ruleset
This commit is contained in:
@@ -14,15 +14,18 @@ import { appendArrayInPlace } from './lib/append-array-in-place';
|
||||
export const buildInternalReverseChnCIDR = task(require.main === module, __filename)(async () => {
|
||||
const [cidr] = await getChnCidrPromise();
|
||||
|
||||
const reversedCidr = merge(appendArrayInPlace(
|
||||
exclude(
|
||||
['0.0.0.0/0'],
|
||||
RESERVED_IPV4_CIDR.concat(cidr),
|
||||
true
|
||||
const reversedCidr = 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
|
||||
),
|
||||
// https://github.com/misakaio/chnroutes2/issues/25
|
||||
NON_CN_CIDR_INCLUDED_IN_CHNROUTE
|
||||
));
|
||||
true
|
||||
);
|
||||
|
||||
const outputFile = path.join(OUTPUT_INTERNAL_DIR, 'reversed-chn-cidr.txt');
|
||||
await mkdirp(OUTPUT_INTERNAL_DIR);
|
||||
|
||||
@@ -49,7 +49,6 @@ export const buildAlwaysRealIPModule = task(require.main === module, __filename)
|
||||
// Intranet, Router Setup, and mant more
|
||||
const dataset = [Object.entries(DIRECTS), Object.entries(LANS)];
|
||||
const surge = dataset.flatMap(data => data.flatMap(([, { domains }]) => domains.flatMap((domain) => [`*.${domain}`, domain])));
|
||||
const clash = ;
|
||||
|
||||
return Promise.all([
|
||||
compareAndWriteFile(
|
||||
@@ -69,6 +68,7 @@ export const buildAlwaysRealIPModule = task(require.main === module, __filename)
|
||||
{
|
||||
dns: {
|
||||
'fake-ip-filter': appendArrayInPlace(
|
||||
/** clash */
|
||||
dataset.flatMap(data => data.flatMap(([, { domains }]) => domains.map((domain) => `+.${domain}`))),
|
||||
HOSTNAMES
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Span } from '../../trace';
|
||||
import { appendArrayInPlace } from '../append-array-in-place';
|
||||
import { appendArrayFromSet } from '../misc';
|
||||
import type { SingboxSourceFormat } from '../singbox';
|
||||
import { RuleOutput } from './base';
|
||||
@@ -15,7 +16,18 @@ export class IPListOutput extends RuleOutput {
|
||||
private $merged: string[] | null = null;
|
||||
get merged() {
|
||||
if (!this.$merged) {
|
||||
this.$merged = merge(appendArrayFromSet([], [this.ipcidr, this.ipcidr6]));
|
||||
const results: string[] = [];
|
||||
appendArrayInPlace(
|
||||
results,
|
||||
merge(
|
||||
appendArrayInPlace(Array.from(this.ipcidrNoResolve), Array.from(this.ipcidr)),
|
||||
true
|
||||
)
|
||||
);
|
||||
appendArrayFromSet(results, this.ipcidr6NoResolve);
|
||||
appendArrayFromSet(results, this.ipcidr6);
|
||||
|
||||
this.$merged = results;
|
||||
}
|
||||
return this.$merged;
|
||||
}
|
||||
@@ -26,7 +38,15 @@ export class IPListOutput extends RuleOutput {
|
||||
if (!this.$surge) {
|
||||
const results: string[] = ['DOMAIN,this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'];
|
||||
|
||||
appendArrayFromSet(results, this.ipcidr, i => `IP-CIDR,${i}`);
|
||||
appendArrayInPlace(
|
||||
results,
|
||||
merge(Array.from(this.ipcidrNoResolve)).map(i => `IP-CIDR,${i},no-resolve`, true)
|
||||
);
|
||||
appendArrayFromSet(results, this.ipcidr6NoResolve, i => `IP-CIDR6,${i},no-resolve`);
|
||||
appendArrayInPlace(
|
||||
results,
|
||||
merge(Array.from(this.ipcidr)).map(i => `IP-CIDR,${i}`, true)
|
||||
);
|
||||
appendArrayFromSet(results, this.ipcidr6, i => `IP-CIDR6,${i}`);
|
||||
|
||||
this.$surge = results;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { merge } from 'fast-cidr-tools';
|
||||
import type { Span } from '../../trace';
|
||||
import createKeywordFilter from '../aho-corasick';
|
||||
import { appendArrayInPlace } from '../append-array-in-place';
|
||||
@@ -54,12 +55,18 @@ export class RulesetOutput extends RuleOutput {
|
||||
|
||||
appendArrayFromSet(results, this.urlRegex, i => `URL-REGEX,${i}`);
|
||||
|
||||
appendArrayFromSet(results, this.ipcidrNoResolve, i => `IP-CIDR,${i},no-resolve`);
|
||||
appendArrayInPlace(
|
||||
results,
|
||||
merge(Array.from(this.ipcidrNoResolve)).map(i => `IP-CIDR,${i},no-resolve`, true)
|
||||
);
|
||||
appendArrayFromSet(results, this.ipcidr6NoResolve, i => `IP-CIDR6,${i},no-resolve`);
|
||||
appendArrayFromSet(results, this.ipasnNoResolve, i => `IP-ASN,${i},no-resolve`);
|
||||
appendArrayFromSet(results, this.groipNoResolve, i => `GEOIP,${i},no-resolve`);
|
||||
|
||||
appendArrayFromSet(results, this.ipcidr, i => `IP-CIDR,${i}`);
|
||||
appendArrayInPlace(
|
||||
results,
|
||||
merge(Array.from(this.ipcidr)).map(i => `IP-CIDR,${i}`, true)
|
||||
);
|
||||
appendArrayFromSet(results, this.ipcidr6, i => `IP-CIDR6,${i}`);
|
||||
appendArrayFromSet(results, this.ipasn, i => `IP-ASN,${i}`);
|
||||
appendArrayFromSet(results, this.geoip, i => `GEOIP,${i}`);
|
||||
@@ -80,12 +87,18 @@ export class RulesetOutput extends RuleOutput {
|
||||
|
||||
// appendArrayInPlace(results, this.otherRules);
|
||||
|
||||
appendArrayFromSet(results, this.ipcidrNoResolve, i => `IP-CIDR,${i},no-resolve`);
|
||||
appendArrayInPlace(
|
||||
results,
|
||||
merge(Array.from(this.ipcidrNoResolve)).map(i => `IP-CIDR,${i},no-resolve`, true)
|
||||
);
|
||||
appendArrayFromSet(results, this.ipcidr6NoResolve, i => `IP-CIDR6,${i},no-resolve`);
|
||||
appendArrayFromSet(results, this.ipasnNoResolve, i => `IP-ASN,${i},no-resolve`);
|
||||
appendArrayFromSet(results, this.groipNoResolve, i => `GEOIP,${i},no-resolve`);
|
||||
|
||||
appendArrayFromSet(results, this.ipcidr, i => `IP-CIDR,${i}`);
|
||||
appendArrayInPlace(
|
||||
results,
|
||||
merge(Array.from(this.ipcidr)).map(i => `IP-CIDR,${i}`, true)
|
||||
);
|
||||
appendArrayFromSet(results, this.ipcidr6, i => `IP-CIDR6,${i}`);
|
||||
appendArrayFromSet(results, this.ipasn, i => `IP-ASN,${i}`);
|
||||
appendArrayFromSet(results, this.geoip, i => `GEOIP,${i}`);
|
||||
@@ -94,6 +107,17 @@ export class RulesetOutput extends RuleOutput {
|
||||
}
|
||||
|
||||
singbox(): string[] {
|
||||
const ip_cidr: string[] = [];
|
||||
appendArrayInPlace(
|
||||
ip_cidr,
|
||||
merge(
|
||||
appendArrayInPlace(Array.from(this.ipcidrNoResolve), Array.from(this.ipcidr)),
|
||||
true
|
||||
)
|
||||
);
|
||||
appendArrayFromSet(ip_cidr, this.ipcidr6NoResolve);
|
||||
appendArrayFromSet(ip_cidr, this.ipcidr6);
|
||||
|
||||
const singbox: SingboxSourceFormat = {
|
||||
version: 2,
|
||||
rules: [{
|
||||
@@ -101,7 +125,7 @@ export class RulesetOutput extends RuleOutput {
|
||||
domain_suffix: this.computed()[1],
|
||||
domain_keyword: Array.from(this.domainKeywords),
|
||||
domain_regex: Array.from(this.domainWildcard).map(RuleOutput.domainWildCardToRegex),
|
||||
ip_cidr: appendArrayFromSet([], [this.ipcidr, this.ipcidrNoResolve, this.ipcidr6, this.ipcidr6NoResolve]),
|
||||
ip_cidr,
|
||||
process_name: Array.from(this.processName),
|
||||
process_path: Array.from(this.processPath)
|
||||
}]
|
||||
|
||||
Reference in New Issue
Block a user