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:
authorMHSanaei <ho3ein.sanaei@gmail.com>2023-03-17 19:07:49 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2023-03-17 19:07:49 +0300
commit96786c94189f3d2f3f04c1915529c786228bdf42 (patch)
tree879085e09a3cd485f3246f46be907fe77eb84a1a /web/web.go
parentbc56e637376142c370c31b17558fc3778a863bd2 (diff)
alireza
Diffstat (limited to 'web/web.go')
-rw-r--r--web/web.go24
1 files changed, 19 insertions, 5 deletions
diff --git a/web/web.go b/web/web.go
index d57fc084..1c692598 100644
--- a/web/web.go
+++ b/web/web.go
@@ -21,11 +21,11 @@ import (
"x-ui/web/network"
"x-ui/web/service"
- "github.com/pelletier/go-toml/v2"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
"github.com/nicksnyder/go-i18n/v2/i18n"
+ "github.com/pelletier/go-toml/v2"
"github.com/robfig/cron/v3"
"golang.org/x/text/language"
)
@@ -88,7 +88,7 @@ type Server struct {
xrayService service.XrayService
settingService service.SettingService
- inboundService service.InboundService
+ tgbotService service.Tgbot
cron *cron.Cron
@@ -309,7 +309,7 @@ func (s *Server) startTask() {
// Check the inbound traffic every 30 seconds that the traffic exceeds and expires
s.cron.AddJob("@every 30s", job.NewCheckInboundJob())
-
+
// check client ips from log file every 10 sec
s.cron.AddJob("@every 10s", job.NewCheckClientIpJob())
@@ -328,8 +328,13 @@ func (s *Server) startTask() {
logger.Warning("Add NewStatsNotifyJob error", err)
return
}
- // listen for TG bot income messages
- go job.NewStatsNotifyJob().OnReceive()
+
+ // Check CPU load and alarm to TgBot if threshold passes
+ cpuThreshold, err := s.settingService.GetTgCpu()
+ if (err == nil) && (cpuThreshold > 0) {
+ s.cron.AddJob("@every 10s", job.NewCheckCpuJob())
+ }
+
} else {
s.cron.Remove(entry)
}
@@ -406,6 +411,12 @@ func (s *Server) Start() (err error) {
s.httpServer.Serve(listener)
}()
+ isTgbotenabled, err := s.settingService.GetTgbotenabled()
+ if (err == nil) && (isTgbotenabled) {
+ tgBot := s.tgbotService.NewTgbot()
+ tgBot.Start()
+ }
+
return nil
}
@@ -415,6 +426,9 @@ func (s *Server) Stop() error {
if s.cron != nil {
s.cron.Stop()
}
+ if s.tgbotService.IsRunnging() {
+ s.tgbotService.Stop()
+ }
var err1 error
var err2 error
if s.httpServer != nil {