Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Rahimi <alirahimi818@gmail.com>2024-01-22 14:36:01 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2024-01-22 14:38:36 +0300
commitb172d450e3a9dba8a56b2f6cd9e059559d232033 (patch)
treef4a84c9a37b771eb16799d294ffafd41ef13b8b0 /web/controller
parent5c695ca6520c9cd9c44b18119a862f8f480969af (diff)
Group editing feature of users with the same subscription (#1661)
Diffstat (limited to 'web/controller')
-rw-r--r--web/controller/inbound.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/web/controller/inbound.go b/web/controller/inbound.go
index b274be64..4d6e0af0 100644
--- a/web/controller/inbound.go
+++ b/web/controller/inbound.go
@@ -1,6 +1,7 @@
package controller
import (
+ "errors"
"encoding/json"
"fmt"
"strconv"
@@ -32,7 +33,9 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) {
g.POST("/clientIps/:email", a.getClientIps)
g.POST("/clearClientIps/:email", a.clearClientIps)
g.POST("/addClient", a.addInboundClient)
+ g.POST("/addGroupClient", a.addGroupInboundClient)
g.POST("/:id/delClient/:clientId", a.delInboundClient)
+ g.POST("/updateClients", a.updateGroupInboundClient)
g.POST("/updateClient/:clientId", a.updateInboundClient)
g.POST("/:id/resetClientTraffic/:email", a.resetClientTraffic)
g.POST("/resetAllTraffics", a.resetAllTraffics)
@@ -186,6 +189,34 @@ func (a *InboundController) addInboundClient(c *gin.Context) {
}
+func (a *InboundController) addGroupInboundClient(c *gin.Context) {
+ var requestData []model.Inbound
+
+ err := c.ShouldBindJSON(&requestData)
+
+ if err != nil {
+ jsonMsg(c, I18nWeb(c, "pages.inbounds.update"), err)
+ return
+ }
+
+ needRestart := true
+
+ for _, data := range requestData {
+
+ needRestart, err = a.inboundService.AddInboundClient(&data)
+ if err != nil {
+ jsonMsg(c, "Something went wrong!", err)
+ return
+ }
+ }
+
+ jsonMsg(c, "Client(s) added", nil)
+ if err == nil && needRestart {
+ a.xrayService.SetToNeedRestart()
+ }
+
+}
+
func (a *InboundController) delInboundClient(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
@@ -230,6 +261,56 @@ func (a *InboundController) updateInboundClient(c *gin.Context) {
}
}
+func (a *InboundController) updateGroupInboundClient(c *gin.Context) {
+ var requestData []map[string]interface{}
+
+ if err := c.ShouldBindJSON(&requestData); err != nil {
+ jsonMsg(c, I18nWeb(c, "pages.inbounds.update"), err)
+ return
+ }
+
+ needRestart := false
+
+ for _, item := range requestData {
+
+ inboundMap, ok := item["inbound"].(map[string]interface{})
+ if !ok {
+ jsonMsg(c, "Something went wrong!", errors.New("Failed to convert 'inbound' to map"))
+ return
+ }
+
+ clientId, ok := item["clientId"].(string)
+ if !ok {
+ jsonMsg(c, "Something went wrong!", errors.New("Failed to convert 'clientId' to string"))
+ return
+ }
+
+ inboundJSON, err := json.Marshal(inboundMap)
+ if err != nil {
+ jsonMsg(c, "Something went wrong!", err)
+ return
+ }
+
+ var inboundModel model.Inbound
+ if err := json.Unmarshal(inboundJSON, &inboundModel); err != nil {
+ jsonMsg(c, "Something went wrong!", err)
+ return
+ }
+
+ if restart, err := a.inboundService.UpdateInboundClient(&inboundModel, clientId); err != nil {
+ jsonMsg(c, "Something went wrong!", err)
+ return
+ } else {
+ needRestart = needRestart || restart
+ }
+ }
+
+ jsonMsg(c, "Client updated", nil)
+ if needRestart {
+ a.xrayService.SetToNeedRestart()
+ }
+}
+
func (a *InboundController) resetClientTraffic(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {