2023-02-09 22:18:06 +03:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"net"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2024-03-11 00:31:24 +03:00
|
|
|
|
2023-02-09 22:18:06 +03:00
|
|
|
"x-ui/util/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Msg struct {
|
|
|
|
Success bool `json:"success"`
|
|
|
|
Msg string `json:"msg"`
|
|
|
|
Obj interface{} `json:"obj"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type AllSetting struct {
|
2023-12-04 21:20:46 +03:00
|
|
|
WebListen string `json:"webListen" form:"webListen"`
|
|
|
|
WebDomain string `json:"webDomain" form:"webDomain"`
|
|
|
|
WebPort int `json:"webPort" form:"webPort"`
|
|
|
|
WebCertFile string `json:"webCertFile" form:"webCertFile"`
|
|
|
|
WebKeyFile string `json:"webKeyFile" form:"webKeyFile"`
|
|
|
|
WebBasePath string `json:"webBasePath" form:"webBasePath"`
|
|
|
|
SessionMaxAge int `json:"sessionMaxAge" form:"sessionMaxAge"`
|
2023-12-08 19:18:51 +03:00
|
|
|
PageSize int `json:"pageSize" form:"pageSize"`
|
2023-12-04 21:20:46 +03:00
|
|
|
ExpireDiff int `json:"expireDiff" form:"expireDiff"`
|
|
|
|
TrafficDiff int `json:"trafficDiff" form:"trafficDiff"`
|
2023-12-08 22:31:17 +03:00
|
|
|
RemarkModel string `json:"remarkModel" form:"remarkModel"`
|
2023-12-04 21:20:46 +03:00
|
|
|
TgBotEnable bool `json:"tgBotEnable" form:"tgBotEnable"`
|
|
|
|
TgBotToken string `json:"tgBotToken" form:"tgBotToken"`
|
2024-01-02 12:42:07 +03:00
|
|
|
TgBotProxy string `json:"tgBotProxy" form:"tgBotProxy"`
|
2024-10-17 11:59:42 +03:00
|
|
|
TgBotAPIServer string `json:"tgBotAPIServer" form:"tgBotAPIServer"`
|
2023-12-04 21:20:46 +03:00
|
|
|
TgBotChatId string `json:"tgBotChatId" form:"tgBotChatId"`
|
|
|
|
TgRunTime string `json:"tgRunTime" form:"tgRunTime"`
|
|
|
|
TgBotBackup bool `json:"tgBotBackup" form:"tgBotBackup"`
|
|
|
|
TgBotLoginNotify bool `json:"tgBotLoginNotify" form:"tgBotLoginNotify"`
|
|
|
|
TgCpu int `json:"tgCpu" form:"tgCpu"`
|
|
|
|
TgLang string `json:"tgLang" form:"tgLang"`
|
|
|
|
TimeLocation string `json:"timeLocation" form:"timeLocation"`
|
|
|
|
SecretEnable bool `json:"secretEnable" form:"secretEnable"`
|
|
|
|
SubEnable bool `json:"subEnable" form:"subEnable"`
|
2025-01-21 05:01:54 +03:00
|
|
|
SubSyncEnable bool `json:"subSyncEnable" form:"subSyncEnable"`
|
2023-12-04 21:20:46 +03:00
|
|
|
SubListen string `json:"subListen" form:"subListen"`
|
|
|
|
SubPort int `json:"subPort" form:"subPort"`
|
|
|
|
SubPath string `json:"subPath" form:"subPath"`
|
|
|
|
SubDomain string `json:"subDomain" form:"subDomain"`
|
|
|
|
SubCertFile string `json:"subCertFile" form:"subCertFile"`
|
|
|
|
SubKeyFile string `json:"subKeyFile" form:"subKeyFile"`
|
|
|
|
SubUpdates int `json:"subUpdates" form:"subUpdates"`
|
|
|
|
SubEncrypt bool `json:"subEncrypt" form:"subEncrypt"`
|
|
|
|
SubShowInfo bool `json:"subShowInfo" form:"subShowInfo"`
|
2023-12-08 19:18:51 +03:00
|
|
|
SubURI string `json:"subURI" form:"subURI"`
|
2024-02-21 13:47:52 +03:00
|
|
|
SubJsonPath string `json:"subJsonPath" form:"subJsonPath"`
|
|
|
|
SubJsonURI string `json:"subJsonURI" form:"subJsonURI"`
|
|
|
|
SubJsonFragment string `json:"subJsonFragment" form:"subJsonFragment"`
|
2024-09-17 10:33:44 +03:00
|
|
|
SubJsonNoises string `json:"subJsonNoises" form:"subJsonNoises"`
|
2024-03-12 19:14:51 +03:00
|
|
|
SubJsonMux string `json:"subJsonMux" form:"subJsonMux"`
|
|
|
|
SubJsonRules string `json:"subJsonRules" form:"subJsonRules"`
|
2024-01-02 11:32:21 +03:00
|
|
|
Datepicker string `json:"datepicker" form:"datepicker"`
|
2023-02-09 22:18:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AllSetting) CheckValid() error {
|
|
|
|
if s.WebListen != "" {
|
|
|
|
ip := net.ParseIP(s.WebListen)
|
|
|
|
if ip == nil {
|
|
|
|
return common.NewError("web listen is not valid ip:", s.WebListen)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-22 17:36:34 +03:00
|
|
|
if s.SubListen != "" {
|
|
|
|
ip := net.ParseIP(s.SubListen)
|
|
|
|
if ip == nil {
|
|
|
|
return common.NewError("Sub listen is not valid ip:", s.SubListen)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-09 22:18:06 +03:00
|
|
|
if s.WebPort <= 0 || s.WebPort > 65535 {
|
|
|
|
return common.NewError("web port is not a valid port:", s.WebPort)
|
|
|
|
}
|
|
|
|
|
2023-05-22 17:36:34 +03:00
|
|
|
if s.SubPort <= 0 || s.SubPort > 65535 {
|
|
|
|
return common.NewError("Sub port is not a valid port:", s.SubPort)
|
|
|
|
}
|
|
|
|
|
2023-12-16 21:48:07 +03:00
|
|
|
if (s.SubPort == s.WebPort) && (s.WebListen == s.SubListen) {
|
|
|
|
return common.NewError("Sub and Web could not use same ip:port, ", s.SubListen, ":", s.SubPort, " & ", s.WebListen, ":", s.WebPort)
|
2023-05-22 17:36:34 +03:00
|
|
|
}
|
|
|
|
|
2023-02-09 22:18:06 +03:00
|
|
|
if s.WebCertFile != "" || s.WebKeyFile != "" {
|
|
|
|
_, err := tls.LoadX509KeyPair(s.WebCertFile, s.WebKeyFile)
|
|
|
|
if err != nil {
|
|
|
|
return common.NewErrorf("cert file <%v> or key file <%v> invalid: %v", s.WebCertFile, s.WebKeyFile, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-22 17:36:34 +03:00
|
|
|
if s.SubCertFile != "" || s.SubKeyFile != "" {
|
|
|
|
_, err := tls.LoadX509KeyPair(s.SubCertFile, s.SubKeyFile)
|
|
|
|
if err != nil {
|
|
|
|
return common.NewErrorf("cert file <%v> or key file <%v> invalid: %v", s.SubCertFile, s.SubKeyFile, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-09 22:18:06 +03:00
|
|
|
if !strings.HasPrefix(s.WebBasePath, "/") {
|
|
|
|
s.WebBasePath = "/" + s.WebBasePath
|
|
|
|
}
|
|
|
|
if !strings.HasSuffix(s.WebBasePath, "/") {
|
|
|
|
s.WebBasePath += "/"
|
|
|
|
}
|
2023-12-08 19:18:51 +03:00
|
|
|
if !strings.HasPrefix(s.SubPath, "/") {
|
|
|
|
s.SubPath = "/" + s.SubPath
|
|
|
|
}
|
|
|
|
if !strings.HasSuffix(s.SubPath, "/") {
|
|
|
|
s.SubPath += "/"
|
|
|
|
}
|
2023-02-09 22:18:06 +03:00
|
|
|
|
2024-02-21 13:47:52 +03:00
|
|
|
if !strings.HasPrefix(s.SubJsonPath, "/") {
|
|
|
|
s.SubJsonPath = "/" + s.SubJsonPath
|
|
|
|
}
|
|
|
|
if !strings.HasSuffix(s.SubJsonPath, "/") {
|
|
|
|
s.SubJsonPath += "/"
|
|
|
|
}
|
|
|
|
|
2023-12-04 21:20:46 +03:00
|
|
|
_, err := time.LoadLocation(s.TimeLocation)
|
2023-02-09 22:18:06 +03:00
|
|
|
if err != nil {
|
|
|
|
return common.NewError("time location not exist:", s.TimeLocation)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|