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:
authorMasoud Hidden <masoud.hidden.user@gmail.com>2023-05-05 04:04:39 +0300
committerMasoud Hidden <masoud.hidden.user@gmail.com>2023-05-05 04:04:39 +0300
commita53d2b927fdc4f543589750d761428f591cabaf7 (patch)
tree7c3f80ec56f5e93a5d6e4eacb97a0796e7f53ea4 /web/service
parentc6295085fe73fa1b2a168e02083ffadbdb4dedf6 (diff)
fix ResetClientExpiryTimeByEmail
Diffstat (limited to 'web/service')
-rw-r--r--web/service/inbound.go65
-rw-r--r--web/service/tgbot.go24
2 files changed, 69 insertions, 20 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go
index 95c3d745..5d80c816 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -664,19 +664,72 @@ func (s *InboundService) DelClientIPs(tx *gorm.DB, email string) error {
return tx.Where("client_email = ?", email).Delete(model.InboundClientIps{}).Error
}
-func (s *InboundService) ResetClientExpiryTimeByEmail(clientEmail string, expiry_time int64) error {
+func (s *InboundService) GetClientInboundByEmail(email string) (inbound *model.Inbound, err error) {
db := database.GetDB()
+ var traffics []*xray.ClientTraffic
+ err = db.Model(xray.ClientTraffic{}).Where("email = ?", email).Find(&traffics).Error
+ if err != nil {
+ logger.Warning(err)
+ return nil, err
+ }
+ if len(traffics) > 0 {
+ return s.GetInbound(traffics[0].InboundId)
+ }
+ return nil, nil
+}
- result := db.Model(xray.ClientTraffic{}).
- Where("email = ?", clientEmail).
- Updates(map[string]interface{}{"enable": true, "expiry_time": expiry_time})
+func (s *InboundService) ResetClientExpiryTimeByEmail(clientEmail string, expiry_time int64) error {
+ inbound, err := s.GetClientInboundByEmail(clientEmail)
+ if err != nil {
+ return err
+ }
+ if inbound == nil {
+ return common.NewError("Inbound Not Found For Email:", clientEmail)
+ }
- err := result.Error
+ oldClients, err := s.getClients(inbound)
+ if err != nil {
+ return err
+ }
+
+ clientId := ""
+
+ for _, oldClient := range oldClients {
+ if oldClient.Email == clientEmail {
+ if inbound.Protocol == "trojan" {
+ clientId = oldClient.Password
+ } else {
+ clientId = oldClient.ID
+ }
+ break
+ }
+ }
+
+ if len(clientId) == 0 {
+ return common.NewError("Client Not Found For Email:", clientEmail)
+ }
+ var settings map[string]interface{}
+ err = json.Unmarshal([]byte(inbound.Settings), &settings)
if err != nil {
return err
}
- return nil
+ clients := settings["clients"].([]interface{})
+ var newClients []interface{}
+ for client_index := range clients {
+ c := clients[client_index].(map[string]interface{})
+ if c["email"] == clientEmail {
+ c["expiryTime"] = expiry_time
+ newClients = append(newClients, interface{}(c))
+ }
+ }
+ settings["clients"] = newClients
+ modifiedSettings, err := json.MarshalIndent(settings, "", " ")
+ if err != nil {
+ return err
+ }
+ inbound.Settings = string(modifiedSettings)
+ return s.UpdateInboundClient(inbound, clientId)
}
func (s *InboundService) ResetClientTrafficByEmail(clientEmail string) error {
diff --git a/web/service/tgbot.go b/web/service/tgbot.go
index ef5d2abd..eca082b5 100644
--- a/web/service/tgbot.go
+++ b/web/service/tgbot.go
@@ -172,8 +172,8 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo
)
t.editMessageCallbackTgBot(callbackQuery.From.ID, callbackQuery.Message.MessageID, inlineKeyboard)
case "reset_traffic_confirm":
- resetError := t.inboundService.ResetClientTrafficByEmail(email)
- if resetError == nil {
+ err := t.inboundService.ResetClientTrafficByEmail(email)
+ if err == nil {
t.xrayService.SetToNeedRestart()
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Traffic reset successfully.", email))
t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID)
@@ -207,28 +207,24 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo
)
t.editMessageCallbackTgBot(callbackQuery.From.ID, callbackQuery.Message.MessageID, inlineKeyboard)
case "reset_expire_days_confirm":
- err := len(dataArray) < 3
- if !err {
- days, err2 := strconv.Atoi(dataArray[2])
- if err2 == nil {
+ if len(dataArray) == 3 {
+ days, err := strconv.Atoi(dataArray[2])
+ if err == nil {
var date int64 = 0
if days > 0 {
date = int64(-(days * 24 * 60 * 60000))
}
- resetError := t.inboundService.ResetClientExpiryTimeByEmail(email, date)
- if resetError == nil {
+ err := t.inboundService.ResetClientExpiryTimeByEmail(email, date)
+ if err == nil {
t.xrayService.SetToNeedRestart()
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Expire days reset successfully.", email))
t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID)
+ return
}
- } else {
- err = true
}
}
- if err {
- t.sendCallbackAnswerTgBot(callbackQuery.ID, "❗ Error in Operation.")
- t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID)
- }
+ t.sendCallbackAnswerTgBot(callbackQuery.ID, "❗ Error in Operation.")
+ t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID)
}
return
}