router.go 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package routers
  2. import (
  3. "fmt"
  4. "github.com/astaxie/beego"
  5. "github.com/astaxie/beego/context"
  6. "github.com/astaxie/beego/logs"
  7. "nginx-ui/server/base"
  8. config2 "nginx-ui/server/config"
  9. "nginx-ui/server/middleware"
  10. "nginx-ui/server/modules/ldap"
  11. "nginx-ui/server/modules/nginx/nginx_controller"
  12. "nginx-ui/server/modules/oauth2"
  13. "nginx-ui/server/modules/settings"
  14. "nginx-ui/server/modules/user"
  15. "strings"
  16. )
  17. var NginxR = "/nginx"
  18. var NginxGetR = "/nginx/:id"
  19. var NginxRefreshR = "/nginx/:id/http/refresh"
  20. var NginxStartR = "/nginx/:id/start"
  21. var NginxStopR = "/nginx/:id/stop"
  22. var NginxStatusR = "/nginx/:id/status"
  23. func init() {
  24. config := config2.Config
  25. userController := user.NewUserController()
  26. logs.Info("baseApi", config.BaseApi)
  27. ns := beego.NewNamespace(config.BaseApi,
  28. beego.NSRouter(NginxR, &nginx_controller.NginxController{}),
  29. beego.NSRouter(NginxGetR, &nginx_controller.NginxController{}, "post:Update"),
  30. beego.NSRouter(NginxGetR, &nginx_controller.NginxController{}, "get:GetNginx"),
  31. beego.NSRouter(NginxGetR, &nginx_controller.NginxController{}, "delete:DelNginx"),
  32. beego.NSRouter(NginxRefreshR, &nginx_controller.NginxController{}, "post:RefreshHttp"),
  33. beego.NSRouter(NginxStartR, &nginx_controller.NginxController{}, "post:StartNginx"),
  34. beego.NSRouter(NginxStopR, &nginx_controller.NginxController{}, "post:StopNginx"),
  35. beego.NSRouter(NginxStatusR, &nginx_controller.NginxController{}, "post:StatusNginx"),
  36. // certs
  37. beego.NSRouter("/nginx/:id/certs", &nginx_controller.CertController{}),
  38. beego.NSRouter("/nginx/:id/certs/sync", &nginx_controller.CertController{}, "post:Sync"),
  39. // nginx server apis
  40. beego.NSRouter("/nginx/:id/server", &nginx_controller.ServerController{}),
  41. beego.NSRouter("/nginx/:id/server/refresh", &nginx_controller.ServerController{}, "post:Refresh"),
  42. // file upload download
  43. beego.NSRouter("/nginx/:id/file/deploy", &nginx_controller.FileController{}, "post:Deploy"),
  44. beego.NSRouter("/file", &nginx_controller.FileController{}),
  45. beego.NSRouter("/logger", &nginx_controller.LoggerController{}),
  46. beego.NSRouter("/user/login", userController, "post:Login"),
  47. beego.NSRouter("/user/logout", userController, "post:Logout"),
  48. beego.NSRouter("/user/info", userController, "get:User"),
  49. beego.NSRouter("/user/info", userController, "post:UpdateUserInfo"),
  50. beego.NSRouter("/user/register", userController, "post:Register"),
  51. beego.NSRouter("/user/list", userController, "post:Users"),
  52. beego.NSRouter("/user/detail", userController, "get:GetDetail"),
  53. beego.NSRouter("/user/save", userController, "post:Update"),
  54. beego.NSRouter("/user/modifyPassword", userController, "post:UpdatePassword"),
  55. beego.NSRouter("/user/resetPassword", userController, "post:ResetPassword"),
  56. beego.NSRouter("/oauth2", &oauth2.Controller{}),
  57. beego.NSRouter("/oauth2/callback", &oauth2.Controller{}, "post:Callback"),
  58. // settings
  59. beego.NSRouter("/settings/list", &settings.SettingController{}, "post:List"),
  60. beego.NSRouter("/settings/save", &settings.SettingController{}, "post:Save"),
  61. beego.NSRouter("/settings/delete", &settings.SettingController{}, "post:Delete"),
  62. )
  63. beego.AddNamespace(ns)
  64. // LDAP路由
  65. beego.AddNamespace(ldap.InitRouter(config.BaseApi))
  66. beego.InsertFilter(fmt.Sprintf("%s/**", config.BaseApi), beego.BeforeRouter, middleware.AuthFilter)
  67. beego.Router(fmt.Sprintf("%s/config.js", config.ContextPath), &nginx_controller.ConfigController{})
  68. // portal static assets
  69. beego.SetStaticPath(config.ContextPath, "static/web")
  70. webPrefix := config.ContextPath
  71. if !strings.HasSuffix(webPrefix, "/") {
  72. webPrefix = webPrefix + "/"
  73. }
  74. beego.Get("/", func(ctx *context.Context) {
  75. ctx.Redirect(301, webPrefix)
  76. })
  77. beego.ErrorController(&base.ErrorController{
  78. WebPath: webPrefix,
  79. })
  80. }