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:
Diffstat (limited to 'web/service')
-rw-r--r--web/service/inbound.go8
-rw-r--r--web/service/outbound.go3
-rw-r--r--web/service/panel.go4
-rw-r--r--web/service/server.go1
-rw-r--r--web/service/setting.go5
-rw-r--r--web/service/tgbot.go31
-rw-r--r--web/service/user.go4
-rw-r--r--web/service/xray.go17
-rw-r--r--web/service/xray_setting.go1
9 files changed, 39 insertions, 35 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go
index a103e256..e9b1e595 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -5,6 +5,7 @@ import (
"fmt"
"strings"
"time"
+
"x-ui/database"
"x-ui/database/model"
"x-ui/logger"
@@ -90,7 +91,6 @@ func (s *InboundService) getAllEmails() ([]string, error) {
FROM inbounds,
JSON_EACH(JSON_EXTRACT(inbounds.settings, '$.clients')) AS client
`).Scan(&emails).Error
-
if err != nil {
return nil, err
}
@@ -1074,7 +1074,9 @@ func (s *InboundService) UpdateClientStat(tx *gorm.DB, email string, client *mod
"email": client.Email,
"total": client.TotalGB,
"expiry_time": client.ExpiryTime,
- "reset": client.Reset})
+ "reset": client.Reset,
+ })
+
err := result.Error
if err != nil {
return err
@@ -1573,7 +1575,6 @@ func (s *InboundService) ResetAllClientTraffics(id int) error {
Updates(map[string]interface{}{"enable": true, "up": 0, "down": 0})
err := result.Error
-
if err != nil {
return err
}
@@ -1588,7 +1589,6 @@ func (s *InboundService) ResetAllTraffics() error {
Updates(map[string]interface{}{"up": 0, "down": 0})
err := result.Error
-
if err != nil {
return err
}
diff --git a/web/service/outbound.go b/web/service/outbound.go
index 05791f69..685ac422 100644
--- a/web/service/outbound.go
+++ b/web/service/outbound.go
@@ -9,8 +9,7 @@ import (
"gorm.io/gorm"
)
-type OutboundService struct {
-}
+type OutboundService struct{}
func (s *OutboundService) AddTraffic(traffics []*xray.Traffic, clientTraffics []*xray.ClientTraffic) (error, bool) {
var err error
diff --git a/web/service/panel.go b/web/service/panel.go
index f90d3e66..71782a8f 100644
--- a/web/service/panel.go
+++ b/web/service/panel.go
@@ -4,11 +4,11 @@ import (
"os"
"syscall"
"time"
+
"x-ui/logger"
)
-type PanelService struct {
-}
+type PanelService struct{}
func (s *PanelService) RestartPanel(delay time.Duration) error {
p, err := os.FindProcess(syscall.Getpid())
diff --git a/web/service/server.go b/web/service/server.go
index 822918a8..b2dfd22f 100644
--- a/web/service/server.go
+++ b/web/service/server.go
@@ -382,7 +382,6 @@ func (s *ServerService) UpdateXray(version string) error {
}
return nil
-
}
func (s *ServerService) GetLogs(count string, level string, syslog string) []string {
diff --git a/web/service/setting.go b/web/service/setting.go
index 3c7b18fe..00ef13b7 100644
--- a/web/service/setting.go
+++ b/web/service/setting.go
@@ -9,6 +9,7 @@ import (
"strconv"
"strings"
"time"
+
"x-ui/database"
"x-ui/database/model"
"x-ui/logger"
@@ -64,8 +65,7 @@ var defaultValueMap = map[string]string{
"warp": "",
}
-type SettingService struct {
-}
+type SettingService struct{}
func (s *SettingService) GetDefaultJsonConfig() (interface{}, error) {
var jsonData interface{}
@@ -444,6 +444,7 @@ func (s *SettingService) GetDatepicker() (string, error) {
func (s *SettingService) GetWarp() (string, error) {
return s.getString("warp")
}
+
func (s *SettingService) SetWarp(data string) error {
return s.setString("warp", data)
}
diff --git a/web/service/tgbot.go b/web/service/tgbot.go
index 30d19dba..40301667 100644
--- a/web/service/tgbot.go
+++ b/web/service/tgbot.go
@@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"time"
+
"x-ui/config"
"x-ui/database"
"x-ui/database/model"
@@ -26,12 +27,14 @@ import (
"github.com/valyala/fasthttp/fasthttpproxy"
)
-var bot *telego.Bot
-var botHandler *th.BotHandler
-var adminIds []int64
-var isRunning bool
-var hostname string
-var hashStorage *global.HashStorage
+var (
+ bot *telego.Bot
+ botHandler *th.BotHandler
+ adminIds []int64
+ isRunning bool
+ hostname string
+ hashStorage *global.HashStorage
+)
type LoginStatus byte
@@ -280,7 +283,6 @@ func (t *Tgbot) answerCommand(message *telego.Message, chatId int64, isAdmin boo
}
func (t *Tgbot) asnwerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool) {
-
chatId := callbackQuery.Message.GetChat().ID
if isAdmin {
@@ -866,7 +868,7 @@ func (t *Tgbot) SendMsgToTgbot(chatId int64, msg string, replyMarkup ...telego.R
Text: message,
ParseMode: "HTML",
}
- //only add replyMarkup to last message
+ // only add replyMarkup to last message
if len(replyMarkup) > 0 && n == (len(allMessages)-1) {
params.ReplyMarkup = replyMarkup[0]
}
@@ -1030,9 +1032,15 @@ func (t *Tgbot) getInboundUsages() string {
return info
}
-func (t *Tgbot) clientInfoMsg(traffic *xray.ClientTraffic, printEnabled bool, printOnline bool, printActive bool,
- printDate bool, printTraffic bool, printRefreshed bool) string {
-
+func (t *Tgbot) clientInfoMsg(
+ traffic *xray.ClientTraffic,
+ printEnabled bool,
+ printOnline bool,
+ printActive bool,
+ printDate bool,
+ printTraffic bool,
+ printRefreshed bool,
+) string {
now := time.Now().Unix()
expiryTime := ""
flag := false
@@ -1544,7 +1552,6 @@ func (t *Tgbot) sendBackup(chatId int64) {
}
} else {
logger.Error("Error in opening db file for backup: ", err)
-
}
file, err = os.Open(xray.GetConfigPath())
diff --git a/web/service/user.go b/web/service/user.go
index f1868424..b8292000 100644
--- a/web/service/user.go
+++ b/web/service/user.go
@@ -2,6 +2,7 @@ package service
import (
"errors"
+
"x-ui/database"
"x-ui/database/model"
"x-ui/logger"
@@ -9,8 +10,7 @@ import (
"gorm.io/gorm"
)
-type UserService struct {
-}
+type UserService struct{}
func (s *UserService) GetFirstUser() (*model.User, error) {
db := database.GetDB()
diff --git a/web/service/xray.go b/web/service/xray.go
index 7cd1612c..6074216d 100644
--- a/web/service/xray.go
+++ b/web/service/xray.go
@@ -4,16 +4,19 @@ import (
"encoding/json"
"errors"
"sync"
+
"x-ui/logger"
"x-ui/xray"
"go.uber.org/atomic"
)
-var p *xray.Process
-var lock sync.Mutex
-var isNeedXrayRestart atomic.Bool
-var result string
+var (
+ p *xray.Process
+ lock sync.Mutex
+ isNeedXrayRestart atomic.Bool
+ result string
+)
type XrayService struct {
inboundService InboundService
@@ -87,7 +90,6 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) {
// check users active or not
clientStats := inbound.ClientStats
for _, clientTraffic := range clientStats {
-
indexDecrease := 0
for index, client := range clients {
c := client.(map[string]interface{})
@@ -96,20 +98,15 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) {
clients = RemoveIndex(clients, index-indexDecrease)
indexDecrease++
logger.Info("Remove Inbound User ", c["email"], " due the expire or traffic limit")
-
}
-
}
}
-
}
// clear client config for additional parameters
var final_clients []interface{}
for _, client := range clients {
-
c := client.(map[string]interface{})
-
if c["enable"] != nil {
if enable, ok := c["enable"].(bool); ok && !enable {
continue
diff --git a/web/service/xray_setting.go b/web/service/xray_setting.go
index 86bb1d7b..a203e649 100644
--- a/web/service/xray_setting.go
+++ b/web/service/xray_setting.go
@@ -8,6 +8,7 @@ import (
"net/http"
"os"
"time"
+
"x-ui/util/common"
"x-ui/xray"
)