Example #1
0
func ConfigRoutes() {
	//owl-protal-routes
	dashboard := beego.NewNamespace("/api/v1/dashboard",
		beego.NSGet("/notallowed", func(ctx *context.Context) {
			ctx.Output.Body([]byte("notAllowed"))
		}),
		beego.NSRouter("/endpoints", &DashBoardController{}, "get:EndpRegxqury;post:EndpRegxqury"),
		beego.NSRouter("/endpointcounters", &DashBoardController{}, "get:CounterQuery;post:CounterQuery"),
	)
	hostgroup := beego.NewNamespace("/api/v1/hostgroup",
		beego.NSGet("/notallowed", func(ctx *context.Context) {
			ctx.Output.Body([]byte("notAllowed"))
		}),
		beego.NSRouter("/query", &DashBoardController{}, "get:HostGroupQuery;post:HostGroupQuery"),
		beego.NSRouter("/hosts", &DashBoardController{}, "get:HostsQueryByHostGroups;post:HostsQueryByHostGroups"),
		beego.NSRouter("/hostgroupscounters", &DashBoardController{}, "get:CounterQueryByHostGroup;post:CounterQueryByHostGroup"),
		beego.NSRouter("/count", &DashBoardController{}, "get:CountNumOfHostGroup;post:CountNumOfHostGroup"),
	)
	beego.Router("/ops/endpoints", &DashBoardController{}, "get:EndpRegxquryForOps")
	beego.AddNamespace(dashboard)
	beego.AddNamespace(hostgroup)
}
Example #2
0
func ConfigRoutes() {
	//owl-protal-routes
	portal := beego.NewNamespace("/api/v1/portal",
		beego.NSGet("/notallowed", func(ctx *context.Context) {
			ctx.Output.Body([]byte("notAllowed"))
		}),
		beego.NSRouter("/eventcases/get", &PortalController{}, "get:EventCasesGet;post:EventCasesGet"),
		beego.NSRouter("/events/get", &PortalController{}, "get:EventGet;post:EventGet"),
		beego.NSRouter("/eventcases/close", &PortalController{}, "get:ColseCase;post:ColseCase;put:ColseCase"),
		beego.NSRouter("/tpl/count", &PortalController{}, "get:CountNumOfTlp;post:CountNumOfTlp"),
	)
	beego.AddNamespace(portal)
}
Example #3
0
func router() {
	authR := beego.NewNamespace("/auth",
		beego.NSCond(func(ctx *context.Context) bool {
			if ctx.Input.Domain() == "api.beego.me" {
				return true
			}
			commonFilter(ctx)
			return true
		}),
		// beego.NSBefore(func(ctx *context.Context) {
		// beego.Debug("path=>", ctx.Request.URL.Path)
		// services.etInstance().AuthService.WithContext(ctx, func() {
		// if services.GetInstance().AuthService.HasLogin() {
		// ctx.Redirect(200, "/admin/index")
		// }
		// })
		// }),
		beego.NSRouter("/login", &controllers.AuthController{}, "*:Login"),
		beego.NSRouter("/logout", &controllers.AuthController{}, "*:Logout"),
	)

	adminR := beego.NewNamespace("/admin",
		beego.NSBefore(func(ctx *context.Context) {
			commonFilter(ctx)
			services.GetInstance().AuthService.WithContext(ctx, func() {
				if !services.GetInstance().AuthService.HasLogin() {
					ctx.Redirect(302, "/auth/login")
				}
			})
		}),
		beego.NSRouter("/index", &controllers.AdminController{}, "*:Index"),
		beego.NSNamespace("/user",
			beego.NSGet("/info/:id", func(ctx *context.Context) {
				ctx.Output.Body([]byte("shopinfo"))
			}),
			beego.NSRouter("/list", &controllers.AdminController{}, "Get:UserList"),
			beego.NSRouter("/operate/?:userId", &controllers.AdminController{}, "*:UserOperate"),
			beego.NSRouter("/delete/:userId", &controllers.AdminController{}, "Get:UserDelete"),
		),
		beego.NSNamespace("/agent",
			beego.NSRouter("/list", &controllers.AdminController{}, "Get:AgentList"),
			beego.NSRouter("/operate/?:agentId", &controllers.AdminController{}, "*:AgentOperate"),
			beego.NSRouter("/delete/:agentId", &controllers.AdminController{}, "Get:AgentDelete"),
			beego.NSRouter("/:agentId/cmd/list", &controllers.AdminController{}, "Get:CmdList"),
			beego.NSRouter("/:agentId/cmd/operate", &controllers.AdminController{}, "*:CmdOperate"),
			beego.NSRouter("/:agentId/cmd/operate/?:cmdId", &controllers.AdminController{}, "*:CmdOperate"),
			beego.NSRouter("/cmd/delete/:cmdId", &controllers.AdminController{}, "Get:CmdDelete"),
		),
		beego.NSNamespace("/ssh",
			beego.NSRouter("/:agentId", &controllers.AdminController{}, "Get:SshIndex"),
			beego.NSRouter("/join/:agentId", &controllers.AdminController{}, "*:SshJoin"),
			beego.NSRouter("/list", &controllers.AdminController{}, "*:SshList"),
		),
		beego.NSNamespace("/server",
			beego.NSRouter("/index/?:serverId", &controllers.ServerController{}, "Get:Index"),
			beego.NSRouter("/operate/?:serverId", &controllers.ServerController{}, "*:Operate"),
			beego.NSRouter("/delete/:serverId", &controllers.ServerController{}, "Get:Delete"),
		),
	)

	guestR := beego.NewNamespace("/guest",
		beego.NSBefore(func(ctx *context.Context) {
			commonFilter(ctx)
		}),
		beego.NSNamespace("/server",
			beego.NSRouter("/share/:serverId", &controllers.ServerController{}, "Get:Share"),
			beego.NSRouter("/:serverId/active/:apiParamId", &controllers.ServerController{}, "*:Active"),
			beego.NSRouter("/:serverId/encode/:apiParamId", &controllers.ServerController{}, "Post:Encode"),
			beego.NSRouter("/info", &controllers.ServerController{}, "Get:Info"),
		),
	)

	//注册namespace
	beego.AddNamespace(authR, adminR, guestR)

}
Example #4
0
func ConfigRoutes() {

	//open-falcon's routes
	beego.Router("/root", &UserController{}, "get:CreateRoot")
	beego.Router("/auth/login", &AuthController{}, "get:LoginGet;post:LoginPost")
	beego.Router("/auth/login/:token", &AuthController{}, "get:LoginWithToken")
	beego.Router("/auth/third-party", &AuthController{}, "post:LoginThirdParty")
	beego.Router("/auth/register", &AuthController{}, "get:RegisterGet;post:RegisterPost")

	beego.Router("/sso/sig", &SsoController{}, "get:Sig")
	beego.Router("/sso/user/:sig:string", &SsoController{}, "get:User")
	beego.Router("/sso/logout/:sig:string", &SsoController{}, "get:Logout")

	beego.Router("/user/query", &UserController{}, "get:Query")
	beego.Router("/user/in", &UserController{}, "get:In")
	beego.Router("/user/qrcode/:id:int", &UserController{}, "get:QrCode")
	beego.Router("/about/:name:string", &UserController{}, "get:About")

	beego.Router("/team/users", &TeamController{}, "get:Users")
	beego.Router("/team/query", &TeamController{}, "get:Query")
	beego.Router("/team/all", &TeamController{}, "get:All")

	//owl-protal-routes
	apins := beego.NewNamespace("/api/v1/auth",
		beego.NSGet("/notallowed", func(ctx *context.Context) {
			ctx.Output.Body([]byte("notAllowed"))
		}),
		beego.NSRouter("/register", &AuthApiController{}, "post:Register"),
		beego.NSRouter("/login", &AuthApiController{}, "post:Login"),
		beego.NSRouter("/sessioncheck", &AuthApiController{}, "get:AuthSession;post:AuthSession"),
		beego.NSRouter("/logout", &AuthApiController{}, "get:Logout;post:Logout"),
		beego.NSRouter("/user", &AuthApiController{}, "post:GetUser"),
		beego.NSRouter("/user/update", &AuthApiController{}, "put:UpdateUser;post:UpdateUser"),
		beego.NSRouter("/team/count", &AuthApiController{}, "get:CountNumOfTeam;post:CountNumOfTeam"),
	)
	beego.AddNamespace(apins)

	loginRequired :=
		beego.NewNamespace("/me",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser),
			beego.NSRouter("/logout", &AuthController{}, "*:Logout"),
			beego.NSRouter("/info", &UserController{}, "get:Info"),
			beego.NSRouter("/profile", &UserController{}, "get:ProfileGet;post:ProfilePost"),
			beego.NSRouter("/chpwd", &UserController{}, "*:ChangePassword"),
			beego.NSRouter("/users", &UserController{}, "get:Users"),
			beego.NSRouter("/user/c", &UserController{}, "get:CreateUserGet;post:CreateUserPost"),
			beego.NSRouter("/teams", &TeamController{}, "get:Teams"),
			beego.NSRouter("/team/c", &TeamController{}, "get:CreateTeamGet;post:CreateTeamPost"),
		)

	beego.AddNamespace(loginRequired)

	targetUserRequired :=
		beego.NewNamespace("/target-user",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser, base.FilterTargetUser),
			beego.NSRouter("/delete", &UserController{}, "*:DeleteUser"),
			beego.NSRouter("/edit", &UserController{}, "get:EditGet;post:EditPost"),
			beego.NSRouter("/chpwd", &UserController{}, "post:ResetPassword"),
			beego.NSRouter("/role", &UserController{}, "*:Role"),
		)

	beego.AddNamespace(targetUserRequired)

	targetTeamRequired :=
		beego.NewNamespace("/target-team",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser, base.FilterTargetTeam),
			beego.NSRouter("/delete", &TeamController{}, "*:DeleteTeam"),
			beego.NSRouter("/edit", &TeamController{}, "get:EditGet;post:EditPost"),
		)

	beego.AddNamespace(targetTeamRequired)

}