-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.go
More file actions
60 lines (48 loc) · 1.28 KB
/
admin.go
File metadata and controls
60 lines (48 loc) · 1.28 KB
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
package main
import (
"errors"
"io"
"log"
"net/http"
"time"
"github.com/ejv2/prepper/logging"
"github.com/gin-gonic/gin"
)
// handleAdminRoot is the handler for "/admin/".
//
// Displays a simple UI for selecting the admin function desired.
func handleAdminRoot(c *gin.Context) {
s := Sessions.Start(c)
defer s.Update()
ddat, err := NewDashboardData(s)
if err != nil {
internalError(c, err)
return
}
c.HTML(http.StatusOK, "admin.gohtml", ddat)
}
func handleAdminLogs(c *gin.Context) {
l := Dmesg.Grab()
defer l.Release()
r := Dmesg.Reader()
buf, _ := io.ReadAll(r)
buf = logging.StripColors(buf)
c.Writer.Write(buf)
}
func handleAdminError(c *gin.Context) {
internalError(c, errors.New("Admin-Triggered Fatal Error"))
}
func handleAdminMaintenance(c *gin.Context) {
if Maintenance.Enter() != nil {
log.Panic("somehow got to admin maintenance handler when in maintenance?")
}
log.Println(c.RemoteIP(), "enables maintenance mode from admin panel")
c.String(http.StatusOK, "Maintenance mode enabled by system administrator.\nTimestamp: %v", time.Now().Format(time.RFC1123))
}
// handleAdminRunMaint is the handler for "/admin/runnow".
//
// Runs admin maintenance tasks now!
func handleAdminRunMaint(c *gin.Context) {
MSched.Now()
c.Redirect(http.StatusFound, "/admin/")
}