diff options
| author | MHSanaei <ho3ein.sanaei@gmail.com> | 2023-03-17 19:30:14 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-17 19:30:14 +0300 |
| commit | f25a7a571e6103587558e970673a09375b1ef318 (patch) | |
| tree | 24e645ff37cec8d8b166bfe59403c4fb19a1da2c /web/controller/inbound.go | |
| parent | b9ffe62d698016b52a5a36ede0eb2bdf86085d8a (diff) | |
| parent | 87e173b56767a861210dc0cc4913bab232765dfd (diff) | |
Merge pull request #26 from MHSanaei/dev
alireza
Diffstat (limited to 'web/controller/inbound.go')
| -rw-r--r-- | web/controller/inbound.go | 80 |
1 files changed, 78 insertions, 2 deletions
diff --git a/web/controller/inbound.go b/web/controller/inbound.go index 8ec90ed4..b567af8c 100644 --- a/web/controller/inbound.go +++ b/web/controller/inbound.go @@ -33,7 +33,10 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) { g.POST("/update/:id", a.updateInbound) g.POST("/clientIps/:email", a.getClientIps) g.POST("/clearClientIps/:email", a.clearClientIps) - g.POST("/resetClientTraffic/:email", a.resetClientTraffic) + g.POST("/addClient/", a.addInboundClient) + g.POST("/delClient/:email", a.delInboundClient) + g.POST("/updateClient/:index", a.updateInboundClient) + g.POST("/:id/resetClientTraffic/:email", a.resetClientTraffic) } @@ -124,6 +127,7 @@ func (a *InboundController) updateInbound(c *gin.Context) { a.xrayService.SetToNeedRestart() } } + func (a *InboundController) getClientIps(c *gin.Context) { email := c.Param("email") @@ -144,13 +148,85 @@ func (a *InboundController) clearClientIps(c *gin.Context) { } jsonMsg(c, "Log Cleared", nil) } +func (a *InboundController) addInboundClient(c *gin.Context) { + inbound := &model.Inbound{} + err := c.ShouldBind(inbound) + if err != nil { + jsonMsg(c, I18n(c, "pages.inbounds.revise"), err) + return + } + + err = a.inboundService.AddInboundClient(inbound) + if err != nil { + jsonMsg(c, "something worng!", err) + return + } + jsonMsg(c, "Client added", nil) + if err == nil { + a.xrayService.SetToNeedRestart() + } +} + +func (a *InboundController) delInboundClient(c *gin.Context) { + email := c.Param("email") + inbound := &model.Inbound{} + err := c.ShouldBind(inbound) + if err != nil { + jsonMsg(c, I18n(c, "pages.inbounds.revise"), err) + return + } + + err = a.inboundService.DelInboundClient(inbound, email) + if err != nil { + jsonMsg(c, "something worng!", err) + return + } + jsonMsg(c, "Client deleted", nil) + if err == nil { + a.xrayService.SetToNeedRestart() + } +} + +func (a *InboundController) updateInboundClient(c *gin.Context) { + index, err := strconv.Atoi(c.Param("index")) + if err != nil { + jsonMsg(c, I18n(c, "pages.inbounds.revise"), err) + return + } + + inbound := &model.Inbound{} + err = c.ShouldBind(inbound) + if err != nil { + jsonMsg(c, I18n(c, "pages.inbounds.revise"), err) + return + } + + err = a.inboundService.UpdateInboundClient(inbound, index) + if err != nil { + jsonMsg(c, "something worng!", err) + return + } + jsonMsg(c, "Client updated", nil) + if err == nil { + a.xrayService.SetToNeedRestart() + } +} + func (a *InboundController) resetClientTraffic(c *gin.Context) { + id, err := strconv.Atoi(c.Param("id")) + if err != nil { + jsonMsg(c, I18n(c, "pages.inbounds.revise"), err) + return + } email := c.Param("email") - err := a.inboundService.ResetClientTraffic(email) + err = a.inboundService.ResetClientTraffic(id, email) if err != nil { jsonMsg(c, "something worng!", err) return } jsonMsg(c, "traffic reseted", nil) + if err == nil { + a.xrayService.SetToNeedRestart() + } } |
