Skip to content

Commit

Permalink
feat: 支持 v2ray SOCKS URI 的输入和输出
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Feb 11, 2025
1 parent 6f82294 commit cae89b8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
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.16.37",
"version": "2.16.38",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"scripts": {
Expand Down
40 changes: 40 additions & 0 deletions backend/src/core/proxy-utils/parsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -1467,6 +1506,7 @@ function isIP(ip) {

export default [
URI_PROXY(),
URI_SOCKS(),
URI_SS(),
URI_SSR(),
URI_VMess(),
Expand Down
5 changes: 5 additions & 0 deletions backend/src/core/proxy-utils/producers/uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -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://${
Expand Down

0 comments on commit cae89b8

Please sign in to comment.