Skip to content

Commit ca07c65

Browse files
committed
fix: 修复多个文件中的变量声明,优化代理配置逻辑和界面标题
1 parent f991a46 commit ca07c65

5 files changed

Lines changed: 100 additions & 46 deletions

File tree

‎src/output/quanx.ts‎

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ export function formatQuanxConfig(config: ClashConfig): string {
44
const proxies = config.proxies || [];
55
const groups = config['proxy-groups'] || [];
66

7-
let nodeLines: string[] = [];
7+
const nodeLines: string[] = [];
88
for (const proxy of proxies) {
99
const line = transformProxyToQuanx(proxy);
1010
if (line) {
1111
nodeLines.push(line);
1212
}
1313
}
1414

15-
let policyLines: string[] = [];
15+
const policyLines: string[] = [];
1616
for (const group of groups) {
1717
const members = (group.proxies || []).join(', ');
1818
policyLines.push(`static=${group.name}, ${members}, img-url=https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/Proxy.png`);
@@ -42,26 +42,35 @@ function transformProxyToQuanx(proxy: ClashProxy): string | null {
4242

4343
let line = '';
4444
if (type === 'socks5' || type === 'socks') {
45-
let auth = '';
46-
if (proxy.username && proxy.password) {
47-
auth = `, fast-open=false, udp-relay=true, user=${proxy.username}, password=${proxy.password}`;
48-
}
45+
const auth = (proxy.username && proxy.password)
46+
? `, fast-open=false, udp-relay=true, user=${proxy.username}, password=${proxy.password}`
47+
: ', fast-open=false, udp-relay=true';
4948
line = `socks5=${server}:${port}${auth}, tag=${name}`;
5049
} else if (type === 'http' || type === 'https') {
51-
let auth = '';
52-
if (proxy.username && proxy.password) {
53-
auth = `, user=${proxy.username}, password=${proxy.password}`;
54-
}
55-
line = `http=${server}:${port}${auth}, tag=${name}`;
50+
const tls = type === 'https' ? ', over-tls=true' : '';
51+
const auth = (proxy.username && proxy.password)
52+
? `, user=${proxy.username}, password=${proxy.password}`
53+
: '';
54+
line = `http=${server}:${port}${auth}${tls}, tag=${name}`;
5655
} else if (type === 'ss') {
57-
line = `shadowsocks=${server}:${port}, method=${proxy.cipher}, password=${proxy.password}, fast-open=false, udp-relay=true, tag=${name}`;
56+
// QX Shadowsocks 格式
57+
const cipher = proxy.cipher || 'chacha20-ietf-poly1305';
58+
line = `shadowsocks=${server}:${port}, method=${cipher}, password=${proxy.password}, fast-open=false, udp-relay=true, tag=${name}`;
5859
} else if (type === 'trojan') {
5960
line = `trojan=${server}:${port}, password=${proxy.password}, over-tls=true, tls-verification=true, tag=${name}`;
6061
} else if (type === 'vmess') {
61-
line = `vmess=${server}:${port}, method=none, password=${proxy.uuid}, tag=${name}`;
62+
// QX VMess: method 使用节点实际加密方式而非固定 none
63+
const cipher = (proxy.cipher && proxy.cipher !== 'auto') ? String(proxy.cipher) : 'chacha20-ietf-poly1305';
64+
const tls = proxy.tls ? ', obfs=over-tls' : '';
65+
line = `vmess=${server}:${port}, method=${cipher}, password=${proxy.uuid}${tls}, tag=${name}`;
66+
} else if (type === 'vless') {
67+
// QX VLESS (需要 QX >= 1.0.30)
68+
line = `vless=${server}:${port}, password=${proxy.uuid}, over-tls=true, tag=${name}`;
6269
} else {
63-
line = `socks5=${server}:${port}, tag=${name}`;
70+
// 不支持的类型跳过
71+
return null;
6472
}
6573

6674
return line;
6775
}
76+

‎src/output/singbox.ts‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function formatSingboxJson(config: ClashConfig): string {
1414
}
1515
}
1616

17-
// 2. 转换策略组
17+
// 2. 转换策略组为 selector
1818
for (const group of clashGroups) {
1919
outbounds.push({
2020
type: 'selector',
@@ -23,32 +23,40 @@ export function formatSingboxJson(config: ClashConfig): string {
2323
});
2424
}
2525

26-
// 3. 默认补全 direct 与 block
26+
// 3. 补全内置出站
2727
outbounds.push(
2828
{ type: 'direct', tag: 'DIRECT' },
2929
{ type: 'block', tag: 'REJECT' },
3030
{ type: 'dns', tag: 'dns-out' }
3131
);
3232

33+
// Sing-box 1.8+ 规范:dns.servers 不放 detour,通过 dns.rules 路由
3334
const singboxConfig = {
3435
log: {
3536
level: 'info',
3637
timestamp: true,
3738
},
3839
dns: {
3940
servers: [
40-
{ tag: 'google', address: 'tls://8.8.8.8' },
41-
{ tag: 'local', address: '223.5.5.5', detour: 'DIRECT' },
41+
{ tag: 'remote', address: 'tls://8.8.8.8', detour: '⚡ 最终出口' },
42+
{ tag: 'local', address: '223.5.5.5' },
43+
{ tag: 'block', address: 'rcode://success' },
4244
],
45+
rules: [
46+
{ geosite: ['cn'], server: 'local' },
47+
{ geosite: ['category-ads-all'], server: 'block', disable_cache: true },
48+
],
49+
final: 'remote',
50+
strategy: 'prefer_ipv4',
4351
},
4452
inbounds: [
4553
{
4654
type: 'tun',
4755
tag: 'tun-in',
48-
interface_name: 'tun0',
49-
inet4_address: '172.19.0.1/30',
56+
address: ['172.19.0.1/30', 'fdfe:dcba:9876::1/126'],
5057
auto_route: true,
5158
strict_route: true,
59+
sniff: true,
5260
},
5361
],
5462
outbounds,
@@ -61,6 +69,7 @@ export function formatSingboxJson(config: ClashConfig): string {
6169
return JSON.stringify(singboxConfig, null, 2);
6270
}
6371

72+
6473
function transformProxyToSingbox(proxy: ClashProxy): Record<string, unknown> | null {
6574
if (!proxy || !proxy.name) return null;
6675

@@ -83,18 +92,22 @@ function transformProxyToSingbox(proxy: ClashProxy): Record<string, unknown> | n
8392

8493
if (type === 'socks5' || type === 'socks') {
8594
outbound.type = 'socks';
95+
outbound.version = '5';
8696
if (proxy.username) outbound.username = proxy.username;
8797
if (proxy.password) outbound.password = proxy.password;
88-
} else if (type === 'http' || type === 'https') {
98+
} else if (type === 'http') {
8999
outbound.type = 'http';
90100
if (proxy.username) outbound.username = proxy.username;
91101
if (proxy.password) outbound.password = proxy.password;
92-
if (type === 'https' || proxy.tls) {
93-
outbound.tls = { enabled: true, server_name: proxy.sni || server };
94-
}
102+
} else if (type === 'https') {
103+
// Sing-box 中 https 代理用 http + tls 实现
104+
outbound.type = 'http';
105+
if (proxy.username) outbound.username = proxy.username;
106+
if (proxy.password) outbound.password = proxy.password;
107+
outbound.tls = { enabled: true, server_name: proxy.sni || server };
95108
} else if (type === 'ss') {
96109
outbound.type = 'shadowsocks';
97-
outbound.method = proxy.cipher;
110+
outbound.method = proxy.cipher || 'chacha20-ietf-poly1305';
98111
outbound.password = proxy.password;
99112
} else if (type === 'vmess') {
100113
outbound.type = 'vmess';
@@ -108,6 +121,8 @@ function transformProxyToSingbox(proxy: ClashProxy): Record<string, unknown> | n
108121
outbound.type = 'vless';
109122
outbound.uuid = proxy.uuid;
110123
if (proxy.flow) outbound.flow = proxy.flow;
124+
// VLESS 通常需要 TLS(Reality 或 TLS)
125+
outbound.tls = { enabled: true, server_name: proxy.sni || proxy.servername || server };
111126
} else if (type === 'trojan') {
112127
outbound.type = 'trojan';
113128
outbound.password = proxy.password;
@@ -117,7 +132,8 @@ function transformProxyToSingbox(proxy: ClashProxy): Record<string, unknown> | n
117132
outbound.password = proxy.auth;
118133
outbound.tls = { enabled: true, server_name: proxy.sni || server };
119134
} else {
120-
outbound.type = type;
135+
// 不支持的类型直接跳过,避免生成无效配置
136+
return null;
121137
}
122138

123139
return outbound;

‎src/output/surge.ts‎

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ export function formatSurgeConf(config: ClashConfig): string {
44
const proxies = config.proxies || [];
55
const groups = config['proxy-groups'] || [];
66

7-
let proxyLines: string[] = [];
7+
const proxyLines: string[] = [];
88
for (const proxy of proxies) {
99
const line = transformProxyToSurge(proxy);
1010
if (line) {
1111
proxyLines.push(line);
1212
}
1313
}
1414

15-
let groupLines: string[] = [];
15+
const groupLines: string[] = [];
1616
for (const group of groups) {
1717
const members = (group.proxies || []).join(', ');
1818
groupLines.push(`${group.name} = select, ${members}`);
@@ -43,26 +43,49 @@ function transformProxyToSurge(proxy: ClashProxy): string | null {
4343
const dialerProxy = proxy['dialer-proxy'] as string | undefined;
4444

4545
const type = (proxy.type || '').toLowerCase();
46-
let parts: string[] = [];
46+
const parts: string[] = [];
4747

4848
if (type === 'socks5' || type === 'socks') {
49+
// Surge SOCKS5: name = socks5, server, port, username=x, password=x
4950
parts.push('socks5', server, String(port));
5051
if (proxy.username) parts.push(`username=${proxy.username}`);
5152
if (proxy.password) parts.push(`password=${proxy.password}`);
5253
parts.push('udp-relay=true');
53-
} else if (type === 'http' || type === 'https') {
54-
parts.push(type === 'https' ? 'https' : 'http', server, String(port));
54+
} else if (type === 'http') {
55+
parts.push('http', server, String(port));
5556
if (proxy.username) parts.push(`username=${proxy.username}`);
5657
if (proxy.password) parts.push(`password=${proxy.password}`);
58+
} else if (type === 'https') {
59+
// Surge: https 用 http 类型加 tls=true
60+
parts.push('http', server, String(port));
61+
if (proxy.username) parts.push(`username=${proxy.username}`);
62+
if (proxy.password) parts.push(`password=${proxy.password}`);
63+
parts.push('tls=true');
64+
if (proxy.sni) parts.push(`sni=${proxy.sni}`);
5765
} else if (type === 'ss') {
58-
parts.push('custom', server, String(port), String(proxy.cipher), String(proxy.password), 'https://raw.githubusercontent.com/lhie1/Rules/master/SSEncrypt.module');
66+
// Surge 4+ 标准 Shadowsocks 格式
67+
parts.push('ss', server, String(port));
68+
parts.push(`encrypt-method=${proxy.cipher}`);
69+
parts.push(`password=${proxy.password}`);
70+
parts.push('udp-relay=true');
5971
} else if (type === 'trojan') {
60-
parts.push('trojan', server, String(port), `password=${proxy.password}`);
72+
// Surge Trojan 格式
73+
parts.push('trojan', server, String(port));
74+
parts.push(`password=${proxy.password}`);
6175
if (proxy.sni) parts.push(`sni=${proxy.sni}`);
76+
parts.push('udp-relay=true');
6277
} else if (type === 'vmess') {
63-
parts.push('vmess', server, String(port), `username=${proxy.uuid}`);
78+
// Surge VMess 格式
79+
parts.push('vmess', server, String(port));
80+
parts.push(`username=${proxy.uuid}`);
81+
if (proxy.cipher) parts.push(`encrypt-method=${proxy.cipher}`);
82+
if (proxy.tls) {
83+
parts.push('tls=true');
84+
if (proxy.servername) parts.push(`sni=${proxy.servername}`);
85+
}
6486
} else {
65-
parts.push(type, server, String(port));
87+
// 降级回 socks5
88+
parts.push('socks5', server, String(port));
6689
}
6790

6891
if (dialerProxy) {
@@ -71,3 +94,4 @@ function transformProxyToSurge(proxy: ClashProxy): string | null {
7194

7295
return `${name} = ${parts.join(', ')}`;
7396
}
97+

‎src/script.js‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,31 +97,36 @@ function main(config, profileName) {
9797
const socksNodeName = customSocks.name || homeExitName;
9898

9999
// 根据不同出口协议组装家宽代理节点
100+
// Clash 中 http/https 出口均使用 type=http,https 通过 tls=true 区分
101+
const clashProxyType = (socksType === 'https') ? 'http' : socksType;
102+
100103
let homeExitProxy = {
101104
name: socksNodeName,
102-
type: socksType,
105+
type: clashProxyType,
103106
server: socksServer,
104107
port: socksPort,
105108
"dialer-proxy": frontGroupName
106109
};
107110

108111
if (socksType === 'socks5') {
109-
homeExitProxy.username = socksUsername;
110-
homeExitProxy.password = socksPassword;
112+
if (socksUsername) homeExitProxy.username = socksUsername;
113+
if (socksPassword) homeExitProxy.password = socksPassword;
111114
homeExitProxy.udp = true;
112-
} else if (socksType === 'http' || socksType === 'https') {
113-
homeExitProxy.username = socksUsername;
114-
homeExitProxy.password = socksPassword;
115-
if (socksType === 'https') {
116-
homeExitProxy.tls = true;
117-
if (socksSni) homeExitProxy.sni = socksSni;
118-
}
115+
} else if (socksType === 'http') {
116+
if (socksUsername) homeExitProxy.username = socksUsername;
117+
if (socksPassword) homeExitProxy.password = socksPassword;
118+
} else if (socksType === 'https') {
119+
if (socksUsername) homeExitProxy.username = socksUsername;
120+
if (socksPassword) homeExitProxy.password = socksPassword;
121+
homeExitProxy.tls = true;
122+
if (socksSni) homeExitProxy.sni = socksSni;
119123
} else if (socksType === 'ss') {
120124
homeExitProxy.cipher = socksCipher;
121125
homeExitProxy.password = socksPassword;
122126
homeExitProxy.udp = true;
123127
} else if (socksType === 'trojan') {
124128
homeExitProxy.password = socksPassword;
129+
homeExitProxy.tls = true;
125130
if (socksSni) homeExitProxy.sni = socksSni;
126131
homeExitProxy.udp = true;
127132
} else if (socksType === 'vless') {

‎src/ui/html.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export function renderWebUI(): string {
44
<head>
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<title>CF-Sub - 机场订阅转换 & 链式代理控制台</title>
7+
<title>CF-Sub - 机场订阅转换 & 链式代理</title>
88
<link rel="preconnect" href="https://fonts.googleapis.com">
99
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
1010
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&family=Noto+Sans+SC:wght@400;500;700&display=swap" rel="stylesheet">

0 commit comments

Comments
 (0)