Skip to content

Commit

Permalink
feat: 支持 Loon SOCKS5/SOCKS5-TLS
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Apr 21, 2024
1 parent 89ab72e commit 3ab21b0
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Core functionalities:
- [x] Clash Proxies YAML
- [x] Clash Proxy JSON(single line)
- [x] QX (SS, SSR, VMess, Trojan, HTTP, SOCKS5, VLESS)
- [x] Loon (SS, SSR, VMess, Trojan, HTTP, SOCKS5, WireGuard, VLESS, Hysteria 2)
- [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), SSR(external, only for macOS), External Proxy Program(only for macOS), WireGuard(Surge to Surge))
- [x] Surfboard (SS, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, WireGuard(Surfboard to Surfboard))
- [x] Shadowrocket (SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard, Hysteria, Hysteria 2, TUIC)
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.291",
"version": "2.14.292",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
10 changes: 10 additions & 0 deletions backend/src/core/proxy-utils/parsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,15 @@ function Loon_Http() {
const parse = (line) => getLoonParser().parse(line);
return { name, test, parse };
}
function Loon_Socks5() {
const name = 'Loon SOCKS5 Parser';
const test = (line) => {
return /^.*=\s*socks5/i.test(line.split(',')[0]);
};

const parse = (line) => getLoonParser().parse(line);
return { name, test, parse };
}

function Loon_WireGuard() {
const name = 'Loon WireGuard Parser';
Expand Down Expand Up @@ -1302,6 +1311,7 @@ export default [
Loon_Hysteria2(),
Loon_Trojan(),
Loon_Http(),
Loon_Socks5(),
Loon_WireGuard(),
QX_SS(),
QX_SSR(),
Expand Down
7 changes: 5 additions & 2 deletions backend/src/core/proxy-utils/parsers/peggy/loon.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const grammars = String.raw`
}
}
start = (shadowsocksr/shadowsocks/vmess/vless/trojan/https/http/hysteria2) {
start = (shadowsocksr/shadowsocks/vmess/vless/trojan/https/http/socks5/hysteria2) {
return proxy;
}
Expand Down Expand Up @@ -78,6 +78,9 @@ https = tag equals "https"i address (username password)? (tls_host/tls_verificat
http = tag equals "http"i address (username password)? (fast_open/udp_relay/others)* {
proxy.type = "http";
}
socks5 = tag equals "socks5"i address (username password)? (over_tls/tls_host/tls_verification/fast_open/udp_relay/others)* {
proxy.type = "socks5";
}
address = comma server:server comma port:port {
proxy.server = server;
Expand Down Expand Up @@ -167,7 +170,7 @@ ssr_protocol_param = comma "protocol-param" equals param:$[^=,]+ { proxy["protoc
vmess_alterId = comma "alterId" equals alterId:$[0-9]+ { proxy.alterId = parseInt(alterId); }
over_tls = comma "over-tls" equals flag:bool { proxy.tls = flag; }
tls_host = comma "tls-name" equals host:domain { proxy.sni = host; }
tls_host = comma sni:("tls-name"/"sni") equals host:domain { proxy.sni = host; }
tls_verification = comma "skip-cert-verify" equals flag:bool { proxy["skip-cert-verify"] = flag; }
fast_open = comma "fast-open" equals flag:bool { proxy.tfo = flag; }
Expand Down
7 changes: 5 additions & 2 deletions backend/src/core/proxy-utils/parsers/peggy/loon.peg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}
}

start = (shadowsocksr/shadowsocks/vmess/vless/trojan/https/http/hysteria2) {
start = (shadowsocksr/shadowsocks/vmess/vless/trojan/https/http/socks5/hysteria2) {
return proxy;
}

Expand Down Expand Up @@ -76,6 +76,9 @@ https = tag equals "https"i address (username password)? (tls_host/tls_verificat
http = tag equals "http"i address (username password)? (fast_open/udp_relay/others)* {
proxy.type = "http";
}
socks5 = tag equals "socks5"i address (username password)? (over_tls/tls_host/tls_verification/fast_open/udp_relay/others)* {
proxy.type = "socks5";
}

address = comma server:server comma port:port {
proxy.server = server;
Expand Down Expand Up @@ -165,7 +168,7 @@ ssr_protocol_param = comma "protocol-param" equals param:$[^=,]+ { proxy["protoc
vmess_alterId = comma "alterId" equals alterId:$[0-9]+ { proxy.alterId = parseInt(alterId); }

over_tls = comma "over-tls" equals flag:bool { proxy.tls = flag; }
tls_host = comma "tls-name" equals host:domain { proxy.sni = host; }
tls_host = comma sni:("tls-name"/"sni") equals host:domain { proxy.sni = host; }
tls_verification = comma "skip-cert-verify" equals flag:bool { proxy["skip-cert-verify"] = flag; }

fast_open = comma "fast-open" equals flag:bool { proxy.tfo = flag; }
Expand Down
25 changes: 25 additions & 0 deletions backend/src/core/proxy-utils/producers/loon.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default function Loon_Producer() {
return vless(proxy);
case 'http':
return http(proxy);
case 'socks5':
return socks5(proxy);
case 'wireguard':
return wireguard(proxy);
case 'hysteria2':
Expand Down Expand Up @@ -316,6 +318,29 @@ function http(proxy) {

return result.toString();
}
function socks5(proxy) {
const result = new Result(proxy);
result.append(`${proxy.name}=socks5,${proxy.server},${proxy.port}`);
result.appendIfPresent(`,${proxy.username}`, 'username');
result.appendIfPresent(`,"${proxy.password}"`, 'password');

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

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

// tls verification
result.appendIfPresent(
`,skip-cert-verify=${proxy['skip-cert-verify']}`,
'skip-cert-verify',
);

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

return result.toString();
}

function wireguard(proxy) {
if (Array.isArray(proxy.peers) && proxy.peers.length > 0) {
Expand Down

0 comments on commit 3ab21b0

Please sign in to comment.