diff options
Diffstat (limited to 'web/controller')
| -rw-r--r-- | web/controller/inbound.go | 80 | ||||
| -rw-r--r-- | web/controller/index.go | 6 | ||||
| -rw-r--r-- | web/controller/setting.go | 3 |
3 files changed, 83 insertions, 6 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() + } } diff --git a/web/controller/index.go b/web/controller/index.go index 71a1a34a..b4f981e8 100644 --- a/web/controller/index.go +++ b/web/controller/index.go @@ -4,7 +4,6 @@ import ( "net/http" "time" "x-ui/logger" - "x-ui/web/job" "x-ui/web/service" "x-ui/web/session" @@ -20,6 +19,7 @@ type IndexController struct { BaseController userService service.UserService + tgbot service.Tgbot } func NewIndexController(g *gin.RouterGroup) *IndexController { @@ -60,13 +60,13 @@ func (a *IndexController) login(c *gin.Context) { user := a.userService.CheckUser(form.Username, form.Password) timeStr := time.Now().Format("2006-01-02 15:04:05") if user == nil { - job.NewStatsNotifyJob().UserLoginNotify(form.Username, getRemoteIp(c), timeStr, 0) + a.tgbot.UserLoginNotify(form.Username, getRemoteIp(c), timeStr, 0) logger.Infof("wrong username or password: \"%s\" \"%s\"", form.Username, form.Password) pureJsonMsg(c, false, I18n(c, "pages.login.toasts.wrongUsernameOrPassword")) return } else { logger.Infof("%s login success,Ip Address:%s\n", form.Username, getRemoteIp(c)) - job.NewStatsNotifyJob().UserLoginNotify(form.Username, getRemoteIp(c), timeStr, 1) + a.tgbot.UserLoginNotify(form.Username, getRemoteIp(c), timeStr, 1) } err = session.SetLoginUser(c, user) diff --git a/web/controller/setting.go b/web/controller/setting.go index 922544fe..0456bca3 100644 --- a/web/controller/setting.go +++ b/web/controller/setting.go @@ -2,11 +2,12 @@ package controller import ( "errors" - "github.com/gin-gonic/gin" "time" "x-ui/web/entity" "x-ui/web/service" "x-ui/web/session" + + "github.com/gin-gonic/gin" ) type updateUserForm struct { |
