mirror of
https://github.com/alireza0/x-ui.git
synced 2026-03-14 05:23:09 +00:00
Fix Bug in deleting the client alireza0/x-ui#20
This commit is contained in:
@@ -32,7 +32,7 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) {
|
|||||||
g.POST("/del/:id", a.delInbound)
|
g.POST("/del/:id", a.delInbound)
|
||||||
g.POST("/update/:id", a.updateInbound)
|
g.POST("/update/:id", a.updateInbound)
|
||||||
g.POST("/addClient/", a.addInboundClient)
|
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("/updateClient/:index", a.updateInboundClient)
|
||||||
g.POST("/resetClientTraffic/:email", a.resetClientTraffic)
|
g.POST("/resetClientTraffic/:email", a.resetClientTraffic)
|
||||||
|
|
||||||
@@ -146,19 +146,17 @@ func (a *InboundController) addInboundClient(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *InboundController) delInboundClient(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 {
|
if err != nil {
|
||||||
jsonMsg(c, I18n(c, "pages.inbounds.revise"), err)
|
jsonMsg(c, I18n(c, "pages.inbounds.revise"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
index, err := strconv.Atoi(c.Param("index"))
|
logger.Error("email: " + email + " ID: " + strconv.Itoa(inbound.Id) + " Settings: " + inbound.Settings)
|
||||||
if err != nil {
|
|
||||||
jsonMsg(c, I18n(c, "pages.inbounds.revise"), err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = a.inboundService.DelInboundClient(inboundId, index)
|
err = a.inboundService.DelInboundClient(inbound, email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, "something worng!", err)
|
jsonMsg(c, "something worng!", err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -423,16 +423,31 @@
|
|||||||
},
|
},
|
||||||
delClient(dbInboundId,client) {
|
delClient(dbInboundId,client) {
|
||||||
dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
|
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);
|
index = this.findIndexOfClient(clients, client);
|
||||||
|
clients.splice(index, 1);
|
||||||
|
const data = {
|
||||||
|
id: dbInboundId,
|
||||||
|
settings: inbound.settings.toString(),
|
||||||
|
};
|
||||||
this.$confirm({
|
this.$confirm({
|
||||||
title: '{{ i18n "pages.inbounds.deleteInbound"}}',
|
title: '{{ i18n "pages.inbounds.deleteInbound"}}',
|
||||||
content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
|
content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
|
||||||
okText: '{{ i18n "delete"}}',
|
okText: '{{ i18n "delete"}}',
|
||||||
cancelText: '{{ i18n "cancel"}}',
|
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) {
|
showQrcode(dbInbound, clientIndex) {
|
||||||
const link = dbInbound.genLink(clientIndex);
|
const link = dbInbound.genLink(clientIndex);
|
||||||
qrModal.show('{{ i18n "qrCode"}}', link, dbInbound);
|
qrModal.show('{{ i18n "qrCode"}}', link, dbInbound);
|
||||||
|
|||||||
@@ -258,28 +258,22 @@ func (s *InboundService) AddInboundClient(inbound *model.Inbound) error {
|
|||||||
return db.Save(oldInbound).Error
|
return db.Save(oldInbound).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *InboundService) DelInboundClient(inboundId int, index int) error {
|
func (s *InboundService) DelInboundClient(inbound *model.Inbound, email string) 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)
|
|
||||||
|
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
err = s.DelClientStat(db, email)
|
err := s.DelClientStat(db, email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Error("Delete stats Data Error")
|
||||||
return err
|
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
|
return db.Save(oldInbound).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user