Compare commits

..

9 Commits

Author SHA1 Message Date
xream
fea9de4fae feat: IP4P 合并进 IPv6; ProxyUtils 中增加 ipAddress 2024-07-18 18:35:22 +08:00
xream
cddd1818fe chore: bump release version 2024-07-08 02:51:21 +08:00
xream
f94830b2df Merge pull request #339 from zhiqiang02/add-tai-wan-keyword
Add 'Tai Wan' as a keyword for Taiwan flag
2024-07-08 02:50:13 +08:00
zhiqiang02
e02a26040e Add 'Tai Wan' as a keyword for Taiwan flag
碰到了某机场奇奇怪怪的节点名
2024-07-08 02:38:50 +08:00
xream
6906efdd55 chore: bump release version 2024-07-02 21:04:14 +08:00
xream
9558b63261 Merge pull request #336 from cooip-jm/patch-1
处理grpc-opts为 {} 的情况
2024-07-02 21:03:30 +08:00
cooip-jm
4bfdef17ee 处理grpc-opts为 {} 的情况
该字段仅影响sing-box内核,对mihomo无影响
2024-07-02 21:01:11 +08:00
xream
9d29fc8a09 feat: 处理 reality-opts 为 {} 的情况 2024-07-02 20:39:04 +08:00
xream
f524920c13 feat: 文件支持设置 查询流量信息订阅链接. 服务器版中使用此链接可在响应中传递订阅流量信息 2024-06-28 18:34:26 +08:00
8 changed files with 104 additions and 17 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.344",
"version": "2.14.349",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
@@ -26,6 +26,7 @@
"dns-packet": "^5.6.1",
"express": "^4.17.1",
"http-proxy-middleware": "^2.0.6",
"ip-address": "^9.0.5",
"js-base64": "^3.7.2",
"jsrsasign": "^11.1.0",
"lodash": "^4.17.21",

25
backend/pnpm-lock.yaml generated
View File

@@ -32,6 +32,9 @@ dependencies:
http-proxy-middleware:
specifier: ^2.0.6
version: registry.npmmirror.com/http-proxy-middleware@2.0.6
ip-address:
specifier: ^9.0.5
version: registry.npmmirror.com/ip-address@9.0.5
js-base64:
specifier: ^3.7.2
version: registry.npmmirror.com/js-base64@3.7.2
@@ -6031,6 +6034,16 @@ packages:
engines: {node: '>=0.10.0'}
dev: true
registry.npmmirror.com/ip-address@9.0.5:
resolution: {integrity: sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==, registry: http://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/ip-address/-/ip-address-9.0.5.tgz}
name: ip-address
version: 9.0.5
engines: {node: '>= 12'}
dependencies:
jsbn: registry.npmmirror.com/jsbn@1.1.0
sprintf-js: registry.npmmirror.com/sprintf-js@1.1.3
dev: false
registry.npmmirror.com/ip6addr@0.2.5:
resolution: {integrity: sha512-9RGGSB6Zc9Ox5DpDGFnJdIeF0AsqXzdH+FspCfPPaU/L/4tI6P+5lIoFUFm9JXs9IrJv1boqAaNCQmoDADTSKQ==, registry: http://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/ip6addr/-/ip6addr-0.2.5.tgz}
name: ip6addr
@@ -6576,6 +6589,12 @@ packages:
version: 0.1.1
dev: false
registry.npmmirror.com/jsbn@1.1.0:
resolution: {integrity: sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==, registry: http://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/jsbn/-/jsbn-1.1.0.tgz}
name: jsbn
version: 1.1.0
dev: false
registry.npmmirror.com/jsesc@0.5.0:
resolution: {integrity: sha512-uZz5UnB7u4T9LvwmFqXii7pZSouaRPorGs5who1Ip7VO0wxanFvBL7GkM6dTHlgX+jhBApRetaWpnDabOeTcnA==, registry: http://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/jsesc/-/jsesc-0.5.0.tgz}
name: jsesc
@@ -9095,6 +9114,12 @@ packages:
version: 1.0.3
dev: false
registry.npmmirror.com/sprintf-js@1.1.3:
resolution: {integrity: sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==, registry: http://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/sprintf-js/-/sprintf-js-1.1.3.tgz}
name: sprintf-js
version: 1.1.3
dev: false
registry.npmmirror.com/sshpk@1.16.1:
resolution: {integrity: sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==, registry: http://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/sshpk/-/sshpk-1.16.1.tgz}
name: sshpk

View File

@@ -2,7 +2,13 @@ import { Buffer } from 'buffer';
import rs from '@/utils/rs';
import YAML from '@/utils/yaml';
import download from '@/utils/download';
import { isIPv4, isIPv6, isValidPortNumber, isNotBlank } from '@/utils';
import {
isIPv4,
isIPv6,
isValidPortNumber,
isNotBlank,
ipAddress,
} from '@/utils';
import PROXY_PROCESSORS, { ApplyProcessor } from './processors';
import PROXY_PREPROCESSORS from './preprocessors';
import PROXY_PRODUCERS from './producers';
@@ -267,6 +273,7 @@ export const ProxyUtils = {
parse,
process: processFn,
produce,
ipAddress,
isIPv4,
isIPv6,
isIP,
@@ -408,6 +415,20 @@ function lastParse(proxy) {
delete proxy.ports;
}
if (['vless'].includes(proxy.type)) {
// 删除 reality-opts: {}
if (
proxy['reality-opts'] &&
Object.keys(proxy['reality-opts']).length === 0
) {
delete proxy['reality-opts'];
}
// 删除 grpc-opts: {}
if (
proxy['grpc-opts'] &&
Object.keys(proxy['grpc-opts']).length === 0
) {
delete proxy['grpc-opts'];
}
// 非 reality, 空 flow 没有意义
if (!proxy['reality-opts'] && !proxy.flow) {
delete proxy.flow;

View File

@@ -1,6 +1,6 @@
import resourceCache from '@/utils/resource-cache';
import scriptResourceCache from '@/utils/script-resource-cache';
import { isIPv4, isIPv6 } from '@/utils';
import { isIPv4, isIPv6, ipAddress } from '@/utils';
import { FULL } from '@/utils/logical';
import { getFlag, removeFlag } from '@/utils/geo';
import { doh } from '@/utils/dns';
@@ -360,10 +360,11 @@ function ScriptOperator(script, targetPlatform, $arguments, source) {
};
}
function parseIP4P(IP4P) {
function parseIP4P(ip) {
let server;
let port;
try {
const IP4P = new ipAddress.Address6(ip).correctForm();
if (!/^2001::[^:]+:[^:]+:[^:]+$/.test(IP4P)) {
throw new Error(`Invalid IP4P: ${IP4P}`);
}
@@ -629,7 +630,7 @@ function ResolveDomainOperator({
)
]
: results[p.server];
if (_type === 'IP4P') {
if (type === 'IPv6' && isIPv6(ip)) {
const { server, port } = parseIP4P(ip);
if (server && port) {
p._domain = p.server;

View File

@@ -1,4 +1,5 @@
import { deleteByName, findByName, updateByName } from '@/utils/database';
import { getFlowHeaders } from '@/utils/flow';
import { FILES_KEY } from '@/constants';
import { failed, success } from '@/restful/response';
import $ from '@/core/app';
@@ -50,7 +51,15 @@ async function getFile(req, res) {
name = decodeURIComponent(name);
$.info(`正在下载文件:${name}`);
let { url, ua, content, mergeSources, ignoreFailedRemoteFile } = req.query;
let {
url,
subInfoUrl,
subInfoUserAgent,
ua,
content,
mergeSources,
ignoreFailedRemoteFile,
} = req.query;
if (url) {
url = decodeURIComponent(url);
$.info(`指定远程文件 URL: ${url}`);
@@ -59,6 +68,14 @@ async function getFile(req, res) {
ua = decodeURIComponent(ua);
$.info(`指定远程文件 User-Agent: ${ua}`);
}
if (subInfoUrl) {
subInfoUrl = decodeURIComponent(subInfoUrl);
$.info(`指定获取流量的 subInfoUrl: ${subInfoUrl}`);
}
if (subInfoUserAgent) {
subInfoUserAgent = decodeURIComponent(subInfoUserAgent);
$.info(`指定获取流量的 subInfoUserAgent: ${subInfoUserAgent}`);
}
if (content) {
content = decodeURIComponent(content);
$.info(`指定本地文件: ${content}`);
@@ -86,6 +103,26 @@ async function getFile(req, res) {
ignoreFailedRemoteFile,
});
try {
subInfoUrl = subInfoUrl || file.subInfoUrl;
if (subInfoUrl) {
// forward flow headers
const flowInfo = await getFlowHeaders(
subInfoUrl,
subInfoUserAgent || file.subInfoUserAgent,
);
if (flowInfo) {
res.set('subscription-userinfo', flowInfo);
}
}
} catch (err) {
$.error(
`文件 ${name} 获取流量信息时发生错误: ${JSON.stringify(
err,
)}`,
);
}
res.set('Content-Type', 'text/plain; charset=utf-8').send(
output ?? '',
);

View File

@@ -329,6 +329,7 @@ export function getFlag(name) {
'台',
'臺',
'Taipei',
'Tai Wan',
],
'🇺🇦': ['Ukraine', '乌克兰', '烏克蘭'],
'🇺🇸': [

View File

@@ -1,3 +1,4 @@
import * as ipAddress from 'ip-address';
// source: https://stackoverflow.com/a/36760050
const IPV4_REGEX = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$/;
@@ -94,6 +95,7 @@ function getPolicyDescriptor(str) {
// })();
export {
ipAddress,
isIPv4,
isIPv6,
isValidPortNumber,

View File

@@ -1,8 +1,7 @@
function operator(proxies = [], targetPlatform, context) {
// 支持快捷操作 不一定要写一个 function
// 可参考 https://t.me/zhetengsha/970
// https://t.me/zhetengsha/1009
// https://t.me/zhetengsha/1009
// proxies 为传入的内部节点数组
// 可在预览界面点击节点查看 JSON 结构 或查看 `target=JSON` 的通用订阅
@@ -19,7 +18,7 @@ function operator(proxies = [], targetPlatform, context) {
// 10. `sni` 在某些协议里会自动与 `servername` 转换
// 11. 读取节点的 ca-str 和 _ca (后端文件路径) 字段, 自动计算 fingerprint (参考 https://t.me/zhetengsha/1512)
// 12. 以 Surge 为例, 最新的参数一般我都会跟进, 以 Surge 文档为例, 一些常用的: TUIC/Hysteria 2 的 `ecn`, Snell 的 `reuse` 连接复用, QUIC 策略 block-quic`, Hysteria 2 下载带宽 `down`
//
//
// 如果只是为了快速修改或者筛选 可以参考 脚本操作支持节点快捷脚本 https://t.me/zhetengsha/970 和 脚本筛选支持节点快捷脚本 https://t.me/zhetengsha/1009
// $arguments 为传入的脚本参数
@@ -30,7 +29,7 @@ function operator(proxies = [], targetPlatform, context) {
// $substore 为 OpenAPI
// 参考 https://github.com/Peng-YM/QuanX/blob/master/Tools/OpenAPI/README.md
// scriptResourceCache 缓存
// 可参考 https://t.me/zhetengsha/1003
// const cache = scriptResourceCache
@@ -43,6 +42,7 @@ function operator(proxies = [], targetPlatform, context) {
// parse, // 订阅解析
// process, // 节点操作/文件操作
// produce, // 输出订阅
// ipAddress, // https://github.com/beaugunderson/ip-address
// isIPv4,
// isIPv6,
// isIP,
@@ -76,7 +76,7 @@ function operator(proxies = [], targetPlatform, context) {
// }
// })
// $content = proxies
// 2. sing-box
// 但是一般不需要这样用, 可参考
@@ -110,7 +110,7 @@ function operator(proxies = [], targetPlatform, context) {
// 4. 一个比较折腾的方案: 在脚本操作中, 把内容同步到另一个 gist
// 见 https://t.me/zhetengsha/1428
//
//
// const content = ProxyUtils.produce([...proxies], platform)
// // YAML
@@ -130,12 +130,11 @@ function operator(proxies = [], targetPlatform, context) {
// yaml.proxies.unshift(...clashMetaProxies)
// $content = ProxyUtils.yaml.dump(yaml)
// { $content, $files } will be passed to the next operator
// { $content, $files } will be passed to the next operator
// $content is the final content of the file
// flowUtils 为机场订阅流量信息处理工具
// 可参考:
// 可参考:
// 1. https://t.me/zhetengsha/948
// context 为传入的上下文
@@ -224,7 +223,7 @@ function operator(proxies = [], targetPlatform, context) {
// 参数说明
// 可参考 https://github.com/sub-store-org/Sub-Store/wiki/%E9%93%BE%E6%8E%A5%E5%8F%82%E6%95%B0%E8%AF%B4%E6%98%8E
console.log(JSON.stringify(context, null, 2))
console.log(JSON.stringify(context, null, 2));
return proxies
return proxies;
}