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:
authorMHSanaei <ho3ein.sanaei@gmail.com>2023-04-09 22:43:18 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2023-04-09 22:43:18 +0300
commite1da43053d23c995bcd6e7267cb20042398cd64f (patch)
tree08c4c371ba070ef765ec2be83270ee6032e54774 /web/controller
parent3bb90cbf2463b31c6a921f7cd75cf32edd3a37f0 (diff)
alireza update pack
Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
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.go5
-rw-r--r--web/controller/setting.go31
-rw-r--r--web/controller/sub.go42
5 files changed, 143 insertions, 46 deletions
diff --git a/web/controller/api.go b/web/controller/api.go
index 843ac7e5..f3021ea4 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.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)
+ 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..43a1fadc 100644
--- a/web/controller/server.go
+++ b/web/controller/server.go
@@ -38,7 +38,7 @@ 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)
}
func (a *ServerController) refreshStatus() {
@@ -109,7 +109,8 @@ 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
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)))
+ }
+}