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-05-14 00:37:17 +0300
committerGitHub <noreply@github.com>2023-05-14 00:37:17 +0300
commit66f0a131453a5373de9a1767fd72967089e70c91 (patch)
tree5eca4a424ff49f524579d32daf6c96e0c261dc28
parent63939244a4ebc63567a11444c9ad045b3b83b3b3 (diff)
parent96263797316f7beab11821ca55ab689113e71ebe (diff)
Merge pull request #431 from hamid-gh98/main
[HOTFIX] Redirect `/xui` to `/panel`
-rw-r--r--README.md2
-rw-r--r--web/controller/api.go15
-rw-r--r--web/web.go24
3 files changed, 39 insertions, 2 deletions
diff --git a/README.md b/README.md
index 006ef464..88bfedd4 100644
--- a/README.md
+++ b/README.md
@@ -187,7 +187,7 @@ Reference syntax:
## API routes
- `/login` with `PUSH` user data: `{username: '', password: ''}` for login
-- `/xui/API/inbounds` base for following actions:
+- `/panel/api/inbounds` base for following actions:
| Method | Path | Action |
| :----: | ---------------------------------- | ------------------------------------------- |
diff --git a/web/controller/api.go b/web/controller/api.go
index 333d4f36..607dd83a 100644
--- a/web/controller/api.go
+++ b/web/controller/api.go
@@ -14,7 +14,7 @@ func NewAPIController(g *gin.RouterGroup) *APIController {
}
func (a *APIController) initRouter(g *gin.RouterGroup) {
- g = g.Group("/xui/API/inbounds")
+ g = g.Group("/panel/api/inbounds")
g.Use(a.checkLogin)
g.GET("/list", a.getAllInbounds)
@@ -35,21 +35,27 @@ func (a *APIController) initRouter(g *gin.RouterGroup) {
a.inboundController = NewInboundController(g)
}
+
func (a *APIController) getAllInbounds(c *gin.Context) {
a.inboundController.getInbounds(c)
}
+
func (a *APIController) getSingleInbound(c *gin.Context) {
a.inboundController.getInbound(c)
}
+
func (a *APIController) getClientTraffics(c *gin.Context) {
a.inboundController.getClientTraffics(c)
}
+
func (a *APIController) addInbound(c *gin.Context) {
a.inboundController.addInbound(c)
}
+
func (a *APIController) delInbound(c *gin.Context) {
a.inboundController.delInbound(c)
}
+
func (a *APIController) updateInbound(c *gin.Context) {
a.inboundController.updateInbound(c)
}
@@ -61,24 +67,31 @@ func (a *APIController) getClientIps(c *gin.Context) {
func (a *APIController) clearClientIps(c *gin.Context) {
a.inboundController.clearClientIps(c)
}
+
func (a *APIController) addInboundClient(c *gin.Context) {
a.inboundController.addInboundClient(c)
}
+
func (a *APIController) delInboundClient(c *gin.Context) {
a.inboundController.delInboundClient(c)
}
+
func (a *APIController) updateInboundClient(c *gin.Context) {
a.inboundController.updateInboundClient(c)
}
+
func (a *APIController) resetClientTraffic(c *gin.Context) {
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)
}
+
func (a *APIController) delDepletedClients(c *gin.Context) {
a.inboundController.delDepletedClients(c)
}
diff --git a/web/web.go b/web/web.go
index 6304d327..849e4beb 100644
--- a/web/web.go
+++ b/web/web.go
@@ -147,6 +147,27 @@ func (s *Server) getHtmlTemplate(funcMap template.FuncMap) (*template.Template,
return t, nil
}
+func redirectMiddleware() gin.HandlerFunc {
+ return func(c *gin.Context) {
+ // Redirect from old '/xui' path to '/panel'
+ path := c.Request.URL.Path
+ redirects := map[string]string{
+ "/panel/API": "/panel/api",
+ "/xui/API": "/panel/api",
+ "/xui": "/panel",
+ }
+ for from, to := range redirects {
+ if strings.HasPrefix(path, from) {
+ newPath := to + path[len(from):]
+ c.Redirect(http.StatusMovedPermanently, newPath)
+ c.Abort()
+ return
+ }
+ }
+ c.Next()
+ }
+}
+
func (s *Server) initRouter() (*gin.Engine, error) {
if config.IsDebug() {
gin.SetMode(gin.DebugMode)
@@ -203,6 +224,9 @@ func (s *Server) initRouter() (*gin.Engine, error) {
engine.StaticFS(basePath+"assets", http.FS(&wrapAssetsFS{FS: assetsFS}))
}
+ // Apply the redirect middleware (`/xui` to `/panel`)
+ engine.Use(redirectMiddleware())
+
g := engine.Group(basePath)
s.index = controller.NewIndexController(g)