mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-10 00:52:40 +00:00
Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3aedd5943d | ||
|
|
222551eb20 | ||
|
|
0d5e1ab38b | ||
|
|
a3ec98caa9 | ||
|
|
d9e4d814bb | ||
|
|
e843aa3702 | ||
|
|
66464645f2 | ||
|
|
9ccd6b3816 | ||
|
|
74be1e3d82 | ||
|
|
6d78eb7356 | ||
|
|
38eccca8b4 | ||
|
|
33e5aeceb5 | ||
|
|
837667edc9 | ||
|
|
0069b0ce83 | ||
|
|
fcc9d047ae | ||
|
|
382d22e622 | ||
|
|
06f3e97af2 | ||
|
|
bd87e9231e | ||
|
|
d1d6d19542 | ||
|
|
08bf0b78bb | ||
|
|
9a3cd4f57c | ||
|
|
d015c7867e | ||
|
|
4713b63083 | ||
|
|
dbf9e7c360 | ||
|
|
4ea84118c4 | ||
|
|
dda8113a42 | ||
|
|
f16b2d34f1 | ||
|
|
5b28e1a4c9 | ||
|
|
8d0a71d983 | ||
|
|
815552d470 | ||
|
|
9d90369594 | ||
|
|
6aece471aa | ||
|
|
99396773f6 | ||
|
|
e229408a2d | ||
|
|
514414587b | ||
|
|
d4c419745e | ||
|
|
fe3da254f4 | ||
|
|
7d8132d7cd | ||
|
|
bc1247efaf | ||
|
|
dea937df66 |
10
.github/workflows/main.yml
vendored
10
.github/workflows/main.yml
vendored
@@ -76,8 +76,8 @@ jobs:
|
|||||||
git commit -m "release: ${{ steps.tag.outputs.release_tag }}"
|
git commit -m "release: ${{ steps.tag.outputs.release_tag }}"
|
||||||
git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
|
git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
|
||||||
git push -f -u origin release
|
git push -f -u origin release
|
||||||
- name: Sync to GitLab
|
# - name: Sync to GitLab
|
||||||
env:
|
# env:
|
||||||
GITLAB_PIPELINE_TOKEN: ${{ secrets.GITLAB_PIPELINE_TOKEN }}
|
# GITLAB_PIPELINE_TOKEN: ${{ secrets.GITLAB_PIPELINE_TOKEN }}
|
||||||
run: |
|
# run: |
|
||||||
curl -X POST --fail -F token=$GITLAB_PIPELINE_TOKEN -F ref=master https://gitlab.com/api/v4/projects/48891296/trigger/pipeline
|
# curl -X POST --fail -F token=$GITLAB_PIPELINE_TOKEN -F ref=master https://gitlab.com/api/v4/projects/48891296/trigger/pipeline
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -7,7 +7,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p align="center" color="#6a737d">
|
<p align="center" color="#6a737d">
|
||||||
Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.
|
Advanced Subscription Manager for QX, Loon, Surge, Stash, Egern and Shadowrocket.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
[](https://github.com/sub-store-org/Sub-Store/actions/workflows/main.yml)     
|
[](https://github.com/sub-store-org/Sub-Store/actions/workflows/main.yml)     
|
||||||
@@ -28,14 +28,18 @@ Core functionalities:
|
|||||||
|
|
||||||
> ⚠️ Do not use `Shadowrocket` to export URI and then import it as input. It is not a standard URI.
|
> ⚠️ 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] URI(SS, SSR, VMess, VLESS, Trojan, Hysteria, Hysteria 2, TUIC v5, WireGuard)
|
||||||
- [x] Clash Proxies YAML
|
- [x] Clash Proxies YAML
|
||||||
- [x] Clash Proxy JSON(single line)
|
- [x] Clash Proxy JSON(single line)
|
||||||
- [x] QX (SS, SSR, VMess, Trojan, HTTP, SOCKS5, VLESS)
|
- [x] QX (SS, SSR, VMess, Trojan, HTTP, SOCKS5, VLESS)
|
||||||
- [x] Loon (SS, SSR, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, WireGuard, VLESS, Hysteria 2)
|
- [x] Loon (SS, SSR, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, WireGuard, VLESS, Hysteria 2)
|
||||||
- [x] Surge (SS, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, TUIC, Snell, Hysteria 2, SSH(Password authentication only), External Proxy Program(only for macOS), WireGuard(Surge to Surge))
|
- [x] Surge (Direct, SS, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, TUIC, Snell, Hysteria 2, SSH(Password authentication only), External Proxy Program(only for macOS), WireGuard(Surge to Surge))
|
||||||
- [x] Surfboard (SS, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, WireGuard(Surfboard to Surfboard))
|
- [x] Surfboard (SS, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, WireGuard(Surfboard to Surfboard))
|
||||||
- [x] Clash.Meta (SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard, Hysteria, Hysteria 2, TUIC)
|
- [x] Clash.Meta (Direct, SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard, Hysteria, Hysteria 2, TUIC, SSH, mieru)
|
||||||
- [x] Stash (SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard, Hysteria, TUIC, Juicity, SSH)
|
- [x] Stash (SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard, Hysteria, TUIC, Juicity, SSH)
|
||||||
- [x] Clash (SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard)
|
- [x] Clash (SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard)
|
||||||
|
|
||||||
@@ -49,6 +53,7 @@ Core functionalities:
|
|||||||
- [x] Surge
|
- [x] Surge
|
||||||
- [x] SurgeMac(Use mihomo to support protocols that are not supported by Surge itself)
|
- [x] SurgeMac(Use mihomo to support protocols that are not supported by Surge itself)
|
||||||
- [x] Loon
|
- [x] Loon
|
||||||
|
- [x] Egern
|
||||||
- [x] Shadowrocket
|
- [x] Shadowrocket
|
||||||
- [x] QX
|
- [x] QX
|
||||||
- [x] sing-box
|
- [x] sing-box
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.14.419",
|
"version": "2.15.5",
|
||||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -86,6 +86,16 @@ async function processFn(
|
|||||||
$options,
|
$options,
|
||||||
) {
|
) {
|
||||||
for (const item of operators) {
|
for (const item of operators) {
|
||||||
|
if (item.disabled) {
|
||||||
|
$.log(
|
||||||
|
`Skipping disabled operator: "${
|
||||||
|
item.type
|
||||||
|
}" with arguments:\n >>> ${
|
||||||
|
JSON.stringify(item.args, null, 2) || 'None'
|
||||||
|
}`,
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// process script
|
// process script
|
||||||
let script;
|
let script;
|
||||||
let $arguments = {};
|
let $arguments = {};
|
||||||
|
|||||||
@@ -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).
|
// Parse SS URI format (only supports new SIP002, legacy format is depreciated).
|
||||||
// reference: https://github.com/shadowsocks/shadowsocks-org/wiki/SIP002-URI-Scheme
|
// reference: https://github.com/shadowsocks/shadowsocks-org/wiki/SIP002-URI-Scheme
|
||||||
function URI_SS() {
|
function URI_SS() {
|
||||||
@@ -46,7 +82,15 @@ function URI_SS() {
|
|||||||
content = content.split('#')[0]; // strip proxy name
|
content = content.split('#')[0]; // strip proxy name
|
||||||
// handle IPV4 and IPV6
|
// handle IPV4 and IPV6
|
||||||
let serverAndPortArray = content.match(/@([^/]*)(\/|$)/);
|
let serverAndPortArray = content.match(/@([^/]*)(\/|$)/);
|
||||||
let userInfoStr = Base64.decode(content.split('@')[0]);
|
|
||||||
|
let rawUserInfoStr = decodeURIComponent(content.split('@')[0]); // 其实应该分隔之后, 用户名和密码再 decodeURIComponent. 但是问题不大
|
||||||
|
let userInfoStr;
|
||||||
|
if (rawUserInfoStr?.startsWith('2022-blake3-')) {
|
||||||
|
userInfoStr = rawUserInfoStr;
|
||||||
|
} else {
|
||||||
|
userInfoStr = Base64.decode(rawUserInfoStr);
|
||||||
|
}
|
||||||
|
|
||||||
let query = '';
|
let query = '';
|
||||||
if (!serverAndPortArray) {
|
if (!serverAndPortArray) {
|
||||||
if (content.includes('?')) {
|
if (content.includes('?')) {
|
||||||
@@ -71,16 +115,21 @@ function URI_SS() {
|
|||||||
userInfoStr = content.split('@')[0];
|
userInfoStr = content.split('@')[0];
|
||||||
serverAndPortArray = content.match(/@([^/]*)(\/|$)/);
|
serverAndPortArray = content.match(/@([^/]*)(\/|$)/);
|
||||||
}
|
}
|
||||||
|
|
||||||
const serverAndPort = serverAndPortArray[1];
|
const serverAndPort = serverAndPortArray[1];
|
||||||
const portIdx = serverAndPort.lastIndexOf(':');
|
const portIdx = serverAndPort.lastIndexOf(':');
|
||||||
proxy.server = serverAndPort.substring(0, portIdx);
|
proxy.server = serverAndPort.substring(0, portIdx);
|
||||||
proxy.port = `${serverAndPort.substring(portIdx + 1)}`.match(
|
proxy.port = `${serverAndPort.substring(portIdx + 1)}`.match(
|
||||||
/\d+/,
|
/\d+/,
|
||||||
)?.[0];
|
)?.[0];
|
||||||
|
let userInfo = userInfoStr.match(/(^.*?):(.*$)/);
|
||||||
const userInfo = userInfoStr.match(/(^.*?):(.*$)/);
|
proxy.cipher = userInfo?.[1];
|
||||||
proxy.cipher = userInfo[1];
|
proxy.password = userInfo?.[2];
|
||||||
proxy.password = userInfo[2];
|
// if (!proxy.cipher || !proxy.password) {
|
||||||
|
// userInfo = rawUserInfoStr.match(/(^.*?):(.*$)/);
|
||||||
|
// proxy.cipher = userInfo?.[1];
|
||||||
|
// proxy.password = userInfo?.[2];
|
||||||
|
// }
|
||||||
|
|
||||||
// handle obfs
|
// handle obfs
|
||||||
const idx = content.indexOf('?plugin=');
|
const idx = content.indexOf('?plugin=');
|
||||||
@@ -340,6 +389,10 @@ function URI_VMess() {
|
|||||||
} else if (params.net === 'h2' || proxy.network === 'h2') {
|
} else if (params.net === 'h2' || proxy.network === 'h2') {
|
||||||
proxy.network = 'h2';
|
proxy.network = 'h2';
|
||||||
}
|
}
|
||||||
|
// 暂不支持 tcp + host + path
|
||||||
|
// else if (params.net === 'tcp' || proxy.network === 'tcp') {
|
||||||
|
// proxy.network = 'tcp';
|
||||||
|
// }
|
||||||
if (proxy.network) {
|
if (proxy.network) {
|
||||||
let transportHost = params.host ?? params.obfsParam;
|
let transportHost = params.host ?? params.obfsParam;
|
||||||
try {
|
try {
|
||||||
@@ -376,6 +429,7 @@ function URI_VMess() {
|
|||||||
proxy[`${proxy.network}-opts`] = {
|
proxy[`${proxy.network}-opts`] = {
|
||||||
'grpc-service-name': getIfNotBlank(transportPath),
|
'grpc-service-name': getIfNotBlank(transportPath),
|
||||||
'_grpc-type': getIfNotBlank(params.type),
|
'_grpc-type': getIfNotBlank(params.type),
|
||||||
|
'_grpc-authority': getIfNotBlank(params.authority),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const opts = {
|
const opts = {
|
||||||
@@ -511,6 +565,9 @@ function URI_VLESS() {
|
|||||||
}
|
}
|
||||||
if (params.serviceName) {
|
if (params.serviceName) {
|
||||||
opts[`${proxy.network}-service-name`] = params.serviceName;
|
opts[`${proxy.network}-service-name`] = params.serviceName;
|
||||||
|
if (['grpc'].includes(proxy.network) && params.authority) {
|
||||||
|
opts['_grpc-authority'] = params.authority;
|
||||||
|
}
|
||||||
} else if (isShadowrocket && params.path) {
|
} else if (isShadowrocket && params.path) {
|
||||||
if (!['ws', 'http', 'h2'].includes(proxy.network)) {
|
if (!['ws', 'http', 'h2'].includes(proxy.network)) {
|
||||||
opts[`${proxy.network}-service-name`] = params.path;
|
opts[`${proxy.network}-service-name`] = params.path;
|
||||||
@@ -838,6 +895,11 @@ function URI_Trojan() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const parse = (line) => {
|
const parse = (line) => {
|
||||||
|
const matched = /^(trojan:\/\/.*?@.*?)(:(\d+))?\/?(\?.*?)?$/.exec(line);
|
||||||
|
const port = matched?.[2];
|
||||||
|
if (!port) {
|
||||||
|
line = line.replace(matched[1], `${matched[1]}:443`);
|
||||||
|
}
|
||||||
let [newLine, name] = line.split(/#(.+)/, 2);
|
let [newLine, name] = line.split(/#(.+)/, 2);
|
||||||
const parser = getTrojanURIParser();
|
const parser = getTrojanURIParser();
|
||||||
const proxy = parser.parse(newLine);
|
const proxy = parser.parse(newLine);
|
||||||
@@ -867,6 +929,8 @@ function Clash_All() {
|
|||||||
const proxy = JSON.parse(line);
|
const proxy = JSON.parse(line);
|
||||||
if (
|
if (
|
||||||
![
|
![
|
||||||
|
'mieru',
|
||||||
|
'juicity',
|
||||||
'ss',
|
'ss',
|
||||||
'ssr',
|
'ssr',
|
||||||
'vmess',
|
'vmess',
|
||||||
@@ -880,6 +944,7 @@ function Clash_All() {
|
|||||||
'hysteria2',
|
'hysteria2',
|
||||||
'wireguard',
|
'wireguard',
|
||||||
'ssh',
|
'ssh',
|
||||||
|
'direct',
|
||||||
].includes(proxy.type)
|
].includes(proxy.type)
|
||||||
) {
|
) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -1178,6 +1243,14 @@ function Loon_WireGuard() {
|
|||||||
return { name, test, parse };
|
return { name, test, parse };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Surge_Direct() {
|
||||||
|
const name = 'Surge Direct Parser';
|
||||||
|
const test = (line) => {
|
||||||
|
return /^.*=\s*direct/.test(line.split(',')[0]);
|
||||||
|
};
|
||||||
|
const parse = (line) => getSurgeParser().parse(line);
|
||||||
|
return { name, test, parse };
|
||||||
|
}
|
||||||
function Surge_SSH() {
|
function Surge_SSH() {
|
||||||
const name = 'Surge SSH Parser';
|
const name = 'Surge SSH Parser';
|
||||||
const test = (line) => {
|
const test = (line) => {
|
||||||
@@ -1357,6 +1430,7 @@ function isIP(ip) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
|
URI_PROXY(),
|
||||||
URI_SS(),
|
URI_SS(),
|
||||||
URI_SSR(),
|
URI_SSR(),
|
||||||
URI_VMess(),
|
URI_VMess(),
|
||||||
@@ -1367,6 +1441,7 @@ export default [
|
|||||||
URI_Hysteria2(),
|
URI_Hysteria2(),
|
||||||
URI_Trojan(),
|
URI_Trojan(),
|
||||||
Clash_All(),
|
Clash_All(),
|
||||||
|
Surge_Direct(),
|
||||||
Surge_SSH(),
|
Surge_SSH(),
|
||||||
Surge_SS(),
|
Surge_SS(),
|
||||||
Surge_VMess(),
|
Surge_VMess(),
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ port = digits:[0-9]+ {
|
|||||||
method = comma cipher:cipher {
|
method = comma cipher:cipher {
|
||||||
proxy.cipher = cipher;
|
proxy.cipher = cipher;
|
||||||
}
|
}
|
||||||
cipher = ("aes-128-cfb"/"aes-128-ctr"/"aes-128-gcm"/"aes-192-cfb"/"aes-192-ctr"/"aes-192-gcm"/"aes-256-cfb"/"aes-256-ctr"/"aes-256-gcm"/"auto"/"bf-cfb"/"camellia-128-cfb"/"camellia-192-cfb"/"camellia-256-cfb"/"chacha20-ietf-poly1305"/"chacha20-ietf"/"chacha20-poly1305"/"chacha20"/"none"/"rc4-md5"/"rc4"/"salsa20"/"xchacha20-ietf-poly1305");
|
cipher = ("aes-128-cfb"/"aes-128-ctr"/"aes-128-gcm"/"aes-192-cfb"/"aes-192-ctr"/"aes-192-gcm"/"aes-256-cfb"/"aes-256-ctr"/"aes-256-gcm"/"auto"/"bf-cfb"/"camellia-128-cfb"/"camellia-192-cfb"/"camellia-256-cfb"/"chacha20-ietf-poly1305"/"chacha20-ietf"/"chacha20-poly1305"/"chacha20"/"none"/"rc4-md5"/"rc4"/"salsa20"/"xchacha20-ietf-poly1305"/"2022-blake3-aes-128-gcm"/"2022-blake3-aes-256-gcm");
|
||||||
|
|
||||||
username = & {
|
username = & {
|
||||||
let j = peg$currPos;
|
let j = peg$currPos;
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ port = digits:[0-9]+ {
|
|||||||
method = comma cipher:cipher {
|
method = comma cipher:cipher {
|
||||||
proxy.cipher = cipher;
|
proxy.cipher = cipher;
|
||||||
}
|
}
|
||||||
cipher = ("aes-128-cfb"/"aes-128-ctr"/"aes-128-gcm"/"aes-192-cfb"/"aes-192-ctr"/"aes-192-gcm"/"aes-256-cfb"/"aes-256-ctr"/"aes-256-gcm"/"auto"/"bf-cfb"/"camellia-128-cfb"/"camellia-192-cfb"/"camellia-256-cfb"/"chacha20-ietf-poly1305"/"chacha20-ietf"/"chacha20-poly1305"/"chacha20"/"none"/"rc4-md5"/"rc4"/"salsa20"/"xchacha20-ietf-poly1305");
|
cipher = ("aes-128-cfb"/"aes-128-ctr"/"aes-128-gcm"/"aes-192-cfb"/"aes-192-ctr"/"aes-192-gcm"/"aes-256-cfb"/"aes-256-ctr"/"aes-256-gcm"/"auto"/"bf-cfb"/"camellia-128-cfb"/"camellia-192-cfb"/"camellia-256-cfb"/"chacha20-ietf-poly1305"/"chacha20-ietf"/"chacha20-poly1305"/"chacha20"/"none"/"rc4-md5"/"rc4"/"salsa20"/"xchacha20-ietf-poly1305"/"2022-blake3-aes-128-gcm"/"2022-blake3-aes-256-gcm");
|
||||||
|
|
||||||
username = & {
|
username = & {
|
||||||
let j = peg$currPos;
|
let j = peg$currPos;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const grammars = String.raw`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
start = (shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh) {
|
start = (shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/direct) {
|
||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,15 +108,18 @@ hysteria2 = tag equals "hysteria2" address (no_error_alert/ip_version/underlying
|
|||||||
proxy.type = "hysteria2";
|
proxy.type = "hysteria2";
|
||||||
handleShadowTLS();
|
handleShadowTLS();
|
||||||
}
|
}
|
||||||
socks5 = tag equals "socks5" address (username password)? (usernamek passwordk)? (no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/fast_open/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
socks5 = tag equals "socks5" address (username password)? (usernamek passwordk)? (udp_relay/no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/fast_open/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||||
proxy.type = "socks5";
|
proxy.type = "socks5";
|
||||||
handleShadowTLS();
|
handleShadowTLS();
|
||||||
}
|
}
|
||||||
socks5_tls = tag equals "socks5-tls" address (username password)? (usernamek passwordk)? (no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/sni/tls_fingerprint/tls_verification/fast_open/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
socks5_tls = tag equals "socks5-tls" address (username password)? (usernamek passwordk)? (udp_relay/no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/sni/tls_fingerprint/tls_verification/fast_open/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||||
proxy.type = "socks5";
|
proxy.type = "socks5";
|
||||||
proxy.tls = true;
|
proxy.tls = true;
|
||||||
handleShadowTLS();
|
handleShadowTLS();
|
||||||
}
|
}
|
||||||
|
direct = tag equals "direct" (udp_relay/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/block_quic/others)* {
|
||||||
|
proxy.type = "direct";
|
||||||
|
}
|
||||||
|
|
||||||
address = comma server:server comma port:port {
|
address = comma server:server comma port:port {
|
||||||
proxy.server = server;
|
proxy.server = server;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
start = (shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh) {
|
start = (shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/direct) {
|
||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,16 +106,18 @@ hysteria2 = tag equals "hysteria2" address (no_error_alert/ip_version/underlying
|
|||||||
proxy.type = "hysteria2";
|
proxy.type = "hysteria2";
|
||||||
handleShadowTLS();
|
handleShadowTLS();
|
||||||
}
|
}
|
||||||
socks5 = tag equals "socks5" address (username password)? (usernamek passwordk)? (no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/fast_open/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
socks5 = tag equals "socks5" address (username password)? (usernamek passwordk)? (udp_relay/no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/fast_open/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||||
proxy.type = "socks5";
|
proxy.type = "socks5";
|
||||||
handleShadowTLS();
|
handleShadowTLS();
|
||||||
}
|
}
|
||||||
socks5_tls = tag equals "socks5-tls" address (username password)? (usernamek passwordk)? (no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/sni/tls_fingerprint/tls_verification/fast_open/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
socks5_tls = tag equals "socks5-tls" address (username password)? (usernamek passwordk)? (udp_relay/no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/sni/tls_fingerprint/tls_verification/fast_open/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||||
proxy.type = "socks5";
|
proxy.type = "socks5";
|
||||||
proxy.tls = true;
|
proxy.tls = true;
|
||||||
handleShadowTLS();
|
handleShadowTLS();
|
||||||
}
|
}
|
||||||
|
direct = tag equals "direct" (udp_relay/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/block_quic/others)* {
|
||||||
|
proxy.type = "direct";
|
||||||
|
}
|
||||||
address = comma server:server comma port:port {
|
address = comma server:server comma port:port {
|
||||||
proxy.server = server;
|
proxy.server = server;
|
||||||
proxy.port = port;
|
proxy.port = port;
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ port = digits:[0-9]+ {
|
|||||||
params = "?" head:param tail:("&"@param)* {
|
params = "?" head:param tail:("&"@param)* {
|
||||||
proxy["skip-cert-verify"] = toBool(params["allowInsecure"]);
|
proxy["skip-cert-verify"] = toBool(params["allowInsecure"]);
|
||||||
proxy.sni = params["sni"] || params["peer"];
|
proxy.sni = params["sni"] || params["peer"];
|
||||||
|
proxy['client-fingerprint'] = params.fp;
|
||||||
|
proxy.alpn = params.alpn ? decodeURIComponent(params.alpn).split(',') : undefined;
|
||||||
|
|
||||||
if (toBool(params["ws"])) {
|
if (toBool(params["ws"])) {
|
||||||
proxy.network = "ws";
|
proxy.network = "ws";
|
||||||
@@ -99,6 +101,7 @@ params = "?" head:param tail:("&"@param)* {
|
|||||||
proxy[proxy.network + '-opts'] = {
|
proxy[proxy.network + '-opts'] = {
|
||||||
'grpc-service-name': params["serviceName"],
|
'grpc-service-name': params["serviceName"],
|
||||||
'_grpc-type': params["mode"],
|
'_grpc-type': params["mode"],
|
||||||
|
'_grpc-authority': params["authority"],
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
if (params["path"]) {
|
if (params["path"]) {
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ port = digits:[0-9]+ {
|
|||||||
params = "?" head:param tail:("&"@param)* {
|
params = "?" head:param tail:("&"@param)* {
|
||||||
proxy["skip-cert-verify"] = toBool(params["allowInsecure"]);
|
proxy["skip-cert-verify"] = toBool(params["allowInsecure"]);
|
||||||
proxy.sni = params["sni"] || params["peer"];
|
proxy.sni = params["sni"] || params["peer"];
|
||||||
|
proxy['client-fingerprint'] = params.fp;
|
||||||
|
proxy.alpn = params.alpn ? decodeURIComponent(params.alpn).split(',') : undefined;
|
||||||
|
|
||||||
if (toBool(params["ws"])) {
|
if (toBool(params["ws"])) {
|
||||||
proxy.network = "ws";
|
proxy.network = "ws";
|
||||||
@@ -97,6 +99,7 @@ params = "?" head:param tail:("&"@param)* {
|
|||||||
proxy[proxy.network + '-opts'] = {
|
proxy[proxy.network + '-opts'] = {
|
||||||
'grpc-service-name': params["serviceName"],
|
'grpc-service-name': params["serviceName"],
|
||||||
'_grpc-type': params["mode"],
|
'_grpc-type': params["mode"],
|
||||||
|
'_grpc-authority': params["authority"],
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
if (params["path"]) {
|
if (params["path"]) {
|
||||||
|
|||||||
@@ -561,7 +561,7 @@ function ResolveDomainOperator({
|
|||||||
throw new Error(`域名解析服务提供方 ${provider} 不支持 ${_type}`);
|
throw new Error(`域名解析服务提供方 ${provider} 不支持 ${_type}`);
|
||||||
}
|
}
|
||||||
const { defaultTimeout } = $.read(SETTINGS_KEY);
|
const { defaultTimeout } = $.read(SETTINGS_KEY);
|
||||||
const requestTimeout = timeout || defaultTimeout;
|
const requestTimeout = timeout || defaultTimeout || 8000;
|
||||||
let type = ['IPv6', 'IP4P'].includes(_type) ? 'IPv6' : 'IPv4';
|
let type = ['IPv6', 'IP4P'].includes(_type) ? 'IPv6' : 'IPv4';
|
||||||
|
|
||||||
const resolver = DOMAIN_RESOLVERS[provider];
|
const resolver = DOMAIN_RESOLVERS[provider];
|
||||||
@@ -699,24 +699,45 @@ function isIP(ip) {
|
|||||||
|
|
||||||
ResolveDomainOperator.resolver = DOMAIN_RESOLVERS;
|
ResolveDomainOperator.resolver = DOMAIN_RESOLVERS;
|
||||||
|
|
||||||
|
function isAscii(str) {
|
||||||
|
// eslint-disable-next-line no-control-regex
|
||||||
|
var pattern = /^[\x00-\x7F]+$/; // ASCII 范围的 Unicode 编码
|
||||||
|
return pattern.test(str);
|
||||||
|
}
|
||||||
|
|
||||||
/**************************** Filters ***************************************/
|
/**************************** Filters ***************************************/
|
||||||
// filter useless proxies
|
// filter useless proxies
|
||||||
function UselessFilter() {
|
function UselessFilter() {
|
||||||
const KEYWORDS = [
|
|
||||||
'网址',
|
|
||||||
'流量',
|
|
||||||
'时间',
|
|
||||||
'应急',
|
|
||||||
'过期',
|
|
||||||
'Bandwidth',
|
|
||||||
'expire',
|
|
||||||
];
|
|
||||||
return {
|
return {
|
||||||
name: 'Useless Filter',
|
name: 'Useless Filter',
|
||||||
func: RegexFilter({
|
func: (proxies) => {
|
||||||
regex: KEYWORDS,
|
return proxies.map((proxy) => {
|
||||||
keep: false,
|
if (proxy.cipher && !isAscii(proxy.cipher)) {
|
||||||
}).func,
|
return false;
|
||||||
|
} else if (proxy.password && !isAscii(proxy.password)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (proxy.network) {
|
||||||
|
let transportHosts =
|
||||||
|
proxy[`${proxy.network}-opts`]?.headers?.Host ||
|
||||||
|
proxy[`${proxy.network}-opts`]?.headers?.host;
|
||||||
|
transportHosts = Array.isArray(transportHosts)
|
||||||
|
? transportHosts
|
||||||
|
: [transportHosts];
|
||||||
|
if (
|
||||||
|
transportHosts.some(
|
||||||
|
(host) => host && !isAscii(host),
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !/网址|流量|时间|应急|过期|Bandwidth|expire/.test(
|
||||||
|
proxy.name,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ export default function Clash_Producer() {
|
|||||||
proxy[`${proxy.network}-opts`]
|
proxy[`${proxy.network}-opts`]
|
||||||
) {
|
) {
|
||||||
delete proxy[`${proxy.network}-opts`]['_grpc-type'];
|
delete proxy[`${proxy.network}-opts`]['_grpc-type'];
|
||||||
|
delete proxy[`${proxy.network}-opts`]['_grpc-authority'];
|
||||||
}
|
}
|
||||||
return proxy;
|
return proxy;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ export default function ClashMeta_Producer() {
|
|||||||
if (opts['include-unsupported-proxy']) return true;
|
if (opts['include-unsupported-proxy']) return true;
|
||||||
if (proxy.type === 'snell' && String(proxy.version) === '4') {
|
if (proxy.type === 'snell' && String(proxy.version) === '4') {
|
||||||
return false;
|
return false;
|
||||||
|
} else if (['juicity'].includes(proxy.type)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
@@ -190,6 +192,7 @@ export default function ClashMeta_Producer() {
|
|||||||
proxy[`${proxy.network}-opts`]
|
proxy[`${proxy.network}-opts`]
|
||||||
) {
|
) {
|
||||||
delete proxy[`${proxy.network}-opts`]['_grpc-type'];
|
delete proxy[`${proxy.network}-opts`]['_grpc-type'];
|
||||||
|
delete proxy[`${proxy.network}-opts`]['_grpc-authority'];
|
||||||
}
|
}
|
||||||
return proxy;
|
return proxy;
|
||||||
});
|
});
|
||||||
|
|||||||
301
backend/src/core/proxy-utils/producers/egern.js
Normal file
301
backend/src/core/proxy-utils/producers/egern.js
Normal file
@@ -0,0 +1,301 @@
|
|||||||
|
export default function Egern_Producer() {
|
||||||
|
const type = 'ALL';
|
||||||
|
const produce = (proxies, type, opts = {}) => {
|
||||||
|
// https://egernapp.com/zh-CN/docs/configuration/proxies
|
||||||
|
const list = proxies
|
||||||
|
.filter((proxy) => {
|
||||||
|
if (opts['include-unsupported-proxy']) return true;
|
||||||
|
if (
|
||||||
|
![
|
||||||
|
'http',
|
||||||
|
'socks5',
|
||||||
|
'ss',
|
||||||
|
'trojan',
|
||||||
|
'hysteria2',
|
||||||
|
'vless',
|
||||||
|
'vmess',
|
||||||
|
].includes(proxy.type) ||
|
||||||
|
(proxy.type === 'ss' &&
|
||||||
|
((proxy.plugin === 'obfs' &&
|
||||||
|
!['http', 'tls'].includes(
|
||||||
|
proxy['plugin-opts']?.mode,
|
||||||
|
)) ||
|
||||||
|
![
|
||||||
|
'chacha20-ietf-poly1305',
|
||||||
|
'chacha20-poly1305',
|
||||||
|
'aes-256-gcm',
|
||||||
|
'aes-128-gcm',
|
||||||
|
'none',
|
||||||
|
'tbale',
|
||||||
|
'rc4',
|
||||||
|
'rc4-md5',
|
||||||
|
'aes-128-cfb',
|
||||||
|
'aes-192-cfb',
|
||||||
|
'aes-256-cfb',
|
||||||
|
'aes-128-ctr',
|
||||||
|
'aes-192-ctr',
|
||||||
|
'aes-256-ctr',
|
||||||
|
'bf-cfb',
|
||||||
|
'camellia-128-cfb',
|
||||||
|
'camellia-192-cfb',
|
||||||
|
'camellia-256-cfb',
|
||||||
|
'cast5-cfb',
|
||||||
|
'des-cfb',
|
||||||
|
'idea-cfb',
|
||||||
|
'rc2-cfb',
|
||||||
|
'seed-cfb',
|
||||||
|
'salsa20',
|
||||||
|
'chacha20',
|
||||||
|
'chacha20-ietf',
|
||||||
|
].includes(proxy.cipher))) ||
|
||||||
|
(proxy.type === 'vmess' &&
|
||||||
|
(![
|
||||||
|
'auto',
|
||||||
|
'aes-128-gcm',
|
||||||
|
'chacha20-poly1305',
|
||||||
|
'none',
|
||||||
|
'zero',
|
||||||
|
].includes(proxy.cipher) ||
|
||||||
|
(!['http', 'ws', 'tcp'].includes(proxy.network) &&
|
||||||
|
proxy.network))) ||
|
||||||
|
(proxy.type === 'trojan' &&
|
||||||
|
!['http', 'ws', 'tcp'].includes(proxy.network) &&
|
||||||
|
proxy.network) ||
|
||||||
|
(proxy.type === 'vless' &&
|
||||||
|
(typeof proxy.flow !== 'undefined' ||
|
||||||
|
proxy['reality-opts'] ||
|
||||||
|
(!['http', 'ws', 'tcp'].includes(proxy.network) &&
|
||||||
|
proxy.network)))
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.map((proxy) => {
|
||||||
|
if (proxy.tls && !proxy.sni) {
|
||||||
|
proxy.sni = proxy.server;
|
||||||
|
}
|
||||||
|
if (proxy.type === 'http') {
|
||||||
|
proxy = {
|
||||||
|
type: 'http',
|
||||||
|
name: proxy.name,
|
||||||
|
server: proxy.server,
|
||||||
|
port: proxy.port,
|
||||||
|
username: proxy.username,
|
||||||
|
password: proxy.password,
|
||||||
|
tfo: proxy.tfo || proxy['fast-open'],
|
||||||
|
next_hop: proxy.next_hop,
|
||||||
|
};
|
||||||
|
} else if (proxy.type === 'socks5') {
|
||||||
|
proxy = {
|
||||||
|
type: 'socks5',
|
||||||
|
name: proxy.name,
|
||||||
|
server: proxy.server,
|
||||||
|
port: proxy.port,
|
||||||
|
username: proxy.username,
|
||||||
|
password: proxy.password,
|
||||||
|
tfo: proxy.tfo || proxy['fast-open'],
|
||||||
|
udp_relay:
|
||||||
|
proxy.udp || proxy.udp_relay || proxy.udp_relay,
|
||||||
|
next_hop: proxy.next_hop,
|
||||||
|
};
|
||||||
|
} else if (proxy.type === 'ss') {
|
||||||
|
proxy = {
|
||||||
|
type: 'shadowsocks',
|
||||||
|
name: proxy.name,
|
||||||
|
method:
|
||||||
|
proxy.cipher === 'chacha20-ietf-poly1305'
|
||||||
|
? 'chacha20-poly1305'
|
||||||
|
: proxy.cipher,
|
||||||
|
server: proxy.server,
|
||||||
|
port: proxy.port,
|
||||||
|
password: proxy.password,
|
||||||
|
tfo: proxy.tfo || proxy['fast-open'],
|
||||||
|
udp_relay:
|
||||||
|
proxy.udp || proxy.udp_relay || proxy.udp_relay,
|
||||||
|
next_hop: proxy.next_hop,
|
||||||
|
};
|
||||||
|
if (proxy.plugin === 'obfs') {
|
||||||
|
proxy.obfs = proxy['plugin-opts'].mode;
|
||||||
|
proxy.obfs_host = proxy['plugin-opts'].host;
|
||||||
|
proxy.obfs_uri = proxy['plugin-opts'].path;
|
||||||
|
}
|
||||||
|
} else if (proxy.type === 'hysteria2') {
|
||||||
|
proxy = {
|
||||||
|
type: 'hysteria2',
|
||||||
|
name: proxy.name,
|
||||||
|
server: proxy.server,
|
||||||
|
port: proxy.port,
|
||||||
|
auth: proxy.password,
|
||||||
|
tfo: proxy.tfo || proxy['fast-open'],
|
||||||
|
udp_relay:
|
||||||
|
proxy.udp || proxy.udp_relay || proxy.udp_relay,
|
||||||
|
next_hop: proxy.next_hop,
|
||||||
|
sni: proxy.sni,
|
||||||
|
skip_tls_verify: proxy['skip-cert-verify'],
|
||||||
|
};
|
||||||
|
if (proxy['obfs-password'] && proxy.obfs == 'salamander') {
|
||||||
|
proxy.obfs = 'salamander';
|
||||||
|
proxy.obfs_password = proxy['obfs-password'];
|
||||||
|
}
|
||||||
|
} else if (proxy.type === 'trojan') {
|
||||||
|
if (proxy.network === 'ws') {
|
||||||
|
proxy.websocket = {
|
||||||
|
path: proxy['ws-opts']?.path,
|
||||||
|
host: proxy['ws-opts']?.headers?.Host,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
proxy = {
|
||||||
|
type: 'trojan',
|
||||||
|
name: proxy.name,
|
||||||
|
server: proxy.server,
|
||||||
|
port: proxy.port,
|
||||||
|
password: proxy.password,
|
||||||
|
tfo: proxy.tfo || proxy['fast-open'],
|
||||||
|
udp_relay:
|
||||||
|
proxy.udp || proxy.udp_relay || proxy.udp_relay,
|
||||||
|
next_hop: proxy.next_hop,
|
||||||
|
sni: proxy.sni,
|
||||||
|
skip_tls_verify: proxy['skip-cert-verify'],
|
||||||
|
websocket: proxy.websocket,
|
||||||
|
};
|
||||||
|
} else if (proxy.type === 'vmess') {
|
||||||
|
if (proxy.network === 'ws') {
|
||||||
|
proxy.transport = {
|
||||||
|
[proxy.tls ? 'wss' : 'ws']: {
|
||||||
|
path: proxy['ws-opts']?.path,
|
||||||
|
headers: {
|
||||||
|
Host: proxy['ws-opts']?.headers?.Host,
|
||||||
|
},
|
||||||
|
sni: proxy.tls ? proxy.sni : undefined,
|
||||||
|
skip_tls_verify: proxy.tls
|
||||||
|
? proxy['skip-cert-verify']
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else if (proxy.network === 'http') {
|
||||||
|
proxy.transport = {
|
||||||
|
http: {
|
||||||
|
method: proxy['http-opts']?.method,
|
||||||
|
path: proxy['http-opts']?.path,
|
||||||
|
headers: {
|
||||||
|
Host: Array.isArray(
|
||||||
|
proxy['http-opts']?.headers?.Host,
|
||||||
|
)
|
||||||
|
? proxy['http-opts']?.headers?.Host[0]
|
||||||
|
: proxy['http-opts']?.headers?.Host,
|
||||||
|
},
|
||||||
|
skip_tls_verify: proxy['skip-cert-verify'],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else if (proxy.network === 'tcp' || !proxy.network) {
|
||||||
|
proxy.transport = {
|
||||||
|
[proxy.tls ? 'tls' : 'tcp']: {
|
||||||
|
sni: proxy.tls ? proxy.sni : undefined,
|
||||||
|
skip_tls_verify: proxy.tls
|
||||||
|
? proxy['skip-cert-verify']
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
proxy = {
|
||||||
|
type: 'vmess',
|
||||||
|
name: proxy.name,
|
||||||
|
server: proxy.server,
|
||||||
|
port: proxy.port,
|
||||||
|
user_id: proxy.uuid,
|
||||||
|
security: proxy.cipher,
|
||||||
|
tfo: proxy.tfo || proxy['fast-open'],
|
||||||
|
legacy: proxy.legacy,
|
||||||
|
udp_relay:
|
||||||
|
proxy.udp || proxy.udp_relay || proxy.udp_relay,
|
||||||
|
next_hop: proxy.next_hop,
|
||||||
|
transport: proxy.transport,
|
||||||
|
// sni: proxy.sni,
|
||||||
|
// skip_tls_verify: proxy['skip-cert-verify'],
|
||||||
|
};
|
||||||
|
} else if (proxy.type === 'vless') {
|
||||||
|
if (proxy.network === 'ws') {
|
||||||
|
proxy.transport = {
|
||||||
|
[proxy.tls ? 'wss' : 'ws']: {
|
||||||
|
path: proxy['ws-opts']?.path,
|
||||||
|
headers: {
|
||||||
|
Host: proxy['ws-opts']?.headers?.Host,
|
||||||
|
},
|
||||||
|
sni: proxy.tls ? proxy.sni : undefined,
|
||||||
|
skip_tls_verify: proxy.tls
|
||||||
|
? proxy['skip-cert-verify']
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else if (proxy.network === 'http') {
|
||||||
|
proxy.transport = {
|
||||||
|
http: {
|
||||||
|
method: proxy['http-opts']?.method,
|
||||||
|
path: proxy['http-opts']?.path,
|
||||||
|
headers: {
|
||||||
|
Host: Array.isArray(
|
||||||
|
proxy['http-opts']?.headers?.Host,
|
||||||
|
)
|
||||||
|
? proxy['http-opts']?.headers?.Host[0]
|
||||||
|
: proxy['http-opts']?.headers?.Host,
|
||||||
|
},
|
||||||
|
skip_tls_verify: proxy['skip-cert-verify'],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else if (proxy.network === 'tcp' || !proxy.network) {
|
||||||
|
proxy.transport = {
|
||||||
|
[proxy.tls ? 'tls' : 'tcp']: {
|
||||||
|
sni: proxy.tls ? proxy.sni : undefined,
|
||||||
|
skip_tls_verify: proxy.tls
|
||||||
|
? proxy['skip-cert-verify']
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
proxy = {
|
||||||
|
type: 'vless',
|
||||||
|
name: proxy.name,
|
||||||
|
server: proxy.server,
|
||||||
|
port: proxy.port,
|
||||||
|
user_id: proxy.uuid,
|
||||||
|
security: proxy.cipher,
|
||||||
|
tfo: proxy.tfo || proxy['fast-open'],
|
||||||
|
legacy: proxy.legacy,
|
||||||
|
udp_relay:
|
||||||
|
proxy.udp || proxy.udp_relay || proxy.udp_relay,
|
||||||
|
next_hop: proxy.next_hop,
|
||||||
|
transport: proxy.transport,
|
||||||
|
// sni: proxy.sni,
|
||||||
|
// skip_tls_verify: proxy['skip-cert-verify'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
delete proxy.subName;
|
||||||
|
delete proxy.collectionName;
|
||||||
|
delete proxy.id;
|
||||||
|
delete proxy.resolved;
|
||||||
|
delete proxy['no-resolve'];
|
||||||
|
if (type !== 'internal') {
|
||||||
|
for (const key in proxy) {
|
||||||
|
if (proxy[key] == null || /^_/i.test(key)) {
|
||||||
|
delete proxy[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
[proxy.type]: {
|
||||||
|
...proxy,
|
||||||
|
type: undefined,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return type === 'internal'
|
||||||
|
? list
|
||||||
|
: 'proxies:\n' +
|
||||||
|
list
|
||||||
|
.map((proxy) => ' - ' + JSON.stringify(proxy) + '\n')
|
||||||
|
.join('');
|
||||||
|
};
|
||||||
|
return { type, produce };
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import QX_Producer from './qx';
|
|||||||
import Shadowrocket_Producer from './shadowrocket';
|
import Shadowrocket_Producer from './shadowrocket';
|
||||||
import Surfboard_Producer from './surfboard';
|
import Surfboard_Producer from './surfboard';
|
||||||
import singbox_Producer from './sing-box';
|
import singbox_Producer from './sing-box';
|
||||||
|
import Egern_Producer from './egern';
|
||||||
|
|
||||||
function JSON_Producer() {
|
function JSON_Producer() {
|
||||||
const type = 'ALL';
|
const type = 'ALL';
|
||||||
@@ -34,4 +35,5 @@ export default {
|
|||||||
ShadowRocket: Shadowrocket_Producer(),
|
ShadowRocket: Shadowrocket_Producer(),
|
||||||
Surfboard: Surfboard_Producer(),
|
Surfboard: Surfboard_Producer(),
|
||||||
'sing-box': singbox_Producer(),
|
'sing-box': singbox_Producer(),
|
||||||
|
Egern: Egern_Producer(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import { isPresent, Result } from './utils';
|
|||||||
import { isIPv4, isIPv6 } from '@/utils';
|
import { isIPv4, isIPv6 } from '@/utils';
|
||||||
|
|
||||||
export default function Loon_Producer() {
|
export default function Loon_Producer() {
|
||||||
const produce = (proxy) => {
|
const produce = (proxy, type, opts = {}) => {
|
||||||
switch (proxy.type) {
|
switch (proxy.type) {
|
||||||
case 'ss':
|
case 'ss':
|
||||||
return shadowsocks(proxy);
|
return shadowsocks(proxy, opts['include-unsupported-proxy']);
|
||||||
case 'ssr':
|
case 'ssr':
|
||||||
return shadowsocksr(proxy);
|
return shadowsocksr(proxy);
|
||||||
case 'trojan':
|
case 'trojan':
|
||||||
@@ -32,7 +32,7 @@ export default function Loon_Producer() {
|
|||||||
return { produce };
|
return { produce };
|
||||||
}
|
}
|
||||||
|
|
||||||
function shadowsocks(proxy) {
|
function shadowsocks(proxy, includeUnsupportedProxy) {
|
||||||
const result = new Result(proxy);
|
const result = new Result(proxy);
|
||||||
if (
|
if (
|
||||||
![
|
![
|
||||||
@@ -56,6 +56,9 @@ function shadowsocks(proxy) {
|
|||||||
'aes-256-gcm',
|
'aes-256-gcm',
|
||||||
'chacha20-ietf-poly1305',
|
'chacha20-ietf-poly1305',
|
||||||
'xchacha20-ietf-poly1305',
|
'xchacha20-ietf-poly1305',
|
||||||
|
...(includeUnsupportedProxy
|
||||||
|
? ['2022-blake3-aes-128-gcm', '2022-blake3-aes-256-gcm']
|
||||||
|
: []),
|
||||||
].includes(proxy.cipher)
|
].includes(proxy.cipher)
|
||||||
) {
|
) {
|
||||||
throw new Error(`cipher ${proxy.cipher} is not supported`);
|
throw new Error(`cipher ${proxy.cipher} is not supported`);
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ export default function ShadowRocket_Producer() {
|
|||||||
if (opts['include-unsupported-proxy']) return true;
|
if (opts['include-unsupported-proxy']) return true;
|
||||||
if (proxy.type === 'snell' && String(proxy.version) === '4') {
|
if (proxy.type === 'snell' && String(proxy.version) === '4') {
|
||||||
return false;
|
return false;
|
||||||
|
} else if (['mieru'].includes(proxy.type)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
@@ -193,6 +195,7 @@ export default function ShadowRocket_Producer() {
|
|||||||
proxy[`${proxy.network}-opts`]
|
proxy[`${proxy.network}-opts`]
|
||||||
) {
|
) {
|
||||||
delete proxy[`${proxy.network}-opts`]['_grpc-type'];
|
delete proxy[`${proxy.network}-opts`]['_grpc-type'];
|
||||||
|
delete proxy[`${proxy.network}-opts`]['_grpc-authority'];
|
||||||
}
|
}
|
||||||
return proxy;
|
return proxy;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import $ from '@/core/app';
|
|||||||
import { isIPv4, isIPv6 } from '@/utils';
|
import { isIPv4, isIPv6 } from '@/utils';
|
||||||
|
|
||||||
const detourParser = (proxy, parsedProxy) => {
|
const detourParser = (proxy, parsedProxy) => {
|
||||||
if (proxy['dialer-proxy']) parsedProxy.detour = proxy['dialer-proxy'];
|
parsedProxy.detour = proxy['dialer-proxy'] || proxy.detour;
|
||||||
};
|
};
|
||||||
const tfoParser = (proxy, parsedProxy) => {
|
const tfoParser = (proxy, parsedProxy) => {
|
||||||
parsedProxy.tcp_fast_open = false;
|
parsedProxy.tcp_fast_open = false;
|
||||||
@@ -214,7 +214,11 @@ const tlsParser = (proxy, parsedProxy) => {
|
|||||||
proxy['reality-opts']['short-id'];
|
proxy['reality-opts']['short-id'];
|
||||||
parsedProxy.tls.utls = { enabled: true };
|
parsedProxy.tls.utls = { enabled: true };
|
||||||
}
|
}
|
||||||
if (proxy['client-fingerprint'] && proxy['client-fingerprint'] !== '')
|
if (
|
||||||
|
!['hysteria', 'hysteria2', 'tuic'].includes(proxy.type) &&
|
||||||
|
proxy['client-fingerprint'] &&
|
||||||
|
proxy['client-fingerprint'] !== ''
|
||||||
|
)
|
||||||
parsedProxy.tls.utls = {
|
parsedProxy.tls.utls = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
fingerprint: proxy['client-fingerprint'],
|
fingerprint: proxy['client-fingerprint'],
|
||||||
@@ -564,7 +568,7 @@ const hysteriaParser = (proxy = {}) => {
|
|||||||
smuxParser(proxy.smux, parsedProxy);
|
smuxParser(proxy.smux, parsedProxy);
|
||||||
return parsedProxy;
|
return parsedProxy;
|
||||||
};
|
};
|
||||||
const hysteria2Parser = (proxy = {}) => {
|
const hysteria2Parser = (proxy = {}, includeUnsupportedProxy) => {
|
||||||
const parsedProxy = {
|
const parsedProxy = {
|
||||||
tag: proxy.name,
|
tag: proxy.name,
|
||||||
type: 'hysteria2',
|
type: 'hysteria2',
|
||||||
@@ -576,6 +580,16 @@ const hysteria2Parser = (proxy = {}) => {
|
|||||||
};
|
};
|
||||||
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
||||||
throw 'invalid port';
|
throw 'invalid port';
|
||||||
|
if (includeUnsupportedProxy) {
|
||||||
|
if (proxy['hop-interval'])
|
||||||
|
parsedProxy.hop_interval = /^\d+$/.test(proxy['hop-interval'])
|
||||||
|
? `${proxy['hop-interval']}s`
|
||||||
|
: proxy['hop-interval'];
|
||||||
|
if (proxy['ports'])
|
||||||
|
parsedProxy.server_ports = proxy['ports']
|
||||||
|
.split(/\s*,\s*/)
|
||||||
|
.map((p) => p.replace(/\s*-\s*/g, ':'));
|
||||||
|
}
|
||||||
if (proxy.up) parsedProxy.up_mbps = parseInt(`${proxy.up}`, 10);
|
if (proxy.up) parsedProxy.up_mbps = parseInt(`${proxy.up}`, 10);
|
||||||
if (proxy.down) parsedProxy.down_mbps = parseInt(`${proxy.down}`, 10);
|
if (proxy.down) parsedProxy.down_mbps = parseInt(`${proxy.down}`, 10);
|
||||||
if (proxy.obfs === 'salamander') parsedProxy.obfs.type = 'salamander';
|
if (proxy.obfs === 'salamander') parsedProxy.obfs.type = 'salamander';
|
||||||
@@ -786,7 +800,12 @@ export default function singbox_Producer() {
|
|||||||
list.push(hysteriaParser(proxy));
|
list.push(hysteriaParser(proxy));
|
||||||
break;
|
break;
|
||||||
case 'hysteria2':
|
case 'hysteria2':
|
||||||
list.push(hysteria2Parser(proxy));
|
list.push(
|
||||||
|
hysteria2Parser(
|
||||||
|
proxy,
|
||||||
|
opts['include-unsupported-proxy'],
|
||||||
|
),
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'tuic':
|
case 'tuic':
|
||||||
if (!proxy.token || proxy.token.length === 0) {
|
if (!proxy.token || proxy.token.length === 0) {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ export default function Stash_Producer() {
|
|||||||
// https://stash.wiki/proxy-protocols/proxy-types#shadowsocks
|
// https://stash.wiki/proxy-protocols/proxy-types#shadowsocks
|
||||||
const list = proxies
|
const list = proxies
|
||||||
.filter((proxy) => {
|
.filter((proxy) => {
|
||||||
if (opts['include-unsupported-proxy']) return true;
|
|
||||||
if (
|
if (
|
||||||
![
|
![
|
||||||
'ss',
|
'ss',
|
||||||
@@ -40,6 +39,12 @@ export default function Stash_Producer() {
|
|||||||
'xchacha20',
|
'xchacha20',
|
||||||
'chacha20-ietf-poly1305',
|
'chacha20-ietf-poly1305',
|
||||||
'xchacha20-ietf-poly1305',
|
'xchacha20-ietf-poly1305',
|
||||||
|
...(opts['include-unsupported-proxy']
|
||||||
|
? [
|
||||||
|
'2022-blake3-aes-128-gcm',
|
||||||
|
'2022-blake3-aes-256-gcm',
|
||||||
|
]
|
||||||
|
: []),
|
||||||
].includes(proxy.cipher)) ||
|
].includes(proxy.cipher)) ||
|
||||||
(proxy.type === 'snell' && String(proxy.version) === '4') ||
|
(proxy.type === 'snell' && String(proxy.version) === '4') ||
|
||||||
(proxy.type === 'vless' && proxy['reality-opts'])
|
(proxy.type === 'vless' && proxy['reality-opts'])
|
||||||
@@ -284,6 +289,7 @@ export default function Stash_Producer() {
|
|||||||
proxy[`${proxy.network}-opts`]
|
proxy[`${proxy.network}-opts`]
|
||||||
) {
|
) {
|
||||||
delete proxy[`${proxy.network}-opts`]['_grpc-type'];
|
delete proxy[`${proxy.network}-opts`]['_grpc-type'];
|
||||||
|
delete proxy[`${proxy.network}-opts`]['_grpc-authority'];
|
||||||
}
|
}
|
||||||
return proxy;
|
return proxy;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ export default function Surge_Producer() {
|
|||||||
return vmess(proxy, opts['include-unsupported-proxy']);
|
return vmess(proxy, opts['include-unsupported-proxy']);
|
||||||
case 'http':
|
case 'http':
|
||||||
return http(proxy);
|
return http(proxy);
|
||||||
|
case 'direct':
|
||||||
|
return direct(proxy);
|
||||||
case 'socks5':
|
case 'socks5':
|
||||||
return socks5(proxy);
|
return socks5(proxy);
|
||||||
case 'snell':
|
case 'snell':
|
||||||
@@ -503,6 +505,54 @@ function http(proxy) {
|
|||||||
|
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
function direct(proxy) {
|
||||||
|
const result = new Result(proxy);
|
||||||
|
const type = 'direct';
|
||||||
|
result.append(`${proxy.name}=${type}`);
|
||||||
|
|
||||||
|
const ip_version = ipVersions[proxy['ip-version']] || proxy['ip-version'];
|
||||||
|
result.appendIfPresent(`,ip-version=${ip_version}`, 'ip-version');
|
||||||
|
|
||||||
|
result.appendIfPresent(
|
||||||
|
`,no-error-alert=${proxy['no-error-alert']}`,
|
||||||
|
'no-error-alert',
|
||||||
|
);
|
||||||
|
|
||||||
|
// tfo
|
||||||
|
result.appendIfPresent(`,tfo=${proxy.tfo}`, 'tfo');
|
||||||
|
|
||||||
|
// udp
|
||||||
|
result.appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp');
|
||||||
|
|
||||||
|
// test-url
|
||||||
|
result.appendIfPresent(`,test-url=${proxy['test-url']}`, 'test-url');
|
||||||
|
result.appendIfPresent(
|
||||||
|
`,test-timeout=${proxy['test-timeout']}`,
|
||||||
|
'test-timeout',
|
||||||
|
);
|
||||||
|
result.appendIfPresent(`,test-udp=${proxy['test-udp']}`, 'test-udp');
|
||||||
|
result.appendIfPresent(`,hybrid=${proxy['hybrid']}`, 'hybrid');
|
||||||
|
result.appendIfPresent(`,tos=${proxy['tos']}`, 'tos');
|
||||||
|
result.appendIfPresent(
|
||||||
|
`,allow-other-interface=${proxy['allow-other-interface']}`,
|
||||||
|
'allow-other-interface',
|
||||||
|
);
|
||||||
|
result.appendIfPresent(
|
||||||
|
`,interface=${proxy['interface-name']}`,
|
||||||
|
'interface-name',
|
||||||
|
);
|
||||||
|
|
||||||
|
// block-quic
|
||||||
|
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
|
||||||
|
|
||||||
|
// underlying-proxy
|
||||||
|
result.appendIfPresent(
|
||||||
|
`,underlying-proxy=${proxy['underlying-proxy']}`,
|
||||||
|
'underlying-proxy',
|
||||||
|
);
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
function socks5(proxy) {
|
function socks5(proxy) {
|
||||||
const result = new Result(proxy);
|
const result = new Result(proxy);
|
||||||
|
|||||||
@@ -29,9 +29,13 @@ export default function URI_Producer() {
|
|||||||
switch (proxy.type) {
|
switch (proxy.type) {
|
||||||
case 'ss':
|
case 'ss':
|
||||||
const userinfo = `${proxy.cipher}:${proxy.password}`;
|
const userinfo = `${proxy.cipher}:${proxy.password}`;
|
||||||
result = `ss://${Base64.encode(userinfo)}@${proxy.server}:${
|
result = `ss://${
|
||||||
proxy.port
|
proxy.cipher?.startsWith('2022-blake3-')
|
||||||
}${proxy.plugin ? '/' : ''}`;
|
? `${encodeURIComponent(
|
||||||
|
proxy.cipher,
|
||||||
|
)}:${encodeURIComponent(proxy.password)}`
|
||||||
|
: Base64.encode(userinfo)
|
||||||
|
}@${proxy.server}:${proxy.port}${proxy.plugin ? '/' : ''}`;
|
||||||
if (proxy.plugin) {
|
if (proxy.plugin) {
|
||||||
result += '?plugin=';
|
result += '?plugin=';
|
||||||
const opts = proxy['plugin-opts'];
|
const opts = proxy['plugin-opts'];
|
||||||
@@ -102,7 +106,7 @@ export default function URI_Producer() {
|
|||||||
port: proxy.port,
|
port: proxy.port,
|
||||||
id: proxy.uuid,
|
id: proxy.uuid,
|
||||||
type,
|
type,
|
||||||
aid: 0,
|
aid: proxy.alterId || 0,
|
||||||
net,
|
net,
|
||||||
tls: proxy.tls ? 'tls' : '',
|
tls: proxy.tls ? 'tls' : '',
|
||||||
};
|
};
|
||||||
@@ -134,6 +138,8 @@ export default function URI_Producer() {
|
|||||||
result.type =
|
result.type =
|
||||||
proxy[`${proxy.network}-opts`]?.['_grpc-type'] ||
|
proxy[`${proxy.network}-opts`]?.['_grpc-type'] ||
|
||||||
'gun';
|
'gun';
|
||||||
|
result.host =
|
||||||
|
proxy[`${proxy.network}-opts`]?.['_grpc-authority'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = 'vmess://' + Base64.encode(JSON.stringify(result));
|
result = 'vmess://' + Base64.encode(JSON.stringify(result));
|
||||||
@@ -196,6 +202,13 @@ export default function URI_Producer() {
|
|||||||
vlessTransport += `&mode=${encodeURIComponent(
|
vlessTransport += `&mode=${encodeURIComponent(
|
||||||
proxy[`${proxy.network}-opts`]?.['_grpc-type'] || 'gun',
|
proxy[`${proxy.network}-opts`]?.['_grpc-type'] || 'gun',
|
||||||
)}`;
|
)}`;
|
||||||
|
const authority =
|
||||||
|
proxy[`${proxy.network}-opts`]?.['_grpc-authority'];
|
||||||
|
if (authority) {
|
||||||
|
vlessTransport += `&authority=${encodeURIComponent(
|
||||||
|
authority,
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let vlessTransportServiceName =
|
let vlessTransportServiceName =
|
||||||
@@ -261,11 +274,18 @@ export default function URI_Producer() {
|
|||||||
proxy[`${proxy.network}-opts`]?.[
|
proxy[`${proxy.network}-opts`]?.[
|
||||||
`${proxy.network}-service-name`
|
`${proxy.network}-service-name`
|
||||||
];
|
];
|
||||||
|
let trojanTransportAuthority =
|
||||||
|
proxy[`${proxy.network}-opts`]?.['_grpc-authority'];
|
||||||
if (trojanTransportServiceName) {
|
if (trojanTransportServiceName) {
|
||||||
trojanTransport += `&serviceName=${encodeURIComponent(
|
trojanTransport += `&serviceName=${encodeURIComponent(
|
||||||
trojanTransportServiceName,
|
trojanTransportServiceName,
|
||||||
)}`;
|
)}`;
|
||||||
}
|
}
|
||||||
|
if (trojanTransportAuthority) {
|
||||||
|
trojanTransport += `&authority=${encodeURIComponent(
|
||||||
|
trojanTransportAuthority,
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
trojanTransport += `&mode=${encodeURIComponent(
|
trojanTransport += `&mode=${encodeURIComponent(
|
||||||
proxy[`${proxy.network}-opts`]?.['_grpc-type'] ||
|
proxy[`${proxy.network}-opts`]?.['_grpc-type'] ||
|
||||||
'gun',
|
'gun',
|
||||||
@@ -290,11 +310,27 @@ export default function URI_Producer() {
|
|||||||
)}`;
|
)}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let trojanFp = '';
|
||||||
|
if (proxy['client-fingerprint']) {
|
||||||
|
trojanFp = `&fp=${encodeURIComponent(
|
||||||
|
proxy['client-fingerprint'],
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
|
let trojanAlpn = '';
|
||||||
|
if (proxy.alpn) {
|
||||||
|
trojanAlpn = `&alpn=${encodeURIComponent(
|
||||||
|
Array.isArray(proxy.alpn)
|
||||||
|
? proxy.alpn
|
||||||
|
: proxy.alpn.join(','),
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
result = `trojan://${proxy.password}@${proxy.server}:${
|
result = `trojan://${proxy.password}@${proxy.server}:${
|
||||||
proxy.port
|
proxy.port
|
||||||
}?sni=${encodeURIComponent(proxy.sni || proxy.server)}${
|
}?sni=${encodeURIComponent(proxy.sni || proxy.server)}${
|
||||||
proxy['skip-cert-verify'] ? '&allowInsecure=1' : ''
|
proxy['skip-cert-verify'] ? '&allowInsecure=1' : ''
|
||||||
}${trojanTransport}#${encodeURIComponent(proxy.name)}`;
|
}${trojanTransport}${trojanAlpn}${trojanFp}#${encodeURIComponent(
|
||||||
|
proxy.name,
|
||||||
|
)}`;
|
||||||
break;
|
break;
|
||||||
case 'hysteria2':
|
case 'hysteria2':
|
||||||
let hysteria2params = [];
|
let hysteria2params = [];
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ let resourceUrl = typeof $resourceUrl !== 'undefined' ? $resourceUrl : '';
|
|||||||
if (resourceType === RESOURCE_TYPE.PROXY) {
|
if (resourceType === RESOURCE_TYPE.PROXY) {
|
||||||
try {
|
try {
|
||||||
let proxies = ProxyUtils.parse(resource);
|
let proxies = ProxyUtils.parse(resource);
|
||||||
result = ProxyUtils.produce(proxies, 'Loon');
|
result = ProxyUtils.produce(proxies, 'Loon', undefined, {
|
||||||
|
'include-unsupported-proxy': arg?.includeUnsupportedProxy,
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('解析器: 使用 resource 出现错误');
|
console.log('解析器: 使用 resource 出现错误');
|
||||||
console.log(e.message ?? e);
|
console.log(e.message ?? e);
|
||||||
@@ -45,9 +47,20 @@ let resourceUrl = typeof $resourceUrl !== 'undefined' ? $resourceUrl : '';
|
|||||||
if ((!result || /^\s*$/.test(result)) && resourceUrl) {
|
if ((!result || /^\s*$/.test(result)) && resourceUrl) {
|
||||||
console.log(`解析器: 尝试从 ${resourceUrl} 获取订阅`);
|
console.log(`解析器: 尝试从 ${resourceUrl} 获取订阅`);
|
||||||
try {
|
try {
|
||||||
let raw = await download(resourceUrl, arg?.ua, arg?.timeout);
|
let raw = await download(
|
||||||
|
resourceUrl,
|
||||||
|
arg?.ua,
|
||||||
|
arg?.timeout,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
true,
|
||||||
|
);
|
||||||
let proxies = ProxyUtils.parse(raw);
|
let proxies = ProxyUtils.parse(raw);
|
||||||
result = ProxyUtils.produce(proxies, 'Loon');
|
result = ProxyUtils.produce(proxies, 'Loon', undefined, {
|
||||||
|
'include-unsupported-proxy': arg?.includeUnsupportedProxy,
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e.message ?? e);
|
console.log(e.message ?? e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ async function downloadSubscription(req, res) {
|
|||||||
$.info(
|
$.info(
|
||||||
`正在下载订阅:${name}\n请求 User-Agent: ${
|
`正在下载订阅:${name}\n请求 User-Agent: ${
|
||||||
req.headers['user-agent'] || req.headers['User-Agent']
|
req.headers['user-agent'] || req.headers['User-Agent']
|
||||||
}`,
|
}\n请求 target: ${req.query.target}\n实际输出: ${platform}`,
|
||||||
);
|
);
|
||||||
let {
|
let {
|
||||||
url,
|
url,
|
||||||
@@ -158,7 +158,7 @@ async function downloadSubscription(req, res) {
|
|||||||
proxy,
|
proxy,
|
||||||
noCache,
|
noCache,
|
||||||
});
|
});
|
||||||
|
let flowInfo;
|
||||||
if (
|
if (
|
||||||
sub.source !== 'local' ||
|
sub.source !== 'local' ||
|
||||||
['localFirst', 'remoteFirst'].includes(sub.mergeSources)
|
['localFirst', 'remoteFirst'].includes(sub.mergeSources)
|
||||||
@@ -193,7 +193,7 @@ async function downloadSubscription(req, res) {
|
|||||||
}
|
}
|
||||||
if (!$arguments.noFlow) {
|
if (!$arguments.noFlow) {
|
||||||
// forward flow headers
|
// forward flow headers
|
||||||
const flowInfo = await getFlowHeaders(
|
flowInfo = await getFlowHeaders(
|
||||||
$arguments?.insecure ? `${url}#insecure` : url,
|
$arguments?.insecure ? `${url}#insecure` : url,
|
||||||
$arguments.flowUserAgent,
|
$arguments.flowUserAgent,
|
||||||
undefined,
|
undefined,
|
||||||
@@ -213,7 +213,30 @@ async function downloadSubscription(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sub.subUserinfo) {
|
if (sub.subUserinfo) {
|
||||||
res.set('subscription-userinfo', 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',
|
||||||
|
[subUserInfo, flowInfo].filter((i) => i).join('; '),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (platform === 'JSON') {
|
if (platform === 'JSON') {
|
||||||
@@ -252,7 +275,7 @@ async function downloadSubscription(req, res) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$.notify(`🌍 Sub-Store 下载订阅失败`, `❌ 未找到订阅:${name}!`);
|
$.error(`🌍 Sub-Store 下载订阅失败\n❌ 未找到订阅:${name}!`);
|
||||||
failed(
|
failed(
|
||||||
res,
|
res,
|
||||||
new ResourceNotFoundError(
|
new ResourceNotFoundError(
|
||||||
@@ -280,7 +303,7 @@ async function downloadCollection(req, res) {
|
|||||||
$.info(
|
$.info(
|
||||||
`正在下载组合订阅:${name}\n请求 User-Agent: ${
|
`正在下载组合订阅:${name}\n请求 User-Agent: ${
|
||||||
req.headers['user-agent'] || req.headers['User-Agent']
|
req.headers['user-agent'] || req.headers['User-Agent']
|
||||||
}`,
|
}\n请求 target: ${req.query.target}\n实际输出: ${platform}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -352,7 +375,7 @@ async function downloadCollection(req, res) {
|
|||||||
proxy,
|
proxy,
|
||||||
noCache,
|
noCache,
|
||||||
});
|
});
|
||||||
|
let subUserInfoOfSub;
|
||||||
// forward flow header from the first subscription in this collection
|
// forward flow header from the first subscription in this collection
|
||||||
const allSubs = $.read(SUBS_KEY);
|
const allSubs = $.read(SUBS_KEY);
|
||||||
const subnames = collection.subscriptions;
|
const subnames = collection.subscriptions;
|
||||||
@@ -391,16 +414,13 @@ async function downloadCollection(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$arguments.noFlow) {
|
if (!$arguments.noFlow) {
|
||||||
const flowInfo = await getFlowHeaders(
|
subUserInfoOfSub = await getFlowHeaders(
|
||||||
$arguments?.insecure ? `${url}#insecure` : url,
|
$arguments?.insecure ? `${url}#insecure` : url,
|
||||||
$arguments.flowUserAgent,
|
$arguments.flowUserAgent,
|
||||||
undefined,
|
undefined,
|
||||||
proxy || sub.proxy || collection.proxy,
|
proxy || sub.proxy || collection.proxy,
|
||||||
$arguments.flowUrl,
|
$arguments.flowUrl,
|
||||||
);
|
);
|
||||||
if (flowInfo) {
|
|
||||||
res.set('subscription-userinfo', flowInfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
$.error(
|
$.error(
|
||||||
@@ -411,10 +431,61 @@ async function downloadCollection(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sub.subUserinfo) {
|
if (sub.subUserinfo) {
|
||||||
res.set('subscription-userinfo', 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;
|
||||||
|
}
|
||||||
|
subUserInfoOfSub = [subUserInfo, subUserInfoOfSub]
|
||||||
|
.filter((i) => i)
|
||||||
|
.join('; ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$.info(`组合订阅 ${name} 透传的的流量信息: ${subUserInfoOfSub}`);
|
||||||
|
|
||||||
|
let subUserInfoOfCol;
|
||||||
|
if (/^https?:\/\//.test(collection.subUserinfo)) {
|
||||||
|
try {
|
||||||
|
subUserInfoOfCol = await getFlowHeaders(
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
proxy || collection.proxy,
|
||||||
|
collection.subUserinfo,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
$.error(
|
||||||
|
`组合订阅 ${name} 使用自定义流量链接 ${
|
||||||
|
collection.subUserinfo
|
||||||
|
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
subUserInfoOfCol = collection.subUserinfo;
|
||||||
|
}
|
||||||
|
res.set(
|
||||||
|
'subscription-userinfo',
|
||||||
|
[subUserInfoOfCol, subUserInfoOfSub]
|
||||||
|
.filter((i) => i)
|
||||||
|
.join('; '),
|
||||||
|
);
|
||||||
|
|
||||||
if (platform === 'JSON') {
|
if (platform === 'JSON') {
|
||||||
if (resultFormat === 'nezha') {
|
if (resultFormat === 'nezha') {
|
||||||
output = nezhaTransform(output);
|
output = nezhaTransform(output);
|
||||||
@@ -450,7 +521,7 @@ async function downloadCollection(req, res) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$.notify(
|
$.error(
|
||||||
`🌍 Sub-Store 下载组合订阅失败`,
|
`🌍 Sub-Store 下载组合订阅失败`,
|
||||||
`❌ 未找到组合订阅:${name}!`,
|
`❌ 未找到组合订阅:${name}!`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ async function getFile(req, res) {
|
|||||||
mergeSources,
|
mergeSources,
|
||||||
ignoreFailedRemoteFile,
|
ignoreFailedRemoteFile,
|
||||||
proxy,
|
proxy,
|
||||||
|
noCache,
|
||||||
} = req.query;
|
} = req.query;
|
||||||
let $options = {};
|
let $options = {};
|
||||||
if (req.query.$options) {
|
if (req.query.$options) {
|
||||||
@@ -113,6 +114,9 @@ async function getFile(req, res) {
|
|||||||
ignoreFailedRemoteFile = decodeURIComponent(ignoreFailedRemoteFile);
|
ignoreFailedRemoteFile = decodeURIComponent(ignoreFailedRemoteFile);
|
||||||
$.info(`指定忽略失败的远程文件: ${ignoreFailedRemoteFile}`);
|
$.info(`指定忽略失败的远程文件: ${ignoreFailedRemoteFile}`);
|
||||||
}
|
}
|
||||||
|
if (noCache) {
|
||||||
|
$.info(`指定不使用缓存: ${noCache}`);
|
||||||
|
}
|
||||||
|
|
||||||
const allFiles = $.read(FILES_KEY);
|
const allFiles = $.read(FILES_KEY);
|
||||||
const file = findByName(allFiles, name);
|
const file = findByName(allFiles, name);
|
||||||
@@ -128,6 +132,7 @@ async function getFile(req, res) {
|
|||||||
ignoreFailedRemoteFile,
|
ignoreFailedRemoteFile,
|
||||||
$options,
|
$options,
|
||||||
proxy,
|
proxy,
|
||||||
|
noCache,
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -179,7 +184,7 @@ async function getFile(req, res) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$.notify(`🌍 Sub-Store 下载文件失败`, `❌ 未找到文件:${name}!`);
|
$.error(`🌍 Sub-Store 下载文件失败\n❌ 未找到文件:${name}!`);
|
||||||
failed(
|
failed(
|
||||||
res,
|
res,
|
||||||
new ResourceNotFoundError(
|
new ResourceNotFoundError(
|
||||||
|
|||||||
@@ -114,6 +114,10 @@ async function compareSub(req, res) {
|
|||||||
sub.ua,
|
sub.ua,
|
||||||
undefined,
|
undefined,
|
||||||
sub.proxy,
|
sub.proxy,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errors[url] = err;
|
errors[url] = err;
|
||||||
@@ -219,6 +223,10 @@ async function compareCollection(req, res) {
|
|||||||
sub.ua,
|
sub.ua,
|
||||||
undefined,
|
undefined,
|
||||||
sub.proxy,
|
sub.proxy,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errors[url] = err;
|
errors[url] = err;
|
||||||
|
|||||||
@@ -57,9 +57,29 @@ async function getFlowInfo(req, res) {
|
|||||||
!['localFirst', 'remoteFirst'].includes(sub.mergeSources)
|
!['localFirst', 'remoteFirst'].includes(sub.mergeSources)
|
||||||
) {
|
) {
|
||||||
if (sub.subUserinfo) {
|
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 {
|
try {
|
||||||
success(res, {
|
success(res, {
|
||||||
...parseFlowHeaders(sub.subUserinfo),
|
...parseFlowHeaders(subUserInfo),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
$.error(
|
$.error(
|
||||||
@@ -125,66 +145,73 @@ async function getFlowInfo(req, res) {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (sub.subUserinfo) {
|
const flowHeaders = await getFlowHeaders(
|
||||||
try {
|
$arguments?.insecure ? `${url}#insecure` : url,
|
||||||
const remainingDays = getRmainingDays({
|
$arguments.flowUserAgent,
|
||||||
resetDay: $arguments.resetDay,
|
undefined,
|
||||||
startDate: $arguments.startDate,
|
sub.proxy,
|
||||||
cycleDays: $arguments.cycleDays,
|
$arguments.flowUrl,
|
||||||
});
|
);
|
||||||
const result = {
|
if (!flowHeaders && !sub.subUserinfo) {
|
||||||
...parseFlowHeaders(sub.subUserinfo),
|
failed(
|
||||||
};
|
res,
|
||||||
if (remainingDays != null) {
|
new InternalServerError(
|
||||||
result.remainingDays = remainingDays;
|
'NO_FLOW_INFO',
|
||||||
}
|
'No flow info',
|
||||||
success(res, result);
|
`Failed to fetch flow headers`,
|
||||||
} catch (e) {
|
),
|
||||||
$.error(
|
|
||||||
`Failed to parse flow info for local subscription ${name}: ${
|
|
||||||
e.message ?? e
|
|
||||||
}`,
|
|
||||||
);
|
|
||||||
failed(
|
|
||||||
res,
|
|
||||||
new RequestInvalidError(
|
|
||||||
'NO_FLOW_INFO',
|
|
||||||
'N/A',
|
|
||||||
`Failed to parse flow info`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const flowHeaders = await getFlowHeaders(
|
|
||||||
$arguments?.insecure ? `${url}#insecure` : url,
|
|
||||||
$arguments.flowUserAgent,
|
|
||||||
undefined,
|
|
||||||
sub.proxy,
|
|
||||||
$arguments.flowUrl,
|
|
||||||
);
|
);
|
||||||
if (!flowHeaders) {
|
return;
|
||||||
failed(
|
}
|
||||||
res,
|
try {
|
||||||
new InternalServerError(
|
|
||||||
'NO_FLOW_INFO',
|
|
||||||
'No flow info',
|
|
||||||
`Failed to fetch flow headers`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const remainingDays = getRmainingDays({
|
const remainingDays = getRmainingDays({
|
||||||
resetDay: $arguments.resetDay,
|
resetDay: $arguments.resetDay,
|
||||||
startDate: $arguments.startDate,
|
startDate: $arguments.startDate,
|
||||||
cycleDays: $arguments.cycleDays,
|
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 = {
|
const result = {
|
||||||
...parseFlowHeaders(flowHeaders),
|
...parseFlowHeaders(
|
||||||
|
[subUserInfo, flowHeaders].filter((i) => i).join('; '),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
if (remainingDays != null) {
|
if (remainingDays != null) {
|
||||||
result.remainingDays = remainingDays;
|
result.remainingDays = remainingDays;
|
||||||
}
|
}
|
||||||
success(res, result);
|
success(res, result);
|
||||||
|
} catch (e) {
|
||||||
|
$.error(
|
||||||
|
`Failed to parse flow info for local subscription ${name}: ${
|
||||||
|
e.message ?? e
|
||||||
|
}`,
|
||||||
|
);
|
||||||
|
failed(
|
||||||
|
res,
|
||||||
|
new RequestInvalidError(
|
||||||
|
'NO_FLOW_INFO',
|
||||||
|
'N/A',
|
||||||
|
`Failed to parse flow info`,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
failed(
|
failed(
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ async function produceArtifact({
|
|||||||
undefined,
|
undefined,
|
||||||
awaitCustomCache,
|
awaitCustomCache,
|
||||||
noCache,
|
noCache,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errors[url] = err;
|
errors[url] = err;
|
||||||
@@ -122,6 +123,7 @@ async function produceArtifact({
|
|||||||
undefined,
|
undefined,
|
||||||
awaitCustomCache,
|
awaitCustomCache,
|
||||||
noCache,
|
noCache,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errors[url] = err;
|
errors[url] = err;
|
||||||
@@ -243,6 +245,7 @@ async function produceArtifact({
|
|||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
noCache,
|
noCache,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errors[url] = err;
|
errors[url] = err;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import $ from '@/core/app';
|
import $ from '@/core/app';
|
||||||
import dnsPacket from 'dns-packet';
|
import dnsPacket from 'dns-packet';
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
|
import { isIPv4 } from '@/utils';
|
||||||
|
|
||||||
export async function doh({ url, domain, type = 'A', timeout, edns }) {
|
export async function doh({ url, domain, type = 'A', timeout, edns }) {
|
||||||
const buf = dnsPacket.encode({
|
const buf = dnsPacket.encode({
|
||||||
@@ -23,7 +24,7 @@ export async function doh({ url, domain, type = 'A', timeout, edns }) {
|
|||||||
{
|
{
|
||||||
code: 'CLIENT_SUBNET',
|
code: 'CLIENT_SUBNET',
|
||||||
ip: edns,
|
ip: edns,
|
||||||
sourcePrefixLength: 24,
|
sourcePrefixLength: isIPv4(edns) ? 24 : 56,
|
||||||
scopePrefixLength: 0,
|
scopePrefixLength: 0,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ import {
|
|||||||
validCheck,
|
validCheck,
|
||||||
} from '@/utils/flow';
|
} from '@/utils/flow';
|
||||||
import $ from '@/core/app';
|
import $ from '@/core/app';
|
||||||
|
import PROXY_PREPROCESSORS from '@/core/proxy-utils/preprocessors';
|
||||||
|
const clashPreprocessor = PROXY_PREPROCESSORS.find(
|
||||||
|
(processor) => processor.name === 'Clash Pre-processor',
|
||||||
|
);
|
||||||
|
|
||||||
const tasks = new Map();
|
const tasks = new Map();
|
||||||
|
|
||||||
@@ -22,6 +26,7 @@ export default async function download(
|
|||||||
skipCustomCache,
|
skipCustomCache,
|
||||||
awaitCustomCache,
|
awaitCustomCache,
|
||||||
noCache,
|
noCache,
|
||||||
|
preprocess,
|
||||||
) {
|
) {
|
||||||
let $arguments = {};
|
let $arguments = {};
|
||||||
let url = rawUrl.replace(/#noFlow$/, '');
|
let url = rawUrl.replace(/#noFlow$/, '');
|
||||||
@@ -44,14 +49,19 @@ export default async function download(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const { isNode, isStash, isLoon, isShadowRocket, isQX } = ENV();
|
const { isNode, isStash, isLoon, isShadowRocket, isQX } = ENV();
|
||||||
const { defaultProxy, defaultUserAgent, defaultTimeout, cacheThreshold } =
|
const {
|
||||||
$.read(SETTINGS_KEY);
|
defaultProxy,
|
||||||
|
defaultUserAgent,
|
||||||
|
defaultTimeout,
|
||||||
|
cacheThreshold: defaultCacheThreshold,
|
||||||
|
} = $.read(SETTINGS_KEY);
|
||||||
|
const cacheThreshold = defaultCacheThreshold || 1024;
|
||||||
let proxy = customProxy || defaultProxy;
|
let proxy = customProxy || defaultProxy;
|
||||||
if ($.env.isNode) {
|
if ($.env.isNode) {
|
||||||
proxy = proxy || eval('process.env.SUB_STORE_BACKEND_DEFAULT_PROXY');
|
proxy = proxy || eval('process.env.SUB_STORE_BACKEND_DEFAULT_PROXY');
|
||||||
}
|
}
|
||||||
const userAgent = ua || defaultUserAgent || 'clash.meta';
|
const userAgent = ua || defaultUserAgent || 'clash.meta';
|
||||||
const requestTimeout = timeout || defaultTimeout;
|
const requestTimeout = timeout || defaultTimeout || 8000;
|
||||||
const id = hex_md5(userAgent + url);
|
const id = hex_md5(userAgent + url);
|
||||||
|
|
||||||
if ($arguments?.cacheKey === true) {
|
if ($arguments?.cacheKey === true) {
|
||||||
@@ -82,6 +92,9 @@ export default async function download(
|
|||||||
timeout,
|
timeout,
|
||||||
proxy,
|
proxy,
|
||||||
true,
|
true,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
preprocess,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
$.error(
|
$.error(
|
||||||
@@ -102,6 +115,9 @@ export default async function download(
|
|||||||
timeout,
|
timeout,
|
||||||
proxy,
|
proxy,
|
||||||
true,
|
true,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
preprocess,
|
||||||
).catch((e) => {
|
).catch((e) => {
|
||||||
$.error(
|
$.error(
|
||||||
`乐观缓存: URL ${url} 异步更新缓存发生错误 ${
|
`乐观缓存: URL ${url} 异步更新缓存发生错误 ${
|
||||||
@@ -151,7 +167,7 @@ export default async function download(
|
|||||||
// try to find in app cache
|
// try to find in app cache
|
||||||
const cached = resourceCache.get(id);
|
const cached = resourceCache.get(id);
|
||||||
if (!noCache && !$arguments?.noCache && cached) {
|
if (!noCache && !$arguments?.noCache && cached) {
|
||||||
$.info(`使用缓存: ${url}`);
|
$.info(`使用缓存: ${url}, ${userAgent}`);
|
||||||
result = cached;
|
result = cached;
|
||||||
if (customCacheKey) {
|
if (customCacheKey) {
|
||||||
$.info(`URL ${url}\n写入自定义缓存 ${$arguments?.cacheKey}`);
|
$.info(`URL ${url}\n写入自定义缓存 ${$arguments?.cacheKey}`);
|
||||||
@@ -164,10 +180,10 @@ export default async function download(
|
|||||||
: { insecure: true }
|
: { insecure: true }
|
||||||
: undefined;
|
: undefined;
|
||||||
$.info(
|
$.info(
|
||||||
`Downloading...\nUser-Agent: ${userAgent}\nTimeout: ${requestTimeout}\nProxy: ${proxy}\nInsecure: ${!!insecure}\nURL: ${url}`,
|
`Downloading...\nUser-Agent: ${userAgent}\nTimeout: ${requestTimeout}\nProxy: ${proxy}\nInsecure: ${!!insecure}\nPreprocess: ${preprocess}\nURL: ${url}`,
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
const { body, headers } = await http.get({
|
let { body, headers, statusCode } = await http.get({
|
||||||
url,
|
url,
|
||||||
...(proxy ? { proxy } : {}),
|
...(proxy ? { proxy } : {}),
|
||||||
...(isLoon && proxy ? { node: proxy } : {}),
|
...(isLoon && proxy ? { node: proxy } : {}),
|
||||||
@@ -175,15 +191,28 @@ export default async function download(
|
|||||||
...(proxy ? getPolicyDescriptor(proxy) : {}),
|
...(proxy ? getPolicyDescriptor(proxy) : {}),
|
||||||
...(insecure ? insecure : {}),
|
...(insecure ? insecure : {}),
|
||||||
});
|
});
|
||||||
|
$.info(`statusCode: ${statusCode}`);
|
||||||
|
if (statusCode < 200 || statusCode >= 400) {
|
||||||
|
throw new Error(`statusCode: ${statusCode}`);
|
||||||
|
}
|
||||||
|
|
||||||
if (headers) {
|
if (headers) {
|
||||||
const flowInfo = getFlowField(headers);
|
const flowInfo = getFlowField(headers);
|
||||||
if (flowInfo) {
|
if (flowInfo) {
|
||||||
headersResourceCache.set(url, flowInfo);
|
headersResourceCache.set(id, flowInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (body.replace(/\s/g, '').length === 0)
|
if (body.replace(/\s/g, '').length === 0)
|
||||||
throw new Error(new Error('远程资源内容为空'));
|
throw new Error(new Error('远程资源内容为空'));
|
||||||
|
if (preprocess) {
|
||||||
|
try {
|
||||||
|
if (clashPreprocessor.test(body)) {
|
||||||
|
body = clashPreprocessor.parse(body);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
$.error(`Clash Pre-processor error: ${e}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
let shouldCache = true;
|
let shouldCache = true;
|
||||||
if (cacheThreshold) {
|
if (cacheThreshold) {
|
||||||
const size = body.length / 1024;
|
const size = body.length / 1024;
|
||||||
|
|||||||
@@ -1,24 +1,25 @@
|
|||||||
import { SETTINGS_KEY } from '@/constants';
|
import { SETTINGS_KEY } from '@/constants';
|
||||||
import { HTTP, ENV } from '@/vendor/open-api';
|
import { HTTP, ENV } from '@/vendor/open-api';
|
||||||
|
import { hex_md5 } from '@/vendor/md5';
|
||||||
import { getPolicyDescriptor } from '@/utils';
|
import { getPolicyDescriptor } from '@/utils';
|
||||||
import $ from '@/core/app';
|
import $ from '@/core/app';
|
||||||
import headersResourceCache from '@/utils/headers-resource-cache';
|
import headersResourceCache from '@/utils/headers-resource-cache';
|
||||||
|
|
||||||
export function getFlowField(headers) {
|
export function getFlowField(headers) {
|
||||||
let subKey = '';
|
const keys = Object.keys(headers);
|
||||||
let webPageKey = '';
|
let sub = '';
|
||||||
|
let webPage = '';
|
||||||
Object.keys(headers).some((k) => {
|
for (let k of keys) {
|
||||||
if (/SUBSCRIPTION-USERINFO/i.test(k)) {
|
const lower = k.toLowerCase();
|
||||||
subKey = k;
|
if (lower === 'subscription-userinfo') {
|
||||||
} else if (/PROFILE-WEB-PAGE-URL/i.test(k)) {
|
sub = headers[k];
|
||||||
webPageKey = k;
|
} else if (lower === 'profile-web-page-url') {
|
||||||
|
webPage = headers[k];
|
||||||
}
|
}
|
||||||
return subKey && webPageKey;
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return `${headers[subKey] || ''}${
|
return `${sub || ''}${
|
||||||
webPageKey ? `;app_url=${headers[webPageKey]}` : ''
|
webPage ? `; app_url=${encodeURIComponent(webPage)}` : ''
|
||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
export async function getFlowHeaders(
|
export async function getFlowHeaders(
|
||||||
@@ -52,29 +53,26 @@ export async function getFlowHeaders(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { isStash, isLoon, isShadowRocket, isQX } = ENV();
|
const { isStash, isLoon, isShadowRocket, isQX } = ENV();
|
||||||
const cached = headersResourceCache.get(url);
|
const insecure = $arguments?.insecure
|
||||||
|
? $.env.isNode
|
||||||
|
? { strictSSL: false }
|
||||||
|
: { insecure: true }
|
||||||
|
: undefined;
|
||||||
|
const { defaultProxy, defaultFlowUserAgent, defaultTimeout } =
|
||||||
|
$.read(SETTINGS_KEY);
|
||||||
|
let proxy = customProxy || defaultProxy;
|
||||||
|
if ($.env.isNode) {
|
||||||
|
proxy = proxy || eval('process.env.SUB_STORE_BACKEND_DEFAULT_PROXY');
|
||||||
|
}
|
||||||
|
const userAgent = ua || defaultFlowUserAgent || 'clash';
|
||||||
|
const requestTimeout = timeout || defaultTimeout || 8000;
|
||||||
|
const id = hex_md5(userAgent + url);
|
||||||
|
const cached = headersResourceCache.get(id);
|
||||||
let flowInfo;
|
let flowInfo;
|
||||||
if (!$arguments?.noCache && cached) {
|
if (!$arguments?.noCache && cached) {
|
||||||
// $.info(`使用缓存的流量信息: ${url}`);
|
$.info(`使用缓存的流量信息: ${url}, ${userAgent}`);
|
||||||
flowInfo = cached;
|
flowInfo = cached;
|
||||||
} else {
|
} else {
|
||||||
const insecure = $arguments?.insecure
|
|
||||||
? $.env.isNode
|
|
||||||
? { strictSSL: false }
|
|
||||||
: { insecure: true }
|
|
||||||
: undefined;
|
|
||||||
const { defaultProxy, defaultFlowUserAgent, defaultTimeout } =
|
|
||||||
$.read(SETTINGS_KEY);
|
|
||||||
let proxy = customProxy || defaultProxy;
|
|
||||||
if ($.env.isNode) {
|
|
||||||
proxy =
|
|
||||||
proxy || eval('process.env.SUB_STORE_BACKEND_DEFAULT_PROXY');
|
|
||||||
}
|
|
||||||
const userAgent =
|
|
||||||
ua ||
|
|
||||||
defaultFlowUserAgent ||
|
|
||||||
'Quantumult%20X/1.0.30 (iPhone14,2; iOS 15.6)';
|
|
||||||
const requestTimeout = timeout || defaultTimeout;
|
|
||||||
const http = HTTP();
|
const http = HTTP();
|
||||||
if (flowUrl) {
|
if (flowUrl) {
|
||||||
$.info(
|
$.info(
|
||||||
@@ -170,7 +168,10 @@ export async function getFlowHeaders(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (flowInfo) {
|
if (flowInfo) {
|
||||||
headersResourceCache.set(url, flowInfo);
|
flowInfo = flowInfo.trim();
|
||||||
|
}
|
||||||
|
if (flowInfo) {
|
||||||
|
headersResourceCache.set(id, flowInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +208,7 @@ export function parseFlowHeaders(flowHeaders) {
|
|||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const appUrlMatch = flowHeaders.match(/app_url=(.*?)\s*?(;|$)/);
|
const appUrlMatch = flowHeaders.match(/app_url=(.*?)\s*?(;|$)/);
|
||||||
const appUrl = appUrlMatch ? appUrlMatch[1] : undefined;
|
const appUrl = appUrlMatch ? decodeURIComponent(appUrlMatch[1]) : undefined;
|
||||||
|
|
||||||
const planNameMatch = flowHeaders.match(/plan_name=(.*?)\s*?(;|$)/);
|
const planNameMatch = flowHeaders.match(/plan_name=(.*?)\s*?(;|$)/);
|
||||||
const planName = planNameMatch
|
const planName = planNameMatch
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const ISOFlags = {
|
|||||||
'🇧🇪': ['BE', 'BEL'],
|
'🇧🇪': ['BE', 'BEL'],
|
||||||
'🇧🇬': ['BG', 'BGR'],
|
'🇧🇬': ['BG', 'BGR'],
|
||||||
'🇧🇭': ['BH', 'BHR'],
|
'🇧🇭': ['BH', 'BHR'],
|
||||||
|
'🇧🇴': ['BO', 'BOL'],
|
||||||
'🇧🇷': ['BR', 'BRA'],
|
'🇧🇷': ['BR', 'BRA'],
|
||||||
'🇧🇾': ['BY', 'BLR'],
|
'🇧🇾': ['BY', 'BLR'],
|
||||||
'🇨🇦': ['CA', 'CAN'],
|
'🇨🇦': ['CA', 'CAN'],
|
||||||
@@ -38,6 +39,7 @@ const ISOFlags = {
|
|||||||
'🇬🇧': ['GB', 'GBR', 'UK'],
|
'🇬🇧': ['GB', 'GBR', 'UK'],
|
||||||
'🇬🇪': ['GE', 'GEO'],
|
'🇬🇪': ['GE', 'GEO'],
|
||||||
'🇬🇷': ['GR', 'GRC'],
|
'🇬🇷': ['GR', 'GRC'],
|
||||||
|
'🇬🇹': ['GT', 'GTM'],
|
||||||
'🇭🇰': ['HK', 'HKG', 'HKT', 'HKBN', 'HGC', 'WTT', 'CMI'],
|
'🇭🇰': ['HK', 'HKG', 'HKT', 'HKBN', 'HGC', 'WTT', 'CMI'],
|
||||||
'🇭🇷': ['HR', 'HRV'],
|
'🇭🇷': ['HR', 'HRV'],
|
||||||
'🇭🇺': ['HU', 'HUN'],
|
'🇭🇺': ['HU', 'HUN'],
|
||||||
@@ -141,6 +143,7 @@ export function getFlag(name) {
|
|||||||
'🇧🇭': ['Bahrain', '巴林'],
|
'🇧🇭': ['Bahrain', '巴林'],
|
||||||
'🇧🇷': ['Brazil', '巴西', '圣保罗'],
|
'🇧🇷': ['Brazil', '巴西', '圣保罗'],
|
||||||
'🇧🇾': ['Belarus', '白俄罗斯', '白俄'],
|
'🇧🇾': ['Belarus', '白俄罗斯', '白俄'],
|
||||||
|
'🇧🇴': ['Bolivia', '玻利维亚'],
|
||||||
'🇨🇦': [
|
'🇨🇦': [
|
||||||
'Canada',
|
'Canada',
|
||||||
'加拿大',
|
'加拿大',
|
||||||
@@ -151,6 +154,7 @@ export function getFlag(name) {
|
|||||||
'滑铁卢',
|
'滑铁卢',
|
||||||
'多伦多',
|
'多伦多',
|
||||||
'Waterloo',
|
'Waterloo',
|
||||||
|
'Toronto',
|
||||||
],
|
],
|
||||||
'🇨🇭': ['Switzerland', '瑞士', '苏黎世', 'Zurich'],
|
'🇨🇭': ['Switzerland', '瑞士', '苏黎世', 'Zurich'],
|
||||||
'🇨🇱': ['Chile', '智利'],
|
'🇨🇱': ['Chile', '智利'],
|
||||||
@@ -190,6 +194,7 @@ export function getFlag(name) {
|
|||||||
],
|
],
|
||||||
'🇬🇪': ['Georgia', '格鲁吉亚', '格魯吉亞'],
|
'🇬🇪': ['Georgia', '格鲁吉亚', '格魯吉亞'],
|
||||||
'🇬🇷': ['Greece', '希腊', '希臘'],
|
'🇬🇷': ['Greece', '希腊', '希臘'],
|
||||||
|
'🇬🇹': ['Guatemala', '危地马拉'],
|
||||||
'🇭🇰': [
|
'🇭🇰': [
|
||||||
'Hongkong',
|
'Hongkong',
|
||||||
'香港',
|
'香港',
|
||||||
@@ -245,7 +250,7 @@ export function getFlag(name) {
|
|||||||
'🇮🇪': ['Ireland', '爱尔兰', '愛爾蘭', '都柏林'],
|
'🇮🇪': ['Ireland', '爱尔兰', '愛爾蘭', '都柏林'],
|
||||||
'🇮🇱': ['Israel', '以色列'],
|
'🇮🇱': ['Israel', '以色列'],
|
||||||
'🇮🇲': ['Isle of Man', '马恩岛', '馬恩島'],
|
'🇮🇲': ['Isle of Man', '马恩岛', '馬恩島'],
|
||||||
'🇮🇳': ['India', '印度', '孟买', 'MFumbai'],
|
'🇮🇳': ['India', '印度', '孟买', 'MFumbai', 'Mumbai'],
|
||||||
'🇮🇷': ['Iran', '伊朗'],
|
'🇮🇷': ['Iran', '伊朗'],
|
||||||
'🇮🇸': ['Iceland', '冰岛', '冰島'],
|
'🇮🇸': ['Iceland', '冰岛', '冰島'],
|
||||||
'🇮🇹': ['Italy', '意大利', '義大利', '米兰', 'Nachash'],
|
'🇮🇹': ['Italy', '意大利', '義大利', '米兰', 'Nachash'],
|
||||||
@@ -261,7 +266,14 @@ export function getFlag(name) {
|
|||||||
'🇲🇹': ['Malta', '马耳他'],
|
'🇲🇹': ['Malta', '马耳他'],
|
||||||
'🇲🇽': ['Mexico', '墨西哥'],
|
'🇲🇽': ['Mexico', '墨西哥'],
|
||||||
'🇲🇾': ['Malaysia', '马来', '馬來', '吉隆坡', '大馬'],
|
'🇲🇾': ['Malaysia', '马来', '馬來', '吉隆坡', '大馬'],
|
||||||
'🇳🇱': ['Netherlands', '荷兰', '荷蘭', '尼德蘭', '阿姆斯特丹'],
|
'🇳🇱': [
|
||||||
|
'Netherlands',
|
||||||
|
'荷兰',
|
||||||
|
'荷蘭',
|
||||||
|
'尼德蘭',
|
||||||
|
'阿姆斯特丹',
|
||||||
|
'Amsterdam',
|
||||||
|
],
|
||||||
'🇳🇴': ['Norway', '挪威'],
|
'🇳🇴': ['Norway', '挪威'],
|
||||||
'🇳🇵': ['Nepal', '尼泊尔'],
|
'🇳🇵': ['Nepal', '尼泊尔'],
|
||||||
'🇳🇿': ['New Zealand', '新西兰', '新西蘭'],
|
'🇳🇿': ['New Zealand', '新西兰', '新西蘭'],
|
||||||
@@ -269,7 +281,7 @@ export function getFlag(name) {
|
|||||||
'🇵🇪': ['Peru', '秘鲁', '祕魯'],
|
'🇵🇪': ['Peru', '秘鲁', '祕魯'],
|
||||||
'🇵🇭': ['Philippines', '菲律宾', '菲律賓'],
|
'🇵🇭': ['Philippines', '菲律宾', '菲律賓'],
|
||||||
'🇵🇰': ['Pakistan', '巴基斯坦'],
|
'🇵🇰': ['Pakistan', '巴基斯坦'],
|
||||||
'🇵🇱': ['Poland', '波兰', '波蘭'],
|
'🇵🇱': ['Poland', '波兰', '波蘭', '华沙', 'Warsaw'],
|
||||||
'🇵🇷': ['Puerto Rico', '波多黎各'],
|
'🇵🇷': ['Puerto Rico', '波多黎各'],
|
||||||
'🇵🇹': ['Portugal', '葡萄牙'],
|
'🇵🇹': ['Portugal', '葡萄牙'],
|
||||||
'🇵🇾': ['Paraguay', '巴拉圭'],
|
'🇵🇾': ['Paraguay', '巴拉圭'],
|
||||||
@@ -294,7 +306,7 @@ export function getFlag(name) {
|
|||||||
'Moscow',
|
'Moscow',
|
||||||
],
|
],
|
||||||
'🇸🇦': ['Saudi', '沙特阿拉伯', '沙特', 'Riyadh', '利雅得'],
|
'🇸🇦': ['Saudi', '沙特阿拉伯', '沙特', 'Riyadh', '利雅得'],
|
||||||
'🇸🇪': ['Sweden', '瑞典'],
|
'🇸🇪': ['Sweden', '瑞典', '斯德哥尔摩', 'Stockholm'],
|
||||||
'🇸🇬': [
|
'🇸🇬': [
|
||||||
'Singapore',
|
'Singapore',
|
||||||
'新加坡',
|
'新加坡',
|
||||||
@@ -314,7 +326,7 @@ export function getFlag(name) {
|
|||||||
'🇸🇰': ['Slovakia', '斯洛伐克'],
|
'🇸🇰': ['Slovakia', '斯洛伐克'],
|
||||||
'🇹🇭': ['Thailand', '泰国', '泰國', '曼谷'],
|
'🇹🇭': ['Thailand', '泰国', '泰國', '曼谷'],
|
||||||
'🇹🇳': ['Tunisia', '突尼斯'],
|
'🇹🇳': ['Tunisia', '突尼斯'],
|
||||||
'🇹🇷': ['Turkey', '土耳其', '伊斯坦布尔'],
|
'🇹🇷': ['Turkey', '土耳其', '伊斯坦布尔', 'Istanbul'],
|
||||||
'🇹🇼': [
|
'🇹🇼': [
|
||||||
'Taiwan',
|
'Taiwan',
|
||||||
'台湾',
|
'台湾',
|
||||||
@@ -341,6 +353,7 @@ export function getFlag(name) {
|
|||||||
'波特兰',
|
'波特兰',
|
||||||
'达拉斯',
|
'达拉斯',
|
||||||
'俄勒冈',
|
'俄勒冈',
|
||||||
|
'Oregon',
|
||||||
'凤凰城',
|
'凤凰城',
|
||||||
'费利蒙',
|
'费利蒙',
|
||||||
'硅谷',
|
'硅谷',
|
||||||
@@ -354,10 +367,17 @@ export function getFlag(name) {
|
|||||||
'沪美',
|
'沪美',
|
||||||
'哥伦布',
|
'哥伦布',
|
||||||
'纽约',
|
'纽约',
|
||||||
|
'New York',
|
||||||
'Los Angeles',
|
'Los Angeles',
|
||||||
'San Jose',
|
'San Jose',
|
||||||
'Sillicon Valley',
|
'Sillicon Valley',
|
||||||
'Michigan',
|
'Michigan',
|
||||||
|
'俄亥俄',
|
||||||
|
'Ohio',
|
||||||
|
'马纳萨斯',
|
||||||
|
'Manassas',
|
||||||
|
'弗吉尼亚',
|
||||||
|
'Virginia',
|
||||||
],
|
],
|
||||||
'🇺🇾': ['Uruguay', '乌拉圭'],
|
'🇺🇾': ['Uruguay', '乌拉圭'],
|
||||||
'🇻🇪': ['Venezuela', '委内瑞拉'],
|
'🇻🇪': ['Venezuela', '委内瑞拉'],
|
||||||
@@ -418,8 +438,12 @@ export function getFlag(name) {
|
|||||||
RegExp(`(^|[^a-zA-Z])${keyword}([^a-zA-Z]|$)`).test(name),
|
RegExp(`(^|[^a-zA-Z])${keyword}([^a-zA-Z]|$)`).test(name),
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
//console.log(`ISOFlag = ${flag}`)
|
const isCN2 =
|
||||||
return (Flag = flag);
|
flag == '🇨🇳' &&
|
||||||
|
RegExp(`(^|[^a-zA-Z])CN2([^a-zA-Z]|$)`).test(name);
|
||||||
|
if (!isCN2) {
|
||||||
|
return (Flag = flag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export default class Gist {
|
|||||||
...(isLoon && proxy ? { node: proxy } : {}),
|
...(isLoon && proxy ? { node: proxy } : {}),
|
||||||
...(isQX && proxy ? { opts: { policy: proxy } } : {}),
|
...(isQX && proxy ? { opts: { policy: proxy } } : {}),
|
||||||
...(proxy ? getPolicyDescriptor(proxy) : {}),
|
...(proxy ? getPolicyDescriptor(proxy) : {}),
|
||||||
timeout,
|
timeout: timeout || 8000,
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
onResponse: (resp) => {
|
onResponse: (resp) => {
|
||||||
@@ -81,7 +81,7 @@ export default class Gist {
|
|||||||
...(isLoon && proxy ? { node: proxy } : {}),
|
...(isLoon && proxy ? { node: proxy } : {}),
|
||||||
...(isQX && proxy ? { opts: { policy: proxy } } : {}),
|
...(isQX && proxy ? { opts: { policy: proxy } } : {}),
|
||||||
...(proxy ? getPolicyDescriptor(proxy) : {}),
|
...(proxy ? getPolicyDescriptor(proxy) : {}),
|
||||||
timeout,
|
timeout: timeout || 8000,
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
onResponse: (resp) => {
|
onResponse: (resp) => {
|
||||||
|
|||||||
@@ -2,18 +2,24 @@ export function getUserAgentFromHeaders(headers) {
|
|||||||
const keys = Object.keys(headers);
|
const keys = Object.keys(headers);
|
||||||
let UA = '';
|
let UA = '';
|
||||||
let ua = '';
|
let ua = '';
|
||||||
|
let accept = '';
|
||||||
for (let k of keys) {
|
for (let k of keys) {
|
||||||
if (/USER-AGENT/i.test(k)) {
|
const lower = k.toLowerCase();
|
||||||
|
if (lower === 'user-agent') {
|
||||||
UA = headers[k];
|
UA = headers[k];
|
||||||
ua = UA.toLowerCase();
|
ua = UA.toLowerCase();
|
||||||
break;
|
} else if (lower === 'accept') {
|
||||||
|
accept = headers[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { UA, ua };
|
return { UA, ua, accept };
|
||||||
}
|
}
|
||||||
export function getPlatformFromUserAgent({ ua, UA }) {
|
|
||||||
|
export function getPlatformFromUserAgent({ ua, UA, accept }) {
|
||||||
if (UA.indexOf('Quantumult%20X') !== -1) {
|
if (UA.indexOf('Quantumult%20X') !== -1) {
|
||||||
return 'QX';
|
return 'QX';
|
||||||
|
} else if (ua.indexOf('egern') !== -1) {
|
||||||
|
return 'Egern';
|
||||||
} else if (UA.indexOf('Surfboard') !== -1) {
|
} else if (UA.indexOf('Surfboard') !== -1) {
|
||||||
return 'Surfboard';
|
return 'Surfboard';
|
||||||
} else if (UA.indexOf('Surge Mac') !== -1) {
|
} else if (UA.indexOf('Surge Mac') !== -1) {
|
||||||
@@ -39,11 +45,14 @@ export function getPlatformFromUserAgent({ ua, UA }) {
|
|||||||
return 'V2Ray';
|
return 'V2Ray';
|
||||||
} else if (ua.indexOf('sing-box') !== -1) {
|
} else if (ua.indexOf('sing-box') !== -1) {
|
||||||
return 'sing-box';
|
return 'sing-box';
|
||||||
} else {
|
} else if (accept.indexOf('application/json') === 0) {
|
||||||
return 'JSON';
|
return 'JSON';
|
||||||
|
} else {
|
||||||
|
return 'V2Ray';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPlatformFromHeaders(headers) {
|
export function getPlatformFromHeaders(headers) {
|
||||||
const { UA, ua } = getUserAgentFromHeaders(headers);
|
const { UA, ua, accept } = getUserAgentFromHeaders(headers);
|
||||||
return getPlatformFromUserAgent({ ua, UA });
|
return getPlatformFromUserAgent({ ua, UA, accept });
|
||||||
}
|
}
|
||||||
|
|||||||
1
backend/src/vendor/express.js
vendored
1
backend/src/vendor/express.js
vendored
@@ -9,6 +9,7 @@ export default function express({ substore: $, port, host }) {
|
|||||||
'Access-Control-Allow-Methods': 'POST,GET,OPTIONS,PATCH,PUT,DELETE',
|
'Access-Control-Allow-Methods': 'POST,GET,OPTIONS,PATCH,PUT,DELETE',
|
||||||
'Access-Control-Allow-Headers':
|
'Access-Control-Allow-Headers':
|
||||||
'Origin, X-Requested-With, Content-Type, Accept',
|
'Origin, X-Requested-With, Content-Type, Accept',
|
||||||
|
'X-Powered-By': 'Sub-Store',
|
||||||
};
|
};
|
||||||
|
|
||||||
// node support
|
// node support
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
name: Sub-Store
|
name: Sub-Store
|
||||||
description: "支持 Surge 正式版的参数设置功能. 测落地功能 ability: http-client-policy, 同步配置的定时 cronexp: 55 23 * * *"
|
description: '支持 Surge 正式版的参数设置功能. 测落地功能 ability: http-client-policy, 同步配置的定时 cronexp: 55 23 * * *'
|
||||||
compat_arguments:
|
compat_arguments:
|
||||||
ability: http-client-policy
|
ability: http-client-policy
|
||||||
cronexp: 55 23 * * *
|
cronexp: 55 23 * * *
|
||||||
sync: '"Sub-Store Sync"'
|
sync: '"Sub-Store Sync"'
|
||||||
timeout: "120"
|
timeout: '120'
|
||||||
engine: auto
|
engine: auto
|
||||||
produce: '"# Sub-Store Produce"'
|
produce: '"# Sub-Store Produce"'
|
||||||
produce_cronexp: 50 */6 * * *
|
produce_cronexp: 50 */6 * * *
|
||||||
@@ -12,26 +12,27 @@ compat_arguments:
|
|||||||
produce_col: '"col1,col2"'
|
produce_col: '"col1,col2"'
|
||||||
compat_arguments_desc: '\n1️⃣ ability\n\n默认已开启测落地能力\n需要配合脚本操作\n如 https://raw.githubusercontent.com/Keywos/rule/main/cname.js\n填写任意其他值关闭\n\n2️⃣ cronexp\n\n同步配置定时任务\n默认为每天 23 点 55 分\n\n定时任务指定时将订阅/文件上传到私有 Gist. 在前端, 叫做 ''同步'' 或 ''同步配置''\n\n3️⃣ sync\n\n自定义定时任务名\n便于在脚本编辑器中选择\n若设为 # 可取消定时任务\n\n4️⃣ timeout\n\n脚本超时, 单位为秒\n\n5️⃣ engine\n\n默认为自动使用 webview 引擎, 可设为指定 jsc, 但 jsc 容易爆内存\n\n6️⃣ produce\n\n自定义处理订阅的定时任务名\n一般用于定时处理耗时较长的订阅, 以更新缓存\n这样 Surge 中拉取的时候就能用到缓存, 不至于总是超时\n若设为 # 可取消此定时任务\n默认不开启\n\n7️⃣ produce_cronexp\n\n配置处理订阅的定时任务\n\n默认为每 6 小时\n\n9️⃣ produce_sub\n\n自定义需定时处理的单条订阅名\n多个用 , 连接\n\n🔟 produce_col\n\n自定义需定时处理的组合订阅名\n多个用 , 连接\n\n⚠️ 注意: 是 名称(name) 不是 显示名称(displayName)\n如果名称需要编码, 请编码后再用 , 连接\n顺序: 并发执行单条订阅, 然后并发执行组合订阅'
|
compat_arguments_desc: '\n1️⃣ ability\n\n默认已开启测落地能力\n需要配合脚本操作\n如 https://raw.githubusercontent.com/Keywos/rule/main/cname.js\n填写任意其他值关闭\n\n2️⃣ cronexp\n\n同步配置定时任务\n默认为每天 23 点 55 分\n\n定时任务指定时将订阅/文件上传到私有 Gist. 在前端, 叫做 ''同步'' 或 ''同步配置''\n\n3️⃣ sync\n\n自定义定时任务名\n便于在脚本编辑器中选择\n若设为 # 可取消定时任务\n\n4️⃣ timeout\n\n脚本超时, 单位为秒\n\n5️⃣ engine\n\n默认为自动使用 webview 引擎, 可设为指定 jsc, 但 jsc 容易爆内存\n\n6️⃣ produce\n\n自定义处理订阅的定时任务名\n一般用于定时处理耗时较长的订阅, 以更新缓存\n这样 Surge 中拉取的时候就能用到缓存, 不至于总是超时\n若设为 # 可取消此定时任务\n默认不开启\n\n7️⃣ produce_cronexp\n\n配置处理订阅的定时任务\n\n默认为每 6 小时\n\n9️⃣ produce_sub\n\n自定义需定时处理的单条订阅名\n多个用 , 连接\n\n🔟 produce_col\n\n自定义需定时处理的组合订阅名\n多个用 , 连接\n\n⚠️ 注意: 是 名称(name) 不是 显示名称(displayName)\n如果名称需要编码, 请编码后再用 , 连接\n顺序: 并发执行单条订阅, 然后并发执行组合订阅'
|
||||||
scriptings:
|
scriptings:
|
||||||
- http_request:
|
- http_request:
|
||||||
name: Sub-Store Core
|
name: Sub-Store Core
|
||||||
match: ^https?:\/\/sub\.store\/((download)|api\/(preview|sync|(utils\/node-info)))
|
match: ^https?:\/\/sub\.store\/((download)|api\/(preview|sync|(utils\/node-info)))
|
||||||
script_url: https://raw.githubusercontent.com/sub-store-org/Sub-Store/release/sub-store-1.min.js
|
script_url: https://raw.githubusercontent.com/sub-store-org/Sub-Store/release/sub-store-1.min.js
|
||||||
body_required: true
|
body_required: true
|
||||||
- http_request:
|
- http_request:
|
||||||
name: Sub-Store Simple
|
name: Sub-Store Simple
|
||||||
match: ^https?:\/\/sub\.store
|
match: ^https?:\/\/sub\.store
|
||||||
script_url: https://raw.githubusercontent.com/sub-store-org/Sub-Store/release/sub-store-0.min.js
|
script_url: https://raw.githubusercontent.com/sub-store-org/Sub-Store/release/sub-store-0.min.js
|
||||||
body_required: true
|
body_required: true
|
||||||
- schedule:
|
- schedule:
|
||||||
name: "{{{sync}}}"
|
name: '{{{sync}}}'
|
||||||
cron: "{{{cronexp}}}"
|
cron: '{{{cronexp}}}'
|
||||||
script_url: https://raw.githubusercontent.com/sub-store-org/Sub-Store/release/cron-sync-artifacts.min.js
|
script_url: https://raw.githubusercontent.com/sub-store-org/Sub-Store/release/cron-sync-artifacts.min.js
|
||||||
- schedule:
|
- schedule:
|
||||||
name: "{{{produce}}}"
|
name: '{{{produce}}}'
|
||||||
cron: "{{{produce_cronexp}}}"
|
cron: '{{{produce_cronexp}}}'
|
||||||
script_url: https://raw.githubusercontent.com/sub-store-org/Sub-Store/release/cron-sync-artifacts.min.js
|
script_url: https://raw.githubusercontent.com/sub-store-org/Sub-Store/release/cron-sync-artifacts.min.js
|
||||||
arguments:
|
arguments:
|
||||||
_compat.$argument: '"sub={{{produce_sub}}}&col={{{produce_col}}}"'
|
_compat.$argument: '"sub={{{produce_sub}}}&col={{{produce_col}}}"'
|
||||||
mitm:
|
mitm:
|
||||||
hostnames:
|
hostnames:
|
||||||
|
includes:
|
||||||
- sub.store
|
- sub.store
|
||||||
|
|||||||
@@ -165,6 +165,20 @@ function operator(proxies = [], targetPlatform, context) {
|
|||||||
|
|
||||||
// 若不存在 `source._collection`, 说明输出结果为单条订阅, 脚本设置在此单条订阅上
|
// 若不存在 `source._collection`, 说明输出结果为单条订阅, 脚本设置在此单条订阅上
|
||||||
|
|
||||||
|
// 这个历史遗留原因, 是有点复杂. 提供一个例子, 用来取当前脚本所在的组合订阅或单条订阅名称
|
||||||
|
|
||||||
|
// let name = ''
|
||||||
|
// for (const [key, value] of Object.entries(env.source)) {
|
||||||
|
// if (!key.startsWith('_')) {
|
||||||
|
// name = value.displayName || value.name
|
||||||
|
// break
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (!name) {
|
||||||
|
// const collection = env.source._collection
|
||||||
|
// name = collection.displayName || collection.name
|
||||||
|
// }
|
||||||
|
|
||||||
// 1. 输出单条订阅 sub-1 时, 该单条订阅中的脚本上下文为:
|
// 1. 输出单条订阅 sub-1 时, 该单条订阅中的脚本上下文为:
|
||||||
// {
|
// {
|
||||||
// "source": {
|
// "source": {
|
||||||
|
|||||||
Reference in New Issue
Block a user