diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2025-07-01 01:28:09 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-01 01:28:09 -0700 |
| commit | 1defee3d682d86c7e0cbc7db7ebdb9cae872a471 (patch) | |
| tree | dae266bee79c36a74214a47d3d9e9274b322d49d /weed/admin/dash/handler_auth.go | |
| parent | e5adc3872a79e062826a387e1e2bb68196f14014 (diff) | |
| download | seaweedfs-1defee3d682d86c7e0cbc7db7ebdb9cae872a471.tar.xz seaweedfs-1defee3d682d86c7e0cbc7db7ebdb9cae872a471.zip | |
Add admin component (#6928)
* init version
* relocate
* add s3 bucket link
* refactor handlers into weed/admin folder
* fix login logout
* adding favicon
* remove fall back to http get topology
* grpc dial option, disk total capacity
* show filer count
* fix each volume disk usage
* add filers to dashboard
* adding hosts, volumes, collections
* refactor code and menu
* remove "refresh" button
* fix data for collections
* rename cluster hosts into volume servers
* add masters, filers
* reorder
* adding file browser
* create folder and upload files
* add filer version, created at time
* remove mock data
* remove fields
* fix submenu item highlighting
* fix bucket creation
* purge files
* delete multiple
* fix bucket creation
* remove region from buckets
* add object store with buckets and users
* rendering permission
* refactor
* get bucket objects and size
* link to file browser
* add file size and count for collections page
* paginate the volumes
* fix possible SSRF
https://github.com/seaweedfs/seaweedfs/pull/6928/checks?check_run_id=45108469801
* Update weed/command/admin.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/command/admin.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* fix build
* import
* remove filer CLI option
* remove filer option
* remove CLI options
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Diffstat (limited to 'weed/admin/dash/handler_auth.go')
| -rw-r--r-- | weed/admin/dash/handler_auth.go | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/weed/admin/dash/handler_auth.go b/weed/admin/dash/handler_auth.go new file mode 100644 index 000000000..c0b7d5636 --- /dev/null +++ b/weed/admin/dash/handler_auth.go @@ -0,0 +1,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"}) +} |
