Skip to content

Commit

Permalink
feat: Surge 支持 direct
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Dec 12, 2024
1 parent 9a3cd4f commit 08bf0b7
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Core functionalities:
- [x] Clash Proxy JSON(single line)
- [x] QX (SS, SSR, VMess, Trojan, HTTP, SOCKS5, VLESS)
- [x] Loon (SS, SSR, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, WireGuard, VLESS, Hysteria 2)
- [x] Surge (SS, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, TUIC, Snell, Hysteria 2, SSH(Password authentication only), External Proxy Program(only for macOS), WireGuard(Surge to Surge))
- [x] Surge (Direct, SS, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, TUIC, Snell, Hysteria 2, SSH(Password authentication only), External Proxy Program(only for macOS), WireGuard(Surge to Surge))
- [x] Surfboard (SS, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, WireGuard(Surfboard to Surfboard))
- [x] Clash.Meta (SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard, Hysteria, Hysteria 2, TUIC)
- [x] Stash (SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard, Hysteria, TUIC, Juicity, SSH)
Expand Down
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.439",
"version": "2.14.440",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
9 changes: 9 additions & 0 deletions backend/src/core/proxy-utils/parsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,14 @@ function Loon_WireGuard() {
return { name, test, parse };
}

function Surge_Direct() {
const name = 'Surge Direct Parser';
const test = (line) => {
return /^.*=\s*direct/.test(line.split(',')[0]);
};
const parse = (line) => getSurgeParser().parse(line);
return { name, test, parse };
}
function Surge_SSH() {
const name = 'Surge SSH Parser';
const test = (line) => {
Expand Down Expand Up @@ -1381,6 +1389,7 @@ export default [
URI_Hysteria2(),
URI_Trojan(),
Clash_All(),
Surge_Direct(),
Surge_SSH(),
Surge_SS(),
Surge_VMess(),
Expand Down
5 changes: 4 additions & 1 deletion backend/src/core/proxy-utils/parsers/peggy/surge.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const grammars = String.raw`
}
}
start = (shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh) {
start = (shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/direct) {
return proxy;
}
Expand Down Expand Up @@ -117,6 +117,9 @@ socks5_tls = tag equals "socks5-tls" address (username password)? (usernamek pas
proxy.tls = true;
handleShadowTLS();
}
direct = tag equals "direct" (ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/block_quic/others)* {
proxy.type = "direct";
}
address = comma server:server comma port:port {
proxy.server = server;
Expand Down
6 changes: 4 additions & 2 deletions backend/src/core/proxy-utils/parsers/peggy/surge.peg
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}
}

start = (shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh) {
start = (shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/direct) {
return proxy;
}

Expand Down Expand Up @@ -115,7 +115,9 @@ socks5_tls = tag equals "socks5-tls" address (username password)? (usernamek pas
proxy.tls = true;
handleShadowTLS();
}

direct = tag equals "direct" (ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/block_quic/others)* {
proxy.type = "direct";
}
address = comma server:server comma port:port {
proxy.server = server;
proxy.port = port;
Expand Down
50 changes: 50 additions & 0 deletions backend/src/core/proxy-utils/producers/surge.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default function Surge_Producer() {
return vmess(proxy, opts['include-unsupported-proxy']);
case 'http':
return http(proxy);
case 'direct':
return direct(proxy);
case 'socks5':
return socks5(proxy);
case 'snell':
Expand Down Expand Up @@ -503,6 +505,54 @@ function http(proxy) {

return result.toString();
}
function direct(proxy) {
const result = new Result(proxy);
const type = 'direct';
result.append(`${proxy.name}=${type}`);

const ip_version = ipVersions[proxy['ip-version']] || proxy['ip-version'];
result.appendIfPresent(`,ip-version=${ip_version}`, 'ip-version');

result.appendIfPresent(
`,no-error-alert=${proxy['no-error-alert']}`,
'no-error-alert',
);

// tfo
result.appendIfPresent(`,tfo=${proxy.tfo}`, 'tfo');

// udp
result.appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp');

// test-url
result.appendIfPresent(`,test-url=${proxy['test-url']}`, 'test-url');
result.appendIfPresent(
`,test-timeout=${proxy['test-timeout']}`,
'test-timeout',
);
result.appendIfPresent(`,test-udp=${proxy['test-udp']}`, 'test-udp');
result.appendIfPresent(`,hybrid=${proxy['hybrid']}`, 'hybrid');
result.appendIfPresent(`,tos=${proxy['tos']}`, 'tos');
result.appendIfPresent(
`,allow-other-interface=${proxy['allow-other-interface']}`,
'allow-other-interface',
);
result.appendIfPresent(
`,interface=${proxy['interface-name']}`,
'interface-name',
);

// block-quic
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');

// underlying-proxy
result.appendIfPresent(
`,underlying-proxy=${proxy['underlying-proxy']}`,
'underlying-proxy',
);

return result.toString();
}

function socks5(proxy) {
const result = new Result(proxy);
Expand Down

0 comments on commit 08bf0b7

Please sign in to comment.