From f0d4dbf8382f42c9189f606ac8520d6405ee8f05 Mon Sep 17 00:00:00 2001
From: MHSanaei <33454419+MHSanaei@users.noreply.github.com>
Date: Fri, 24 Mar 2023 16:50:10 +0330
Subject: [tgbot] fix exhausted report
---
web/service/tgbot.go | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
(limited to 'web/service')
diff --git a/web/service/tgbot.go b/web/service/tgbot.go
index 63aa86ac..e88edbdf 100644
--- a/web/service/tgbot.go
+++ b/web/service/tgbot.go
@@ -473,7 +473,7 @@ func (t *Tgbot) getExhausted() string {
}
ExpireThreshold, err := t.settingService.GetTgExpireDiff()
if err == nil && ExpireThreshold > 0 {
- exDiff = int64(ExpireThreshold) * 84600
+ exDiff = int64(ExpireThreshold) * 84600000
}
inbounds, err := t.inboundService.GetAllInbounds()
if err != nil {
@@ -481,14 +481,14 @@ func (t *Tgbot) getExhausted() string {
}
for _, inbound := range inbounds {
if inbound.Enable {
- if (inbound.ExpiryTime > 0 && (now-inbound.ExpiryTime < exDiff)) ||
+ if (inbound.ExpiryTime > 0 && (inbound.ExpiryTime-now < exDiff)) ||
(inbound.Total > 0 && (inbound.Total-inbound.Up+inbound.Down < trDiff)) {
exhaustedInbounds = append(exhaustedInbounds, *inbound)
}
if len(inbound.ClientStats) > 0 {
for _, client := range inbound.ClientStats {
if client.Enable {
- if (client.ExpiryTime > 0 && (now-client.ExpiryTime < exDiff)) ||
+ if (client.ExpiryTime > 0 && (client.ExpiryTime-now < exDiff)) ||
(client.Total > 0 && (client.Total-client.Up+client.Down < trDiff)) {
exhaustedClients = append(exhaustedClients, client)
}
@@ -502,7 +502,7 @@ func (t *Tgbot) getExhausted() string {
}
}
output += fmt.Sprintf("Exhausted Inbounds count:\r\n🛑 Disabled: %d\r\n🔜 Exhaust soon: %d\r\n \r\n", len(disabledInbounds), len(exhaustedInbounds))
- if len(disabledInbounds)+len(exhaustedInbounds) > 0 {
+ if len(exhaustedInbounds) > 0 {
output += "Exhausted Inbounds:\r\n"
for _, inbound := range exhaustedInbounds {
output += fmt.Sprintf("📍Inbound:%s\r\nPort:%d\r\nTraffic: %s (↑%s,↓%s)\r\n", inbound.Remark, inbound.Port, common.FormatTraffic((inbound.Up + inbound.Down)), common.FormatTraffic(inbound.Up), common.FormatTraffic(inbound.Down))
@@ -514,7 +514,7 @@ func (t *Tgbot) getExhausted() string {
}
}
output += fmt.Sprintf("Exhausted Clients count:\r\n🛑 Disabled: %d\r\n🔜 Exhaust soon: %d\r\n \r\n", len(disabledClients), len(exhaustedClients))
- if len(disabledClients)+len(exhaustedClients) > 0 {
+ if len(exhaustedClients) > 0 {
output += "Exhausted Clients:\r\n"
for _, traffic := range exhaustedClients {
expiryTime := ""
@@ -529,7 +529,7 @@ func (t *Tgbot) getExhausted() string {
} else {
total = common.FormatTraffic((traffic.Total))
}
- output += fmt.Sprintf("💡 Active: %t\r\n📧 Email: %s\r\n🔼 Upload↑: %s\r\n🔽 Download↓: %s\r\n🔄 Total: %s / %s\r\n📅 Expire in: %s\r\n",
+ output += fmt.Sprintf("💡 Active: %t\r\n📧 Email: %s\r\n🔼 Upload↑: %s\r\n🔽 Download↓: %s\r\n🔄 Total: %s / %s\r\n📅 Expire date: %s\r\n \r\n",
traffic.Enable, traffic.Email, common.FormatTraffic(traffic.Up), common.FormatTraffic(traffic.Down), common.FormatTraffic((traffic.Up + traffic.Down)),
total, expiryTime)
}
--
cgit v1.2.3
From a6dfdcdd316f53444a30ae7fa6038f252f1b20b7 Mon Sep 17 00:00:00 2001
From: MHSanaei <33454419+MHSanaei@users.noreply.github.com>
Date: Fri, 24 Mar 2023 17:08:30 +0330
Subject: Add version and log
---
web/service/inbound.go | 10 +++++++++
web/service/server.go | 47 ++++++++++++++++++++++++++++++---------
web/service/tgbot.go | 60 ++++++++++++++++++++++++++++++++++++++++++++------
3 files changed, 99 insertions(+), 18 deletions(-)
(limited to 'web/service')
diff --git a/web/service/inbound.go b/web/service/inbound.go
index b6f4f031..9814b549 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -634,3 +634,13 @@ func (s *InboundService) ClearClientIps(clientEmail string) error {
}
return nil
}
+
+func (s *InboundService) SearchInbounds(query string) ([]*model.Inbound, error) {
+ db := database.GetDB()
+ var inbounds []*model.Inbound
+ err := db.Model(model.Inbound{}).Preload("ClientStats").Where("remark like ?", "%"+query+"%").Find(&inbounds).Error
+ if err != nil && err != gorm.ErrRecordNotFound {
+ return nil, err
+ }
+ return inbounds, nil
+}
\ No newline at end of file
diff --git a/web/service/server.go b/web/service/server.go
index 6737bef2..5e6065b5 100644
--- a/web/service/server.go
+++ b/web/service/server.go
@@ -9,7 +9,9 @@ import (
"io/fs"
"net/http"
"os"
+ "os/exec"
"runtime"
+ "strings"
"time"
"x-ui/logger"
"x-ui/util/sys"
@@ -200,24 +202,24 @@ func (s *ServerService) GetXrayVersions() ([]string, error) {
func (s *ServerService) StopXrayService() (string error) {
- err := s.xrayService.StopXray()
- if err != nil {
- logger.Error("stop xray failed:", err)
- return err
- }
+ err := s.xrayService.StopXray()
+ if err != nil {
+ logger.Error("stop xray failed:", err)
+ return err
+ }
return nil
}
func (s *ServerService) RestartXrayService() (string error) {
- s.xrayService.StopXray()
- defer func() {
- err := s.xrayService.RestartXray(true)
- if err != nil {
- logger.Error("start xray failed:", err)
+ s.xrayService.StopXray()
+ defer func() {
+ err := s.xrayService.RestartXray(true)
+ if err != nil {
+ logger.Error("start xray failed:", err)
}
- }()
+ }()
return nil
}
@@ -324,3 +326,26 @@ func (s *ServerService) UpdateXray(version string) error {
return nil
}
+
+func (s *ServerService) GetLogs() ([]string, error) {
+ // Define the journalctl command and its arguments
+ var cmdArgs []string
+ if runtime.GOOS == "linux" {
+ cmdArgs = []string{"journalctl", "-u", "x-ui", "--no-pager", "-n", "100"}
+ } else {
+ return []string{"Unsupported operating system"}, nil
+ }
+
+ // Run the command
+ cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
+ var out bytes.Buffer
+ cmd.Stdout = &out
+ err := cmd.Run()
+ if err != nil {
+ return nil, err
+ }
+
+ lines := strings.Split(out.String(), "\n")
+
+ return lines, nil
+}
diff --git a/web/service/tgbot.go b/web/service/tgbot.go
index e88edbdf..86097b0f 100644
--- a/web/service/tgbot.go
+++ b/web/service/tgbot.go
@@ -105,8 +105,6 @@ func (t *Tgbot) OnReceive() {
} else {
if update.Message.IsCommand() {
t.answerCommand(update.Message, chatId, isAdmin)
- } else {
- t.aswerChat(update.Message.Text, chatId, isAdmin)
}
}
}
@@ -137,16 +135,18 @@ func (t *Tgbot) answerCommand(message *tgbotapi.Message, chatId int64, isAdmin b
} else {
msg = "âť—Please provide a text for search!"
}
+ case "inbound":
+ if isAdmin {
+ t.searchInbound(chatId, message.CommandArguments())
+ } else {
+ msg = "âť— Unknown command"
+ }
default:
msg = "âť— Unknown command"
}
t.SendAnswer(chatId, msg, isAdmin)
}
-func (t *Tgbot) aswerChat(message string, chatId int64, isAdmin bool) {
- t.SendAnswer(chatId, "âť— Unknown message", isAdmin)
-}
-
func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bool) {
// Respond to the callback query, telling Telegram to show the user
// a message with the data received.
@@ -169,7 +169,7 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo
case "client_commands":
t.SendMsgToTgbot(callbackQuery.From.ID, "To search for statistics, just use folowing command:\r\n \r\n/usage [UID|Passowrd]\r\n \r\nUse UID for vmess and vless and Password for Trojan.")
case "commands":
- t.SendMsgToTgbot(callbackQuery.From.ID, "To search for a client email, just use folowing command:\r\n \r\n/usage email")
+ t.SendMsgToTgbot(callbackQuery.From.ID, "Search for a client email:\r\n/usage email\r\n \r\nSearch for inbounds (with client stats):\r\n/inbound [remark]")
}
}
@@ -276,6 +276,7 @@ func (t *Tgbot) getServerUsage() string {
name = ""
}
info = fmt.Sprintf("đź’» Hostname: %s\r\n", name)
+ info += fmt.Sprintf("🚀X-UI Version: %s\r\n", config.GetVersion())
//get ip address
var ip string
var ipv6 string
@@ -427,6 +428,45 @@ func (t *Tgbot) searchClient(chatId int64, email string) {
}
}
+func (t *Tgbot) searchInbound(chatId int64, remark string) {
+ inbouds, err := t.inboundService.SearchInbounds(remark)
+ if err != nil {
+ logger.Warning(err)
+ msg := "❌ Something went wrong!"
+ t.SendMsgToTgbot(chatId, msg)
+ return
+ }
+ for _, inbound := range inbouds {
+ info := ""
+ info += fmt.Sprintf("📍Inbound:%s\r\nPort:%d\r\n", inbound.Remark, inbound.Port)
+ info += fmt.Sprintf("Traffic: %s (↑%s,↓%s)\r\n", common.FormatTraffic((inbound.Up + inbound.Down)), common.FormatTraffic(inbound.Up), common.FormatTraffic(inbound.Down))
+ if inbound.ExpiryTime == 0 {
+ info += "Expire date: ♾ Unlimited\r\n \r\n"
+ } else {
+ info += fmt.Sprintf("Expire date:%s\r\n \r\n", time.Unix((inbound.ExpiryTime/1000), 0).Format("2006-01-02 15:04:05"))
+ }
+ t.SendMsgToTgbot(chatId, info)
+ for _, traffic := range inbound.ClientStats {
+ expiryTime := ""
+ if traffic.ExpiryTime == 0 {
+ expiryTime = "♾Unlimited"
+ } else {
+ expiryTime = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
+ }
+ total := ""
+ if traffic.Total == 0 {
+ total = "♾Unlimited"
+ } else {
+ total = common.FormatTraffic((traffic.Total))
+ }
+ output := fmt.Sprintf("💡 Active: %t\r\n📧 Email: %s\r\n🔼 Upload↑: %s\r\n🔽 Download↓: %s\r\n🔄 Total: %s / %s\r\n📅 Expire in: %s\r\n",
+ traffic.Enable, traffic.Email, common.FormatTraffic(traffic.Up), common.FormatTraffic(traffic.Down), common.FormatTraffic((traffic.Up + traffic.Down)),
+ total, expiryTime)
+ t.SendMsgToTgbot(chatId, output)
+ }
+ }
+}
+
func (t *Tgbot) searchForClient(chatId int64, query string) {
traffic, err := t.inboundService.SearchClientTraffic(query)
if err != nil {
@@ -547,4 +587,10 @@ func (t *Tgbot) sendBackup(chatId int64) {
if err != nil {
logger.Warning("Error in uploading backup: ", err)
}
+ file = tgbotapi.FilePath(xray.GetConfigPath())
+ msg = tgbotapi.NewDocument(chatId, file)
+ _, err = bot.Send(msg)
+ if err != nil {
+ logger.Warning("Error in uploading config.json: ", err)
+ }
}
--
cgit v1.2.3
From 826c7264b5cbea4e4149645bef220fd3c6a010e7 Mon Sep 17 00:00:00 2001
From: MHSanaei <33454419+MHSanaei@users.noreply.github.com>
Date: Fri, 24 Mar 2023 17:13:31 +0330
Subject: Add version and log
TGBOT: Add xray config to backup
[TGBOT] add seach inbound
---
web/service/inbound.go | 10 ---------
web/service/server.go | 47 +++++++++------------------------------
web/service/tgbot.go | 60 ++++++--------------------------------------------
3 files changed, 18 insertions(+), 99 deletions(-)
(limited to 'web/service')
diff --git a/web/service/inbound.go b/web/service/inbound.go
index 9814b549..b6f4f031 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -634,13 +634,3 @@ func (s *InboundService) ClearClientIps(clientEmail string) error {
}
return nil
}
-
-func (s *InboundService) SearchInbounds(query string) ([]*model.Inbound, error) {
- db := database.GetDB()
- var inbounds []*model.Inbound
- err := db.Model(model.Inbound{}).Preload("ClientStats").Where("remark like ?", "%"+query+"%").Find(&inbounds).Error
- if err != nil && err != gorm.ErrRecordNotFound {
- return nil, err
- }
- return inbounds, nil
-}
\ No newline at end of file
diff --git a/web/service/server.go b/web/service/server.go
index 5e6065b5..6737bef2 100644
--- a/web/service/server.go
+++ b/web/service/server.go
@@ -9,9 +9,7 @@ import (
"io/fs"
"net/http"
"os"
- "os/exec"
"runtime"
- "strings"
"time"
"x-ui/logger"
"x-ui/util/sys"
@@ -202,24 +200,24 @@ func (s *ServerService) GetXrayVersions() ([]string, error) {
func (s *ServerService) StopXrayService() (string error) {
- err := s.xrayService.StopXray()
- if err != nil {
- logger.Error("stop xray failed:", err)
- return err
- }
+ err := s.xrayService.StopXray()
+ if err != nil {
+ logger.Error("stop xray failed:", err)
+ return err
+ }
return nil
}
func (s *ServerService) RestartXrayService() (string error) {
- s.xrayService.StopXray()
- defer func() {
- err := s.xrayService.RestartXray(true)
- if err != nil {
- logger.Error("start xray failed:", err)
+ s.xrayService.StopXray()
+ defer func() {
+ err := s.xrayService.RestartXray(true)
+ if err != nil {
+ logger.Error("start xray failed:", err)
}
- }()
+ }()
return nil
}
@@ -326,26 +324,3 @@ func (s *ServerService) UpdateXray(version string) error {
return nil
}
-
-func (s *ServerService) GetLogs() ([]string, error) {
- // Define the journalctl command and its arguments
- var cmdArgs []string
- if runtime.GOOS == "linux" {
- cmdArgs = []string{"journalctl", "-u", "x-ui", "--no-pager", "-n", "100"}
- } else {
- return []string{"Unsupported operating system"}, nil
- }
-
- // Run the command
- cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
- var out bytes.Buffer
- cmd.Stdout = &out
- err := cmd.Run()
- if err != nil {
- return nil, err
- }
-
- lines := strings.Split(out.String(), "\n")
-
- return lines, nil
-}
diff --git a/web/service/tgbot.go b/web/service/tgbot.go
index 86097b0f..e88edbdf 100644
--- a/web/service/tgbot.go
+++ b/web/service/tgbot.go
@@ -105,6 +105,8 @@ func (t *Tgbot) OnReceive() {
} else {
if update.Message.IsCommand() {
t.answerCommand(update.Message, chatId, isAdmin)
+ } else {
+ t.aswerChat(update.Message.Text, chatId, isAdmin)
}
}
}
@@ -135,18 +137,16 @@ func (t *Tgbot) answerCommand(message *tgbotapi.Message, chatId int64, isAdmin b
} else {
msg = "âť—Please provide a text for search!"
}
- case "inbound":
- if isAdmin {
- t.searchInbound(chatId, message.CommandArguments())
- } else {
- msg = "âť— Unknown command"
- }
default:
msg = "âť— Unknown command"
}
t.SendAnswer(chatId, msg, isAdmin)
}
+func (t *Tgbot) aswerChat(message string, chatId int64, isAdmin bool) {
+ t.SendAnswer(chatId, "âť— Unknown message", isAdmin)
+}
+
func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bool) {
// Respond to the callback query, telling Telegram to show the user
// a message with the data received.
@@ -169,7 +169,7 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo
case "client_commands":
t.SendMsgToTgbot(callbackQuery.From.ID, "To search for statistics, just use folowing command:\r\n \r\n/usage [UID|Passowrd]\r\n \r\nUse UID for vmess and vless and Password for Trojan.")
case "commands":
- t.SendMsgToTgbot(callbackQuery.From.ID, "Search for a client email:\r\n/usage email\r\n \r\nSearch for inbounds (with client stats):\r\n/inbound [remark]")
+ t.SendMsgToTgbot(callbackQuery.From.ID, "To search for a client email, just use folowing command:\r\n \r\n/usage email")
}
}
@@ -276,7 +276,6 @@ func (t *Tgbot) getServerUsage() string {
name = ""
}
info = fmt.Sprintf("đź’» Hostname: %s\r\n", name)
- info += fmt.Sprintf("🚀X-UI Version: %s\r\n", config.GetVersion())
//get ip address
var ip string
var ipv6 string
@@ -428,45 +427,6 @@ func (t *Tgbot) searchClient(chatId int64, email string) {
}
}
-func (t *Tgbot) searchInbound(chatId int64, remark string) {
- inbouds, err := t.inboundService.SearchInbounds(remark)
- if err != nil {
- logger.Warning(err)
- msg := "❌ Something went wrong!"
- t.SendMsgToTgbot(chatId, msg)
- return
- }
- for _, inbound := range inbouds {
- info := ""
- info += fmt.Sprintf("📍Inbound:%s\r\nPort:%d\r\n", inbound.Remark, inbound.Port)
- info += fmt.Sprintf("Traffic: %s (↑%s,↓%s)\r\n", common.FormatTraffic((inbound.Up + inbound.Down)), common.FormatTraffic(inbound.Up), common.FormatTraffic(inbound.Down))
- if inbound.ExpiryTime == 0 {
- info += "Expire date: ♾ Unlimited\r\n \r\n"
- } else {
- info += fmt.Sprintf("Expire date:%s\r\n \r\n", time.Unix((inbound.ExpiryTime/1000), 0).Format("2006-01-02 15:04:05"))
- }
- t.SendMsgToTgbot(chatId, info)
- for _, traffic := range inbound.ClientStats {
- expiryTime := ""
- if traffic.ExpiryTime == 0 {
- expiryTime = "♾Unlimited"
- } else {
- expiryTime = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
- }
- total := ""
- if traffic.Total == 0 {
- total = "♾Unlimited"
- } else {
- total = common.FormatTraffic((traffic.Total))
- }
- output := fmt.Sprintf("💡 Active: %t\r\n📧 Email: %s\r\n🔼 Upload↑: %s\r\n🔽 Download↓: %s\r\n🔄 Total: %s / %s\r\n📅 Expire in: %s\r\n",
- traffic.Enable, traffic.Email, common.FormatTraffic(traffic.Up), common.FormatTraffic(traffic.Down), common.FormatTraffic((traffic.Up + traffic.Down)),
- total, expiryTime)
- t.SendMsgToTgbot(chatId, output)
- }
- }
-}
-
func (t *Tgbot) searchForClient(chatId int64, query string) {
traffic, err := t.inboundService.SearchClientTraffic(query)
if err != nil {
@@ -587,10 +547,4 @@ func (t *Tgbot) sendBackup(chatId int64) {
if err != nil {
logger.Warning("Error in uploading backup: ", err)
}
- file = tgbotapi.FilePath(xray.GetConfigPath())
- msg = tgbotapi.NewDocument(chatId, file)
- _, err = bot.Send(msg)
- if err != nil {
- logger.Warning("Error in uploading config.json: ", err)
- }
}
--
cgit v1.2.3
From 9c0718bc44037d6415bcf3bcb300de62c67ad782 Mon Sep 17 00:00:00 2001
From: MHSanaei <33454419+MHSanaei@users.noreply.github.com>
Date: Fri, 24 Mar 2023 17:14:26 +0330
Subject: Revert "Add version and log"
This reverts commit 826c7264b5cbea4e4149645bef220fd3c6a010e7.
---
web/service/inbound.go | 10 +++++++++
web/service/server.go | 47 ++++++++++++++++++++++++++++++---------
web/service/tgbot.go | 60 ++++++++++++++++++++++++++++++++++++++++++++------
3 files changed, 99 insertions(+), 18 deletions(-)
(limited to 'web/service')
diff --git a/web/service/inbound.go b/web/service/inbound.go
index b6f4f031..9814b549 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -634,3 +634,13 @@ func (s *InboundService) ClearClientIps(clientEmail string) error {
}
return nil
}
+
+func (s *InboundService) SearchInbounds(query string) ([]*model.Inbound, error) {
+ db := database.GetDB()
+ var inbounds []*model.Inbound
+ err := db.Model(model.Inbound{}).Preload("ClientStats").Where("remark like ?", "%"+query+"%").Find(&inbounds).Error
+ if err != nil && err != gorm.ErrRecordNotFound {
+ return nil, err
+ }
+ return inbounds, nil
+}
\ No newline at end of file
diff --git a/web/service/server.go b/web/service/server.go
index 6737bef2..5e6065b5 100644
--- a/web/service/server.go
+++ b/web/service/server.go
@@ -9,7 +9,9 @@ import (
"io/fs"
"net/http"
"os"
+ "os/exec"
"runtime"
+ "strings"
"time"
"x-ui/logger"
"x-ui/util/sys"
@@ -200,24 +202,24 @@ func (s *ServerService) GetXrayVersions() ([]string, error) {
func (s *ServerService) StopXrayService() (string error) {
- err := s.xrayService.StopXray()
- if err != nil {
- logger.Error("stop xray failed:", err)
- return err
- }
+ err := s.xrayService.StopXray()
+ if err != nil {
+ logger.Error("stop xray failed:", err)
+ return err
+ }
return nil
}
func (s *ServerService) RestartXrayService() (string error) {
- s.xrayService.StopXray()
- defer func() {
- err := s.xrayService.RestartXray(true)
- if err != nil {
- logger.Error("start xray failed:", err)
+ s.xrayService.StopXray()
+ defer func() {
+ err := s.xrayService.RestartXray(true)
+ if err != nil {
+ logger.Error("start xray failed:", err)
}
- }()
+ }()
return nil
}
@@ -324,3 +326,26 @@ func (s *ServerService) UpdateXray(version string) error {
return nil
}
+
+func (s *ServerService) GetLogs() ([]string, error) {
+ // Define the journalctl command and its arguments
+ var cmdArgs []string
+ if runtime.GOOS == "linux" {
+ cmdArgs = []string{"journalctl", "-u", "x-ui", "--no-pager", "-n", "100"}
+ } else {
+ return []string{"Unsupported operating system"}, nil
+ }
+
+ // Run the command
+ cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
+ var out bytes.Buffer
+ cmd.Stdout = &out
+ err := cmd.Run()
+ if err != nil {
+ return nil, err
+ }
+
+ lines := strings.Split(out.String(), "\n")
+
+ return lines, nil
+}
diff --git a/web/service/tgbot.go b/web/service/tgbot.go
index e88edbdf..86097b0f 100644
--- a/web/service/tgbot.go
+++ b/web/service/tgbot.go
@@ -105,8 +105,6 @@ func (t *Tgbot) OnReceive() {
} else {
if update.Message.IsCommand() {
t.answerCommand(update.Message, chatId, isAdmin)
- } else {
- t.aswerChat(update.Message.Text, chatId, isAdmin)
}
}
}
@@ -137,16 +135,18 @@ func (t *Tgbot) answerCommand(message *tgbotapi.Message, chatId int64, isAdmin b
} else {
msg = "âť—Please provide a text for search!"
}
+ case "inbound":
+ if isAdmin {
+ t.searchInbound(chatId, message.CommandArguments())
+ } else {
+ msg = "âť— Unknown command"
+ }
default:
msg = "âť— Unknown command"
}
t.SendAnswer(chatId, msg, isAdmin)
}
-func (t *Tgbot) aswerChat(message string, chatId int64, isAdmin bool) {
- t.SendAnswer(chatId, "âť— Unknown message", isAdmin)
-}
-
func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bool) {
// Respond to the callback query, telling Telegram to show the user
// a message with the data received.
@@ -169,7 +169,7 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo
case "client_commands":
t.SendMsgToTgbot(callbackQuery.From.ID, "To search for statistics, just use folowing command:\r\n \r\n/usage [UID|Passowrd]\r\n \r\nUse UID for vmess and vless and Password for Trojan.")
case "commands":
- t.SendMsgToTgbot(callbackQuery.From.ID, "To search for a client email, just use folowing command:\r\n \r\n/usage email")
+ t.SendMsgToTgbot(callbackQuery.From.ID, "Search for a client email:\r\n/usage email\r\n \r\nSearch for inbounds (with client stats):\r\n/inbound [remark]")
}
}
@@ -276,6 +276,7 @@ func (t *Tgbot) getServerUsage() string {
name = ""
}
info = fmt.Sprintf("đź’» Hostname: %s\r\n", name)
+ info += fmt.Sprintf("🚀X-UI Version: %s\r\n", config.GetVersion())
//get ip address
var ip string
var ipv6 string
@@ -427,6 +428,45 @@ func (t *Tgbot) searchClient(chatId int64, email string) {
}
}
+func (t *Tgbot) searchInbound(chatId int64, remark string) {
+ inbouds, err := t.inboundService.SearchInbounds(remark)
+ if err != nil {
+ logger.Warning(err)
+ msg := "❌ Something went wrong!"
+ t.SendMsgToTgbot(chatId, msg)
+ return
+ }
+ for _, inbound := range inbouds {
+ info := ""
+ info += fmt.Sprintf("📍Inbound:%s\r\nPort:%d\r\n", inbound.Remark, inbound.Port)
+ info += fmt.Sprintf("Traffic: %s (↑%s,↓%s)\r\n", common.FormatTraffic((inbound.Up + inbound.Down)), common.FormatTraffic(inbound.Up), common.FormatTraffic(inbound.Down))
+ if inbound.ExpiryTime == 0 {
+ info += "Expire date: ♾ Unlimited\r\n \r\n"
+ } else {
+ info += fmt.Sprintf("Expire date:%s\r\n \r\n", time.Unix((inbound.ExpiryTime/1000), 0).Format("2006-01-02 15:04:05"))
+ }
+ t.SendMsgToTgbot(chatId, info)
+ for _, traffic := range inbound.ClientStats {
+ expiryTime := ""
+ if traffic.ExpiryTime == 0 {
+ expiryTime = "♾Unlimited"
+ } else {
+ expiryTime = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
+ }
+ total := ""
+ if traffic.Total == 0 {
+ total = "♾Unlimited"
+ } else {
+ total = common.FormatTraffic((traffic.Total))
+ }
+ output := fmt.Sprintf("💡 Active: %t\r\n📧 Email: %s\r\n🔼 Upload↑: %s\r\n🔽 Download↓: %s\r\n🔄 Total: %s / %s\r\n📅 Expire in: %s\r\n",
+ traffic.Enable, traffic.Email, common.FormatTraffic(traffic.Up), common.FormatTraffic(traffic.Down), common.FormatTraffic((traffic.Up + traffic.Down)),
+ total, expiryTime)
+ t.SendMsgToTgbot(chatId, output)
+ }
+ }
+}
+
func (t *Tgbot) searchForClient(chatId int64, query string) {
traffic, err := t.inboundService.SearchClientTraffic(query)
if err != nil {
@@ -547,4 +587,10 @@ func (t *Tgbot) sendBackup(chatId int64) {
if err != nil {
logger.Warning("Error in uploading backup: ", err)
}
+ file = tgbotapi.FilePath(xray.GetConfigPath())
+ msg = tgbotapi.NewDocument(chatId, file)
+ _, err = bot.Send(msg)
+ if err != nil {
+ logger.Warning("Error in uploading config.json: ", err)
+ }
}
--
cgit v1.2.3