From 35feef650f793ffbec2af51a18fd25d8b0beefb1 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Fri, 8 Dec 2023 20:08:44 +0100 Subject: import-export inbound #1300 --- web/controller/inbound.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'web/controller/inbound.go') 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 { -- cgit v1.2.3