Compare commits

..

5 Commits

9 changed files with 134 additions and 9 deletions

View File

@@ -28,6 +28,10 @@ Core functionalities:
> ⚠️ Do not use `Shadowrocket` to export URI and then import it as input. It is not a standard URI.
- [x] Normal Proxy(`socks5`, `socks5+tls`, `http`, `https`(it's ok))
example: `socks5+tls://user:pass@ip:port#name`
- [x] URI(SS, SSR, VMess, VLESS, Trojan, Hysteria, Hysteria 2, TUIC v5, WireGuard)
- [x] Clash Proxies YAML
- [x] Clash Proxy JSON(single line)

View File

@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.443",
"version": "2.14.448",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {

View File

@@ -27,6 +27,42 @@ function surge_port_hopping(raw) {
};
}
function URI_PROXY() {
// socks5+tls
// socks5
// http, https(可以这么写)
const name = 'URI PROXY Parser';
const test = (line) => {
return /^(socks5\+tls|socks5|http|https):\/\//.test(line);
};
const parse = (line) => {
// parse url
// eslint-disable-next-line no-unused-vars
let [__, type, tls, username, password, server, port, query, name] =
line.match(
/^(socks5|http|http)(\+tls|s)?:\/\/(?:(.*?):(.*?)@)?(.*?):(\d+?)(\?.*?)?(?:#(.*?))?$/,
);
const proxy = {
name:
name != null
? decodeURIComponent(name)
: `${type} ${server}:${port}`,
type,
tls: tls ? true : false,
server,
port,
username:
username != null ? decodeURIComponent(username) : undefined,
password:
password != null ? decodeURIComponent(password) : undefined,
};
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() {
@@ -1392,6 +1428,7 @@ function isIP(ip) {
}
export default [
URI_PROXY(),
URI_SS(),
URI_SSR(),
URI_VMess(),

View File

@@ -3,7 +3,7 @@ import $ from '@/core/app';
import { isIPv4, isIPv6 } from '@/utils';
const detourParser = (proxy, parsedProxy) => {
if (proxy['dialer-proxy']) parsedProxy.detour = proxy['dialer-proxy'];
parsedProxy.detour = proxy['dialer-proxy'] || proxy.detour;
};
const tfoParser = (proxy, parsedProxy) => {
parsedProxy.tcp_fast_open = false;

View File

@@ -213,9 +213,29 @@ async function downloadSubscription(req, res) {
}
}
if (sub.subUserinfo) {
let subUserInfo;
if (/^https?:\/\//.test(sub.subUserinfo)) {
try {
subUserInfo = await getFlowHeaders(
undefined,
undefined,
undefined,
proxy || sub.proxy,
sub.subUserinfo,
);
} catch (e) {
$.error(
`订阅 ${name} 使用自定义流量链接 ${
sub.subUserinfo
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
);
}
} else {
subUserInfo = sub.subUserinfo;
}
res.set(
'subscription-userinfo',
[sub.subUserinfo, flowInfo].filter((i) => i).join('; '),
[subUserInfo, flowInfo].filter((i) => i).join('; '),
);
}
@@ -255,7 +275,7 @@ async function downloadSubscription(req, res) {
);
}
} else {
$.error(`🌍 Sub-Store 下载订阅失败`, `❌ 未找到订阅:${name}`);
$.error(`🌍 Sub-Store 下载订阅失败\n❌ 未找到订阅:${name}`);
failed(
res,
new ResourceNotFoundError(
@@ -415,9 +435,29 @@ async function downloadCollection(req, res) {
}
}
if (sub.subUserinfo) {
let subUserInfo;
if (/^https?:\/\//.test(sub.subUserinfo)) {
try {
subUserInfo = await getFlowHeaders(
undefined,
undefined,
undefined,
proxy || sub.proxy,
sub.subUserinfo,
);
} catch (e) {
$.error(
`组合订阅 ${name} 使用自定义流量链接 ${
sub.subUserinfo
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
);
}
} else {
subUserInfo = sub.subUserinfo;
}
res.set(
'subscription-userinfo',
[sub.subUserinfo, flowInfo].filter((i) => i).join('; '),
[subUserInfo, flowInfo].filter((i) => i).join('; '),
);
}
}

View File

@@ -179,7 +179,7 @@ async function getFile(req, res) {
);
}
} else {
$.error(`🌍 Sub-Store 下载文件失败`, `❌ 未找到文件:${name}`);
$.error(`🌍 Sub-Store 下载文件失败\n❌ 未找到文件:${name}`);
failed(
res,
new ResourceNotFoundError(

View File

@@ -57,9 +57,29 @@ async function getFlowInfo(req, res) {
!['localFirst', 'remoteFirst'].includes(sub.mergeSources)
) {
if (sub.subUserinfo) {
let subUserInfo;
if (/^https?:\/\//.test(sub.subUserinfo)) {
try {
subUserInfo = await getFlowHeaders(
undefined,
undefined,
undefined,
sub.proxy,
sub.subUserinfo,
);
} catch (e) {
$.error(
`订阅 ${name} 使用自定义流量链接 ${
sub.subUserinfo
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
);
}
} else {
subUserInfo = sub.subUserinfo;
}
try {
success(res, {
...parseFlowHeaders(sub.subUserinfo),
...parseFlowHeaders(subUserInfo),
});
} catch (e) {
$.error(
@@ -149,9 +169,29 @@ async function getFlowInfo(req, res) {
startDate: $arguments.startDate,
cycleDays: $arguments.cycleDays,
});
let subUserInfo;
if (/^https?:\/\//.test(sub.subUserinfo)) {
try {
subUserInfo = await getFlowHeaders(
undefined,
undefined,
undefined,
sub.proxy,
sub.subUserinfo,
);
} catch (e) {
$.error(
`订阅 ${name} 使用自定义流量链接 ${
sub.subUserinfo
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
);
}
} else {
subUserInfo = sub.subUserinfo;
}
const result = {
...parseFlowHeaders(
[sub.subUserinfo, flowHeaders].filter((i) => i).join('; '),
[subUserInfo, flowHeaders].filter((i) => i).join('; '),
),
};
if (remainingDays != null) {

View File

@@ -1,6 +1,7 @@
import $ from '@/core/app';
import dnsPacket from 'dns-packet';
import { Buffer } from 'buffer';
import { isIPv4 } from '@/utils';
export async function doh({ url, domain, type = 'A', timeout, edns }) {
const buf = dnsPacket.encode({
@@ -23,7 +24,7 @@ export async function doh({ url, domain, type = 'A', timeout, edns }) {
{
code: 'CLIENT_SUBNET',
ip: edns,
sourcePrefixLength: 24,
sourcePrefixLength: isIPv4(edns) ? 24 : 56,
scopePrefixLength: 0,
},
],

View File

@@ -167,6 +167,9 @@ export async function getFlowHeaders(
flowInfo = getFlowField(headers);
}
}
if (flowInfo) {
flowInfo = flowInfo.trim();
}
if (flowInfo) {
headersResourceCache.set(id, flowInfo);
}