Skip to content

Commit

Permalink
feat: 远程订阅支持 insecure 不验证服务器证书
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Oct 30, 2024
1 parent b048ecd commit e09d660
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
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.405",
"version": "2.14.406",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/restful/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ async function downloadSubscription(req, res) {
if (!$arguments.noFlow) {
// forward flow headers
const flowInfo = await getFlowHeaders(
url,
$arguments?.insecure ? `${url}#insecure` : url,
$arguments.flowUserAgent,
undefined,
proxy || sub.proxy,
Expand Down Expand Up @@ -378,7 +378,7 @@ async function downloadCollection(req, res) {
}
if (!$arguments.noFlow) {
const flowInfo = await getFlowHeaders(
url,
$arguments?.insecure ? `${url}#insecure` : url,
$arguments.flowUserAgent,
undefined,
proxy || sub.proxy || collection.proxy,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/restful/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async function getFlowInfo(req, res) {
}
} else {
const flowHeaders = await getFlowHeaders(
url,
$arguments?.insecure ? `${url}#insecure` : url,
$arguments.flowUserAgent,
undefined,
sub.proxy,
Expand Down
8 changes: 7 additions & 1 deletion backend/src/utils/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,13 @@ export default async function download(
$.write(cached, customCacheKey);
}
} else {
const insecure = $arguments?.insecure
? isNode
? { strictSSL: false }
: { insecure: true }
: undefined;
$.info(
`Downloading...\nUser-Agent: ${userAgent}\nTimeout: ${requestTimeout}\nProxy: ${proxy}\nURL: ${url}`,
`Downloading...\nUser-Agent: ${userAgent}\nTimeout: ${requestTimeout}\nProxy: ${proxy}\nInsecure: ${!!insecure}\nURL: ${url}`,
);
try {
const { body, headers } = await http.get({
Expand All @@ -167,6 +172,7 @@ export default async function download(
...(isLoon && proxy ? { node: proxy } : {}),
...(isQX && proxy ? { opts: { policy: proxy } } : {}),
...(proxy ? getPolicyDescriptor(proxy) : {}),
...(insecure ? insecure : {}),
});

if (headers) {
Expand Down
22 changes: 18 additions & 4 deletions backend/src/utils/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export async function getFlowHeaders(
// $.info(`使用缓存的流量信息: ${url}`);
flowInfo = cached;
} else {
const insecure = $arguments?.insecure
? $.env.isNode
? { strictSSL: false }
: { insecure: true }
: undefined;
const { defaultProxy, defaultFlowUserAgent, defaultTimeout } =
$.read(SETTINGS_KEY);
let proxy = customProxy || defaultProxy;
Expand All @@ -64,22 +69,27 @@ export async function getFlowHeaders(
$.info(
`使用 GET 方法从响应体获取流量信息: ${flowUrl}, User-Agent: ${
userAgent || ''
}`,
}, Insecure: ${!!insecure}, Proxy: ${proxy}`,
);
const { body } = await http.get({
url: flowUrl,
headers: {
'User-Agent': userAgent,
},
timeout: requestTimeout,
...(proxy ? { proxy } : {}),
...(isLoon && proxy ? { node: proxy } : {}),
...(isQX && proxy ? { opts: { policy: proxy } } : {}),
...(proxy ? getPolicyDescriptor(proxy) : {}),
...(insecure ? insecure : {}),
});
flowInfo = body;
} else {
try {
$.info(
`使用 HEAD 方法从响应头获取流量信息: ${url}, User-Agent: ${
userAgent || ''
}, Proxy: ${proxy}`,
}, Insecure: ${!!insecure}, Proxy: ${proxy}`,
);
const { headers } = await http.head({
url: url
Expand All @@ -103,20 +113,23 @@ export async function getFlowHeaders(
...(isLoon && proxy ? { node: proxy } : {}),
...(isQX && proxy ? { opts: { policy: proxy } } : {}),
...(proxy ? getPolicyDescriptor(proxy) : {}),
...(insecure ? insecure : {}),
});
flowInfo = getFlowField(headers);
} catch (e) {
$.error(
`使用 HEAD 方法从响应头获取流量信息失败: ${url}, User-Agent: ${
userAgent || ''
}, Proxy: ${proxy}: ${e.message ?? e}`,
}, Insecure: ${!!insecure}, Proxy: ${proxy}: ${
e.message ?? e
}`,
);
}
if (!flowInfo) {
$.info(
`使用 GET 方法获取流量信息: ${url}, User-Agent: ${
userAgent || ''
}, Proxy: ${proxy}`,
}, Insecure: ${!!insecure}, Proxy: ${proxy}`,
);
const { headers } = await http.get({
url: url
Expand All @@ -140,6 +153,7 @@ export async function getFlowHeaders(
...(isLoon && proxy ? { node: proxy } : {}),
...(isQX && proxy ? { opts: { policy: proxy } } : {}),
...(proxy ? getPolicyDescriptor(proxy) : {}),
...(insecure ? insecure : {}),
});
flowInfo = getFlowField(headers);
}
Expand Down

0 comments on commit e09d660

Please sign in to comment.