From 71fc9affbf50c8722414d9f42be67a297aadb700 Mon Sep 17 00:00:00 2001 From: xream Date: Wed, 12 Feb 2025 03:21:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20v2ray=20SOCKS=20UR?= =?UTF-8?q?I=20=E7=9A=84=E8=BE=93=E5=85=A5=E5=92=8C=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/core/proxy-utils/parsers/index.js | 40 +++++++++++++++++++ .../core/proxy-utils/preprocessors/index.js | 1 + backend/src/core/proxy-utils/producers/uri.js | 5 +++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/backend/package.json b/backend/package.json index cad4553..1cdcba2 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.16.37", + "version": "2.16.38", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/parsers/index.js b/backend/src/core/proxy-utils/parsers/index.js index 1b2d41b..4ca6890 100644 --- a/backend/src/core/proxy-utils/parsers/index.js +++ b/backend/src/core/proxy-utils/parsers/index.js @@ -76,7 +76,46 @@ function URI_PROXY() { }; return { name, test, parse }; } +function URI_SOCKS() { + const name = 'URI SOCKS Parser'; + const test = (line) => { + return /^socks:\/\//.test(line); + }; + const parse = (line) => { + // parse url + // eslint-disable-next-line no-unused-vars + let [__, type, auth, server, port, query, name] = line.match( + /^(socks)?:\/\/(?:(.*)@)?(.*?)(?::(\d+?))?(\?.*?)?(?:#(.*?))?$/, + ); + if (port) { + port = parseInt(port, 10); + } else { + $.error(`port is not present in line: ${line}`); + throw new Error(`port is not present in line: ${line}`); + } + let username, password; + if (auth) { + const parsed = Base64.decode(decodeURIComponent(auth)).split(':'); + username = parsed[0]; + password = parsed[1]; + } + const proxy = { + name: + name != null + ? decodeURIComponent(name) + : `${type} ${server}:${port}`, + type: 'socks5', + server, + port, + username, + password, + }; + + return proxy; + }; + return { name, test, parse }; +} // Parse SS URI format (only supports new SIP002, legacy format is depreciated). // reference: https://github.com/shadowsocks/shadowsocks-org/wiki/SIP002-URI-Scheme function URI_SS() { @@ -1467,6 +1506,7 @@ function isIP(ip) { export default [ URI_PROXY(), + URI_SOCKS(), URI_SS(), URI_SSR(), URI_VMess(), diff --git a/backend/src/core/proxy-utils/preprocessors/index.js b/backend/src/core/proxy-utils/preprocessors/index.js index 2305800..2c86603 100644 --- a/backend/src/core/proxy-utils/preprocessors/index.js +++ b/backend/src/core/proxy-utils/preprocessors/index.js @@ -16,6 +16,7 @@ function Base64Encoded() { const keys = [ 'dm1lc3M', // vmess 'c3NyOi8v', // ssr:// + 'c29ja3M6Ly', // socks:// 'dHJvamFu', // trojan 'c3M6Ly', // ss:/ 'c3NkOi8v', // ssd:// diff --git a/backend/src/core/proxy-utils/producers/uri.js b/backend/src/core/proxy-utils/producers/uri.js index 7b87540..edcbc2b 100644 --- a/backend/src/core/proxy-utils/producers/uri.js +++ b/backend/src/core/proxy-utils/producers/uri.js @@ -27,6 +27,11 @@ export default function URI_Producer() { proxy.server = `[${proxy.server}]`; } switch (proxy.type) { + case 'socks5': + result = `socks://${encodeURIComponent( + Base64.encode(`${proxy.username}:${proxy.password}`), + )}@${proxy.server}:${proxy.port}#${proxy.name}`; + break; case 'ss': const userinfo = `${proxy.cipher}:${proxy.password}`; result = `ss://${