From 8b5fe0b018af70c5302966f1d3d4d9a1cdd82dad Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Tue, 12 Mar 2024 19:44:51 +0330 Subject: [subJson] add mux and direct Co-Authored-By: Alireza Ahmadi --- web/assets/js/model/setting.js | 8 ++- web/entity/entity.go | 2 + web/html/xui/settings.html | 121 +++++++++++++++++++++++++++++++++++++++++ web/service/setting.go | 10 ++++ 4 files changed, 138 insertions(+), 3 deletions(-) (limited to 'web') diff --git a/web/assets/js/model/setting.js b/web/assets/js/model/setting.js index 637830e8..d9d0f4d4 100644 --- a/web/assets/js/model/setting.js +++ b/web/assets/js/model/setting.js @@ -35,9 +35,11 @@ class AllSetting { this.subUpdates = 0; this.subEncrypt = true; this.subShowInfo = false; - this.subURI = ''; - this.subJsonURI = ''; - this.subJsonFragment = ''; + this.subURI = ""; + this.subJsonURI = ""; + this.subJsonFragment = ""; + this.subJsonMux = ""; + this.subJsonRules = ""; this.timeLocation = "Asia/Tehran"; diff --git a/web/entity/entity.go b/web/entity/entity.go index 0a9c3a56..533fe973 100644 --- a/web/entity/entity.go +++ b/web/entity/entity.go @@ -52,6 +52,8 @@ type AllSetting struct { SubJsonPath string `json:"subJsonPath" form:"subJsonPath"` SubJsonURI string `json:"subJsonURI" form:"subJsonURI"` SubJsonFragment string `json:"subJsonFragment" form:"subJsonFragment"` + SubJsonMux string `json:"subJsonMux" form:"subJsonMux"` + SubJsonRules string `json:"subJsonRules" form:"subJsonRules"` Datepicker string `json:"datepicker" form:"datepicker"` } diff --git a/web/html/xui/settings.html b/web/html/xui/settings.html index 3096970f..f9f2aba7 100644 --- a/web/html/xui/settings.html +++ b/web/html/xui/settings.html @@ -295,6 +295,8 @@ + + @@ -318,6 +320,36 @@ + + + + + + + + + + + + [[ p ]] + + + + + + + + + + + @@ -367,6 +399,40 @@ } } }, + defaultMux: { + enabled: true, + concurrency: 8, + xudpConcurrency: 16, + xudpProxyUDP443: "reject" + }, + defaultRules: [ + { + type: "field", + outboundTag: "direct", + domain: [ + "geosite:category-ir", + "geosite:cn" + ], + "enabled": true + }, + { + type: "field", + outboundTag: "direct", + ip: [ + "geoip:private", + "geoip:ir", + "geoip:cn" + ], + enabled: true + }, + ], + countryOptions: [ + { label: 'Private IP/Domain', value: 'private' }, + { label: '🇮🇷 Iran', value: 'ir' }, + { label: '🇨🇳 China', value: 'cn' }, + { label: '🇷🇺 Russia', value: 'ru' }, + { label: '🇻🇳 Vietnam', value: 'vn' }, + ], get remarkModel() { rm = this.allSetting.remarkModel; return rm.length>1 ? rm.substring(1).split('') : []; @@ -530,6 +596,61 @@ } } }, + enableMux: { + get: function() { return this.allSetting?.subJsonMux != ""; }, + set: function (v) { + this.allSetting.subJsonMux = v ? JSON.stringify(this.defaultMux) : ""; + } + }, + muxConcurrency: { + get: function() { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).concurrency : -1; }, + set: function(v) { + newMux = JSON.parse(this.allSetting.subJsonMux); + newMux.concurrency = v; + this.allSetting.subJsonMux = JSON.stringify(newMux); + } + }, + muxXudpConcurrency: { + get: function() { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).xudpConcurrency : -1; }, + set: function(v) { + newMux = JSON.parse(this.allSetting.subJsonMux); + newMux.xudpConcurrency = v; + this.allSetting.subJsonMux = JSON.stringify(newMux); + } + }, + muxXudpProxyUDP443: { + get: function() { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).xudpProxyUDP443 : "reject"; }, + set: function(v) { + newMux = JSON.parse(this.allSetting.subJsonMux); + newMux.xudpProxyUDP443 = v; + this.allSetting.subJsonMux = JSON.stringify(newMux); + } + }, + enableDirect: { + get: function() { return this.allSetting?.subJsonRules != ""; }, + set: function (v) { + this.allSetting.subJsonRules = v ? JSON.stringify(this.defaultRules) : ""; + } + }, + directCountries: { + get: function() { + if (!this.enableDirect) return []; + rules = JSON.parse(this.allSetting.subJsonRules); + return Array.isArray(rules) ? rules[1].ip.map(d => d.replace("geoip:","")) : []; + }, + set: function (v) { + rules = JSON.parse(this.allSetting.subJsonRules); + if (!Array.isArray(rules)) return; + rules[0].domain = []; + rules[1].ip = []; + v.forEach(d => { + category = ["cn","private"].includes(d) ? "" : "category-"; + rules[0].domain.push("geosite:"+category+d); + rules[1].ip.push("geoip:"+d); + }); + this.allSetting.subJsonRules = JSON.stringify(rules); + } + }, confAlerts: { get: function() { if (!this.allSetting) return []; diff --git a/web/service/setting.go b/web/service/setting.go index 00ef13b7..10147dfc 100644 --- a/web/service/setting.go +++ b/web/service/setting.go @@ -61,6 +61,8 @@ var defaultValueMap = map[string]string{ "subJsonPath": "/json/", "subJsonURI": "", "subJsonFragment": "", + "subJsonMux": "", + "subJsonRules": "", "datepicker": "gregorian", "warp": "", } @@ -437,6 +439,14 @@ func (s *SettingService) GetSubJsonFragment() (string, error) { return s.getString("subJsonFragment") } +func (s *SettingService) GetSubJsonMux() (string, error) { + return s.getString("subJsonMux") +} + +func (s *SettingService) GetSubJsonRules() (string, error) { + return s.getString("subJsonRules") +} + func (s *SettingService) GetDatepicker() (string, error) { return s.getString("datepicker") } -- cgit v1.2.3