Fix Bug in deleting the client alireza0/x-ui#20

This commit is contained in:
Alireza Ahmadi
2023-03-01 13:57:48 +01:00
parent 40bb9f9864
commit afd369993a
3 changed files with 35 additions and 28 deletions

View File

@@ -32,7 +32,7 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) {
g.POST("/del/:id", a.delInbound)
g.POST("/update/:id", a.updateInbound)
g.POST("/addClient/", a.addInboundClient)
g.POST("/delClient/:inboundId/:index", a.delInboundClient)
g.POST("/delClient/:email", a.delInboundClient)
g.POST("/updateClient/:index", a.updateInboundClient)
g.POST("/resetClientTraffic/:email", a.resetClientTraffic)
@@ -146,19 +146,17 @@ func (a *InboundController) addInboundClient(c *gin.Context) {
}
func (a *InboundController) delInboundClient(c *gin.Context) {
inboundId, err := strconv.Atoi(c.Param("inboundId"))
email := c.Param("email")
inbound := &model.Inbound{}
err := c.ShouldBind(inbound)
if err != nil {
jsonMsg(c, I18n(c, "pages.inbounds.revise"), err)
return
}
index, err := strconv.Atoi(c.Param("index"))
if err != nil {
jsonMsg(c, I18n(c, "pages.inbounds.revise"), err)
return
}
logger.Error("email: " + email + " ID: " + strconv.Itoa(inbound.Id) + " Settings: " + inbound.Settings)
err = a.inboundService.DelInboundClient(inboundId, index)
err = a.inboundService.DelInboundClient(inbound, email)
if err != nil {
jsonMsg(c, "something worng!", err)
return

View File

@@ -423,16 +423,31 @@
},
delClient(dbInboundId,client) {
dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
clients = this.getInboundClients(dbInbound);
newDbInbound = new DBInbound(dbInbound);
inbound = newDbInbound.toInbound();
clients = this.getClients(dbInbound.protocol, inbound.settings);
index = this.findIndexOfClient(clients, client);
clients.splice(index, 1);
const data = {
id: dbInboundId,
settings: inbound.settings.toString(),
};
this.$confirm({
title: '{{ i18n "pages.inbounds.deleteInbound"}}',
content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
okText: '{{ i18n "delete"}}',
cancelText: '{{ i18n "cancel"}}',
onOk: () => this.submit('/xui/inbound/delClient/' + dbInboundId + '/' + index),
onOk: () => this.submit('/xui/inbound/delClient/' + client.email, data),
});
},
getClients(protocol, clientSettings) {
switch(protocol){
case Protocols.VMESS: return clientSettings.vmesses;
case Protocols.VLESS: return clientSettings.vlesses;
case Protocols.TROJAN: return clientSettings.trojans;
default: return null;
}
},
showQrcode(dbInbound, clientIndex) {
const link = dbInbound.genLink(clientIndex);
qrModal.show('{{ i18n "qrCode"}}', link, dbInbound);

View File

@@ -258,28 +258,22 @@ func (s *InboundService) AddInboundClient(inbound *model.Inbound) error {
return db.Save(oldInbound).Error
}
func (s *InboundService) DelInboundClient(inboundId int, index int) error {
oldInbound, err := s.GetInbound(inboundId)
if err != nil {
return err
}
settings := map[string][]model.Client{}
json.Unmarshal([]byte(oldInbound.Settings), &settings)
clients := settings["clients"]
email := clients[index].Email
settings["clients"] = append(clients[:index], clients[index+1:]...)
newSetting, err := json.Marshal(settings)
if err != nil {
return err
}
oldInbound.Settings = string(newSetting)
func (s *InboundService) DelInboundClient(inbound *model.Inbound, email string) error {
db := database.GetDB()
err = s.DelClientStat(db, email)
err := s.DelClientStat(db, email)
if err != nil {
logger.Error("Delete stats Data Error")
return err
}
oldInbound, err := s.GetInbound(inbound.Id)
if err != nil {
logger.Error("Load Old Data Error")
return err
}
oldInbound.Settings = inbound.Settings
return db.Save(oldInbound).Error
}