xui.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. )
  5. // XUIController is the main controller for the X-UI panel, managing sub-controllers.
  6. type XUIController struct {
  7. BaseController
  8. inboundController *InboundController
  9. serverController *ServerController
  10. settingController *SettingController
  11. xraySettingController *XraySettingController
  12. }
  13. // NewXUIController creates a new XUIController and initializes its routes.
  14. func NewXUIController(g *gin.RouterGroup) *XUIController {
  15. a := &XUIController{}
  16. a.initRouter(g)
  17. return a
  18. }
  19. // initRouter sets up the main panel routes and initializes sub-controllers.
  20. func (a *XUIController) initRouter(g *gin.RouterGroup) {
  21. g = g.Group("/panel")
  22. g.Use(a.checkLogin)
  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.inboundController = NewInboundController(g)
  28. a.serverController = NewServerController(g)
  29. a.settingController = NewSettingController(g)
  30. a.xraySettingController = NewXraySettingController(g)
  31. }
  32. // index renders the main panel index page.
  33. func (a *XUIController) index(c *gin.Context) {
  34. html(c, "index.html", "pages.index.title", nil)
  35. }
  36. // inbounds renders the inbounds management page.
  37. func (a *XUIController) inbounds(c *gin.Context) {
  38. html(c, "inbounds.html", "pages.inbounds.title", nil)
  39. }
  40. // settings renders the settings management page.
  41. func (a *XUIController) settings(c *gin.Context) {
  42. html(c, "settings.html", "pages.settings.title", nil)
  43. }
  44. // xraySettings renders the Xray settings page.
  45. func (a *XUIController) xraySettings(c *gin.Context) {
  46. html(c, "xray.html", "pages.xray.title", nil)
  47. }