mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
fix ResetClientExpiryTimeByEmail
This commit is contained in:
parent
c6295085fe
commit
a53d2b927f
2 changed files with 71 additions and 22 deletions
|
@ -664,19 +664,72 @@ func (s *InboundService) DelClientIPs(tx *gorm.DB, email string) error {
|
||||||
return tx.Where("client_email = ?", email).Delete(model.InboundClientIps{}).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()
|
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{}).
|
func (s *InboundService) ResetClientExpiryTimeByEmail(clientEmail string, expiry_time int64) error {
|
||||||
Where("email = ?", clientEmail).
|
inbound, err := s.GetClientInboundByEmail(clientEmail)
|
||||||
Updates(map[string]interface{}{"enable": true, "expiry_time": expiry_time})
|
|
||||||
|
|
||||||
err := result.Error
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
if inbound == nil {
|
||||||
|
return common.NewError("Inbound Not Found For Email:", clientEmail)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
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 {
|
func (s *InboundService) ResetClientTrafficByEmail(clientEmail string) error {
|
||||||
|
|
|
@ -172,8 +172,8 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo
|
||||||
)
|
)
|
||||||
t.editMessageCallbackTgBot(callbackQuery.From.ID, callbackQuery.Message.MessageID, inlineKeyboard)
|
t.editMessageCallbackTgBot(callbackQuery.From.ID, callbackQuery.Message.MessageID, inlineKeyboard)
|
||||||
case "reset_traffic_confirm":
|
case "reset_traffic_confirm":
|
||||||
resetError := t.inboundService.ResetClientTrafficByEmail(email)
|
err := t.inboundService.ResetClientTrafficByEmail(email)
|
||||||
if resetError == nil {
|
if err == nil {
|
||||||
t.xrayService.SetToNeedRestart()
|
t.xrayService.SetToNeedRestart()
|
||||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Traffic reset successfully.", email))
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Traffic reset successfully.", email))
|
||||||
t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID)
|
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)
|
t.editMessageCallbackTgBot(callbackQuery.From.ID, callbackQuery.Message.MessageID, inlineKeyboard)
|
||||||
case "reset_expire_days_confirm":
|
case "reset_expire_days_confirm":
|
||||||
err := len(dataArray) < 3
|
if len(dataArray) == 3 {
|
||||||
if !err {
|
days, err := strconv.Atoi(dataArray[2])
|
||||||
days, err2 := strconv.Atoi(dataArray[2])
|
if err == nil {
|
||||||
if err2 == nil {
|
|
||||||
var date int64 = 0
|
var date int64 = 0
|
||||||
if days > 0 {
|
if days > 0 {
|
||||||
date = int64(-(days * 24 * 60 * 60000))
|
date = int64(-(days * 24 * 60 * 60000))
|
||||||
}
|
}
|
||||||
resetError := t.inboundService.ResetClientExpiryTimeByEmail(email, date)
|
err := t.inboundService.ResetClientExpiryTimeByEmail(email, date)
|
||||||
if resetError == nil {
|
if err == nil {
|
||||||
t.xrayService.SetToNeedRestart()
|
t.xrayService.SetToNeedRestart()
|
||||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Expire days reset successfully.", email))
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Expire days reset successfully.", email))
|
||||||
t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID)
|
t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
err = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err {
|
t.sendCallbackAnswerTgBot(callbackQuery.ID, "❗ Error in Operation.")
|
||||||
t.sendCallbackAnswerTgBot(callbackQuery.ID, "❗ Error in Operation.")
|
t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID)
|
||||||
t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue