From 0b92c578b5302d1f23a6cfea334736fa9fe47221 Mon Sep 17 00:00:00 2001 From: zuiwuchang Date: Thu, 7 Dec 2023 13:42:46 +0800 Subject: [PATCH] grpc --- bin/js/main.js | 1 - bin/js/metadata/i18n.js | 3 ++ bin/js/metadata/trojan.js | 48 ++++++++++++++++++++++++---- bin/js/metadata/vless.js | 13 ++++++-- bin/js/metadata/vmess.js | 2 +- bin/js/xray/outbounds.js | 18 ++++++++++- bin/ts/main.ts | 1 - bin/ts/metadata/i18n.ts | 3 ++ bin/ts/metadata/trojan.ts | 57 +++++++++++++++++++++++++++++----- bin/ts/metadata/vless.ts | 17 ++++++++-- bin/ts/metadata/vmess.ts | 2 +- bin/ts/xray/outbounds.ts | 16 +++++++++- bin/ts/xray/transport/grpc.ts | 5 ++- view/src/app/app/home/steps.ts | 13 +++++++- 14 files changed, 174 insertions(+), 25 deletions(-) diff --git a/bin/js/main.js b/bin/js/main.js index e2300bb..ff3d02e 100644 --- a/bin/js/main.js +++ b/bin/js/main.js @@ -143,7 +143,6 @@ ${s} * 返回 xray 設定 */ configure(opts) { - core.println(JSON.stringify(opts.fileds, undefined, " ")); let ips; let ip; const address = opts.fileds.address; diff --git a/bin/js/metadata/i18n.js b/bin/js/metadata/i18n.js index 71f90db..2437dce 100644 --- a/bin/js/metadata/i18n.js +++ b/bin/js/metadata/i18n.js @@ -73,6 +73,9 @@ exports.i18n = { 'zh-Hans': '指纹', 'default': 'Fingerprint', }, + grpcMode: { + 'default': 'grpc mode', + }, encryption: { 'zh-Hant': '加密方式', 'zh-Hans': '加密方式', diff --git a/bin/js/metadata/trojan.js b/bin/js/metadata/trojan.js index cba3116..6ee4cfd 100644 --- a/bin/js/metadata/trojan.js +++ b/bin/js/metadata/trojan.js @@ -58,12 +58,33 @@ exports.trojan = { key: 'host', label: i18n_1.i18n.host, ui: 'text', - class: 'col-12 md:col-6', + class: 'col-12 md:col-4', from: { from: 'query', key: 'host', }, }, + { + // url path + key: 'path', + label: i18n_1.i18n.path, + ui: 'text', + class: 'col-12 md:col-4', + from: { + from: 'query', + key: 'path', + }, + alias: [ + { + key: 'protocol', + value: 'grpc', + from: { + from: 'query', + key: 'serviceName', + } + } + ], + }, { // 傳輸層加密 key: 'security', @@ -72,7 +93,7 @@ exports.trojan = { value: [ 'xtls', 'tls', 'reality', ], - class: 'col-12 md:col-6', + class: 'col-12 md:col-4', from: { from: 'query', key: 'security', @@ -84,7 +105,7 @@ exports.trojan = { key: 'userID', label: i18n_1.i18n.userID, ui: 'text', - class: 'col-12 md:col-6', + class: 'col-12 md:col-4', from: { from: 'username', }, @@ -94,7 +115,7 @@ exports.trojan = { key: 'flow', label: i18n_1.i18n.flow, ui: 'select-editable', - class: 'col-12 md:col-6', + class: 'col-12 md:col-4', value: [ 'none', 'xtls-rprx-vision', 'xtls-rprx-vision-udp443' ], @@ -103,13 +124,17 @@ exports.trojan = { key: 'flow', }, }, + { + ui: 'placeholder', + class: 'p-0 col-fixed md:col-4', + }, // row { key: 'alpn', label: i18n_1.i18n.alpn, ui: 'select-editable', value: ['', 'h2', 'http/1.1', 'h2,http/1.1'], - class: 'col-12 md:col-6', + class: 'col-12 md:col-4', from: { from: 'query', key: 'alpn', @@ -120,11 +145,22 @@ exports.trojan = { label: i18n_1.i18n.fingerprint, ui: 'select-editable', value: ['', 'chrome', 'firefox', 'safari', 'ios', 'android', 'edge', '360', 'qq', 'random', 'randomized'], - class: 'col-12 md:col-6', + class: 'col-12 md:col-4', from: { from: 'query', key: 'fp', }, }, + { + key: 'mode', + label: i18n_1.i18n.grpcMode, + ui: 'select', + value: ['', 'gun', 'multi'], + class: 'col-12 md:col-4', + from: { + from: 'query', + key: 'mode', + }, + }, ], }; diff --git a/bin/js/metadata/vless.js b/bin/js/metadata/vless.js index 999f906..4eb65aa 100644 --- a/bin/js/metadata/vless.js +++ b/bin/js/metadata/vless.js @@ -162,8 +162,17 @@ exports.vless = { }, }, { - ui: 'placeholder', - class: 'p-0 col-fixed md:col-4', + key: 'mode', + label: i18n_1.i18n.grpcMode, + ui: 'select', + value: ['', 'gun', 'multi'], + class: 'col-12 md:col-4', + from: { + from: 'query', + key: 'mode', + }, + // ui: 'placeholder', + // class: 'p-0 col-fixed md:col-4', }, // row { diff --git a/bin/js/metadata/vmess.js b/bin/js/metadata/vmess.js index 8b89864..ce2a97c 100644 --- a/bin/js/metadata/vmess.js +++ b/bin/js/metadata/vmess.js @@ -46,7 +46,7 @@ exports.vmess = { label: i18n_1.i18n.protocol, ui: 'select-editable', value: [ - 'tcp', 'ws', 'quic', 'kcp', 'http', 'grpc', + 'tcp', 'ws', 'quic', 'kcp', 'http', ], class: 'col-12 md:col-4', from: { diff --git a/bin/js/xray/outbounds.js b/bin/js/xray/outbounds.js index 64ea0c0..dab1434 100644 --- a/bin/js/xray/outbounds.js +++ b/bin/js/xray/outbounds.js @@ -266,7 +266,8 @@ class OutboundStream { case 'grpc': result.network = 'grpc'; result.grpcSettings = { - serviceName: this._serverName(), + serviceName: this._serviceName(), + multiMode: this._multiMode(), idle_timeout: 40, }; break; @@ -281,6 +282,21 @@ class OutboundStream { } return result; } + _multiMode() { + var _a; + const fileds = this.opts.fileds; + const val = (_a = fileds.mode) !== null && _a !== void 0 ? _a : ''; + return val == 'multi'; + } + _serviceName() { + var _a; + const fileds = this.opts.fileds; + const val = (_a = fileds.path) !== null && _a !== void 0 ? _a : ''; + if (val != '') { + return val; + } + return ''; + } _path() { var _a; const fileds = this.opts.fileds; diff --git a/bin/ts/main.ts b/bin/ts/main.ts index 8322bc0..9859029 100644 --- a/bin/ts/main.ts +++ b/bin/ts/main.ts @@ -112,7 +112,6 @@ ${s} * 返回 xray 設定 */ configure(opts: ConfigureOptions): ConfigureResult { - core.println(JSON.stringify(opts.fileds, undefined, " ")) let ips: undefined | Array let ip: undefined | string const address = opts.fileds.address! diff --git a/bin/ts/metadata/i18n.ts b/bin/ts/metadata/i18n.ts index 19a4a68..0c39888 100644 --- a/bin/ts/metadata/i18n.ts +++ b/bin/ts/metadata/i18n.ts @@ -70,6 +70,9 @@ export const i18n = { 'zh-Hans': '指纹', 'default': 'Fingerprint', }, + grpcMode: { + 'default': 'grpc mode', + }, encryption: { 'zh-Hant': '加密方式', 'zh-Hans': '加密方式', diff --git a/bin/ts/metadata/trojan.ts b/bin/ts/metadata/trojan.ts index 55cd59b..5ce5ae1 100644 --- a/bin/ts/metadata/trojan.ts +++ b/bin/ts/metadata/trojan.ts @@ -57,12 +57,33 @@ export const trojan: Metadata = { key: 'host', label: i18n.host, ui: 'text', - class: 'col-12 md:col-6', + class: 'col-12 md:col-4', from: { from: 'query', key: 'host', }, }, + { + // url path + key: 'path', + label: i18n.path, + ui: 'text', + class: 'col-12 md:col-4', + from: { + from: 'query', + key: 'path', + }, + alias: [ + { + key: 'protocol', + value: 'grpc', + from: { + from: 'query', + key: 'serviceName', + } + } + ], + }, { // 傳輸層加密 key: 'security', @@ -71,7 +92,7 @@ export const trojan: Metadata = { value: [ 'xtls', 'tls', 'reality', ], - class: 'col-12 md:col-6', + class: 'col-12 md:col-4', from: { from: 'query', key: 'security', @@ -84,7 +105,7 @@ export const trojan: Metadata = { key: 'userID', label: i18n.userID, ui: 'text', - class: 'col-12 md:col-6', + class: 'col-12 md:col-4', from: { from: 'username', }, @@ -94,7 +115,7 @@ export const trojan: Metadata = { key: 'flow', label: i18n.flow, ui: 'select-editable', - class: 'col-12 md:col-6', + class: 'col-12 md:col-4', value: [ 'none', 'xtls-rprx-vision', 'xtls-rprx-vision-udp443' ], @@ -103,14 +124,17 @@ export const trojan: Metadata = { key: 'flow', }, }, - + { + ui: 'placeholder', + class: 'p-0 col-fixed md:col-4', + }, // row { key: 'alpn', label: i18n.alpn, ui: 'select-editable', value: ['', 'h2', 'http/1.1', 'h2,http/1.1'], - class: 'col-12 md:col-6', + class: 'col-12 md:col-4', from: { from: 'query', key: 'alpn', @@ -121,12 +145,23 @@ export const trojan: Metadata = { label: i18n.fingerprint, ui: 'select-editable', value: ['', 'chrome', 'firefox', 'safari', 'ios', 'android', 'edge', '360', 'qq', 'random', 'randomized'], - class: 'col-12 md:col-6', + class: 'col-12 md:col-4', from: { from: 'query', key: 'fp', }, }, + { + key: 'mode', + label: i18n.grpcMode, + ui: 'select', + value: ['', 'gun', 'multi'], + class: 'col-12 md:col-4', + from: { + from: 'query', + key: 'mode', + }, + }, ], } @@ -147,6 +182,10 @@ export interface TrojanFileds { * 主機名稱 */ host?: string + /** + * url path,只在 grpc 時有效 + */ + path?: string /** * 傳輸層加密 */ @@ -162,4 +201,8 @@ export interface TrojanFileds { alpn?: string fingerprint?: string + /** + * grpc 模式 + */ + mode?: string } \ No newline at end of file diff --git a/bin/ts/metadata/vless.ts b/bin/ts/metadata/vless.ts index c795fa4..477a710 100644 --- a/bin/ts/metadata/vless.ts +++ b/bin/ts/metadata/vless.ts @@ -162,8 +162,17 @@ export const vless: Metadata = { }, }, { - ui: 'placeholder', - class: 'p-0 col-fixed md:col-4', + key: 'mode', + label: i18n.grpcMode, + ui: 'select', + value: ['', 'gun', 'multi'], + class: 'col-12 md:col-4', + from: { + from: 'query', + key: 'mode', + }, + // ui: 'placeholder', + // class: 'p-0 col-fixed md:col-4', }, // row { @@ -240,6 +249,10 @@ export interface VLessFileds { alpn?: string fingerprint?: string + /** + * grpc 模式 + */ + mode?: string publicKey?: string shortID?: string diff --git a/bin/ts/metadata/vmess.ts b/bin/ts/metadata/vmess.ts index 05def95..1c5db54 100644 --- a/bin/ts/metadata/vmess.ts +++ b/bin/ts/metadata/vmess.ts @@ -45,7 +45,7 @@ export const vmess: Metadata = { label: i18n.protocol, ui: 'select-editable', value: [ - 'tcp', 'ws', 'quic', 'kcp', 'http', 'grpc', + 'tcp', 'ws', 'quic', 'kcp', 'http', ], class: 'col-12 md:col-4', from: { diff --git a/bin/ts/xray/outbounds.ts b/bin/ts/xray/outbounds.ts index 2e0cbdf..b084fc7 100644 --- a/bin/ts/xray/outbounds.ts +++ b/bin/ts/xray/outbounds.ts @@ -281,7 +281,8 @@ class OutboundStream { case 'grpc': result.network = 'grpc'; (result as GRPCStream).grpcSettings = { - serviceName: this._serverName(), + serviceName: this._serviceName(), + multiMode: this._multiMode(), idle_timeout: 40, } break @@ -296,6 +297,19 @@ class OutboundStream { } return result } + private _multiMode(): boolean { + const fileds = this.opts.fileds + const val = fileds.mode ?? '' + return val == 'multi' + } + private _serviceName(): string { + const fileds = this.opts.fileds + const val = fileds.path ?? '' + if (val != '') { + return val + } + return '' + } private _path(): string { const fileds = this.opts.fileds const val = fileds.path ?? '' diff --git a/bin/ts/xray/transport/grpc.ts b/bin/ts/xray/transport/grpc.ts index 48260d9..65d7381 100644 --- a/bin/ts/xray/transport/grpc.ts +++ b/bin/ts/xray/transport/grpc.ts @@ -8,7 +8,10 @@ export interface GRPC { * 指定一個服務名稱,只需在出棧中配置 */ serviceName?: string - + /** + * 不穩定的測試屬性 + */ + multiMode?: boolean /** * 設定 gRPC 的用戶代理,可能能防止某些 CDN 阻止 gRPC 流量 */ diff --git a/view/src/app/app/home/steps.ts b/view/src/app/app/home/steps.ts index f766669..85c20d0 100644 --- a/view/src/app/app/home/steps.ts +++ b/view/src/app/app/home/steps.ts @@ -413,7 +413,9 @@ export class MetadataProvider { if (!json) { json = {} } - json[from.key ?? ''] = value + if (value != '') { + json[from.key ?? ''] = value + } break } } @@ -426,6 +428,15 @@ export class MetadataProvider { u.user = new Userinfo(Base64.encode(`${base64name}:${base64password}`)) } if (query.length != 0) { + const deleted = new Array() + for (const [k, _] of query.m) { + if (query.get(k) == '') { + deleted.push(k) + } + } + for (const k of deleted) { + query.del(k) + } u.rawQuery = query.encode() } if (fragment != '') {