|
@@ -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<code>/usage [UID|Passowrd]</code>\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<code>/usage email</code>")
|
|
|
+ t.SendMsgToTgbot(callbackQuery.From.ID, "Search for a client email:\r\n<code>/usage email</code>\r\n \r\nSearch for inbounds (with client stats):\r\n<code>/inbound [remark]</code>")
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -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)
|
|
|
+ }
|
|
|
}
|