mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-09-11 20:50:06 +00:00
multi reset and delete request for clients group
This commit is contained in:
parent
93ea2b80dd
commit
1cc9b6583e
3 changed files with 97 additions and 18 deletions
|
@ -35,9 +35,11 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) {
|
||||||
g.POST("/addClient", a.addInboundClient)
|
g.POST("/addClient", a.addInboundClient)
|
||||||
g.POST("/addGroupClient", a.addGroupInboundClient)
|
g.POST("/addGroupClient", a.addGroupInboundClient)
|
||||||
g.POST("/:id/delClient/:clientId", a.delInboundClient)
|
g.POST("/:id/delClient/:clientId", a.delInboundClient)
|
||||||
|
g.POST("/delGroupClients", a.delGroupClients)
|
||||||
g.POST("/updateClient/:clientId", a.updateInboundClient)
|
g.POST("/updateClient/:clientId", a.updateInboundClient)
|
||||||
g.POST("/updateClients", a.updateGroupInboundClient)
|
g.POST("/updateClients", a.updateGroupInboundClient)
|
||||||
g.POST("/:id/resetClientTraffic/:email", a.resetClientTraffic)
|
g.POST("/:id/resetClientTraffic/:email", a.resetClientTraffic)
|
||||||
|
g.POST("/resetGroupClientTraffic", a.resetGroupClientTraffic)
|
||||||
g.POST("/resetAllTraffics", a.resetAllTraffics)
|
g.POST("/resetAllTraffics", a.resetAllTraffics)
|
||||||
g.POST("/resetAllClientTraffics/:id", a.resetAllClientTraffics)
|
g.POST("/resetAllClientTraffics/:id", a.resetAllClientTraffics)
|
||||||
g.POST("/delDepletedClients/:id", a.delDepletedClients)
|
g.POST("/delDepletedClients/:id", a.delDepletedClients)
|
||||||
|
@ -241,6 +243,38 @@ func (a *InboundController) delInboundClient(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *InboundController) delGroupClients(c *gin.Context) {
|
||||||
|
var requestData []struct {
|
||||||
|
InboundID int `json:"inboundId"`
|
||||||
|
ClientID string `json:"clientId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.ShouldBindJSON(&requestData); err != nil {
|
||||||
|
jsonMsg(c, "Invalid request data", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
needRestart := false
|
||||||
|
|
||||||
|
for _, req := range requestData {
|
||||||
|
needRestartTmp, err := a.inboundService.DelInboundClient(req.InboundID, req.ClientID)
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, "Failed to delete client", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if needRestartTmp {
|
||||||
|
needRestart = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonMsg(c, "Clients deleted successfully", nil)
|
||||||
|
|
||||||
|
if needRestart {
|
||||||
|
a.xrayService.SetToNeedRestart()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (a *InboundController) updateInboundClient(c *gin.Context) {
|
func (a *InboundController) updateInboundClient(c *gin.Context) {
|
||||||
clientId := c.Param("clientId")
|
clientId := c.Param("clientId")
|
||||||
|
|
||||||
|
@ -333,6 +367,44 @@ func (a *InboundController) resetClientTraffic(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *InboundController) resetGroupClientTraffic(c *gin.Context) {
|
||||||
|
var requestData []struct {
|
||||||
|
InboundID int `json:"inboundId"` // Map JSON "inboundId" to struct field "InboundID"
|
||||||
|
Email string `json:"email"` // Map JSON "email" to struct field "Email"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse JSON body directly using ShouldBindJSON
|
||||||
|
if err := c.ShouldBindJSON(&requestData); err != nil {
|
||||||
|
jsonMsg(c, "Invalid request data", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
needRestart := false
|
||||||
|
|
||||||
|
// Process each request data
|
||||||
|
for _, req := range requestData {
|
||||||
|
needRestartTmp, err := a.inboundService.ResetClientTraffic(req.InboundID, req.Email)
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, "Failed to reset client traffic", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// If any request requires a restart, set needRestart to true
|
||||||
|
if needRestartTmp {
|
||||||
|
needRestart = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send response back to the client
|
||||||
|
jsonMsg(c, "Traffic reset for all clients", nil)
|
||||||
|
|
||||||
|
// Restart the service if required
|
||||||
|
if needRestart {
|
||||||
|
a.xrayService.SetToNeedRestart()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func (a *InboundController) resetAllTraffics(c *gin.Context) {
|
func (a *InboundController) resetAllTraffics(c *gin.Context) {
|
||||||
err := a.inboundService.ResetAllTraffics()
|
err := a.inboundService.ResetAllTraffics()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -271,21 +271,20 @@
|
||||||
},
|
},
|
||||||
async resetClientTrafficHandler(client, dbInboundId, clients = []) {
|
async resetClientTrafficHandler(client, dbInboundId, clients = []) {
|
||||||
if (clients.length > 0) {
|
if (clients.length > 0) {
|
||||||
let response;
|
const resetRequests = clients
|
||||||
clients.forEach((client) => {
|
.filter(client => {
|
||||||
const inbound = clientModal.dbInbounds.find(inbound => inbound.id === client.inboundId)
|
const inbound = clientModal.dbInbounds.find(inbound => inbound.id === client.inboundId);
|
||||||
if(inbound && app.hasClientStats(inbound, client.email)) {
|
return inbound && app.hasClientStats(inbound, client.email);
|
||||||
response = HttpUtil.postWithModal('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email);
|
}).map(client => ({ inboundId: client.inboundId, email: client.email}));
|
||||||
}
|
|
||||||
})
|
return HttpUtil.postWithModalJson('/panel/inbound/resetGroupClientTraffic', resetRequests, null)
|
||||||
return response;
|
|
||||||
} else {
|
} else {
|
||||||
return HttpUtil.postWithModal('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email)
|
return HttpUtil.postWithModal('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resetClientTraffic(client, dbInboundId, iconElement) {
|
resetClientTraffic(client, dbInboundId, iconElement) {
|
||||||
const subGroup = app.subSettings.enable && clientModal.group.isGroup && clientModal.group.canGroup && clientModal.dbInbounds && clientModal.dbInbounds.length > 0 ? app.getSubGroupClients(clientModal.dbInbounds, client) : [];
|
const subGroup = app.subSettings.enable && clientModal.group.isGroup && clientModal.group.canGroup && clientModal.dbInbounds && clientModal.dbInbounds.length > 0 ? app.getSubGroupClients(clientModal.dbInbounds, client) : [];
|
||||||
const clients = subGroup && subGroup.clients && subGroup.clients.length > 0 ? subGroup.clients : [];
|
const clients = subGroup && subGroup.clients && subGroup.clients.length > 1 ? subGroup.clients : [];
|
||||||
this.$confirm({
|
this.$confirm({
|
||||||
title: '{{ i18n "pages.inbounds.resetTraffic"}}',
|
title: '{{ i18n "pages.inbounds.resetTraffic"}}',
|
||||||
content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
|
content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
|
||||||
|
|
|
@ -1145,6 +1145,8 @@
|
||||||
},
|
},
|
||||||
async delClientHandler(dbInboundId, currentClient, clients = []) {
|
async delClientHandler(dbInboundId, currentClient, clients = []) {
|
||||||
if (clients.length > 0) {
|
if (clients.length > 0) {
|
||||||
|
const deleteRequestData = [];
|
||||||
|
|
||||||
for (const client of clients) {
|
for (const client of clients) {
|
||||||
const dbInbound = this.dbInbounds.find(inbound => inbound.id === client.inboundId);
|
const dbInbound = this.dbInbounds.find(inbound => inbound.id === client.inboundId);
|
||||||
if (dbInbound) {
|
if (dbInbound) {
|
||||||
|
@ -1161,9 +1163,14 @@
|
||||||
await this.submit(`/panel/inbound/addClient`, data, null);
|
await this.submit(`/panel/inbound/addClient`, data, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteRequestData.push({
|
||||||
|
inboundId: client.inboundId,
|
||||||
|
clientId: client.clientId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
await this.submit(`/panel/inbound/${client.inboundId}/delClient/${client.clientId}`);
|
|
||||||
}
|
}
|
||||||
|
await this.submit('/panel/inbound/delGroupClients', deleteRequestData, null, true);
|
||||||
} else {
|
} else {
|
||||||
const dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
|
const dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
|
||||||
const clientId = this.getClientId(dbInbound.protocol, currentClient);
|
const clientId = this.getClientId(dbInbound.protocol, currentClient);
|
||||||
|
@ -1172,7 +1179,7 @@
|
||||||
},
|
},
|
||||||
delClient(dbInboundId, currentClient, confirmation = true) {
|
delClient(dbInboundId, currentClient, confirmation = true) {
|
||||||
const subGroup = this.subSettings.enable ? this.getSubGroupClients(this.dbInbounds, currentClient) : [];
|
const subGroup = this.subSettings.enable ? this.getSubGroupClients(this.dbInbounds, currentClient) : [];
|
||||||
const clients = subGroup && subGroup.clients && subGroup.clients.length > 0 ? subGroup.clients : [];
|
const clients = subGroup && subGroup.clients && subGroup.clients.length > 1 ? subGroup.clients : [];
|
||||||
if (confirmation){
|
if (confirmation){
|
||||||
const clientEmails = clients.length > 0 ? clients.map(item => item.email) : currentClient.email
|
const clientEmails = clients.length > 0 ? clients.map(item => item.email) : currentClient.email
|
||||||
this.$confirm({
|
this.$confirm({
|
||||||
|
@ -1295,19 +1302,20 @@
|
||||||
},
|
},
|
||||||
resetClientTrafficHandler(client, dbInboundId, clients = []) {
|
resetClientTrafficHandler(client, dbInboundId, clients = []) {
|
||||||
if (clients.length > 0){
|
if (clients.length > 0){
|
||||||
clients.forEach(async (client) => {
|
const resetRequests = clients
|
||||||
const inbound = this.dbInbounds.find(inbound => inbound.id === client.inboundId)
|
.filter(client => {
|
||||||
if(inbound && this.hasClientStats(inbound, client.email)) {
|
const inbound = this.dbInbounds.find(inbound => inbound.id === client.inboundId);
|
||||||
await this.submit('/panel/inbound/' + client.inboundId + '/resetClientTraffic/' + client.email)
|
return inbound && this.hasClientStats(inbound, client.email);
|
||||||
}
|
}).map(client => ({ inboundId: client.inboundId, email: client.email}));
|
||||||
})
|
|
||||||
|
this.submit('/panel/inbound/resetGroupClientTraffic', resetRequests, null, true)
|
||||||
}else {
|
}else {
|
||||||
this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email);
|
this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resetClientTraffic(client, dbInboundId, confirmation = true) {
|
resetClientTraffic(client, dbInboundId, confirmation = true) {
|
||||||
const subGroup = this.subSettings.enable ? this.getSubGroupClients(this.dbInbounds, client) : [];
|
const subGroup = this.subSettings.enable ? this.getSubGroupClients(this.dbInbounds, client) : [];
|
||||||
const clients = subGroup && subGroup.clients && subGroup.clients.length > 0 ? subGroup.clients : [];
|
const clients = subGroup && subGroup.clients && subGroup.clients.length > 1 ? subGroup.clients : [];
|
||||||
if (confirmation){
|
if (confirmation){
|
||||||
const clientEmails = clients.length > 0 ? clients.map(item => item.email) : client.email
|
const clientEmails = clients.length > 0 ? clients.map(item => item.email) : client.email
|
||||||
this.$confirm({
|
this.$confirm({
|
||||||
|
|
Loading…
Reference in a new issue