From 566cd9e9c4b7f10f19b7eb647c6c7cad4647ac44 Mon Sep 17 00:00:00 2001 From: mhsanaei Date: Mon, 16 Sep 2024 11:41:21 +0200 Subject: [PATCH] New - Allocate --- database/model/model.go | 2 ++ sub/default.json | 1 + web/assets/js/model/xray.js | 26 ++++++++++++++++++++++++++ web/html/xui/form/allocate.html | 16 ++++++++++++++++ web/html/xui/form/inbound.html | 6 ++++++ web/html/xui/form/sniffing.html | 2 +- web/html/xui/inbounds.html | 3 +++ web/service/inbound.go | 1 + xray/inbound.go | 4 ++++ 9 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 web/html/xui/form/allocate.html diff --git a/database/model/model.go b/database/model/model.go index 402565b6..9893776d 100644 --- a/database/model/model.go +++ b/database/model/model.go @@ -46,6 +46,7 @@ type Inbound struct { StreamSettings string `json:"streamSettings" form:"streamSettings"` Tag string `json:"tag" form:"tag" gorm:"unique"` Sniffing string `json:"sniffing" form:"sniffing"` + Allocate string `json:"allocate" form:"allocate"` } type OutboundTraffics struct { @@ -75,6 +76,7 @@ func (i *Inbound) GenXrayInboundConfig() *xray.InboundConfig { StreamSettings: json_util.RawMessage(i.StreamSettings), Tag: i.Tag, Sniffing: json_util.RawMessage(i.Sniffing), + Allocate: json_util.RawMessage(i.Allocate), } } diff --git a/sub/default.json b/sub/default.json index d98a03ef..32948c77 100644 --- a/sub/default.json +++ b/sub/default.json @@ -23,6 +23,7 @@ "destOverride": [ "http", "tls", + "quic", "fakedns" ], "enabled": true diff --git a/web/assets/js/model/xray.js b/web/assets/js/model/xray.js index 8b7fca28..3710ec6e 100644 --- a/web/assets/js/model/xray.js +++ b/web/assets/js/model/xray.js @@ -1197,6 +1197,27 @@ class Sniffing extends XrayCommonClass { } } +class Allocate extends XrayCommonClass { + constructor( + strategy = "always", + refresh = 5, + concurrency = 3, + ) { + super(); + this.strategy = strategy; + this.refresh = refresh; + this.concurrency = concurrency; + } + + static fromJson(json = {}) { + return new Allocate( + json.strategy, + json.refresh, + json.concurrency, + ); + } +} + class Inbound extends XrayCommonClass { constructor( port = RandomUtil.randomIntRange(10000, 60000), @@ -1206,6 +1227,7 @@ class Inbound extends XrayCommonClass { streamSettings = new StreamSettings(), tag = '', sniffing = new Sniffing(), + allocate = new Allocate(), clientStats = '', ) { super(); @@ -1216,6 +1238,7 @@ class Inbound extends XrayCommonClass { this.stream = streamSettings; this.tag = tag; this.sniffing = sniffing; + this.allocate = allocate; this.clientStats = clientStats; } getClientStats() { @@ -1406,6 +1429,7 @@ class Inbound extends XrayCommonClass { this.stream = new StreamSettings(); this.tag = ''; this.sniffing = new Sniffing(); + this.allocate = new Allocate(); } genVmessLink(address = '', port = this.port, forceTls, remark = '', clientId, security) { @@ -1885,6 +1909,7 @@ class Inbound extends XrayCommonClass { StreamSettings.fromJson(json.streamSettings), json.tag, Sniffing.fromJson(json.sniffing), + Allocate.fromJson(json.allocate), json.clientStats ) } @@ -1902,6 +1927,7 @@ class Inbound extends XrayCommonClass { streamSettings: streamSettings, tag: this.tag, sniffing: this.sniffing.toJson(), + allocate: this.allocate.toJson(), clientStats: this.clientStats }; } diff --git a/web/html/xui/form/allocate.html b/web/html/xui/form/allocate.html new file mode 100644 index 00000000..8c19d3ec --- /dev/null +++ b/web/html/xui/form/allocate.html @@ -0,0 +1,16 @@ +{{define "form/allocate"}} +Allocate + + + + [[ s ]] + + + + + + + + + +{{end}} diff --git a/web/html/xui/form/inbound.html b/web/html/xui/form/inbound.html index c0ae1998..2930b7be 100644 --- a/web/html/xui/form/inbound.html +++ b/web/html/xui/form/inbound.html @@ -118,4 +118,10 @@ + + + + {{end}} diff --git a/web/html/xui/form/sniffing.html b/web/html/xui/form/sniffing.html index f4230dd1..23dfea65 100644 --- a/web/html/xui/form/sniffing.html +++ b/web/html/xui/form/sniffing.html @@ -1,5 +1,5 @@ {{define "form/sniffing"}} - +Sniffing diff --git a/web/html/xui/inbounds.html b/web/html/xui/inbounds.html index f27be794..e93a0a1d 100644 --- a/web/html/xui/inbounds.html +++ b/web/html/xui/inbounds.html @@ -935,6 +935,7 @@ settings: Inbound.Settings.getSettings(baseInbound.protocol).toString(), streamSettings: baseInbound.stream.toString(), sniffing: baseInbound.sniffing.toString(), + allocate: baseInbound.allocate.toString(), }; await this.submit('/panel/inbound/add', data, inModal); }, @@ -980,6 +981,7 @@ }; if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString(); data.sniffing = inbound.sniffing.toString(); + data.allocate = inbound.allocate.toString(); await this.submit('/panel/inbound/add', data, inModal); }, @@ -999,6 +1001,7 @@ }; if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString(); data.sniffing = inbound.sniffing.toString(); + data.allocate = inbound.allocate.toString(); await this.submit(`/panel/inbound/update/${dbInbound.id}`, data, inModal); }, diff --git a/web/service/inbound.go b/web/service/inbound.go index 0ed76880..5213fce6 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -331,6 +331,7 @@ func (s *InboundService) UpdateInbound(inbound *model.Inbound) (*model.Inbound, oldInbound.Settings = inbound.Settings oldInbound.StreamSettings = inbound.StreamSettings oldInbound.Sniffing = inbound.Sniffing + oldInbound.Allocate = inbound.Allocate if inbound.Listen == "" || inbound.Listen == "0.0.0.0" || inbound.Listen == "::" || inbound.Listen == "::0" { oldInbound.Tag = fmt.Sprintf("inbound-%v", inbound.Port) } else { diff --git a/xray/inbound.go b/xray/inbound.go index ea11449d..c74b07ba 100644 --- a/xray/inbound.go +++ b/xray/inbound.go @@ -14,6 +14,7 @@ type InboundConfig struct { StreamSettings json_util.RawMessage `json:"streamSettings"` Tag string `json:"tag"` Sniffing json_util.RawMessage `json:"sniffing"` + Allocate json_util.RawMessage `json:"allocate"` } func (c *InboundConfig) Equals(other *InboundConfig) bool { @@ -38,5 +39,8 @@ func (c *InboundConfig) Equals(other *InboundConfig) bool { if !bytes.Equal(c.Sniffing, other.Sniffing) { return false } + if !bytes.Equal(c.Allocate, other.Allocate) { + return false + } return true }