fix
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user