From 9e3e4c6e46d6f5002eae571f1f428894eb1af102 Mon Sep 17 00:00:00 2001 From: xream Date: Sun, 1 Oct 2023 22:05:51 +0800 Subject: [PATCH] =?UTF-8?q?[+]=20Surge=20=E8=BE=93=E5=87=BA=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20underlying-proxy;=20VMess/Vless=20URI=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20gRPC=20mode(=E9=BB=98=E8=AE=A4=E4=B8=BA=20gun)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/core/proxy-utils/parsers/index.js | 21 ++++++-- .../src/core/proxy-utils/producers/clash.js | 6 +++ .../core/proxy-utils/producers/clashmeta.js | 6 +++ .../proxy-utils/producers/shadowrocket.js | 6 +++ .../src/core/proxy-utils/producers/stash.js | 6 +++ .../src/core/proxy-utils/producers/surge.js | 53 +++++++++++++++++-- backend/src/core/proxy-utils/producers/uri.js | 16 ++++++ 8 files changed, 107 insertions(+), 9 deletions(-) diff --git a/backend/package.json b/backend/package.json index d861f26..6d4e6eb 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.60", + "version": "2.14.61", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/parsers/index.js b/backend/src/core/proxy-utils/parsers/index.js index c32df1a..560251c 100644 --- a/backend/src/core/proxy-utils/parsers/index.js +++ b/backend/src/core/proxy-utils/parsers/index.js @@ -267,6 +267,8 @@ function URI_VMess() { params.obfs === 'http' ) { proxy.network = 'http'; + } else if (['grpc'].includes(params.net)) { + proxy.network = 'grpc'; } if (proxy.network) { let transportHost = params.host ?? params.obfsParam; @@ -285,10 +287,17 @@ function URI_VMess() { } } if (transportPath || transportHost) { - proxy[`${proxy.network}-opts`] = { - path: getIfNotBlank(transportPath), - headers: { Host: getIfNotBlank(transportHost) }, - }; + if (['grpc'].includes(proxy.network)) { + proxy[`${proxy.network}-opts`] = { + 'grpc-service-name': getIfNotBlank(transportPath), + '_grpc-type': getIfNotBlank(params.type), + }; + } else { + proxy[`${proxy.network}-opts`] = { + path: getIfNotBlank(transportPath), + headers: { Host: getIfNotBlank(transportHost) }, + }; + } } else { delete proxy.network; } @@ -365,6 +374,10 @@ function URI_VLESS() { if (params.serviceName) { opts[`${proxy.network}-service-name`] = params.serviceName; } + // https://github.com/XTLS/Xray-core/issues/91 + if (['grpc'].includes(proxy.network)) { + opts['_grpc-type'] = params.mode || 'gun'; + } if (Object.keys(opts).length > 0) { proxy[`${proxy.network}-opts`] = opts; } diff --git a/backend/src/core/proxy-utils/producers/clash.js b/backend/src/core/proxy-utils/producers/clash.js index 3571dd3..afebfae 100644 --- a/backend/src/core/proxy-utils/producers/clash.js +++ b/backend/src/core/proxy-utils/producers/clash.js @@ -98,6 +98,12 @@ export default function Clash_Producer() { delete proxy.tls; } delete proxy['tls-fingerprint']; + if ( + ['grpc'].includes(proxy.network) && + proxy[`${proxy.network}-opts`] + ) { + delete proxy[`${proxy.network}-opts`]['_grpc-type']; + } return ' - ' + JSON.stringify(proxy) + '\n'; }) .join('') diff --git a/backend/src/core/proxy-utils/producers/clashmeta.js b/backend/src/core/proxy-utils/producers/clashmeta.js index 7d0573c..a55c628 100644 --- a/backend/src/core/proxy-utils/producers/clashmeta.js +++ b/backend/src/core/proxy-utils/producers/clashmeta.js @@ -117,6 +117,12 @@ export default function ClashMeta_Producer() { } delete proxy['tls-fingerprint']; + if ( + ['grpc'].includes(proxy.network) && + proxy[`${proxy.network}-opts`] + ) { + delete proxy[`${proxy.network}-opts`]['_grpc-type']; + } return ' - ' + JSON.stringify(proxy) + '\n'; }) .join('') diff --git a/backend/src/core/proxy-utils/producers/shadowrocket.js b/backend/src/core/proxy-utils/producers/shadowrocket.js index 458544a..583fba9 100644 --- a/backend/src/core/proxy-utils/producers/shadowrocket.js +++ b/backend/src/core/proxy-utils/producers/shadowrocket.js @@ -117,6 +117,12 @@ export default function ShadowRocket_Producer() { } delete proxy['tls-fingerprint']; + if ( + ['grpc'].includes(proxy.network) && + proxy[`${proxy.network}-opts`] + ) { + delete proxy[`${proxy.network}-opts`]['_grpc-type']; + } return ' - ' + JSON.stringify(proxy) + '\n'; }) .join('') diff --git a/backend/src/core/proxy-utils/producers/stash.js b/backend/src/core/proxy-utils/producers/stash.js index e641a4c..ec1a6ca 100644 --- a/backend/src/core/proxy-utils/producers/stash.js +++ b/backend/src/core/proxy-utils/producers/stash.js @@ -128,6 +128,12 @@ export default function Stash_Producer() { delete proxy.tls; } delete proxy['tls-fingerprint']; + if ( + ['grpc'].includes(proxy.network) && + proxy[`${proxy.network}-opts`] + ) { + delete proxy[`${proxy.network}-opts`]['_grpc-type']; + } return ' - ' + JSON.stringify(proxy) + '\n'; }) .join('') diff --git a/backend/src/core/proxy-utils/producers/surge.js b/backend/src/core/proxy-utils/producers/surge.js index bd7601d..dfdaa6b 100644 --- a/backend/src/core/proxy-utils/producers/surge.js +++ b/backend/src/core/proxy-utils/producers/surge.js @@ -71,6 +71,12 @@ function shadowsocks(proxy) { // test-url result.appendIfPresent(`,test-url=${proxy['test-url']}`, 'test-url'); + // underlying-proxy + result.appendIfPresent( + `,underlying-proxy=${proxy['underlying-proxy']}`, + 'underlying-proxy', + ); + return result.toString(); } @@ -107,6 +113,12 @@ function trojan(proxy) { // test-url result.appendIfPresent(`,test-url=${proxy['test-url']}`, 'test-url'); + // underlying-proxy + result.appendIfPresent( + `,underlying-proxy=${proxy['underlying-proxy']}`, + 'underlying-proxy', + ); + return result.toString(); } @@ -150,6 +162,12 @@ function vmess(proxy) { // test-url result.appendIfPresent(`,test-url=${proxy['test-url']}`, 'test-url'); + // underlying-proxy + result.appendIfPresent( + `,underlying-proxy=${proxy['underlying-proxy']}`, + 'underlying-proxy', + ); + return result.toString(); } @@ -182,6 +200,12 @@ function http(proxy) { // test-url result.appendIfPresent(`,test-url=${proxy['test-url']}`, 'test-url'); + // underlying-proxy + result.appendIfPresent( + `,underlying-proxy=${proxy['underlying-proxy']}`, + 'underlying-proxy', + ); + return result.toString(); } @@ -216,6 +240,12 @@ function socks5(proxy) { // test-url result.appendIfPresent(`,test-url=${proxy['test-url']}`, 'test-url'); + // underlying-proxy + result.appendIfPresent( + `,underlying-proxy=${proxy['underlying-proxy']}`, + 'underlying-proxy', + ); + return result.toString(); } @@ -245,6 +275,12 @@ function snell(proxy) { // test-url result.appendIfPresent(`,test-url=${proxy['test-url']}`, 'test-url'); + // underlying-proxy + result.appendIfPresent( + `,underlying-proxy=${proxy['underlying-proxy']}`, + 'underlying-proxy', + ); + // reuse result.appendIfPresent(`,reuse=${proxy['reuse']}`, 'reuse'); @@ -288,6 +324,12 @@ function tuic(proxy) { // test-url result.appendIfPresent(`,test-url=${proxy['test-url']}`, 'test-url'); + // underlying-proxy + result.appendIfPresent( + `,underlying-proxy=${proxy['underlying-proxy']}`, + 'underlying-proxy', + ); + return result.toString(); } @@ -304,10 +346,7 @@ function wireguard(proxy) { `,no-error-alert=${proxy['no-error-alert']}`, 'no-error-alert', ); - result.appendIfPresent( - `,underlying-proxy=${proxy['underlying-proxy']}`, - 'underlying-proxy', - ); + result.appendIfPresent( `,ip-version=${ipVersions[proxy['ip-version']] || proxy['ip-version']}`, 'ip-version', @@ -316,6 +355,12 @@ function wireguard(proxy) { // test-url result.appendIfPresent(`,test-url=${proxy['test-url']}`, 'test-url'); + // underlying-proxy + result.appendIfPresent( + `,underlying-proxy=${proxy['underlying-proxy']}`, + 'underlying-proxy', + ); + return result.toString(); } diff --git a/backend/src/core/proxy-utils/producers/uri.js b/backend/src/core/proxy-utils/producers/uri.js index 34b6234..03fc87e 100644 --- a/backend/src/core/proxy-utils/producers/uri.js +++ b/backend/src/core/proxy-utils/producers/uri.js @@ -91,6 +91,16 @@ export default function URI_Producer() { ? vmessTransportHost[0] : vmessTransportHost; } + if (['grpc'].includes(proxy.network)) { + result.path = + proxy[`${proxy.network}-opts`]?.[ + 'grpc-service-name' + ]; + // https://github.com/XTLS/Xray-core/issues/91 + result.type = + proxy[`${proxy.network}-opts`]?.['_grpc-type'] || + 'gun'; + } } result = 'vmess://' + Base64.encode(JSON.stringify(result)); break; @@ -141,6 +151,12 @@ export default function URI_Producer() { let vlessTransport = `&type=${encodeURIComponent( proxy.network, )}`; + if (['grpc'].includes(proxy.network)) { + // https://github.com/XTLS/Xray-core/issues/91 + vlessTransport += `&mode=${encodeURIComponent( + proxy[`${proxy.network}-opts`]?.['_grpc-type'] || 'gun', + )}`; + } let vlessTransportServiceName = proxy[`${proxy.network}-opts`]?.[