1
0

xui.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package controller
  2. import (
  3. "github.com/mhsanaei/3x-ui/v2/web/middleware"
  4. "github.com/gin-gonic/gin"
  5. )
  6. // XUIController is the main controller for the X-UI panel, managing sub-controllers.
  7. type XUIController struct {
  8. BaseController
  9. settingController *SettingController
  10. xraySettingController *XraySettingController
  11. }
  12. // NewXUIController creates a new XUIController and initializes its routes.
  13. func NewXUIController(g *gin.RouterGroup) *XUIController {
  14. a := &XUIController{}
  15. a.initRouter(g)
  16. return a
  17. }
  18. // initRouter sets up the main panel routes and initializes sub-controllers.
  19. func (a *XUIController) initRouter(g *gin.RouterGroup) {
  20. g = g.Group("/panel")
  21. g.Use(a.checkLogin)
  22. g.Use(middleware.CSRFMiddleware())
  23. g.GET("/", a.index)
  24. g.GET("/inbounds", a.inbounds)
  25. g.GET("/settings", a.settings)
  26. g.GET("/xray", a.xraySettings)
  27. a.settingController = NewSettingController(g)
  28. a.xraySettingController = NewXraySettingController(g)
  29. }
  30. // index renders the main panel index page.
  31. func (a *XUIController) index(c *gin.Context) {
  32. html(c, "index.html", "pages.index.title", nil)
  33. }
  34. // inbounds renders the inbounds management page.
  35. func (a *XUIController) inbounds(c *gin.Context) {
  36. html(c, "inbounds.html", "pages.inbounds.title", nil)
  37. }
  38. // settings renders the settings management page.
  39. func (a *XUIController) settings(c *gin.Context) {
  40. html(c, "settings.html", "pages.settings.title", nil)
  41. }
  42. // xraySettings renders the Xray settings page.
  43. func (a *XUIController) xraySettings(c *gin.Context) {
  44. html(c, "xray.html", "pages.xray.title", nil)
  45. }