func GetDashboardData() func(c *gin.Context) { return func(c *gin.Context) { if user_id, token_id, err := auth.GetTokenFromCookies(c); auth.IsAuthorized(c) && err == nil { dashboardId := c.Param("dashboardId") dashboardGroupId := c.Param("dashboardGroupId") fmt.Printf("\nDashboard %v DashboardGroup %v\n", dashboardId, dashboardGroupId) dashboard_data, _ := webclient.GetDashboardData(user_id, token_id, dashboardId) c.JSON(200, gin.H{"status": "ok", "data": dashboard_data}) } else { c.JSON(200, gin.H{"status": "error"}) } } }
func Index() func(c *gin.Context) { template_name := "index.html" navigaton_menu := GetNavigationMenu() data := gin.H{"navigation_items": navigaton_menu, "static_url": settings.STATIC_URL, "app_data_url": settings.ADMIN_DATA_URL, "websocket": "false"} return func(c *gin.Context) { if auth.IsAuthorized(c) == true { c.HTML(200, template_name, data) } else { c.Redirect(302, "/auth/login"+"?redirect_to="+"/index") } } }
func UserspaceData() func(c *gin.Context) { //template_name := "index.html" return func(c *gin.Context) { if user_id, token_id, err := auth.GetTokenFromCookies(c); auth.IsAuthorized(c) && err == nil { dashboards := webclient.GetUserDashboards(user_id, token_id) data := settings.APP_SETTINGS data["navigation_menu"] = CreateNavigationMenuJson(dashboards) //data["status"] = "ok" c.JSON(200, gin.H{"status": "ok", "data": data}) } else { c.JSON(401, gin.H{"status": "Unauthorized", "data": gin.H{}}) } } }
func IndexData() func(c *gin.Context) { return func(c *gin.Context) { if auth.IsAuthorized(c) == true { /* menu_name:="Admin Dashboard" var navigation_menu = gin.H { "menu_name": menu_name , "items":items } data_items:=[]gin.H{ gin.H{"data_type":"wapour-table","name":"Files Table","id":"files_table","title":"Files Table","rows":rows, "header":header}} var data = gin.H{"data_items":data_items}*/ var data = gin.H{"navigation_menu": GetNavigationMenuJson()} c.JSON(200, gin.H{"status": "ok", "data": data}) } else { c.JSON(401, gin.H{"status": "Unauthorized", "data": gin.H{}}) } } }
func Login() func(c *gin.Context) { template_name := "login.html" server_addr := settings.SERVER_ADDR server_proto := settings.SERVER_PROTO server_port := settings.SERVER_PORT post_url := server_proto + "://" + server_addr + ":" + server_port + "/auth/login" data := gin.H{"post_url": post_url, "static_url": settings.STATIC_URL} return func(c *gin.Context) { redirect_to := c.DefaultQuery("redirect_to", "/index") if common.IsIn(redirect_to, settings.ALLOWED_REDIRECTS) == false { redirect_to = "/index" } if auth.IsAuthorized(c) == true { c.Redirect(302, redirect_to) } else { data["post_url"] = post_url + "?redirect_to=" + redirect_to c.HTML(200, template_name, data) } } }
func Index() func(c *gin.Context) { template_name := "index.html" self_link := "/userspace" return func(c *gin.Context) { //if (auth.IsAuthorized(c,wrappers) && (user_id,token_id,err:=auth.GetTokenFromCookies(c); err==nil) ) { // thanks for postman from golang@cjr if user_id, token_id, err := auth.GetTokenFromCookies(c); auth.IsAuthorized(c) && err == nil { session_id, _ := common.GenId() dashboards := webclient.GetUserDashboards(user_id, token_id) navigaton_menu := CreateNavigationMenu(dashboards) data := settings.APP_SETTINGS data["navigation_menu"] = navigaton_menu data["session_id"] = session_id data["websocket"] = "true" data["app_data_url"] = settings.USERSPACE_DATA_URL c.HTML(200, template_name, data) } else { c.Redirect(302, "/auth/login?redirect_to="+self_link) } } }
func HostsJson() func(c *gin.Context) { return func(c *gin.Context) { if auth.IsAuthorized(c) == true { rows := [][]string{} api := wengine.GetApi("", "", "") _, hosts := api.HostsList() // header := []string{"ID"} for id := range hosts { host := hosts[id] row := []string{host.Id} rows = append(rows, row) } data_items := []gin.H{gin.H{"data_type": "wapour-table", "name": "Files Table", "id": "files_table", "title": "Files Table", "rows": rows, "header": header}} var data = gin.H{"data_items": data_items} c.JSON(200, gin.H{"status": "ok", "data": data}) } else { c.JSON(401, gin.H{"status": "Unauthorized", "data": gin.H{}}) } } }
func ActionsJson() func(c *gin.Context) { return func(c *gin.Context) { if auth.IsAuthorized(c) == true { rows := [][]string{} api := wengine.GetApi("", "", "") _, action_list := api.ActionsList() header := []string{"Name", "Command"} for id := range action_list { action := action_list[id] row := []string{action.Name, action.Command} rows = append(rows, row) } data_items := []gin.H{gin.H{"data_type": "wapour-table", "name": "Actions Table", "id": "actions_table", "title": "Actions Table", "rows": rows, "header": header}} var data = gin.H{"data_items": data_items} c.JSON(200, gin.H{"status": "ok", "data": data}) } else { c.JSON(401, gin.H{"status": "Unauthorized", "data": gin.H{}}) } } }
func FilesJson() func(c *gin.Context) { return func(c *gin.Context) { if auth.IsAuthorized(c) == true { rows := [][]string{} api := wengine.GetApi("", "", "") _, file_list := api.FilesList() // header := []string{"Name", "Path", "IsDir"} for id := range file_list { file := file_list[id] row := []string{file.Name, file.Path, fmt.Sprintf("%v", file.IsDir)} rows = append(rows, row) } data_items := []gin.H{gin.H{"data_type": "wapour-table", "name": "Files Table", "id": "files_table", "title": "Files Table", "rows": rows, "header": header}} var data = gin.H{"data_items": data_items} c.JSON(200, gin.H{"status": "ok", "data": data}) } else { c.JSON(401, gin.H{"status": "Unauthorized", "data": gin.H{}}) } } }