From af5d681c2294654c701d1af88a65111a04ea8d4d Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Fri, 25 Aug 2023 20:26:59 +0200 Subject: [PATCH] Transparent Proxy with sockopt Stream Setting --- web/assets/js/model/xray.js | 40 ++++++++++++++++ web/html/xui/form/stream/stream_settings.html | 4 ++ web/html/xui/form/stream/stream_sockopt.html | 46 +++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 web/html/xui/form/stream/stream_sockopt.html diff --git a/web/assets/js/model/xray.js b/web/assets/js/model/xray.js index 4b391dfa..08720165 100644 --- a/web/assets/js/model/xray.js +++ b/web/assets/js/model/xray.js @@ -676,6 +676,34 @@ RealityStreamSettings.Settings = class extends XrayCommonClass { } }; +class SockoptStreamSettings extends XrayCommonClass { + constructor(acceptProxyProtocol = false, tcpFastOpen = false, mark = 0, tproxy="off") { + super(); + this.acceptProxyProtocol = acceptProxyProtocol; + this.tcpFastOpen = tcpFastOpen; + this.mark = mark; + this.tproxy = tproxy; + } + + static fromJson(json = {}) { + return new SockoptStreamSettings( + json.acceptProxyProtocol, + json.tcpFastOpen, + json.mark, + json.tproxy, + ); + } + + toJson() { + return { + acceptProxyProtocol: this.acceptProxyProtocol, + tcpFastOpen: this.tcpFastOpen, + mark: this.mark, + tproxy: this.tproxy, + }; + } +} + class StreamSettings extends XrayCommonClass { constructor(network='tcp', security='none', @@ -687,6 +715,7 @@ class StreamSettings extends XrayCommonClass { httpSettings=new HttpStreamSettings(), quicSettings=new QuicStreamSettings(), grpcSettings=new GrpcStreamSettings(), + sockopt = undefined, ) { super(); this.network = network; @@ -699,6 +728,7 @@ class StreamSettings extends XrayCommonClass { this.http = httpSettings; this.quic = quicSettings; this.grpc = grpcSettings; + this.sockopt = sockopt; } get isTls() { @@ -725,6 +755,14 @@ class StreamSettings extends XrayCommonClass { } } + get sockoptSwitch() { + return this.sockopt != undefined; + } + + set sockoptSwitch(value) { + this.sockopt = value ? new SockoptStreamSettings() : undefined; + } + static fromJson(json={}) { return new StreamSettings( @@ -738,6 +776,7 @@ class StreamSettings extends XrayCommonClass { HttpStreamSettings.fromJson(json.httpSettings), QuicStreamSettings.fromJson(json.quicSettings), GrpcStreamSettings.fromJson(json.grpcSettings), + SockoptStreamSettings.fromJson(json.sockopt), ); } @@ -754,6 +793,7 @@ class StreamSettings extends XrayCommonClass { httpSettings: network === 'http' ? this.http.toJson() : undefined, quicSettings: network === 'quic' ? this.quic.toJson() : undefined, grpcSettings: network === 'grpc' ? this.grpc.toJson() : undefined, + sockopt: this.sockopt != undefined ? this.sockopt.toJson() : undefined, }; } } diff --git a/web/html/xui/form/stream/stream_settings.html b/web/html/xui/form/stream/stream_settings.html index e2398b15..a78f283b 100644 --- a/web/html/xui/form/stream/stream_settings.html +++ b/web/html/xui/form/stream/stream_settings.html @@ -43,4 +43,8 @@ + + {{end}} \ No newline at end of file diff --git a/web/html/xui/form/stream/stream_sockopt.html b/web/html/xui/form/stream/stream_sockopt.html new file mode 100644 index 00000000..d90bf206 --- /dev/null +++ b/web/html/xui/form/stream/stream_sockopt.html @@ -0,0 +1,46 @@ +{{define "form/streamSockopt"}} + + + + + + + + + + + + + + + + + + + + + +
Accept Proxy Protocol + + + +
TCP FastOpen + + + +
Route Mark + + + +
T-Proxy + + + OFF + Redirect + T-Proxy + + +
+
+{{end}} \ No newline at end of file