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:
authorHo3ein <ho3ein.sanaei@gmail.com>2023-12-10 17:42:52 +0300
committerGitHub <noreply@github.com>2023-12-10 17:42:52 +0300
commite3f1d3c892a1af48f27fdc36f273a55f38d13b40 (patch)
treeb11d0c1ed3c15c8f6f891a5e6df8e021d5db8ab6 /web/controller/inbound.go
parent36cf7c0a8fda915b51e75958ce729fd9a61a5c90 (diff)
parent9fbe80f87f950673058f0001b3704251fa8b9243 (diff)
huge changes
Diffstat (limited to 'web/controller/inbound.go')
-rw-r--r--web/controller/inbound.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/web/controller/inbound.go b/web/controller/inbound.go
index 8b64fe6e..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,8 @@ 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)
}
func (a *InboundController) getInbounds(c *gin.Context) {
@@ -265,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 {
@@ -278,3 +306,7 @@ func (a *InboundController) delDepletedClients(c *gin.Context) {
}
jsonMsg(c, "All delpeted clients are deleted", nil)
}
+
+func (a *InboundController) onlines(c *gin.Context) {
+ jsonObj(c, a.inboundService.GetOnlineClinets(), nil)
+}