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:
authorHo3ein <ho3ein.sanaei@gmail.com>2023-05-31 09:17:02 +0300
committerGitHub <noreply@github.com>2023-05-31 09:17:02 +0300
commit94fad02737d82817ca69f1f05872b49e769a0cb4 (patch)
tree55e7ead217c5a3e82791c0edae6ad44de1ba524f /web/service
parent8442836512d82b705e404bc1749e3000115ba550 (diff)
parentd694e6eafccad246c63264714897316f671d6428 (diff)
Merge pull request #545 from hamid-gh98/main
🔀 New Feature + Fix URLs + Some Improvements 🛠️🌐
Diffstat (limited to 'web/service')
-rw-r--r--web/service/inbound.go1
-rw-r--r--web/service/setting.go7
-rw-r--r--web/service/tgbot.go47
3 files changed, 38 insertions, 17 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go
index 6a182fcf..11522ad2 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -1185,6 +1185,7 @@ func (s *InboundService) GetInboundClientIps(clientEmail string) (string, error)
}
return InboundClientIps.Ips, nil
}
+
func (s *InboundService) ClearClientIps(clientEmail string) error {
db := database.GetDB()
diff --git a/web/service/setting.go b/web/service/setting.go
index 593b23be..677ccbb2 100644
--- a/web/service/setting.go
+++ b/web/service/setting.go
@@ -24,6 +24,7 @@ var xrayTemplateConfig string
var defaultValueMap = map[string]string{
"xrayTemplateConfig": xrayTemplateConfig,
"webListen": "",
+ "webDomain": "",
"webPort": "2053",
"webCertFile": "",
"webKeyFile": "",
@@ -44,7 +45,7 @@ var defaultValueMap = map[string]string{
"subEnable": "false",
"subListen": "",
"subPort": "2096",
- "subPath": "sub/",
+ "subPath": "/sub/",
"subDomain": "",
"subCertFile": "",
"subKeyFile": "",
@@ -225,6 +226,10 @@ func (s *SettingService) GetListen() (string, error) {
return s.getString("webListen")
}
+func (s *SettingService) GetWebDomain() (string, error) {
+ return s.getString("webDomain")
+}
+
func (s *SettingService) GetTgBotToken() (string, error) {
return s.getString("tgBotToken")
}
diff --git a/web/service/tgbot.go b/web/service/tgbot.go
index e0261775..d1a1e3fe 100644
--- a/web/service/tgbot.go
+++ b/web/service/tgbot.go
@@ -77,13 +77,15 @@ func (t *Tgbot) Start(i18nFS embed.FS) error {
return err
}
- for _, adminId := range strings.Split(tgBotid, ",") {
- id, err := strconv.Atoi(adminId)
- if err != nil {
- logger.Warning("Failed to get IDs from GetTgBotChatId:", err)
- return err
+ if tgBotid != "" {
+ for _, adminId := range strings.Split(tgBotid, ",") {
+ id, err := strconv.Atoi(adminId)
+ if err != nil {
+ logger.Warning("Failed to get IDs from GetTgBotChatId:", err)
+ return err
+ }
+ adminIds = append(adminIds, int64(id))
}
- adminIds = append(adminIds, int64(id))
}
bot, err = telego.NewBot(tgBottoken)
@@ -188,7 +190,7 @@ func (t *Tgbot) OnReceive() {
}
func (t *Tgbot) answerCommand(message *telego.Message, chatId int64, isAdmin bool) {
- msg := ""
+ msg, onlyMessage := "", false
command, commandArgs := tu.ParseCommand(message.Text)
@@ -204,8 +206,13 @@ func (t *Tgbot) answerCommand(message *telego.Message, chatId int64, isAdmin boo
}
msg += "\n\n" + t.I18nBot("tgbot.commands.pleaseChoose")
case "status":
+ onlyMessage = true
msg += t.I18nBot("tgbot.commands.status")
+ case "id":
+ onlyMessage = true
+ msg += t.I18nBot("tgbot.commands.getID", "ID=="+strconv.FormatInt(message.From.ID, 10))
case "usage":
+ onlyMessage = true
if len(commandArgs) > 0 {
if isAdmin {
t.searchClient(chatId, commandArgs[0])
@@ -216,6 +223,7 @@ func (t *Tgbot) answerCommand(message *telego.Message, chatId int64, isAdmin boo
msg += t.I18nBot("tgbot.commands.usage")
}
case "inbound":
+ onlyMessage = true
if isAdmin && len(commandArgs) > 0 {
t.searchInbound(chatId, commandArgs[0])
} else {
@@ -224,6 +232,11 @@ func (t *Tgbot) answerCommand(message *telego.Message, chatId int64, isAdmin boo
default:
msg += t.I18nBot("tgbot.commands.unknown")
}
+
+ if onlyMessage {
+ t.SendMsgToTgbot(chatId, msg)
+ return
+ }
t.SendAnswer(chatId, msg, isAdmin)
}
@@ -498,6 +511,7 @@ func (t *Tgbot) SendMsgToTgbot(chatId int64, msg string, replyMarkup ...telego.R
if !isRunning {
return
}
+
if msg == "" {
logger.Info("[tgbot] message is empty!")
return
@@ -723,7 +737,7 @@ func (t *Tgbot) getClientUsage(chatId int64, tgUserName string, tgUserID string)
output := ""
output += t.I18nBot("tgbot.messages.email", "Email=="+traffic.Email)
- if (traffic.Enable) {
+ if traffic.Enable {
output += t.I18nBot("tgbot.messages.active")
if flag {
output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime)
@@ -791,6 +805,7 @@ func (t *Tgbot) clientTelegramUserInfo(chatId int64, email string, messageID ...
output := ""
output += t.I18nBot("tgbot.messages.email", "Email=="+email)
output += t.I18nBot("tgbot.messages.TGUser", "TelegramID=="+tgId)
+ output += t.I18nBot("tgbot.messages.refreshedOn", "Time=="+time.Now().Format("2006-01-02 15:04:05"))
inlineKeyboard := tu.InlineKeyboard(
tu.InlineKeyboardRow(
@@ -840,7 +855,7 @@ func (t *Tgbot) searchClient(chatId int64, email string, messageID ...int) {
flag := false
diff := traffic.ExpiryTime/1000 - now
if traffic.ExpiryTime == 0 {
- expiryTime = t.I18nBot("tgbot.unlimited")
+ expiryTime = t.I18nBot("tgbot.unlimited")
} else if diff > 172800 || !traffic.Enable {
expiryTime = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
} else if traffic.ExpiryTime < 0 {
@@ -860,7 +875,7 @@ func (t *Tgbot) searchClient(chatId int64, email string, messageID ...int) {
output := ""
output += t.I18nBot("tgbot.messages.email", "Email=="+traffic.Email)
- if (traffic.Enable) {
+ if traffic.Enable {
output += t.I18nBot("tgbot.messages.active")
if flag {
output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime)
@@ -918,7 +933,7 @@ func (t *Tgbot) searchInbound(chatId int64, remark string) {
t.SendMsgToTgbot(chatId, msg)
return
}
-
+
now := time.Now().Unix()
for _, inbound := range inbouds {
info := ""
@@ -958,7 +973,7 @@ func (t *Tgbot) searchInbound(chatId int64, remark string) {
output := ""
output += t.I18nBot("tgbot.messages.email", "Email=="+traffic.Email)
- if (traffic.Enable) {
+ if traffic.Enable {
output += t.I18nBot("tgbot.messages.active")
if flag {
output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime)
@@ -998,7 +1013,7 @@ func (t *Tgbot) searchForClient(chatId int64, query string) {
flag := false
diff := traffic.ExpiryTime/1000 - now
if traffic.ExpiryTime == 0 {
- expiryTime = t.I18nBot("tgbot.unlimited")
+ expiryTime = t.I18nBot("tgbot.unlimited")
} else if diff > 172800 || !traffic.Enable {
expiryTime = time.Unix((traffic.ExpiryTime / 1000), 0).Format("2006-01-02 15:04:05")
} else if traffic.ExpiryTime < 0 {
@@ -1018,7 +1033,7 @@ func (t *Tgbot) searchForClient(chatId int64, query string) {
output := ""
output += t.I18nBot("tgbot.messages.email", "Email=="+traffic.Email)
- if (traffic.Enable) {
+ if traffic.Enable {
output += t.I18nBot("tgbot.messages.active")
if flag {
output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime)
@@ -1117,7 +1132,7 @@ func (t *Tgbot) getExhausted() string {
for _, traffic := range exhaustedClients {
expiryTime := ""
flag := false
- diff := (traffic.ExpiryTime - now)/1000
+ diff := (traffic.ExpiryTime - now) / 1000
if traffic.ExpiryTime == 0 {
expiryTime = t.I18nBot("tgbot.unlimited")
} else if diff > 172800 || !traffic.Enable {
@@ -1138,7 +1153,7 @@ func (t *Tgbot) getExhausted() string {
}
output += t.I18nBot("tgbot.messages.email", "Email=="+traffic.Email)
- if (traffic.Enable) {
+ if traffic.Enable {
output += t.I18nBot("tgbot.messages.active")
if flag {
output += t.I18nBot("tgbot.messages.expireIn", "Time=="+expiryTime)