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:
authorMohammad Movaghari <52345697+mohammadmovaghari@users.noreply.github.com>2023-04-12 16:29:17 +0300
committerGitHub <noreply@github.com>2023-04-12 16:29:17 +0300
commitc575425292e2c4c690728174e42a6f34963394c2 (patch)
treec9b033457baa55a98cea23a8769645f8f3dbd476 /web/controller
parent63f71e527ceddc724e0bd2893c4946b01f3a5f6c (diff)
parent82b2809fccb6a131b4f84e2ca236f8bea567beae (diff)
Merge branch 'MHSanaei:main' into main
Diffstat (limited to 'web/controller')
-rw-r--r--web/controller/api.go83
-rw-r--r--web/controller/inbound.go28
-rw-r--r--web/controller/server.go30
-rw-r--r--web/controller/setting.go31
-rw-r--r--web/controller/sub.go42
5 files changed, 168 insertions, 46 deletions
diff --git a/web/controller/api.go b/web/controller/api.go
index 843ac7e5..c64b27bf 100644
--- a/web/controller/api.go
+++ b/web/controller/api.go
@@ -3,77 +3,74 @@ package controller
import "github.com/gin-gonic/gin"
type APIController struct {
- BaseController
- inboundController *InboundController
- settingController *SettingController
+ BaseController
+ inboundController *InboundController
}
func NewAPIController(g *gin.RouterGroup) *APIController {
- a := &APIController{}
- a.initRouter(g)
- return a
+ a := &APIController{}
+ a.initRouter(g)
+ return a
}
func (a *APIController) initRouter(g *gin.RouterGroup) {
- g = g.Group("/xui/API/inbounds")
- g.Use(a.checkLogin)
-
- g.POST("/list", a.getAllInbounds)
- g.GET("/get/:id", a.getSingleInbound)
- g.POST("/add", a.addInbound)
- g.POST("/del/:id", a.delInbound)
- g.POST("/update/:id", a.updateInbound)
- g.POST("/clientIps/:email", a.getClientIps)
- g.POST("/clearClientIps/:email", a.clearClientIps)
- g.POST("/addClient/", a.addInboundClient)
- g.POST("/delClient/:email", a.delInboundClient)
- g.POST("/updateClient/:index", a.updateInboundClient)
- g.POST("/:id/resetClientTraffic/:email", a.resetClientTraffic)
-
- a.inboundController = NewInboundController(g)
+ g = g.Group("/xui/API/inbounds")
+ g.Use(a.checkLogin)
+
+ g.GET("/list", a.getAllInbounds)
+ g.GET("/get/:id", a.getSingleInbound)
+ g.POST("/add", a.addInbound)
+ g.POST("/del/:id", a.delInbound)
+ g.POST("/update/:id", a.updateInbound)
+ g.POST("/clientIps/:email", a.getClientIps)
+ g.POST("/clearClientIps/:email", a.clearClientIps)
+ g.POST("/addClient/", a.addInboundClient)
+ g.POST("/delClient/:email", a.delInboundClient)
+ g.POST("/updateClient/:index", a.updateInboundClient)
+ g.POST("/:id/resetClientTraffic/:email", a.resetClientTraffic)
+ g.POST("/resetAllTraffics", a.resetAllTraffics)
+ g.POST("/resetAllClientTraffics/:id", a.resetAllClientTraffics)
+
+ a.inboundController = NewInboundController(g)
}
-
-
func (a *APIController) getAllInbounds(c *gin.Context) {
- a.inboundController.getInbounds(c)
+ a.inboundController.getInbounds(c)
}
-
func (a *APIController) getSingleInbound(c *gin.Context) {
- a.inboundController.getInbound(c)
+ a.inboundController.getInbound(c)
}
-
func (a *APIController) addInbound(c *gin.Context) {
- a.inboundController.addInbound(c)
+ a.inboundController.addInbound(c)
}
-
func (a *APIController) delInbound(c *gin.Context) {
- a.inboundController.delInbound(c)
+ a.inboundController.delInbound(c)
}
-
func (a *APIController) updateInbound(c *gin.Context) {
- a.inboundController.updateInbound(c)
+ a.inboundController.updateInbound(c)
}
func (a *APIController) getClientIps(c *gin.Context) {
- a.inboundController.getClientIps(c)
+ a.inboundController.getClientIps(c)
}
func (a *APIController) clearClientIps(c *gin.Context) {
- a.inboundController.clearClientIps(c)
+ a.inboundController.clearClientIps(c)
}
-
func (a *APIController) addInboundClient(c *gin.Context) {
- a.inboundController.addInboundClient(c)
+ a.inboundController.addInboundClient(c)
}
-
func (a *APIController) delInboundClient(c *gin.Context) {
- a.inboundController.delInboundClient(c)
+ a.inboundController.delInboundClient(c)
}
-
func (a *APIController) updateInboundClient(c *gin.Context) {
- a.inboundController.updateInboundClient(c)
+ a.inboundController.updateInboundClient(c)
}
-
func (a *APIController) resetClientTraffic(c *gin.Context) {
- a.inboundController.resetClientTraffic(c)
+ a.inboundController.resetClientTraffic(c)
+}
+func (a *APIController) resetAllTraffics(c *gin.Context) {
+ a.inboundController.resetAllTraffics(c)
+}
+func (a *APIController) resetAllClientTraffics(c *gin.Context) {
+ a.inboundController.resetAllClientTraffics(c)
}
diff --git a/web/controller/inbound.go b/web/controller/inbound.go
index b567af8c..f7ea35eb 100644
--- a/web/controller/inbound.go
+++ b/web/controller/inbound.go
@@ -37,6 +37,8 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) {
g.POST("/delClient/:email", a.delInboundClient)
g.POST("/updateClient/:index", a.updateInboundClient)
g.POST("/:id/resetClientTraffic/:email", a.resetClientTraffic)
+ g.POST("/resetAllTraffics", a.resetAllTraffics)
+ g.POST("/resetAllClientTraffics/:id", a.resetAllClientTraffics)
}
@@ -131,7 +133,7 @@ func (a *InboundController) updateInbound(c *gin.Context) {
func (a *InboundController) getClientIps(c *gin.Context) {
email := c.Param("email")
- ips , err := a.inboundService.GetInboundClientIps(email)
+ ips, err := a.inboundService.GetInboundClientIps(email)
if err != nil {
jsonObj(c, "No IP Record", nil)
return
@@ -230,3 +232,27 @@ func (a *InboundController) resetClientTraffic(c *gin.Context) {
a.xrayService.SetToNeedRestart()
}
}
+
+func (a *InboundController) resetAllTraffics(c *gin.Context) {
+ err := a.inboundService.ResetAllTraffics()
+ if err != nil {
+ jsonMsg(c, "something worng!", err)
+ return
+ }
+ jsonMsg(c, "All traffics reseted", nil)
+}
+
+func (a *InboundController) resetAllClientTraffics(c *gin.Context) {
+ id, err := strconv.Atoi(c.Param("id"))
+ if err != nil {
+ jsonMsg(c, I18n(c, "pages.inbounds.revise"), err)
+ return
+ }
+
+ err = a.inboundService.ResetAllClientTraffics(id)
+ if err != nil {
+ jsonMsg(c, "something worng!", err)
+ return
+ }
+ jsonMsg(c, "All traffics of client reseted", nil)
+}
diff --git a/web/controller/server.go b/web/controller/server.go
index 7b7239d5..c5a3965b 100644
--- a/web/controller/server.go
+++ b/web/controller/server.go
@@ -38,7 +38,9 @@ func (a *ServerController) initRouter(g *gin.RouterGroup) {
g.POST("/stopXrayService", a.stopXrayService)
g.POST("/restartXrayService", a.restartXrayService)
g.POST("/installXray/:version", a.installXray)
- g.POST("/logs", a.getLogs)
+ g.POST("/logs/:count", a.getLogs)
+ g.POST("/getConfigJson", a.getConfigJson)
+ g.GET("/getDb", a.getDb)
}
func (a *ServerController) refreshStatus() {
@@ -109,10 +111,34 @@ func (a *ServerController) restartXrayService(c *gin.Context) {
}
func (a *ServerController) getLogs(c *gin.Context) {
- logs, err := a.serverService.GetLogs()
+ count := c.Param("count")
+ logs, err := a.serverService.GetLogs(count)
if err != nil {
jsonMsg(c, I18n(c, "getLogs"), err)
return
}
jsonObj(c, logs, nil)
}
+
+func (a *ServerController) getConfigJson(c *gin.Context) {
+ configJson, err := a.serverService.GetConfigJson()
+ if err != nil {
+ jsonMsg(c, I18n(c, "getLogs"), err)
+ return
+ }
+ jsonObj(c, configJson, nil)
+}
+
+func (a *ServerController) getDb(c *gin.Context) {
+ db, err := a.serverService.GetDb()
+ if err != nil {
+ jsonMsg(c, I18n(c, "getLogs"), err)
+ return
+ }
+ // Set the headers for the response
+ c.Header("Content-Type", "application/octet-stream")
+ c.Header("Content-Disposition", "attachment; filename=xui.db")
+
+ // Write the file contents to the response
+ c.Writer.Write(db)
+}
diff --git a/web/controller/setting.go b/web/controller/setting.go
index 0456bca3..261eeec8 100644
--- a/web/controller/setting.go
+++ b/web/controller/setting.go
@@ -33,6 +33,7 @@ func (a *SettingController) initRouter(g *gin.RouterGroup) {
g = g.Group("/setting")
g.POST("/all", a.getAllSetting)
+ g.POST("/defaultSettings", a.getDefaultSettings)
g.POST("/update", a.updateSetting)
g.POST("/updateUser", a.updateUser)
g.POST("/restartPanel", a.restartPanel)
@@ -47,6 +48,36 @@ func (a *SettingController) getAllSetting(c *gin.Context) {
jsonObj(c, allSetting, nil)
}
+func (a *SettingController) getDefaultSettings(c *gin.Context) {
+ expireDiff, err := a.settingService.GetExpireDiff()
+ if err != nil {
+ jsonMsg(c, I18n(c, "pages.setting.toasts.getSetting"), err)
+ return
+ }
+ trafficDiff, err := a.settingService.GetTrafficDiff()
+ if err != nil {
+ jsonMsg(c, I18n(c, "pages.setting.toasts.getSetting"), err)
+ return
+ }
+ defaultCert, err := a.settingService.GetCertFile()
+ if err != nil {
+ jsonMsg(c, I18n(c, "pages.setting.toasts.getSetting"), err)
+ return
+ }
+ defaultKey, err := a.settingService.GetKeyFile()
+ if err != nil {
+ jsonMsg(c, I18n(c, "pages.setting.toasts.getSetting"), err)
+ return
+ }
+ result := map[string]interface{}{
+ "expireDiff": expireDiff,
+ "trafficDiff": trafficDiff,
+ "defaultCert": defaultCert,
+ "defaultKey": defaultKey,
+ }
+ jsonObj(c, result, nil)
+}
+
func (a *SettingController) updateSetting(c *gin.Context) {
allSetting := &entity.AllSetting{}
err := c.ShouldBind(allSetting)
diff --git a/web/controller/sub.go b/web/controller/sub.go
new file mode 100644
index 00000000..5695f032
--- /dev/null
+++ b/web/controller/sub.go
@@ -0,0 +1,42 @@
+package controller
+
+import (
+ "encoding/base64"
+ "strings"
+ "x-ui/web/service"
+
+ "github.com/gin-gonic/gin"
+)
+
+type SUBController struct {
+ BaseController
+
+ subService service.SubService
+}
+
+func NewSUBController(g *gin.RouterGroup) *SUBController {
+ a := &SUBController{}
+ a.initRouter(g)
+ return a
+}
+
+func (a *SUBController) initRouter(g *gin.RouterGroup) {
+ g = g.Group("/sub")
+
+ g.GET("/:subid", a.subs)
+}
+
+func (a *SUBController) subs(c *gin.Context) {
+ subId := c.Param("subid")
+ host := strings.Split(c.Request.Host, ":")[0]
+ subs, err := a.subService.GetSubs(subId, host)
+ if err != nil {
+ c.String(400, "Error!")
+ } else {
+ result := ""
+ for _, sub := range subs {
+ result += sub + "\n"
+ }
+ c.String(200, base64.StdEncoding.EncodeToString([]byte(result)))
+ }
+}