Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlireza Ahmadi <alireza7@gmail.com>2023-12-08 19:18:51 +0300
committerAlireza Ahmadi <alireza7@gmail.com>2023-12-08 19:18:51 +0300
commit5e47b4e94925c2272a7f0a4cc355cede72c671a4 (patch)
tree1cc0b2f5c8cea380b65c6d8bb1294e9c5eeb83a7 /web/service
parent549f230221d7139270efefd76ac81f37e1a747f9 (diff)
pagination and sub URI support #1300
Diffstat (limited to 'web/service')
-rw-r--r--web/service/setting.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/web/service/setting.go b/web/service/setting.go
index 933fff1b..d6cf193e 100644
--- a/web/service/setting.go
+++ b/web/service/setting.go
@@ -31,6 +31,7 @@ var defaultValueMap = map[string]string{
"secret": random.Seq(32),
"webBasePath": "/",
"sessionMaxAge": "0",
+ "pageSize": "0",
"expireDiff": "0",
"trafficDiff": "0",
"timeLocation": "Asia/Tehran",
@@ -53,6 +54,7 @@ var defaultValueMap = map[string]string{
"subUpdates": "12",
"subEncrypt": "true",
"subShowInfo": "true",
+ "subURI": "",
}
type SettingService struct {
@@ -406,6 +408,14 @@ func (s *SettingService) GetSubShowInfo() (bool, error) {
return s.getBool("subShowInfo")
}
+func (s *SettingService) GetSubURI() (string, error) {
+ return s.getString("subURI")
+}
+
+func (s *SettingService) GetPageSize() (int, error) {
+ return s.getInt("pageSize")
+}
+
func (s *SettingService) UpdateAllSetting(allSetting *entity.AllSetting) error {
if err := allSetting.CheckValid(); err != nil {
return err
@@ -435,3 +445,61 @@ func (s *SettingService) GetDefaultXrayConfig() (interface{}, error) {
}
return jsonData, nil
}
+
+func (s *SettingService) GetDefaultSettings(host string) (interface{}, error) {
+ type settingFunc func() (interface{}, error)
+ settings := map[string]settingFunc{
+ "expireDiff": func() (interface{}, error) { return s.GetExpireDiff() },
+ "trafficDiff": func() (interface{}, error) { return s.GetTrafficDiff() },
+ "pageSize": func() (interface{}, error) { return s.GetPageSize() },
+ "defaultCert": func() (interface{}, error) { return s.GetCertFile() },
+ "defaultKey": func() (interface{}, error) { return s.GetKeyFile() },
+ "tgBotEnable": func() (interface{}, error) { return s.GetTgbotenabled() },
+ "subEnable": func() (interface{}, error) { return s.GetSubEnable() },
+ "subURI": func() (interface{}, error) { return s.GetSubURI() },
+ }
+
+ result := make(map[string]interface{})
+
+ for key, fn := range settings {
+ value, err := fn()
+ if err != nil {
+ return "", err
+ }
+ result[key] = value
+ }
+
+ if result["subEnable"].(bool) && result["subURI"].(string) == "" {
+ subURI := ""
+ subPort, _ := s.GetSubPort()
+ subPath, _ := s.GetSubPath()
+ subDomain, _ := s.GetSubDomain()
+ subKeyFile, _ := s.GetSubKeyFile()
+ subCertFile, _ := s.GetSubCertFile()
+ subTLS := false
+ if subKeyFile != "" && subCertFile != "" {
+ subTLS = true
+ }
+ if subDomain == "" {
+ subDomain = strings.Split(host, ":")[0]
+ }
+ if subTLS {
+ subURI = "https://"
+ } else {
+ subURI = "http://"
+ }
+ if (subPort == 443 && subTLS) || (subPort == 80 && !subTLS) {
+ subURI += subDomain
+ } else {
+ subURI += fmt.Sprintf("%s:%d", subDomain, subPort)
+ }
+ if subPath[0] == byte('/') {
+ subURI += subPath
+ } else {
+ subURI += "/" + subPath
+ }
+ result["subURI"] = subURI
+ }
+
+ return result, nil
+}