mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-14 02:00:37 +08:00
Fix sing-box by disabling all rule types but Domain & IP
Due to how sing-box rules are composed, it is impossible for me to fully compatible with it
This commit is contained in:
parent
f83cd9071c
commit
6354a1972e
@ -2,7 +2,6 @@ import { BaseWriteStrategy } from './base';
|
|||||||
import { appendArrayInPlace } from 'foxts/append-array-in-place';
|
import { appendArrayInPlace } from 'foxts/append-array-in-place';
|
||||||
import { noop } from 'foxts/noop';
|
import { noop } from 'foxts/noop';
|
||||||
import { withIdentityContent } from '../misc';
|
import { withIdentityContent } from '../misc';
|
||||||
import { fastIpVersion } from 'foxts/fast-ip-version';
|
|
||||||
import stringify from 'json-stringify-pretty-compact';
|
import stringify from 'json-stringify-pretty-compact';
|
||||||
import { OUTPUT_SINGBOX_DIR } from '../../constants/dir';
|
import { OUTPUT_SINGBOX_DIR } from '../../constants/dir';
|
||||||
import { MARKER_DOMAIN } from '../../constants/description';
|
import { MARKER_DOMAIN } from '../../constants/description';
|
||||||
@ -79,19 +78,21 @@ export class SingboxSource extends BaseWriteStrategy {
|
|||||||
|
|
||||||
writeUserAgents = noop;
|
writeUserAgents = noop;
|
||||||
|
|
||||||
writeProcessNames(processName: Set<string>): void {
|
writeProcessNames = noop;
|
||||||
appendArrayInPlace(
|
// writeProcessNames(processName: Set<string>): void {
|
||||||
this.singbox.process_name ??= [],
|
// appendArrayInPlace(
|
||||||
Array.from(processName)
|
// this.singbox.process_name ??= [],
|
||||||
);
|
// Array.from(processName)
|
||||||
}
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
writeProcessPaths(processPath: Set<string>): void {
|
writeProcessPaths = noop;
|
||||||
appendArrayInPlace(
|
// writeProcessPaths(processPath: Set<string>): void {
|
||||||
this.singbox.process_path ??= [],
|
// appendArrayInPlace(
|
||||||
Array.from(processPath)
|
// this.singbox.process_path ??= [],
|
||||||
);
|
// Array.from(processPath)
|
||||||
}
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
writeUrlRegexes = noop;
|
writeUrlRegexes = noop;
|
||||||
|
|
||||||
@ -113,58 +114,62 @@ export class SingboxSource extends BaseWriteStrategy {
|
|||||||
|
|
||||||
writeIpAsns = noop;
|
writeIpAsns = noop;
|
||||||
|
|
||||||
writeSourceIpCidrs(sourceIpCidr: string[]): void {
|
writeSourceIpCidrs = noop;
|
||||||
this.singbox.source_ip_cidr ??= [];
|
// writeSourceIpCidrs(sourceIpCidr: string[]): void {
|
||||||
for (let i = 0, len = sourceIpCidr.length; i < len; i++) {
|
// this.singbox.source_ip_cidr ??= [];
|
||||||
const value = sourceIpCidr[i];
|
// for (let i = 0, len = sourceIpCidr.length; i < len; i++) {
|
||||||
if (value.includes('/')) {
|
// const value = sourceIpCidr[i];
|
||||||
this.singbox.source_ip_cidr.push(value);
|
// if (value.includes('/')) {
|
||||||
continue;
|
// this.singbox.source_ip_cidr.push(value);
|
||||||
}
|
// continue;
|
||||||
const v = fastIpVersion(value);
|
// }
|
||||||
if (v === 4) {
|
// const v = fastIpVersion(value);
|
||||||
this.singbox.source_ip_cidr.push(`${value}/32`);
|
// if (v === 4) {
|
||||||
continue;
|
// this.singbox.source_ip_cidr.push(`${value}/32`);
|
||||||
}
|
// continue;
|
||||||
if (v === 6) {
|
// }
|
||||||
this.singbox.source_ip_cidr.push(`${value}/128`);
|
// if (v === 6) {
|
||||||
continue;
|
// this.singbox.source_ip_cidr.push(`${value}/128`);
|
||||||
}
|
// continue;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
writeSourcePorts(port: Set<string>): void {
|
writeSourcePorts = noop;
|
||||||
this.singbox.source_port ??= [];
|
// writeSourcePorts(port: Set<string>): void {
|
||||||
|
// this.singbox.source_port ??= [];
|
||||||
|
|
||||||
for (const i of port) {
|
// for (const i of port) {
|
||||||
const tmp = Number(i);
|
// const tmp = Number(i);
|
||||||
if (!Number.isNaN(tmp)) {
|
// if (!Number.isNaN(tmp)) {
|
||||||
this.singbox.source_port.push(tmp);
|
// this.singbox.source_port.push(tmp);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
writeDestinationPorts(port: Set<string>): void {
|
writeDestinationPorts = noop;
|
||||||
this.singbox.port ??= [];
|
// writeDestinationPorts(port: Set<string>): void {
|
||||||
|
// this.singbox.port ??= [];
|
||||||
|
|
||||||
for (const i of port) {
|
// for (const i of port) {
|
||||||
const tmp = Number(i);
|
// const tmp = Number(i);
|
||||||
if (!Number.isNaN(tmp)) {
|
// if (!Number.isNaN(tmp)) {
|
||||||
this.singbox.port.push(tmp);
|
// this.singbox.port.push(tmp);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
writeProtocols(protocol: Set<string>): void {
|
writeProtocols = noop;
|
||||||
this.singbox.network ??= [];
|
// writeProtocols(protocol: Set<string>): void {
|
||||||
// protocol has already be normalized and will only be uppercase
|
// this.singbox.network ??= [];
|
||||||
if (protocol.has('UDP')) {
|
// // protocol has already be normalized and will only be uppercase
|
||||||
this.singbox.network.push('udp');
|
// if (protocol.has('UDP')) {
|
||||||
}
|
// this.singbox.network.push('udp');
|
||||||
if (protocol.has('TCP')) {
|
// }
|
||||||
this.singbox.network.push('tcp');
|
// if (protocol.has('TCP')) {
|
||||||
}
|
// this.singbox.network.push('tcp');
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
writeOtherRules = noop;
|
writeOtherRules = noop;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user