1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package routers
- import (
- "fmt"
- "github.com/astaxie/beego"
- "github.com/astaxie/beego/context"
- "github.com/astaxie/beego/logs"
- "nginx-ui/server/base"
- config2 "nginx-ui/server/config"
- "nginx-ui/server/middleware"
- "nginx-ui/server/modules/ldap"
- "nginx-ui/server/modules/nginx/nginx_controller"
- "nginx-ui/server/modules/oauth2"
- "nginx-ui/server/modules/settings"
- "nginx-ui/server/modules/user"
- "strings"
- )
- var NginxR = "/nginx"
- var NginxGetR = "/nginx/:id"
- var NginxRefreshR = "/nginx/:id/http/refresh"
- var NginxStartR = "/nginx/:id/start"
- var NginxStopR = "/nginx/:id/stop"
- var NginxStatusR = "/nginx/:id/status"
- func init() {
- config := config2.Config
- userController := user.NewUserController()
- logs.Info("baseApi", config.BaseApi)
- ns := beego.NewNamespace(config.BaseApi,
- beego.NSRouter(NginxR, &nginx_controller.NginxController{}),
- beego.NSRouter(NginxGetR, &nginx_controller.NginxController{}, "post:Update"),
- beego.NSRouter(NginxGetR, &nginx_controller.NginxController{}, "get:GetNginx"),
- beego.NSRouter(NginxGetR, &nginx_controller.NginxController{}, "delete:DelNginx"),
- beego.NSRouter(NginxRefreshR, &nginx_controller.NginxController{}, "post:RefreshHttp"),
- beego.NSRouter(NginxStartR, &nginx_controller.NginxController{}, "post:StartNginx"),
- beego.NSRouter(NginxStopR, &nginx_controller.NginxController{}, "post:StopNginx"),
- beego.NSRouter(NginxStatusR, &nginx_controller.NginxController{}, "post:StatusNginx"),
- // certs
- beego.NSRouter("/nginx/:id/certs", &nginx_controller.CertController{}),
- beego.NSRouter("/nginx/:id/certs/sync", &nginx_controller.CertController{}, "post:Sync"),
- // nginx server apis
- beego.NSRouter("/nginx/:id/server", &nginx_controller.ServerController{}),
- beego.NSRouter("/nginx/:id/server/refresh", &nginx_controller.ServerController{}, "post:Refresh"),
- // file upload download
- beego.NSRouter("/nginx/:id/file/deploy", &nginx_controller.FileController{}, "post:Deploy"),
- beego.NSRouter("/file", &nginx_controller.FileController{}),
- beego.NSRouter("/logger", &nginx_controller.LoggerController{}),
- beego.NSRouter("/user/login", userController, "post:Login"),
- beego.NSRouter("/user/logout", userController, "post:Logout"),
- beego.NSRouter("/user/info", userController, "get:User"),
- beego.NSRouter("/user/info", userController, "post:UpdateUserInfo"),
- beego.NSRouter("/user/register", userController, "post:Register"),
- beego.NSRouter("/user/list", userController, "post:Users"),
- beego.NSRouter("/user/detail", userController, "get:GetDetail"),
- beego.NSRouter("/user/save", userController, "post:Update"),
- beego.NSRouter("/user/modifyPassword", userController, "post:UpdatePassword"),
- beego.NSRouter("/user/resetPassword", userController, "post:ResetPassword"),
- beego.NSRouter("/oauth2", &oauth2.Controller{}),
- beego.NSRouter("/oauth2/callback", &oauth2.Controller{}, "post:Callback"),
- // settings
- beego.NSRouter("/settings/list", &settings.SettingController{}, "post:List"),
- beego.NSRouter("/settings/save", &settings.SettingController{}, "post:Save"),
- beego.NSRouter("/settings/delete", &settings.SettingController{}, "post:Delete"),
- )
- beego.AddNamespace(ns)
- // LDAP路由
- beego.AddNamespace(ldap.InitRouter(config.BaseApi))
- beego.InsertFilter(fmt.Sprintf("%s/**", config.BaseApi), beego.BeforeRouter, middleware.AuthFilter)
- beego.Router(fmt.Sprintf("%s/config.js", config.ContextPath), &nginx_controller.ConfigController{})
- // portal static assets
- beego.SetStaticPath(config.ContextPath, "static/web")
- webPrefix := config.ContextPath
- if !strings.HasSuffix(webPrefix, "/") {
- webPrefix = webPrefix + "/"
- }
- beego.Get("/", func(ctx *context.Context) {
- ctx.Redirect(301, webPrefix)
- })
- beego.ErrorController(&base.ErrorController{
- WebPath: webPrefix,
- })
- }
|