diff --git a/sub/sub.go b/sub/sub.go index dc8e9c5e..87808761 100644 --- a/sub/sub.go +++ b/sub/sub.go @@ -92,9 +92,9 @@ func (s *Server) initRouter() (*gin.Engine, error) { SubJsonFragment = "" } - SubJsonNoise, err := s.settingService.GetSubJsonNoise() + SubJsonNoises, err := s.settingService.GetSubJsonNoises() if err != nil { - SubJsonNoise = "" + SubJsonNoises = "" } SubJsonMux, err := s.settingService.GetSubJsonMux() @@ -111,7 +111,7 @@ func (s *Server) initRouter() (*gin.Engine, error) { s.sub = NewSUBController( g, LinksPath, JsonPath, Encrypt, ShowInfo, RemarkModel, SubUpdates, - SubJsonFragment, SubJsonNoise, SubJsonMux, SubJsonRules) + SubJsonFragment, SubJsonNoises, SubJsonMux, SubJsonRules) return engine, nil } diff --git a/sub/subJsonService.go b/sub/subJsonService.go index 9ffaa4a0..5f994d87 100644 --- a/sub/subJsonService.go +++ b/sub/subJsonService.go @@ -21,14 +21,14 @@ type SubJsonService struct { configJson map[string]interface{} defaultOutbounds []json_util.RawMessage fragment string - noise string + noises string mux string inboundService service.InboundService SubService *SubService } -func NewSubJsonService(fragment string, noise string, mux string, rules string, subService *SubService) *SubJsonService { +func NewSubJsonService(fragment string, noises string, mux string, rules string, subService *SubService) *SubJsonService { var configJson map[string]interface{} var defaultOutbounds []json_util.RawMessage json.Unmarshal([]byte(defaultJson), &configJson) @@ -53,15 +53,15 @@ func NewSubJsonService(fragment string, noise string, mux string, rules string, defaultOutbounds = append(defaultOutbounds, json_util.RawMessage(fragment)) } - if noise != "" { - defaultOutbounds = append(defaultOutbounds, json_util.RawMessage(noise)) + if noises != "" { + defaultOutbounds = append(defaultOutbounds, json_util.RawMessage(noises)) } return &SubJsonService{ configJson: configJson, defaultOutbounds: defaultOutbounds, fragment: fragment, - noise: noise, + noises: noises, mux: mux, SubService: subService, } diff --git a/web/assets/js/model/outbound.js b/web/assets/js/model/outbound.js index 76487ab7..596ff6c6 100644 --- a/web/assets/js/model/outbound.js +++ b/web/assets/js/model/outbound.js @@ -786,13 +786,21 @@ Outbound.FreedomSettings = class extends CommonClass { domainStrategy = '', redirect = '', fragment = {}, - noise = {} + noises = [] ) { super(); this.domainStrategy = domainStrategy; this.redirect = redirect; this.fragment = fragment; - this.noise = noise; + this.noises = noises; + } + + addNoise() { + this.noises.push(new Outbound.FreedomSettings.Noise()); + } + + delNoise(index) { + this.noises.splice(index, 1); } static fromJson(json = {}) { @@ -800,7 +808,7 @@ Outbound.FreedomSettings = class extends CommonClass { json.domainStrategy, json.redirect, json.fragment ? Outbound.FreedomSettings.Fragment.fromJson(json.fragment) : undefined, - json.noise ? Outbound.FreedomSettings.Noise.fromJson(json.noise) : undefined, + json.noises ? json.noises.map(noise => Outbound.FreedomSettings.Noise.fromJson(noise)) : [new Outbound.FreedomSettings.Noise()], ); } @@ -809,10 +817,11 @@ Outbound.FreedomSettings = class extends CommonClass { domainStrategy: ObjectUtil.isEmpty(this.domainStrategy) ? undefined : this.domainStrategy, redirect: this.redirect, fragment: Object.keys(this.fragment).length === 0 ? undefined : this.fragment, - noise: Object.keys(this.noise).length === 0 ? undefined : this.noise, + noises: Outbound.FreedomSettings.Noise.toJsonArray(this.noises), }; } }; + Outbound.FreedomSettings.Fragment = class extends CommonClass { constructor(packets='1-3',length='',interval=''){ super(); @@ -829,20 +838,40 @@ Outbound.FreedomSettings.Fragment = class extends CommonClass { ); } }; + Outbound.FreedomSettings.Noise = class extends CommonClass { - constructor(packet = '', delay = '') { + constructor( + type = 'rand', + packet = '10-20', + delay = '10-16' + ) { super(); + this.type = type; this.packet = packet; this.delay = delay; } static fromJson(json = {}) { return new Outbound.FreedomSettings.Noise( + json.type, json.packet, json.delay, ); } + + toJson() { + return { + type: this.type, + packet: this.packet, + delay: this.delay, + }; + } + + static toJsonArray(noises) { + return noises.map(noise => noise.toJson()); + } }; + Outbound.BlackholeSettings = class extends CommonClass { constructor(type) { super(); diff --git a/web/assets/js/model/setting.js b/web/assets/js/model/setting.js index dd7effe2..b1ef55ae 100644 --- a/web/assets/js/model/setting.js +++ b/web/assets/js/model/setting.js @@ -34,7 +34,7 @@ class AllSetting { this.subURI = ""; this.subJsonURI = ""; this.subJsonFragment = ""; - this.subJsonNoise = ""; + this.subJsonNoises = ""; this.subJsonMux = ""; this.subJsonRules = ""; diff --git a/web/entity/entity.go b/web/entity/entity.go index 8975afd0..e49e3ef9 100644 --- a/web/entity/entity.go +++ b/web/entity/entity.go @@ -50,7 +50,7 @@ type AllSetting struct { SubJsonPath string `json:"subJsonPath" form:"subJsonPath"` SubJsonURI string `json:"subJsonURI" form:"subJsonURI"` SubJsonFragment string `json:"subJsonFragment" form:"subJsonFragment"` - SubJsonNoise string `json:"subJsonNoise" form:"subJsonNoise"` + SubJsonNoises string `json:"subJsonNoises" form:"subJsonNoises"` SubJsonMux string `json:"subJsonMux" form:"subJsonMux"` SubJsonRules string `json:"subJsonRules" form:"subJsonRules"` } diff --git a/web/html/xui/form/outbound.html b/web/html/xui/form/outbound.html index e37874bd..0bca0ff6 100644 --- a/web/html/xui/form/outbound.html +++ b/web/html/xui/form/outbound.html @@ -18,51 +18,66 @@