hotfix / some fixes

hotfix / XUI_DEBUG, XUI_LOG_LEVEL
hotfix / announce
hotfix / debug mode (XUI_DEBUG) fix
hotfix / tg bot server ipv4
hotfix / check mem usage
This commit is contained in:
serogaq 2024-12-08 23:41:07 +03:00
parent 7de62efc6b
commit 26abb907a0
No known key found for this signature in database
GPG key ID: 6657A27160536D7E
5 changed files with 23 additions and 21 deletions

View file

@ -8,3 +8,5 @@ XUI_VLESS_SNI=""
#XUI_SUB_PROFILE_TITLE="" #XUI_SUB_PROFILE_TITLE=""
#XUI_SUB_SUPPORT_URL="" #XUI_SUB_SUPPORT_URL=""
#XUI_SUB_PROFILE_WEB_PAGE_URL="" #XUI_SUB_PROFILE_WEB_PAGE_URL=""
#XUI_DEBUG="false"
#XUI_LOG_LEVEL="info"

View file

@ -34,6 +34,7 @@ services:
volumes: volumes:
- ./db/:/etc/x-ui/ - ./db/:/etc/x-ui/
- ./db/fail2ban.sqlite3:/var/lib/fail2ban/fail2ban.sqlite3 - ./db/fail2ban.sqlite3:/var/lib/fail2ban/fail2ban.sqlite3
- ./db/announce.txt:/etc/x-ui/announce.txt
- ./cert/:/root/cert/ - ./cert/:/root/cert/
- ./logs/xray-access.log:/app/access.log - ./logs/xray-access.log:/app/access.log
- ./logs/xray-error.log:/app/error.log - ./logs/xray-error.log:/app/error.log
@ -41,7 +42,6 @@ services:
- ./logs/3xipl-ap.log:/var/log/3xipl-ap.log - ./logs/3xipl-ap.log:/var/log/3xipl-ap.log
- ./logs/3xipl-banned.log:/var/log/3xipl-banned.log - ./logs/3xipl-banned.log:/var/log/3xipl-banned.log
- ./logs/fail2ban.log:/var/log/fail2ban.log - ./logs/fail2ban.log:/var/log/fail2ban.log
- ./announce.txt:/etc/x-ui/announce.txt
environment: environment:
PUID: 1000 PUID: 1000
PGID: 1000 PGID: 1000
@ -51,6 +51,8 @@ services:
XUI_SUB_PROFILE_TITLE: "${XUI_SUB_PROFILE_TITLE:-}" XUI_SUB_PROFILE_TITLE: "${XUI_SUB_PROFILE_TITLE:-}"
XUI_SUB_SUPPORT_URL: "${XUI_SUB_SUPPORT_URL:-}" XUI_SUB_SUPPORT_URL: "${XUI_SUB_SUPPORT_URL:-}"
XUI_SUB_PROFILE_WEB_PAGE_URL: "${XUI_SUB_PROFILE_WEB_PAGE_URL:-}" XUI_SUB_PROFILE_WEB_PAGE_URL: "${XUI_SUB_PROFILE_WEB_PAGE_URL:-}"
XUI_DEBUG: "${XUI_DEBUG:-false}"
XUI_LOG_LEVEL: "${XUI_LOG_LEVEL:-info}"
tty: true tty: true
restart: unless-stopped restart: unless-stopped

View file

@ -30,7 +30,7 @@ func (j *CheckMemJob) Run() {
} else { } else {
currentMem := memInfo.Used currentMem := memInfo.Used
totalMem := memInfo.Total totalMem := memInfo.Total
percentMem := int(currentMem / totalMem * 100) percentMem := int(float64(currentMem) / float64(totalMem) * 100)
if percentMem >= int(threshold) && bool(needRestart) == true { if percentMem >= int(threshold) && bool(needRestart) == true {
msg := j.tgbotService.I18nBot("tgbot.messages.memThreshold", "Threshold=="+strconv.Itoa(threshold)) msg := j.tgbotService.I18nBot("tgbot.messages.memThreshold", "Threshold=="+strconv.Itoa(threshold))

View file

@ -1074,6 +1074,8 @@ func (t *Tgbot) prepareServerUsageInfo() string {
info += t.I18nBot("tgbot.messages.xrayVersion", "XrayVersion=="+fmt.Sprint(t.lastStatus.Xray.Version)) info += t.I18nBot("tgbot.messages.xrayVersion", "XrayVersion=="+fmt.Sprint(t.lastStatus.Xray.Version))
// get ip address // get ip address
var host string
host = os.Getenv("XUI_SERVER_IP")
netInterfaces, err := net.Interfaces() netInterfaces, err := net.Interfaces()
if err != nil { if err != nil {
logger.Error("net.Interfaces failed, err: ", err.Error()) logger.Error("net.Interfaces failed, err: ", err.Error())
@ -1087,7 +1089,11 @@ func (t *Tgbot) prepareServerUsageInfo() string {
for _, address := range addrs { for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil { if ipnet.IP.To4() != nil {
ipv4 += ipnet.IP.String() + " " if host != "" {
ipv4 += host + " "
} else {
ipv4 += ipnet.IP.String() + " "
}
} else if ipnet.IP.To16() != nil && !ipnet.IP.IsLinkLocalUnicast() { } else if ipnet.IP.To16() != nil && !ipnet.IP.IsLinkLocalUnicast() {
ipv6 += ipnet.IP.String() + " " ipv6 += ipnet.IP.String() + " "
} }

View file

@ -204,24 +204,12 @@ func (s *Server) initRouter() (*gin.Engine, error) {
engine.FuncMap["i18n"] = i18nWebFunc engine.FuncMap["i18n"] = i18nWebFunc
engine.Use(locale.LocalizerMiddleware()) engine.Use(locale.LocalizerMiddleware())
// set static files and template template, err := s.getHtmlTemplate(engine.FuncMap)
if config.IsDebug() { if err != nil {
// for development return nil, err
files, err := s.getHtmlFiles()
if err != nil {
return nil, err
}
engine.LoadHTMLFiles(files...)
engine.StaticFS(basePath+"assets", http.FS(os.DirFS("web/assets")))
} else {
// for production
template, err := s.getHtmlTemplate(engine.FuncMap)
if err != nil {
return nil, err
}
engine.SetHTMLTemplate(template)
engine.StaticFS(basePath+"assets", http.FS(&wrapAssetsFS{FS: assetsFS}))
} }
engine.SetHTMLTemplate(template)
engine.StaticFS(basePath+"assets", http.FS(&wrapAssetsFS{FS: assetsFS}))
// Apply the redirect middleware (`/xui` to `/panel`) // Apply the redirect middleware (`/xui` to `/panel`)
engine.Use(middleware.RedirectMiddleware(basePath)) engine.Use(middleware.RedirectMiddleware(basePath))
@ -289,12 +277,16 @@ func (s *Server) startTask() {
cpuThreshold, err := s.settingService.GetTgCpu() cpuThreshold, err := s.settingService.GetTgCpu()
if (err == nil) && (cpuThreshold > 0) { if (err == nil) && (cpuThreshold > 0) {
s.cron.AddJob("@every 10s", job.NewCheckCpuJob()) s.cron.AddJob("@every 10s", job.NewCheckCpuJob())
} else if err != nil {
logger.Errorf("Add NewCheckCpuJob error: %s", err)
} }
// Check RAM and alarm to TgBot if threshold passes // Check RAM and alarm to TgBot if threshold passes
memThreshold, err := s.settingService.GetTgMem() memThreshold, err := s.settingService.GetTgMem()
if (err == nil) && (memThreshold > 0) { if (err == nil) && (memThreshold > 0) {
s.cron.AddJob("@every 10s", job.NewCheckMemJob()) s.cron.AddJob("@every 10s", job.NewCheckMemJob())
} else if err != nil {
logger.Errorf("Add NewCheckMemJob error: %s", err)
} }
} else { } else {
s.cron.Remove(entry) s.cron.Remove(entry)