mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-03-02 01:30:51 +03:00
Fix del/update affects on clientIPs
This commit is contained in:
parent
a0d6f85837
commit
baaa814a51
@ -179,6 +179,20 @@ func (s *InboundService) DelInbound(id int) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
inbound, err := s.GetInbound(id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
clients, err := s.getClients(inbound)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, client := range clients {
|
||||||
|
err := db.Where("client_email = ?", client.Email).Delete(model.InboundClientIps{}).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return db.Delete(model.Inbound{}, id).Error
|
return db.Delete(model.Inbound{}, id).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,6 +300,12 @@ func (s *InboundService) DelInboundClient(inbound *model.Inbound, email string)
|
|||||||
|
|
||||||
oldInbound.Settings = inbound.Settings
|
oldInbound.Settings = inbound.Settings
|
||||||
|
|
||||||
|
err = s.DelClientIPs(db, email)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("Error in delete client IPs")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return db.Save(oldInbound).Error
|
return db.Save(oldInbound).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,12 +339,26 @@ func (s *InboundService) UpdateInboundClient(inbound *model.Inbound, index int)
|
|||||||
|
|
||||||
if len(clients[index].Email) > 0 {
|
if len(clients[index].Email) > 0 {
|
||||||
if len(oldClients[index].Email) > 0 {
|
if len(oldClients[index].Email) > 0 {
|
||||||
s.UpdateClientStat(oldClients[index].Email, &clients[index])
|
err = s.UpdateClientStat(oldClients[index].Email, &clients[index])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = s.UpdateClientIPs(db, oldClients[index].Email, clients[index].Email)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
s.AddClientStat(inbound.Id, &clients[index])
|
s.AddClientStat(inbound.Id, &clients[index])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
s.DelClientStat(db, oldClients[index].Email)
|
err = s.DelClientStat(db, oldClients[index].Email)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = s.DelClientIPs(db, oldClients[index].Email)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return db.Save(oldInbound).Error
|
return db.Save(oldInbound).Error
|
||||||
}
|
}
|
||||||
@ -483,8 +517,17 @@ func (s *InboundService) UpdateClientStat(email string, client *model.Client) er
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *InboundService) UpdateClientIPs(tx *gorm.DB, oldEmail string, newEmail string) error {
|
||||||
|
return tx.Model(model.InboundClientIps{}).Where("client_email = ?", oldEmail).Update("client_email", newEmail).Error
|
||||||
|
}
|
||||||
|
|
||||||
func (s *InboundService) DelClientStat(tx *gorm.DB, email string) error {
|
func (s *InboundService) DelClientStat(tx *gorm.DB, email string) error {
|
||||||
return tx.Where("email = ?", email).Delete(xray.ClientTraffic{}).Error
|
return tx.Where("client_email = ?", email).Delete(xray.ClientTraffic{}).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *InboundService) DelClientIPs(tx *gorm.DB, email string) error {
|
||||||
|
return tx.Where("email = ?", email).Delete(model.InboundClientIps{}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *InboundService) ResetClientTraffic(id int, clientEmail string) error {
|
func (s *InboundService) ResetClientTraffic(id int, clientEmail string) error {
|
||||||
@ -567,6 +610,7 @@ func (s *InboundService) SearchClientTraffic(query string) (traffic *xray.Client
|
|||||||
}
|
}
|
||||||
return traffic, err
|
return traffic, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *InboundService) GetInboundClientIps(clientEmail string) (string, error) {
|
func (s *InboundService) GetInboundClientIps(clientEmail string) (string, error) {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
InboundClientIps := &model.InboundClientIps{}
|
InboundClientIps := &model.InboundClientIps{}
|
||||||
@ -576,7 +620,7 @@ func (s *InboundService) GetInboundClientIps(clientEmail string) (string, error)
|
|||||||
}
|
}
|
||||||
return InboundClientIps.Ips, nil
|
return InboundClientIps.Ips, nil
|
||||||
}
|
}
|
||||||
func (s *InboundService) ClearClientIps(clientEmail string) (error) {
|
func (s *InboundService) ClearClientIps(clientEmail string) error {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
|
|
||||||
result := db.Model(model.InboundClientIps{}).
|
result := db.Model(model.InboundClientIps{}).
|
||||||
@ -584,7 +628,6 @@ func (s *InboundService) ClearClientIps(clientEmail string) (error) {
|
|||||||
Update("ips", "")
|
Update("ips", "")
|
||||||
err := result.Error
|
err := result.Error
|
||||||
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user