2023-02-09 19:18:06 +00:00
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
2025-09-20 07:35:50 +00:00
|
|
|
// XUIController is the main controller for the X-UI panel, managing sub-controllers.
|
2023-02-09 19:18:06 +00:00
|
|
|
type XUIController struct {
|
|
|
|
|
BaseController
|
|
|
|
|
|
2023-12-04 18:20:46 +00:00
|
|
|
settingController *SettingController
|
|
|
|
|
xraySettingController *XraySettingController
|
2026-01-05 21:12:53 +00:00
|
|
|
nodeController *NodeController
|
2023-02-09 19:18:06 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-20 07:35:50 +00:00
|
|
|
// NewXUIController creates a new XUIController and initializes its routes.
|
2023-02-09 19:18:06 +00:00
|
|
|
func NewXUIController(g *gin.RouterGroup) *XUIController {
|
|
|
|
|
a := &XUIController{}
|
|
|
|
|
a.initRouter(g)
|
|
|
|
|
return a
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-20 07:35:50 +00:00
|
|
|
// initRouter sets up the main panel routes and initializes sub-controllers.
|
2023-02-09 19:18:06 +00:00
|
|
|
func (a *XUIController) initRouter(g *gin.RouterGroup) {
|
2023-05-12 18:06:05 +00:00
|
|
|
g = g.Group("/panel")
|
2023-02-09 19:18:06 +00:00
|
|
|
g.Use(a.checkLogin)
|
|
|
|
|
|
|
|
|
|
g.GET("/", a.index)
|
|
|
|
|
g.GET("/inbounds", a.inbounds)
|
2023-05-04 16:39:08 +00:00
|
|
|
g.GET("/settings", a.settings)
|
2023-12-04 18:20:46 +00:00
|
|
|
g.GET("/xray", a.xraySettings)
|
2026-01-05 21:12:53 +00:00
|
|
|
g.GET("/nodes", a.nodes)
|
2026-01-09 12:36:14 +00:00
|
|
|
g.GET("/clients", a.clients)
|
|
|
|
|
g.GET("/hosts", a.hosts)
|
2023-02-09 19:18:06 +00:00
|
|
|
|
|
|
|
|
a.settingController = NewSettingController(g)
|
2023-12-04 18:20:46 +00:00
|
|
|
a.xraySettingController = NewXraySettingController(g)
|
2026-01-05 21:12:53 +00:00
|
|
|
a.nodeController = NewNodeController(g.Group("/node"))
|
2026-01-09 12:36:14 +00:00
|
|
|
|
|
|
|
|
// Register client and host controllers directly under /panel (not /panel/api)
|
|
|
|
|
NewClientController(g.Group("/client"))
|
|
|
|
|
NewHostController(g.Group("/host"))
|
|
|
|
|
NewClientHWIDController(g.Group("/client")) // Register HWID controller under /panel/client/hwid
|
2023-02-09 19:18:06 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-20 07:35:50 +00:00
|
|
|
// index renders the main panel index page.
|
2023-02-09 19:18:06 +00:00
|
|
|
func (a *XUIController) index(c *gin.Context) {
|
|
|
|
|
html(c, "index.html", "pages.index.title", nil)
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-20 07:35:50 +00:00
|
|
|
// inbounds renders the inbounds management page.
|
2023-02-09 19:18:06 +00:00
|
|
|
func (a *XUIController) inbounds(c *gin.Context) {
|
|
|
|
|
html(c, "inbounds.html", "pages.inbounds.title", nil)
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-20 07:35:50 +00:00
|
|
|
// settings renders the settings management page.
|
2023-05-04 16:39:08 +00:00
|
|
|
func (a *XUIController) settings(c *gin.Context) {
|
2023-05-04 17:52:54 +00:00
|
|
|
html(c, "settings.html", "pages.settings.title", nil)
|
2023-02-09 19:18:06 +00:00
|
|
|
}
|
2023-12-04 18:20:46 +00:00
|
|
|
|
2025-09-20 07:35:50 +00:00
|
|
|
// xraySettings renders the Xray settings page.
|
2023-12-04 18:20:46 +00:00
|
|
|
func (a *XUIController) xraySettings(c *gin.Context) {
|
|
|
|
|
html(c, "xray.html", "pages.xray.title", nil)
|
|
|
|
|
}
|
2026-01-05 21:12:53 +00:00
|
|
|
|
|
|
|
|
// nodes renders the nodes management page (multi-node mode).
|
|
|
|
|
func (a *XUIController) nodes(c *gin.Context) {
|
|
|
|
|
html(c, "nodes.html", "pages.nodes.title", nil)
|
|
|
|
|
}
|
2026-01-09 12:36:14 +00:00
|
|
|
|
|
|
|
|
// clients renders the clients management page.
|
|
|
|
|
func (a *XUIController) clients(c *gin.Context) {
|
|
|
|
|
html(c, "clients.html", "pages.clients.title", nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// hosts renders the hosts management page (multi-node mode).
|
|
|
|
|
func (a *XUIController) hosts(c *gin.Context) {
|
|
|
|
|
html(c, "hosts.html", "pages.hosts.title", nil)
|
|
|
|
|
}
|