This commit is contained in:
2026-02-13 23:27:54 +01:00
parent 1825b50dec
commit 1e126734b0
13 changed files with 2743 additions and 3 deletions

View File

@@ -6,8 +6,11 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/fs"
"net/http"
"time"
"git.ma-al.com/goc_marek/zfs/internal/server/templates/pages"
)
// Admin authentication and management handlers
@@ -679,9 +682,51 @@ func (s *Server) handleAdminChangePassword(w http.ResponseWriter, r *http.Reques
// handleAdminUI serves the admin panel UI
func (s *Server) handleAdminUI(w http.ResponseWriter, r *http.Request) {
// Serve the embedded admin UI HTML
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write([]byte(adminPanelHTML))
// Check if admin is authenticated
admin, _ := s.authenticateAdmin(r)
if admin != nil {
// Serve the admin panel using templ
w.Header().Set("Content-Type", "text/html; charset=utf-8")
pages.AdminPage(admin.Username).Render(r.Context(), w)
} else {
// Serve the login page using templ
w.Header().Set("Content-Type", "text/html; charset=utf-8")
pages.LoginPage().Render(r.Context(), w)
}
}
// handleAdminStatic serves static files for the admin panel
func (s *Server) handleAdminStatic(w http.ResponseWriter, r *http.Request) {
// Extract the file path from the URL
// URL format: /admin/static/<filename>
path := r.URL.Path[len("/admin/static/"):]
// Get the embedded filesystem
staticFS, err := GetStaticFS()
if err != nil {
http.Error(w, "Failed to load static files", http.StatusInternalServerError)
return
}
// Serve the file
content, err := fs.ReadFile(staticFS, path)
if err != nil {
http.NotFound(w, r)
return
}
// Set content type based on file extension
switch {
case len(path) >= 3 && path[len(path)-3:] == ".js":
w.Header().Set("Content-Type", "application/javascript; charset=utf-8")
case len(path) >= 4 && path[len(path)-4:] == ".css":
w.Header().Set("Content-Type", "text/css; charset=utf-8")
default:
w.Header().Set("Content-Type", "application/octet-stream")
}
w.Write(content)
}
// handleAdminResetClientPassword resets a client's API key to a new random value