Some fixes and improvements (#1077)

* [refactor] api controller

* [update] use status code for jsonMsg and 401 to unauthorize

* [update] handle response status code via axios

* [lint] all .go files
This commit is contained in:
Hamidreza
2024-03-10 20:30:44 +03:30
committed by GitHub
parent e3c2b42048
commit b6ccb2e076
40 changed files with 135 additions and 142 deletions

1
.gitignore vendored
View File

@@ -3,6 +3,7 @@
.cache .cache
.sync* .sync*
*.tar.gz *.tar.gz
*.log
access.log access.log
error.log error.log
tmp tmp

View File

@@ -6,6 +6,7 @@ import (
"io/fs" "io/fs"
"os" "os"
"path" "path"
"x-ui/config" "x-ui/config"
"x-ui/database/model" "x-ui/database/model"
"x-ui/xray" "x-ui/xray"

View File

@@ -2,6 +2,7 @@ package model
import ( import (
"fmt" "fmt"
"x-ui/util/json_util" "x-ui/util/json_util"
"x-ui/xray" "x-ui/xray"
) )

View File

@@ -8,12 +8,14 @@ import (
"github.com/op/go-logging" "github.com/op/go-logging"
) )
var logger *logging.Logger var (
var logBuffer []struct { logger *logging.Logger
logBuffer []struct {
time string time string
level logging.Level level logging.Level
log string log string
} }
)
func init() { func init() {
InitLogger(logging.INFO) InitLogger(logging.INFO)

View File

@@ -8,6 +8,7 @@ import (
"os/signal" "os/signal"
"syscall" "syscall"
_ "unsafe" _ "unsafe"
"x-ui/config" "x-ui/config"
"x-ui/database" "x-ui/database"
"x-ui/logger" "x-ui/logger"

View File

@@ -7,6 +7,7 @@ import (
"net" "net"
"net/http" "net/http"
"strconv" "strconv"
"x-ui/config" "x-ui/config"
"x-ui/logger" "x-ui/logger"
"x-ui/util/common" "x-ui/util/common"

View File

@@ -25,8 +25,8 @@ func NewSUBController(
showInfo bool, showInfo bool,
rModel string, rModel string,
update string, update string,
jsonFragment string) *SUBController { jsonFragment string,
) *SUBController {
a := &SUBController{ a := &SUBController{
subPath: subPath, subPath: subPath,
subJsonPath: jsonPath, subJsonPath: jsonPath,

View File

@@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings" "strings"
"x-ui/database/model" "x-ui/database/model"
"x-ui/logger" "x-ui/logger"
"x-ui/util/json_util" "x-ui/util/json_util"

View File

@@ -6,6 +6,7 @@ import (
"net/url" "net/url"
"strings" "strings"
"time" "time"
"x-ui/database" "x-ui/database"
"x-ui/database/model" "x-ui/database/model"
"x-ui/logger" "x-ui/logger"

View File

@@ -3,6 +3,7 @@ package common
import ( import (
"errors" "errors"
"fmt" "fmt"
"x-ui/logger" "x-ui/logger"
) )

View File

@@ -5,12 +5,14 @@ import (
"time" "time"
) )
var numSeq [10]rune var (
var lowerSeq [26]rune numSeq [10]rune
var upperSeq [26]rune lowerSeq [26]rune
var numLowerSeq [36]rune upperSeq [26]rune
var numUpperSeq [36]rune numLowerSeq [36]rune
var allSeq [62]rune numUpperSeq [36]rune
allSeq [62]rune
)
func init() { func init() {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())

View File

@@ -14,3 +14,17 @@ axios.interceptors.request.use(
}, },
(error) => Promise.reject(error), (error) => Promise.reject(error),
); );
axios.interceptors.response.use(
(response) => response,
(error) => {
if (error.response) {
const statusCode = error.response.status;
// Check the status code
if (statusCode === 401) { // Unauthorized
return window.location.reload();
}
}
return Promise.reject(error);
}
);

View File

@@ -22,81 +22,35 @@ func (a *APIController) initRouter(g *gin.RouterGroup) {
g = g.Group("/xui/API/inbounds") g = g.Group("/xui/API/inbounds")
g.Use(a.checkLogin) g.Use(a.checkLogin)
g.GET("/", a.inbounds)
g.GET("/get/:id", a.inbound)
g.GET("/getClientTraffics/:email", a.getClientTraffics)
g.POST("/add", a.addInbound)
g.POST("/del/:id", a.delInbound)
g.POST("/update/:id", a.updateInbound)
g.POST("/addClient", a.addInboundClient)
g.POST("/:id/delClient/:clientId", a.delInboundClient)
g.POST("/updateClient/:clientId", a.updateInboundClient)
g.POST("/:id/resetClientTraffic/:email", a.resetClientTraffic)
g.POST("/resetAllTraffics", a.resetAllTraffics)
g.POST("/resetAllClientTraffics/:id", a.resetAllClientTraffics)
g.POST("/delDepletedClients/:id", a.delDepletedClients)
g.GET("/createbackup", a.createBackup)
g.POST("/onlines", a.onlines)
a.inboundController = NewInboundController(g) a.inboundController = NewInboundController(g)
inboundRoutes := []struct {
Method string
Path string
Handler gin.HandlerFunc
}{
{"GET", "/createbackup", a.createBackup},
{"GET", "/", a.inboundController.getInbounds},
{"GET", "/get/:id", a.inboundController.getInbound},
{"GET", "/getClientTraffics/:email", a.inboundController.getClientTraffics},
{"POST", "/add", a.inboundController.addInbound},
{"POST", "/del/:id", a.inboundController.delInbound},
{"POST", "/update/:id", a.inboundController.updateInbound},
{"POST", "/addClient", a.inboundController.addInboundClient},
{"POST", "/:id/delClient/:clientId", a.inboundController.delInboundClient},
{"POST", "/updateClient/:clientId", a.inboundController.updateInboundClient},
{"POST", "/:id/resetClientTraffic/:email", a.inboundController.resetClientTraffic},
{"POST", "/resetAllTraffics", a.inboundController.resetAllTraffics},
{"POST", "/resetAllClientTraffics/:id", a.inboundController.resetAllClientTraffics},
{"POST", "/delDepletedClients/:id", a.inboundController.delDepletedClients},
{"POST", "/onlines", a.inboundController.onlines},
} }
func (a *APIController) inbounds(c *gin.Context) { for _, route := range inboundRoutes {
a.inboundController.getInbounds(c) g.Handle(route.Method, route.Path, route.Handler)
} }
func (a *APIController) inbound(c *gin.Context) {
a.inboundController.getInbound(c)
}
func (a *APIController) getClientTraffics(c *gin.Context) {
a.inboundController.getClientTraffics(c)
}
func (a *APIController) addInbound(c *gin.Context) {
a.inboundController.addInbound(c)
}
func (a *APIController) delInbound(c *gin.Context) {
a.inboundController.delInbound(c)
}
func (a *APIController) updateInbound(c *gin.Context) {
a.inboundController.updateInbound(c)
}
func (a *APIController) addInboundClient(c *gin.Context) {
a.inboundController.addInboundClient(c)
}
func (a *APIController) delInboundClient(c *gin.Context) {
a.inboundController.delInboundClient(c)
}
func (a *APIController) updateInboundClient(c *gin.Context) {
a.inboundController.updateInboundClient(c)
}
func (a *APIController) resetClientTraffic(c *gin.Context) {
a.inboundController.resetClientTraffic(c)
}
func (a *APIController) resetAllTraffics(c *gin.Context) {
a.inboundController.resetAllTraffics(c)
}
func (a *APIController) resetAllClientTraffics(c *gin.Context) {
a.inboundController.resetAllClientTraffics(c)
}
func (a *APIController) delDepletedClients(c *gin.Context) {
a.inboundController.delDepletedClients(c)
} }
func (a *APIController) createBackup(c *gin.Context) { func (a *APIController) createBackup(c *gin.Context) {
a.Tgbot.SendBackupToAdmins() a.Tgbot.SendBackupToAdmins()
} }
func (a *APIController) onlines(c *gin.Context) {
a.inboundController.onlines(c)
}

View File

@@ -2,6 +2,7 @@ package controller
import ( import (
"net/http" "net/http"
"x-ui/logger" "x-ui/logger"
"x-ui/web/locale" "x-ui/web/locale"
"x-ui/web/session" "x-ui/web/session"
@@ -9,13 +10,12 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
type BaseController struct { type BaseController struct{}
}
func (a *BaseController) checkLogin(c *gin.Context) { func (a *BaseController) checkLogin(c *gin.Context) {
if !session.IsLogin(c) { if !session.IsLogin(c) {
if isAjax(c) { if isAjax(c) {
pureJsonMsg(c, false, I18nWeb(c, "pages.login.loginAgain")) pureJsonMsg(c, http.StatusUnauthorized, false, I18nWeb(c, "pages.login.loginAgain"))
} else { } else {
c.Redirect(http.StatusTemporaryRedirect, c.GetString("base_path")) c.Redirect(http.StatusTemporaryRedirect, c.GetString("base_path"))
} }

View File

@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strconv" "strconv"
"x-ui/database/model" "x-ui/database/model"
"x-ui/web/service" "x-ui/web/service"
"x-ui/web/session" "x-ui/web/session"
@@ -63,6 +64,7 @@ func (a *InboundController) getInbound(c *gin.Context) {
} }
jsonObj(c, inbound, nil) jsonObj(c, inbound, nil)
} }
func (a *InboundController) getClientTraffics(c *gin.Context) { func (a *InboundController) getClientTraffics(c *gin.Context) {
email := c.Param("email") email := c.Param("email")
clientTraffics, err := a.inboundService.GetClientTrafficByEmail(email) clientTraffics, err := a.inboundService.GetClientTrafficByEmail(email)

View File

@@ -3,6 +3,7 @@ package controller
import ( import (
"net/http" "net/http"
"time" "time"
"x-ui/logger" "x-ui/logger"
"x-ui/web/service" "x-ui/web/service"
"x-ui/web/session" "x-ui/web/session"
@@ -47,15 +48,15 @@ func (a *IndexController) login(c *gin.Context) {
var form LoginForm var form LoginForm
err := c.ShouldBind(&form) err := c.ShouldBind(&form)
if err != nil { if err != nil {
pureJsonMsg(c, false, I18nWeb(c, "pages.login.toasts.invalidFormData")) pureJsonMsg(c, http.StatusOK, false, I18nWeb(c, "pages.login.toasts.invalidFormData"))
return return
} }
if form.Username == "" { if form.Username == "" {
pureJsonMsg(c, false, I18nWeb(c, "pages.login.toasts.emptyUsername")) pureJsonMsg(c, http.StatusOK, false, I18nWeb(c, "pages.login.toasts.emptyUsername"))
return return
} }
if form.Password == "" { if form.Password == "" {
pureJsonMsg(c, false, I18nWeb(c, "pages.login.toasts.emptyPassword")) pureJsonMsg(c, http.StatusOK, false, I18nWeb(c, "pages.login.toasts.emptyPassword"))
return return
} }
@@ -64,7 +65,7 @@ func (a *IndexController) login(c *gin.Context) {
if user == nil { if user == nil {
logger.Infof("wrong username or password: \"%s\" \"%s\"", form.Username, form.Password) logger.Infof("wrong username or password: \"%s\" \"%s\"", form.Username, form.Password)
a.tgbot.UserLoginNotify(form.Username, getRemoteIp(c), timeStr, 0) a.tgbot.UserLoginNotify(form.Username, getRemoteIp(c), timeStr, 0)
pureJsonMsg(c, false, I18nWeb(c, "pages.login.toasts.wrongUsernameOrPassword")) pureJsonMsg(c, http.StatusOK, false, I18nWeb(c, "pages.login.toasts.wrongUsernameOrPassword"))
return return
} else { } else {
logger.Infof("%s login success ,Ip Address: %s\n", form.Username, getRemoteIp(c)) logger.Infof("%s login success ,Ip Address: %s\n", form.Username, getRemoteIp(c))

View File

@@ -5,6 +5,7 @@ import (
"net/http" "net/http"
"regexp" "regexp"
"time" "time"
"x-ui/web/global" "x-ui/web/global"
"x-ui/web/service" "x-ui/web/service"

View File

@@ -3,6 +3,7 @@ package controller
import ( import (
"errors" "errors"
"time" "time"
"x-ui/web/entity" "x-ui/web/entity"
"x-ui/web/service" "x-ui/web/service"
"x-ui/web/session" "x-ui/web/session"

View File

@@ -4,6 +4,7 @@ import (
"net" "net"
"net/http" "net/http"
"strings" "strings"
"x-ui/config" "x-ui/config"
"x-ui/logger" "x-ui/logger"
"x-ui/web/entity" "x-ui/web/entity"
@@ -48,18 +49,11 @@ func jsonMsgObj(c *gin.Context, msg string, obj interface{}, err error) {
c.JSON(http.StatusOK, m) c.JSON(http.StatusOK, m)
} }
func pureJsonMsg(c *gin.Context, success bool, msg string) { func pureJsonMsg(c *gin.Context, statusCode int, success bool, msg string) {
if success { c.JSON(statusCode, entity.Msg{
c.JSON(http.StatusOK, entity.Msg{ Success: success,
Success: true,
Msg: msg, Msg: msg,
}) })
} else {
c.JSON(http.StatusOK, entity.Msg{
Success: false,
Msg: msg,
})
}
} }
func html(c *gin.Context, name string, title string, data gin.H) { func html(c *gin.Context, name string, title string, data gin.H) {

View File

@@ -5,6 +5,7 @@ import (
"net" "net"
"strings" "strings"
"time" "time"
"x-ui/util/common" "x-ui/util/common"
) )

View File

@@ -7,8 +7,10 @@ import (
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"
) )
var webServer WebServer var (
var subServer SubServer webServer WebServer
subServer SubServer
)
type WebServer interface { type WebServer interface {
GetCron() *cron.Cron GetCron() *cron.Cron

View File

@@ -3,6 +3,7 @@ package job
import ( import (
"strconv" "strconv"
"time" "time"
"x-ui/web/service" "x-ui/web/service"
"github.com/shirou/gopsutil/v3/cpu" "github.com/shirou/gopsutil/v3/cpu"

View File

@@ -31,5 +31,4 @@ func (j *XrayTrafficJob) Run() {
if needRestart { if needRestart {
j.xrayService.SetToNeedRestart() j.xrayService.SetToNeedRestart()
} }
} }

View File

@@ -4,6 +4,7 @@ import (
"embed" "embed"
"io/fs" "io/fs"
"strings" "strings"
"x-ui/logger" "x-ui/logger"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -12,9 +13,11 @@ import (
"golang.org/x/text/language" "golang.org/x/text/language"
) )
var i18nBundle *i18n.Bundle var (
var LocalizerWeb *i18n.Localizer i18nBundle *i18n.Bundle
var LocalizerBot *i18n.Localizer LocalizerWeb *i18n.Localizer
LocalizerBot *i18n.Localizer
)
type I18nType string type I18nType string
@@ -79,7 +82,6 @@ func I18n(i18nType I18nType, key string, params ...string) string {
MessageID: key, MessageID: key,
TemplateData: templateData, TemplateData: templateData,
}) })
if err != nil { if err != nil {
logger.Errorf("Failed to localize message: %v", err) logger.Errorf("Failed to localize message: %v", err)
return "" return ""
@@ -135,7 +137,6 @@ func parseTranslationFiles(i18nFS embed.FS, i18nBundle *i18n.Bundle) error {
_, err = i18nBundle.ParseMessageFileBytes(data, path) _, err = i18nBundle.ParseMessageFileBytes(data, path)
return err return err
}) })
if err != nil { if err != nil {
return err return err
} }

View File

@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"time" "time"
"x-ui/database" "x-ui/database"
"x-ui/database/model" "x-ui/database/model"
"x-ui/logger" "x-ui/logger"
@@ -90,7 +91,6 @@ func (s *InboundService) getAllEmails() ([]string, error) {
FROM inbounds, FROM inbounds,
JSON_EACH(JSON_EXTRACT(inbounds.settings, '$.clients')) AS client JSON_EACH(JSON_EXTRACT(inbounds.settings, '$.clients')) AS client
`).Scan(&emails).Error `).Scan(&emails).Error
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1044,13 +1044,15 @@ func (s *InboundService) UpdateClientStat(tx *gorm.DB, email string, client *mod
"email": client.Email, "email": client.Email,
"total": client.TotalGB, "total": client.TotalGB,
"expiry_time": client.ExpiryTime, "expiry_time": client.ExpiryTime,
"reset": client.Reset}) "reset": client.Reset,
})
err := result.Error err := result.Error
if err != nil { if err != nil {
return err return err
} }
return nil return nil
} }
func (s *InboundService) DelClientStat(tx *gorm.DB, email string) error { func (s *InboundService) DelClientStat(tx *gorm.DB, email string) error {
return tx.Where("email = ?", email).Delete(xray.ClientTraffic{}).Error return tx.Where("email = ?", email).Delete(xray.ClientTraffic{}).Error
} }
@@ -1131,7 +1133,6 @@ func (s *InboundService) ResetAllClientTraffics(id int) error {
Updates(map[string]interface{}{"enable": true, "up": 0, "down": 0}) Updates(map[string]interface{}{"enable": true, "up": 0, "down": 0})
err := result.Error err := result.Error
if err != nil { if err != nil {
return err return err
} }
@@ -1146,7 +1147,6 @@ func (s *InboundService) ResetAllTraffics() error {
Updates(map[string]interface{}{"up": 0, "down": 0}) Updates(map[string]interface{}{"up": 0, "down": 0})
err := result.Error err := result.Error
if err != nil { if err != nil {
return err return err
} }

View File

@@ -4,11 +4,11 @@ import (
"os" "os"
"syscall" "syscall"
"time" "time"
"x-ui/logger" "x-ui/logger"
) )
type PanelService struct { type PanelService struct{}
}
func (s *PanelService) RestartPanel(delay time.Duration) error { func (s *PanelService) RestartPanel(delay time.Duration) error {
p, err := os.FindProcess(syscall.Getpid()) p, err := os.FindProcess(syscall.Getpid())

View File

@@ -15,6 +15,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"x-ui/config" "x-ui/config"
"x-ui/database" "x-ui/database"
"x-ui/logger" "x-ui/logger"
@@ -250,7 +251,6 @@ func (s *ServerService) GetXrayVersions() ([]string, error) {
} }
func (s *ServerService) StopXrayService() (string error) { func (s *ServerService) StopXrayService() (string error) {
err := s.xrayService.StopXray() err := s.xrayService.StopXray()
if err != nil { if err != nil {
logger.Error("stop xray failed:", err) logger.Error("stop xray failed:", err)
@@ -261,7 +261,6 @@ func (s *ServerService) StopXrayService() (string error) {
} }
func (s *ServerService) RestartXrayService() (string error) { func (s *ServerService) RestartXrayService() (string error) {
s.xrayService.StopXray() s.xrayService.StopXray()
defer func() { defer func() {
err := s.xrayService.RestartXray(true) err := s.xrayService.RestartXray(true)
@@ -365,7 +364,6 @@ func (s *ServerService) UpdateXray(version string) error {
} }
return nil return nil
} }
func (s *ServerService) GetLogs(count string, level string, syslog string) []string { func (s *ServerService) GetLogs(count string, level string, syslog string) []string {

View File

@@ -9,6 +9,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"x-ui/database" "x-ui/database"
"x-ui/database/model" "x-ui/database/model"
"x-ui/logger" "x-ui/logger"
@@ -61,8 +62,7 @@ var defaultValueMap = map[string]string{
"warp": "", "warp": "",
} }
type SettingService struct { type SettingService struct{}
}
func (s *SettingService) GetAllSetting() (*entity.AllSetting, error) { func (s *SettingService) GetAllSetting() (*entity.AllSetting, error) {
db := database.GetDB() db := database.GetDB()
@@ -406,6 +406,7 @@ func (s *SettingService) GetSubJsonFragment() (string, error) {
func (s *SettingService) GetWarp() (string, error) { func (s *SettingService) GetWarp() (string, error) {
return s.getString("warp") return s.getString("warp")
} }
func (s *SettingService) SetWarp(data string) error { func (s *SettingService) SetWarp(data string) error {
return s.setString("warp", data) return s.setString("warp", data)
} }

View File

@@ -8,6 +8,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"x-ui/config" "x-ui/config"
"x-ui/database" "x-ui/database"
"x-ui/database/model" "x-ui/database/model"
@@ -19,10 +20,12 @@ import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
) )
var bot *tgbotapi.BotAPI var (
var adminIds []int64 bot *tgbotapi.BotAPI
var isRunning bool adminIds []int64
var hostname string isRunning bool
hostname string
)
type LoginStatus byte type LoginStatus byte

View File

@@ -2,6 +2,7 @@ package service
import ( import (
"errors" "errors"
"x-ui/database" "x-ui/database"
"x-ui/database/model" "x-ui/database/model"
"x-ui/logger" "x-ui/logger"
@@ -9,8 +10,7 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
type UserService struct { type UserService struct{}
}
func (s *UserService) GetFirstUser() (*model.User, error) { func (s *UserService) GetFirstUser() (*model.User, error) {
db := database.GetDB() db := database.GetDB()

View File

@@ -4,16 +4,19 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"sync" "sync"
"x-ui/logger" "x-ui/logger"
"x-ui/xray" "x-ui/xray"
"go.uber.org/atomic" "go.uber.org/atomic"
) )
var p *xray.Process var (
var lock sync.Mutex p *xray.Process
var isNeedXrayRestart atomic.Bool lock sync.Mutex
var result string isNeedXrayRestart atomic.Bool
result string
)
type XrayService struct { type XrayService struct {
inboundService InboundService inboundService InboundService
@@ -87,7 +90,6 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) {
// check users active or not // check users active or not
clientStats := inbound.ClientStats clientStats := inbound.ClientStats
for _, clientTraffic := range clientStats { for _, clientTraffic := range clientStats {
indexDecrease := 0 indexDecrease := 0
for index, client := range clients { for index, client := range clients {
c := client.(map[string]interface{}) c := client.(map[string]interface{})
@@ -96,10 +98,8 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) {
clients = RemoveIndex(clients, index-indexDecrease) clients = RemoveIndex(clients, index-indexDecrease)
indexDecrease++ indexDecrease++
} }
} }
} }
} }
// clear client config for additional parameters // clear client config for additional parameters

View File

@@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"os" "os"
"time" "time"
"x-ui/util/common" "x-ui/util/common"
"x-ui/xray" "x-ui/xray"
) )

View File

@@ -2,6 +2,7 @@ package session
import ( import (
"encoding/gob" "encoding/gob"
"x-ui/database/model" "x-ui/database/model"
sessions "github.com/Calidity/gin-sessions" sessions "github.com/Calidity/gin-sessions"

View File

@@ -13,6 +13,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"x-ui/config" "x-ui/config"
"x-ui/logger" "x-ui/logger"
"x-ui/util/common" "x-ui/util/common"

View File

@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"regexp" "regexp"
"time" "time"
"x-ui/logger" "x-ui/logger"
"x-ui/util/common" "x-ui/util/common"
@@ -159,8 +160,8 @@ func (x *XrayAPI) GetTraffic(reset bool) ([]*Traffic, []*ClientTraffic, error) {
if x.grpcClient == nil { if x.grpcClient == nil {
return nil, nil, common.NewError("xray api is not initialized") return nil, nil, common.NewError("xray api is not initialized")
} }
var trafficRegex = regexp.MustCompile("(inbound|outbound)>>>([^>]+)>>>traffic>>>(downlink|uplink)") trafficRegex := regexp.MustCompile("(inbound|outbound)>>>([^>]+)>>>traffic>>>(downlink|uplink)")
var ClientTrafficRegex = regexp.MustCompile("(user)>>>([^>]+)>>>traffic>>>(downlink|uplink)") ClientTrafficRegex := regexp.MustCompile("(user)>>>([^>]+)>>>traffic>>>(downlink|uplink)")
client := *x.StatsServiceClient client := *x.StatsServiceClient
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)

View File

@@ -2,6 +2,7 @@ package xray
import ( import (
"bytes" "bytes"
"x-ui/util/json_util" "x-ui/util/json_util"
) )

View File

@@ -2,6 +2,7 @@ package xray
import ( import (
"bytes" "bytes"
"x-ui/util/json_util" "x-ui/util/json_util"
) )

View File

@@ -3,6 +3,7 @@ package xray
import ( import (
"regexp" "regexp"
"strings" "strings"
"x-ui/logger" "x-ui/logger"
) )

View File

@@ -11,6 +11,7 @@ import (
"runtime" "runtime"
"syscall" "syscall"
"time" "time"
"x-ui/config" "x-ui/config"
"x-ui/util/common" "x-ui/util/common"
) )