From baaa814a519e9867536811529b490af059d55fbb Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Fri, 17 Mar 2023 18:51:43 +0100 Subject: [PATCH 1/6] Fix del/update affects on clientIPs --- web/service/inbound.go | 53 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/web/service/inbound.go b/web/service/inbound.go index 87440c84..fca42edd 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -179,6 +179,20 @@ func (s *InboundService) DelInbound(id int) error { if err != nil { 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 } @@ -286,6 +300,12 @@ func (s *InboundService) DelInboundClient(inbound *model.Inbound, email string) 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 } @@ -319,12 +339,26 @@ func (s *InboundService) UpdateInboundClient(inbound *model.Inbound, index int) if len(clients[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 { s.AddClientStat(inbound.Id, &clients[index]) } } 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 } @@ -483,8 +517,17 @@ func (s *InboundService) UpdateClientStat(email string, client *model.Client) er } 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 { - 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 { @@ -567,6 +610,7 @@ func (s *InboundService) SearchClientTraffic(query string) (traffic *xray.Client } return traffic, err } + func (s *InboundService) GetInboundClientIps(clientEmail string) (string, error) { db := database.GetDB() InboundClientIps := &model.InboundClientIps{} @@ -576,7 +620,7 @@ func (s *InboundService) GetInboundClientIps(clientEmail string) (string, error) } return InboundClientIps.Ips, nil } -func (s *InboundService) ClearClientIps(clientEmail string) (error) { +func (s *InboundService) ClearClientIps(clientEmail string) error { db := database.GetDB() result := db.Model(model.InboundClientIps{}). @@ -584,7 +628,6 @@ func (s *InboundService) ClearClientIps(clientEmail string) (error) { Update("ips", "") err := result.Error - if err != nil { return err } From 025f559460108ce4f6e55025c08a291796ae4538 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Fri, 17 Mar 2023 19:04:07 +0100 Subject: [PATCH 2/6] Fix clear IP affect in UI --- web/html/xui/client_modal.html | 4 ++-- web/html/xui/form/client.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/web/html/xui/client_modal.html b/web/html/xui/client_modal.html index 17381a88..e4ee8659 100644 --- a/web/html/xui/client_modal.html +++ b/web/html/xui/client_modal.html @@ -120,12 +120,12 @@ event.target.value = msg.obj } }, - async clearDBClientIps(email,event) { + async clearDBClientIps(email) { const msg = await HttpUtil.post('/xui/inbound/clearClientIps/'+ email); if (!msg.success) { return; } - event.target.value = "" + document.getElementById("clientIPs").value = "" }, }, }); diff --git a/web/html/xui/form/client.html b/web/html/xui/form/client.html index 586f4fd4..fac830e2 100644 --- a/web/html/xui/form/client.html +++ b/web/html/xui/form/client.html @@ -50,12 +50,12 @@ Clear The Log - + - + From 738a771b87d5addce9ca6510dec4e2bdf6ec8c6d Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Fri, 17 Mar 2023 19:29:08 +0100 Subject: [PATCH 3/6] Fix delete bug --- web/service/inbound.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/service/inbound.go b/web/service/inbound.go index fca42edd..b6f4f031 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -188,7 +188,7 @@ func (s *InboundService) DelInbound(id int) error { return err } for _, client := range clients { - err := db.Where("client_email = ?", client.Email).Delete(model.InboundClientIps{}).Error + err := s.DelClientIPs(db, client.Email) if err != nil { return err } @@ -523,11 +523,12 @@ func (s *InboundService) UpdateClientIPs(tx *gorm.DB, oldEmail string, newEmail } func (s *InboundService) DelClientStat(tx *gorm.DB, email string) error { - return tx.Where("client_email = ?", email).Delete(xray.ClientTraffic{}).Error + return tx.Where("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 + logger.Warning(email) + return tx.Where("client_email = ?", email).Delete(model.InboundClientIps{}).Error } func (s *InboundService) ResetClientTraffic(id int, clientEmail string) error { From 263df2abf5815e7effb46aab5a4c2f9e936b087b Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Fri, 17 Mar 2023 19:29:08 +0100 Subject: [PATCH 4/6] Fix delete bug --- web/service/inbound.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/service/inbound.go b/web/service/inbound.go index fca42edd..6e72d0db 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -188,7 +188,7 @@ func (s *InboundService) DelInbound(id int) error { return err } for _, client := range clients { - err := db.Where("client_email = ?", client.Email).Delete(model.InboundClientIps{}).Error + err := s.DelClientIPs(db, client.Email) if err != nil { return err } @@ -523,11 +523,11 @@ func (s *InboundService) UpdateClientIPs(tx *gorm.DB, oldEmail string, newEmail } func (s *InboundService) DelClientStat(tx *gorm.DB, email string) error { - return tx.Where("client_email = ?", email).Delete(xray.ClientTraffic{}).Error + return tx.Where("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 + return tx.Where("client_email = ?", email).Delete(model.InboundClientIps{}).Error } func (s *InboundService) ResetClientTraffic(id int, clientEmail string) error { From 74b14657cf7baf57ed2a0f2d8d1eef3e5d55be97 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Fri, 17 Mar 2023 23:03:21 +0330 Subject: [PATCH 5/6] remove useless code --- web/html/xui/form/protocol/trojan.html | 23 ---------------- web/html/xui/form/protocol/vless.html | 23 ---------------- web/html/xui/form/protocol/vmess.html | 23 ---------------- web/html/xui/inbounds_client_row.html | 36 -------------------------- 4 files changed, 105 deletions(-) delete mode 100644 web/html/xui/inbounds_client_row.html diff --git a/web/html/xui/form/protocol/trojan.html b/web/html/xui/form/protocol/trojan.html index e1d82572..ca9213c2 100644 --- a/web/html/xui/form/protocol/trojan.html +++ b/web/html/xui/form/protocol/trojan.html @@ -31,29 +31,6 @@ - - - IP log - - - - - - - - - - - - - - - - {{ i18n "none" }} diff --git a/web/html/xui/form/protocol/vless.html b/web/html/xui/form/protocol/vless.html index 146587f7..6b3436f0 100644 --- a/web/html/xui/form/protocol/vless.html +++ b/web/html/xui/form/protocol/vless.html @@ -31,29 +31,6 @@ - - - IP log - - - - - - - - - - - - - - - - {{ i18n "none" }} diff --git a/web/html/xui/form/protocol/vmess.html b/web/html/xui/form/protocol/vmess.html index 4c6779dd..59cf6d2b 100644 --- a/web/html/xui/form/protocol/vmess.html +++ b/web/html/xui/form/protocol/vmess.html @@ -34,29 +34,6 @@ - - - IP Log - - - - - - - - - - - - - - - - {{ i18n "pages.inbounds.totalFlow" }}(GB) diff --git a/web/html/xui/inbounds_client_row.html b/web/html/xui/inbounds_client_row.html deleted file mode 100644 index 76f2a799..00000000 --- a/web/html/xui/inbounds_client_row.html +++ /dev/null @@ -1,36 +0,0 @@ -{{define "client_row"}} - - - - -{{end}} From 430338f04596d7014ca5357433e5587d2161f5cc Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Fri, 17 Mar 2023 23:05:33 +0330 Subject: [PATCH 6/6] Update trojan.html --- web/html/xui/form/protocol/trojan.html | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/web/html/xui/form/protocol/trojan.html b/web/html/xui/form/protocol/trojan.html index ca9213c2..840ce17d 100644 --- a/web/html/xui/form/protocol/trojan.html +++ b/web/html/xui/form/protocol/trojan.html @@ -31,16 +31,11 @@ - + {{ i18n "none" }} [[ key ]] - - - - [[ key ]] -