/
app.go
119 lines (101 loc) · 3.68 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package dashboard
import "github.com/gin-gonic/gin"
import "fmt"
import . "wapour/dashboard/actions"
import . "wapour/dashboard/files"
import . "wapour/dashboard/hosts"
import "wapour/api/wengine"
import "wapour/auth"
//import "html/template"
func ActionsView()(func (c *gin.Context)) {
//template_name := "index.html"
//data["content"] = template.HTML(Actions())
return func(c *gin.Context ){
//c.HTML(200, template_name, data )
c.String(200,Actions())
}
}
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 FilesView()(func (c *gin.Context)) {
//template_name := "index.html"
//var content string
//content = Files()
// content += Actions() : Example of creating several tables
//data["content"] = template.HTML(content)
return func(c *gin.Context ){
//c.HTML(200, template_name, data )
c.String(200, Files())
}
}
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{}})
}
}
}
func HostsView()(func (c *gin.Context)) {
return func(c *gin.Context ){
c.String(200, Hosts())
}
}
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 Overview()(func (c *gin.Context)) {
template_name:="table.html"
return func(c *gin.Context ){
c.HTML(200, template_name , gin.H{})
}
}