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
120
121
122
123
124
125
126
127
128
|
package dash
import (
"net/http"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
// ShowLogin displays the login page
func (s *AdminServer) ShowLogin(c *gin.Context) {
// If authentication is not required, redirect to admin
session := sessions.Default(c)
if session.Get("authenticated") == true {
c.Redirect(http.StatusSeeOther, "/admin")
return
}
// For now, return a simple login form as JSON
c.HTML(http.StatusOK, "login.html", gin.H{
"title": "SeaweedFS Admin Login",
"error": c.Query("error"),
})
}
// HandleLogin handles login form submission
func (s *AdminServer) HandleLogin(username, password string) gin.HandlerFunc {
return func(c *gin.Context) {
loginUsername := c.PostForm("username")
loginPassword := c.PostForm("password")
if loginUsername == username && loginPassword == password {
session := sessions.Default(c)
session.Set("authenticated", true)
session.Set("username", loginUsername)
session.Save()
c.Redirect(http.StatusSeeOther, "/admin")
return
}
// Authentication failed
c.Redirect(http.StatusSeeOther, "/login?error=Invalid credentials")
}
}
// HandleLogout handles user logout
func (s *AdminServer) HandleLogout(c *gin.Context) {
session := sessions.Default(c)
session.Clear()
session.Save()
c.Redirect(http.StatusSeeOther, "/login")
}
// Additional methods for admin functionality
func (s *AdminServer) GetClusterTopologyHandler(c *gin.Context) {
topology, err := s.GetClusterTopology()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, topology)
}
func (s *AdminServer) GetMasters(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"masters": []string{s.masterAddress}})
}
func (s *AdminServer) GetVolumeServers(c *gin.Context) {
topology, err := s.GetClusterTopology()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"volume_servers": topology.VolumeServers})
}
func (s *AdminServer) AssignVolume(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "Volume assignment not yet implemented"})
}
func (s *AdminServer) ListVolumes(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "Volume listing not yet implemented"})
}
func (s *AdminServer) CreateVolume(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "Volume creation not yet implemented"})
}
func (s *AdminServer) DeleteVolume(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "Volume deletion not yet implemented"})
}
func (s *AdminServer) ReplicateVolume(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "Volume replication not yet implemented"})
}
func (s *AdminServer) BrowseFiles(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "File browsing not yet implemented"})
}
func (s *AdminServer) UploadFile(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "File upload not yet implemented"})
}
func (s *AdminServer) DeleteFile(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "File deletion not yet implemented"})
}
func (s *AdminServer) ShowMetrics(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "Metrics display not yet implemented"})
}
func (s *AdminServer) GetMetricsData(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "Metrics data not yet implemented"})
}
func (s *AdminServer) TriggerGC(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "Garbage collection not yet implemented"})
}
func (s *AdminServer) CompactVolumes(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "Volume compaction not yet implemented"})
}
func (s *AdminServer) GetMaintenanceStatus(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "Maintenance status not yet implemented"})
}
|