diff options
| author | Alireza Ahmadi <alireza7@gmail.com> | 2023-12-08 22:08:44 +0300 |
|---|---|---|
| committer | Alireza Ahmadi <alireza7@gmail.com> | 2023-12-08 22:08:44 +0300 |
| commit | 35feef650f793ffbec2af51a18fd25d8b0beefb1 (patch) | |
| tree | f36cac6a4c188118418b53f45c681e7a4e821e6d /web/controller/inbound.go | |
| parent | 38013e5ea942f35d7f187b476c2f8914281b6c18 (diff) | |
import-export inbound #1300
Diffstat (limited to 'web/controller/inbound.go')
| -rw-r--r-- | web/controller/inbound.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/web/controller/inbound.go b/web/controller/inbound.go index 0fa54cd4..123c486f 100644 --- a/web/controller/inbound.go +++ b/web/controller/inbound.go @@ -1,6 +1,7 @@ package controller import ( + "encoding/json" "fmt" "strconv" "x-ui/database/model" @@ -37,6 +38,7 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) { g.POST("/resetAllTraffics", a.resetAllTraffics) g.POST("/resetAllClientTraffics/:id", a.resetAllClientTraffics) g.POST("/delDepletedClients/:id", a.delDepletedClients) + g.POST("/import", a.importInbound) g.POST("/onlines", a.onlines) } @@ -266,6 +268,31 @@ func (a *InboundController) resetAllClientTraffics(c *gin.Context) { jsonMsg(c, "All traffics of client reseted", nil) } +func (a *InboundController) importInbound(c *gin.Context) { + inbound := &model.Inbound{} + err := json.Unmarshal([]byte(c.PostForm("data")), inbound) + if err != nil { + jsonMsg(c, "Something went wrong!", err) + return + } + user := session.GetLoginUser(c) + inbound.Id = 0 + inbound.UserId = user.Id + inbound.Tag = fmt.Sprintf("inbound-%v", inbound.Port) + + for index := range inbound.ClientStats { + inbound.ClientStats[index].Id = 0 + inbound.ClientStats[index].Enable = true + } + + needRestart := false + inbound, needRestart, err = a.inboundService.AddInbound(inbound) + jsonMsgObj(c, I18nWeb(c, "pages.inbounds.create"), inbound, err) + if err == nil && needRestart { + a.xrayService.SetToNeedRestart() + } +} + func (a *InboundController) delDepletedClients(c *gin.Context) { id, err := strconv.Atoi(c.Param("id")) if err != nil { |
