-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.go
108 lines (90 loc) · 3.52 KB
/
views.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
package main
import (
"fmt"
"net/http"
"github.com/rexlx/threatco/views"
)
func (s *Server) LoginViewHandler(w http.ResponseWriter, r *http.Request) {
// need to format with details.fqdn
fmt.Fprintf(w, views.LoginView)
}
func (s *Server) LogViewHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, views.LogView)
}
func (s *Server) AllUsersViewHandler(w http.ResponseWriter, r *http.Request) {
// s.Memory.RLock()
// defer s.Memory.RUnlock()
_users, err := s.DB.GetAllUsers()
if err != nil {
s.Log.Println("AllUsersViewHandler", err)
}
users := ""
for _, u := range _users {
deleteButton := fmt.Sprintf(`<button class="button is-danger is-outlined" onclick="deleteUser('%s')">Delete</button>`, u.Email)
svcs := []string{}
for _, svc := range u.Services {
svcs = append(svcs, svc.Kind)
}
users += fmt.Sprintf(views.UserTableBody, u.Email, u.Admin, svcs, u.Created, u.Updated, deleteButton)
}
tempDiv := fmt.Sprintf(views.ViewUsersSection, users)
fmt.Fprintf(w, views.BaseView, tempDiv)
}
func (S *Server) CreateUserViewHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, views.AddUserView)
}
func (s *Server) AddServicesHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, views.AddServiceView)
}
func (s *Server) ChartViewHandler(w http.ResponseWriter, r *http.Request) {
s.Memory.RLock()
defer s.Memory.RUnlock()
out := string(s.Cache.Charts)
fmt.Fprint(w, out)
}
func (s *Server) ViewResponsesHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, views.ResponsesListView)
}
func (s *Server) ViewServicesHandler(w http.ResponseWriter, r *http.Request) {
s.Memory.RLock()
defer s.Memory.RUnlock()
serviceDiv := `<div class="box has-background-black-ter">
<div class="columns is-multiline">`
for _, service := range s.Details.SupportedServices {
// Create a unique modal ID for each service
modalID := fmt.Sprintf("modal-%s", service.Kind)
serviceDiv += fmt.Sprintf(`<div class="column">
<div class="card has-background-black-ter" style="height: 200px;"> <!-- Set fixed height -->
<div class="card-content">
<p class="title has-text-primary is-4">%s</p> <!-- Use title class for consistency -->
<div class="content">
<p class="has-text-white">Description or additional info can go here.</p> <!-- Optional description -->
</div>
<div class="has-text-centered">
<button class="button open-modal is-primary" data-modal-id="%s">View Details</button> <!-- Button to open modal -->
</div>
</div>
</div>
<!-- Modal Structure -->
<div class="modal" id="%s">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head has-background-black">
<p class="modal-card-title has-text-primary">%s types</p>
<button class="delete close-modal" aria-label="close"></button>
</header>
<section class="modal-card-body has-background-black"><ul>
`, service.Kind, modalID, modalID, service.Kind)
// Loop through service types
for _, t := range service.Type {
serviceDiv += fmt.Sprintf(`<li class="has-text-primary">%s</li>`, t) // Ensure t is a string
}
serviceDiv += `</ul></section>
</div>
</div>
</div>`
}
serviceDiv += `</div></div>`
tempDiv := fmt.Sprintf(views.ViewSection, serviceDiv)
fmt.Fprintf(w, views.BaseView, tempDiv)
}