mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-29 07:50:33 +00:00
feat: URI 逻辑调整. AnyTLS URI/sing-box 支持传输层(mihomo, Shadowrocket 中自动过滤此类节点)
This commit is contained in:
6 files changed
+196
-137
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.20.10",
|
||||
"version": "2.20.12",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -753,6 +753,8 @@ function URI_AnyTLS() {
|
||||
return /^anytls:\/\//.test(line);
|
||||
};
|
||||
const parse = (line) => {
|
||||
const parsed = URI_VLESS().parse(line.replace('anytls', 'vless'));
|
||||
// 偷个懒
|
||||
line = line.split(/anytls:\/\//)[1];
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
let [__, password, server, port, addons = '', name] =
|
||||
@@ -769,6 +771,8 @@ function URI_AnyTLS() {
|
||||
name = name ?? `AnyTLS ${server}:${port}`;
|
||||
|
||||
const proxy = {
|
||||
...parsed,
|
||||
uuid: undefined,
|
||||
type: 'anytls',
|
||||
name,
|
||||
server,
|
||||
@@ -786,11 +790,14 @@ function URI_AnyTLS() {
|
||||
proxy['skip-cert-verify'] = /(TRUE)|1/i.test(value);
|
||||
} else if (['udp'].includes(key)) {
|
||||
proxy[key] = /(TRUE)|1/i.test(value);
|
||||
} else {
|
||||
} else if (!Object.keys(proxy).includes(key)) {
|
||||
proxy[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (['tcp'].includes(proxy.network) && !proxy['reality-opts']) {
|
||||
delete proxy.network;
|
||||
delete proxy.security;
|
||||
}
|
||||
return proxy;
|
||||
};
|
||||
return { name, test, parse };
|
||||
@@ -940,7 +947,7 @@ function URI_Hysteria() {
|
||||
proxy['_obfs'] = value || '';
|
||||
} else if (['fast-open', 'peer'].includes(key)) {
|
||||
params[key] = value;
|
||||
} else {
|
||||
} else if (!Object.keys(proxy).includes(key)) {
|
||||
proxy[key] = value;
|
||||
}
|
||||
}
|
||||
@@ -1007,7 +1014,7 @@ function URI_TUIC() {
|
||||
} else if (key === 'congestion-control') {
|
||||
proxy['congestion-controller'] = value;
|
||||
delete proxy[key];
|
||||
} else {
|
||||
} else if (!Object.keys(proxy).includes(key)) {
|
||||
proxy[key] = value;
|
||||
}
|
||||
}
|
||||
@@ -1090,7 +1097,7 @@ function URI_WireGuard() {
|
||||
proxy['private-key'] = value;
|
||||
} else if (['udp'].includes(key)) {
|
||||
proxy[key] = /(TRUE)|1/i.test(value);
|
||||
} else if (!['flag'].includes(key)) {
|
||||
} else if (![...Object.keys(proxy), 'flag'].includes(key)) {
|
||||
proxy[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,14 @@ export default function ClashMeta_Producer() {
|
||||
) {
|
||||
// https://wiki.metacubex.one/config/proxies/ss/#cipher
|
||||
return false;
|
||||
} else if (
|
||||
['anytls'].includes(proxy.type) &&
|
||||
proxy.network &&
|
||||
(!['tcp'].includes(proxy.network) ||
|
||||
(['tcp'].includes(proxy.network) &&
|
||||
proxy['reality-opts']))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
|
||||
@@ -126,6 +126,14 @@ export default function Shadowrocket_Producer() {
|
||||
delete proxy['shadow-tls-sni'];
|
||||
delete proxy['shadow-tls-version'];
|
||||
}
|
||||
} else if (
|
||||
['anytls'].includes(proxy.type) &&
|
||||
proxy.network &&
|
||||
(!['tcp'].includes(proxy.network) ||
|
||||
(['tcp'].includes(proxy.network) &&
|
||||
proxy['reality-opts']))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
@@ -736,6 +736,7 @@ const anytlsParser = (proxy = {}) => {
|
||||
`${proxy['min-idle-session']}`,
|
||||
10,
|
||||
);
|
||||
networkParser(proxy, parsedProxy);
|
||||
detourParser(proxy, parsedProxy);
|
||||
tlsParser(proxy, parsedProxy);
|
||||
ipVersionParser(proxy, parsedProxy);
|
||||
|
||||
@@ -1,6 +1,120 @@
|
||||
/* eslint-disable no-case-declarations */
|
||||
import { Base64 } from 'js-base64';
|
||||
import { isIPv6 } from '@/utils';
|
||||
import { uuid } from 'automerge';
|
||||
|
||||
function vless(proxy) {
|
||||
let security = 'none';
|
||||
const isReality = proxy['reality-opts'];
|
||||
let sid = '';
|
||||
let pbk = '';
|
||||
let spx = '';
|
||||
if (isReality) {
|
||||
security = 'reality';
|
||||
const publicKey = proxy['reality-opts']?.['public-key'];
|
||||
if (publicKey) {
|
||||
pbk = `&pbk=${encodeURIComponent(publicKey)}`;
|
||||
}
|
||||
const shortId = proxy['reality-opts']?.['short-id'];
|
||||
if (shortId) {
|
||||
sid = `&sid=${encodeURIComponent(shortId)}`;
|
||||
}
|
||||
const spiderX = proxy['reality-opts']?.['_spider-x'];
|
||||
if (spiderX) {
|
||||
spx = `&spx=${encodeURIComponent(spiderX)}`;
|
||||
}
|
||||
} else if (proxy.tls) {
|
||||
security = 'tls';
|
||||
}
|
||||
let alpn = '';
|
||||
if (proxy.alpn) {
|
||||
alpn = `&alpn=${encodeURIComponent(
|
||||
Array.isArray(proxy.alpn) ? proxy.alpn : proxy.alpn.join(','),
|
||||
)}`;
|
||||
}
|
||||
let allowInsecure = '';
|
||||
if (proxy['skip-cert-verify']) {
|
||||
allowInsecure = `&allowInsecure=1`;
|
||||
}
|
||||
let sni = '';
|
||||
if (proxy.sni) {
|
||||
sni = `&sni=${encodeURIComponent(proxy.sni)}`;
|
||||
}
|
||||
let fp = '';
|
||||
if (proxy['client-fingerprint']) {
|
||||
fp = `&fp=${encodeURIComponent(proxy['client-fingerprint'])}`;
|
||||
}
|
||||
let flow = '';
|
||||
if (proxy.flow) {
|
||||
flow = `&flow=${encodeURIComponent(proxy.flow)}`;
|
||||
}
|
||||
let extra = '';
|
||||
if (proxy._extra) {
|
||||
extra = `&extra=${encodeURIComponent(proxy._extra)}`;
|
||||
}
|
||||
let mode = '';
|
||||
if (proxy._mode) {
|
||||
mode = `&mode=${encodeURIComponent(proxy._mode)}`;
|
||||
}
|
||||
let vlessType = proxy.network;
|
||||
if (proxy.network === 'ws' && proxy['ws-opts']?.['v2ray-http-upgrade']) {
|
||||
vlessType = 'httpupgrade';
|
||||
}
|
||||
|
||||
let vlessTransport = `&type=${encodeURIComponent(vlessType)}`;
|
||||
if (['grpc'].includes(proxy.network)) {
|
||||
// https://github.com/XTLS/Xray-core/issues/91
|
||||
vlessTransport += `&mode=${encodeURIComponent(
|
||||
proxy[`${proxy.network}-opts`]?.['_grpc-type'] || 'gun',
|
||||
)}`;
|
||||
const authority = proxy[`${proxy.network}-opts`]?.['_grpc-authority'];
|
||||
if (authority) {
|
||||
vlessTransport += `&authority=${encodeURIComponent(authority)}`;
|
||||
}
|
||||
}
|
||||
|
||||
let vlessTransportServiceName =
|
||||
proxy[`${proxy.network}-opts`]?.[`${proxy.network}-service-name`];
|
||||
let vlessTransportPath = proxy[`${proxy.network}-opts`]?.path;
|
||||
let vlessTransportHost = proxy[`${proxy.network}-opts`]?.headers?.Host;
|
||||
if (vlessTransportPath) {
|
||||
vlessTransport += `&path=${encodeURIComponent(
|
||||
Array.isArray(vlessTransportPath)
|
||||
? vlessTransportPath[0]
|
||||
: vlessTransportPath,
|
||||
)}`;
|
||||
}
|
||||
if (vlessTransportHost) {
|
||||
vlessTransport += `&host=${encodeURIComponent(
|
||||
Array.isArray(vlessTransportHost)
|
||||
? vlessTransportHost[0]
|
||||
: vlessTransportHost,
|
||||
)}`;
|
||||
}
|
||||
if (vlessTransportServiceName) {
|
||||
vlessTransport += `&serviceName=${encodeURIComponent(
|
||||
vlessTransportServiceName,
|
||||
)}`;
|
||||
}
|
||||
if (proxy.network === 'kcp') {
|
||||
if (proxy.seed) {
|
||||
vlessTransport += `&seed=${encodeURIComponent(proxy.seed)}`;
|
||||
}
|
||||
if (proxy.headerType) {
|
||||
vlessTransport += `&headerType=${encodeURIComponent(
|
||||
proxy.headerType,
|
||||
)}`;
|
||||
}
|
||||
}
|
||||
|
||||
return `vless://${proxy.uuid}@${proxy.server}:${
|
||||
proxy.port
|
||||
}?security=${encodeURIComponent(
|
||||
security,
|
||||
)}${vlessTransport}${alpn}${allowInsecure}${sni}${fp}${flow}${sid}${spx}${pbk}${mode}${extra}#${encodeURIComponent(
|
||||
proxy.name,
|
||||
)}`;
|
||||
}
|
||||
|
||||
export default function URI_Producer() {
|
||||
const type = 'SINGLE';
|
||||
@@ -182,131 +296,7 @@ export default function URI_Producer() {
|
||||
result = 'vmess://' + Base64.encode(JSON.stringify(result));
|
||||
break;
|
||||
case 'vless':
|
||||
let security = 'none';
|
||||
const isReality = proxy['reality-opts'];
|
||||
let sid = '';
|
||||
let pbk = '';
|
||||
let spx = '';
|
||||
if (isReality) {
|
||||
security = 'reality';
|
||||
const publicKey = proxy['reality-opts']?.['public-key'];
|
||||
if (publicKey) {
|
||||
pbk = `&pbk=${encodeURIComponent(publicKey)}`;
|
||||
}
|
||||
const shortId = proxy['reality-opts']?.['short-id'];
|
||||
if (shortId) {
|
||||
sid = `&sid=${encodeURIComponent(shortId)}`;
|
||||
}
|
||||
const spiderX = proxy['reality-opts']?.['_spider-x'];
|
||||
if (spiderX) {
|
||||
spx = `&spx=${encodeURIComponent(spiderX)}`;
|
||||
}
|
||||
} else if (proxy.tls) {
|
||||
security = 'tls';
|
||||
}
|
||||
let alpn = '';
|
||||
if (proxy.alpn) {
|
||||
alpn = `&alpn=${encodeURIComponent(
|
||||
Array.isArray(proxy.alpn)
|
||||
? proxy.alpn
|
||||
: proxy.alpn.join(','),
|
||||
)}`;
|
||||
}
|
||||
let allowInsecure = '';
|
||||
if (proxy['skip-cert-verify']) {
|
||||
allowInsecure = `&allowInsecure=1`;
|
||||
}
|
||||
let sni = '';
|
||||
if (proxy.sni) {
|
||||
sni = `&sni=${encodeURIComponent(proxy.sni)}`;
|
||||
}
|
||||
let fp = '';
|
||||
if (proxy['client-fingerprint']) {
|
||||
fp = `&fp=${encodeURIComponent(
|
||||
proxy['client-fingerprint'],
|
||||
)}`;
|
||||
}
|
||||
let flow = '';
|
||||
if (proxy.flow) {
|
||||
flow = `&flow=${encodeURIComponent(proxy.flow)}`;
|
||||
}
|
||||
let extra = '';
|
||||
if (proxy._extra) {
|
||||
extra = `&extra=${encodeURIComponent(proxy._extra)}`;
|
||||
}
|
||||
let mode = '';
|
||||
if (proxy._mode) {
|
||||
mode = `&mode=${encodeURIComponent(proxy._mode)}`;
|
||||
}
|
||||
let vlessType = proxy.network;
|
||||
if (
|
||||
proxy.network === 'ws' &&
|
||||
proxy['ws-opts']?.['v2ray-http-upgrade']
|
||||
) {
|
||||
vlessType = 'httpupgrade';
|
||||
}
|
||||
|
||||
let vlessTransport = `&type=${encodeURIComponent(vlessType)}`;
|
||||
if (['grpc'].includes(proxy.network)) {
|
||||
// https://github.com/XTLS/Xray-core/issues/91
|
||||
vlessTransport += `&mode=${encodeURIComponent(
|
||||
proxy[`${proxy.network}-opts`]?.['_grpc-type'] || 'gun',
|
||||
)}`;
|
||||
const authority =
|
||||
proxy[`${proxy.network}-opts`]?.['_grpc-authority'];
|
||||
if (authority) {
|
||||
vlessTransport += `&authority=${encodeURIComponent(
|
||||
authority,
|
||||
)}`;
|
||||
}
|
||||
}
|
||||
|
||||
let vlessTransportServiceName =
|
||||
proxy[`${proxy.network}-opts`]?.[
|
||||
`${proxy.network}-service-name`
|
||||
];
|
||||
let vlessTransportPath = proxy[`${proxy.network}-opts`]?.path;
|
||||
let vlessTransportHost =
|
||||
proxy[`${proxy.network}-opts`]?.headers?.Host;
|
||||
if (vlessTransportPath) {
|
||||
vlessTransport += `&path=${encodeURIComponent(
|
||||
Array.isArray(vlessTransportPath)
|
||||
? vlessTransportPath[0]
|
||||
: vlessTransportPath,
|
||||
)}`;
|
||||
}
|
||||
if (vlessTransportHost) {
|
||||
vlessTransport += `&host=${encodeURIComponent(
|
||||
Array.isArray(vlessTransportHost)
|
||||
? vlessTransportHost[0]
|
||||
: vlessTransportHost,
|
||||
)}`;
|
||||
}
|
||||
if (vlessTransportServiceName) {
|
||||
vlessTransport += `&serviceName=${encodeURIComponent(
|
||||
vlessTransportServiceName,
|
||||
)}`;
|
||||
}
|
||||
if (proxy.network === 'kcp') {
|
||||
if (proxy.seed) {
|
||||
vlessTransport += `&seed=${encodeURIComponent(
|
||||
proxy.seed,
|
||||
)}`;
|
||||
}
|
||||
if (proxy.headerType) {
|
||||
vlessTransport += `&headerType=${encodeURIComponent(
|
||||
proxy.headerType,
|
||||
)}`;
|
||||
}
|
||||
}
|
||||
|
||||
result = `vless://${proxy.uuid}@${proxy.server}:${
|
||||
proxy.port
|
||||
}?security=${encodeURIComponent(
|
||||
security,
|
||||
)}${vlessTransport}${alpn}${allowInsecure}${sni}${fp}${flow}${sid}${spx}${pbk}${mode}${extra}#${encodeURIComponent(
|
||||
proxy.name,
|
||||
)}`;
|
||||
result = vless(proxy);
|
||||
break;
|
||||
case 'trojan':
|
||||
let trojanTransport = '';
|
||||
@@ -585,6 +575,12 @@ export default function URI_Producer() {
|
||||
}
|
||||
break;
|
||||
case 'anytls':
|
||||
result = vless({
|
||||
...proxy,
|
||||
uuid: proxy.password,
|
||||
network: proxy.network || 'tcp',
|
||||
}).replace('vless', 'anytls');
|
||||
// 偷个懒
|
||||
let anytlsParams = [];
|
||||
Object.keys(proxy).forEach((key) => {
|
||||
if (
|
||||
@@ -616,7 +612,13 @@ export default function URI_Producer() {
|
||||
if (proxy[key]) {
|
||||
anytlsParams.push(`udp=1`);
|
||||
}
|
||||
} else if (proxy[key] && !/^_/i.test(key)) {
|
||||
} else if (
|
||||
proxy[key] &&
|
||||
!/^_|client-fingerprint/i.test(key) &&
|
||||
['number', 'string', 'boolean'].includes(
|
||||
typeof proxy[key],
|
||||
)
|
||||
) {
|
||||
anytlsParams.push(
|
||||
`${i.replace(/-/g, '_')}=${encodeURIComponent(
|
||||
proxy[key],
|
||||
@@ -625,12 +627,45 @@ export default function URI_Producer() {
|
||||
}
|
||||
}
|
||||
});
|
||||
// Parse existing query parameters from result
|
||||
const urlParts = result.split('?');
|
||||
let baseUrl = urlParts[0];
|
||||
let existingParams = {};
|
||||
|
||||
result = `anytls://${encodeURIComponent(proxy.password)}@${
|
||||
proxy.server
|
||||
}:${proxy.port}/?${anytlsParams.join('&')}#${encodeURIComponent(
|
||||
proxy.name,
|
||||
)}`;
|
||||
if (urlParts.length > 1) {
|
||||
const queryString = urlParts[1].split('#')[0]; // Remove fragment if exists
|
||||
const pairs = queryString.split('&');
|
||||
pairs.forEach((pair) => {
|
||||
const [key, value] = pair.split('=');
|
||||
if (key) {
|
||||
existingParams[key] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Merge anytlsParams with existing parameters
|
||||
anytlsParams.forEach((param) => {
|
||||
const [key, value] = param.split('=');
|
||||
if (key) {
|
||||
existingParams[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
// Reconstruct query string
|
||||
const newParams = Object.keys(existingParams)
|
||||
.map((key) => `${key}=${existingParams[key]}`)
|
||||
.join('&');
|
||||
|
||||
// Get fragment part if exists
|
||||
const fragmentMatch = result.match(/#(.*)$/);
|
||||
const fragment = fragmentMatch ? `#${fragmentMatch[1]}` : '';
|
||||
|
||||
result = `${baseUrl}?${newParams}${fragment}`;
|
||||
// result = `anytls://${encodeURIComponent(proxy.password)}@${
|
||||
// proxy.server
|
||||
// }:${proxy.port}/?${anytlsParams.join('&')}#${encodeURIComponent(
|
||||
// proxy.name,
|
||||
// )}`;
|
||||
break;
|
||||
case 'wireguard':
|
||||
let wireguardParams = [];
|
||||
|
||||
Reference in new issue
Block a user