hub: unified customer page, blocked status, dashboard merge
- Replace separate config detail and report detail pages with unified
/customers/{id} page showing both config info and live report data
- Add "blocked" status for customers (hidden from dashboard, notifications
suppressed, still accepts reports)
- Dashboard now shows config-only customers as "PENDING" status
- Customers list: all rows link to /customers/{id}, show BLOCKED badge
- New actions: block/unblock, push config to controller, auto-create
config from report data
- /configs/{id} now redirects to /customers/{id}
- Add config-badge CSS classes for MANAGED/MANUAL/BLOCKED badges
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -255,6 +255,15 @@ func (h *Handler) handleNotify(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
h.logger.Printf("[INFO] Notification from %s: %s (%s) — %s", payload.CustomerID, payload.EventType, payload.Severity, payload.Message)
|
||||
|
||||
// Check if customer is blocked
|
||||
if h.store.IsCustomerBlocked(payload.CustomerID) {
|
||||
h.logger.Printf("[INFO] Notification suppressed for blocked customer %s", payload.CustomerID)
|
||||
h.store.LogNotification(payload.CustomerID, payload.EventType, payload.Severity, payload.Message, "skipped", "customer blocked")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(`{"status":"ok","sent":false,"reason":"blocked"}`))
|
||||
return
|
||||
}
|
||||
|
||||
// Look up customer notification preferences
|
||||
prefs, err := h.store.GetNotificationPrefs(payload.CustomerID)
|
||||
if err != nil {
|
||||
|
||||
@@ -118,6 +118,9 @@ func (s *Store) migrate() error {
|
||||
// v0.1.8: add controller_url column (idempotent — ignore error if already exists)
|
||||
s.db.Exec("ALTER TABLE reports ADD COLUMN controller_url TEXT")
|
||||
|
||||
// v0.2.1: add status column to customer_configs (idempotent)
|
||||
s.db.Exec("ALTER TABLE customer_configs ADD COLUMN status TEXT NOT NULL DEFAULT 'active'")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -520,6 +523,7 @@ type CustomerConfig struct {
|
||||
RetrievalPassword string
|
||||
APIKey string
|
||||
ConfigJSON string // JSON object with customer-specific override fields
|
||||
Status string // "active" or "blocked"
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
@@ -550,11 +554,11 @@ func (s *Store) GetCustomerConfig(customerID string) (*CustomerConfig, error) {
|
||||
var createdAt, updatedAt string
|
||||
err := s.db.QueryRow(`
|
||||
SELECT customer_id, customer_name, domain, email,
|
||||
retrieval_password, api_key, config_json, created_at, updated_at
|
||||
retrieval_password, api_key, config_json, status, created_at, updated_at
|
||||
FROM customer_configs WHERE customer_id = ?`,
|
||||
customerID,
|
||||
).Scan(&cfg.CustomerID, &cfg.CustomerName, &cfg.Domain, &cfg.Email,
|
||||
&cfg.RetrievalPassword, &cfg.APIKey, &cfg.ConfigJSON,
|
||||
&cfg.RetrievalPassword, &cfg.APIKey, &cfg.ConfigJSON, &cfg.Status,
|
||||
&createdAt, &updatedAt)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
@@ -571,7 +575,7 @@ func (s *Store) GetCustomerConfig(customerID string) (*CustomerConfig, error) {
|
||||
func (s *Store) ListCustomerConfigs() ([]CustomerConfig, error) {
|
||||
rows, err := s.db.Query(`
|
||||
SELECT customer_id, customer_name, domain, email,
|
||||
retrieval_password, api_key, config_json, created_at, updated_at
|
||||
retrieval_password, api_key, config_json, status, created_at, updated_at
|
||||
FROM customer_configs ORDER BY customer_id`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -583,7 +587,7 @@ func (s *Store) ListCustomerConfigs() ([]CustomerConfig, error) {
|
||||
var cfg CustomerConfig
|
||||
var createdAt, updatedAt string
|
||||
if err := rows.Scan(&cfg.CustomerID, &cfg.CustomerName, &cfg.Domain, &cfg.Email,
|
||||
&cfg.RetrievalPassword, &cfg.APIKey, &cfg.ConfigJSON,
|
||||
&cfg.RetrievalPassword, &cfg.APIKey, &cfg.ConfigJSON, &cfg.Status,
|
||||
&createdAt, &updatedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -607,11 +611,11 @@ func (s *Store) GetCustomerConfigByAPIKey(apiKey string) (*CustomerConfig, error
|
||||
var createdAt, updatedAt string
|
||||
err := s.db.QueryRow(`
|
||||
SELECT customer_id, customer_name, domain, email,
|
||||
retrieval_password, api_key, config_json, created_at, updated_at
|
||||
retrieval_password, api_key, config_json, status, created_at, updated_at
|
||||
FROM customer_configs WHERE api_key = ?`,
|
||||
apiKey,
|
||||
).Scan(&cfg.CustomerID, &cfg.CustomerName, &cfg.Domain, &cfg.Email,
|
||||
&cfg.RetrievalPassword, &cfg.APIKey, &cfg.ConfigJSON,
|
||||
&cfg.RetrievalPassword, &cfg.APIKey, &cfg.ConfigJSON, &cfg.Status,
|
||||
&createdAt, &updatedAt)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
@@ -624,6 +628,26 @@ func (s *Store) GetCustomerConfigByAPIKey(apiKey string) (*CustomerConfig, error
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
// SetCustomerConfigStatus sets the status (active/blocked) for a customer config.
|
||||
func (s *Store) SetCustomerConfigStatus(customerID, status string) error {
|
||||
_, err := s.db.Exec(`
|
||||
UPDATE customer_configs SET status = ?, updated_at = datetime('now')
|
||||
WHERE customer_id = ?`,
|
||||
status, customerID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
// IsCustomerBlocked returns true if the customer config has status "blocked".
|
||||
func (s *Store) IsCustomerBlocked(customerID string) bool {
|
||||
var status string
|
||||
err := s.db.QueryRow(
|
||||
"SELECT status FROM customer_configs WHERE customer_id = ?",
|
||||
customerID,
|
||||
).Scan(&status)
|
||||
return err == nil && status == "blocked"
|
||||
}
|
||||
|
||||
// UpdateRetrievalPassword updates the retrieval password for a customer config.
|
||||
func (s *Store) UpdateRetrievalPassword(customerID, newPassword string) error {
|
||||
_, err := s.db.Exec(`
|
||||
|
||||
+313
-51
@@ -3,6 +3,7 @@ package web
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"sort"
|
||||
@@ -21,7 +22,8 @@ type customerListEntry struct {
|
||||
CustomerName string
|
||||
Domain string
|
||||
HasConfig bool
|
||||
OverallStatus string // ok, warn, down, disabled, "" if no reports
|
||||
IsBlocked bool
|
||||
OverallStatus string // ok, warn, down, disabled, pending, "" if no reports
|
||||
ControllerVersion string
|
||||
TimeSinceReport time.Duration
|
||||
ConfigCreatedAt time.Time
|
||||
@@ -52,6 +54,7 @@ func (s *Server) handleConfigList(w http.ResponseWriter, r *http.Request) {
|
||||
CustomerName: cfg.CustomerName,
|
||||
Domain: cfg.Domain,
|
||||
HasConfig: true,
|
||||
IsBlocked: cfg.Status == "blocked",
|
||||
ConfigCreatedAt: cfg.CreatedAt,
|
||||
}
|
||||
}
|
||||
@@ -109,6 +112,167 @@ func (s *Server) handleConfigList(w http.ResponseWriter, r *http.Request) {
|
||||
s.templates.ExecuteTemplate(w, "configs.html", data)
|
||||
}
|
||||
|
||||
// handleCustomerUnified shows the unified customer detail page (config + reports).
|
||||
func (s *Server) handleCustomerUnified(w http.ResponseWriter, r *http.Request, customerID string) {
|
||||
cfg, _ := s.store.GetCustomerConfig(customerID)
|
||||
customer, _ := s.store.GetCustomer(customerID)
|
||||
|
||||
// 404 if neither config nor reports exist
|
||||
if cfg == nil && customer == nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
// Determine identity fields from best source
|
||||
name := ""
|
||||
domain := ""
|
||||
email := ""
|
||||
if cfg != nil {
|
||||
name = cfg.CustomerName
|
||||
domain = cfg.Domain
|
||||
email = cfg.Email
|
||||
}
|
||||
if name == "" && customer != nil {
|
||||
name = customer.CustomerName
|
||||
}
|
||||
|
||||
// Parse report JSON
|
||||
var report map[string]interface{}
|
||||
if customer != nil {
|
||||
json.Unmarshal([]byte(customer.ReportJSON), &report)
|
||||
}
|
||||
|
||||
// Parse config overrides
|
||||
var overrides map[string]interface{}
|
||||
if cfg != nil {
|
||||
json.Unmarshal([]byte(cfg.ConfigJSON), &overrides)
|
||||
}
|
||||
|
||||
// Overall status
|
||||
overallStatus := "pending"
|
||||
if customer != nil {
|
||||
if customer.HealthStatus == "disabled" {
|
||||
overallStatus = "disabled"
|
||||
} else if customer.TimeSinceReport > time.Hour {
|
||||
overallStatus = "down"
|
||||
} else if customer.TimeSinceReport > 30*time.Minute || customer.HealthStatus == "warn" {
|
||||
overallStatus = "warn"
|
||||
} else if customer.HealthStatus == "fail" {
|
||||
overallStatus = "down"
|
||||
} else {
|
||||
overallStatus = "ok"
|
||||
}
|
||||
}
|
||||
if cfg != nil && cfg.Status == "blocked" {
|
||||
overallStatus = "blocked"
|
||||
}
|
||||
|
||||
// Controller URL
|
||||
controllerURL := ""
|
||||
if customer != nil {
|
||||
controllerURL = customer.ControllerURL
|
||||
if controllerURL == "" {
|
||||
var rpt struct {
|
||||
ControllerURL string `json:"controller_url"`
|
||||
}
|
||||
json.Unmarshal([]byte(customer.ReportJSON), &rpt)
|
||||
controllerURL = rpt.ControllerURL
|
||||
}
|
||||
}
|
||||
|
||||
// Version check
|
||||
var latestVersion string
|
||||
var updateAvailable bool
|
||||
if s.versionChecker != nil && customer != nil {
|
||||
latestVersion = s.versionChecker.LatestVersion()
|
||||
if latestVersion != "" && customer.ControllerVersion != "" {
|
||||
updateAvailable = latestVersion != customer.ControllerVersion && compareVersions(latestVersion, customer.ControllerVersion) > 0
|
||||
}
|
||||
}
|
||||
|
||||
// History, notifications, infra backup
|
||||
var history []store.CustomerSummary
|
||||
var notifPrefs *store.NotificationPrefs
|
||||
var recentNotifs []store.NotificationLogEntry
|
||||
var infraMeta *store.InfraBackupMeta
|
||||
var infraBackupAge string
|
||||
|
||||
if customer != nil {
|
||||
history, _ = s.store.GetCustomerHistory(customerID, 24*time.Hour)
|
||||
notifPrefs, _ = s.store.GetNotificationPrefs(customerID)
|
||||
recentNotifs, _ = s.store.GetRecentNotifications(customerID, 10)
|
||||
infraMeta, _ = s.store.GetInfraBackupMeta(customerID)
|
||||
if infraMeta != nil {
|
||||
infraBackupAge = timeAgo(infraMeta.UpdatedAt)
|
||||
}
|
||||
}
|
||||
|
||||
type pageData struct {
|
||||
CustomerID string
|
||||
CustomerName string
|
||||
Domain string
|
||||
Email string
|
||||
|
||||
HasConfig bool
|
||||
Config *store.CustomerConfig
|
||||
Overrides map[string]interface{}
|
||||
IsBlocked bool
|
||||
|
||||
HasReports bool
|
||||
Customer *store.CustomerSummary
|
||||
Report map[string]interface{}
|
||||
OverallStatus string
|
||||
|
||||
LatestVersion string
|
||||
UpdateAvailable bool
|
||||
ControllerURL string
|
||||
|
||||
InfraBackup *store.InfraBackupMeta
|
||||
InfraBackupAge string
|
||||
NotifPrefs *store.NotificationPrefs
|
||||
RecentNotifications []store.NotificationLogEntry
|
||||
History []store.CustomerSummary
|
||||
|
||||
Flash string
|
||||
ActiveNav string
|
||||
}
|
||||
|
||||
data := pageData{
|
||||
CustomerID: customerID,
|
||||
CustomerName: name,
|
||||
Domain: domain,
|
||||
Email: email,
|
||||
|
||||
HasConfig: cfg != nil,
|
||||
Config: cfg,
|
||||
Overrides: overrides,
|
||||
IsBlocked: cfg != nil && cfg.Status == "blocked",
|
||||
|
||||
HasReports: customer != nil,
|
||||
Customer: customer,
|
||||
Report: report,
|
||||
OverallStatus: overallStatus,
|
||||
|
||||
LatestVersion: latestVersion,
|
||||
UpdateAvailable: updateAvailable,
|
||||
ControllerURL: controllerURL,
|
||||
|
||||
InfraBackup: infraMeta,
|
||||
InfraBackupAge: infraBackupAge,
|
||||
NotifPrefs: notifPrefs,
|
||||
RecentNotifications: recentNotifs,
|
||||
History: history,
|
||||
|
||||
Flash: r.URL.Query().Get("flash"),
|
||||
ActiveNav: "configs",
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
if err := s.templates.ExecuteTemplate(w, "customer_unified.html", data); err != nil {
|
||||
s.logger.Printf("[ERROR] Template render: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// handleConfigNewForm shows the form to create a new customer config.
|
||||
func (s *Server) handleConfigNewForm(w http.ResponseWriter, r *http.Request) {
|
||||
data := struct {
|
||||
@@ -187,38 +351,7 @@ func (s *Server) handleConfigCreate(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
s.logger.Printf("[INFO] Customer config created: %s", customerID)
|
||||
http.Redirect(w, r, "/configs/"+customerID+"?flash=created", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// handleConfigDetail shows a customer config with credentials and setup commands.
|
||||
func (s *Server) handleConfigDetail(w http.ResponseWriter, r *http.Request, customerID string) {
|
||||
cfg, err := s.store.GetCustomerConfig(customerID)
|
||||
if err != nil {
|
||||
s.logger.Printf("[ERROR] Failed to get config %s: %v", customerID, err)
|
||||
http.Error(w, "Internal error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if cfg == nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
// Parse config_json for display
|
||||
var overrides map[string]interface{}
|
||||
json.Unmarshal([]byte(cfg.ConfigJSON), &overrides)
|
||||
|
||||
data := struct {
|
||||
Config *store.CustomerConfig
|
||||
Overrides map[string]interface{}
|
||||
ActiveNav string
|
||||
Flash string
|
||||
}{
|
||||
Config: cfg,
|
||||
Overrides: overrides,
|
||||
ActiveNav: "configs",
|
||||
Flash: r.URL.Query().Get("flash"),
|
||||
}
|
||||
s.templates.ExecuteTemplate(w, "config_detail.html", data)
|
||||
http.Redirect(w, r, "/customers/"+customerID+"?flash=created", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// handleConfigEditForm shows the edit form for a customer config.
|
||||
@@ -272,7 +405,7 @@ func (s *Server) handleConfigUpdate(w http.ResponseWriter, r *http.Request, cust
|
||||
}
|
||||
|
||||
s.logger.Printf("[INFO] Customer config updated: %s", customerID)
|
||||
http.Redirect(w, r, "/configs/"+customerID+"?flash=updated", http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/customers/"+customerID+"?flash=updated", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// handleConfigDelete deletes a customer config.
|
||||
@@ -326,7 +459,152 @@ func (s *Server) handleConfigRegenPassword(w http.ResponseWriter, r *http.Reques
|
||||
}
|
||||
|
||||
s.logger.Printf("[INFO] Retrieval password regenerated for %s", customerID)
|
||||
http.Redirect(w, r, "/configs/"+customerID+"?flash=password_regenerated", http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/customers/"+customerID+"?flash=password_regenerated", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// handleBlockCustomer sets a customer's status to "blocked".
|
||||
func (s *Server) handleBlockCustomer(w http.ResponseWriter, r *http.Request, customerID string) {
|
||||
cfg, _ := s.store.GetCustomerConfig(customerID)
|
||||
if cfg == nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if err := s.store.SetCustomerConfigStatus(customerID, "blocked"); err != nil {
|
||||
s.logger.Printf("[ERROR] Failed to block %s: %v", customerID, err)
|
||||
http.Error(w, "Internal error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
s.logger.Printf("[INFO] Customer blocked: %s", customerID)
|
||||
http.Redirect(w, r, "/customers/"+customerID+"?flash=blocked", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// handleUnblockCustomer sets a customer's status back to "active".
|
||||
func (s *Server) handleUnblockCustomer(w http.ResponseWriter, r *http.Request, customerID string) {
|
||||
cfg, _ := s.store.GetCustomerConfig(customerID)
|
||||
if cfg == nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if err := s.store.SetCustomerConfigStatus(customerID, "active"); err != nil {
|
||||
s.logger.Printf("[ERROR] Failed to unblock %s: %v", customerID, err)
|
||||
http.Error(w, "Internal error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
s.logger.Printf("[INFO] Customer unblocked: %s", customerID)
|
||||
http.Redirect(w, r, "/customers/"+customerID+"?flash=unblocked", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// handlePushConfig sends the generated YAML config to the controller.
|
||||
func (s *Server) handlePushConfig(w http.ResponseWriter, r *http.Request, customerID string) {
|
||||
cfg, err := s.store.GetCustomerConfig(customerID)
|
||||
if err != nil || cfg == nil {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.Write([]byte(`{"ok":false,"error":"No config found for this customer"}`))
|
||||
return
|
||||
}
|
||||
|
||||
// Get controller URL from latest report
|
||||
customer, _ := s.store.GetCustomer(customerID)
|
||||
controllerURL := ""
|
||||
if customer != nil {
|
||||
controllerURL = customer.ControllerURL
|
||||
if controllerURL == "" {
|
||||
var rpt struct {
|
||||
ControllerURL string `json:"controller_url"`
|
||||
}
|
||||
json.Unmarshal([]byte(customer.ReportJSON), &rpt)
|
||||
controllerURL = rpt.ControllerURL
|
||||
}
|
||||
}
|
||||
if controllerURL == "" {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(`{"ok":false,"error":"Controller URL not available — waiting for first report"}`))
|
||||
return
|
||||
}
|
||||
|
||||
// Generate YAML
|
||||
templateYAML := defaultControllerTemplate
|
||||
if s.templateFetcher != nil {
|
||||
templateYAML = s.templateFetcher.Template()
|
||||
}
|
||||
yamlOutput, err := configgen.Generate(templateYAML, cfg)
|
||||
if err != nil {
|
||||
s.logger.Printf("[ERROR] Failed to generate config for push to %s: %v", customerID, err)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(`{"ok":false,"error":"Failed to generate config"}`))
|
||||
return
|
||||
}
|
||||
|
||||
// POST to controller
|
||||
pushURL := controllerURL + "/api/config/apply"
|
||||
req, err := http.NewRequest("POST", pushURL, strings.NewReader(yamlOutput))
|
||||
if err != nil {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(`{"ok":false,"error":"Failed to create request"}`))
|
||||
return
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+s.apiKey)
|
||||
req.Header.Set("Content-Type", "text/yaml")
|
||||
|
||||
client := &http.Client{Timeout: 30 * time.Second}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
s.logger.Printf("[ERROR] Push config to %s failed: %v", pushURL, err)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusBadGateway)
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{"ok": false, "error": fmt.Sprintf("Controller unreachable: %v", err)})
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<16))
|
||||
s.logger.Printf("[INFO] Push config to %s — controller responded %d: %s", customerID, resp.StatusCode, string(body))
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(resp.StatusCode)
|
||||
w.Write(body)
|
||||
}
|
||||
|
||||
// handleCreateConfigFromReport auto-creates a config entry from report data.
|
||||
func (s *Server) handleCreateConfigFromReport(w http.ResponseWriter, r *http.Request, customerID string) {
|
||||
// Check if config already exists
|
||||
existing, _ := s.store.GetCustomerConfig(customerID)
|
||||
if existing != nil {
|
||||
http.Redirect(w, r, "/configs/"+customerID+"/edit", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
// Get report data to pre-fill
|
||||
customer, _ := s.store.GetCustomer(customerID)
|
||||
name := customerID
|
||||
if customer != nil && customer.CustomerName != "" {
|
||||
name = customer.CustomerName
|
||||
}
|
||||
|
||||
// Generate credentials
|
||||
retrievalPassword, _ := configgen.RandomHex(32)
|
||||
apiKey, _ := configgen.RandomHex(32)
|
||||
|
||||
cfg := &store.CustomerConfig{
|
||||
CustomerID: customerID,
|
||||
CustomerName: name,
|
||||
RetrievalPassword: retrievalPassword,
|
||||
APIKey: apiKey,
|
||||
ConfigJSON: "{}",
|
||||
}
|
||||
|
||||
if err := s.store.SaveCustomerConfig(cfg); err != nil {
|
||||
s.logger.Printf("[ERROR] Failed to create config from report for %s: %v", customerID, err)
|
||||
http.Error(w, "Internal error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
s.logger.Printf("[INFO] Config auto-created from report for %s", customerID)
|
||||
http.Redirect(w, r, "/configs/"+customerID+"/edit", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// renderConfigForm is a helper to re-render the form with an error.
|
||||
@@ -395,19 +673,3 @@ func buildConfigJSON(r *http.Request) string {
|
||||
data, _ := json.Marshal(overrides)
|
||||
return string(data)
|
||||
}
|
||||
|
||||
// getNestedString is a helper to extract a nested string from a map.
|
||||
func getNestedString(m map[string]interface{}, keys ...string) string {
|
||||
var current interface{} = m
|
||||
for _, key := range keys {
|
||||
if cm, ok := current.(map[string]interface{}); ok {
|
||||
current = cm[key]
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
if s, ok := current.(string); ok {
|
||||
return s
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
+60
-97
@@ -83,9 +83,41 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
case strings.HasPrefix(path, "/customers/") && strings.HasSuffix(path, "/block"):
|
||||
customerID := strings.TrimPrefix(path, "/customers/")
|
||||
customerID = strings.TrimSuffix(customerID, "/block")
|
||||
if r.Method == http.MethodPost {
|
||||
s.handleBlockCustomer(w, r, customerID)
|
||||
} else {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
case strings.HasPrefix(path, "/customers/") && strings.HasSuffix(path, "/unblock"):
|
||||
customerID := strings.TrimPrefix(path, "/customers/")
|
||||
customerID = strings.TrimSuffix(customerID, "/unblock")
|
||||
if r.Method == http.MethodPost {
|
||||
s.handleUnblockCustomer(w, r, customerID)
|
||||
} else {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
case strings.HasPrefix(path, "/customers/") && strings.HasSuffix(path, "/push-config"):
|
||||
customerID := strings.TrimPrefix(path, "/customers/")
|
||||
customerID = strings.TrimSuffix(customerID, "/push-config")
|
||||
if r.Method == http.MethodPost {
|
||||
s.handlePushConfig(w, r, customerID)
|
||||
} else {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
case strings.HasPrefix(path, "/customers/") && strings.HasSuffix(path, "/create-config"):
|
||||
customerID := strings.TrimPrefix(path, "/customers/")
|
||||
customerID = strings.TrimSuffix(customerID, "/create-config")
|
||||
if r.Method == http.MethodPost {
|
||||
s.handleCreateConfigFromReport(w, r, customerID)
|
||||
} else {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
case strings.HasPrefix(path, "/customers/"):
|
||||
customerID := strings.TrimPrefix(path, "/customers/")
|
||||
s.handleCustomerDetail(w, r, customerID)
|
||||
s.handleCustomerUnified(w, r, customerID)
|
||||
// Config management routes — exact matches first, then prefix matches
|
||||
case path == "/configs":
|
||||
s.handleConfigList(w, r)
|
||||
@@ -124,8 +156,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
case strings.HasPrefix(path, "/configs/"):
|
||||
// Redirect old config detail URL to unified customer page
|
||||
customerID := strings.TrimPrefix(path, "/configs/")
|
||||
s.handleConfigDetail(w, r, customerID)
|
||||
http.Redirect(w, r, "/customers/"+customerID, http.StatusSeeOther)
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
@@ -193,14 +226,24 @@ func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
configs, _ := s.store.ListCustomerConfigs()
|
||||
|
||||
type dashboardCustomer struct {
|
||||
store.CustomerSummary
|
||||
OverallStatus string // "ok", "warn", "down"
|
||||
OverallStatus string // "ok", "warn", "down", "pending"
|
||||
BackupAge string
|
||||
}
|
||||
|
||||
// Build map of report customers keyed by ID
|
||||
seen := make(map[string]bool)
|
||||
var data []dashboardCustomer
|
||||
for _, c := range customers {
|
||||
// Skip blocked customers
|
||||
if s.store.IsCustomerBlocked(c.CustomerID) {
|
||||
continue
|
||||
}
|
||||
|
||||
seen[c.CustomerID] = true
|
||||
dc := dashboardCustomer{CustomerSummary: c}
|
||||
|
||||
// Determine overall status
|
||||
@@ -226,104 +269,24 @@ func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) {
|
||||
data = append(data, dc)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
if err := s.templates.ExecuteTemplate(w, "dashboard.html", data); err != nil {
|
||||
s.logger.Printf("[ERROR] Template render: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) handleCustomerDetail(w http.ResponseWriter, r *http.Request, customerID string) {
|
||||
customer, err := s.store.GetCustomer(customerID)
|
||||
if err != nil {
|
||||
s.logger.Printf("[ERROR] Customer detail: %v", err)
|
||||
http.Error(w, "Internal error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if customer == nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
// Parse the full report
|
||||
var report map[string]interface{}
|
||||
json.Unmarshal([]byte(customer.ReportJSON), &report)
|
||||
|
||||
// Get history (last 24h)
|
||||
history, _ := s.store.GetCustomerHistory(customerID, 24*time.Hour)
|
||||
|
||||
// Get notification preferences and recent log
|
||||
notifPrefs, _ := s.store.GetNotificationPrefs(customerID)
|
||||
recentNotifs, _ := s.store.GetRecentNotifications(customerID, 10)
|
||||
|
||||
// Get infra backup metadata
|
||||
infraMeta, _ := s.store.GetInfraBackupMeta(customerID)
|
||||
|
||||
type detailData struct {
|
||||
Customer *store.CustomerSummary
|
||||
Report map[string]interface{}
|
||||
History []store.CustomerSummary
|
||||
OverallStatus string
|
||||
NotifPrefs *store.NotificationPrefs
|
||||
RecentNotifications []store.NotificationLogEntry
|
||||
InfraBackup *store.InfraBackupMeta
|
||||
InfraBackupAge string
|
||||
ControllerURL string // controller's external URL
|
||||
LatestVersion string // latest controller image version from registry
|
||||
UpdateAvailable bool // true if latest > current
|
||||
}
|
||||
|
||||
// Get controller URL (from denormalized field or report JSON fallback)
|
||||
controllerURL := customer.ControllerURL
|
||||
if controllerURL == "" {
|
||||
var rpt struct {
|
||||
ControllerURL string `json:"controller_url"`
|
||||
// Add config-only customers (no reports yet) as "pending"
|
||||
for _, cfg := range configs {
|
||||
if seen[cfg.CustomerID] || cfg.Status == "blocked" {
|
||||
continue
|
||||
}
|
||||
json.Unmarshal([]byte(customer.ReportJSON), &rpt)
|
||||
controllerURL = rpt.ControllerURL
|
||||
}
|
||||
|
||||
// Check if update is available
|
||||
var latestVersion string
|
||||
var updateAvailable bool
|
||||
if s.versionChecker != nil {
|
||||
latestVersion = s.versionChecker.LatestVersion()
|
||||
if latestVersion != "" && customer.ControllerVersion != "" {
|
||||
updateAvailable = latestVersion != customer.ControllerVersion && compareVersions(latestVersion, customer.ControllerVersion) > 0
|
||||
dc := dashboardCustomer{
|
||||
CustomerSummary: store.CustomerSummary{
|
||||
CustomerID: cfg.CustomerID,
|
||||
CustomerName: cfg.CustomerName,
|
||||
},
|
||||
OverallStatus: "pending",
|
||||
BackupAge: "–",
|
||||
}
|
||||
}
|
||||
|
||||
overallStatus := "ok"
|
||||
if customer.HealthStatus == "disabled" {
|
||||
overallStatus = "disabled"
|
||||
} else if customer.TimeSinceReport > time.Hour {
|
||||
overallStatus = "down"
|
||||
} else if customer.TimeSinceReport > 30*time.Minute || customer.HealthStatus == "warn" {
|
||||
overallStatus = "warn"
|
||||
} else if customer.HealthStatus == "fail" {
|
||||
overallStatus = "down"
|
||||
}
|
||||
|
||||
var infraBackupAge string
|
||||
if infraMeta != nil {
|
||||
infraBackupAge = timeAgo(infraMeta.UpdatedAt)
|
||||
}
|
||||
|
||||
data := detailData{
|
||||
Customer: customer,
|
||||
Report: report,
|
||||
History: history,
|
||||
OverallStatus: overallStatus,
|
||||
NotifPrefs: notifPrefs,
|
||||
RecentNotifications: recentNotifs,
|
||||
InfraBackup: infraMeta,
|
||||
InfraBackupAge: infraBackupAge,
|
||||
ControllerURL: controllerURL,
|
||||
LatestVersion: latestVersion,
|
||||
UpdateAvailable: updateAvailable,
|
||||
data = append(data, dc)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
if err := s.templates.ExecuteTemplate(w, "customer.html", data); err != nil {
|
||||
if err := s.templates.ExecuteTemplate(w, "dashboard.html", data); err != nil {
|
||||
s.logger.Printf("[ERROR] Template render: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -455,7 +418,7 @@ func statusColor(status string) string {
|
||||
return "#facc15" // yellow
|
||||
case "down", "fail":
|
||||
return "#f87171" // red
|
||||
case "disabled":
|
||||
case "disabled", "pending", "blocked":
|
||||
return "#94a3b8" // gray
|
||||
default:
|
||||
return "#94a3b8" // gray
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<a href="{{if .IsNew}}/configs{{else}}/configs/{{.Config.CustomerID}}{{end}}" class="back-link">← Back</a>
|
||||
<a href="{{if .IsNew}}/configs{{else}}/customers/{{.Config.CustomerID}}{{end}}" class="back-link">← Back</a>
|
||||
<h2>{{if .IsNew}}Add Customer{{else}}Edit: {{.Config.CustomerID}}{{end}}</h2>
|
||||
|
||||
{{if .Error}}
|
||||
@@ -136,7 +136,7 @@
|
||||
|
||||
<div style="margin-top: 1.5rem; display: flex; gap: 1rem;">
|
||||
<button type="submit" class="btn">{{if .IsNew}}Create Configuration{{else}}Save Changes{{end}}</button>
|
||||
<a href="{{if .IsNew}}/configs{{else}}/configs/{{.Config.CustomerID}}{{end}}" class="btn btn-outline">Cancel</a>
|
||||
<a href="{{if .IsNew}}/configs{{else}}/customers/{{.Config.CustomerID}}{{end}}" class="btn btn-outline">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
@@ -46,13 +46,17 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range .Customers}}
|
||||
<tr onclick="window.location='{{if .HasConfig}}/configs/{{.CustomerID}}{{else}}/customers/{{.CustomerID}}{{end}}'">
|
||||
<tr class="{{if .IsBlocked}}row-blocked{{end}}" onclick="window.location='/customers/{{.CustomerID}}'">
|
||||
<td><code>{{.CustomerID}}</code></td>
|
||||
<td>{{if .CustomerName}}{{.CustomerName}}{{else}}<span class="text-muted">—</span>{{end}}</td>
|
||||
<td>{{if .Domain}}{{.Domain}}{{else}}<span class="text-muted">—</span>{{end}}</td>
|
||||
<td>
|
||||
{{if .OverallStatus}}
|
||||
<span class="status-badge status-badge-{{.OverallStatus}}">{{.OverallStatus}}</span>
|
||||
{{if .IsBlocked}}
|
||||
<span class="config-badge config-badge-blocked">BLOCKED</span>
|
||||
{{else if .OverallStatus}}
|
||||
<span class="status-badge status-badge-{{.OverallStatus}}">
|
||||
{{if eq .OverallStatus "ok"}}OK{{else if eq .OverallStatus "warn"}}WARN{{else if eq .OverallStatus "down"}}DOWN{{else if eq .OverallStatus "disabled"}}PAUSED{{else if eq .OverallStatus "pending"}}PENDING{{else}}{{.OverallStatus}}{{end}}
|
||||
</span>
|
||||
{{else}}
|
||||
<span class="text-muted">—</span>
|
||||
{{end}}
|
||||
@@ -60,9 +64,9 @@
|
||||
<td>{{if .ControllerVersion}}<code>{{.ControllerVersion}}</code>{{else}}<span class="text-muted">—</span>{{end}}</td>
|
||||
<td>
|
||||
{{if .HasConfig}}
|
||||
<span class="status-badge status-badge-ok">managed</span>
|
||||
<span class="config-badge config-badge-managed">MANAGED</span>
|
||||
{{else}}
|
||||
<span class="status-badge status-badge-disabled">manual</span>
|
||||
<span class="config-badge config-badge-manual">MANUAL</span>
|
||||
{{end}}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -0,0 +1,558 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{if .CustomerName}}{{.CustomerName}}{{else}}{{.CustomerID}}{{end}} — Felhom Hub</title>
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
{{if .HasReports}}<meta http-equiv="refresh" content="60">{{end}}
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header>
|
||||
<nav class="nav-links" style="margin-bottom: 0.5rem;">
|
||||
<a href="/" class="nav-link">Dashboard</a>
|
||||
<a href="/configs" class="nav-link active">Customers</a>
|
||||
</nav>
|
||||
<a href="/configs" class="back-link">← All Customers</a>
|
||||
<h1>
|
||||
<span class="status-dot" style="color: {{statusColor .OverallStatus}}">{{statusIcon .OverallStatus}}</span>
|
||||
{{if .CustomerName}}{{.CustomerName}}{{else}}{{.CustomerID}}{{end}}
|
||||
</h1>
|
||||
{{if .HasReports}}
|
||||
<p class="subtitle">Last report: {{timeAgo .Customer.ReceivedAt}} · Controller v{{.Customer.ControllerVersion}}</p>
|
||||
{{else}}
|
||||
<p class="subtitle">No reports received yet</p>
|
||||
{{end}}
|
||||
</header>
|
||||
|
||||
{{if .Flash}}
|
||||
<div class="flash flash-success">
|
||||
{{if eq .Flash "created"}}Configuration created successfully.
|
||||
{{else if eq .Flash "updated"}}Configuration updated.
|
||||
{{else if eq .Flash "password_regenerated"}}Retrieval password regenerated.
|
||||
{{else if eq .Flash "blocked"}}Customer blocked — hidden from Dashboard.
|
||||
{{else if eq .Flash "unblocked"}}Customer unblocked — visible on Dashboard again.
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if .IsBlocked}}
|
||||
<div class="flash flash-blocked">
|
||||
This customer is blocked — reports are accepted but not shown on the Dashboard.
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
<!-- Customer Info -->
|
||||
<section class="card">
|
||||
<div style="display: flex; justify-content: space-between; align-items: flex-start;">
|
||||
<h2>Customer Info</h2>
|
||||
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
|
||||
{{if .HasConfig}}
|
||||
<a href="/configs/{{.CustomerID}}/edit" class="btn btn-outline btn-sm">Edit</a>
|
||||
{{if .IsBlocked}}
|
||||
<form method="POST" action="/customers/{{.CustomerID}}/unblock" style="display:inline">
|
||||
<button type="submit" class="btn btn-sm">Unblock</button>
|
||||
</form>
|
||||
{{else}}
|
||||
<form method="POST" action="/customers/{{.CustomerID}}/block" style="display:inline"
|
||||
onsubmit="return confirm('Block this customer? They will be hidden from the Dashboard.')">
|
||||
<button type="submit" class="btn btn-outline btn-sm">Block</button>
|
||||
</form>
|
||||
{{end}}
|
||||
<form method="POST" action="/configs/{{.CustomerID}}/delete" style="display:inline"
|
||||
onsubmit="return confirm('Delete configuration for {{.CustomerID}}? This cannot be undone.')">
|
||||
<button type="submit" class="btn btn-danger btn-sm">Delete</button>
|
||||
</form>
|
||||
{{else}}
|
||||
<form method="POST" action="/customers/{{.CustomerID}}/create-config" style="display:inline">
|
||||
<button type="submit" class="btn btn-sm">Create Config</button>
|
||||
</form>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="info-grid">
|
||||
<div class="info-item">
|
||||
<span class="label">Customer ID</span>
|
||||
<span class="value"><code>{{.CustomerID}}</code></span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">Name</span>
|
||||
<span class="value">{{if .CustomerName}}{{.CustomerName}}{{else}}—{{end}}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">Domain</span>
|
||||
<span class="value">{{if .Domain}}{{.Domain}}{{else}}—{{end}}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">Email</span>
|
||||
<span class="value">{{if .Email}}{{.Email}}{{else}}—{{end}}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">Config</span>
|
||||
<span class="value">
|
||||
{{if .HasConfig}}
|
||||
<span class="config-badge config-badge-managed">MANAGED</span>
|
||||
{{else}}
|
||||
<span class="config-badge config-badge-manual">MANUAL</span>
|
||||
{{end}}
|
||||
{{if .IsBlocked}}<span class="config-badge config-badge-blocked">BLOCKED</span>{{end}}
|
||||
</span>
|
||||
</div>
|
||||
{{if .HasConfig}}
|
||||
<div class="info-item">
|
||||
<span class="label">Config Created</span>
|
||||
<span class="value">{{timeAgo .Config.CreatedAt}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{{if .HasReports}}
|
||||
<!-- System Info -->
|
||||
<section class="card">
|
||||
<h2>System</h2>
|
||||
<div class="info-grid">
|
||||
{{with .Report.system}}
|
||||
<div class="info-item">
|
||||
<span class="label">Hostname</span>
|
||||
<span class="value">{{index . "hostname"}}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">OS</span>
|
||||
<span class="value">{{index . "os"}}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">Kernel</span>
|
||||
<span class="value">{{index . "kernel"}}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">CPU</span>
|
||||
<span class="value">{{index . "cpu_model"}} ({{index . "cpu_cores"}} cores)</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="metrics-grid">
|
||||
<div class="metric">
|
||||
<span class="metric-label">CPU</span>
|
||||
<span class="metric-value">{{formatFloat .Customer.CPUPercent}}%</span>
|
||||
<div class="bar"><div class="bar-fill" style="width: {{formatFloat .Customer.CPUPercent}}%"></div></div>
|
||||
</div>
|
||||
<div class="metric">
|
||||
<span class="metric-label">Memory</span>
|
||||
<span class="metric-value">{{formatFloat .Customer.MemoryPercent}}%</span>
|
||||
<div class="bar"><div class="bar-fill" style="width: {{formatFloat .Customer.MemoryPercent}}%"></div></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Storage -->
|
||||
<section class="card">
|
||||
<h2>Storage</h2>
|
||||
{{with .Report.storage}}
|
||||
<div class="metrics-grid">
|
||||
{{range .}}
|
||||
<div class="metric">
|
||||
<span class="metric-label">{{with index . "label"}}{{.}}{{else}}{{index . "mount"}}{{end}}</span>
|
||||
<span class="metric-value">{{printf "%.0f" (index . "percent")}}%</span>
|
||||
<div class="bar"><div class="bar-fill" style="width: {{printf "%.0f" (index . "percent")}}%"></div></div>
|
||||
<span class="metric-detail">{{printf "%.1f" (index . "used_gb")}} / {{printf "%.1f" (index . "total_gb")}} GB</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
<!-- Containers -->
|
||||
<section class="card">
|
||||
<h2>Containers ({{.Customer.ContainerRunning}}/{{.Customer.ContainerTotal}})</h2>
|
||||
{{with .Report.containers}}
|
||||
{{$list := index . "list"}}
|
||||
{{if $list}}
|
||||
<table class="container-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>State</th>
|
||||
<th>CPU</th>
|
||||
<th>Memory</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range $list}}
|
||||
<tr>
|
||||
<td>{{index . "name"}}</td>
|
||||
<td><span class="container-state container-state-{{index . "state"}}">{{index . "state"}}</span></td>
|
||||
<td>{{printf "%.1f" (index . "cpu_percent")}}%</td>
|
||||
<td>{{printf "%.0f" (index . "memory_mb")}} MB</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
<!-- Backup -->
|
||||
<section class="card">
|
||||
<h2>Backup</h2>
|
||||
{{with .Report.backup}}
|
||||
<div class="info-grid">
|
||||
<div class="info-item">
|
||||
<span class="label">Enabled</span>
|
||||
<span class="value">{{if index . "enabled"}}Yes{{else}}No{{end}}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">Snapshots</span>
|
||||
<span class="value">{{index . "snapshot_count"}}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">Repo Size</span>
|
||||
<span class="value">{{index . "repo_size_mb"}} MB</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">Integrity</span>
|
||||
<span class="value">{{if index . "integrity_ok"}}OK{{else}}Unknown{{end}}</span>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
<!-- Infra Backup -->
|
||||
<section class="card">
|
||||
<h2>Infra Backup</h2>
|
||||
{{if .InfraBackup}}
|
||||
<div class="info-grid">
|
||||
<div class="info-item">
|
||||
<span class="label">Last Updated</span>
|
||||
<span class="value">{{.InfraBackupAge}}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">Deployed Stacks</span>
|
||||
<span class="value">{{.InfraBackup.StackCount}}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">Disks</span>
|
||||
<span class="value">{{.InfraBackup.DiskCount}}</span>
|
||||
</div>
|
||||
</div>
|
||||
{{else}}
|
||||
<p style="color: #facc15">No infra backup received yet</p>
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
<!-- Health -->
|
||||
<section class="card">
|
||||
<h2>Health</h2>
|
||||
{{if eq .OverallStatus "disabled"}}
|
||||
<p class="health-status health-status-disabled">Reporting has been disabled on this node</p>
|
||||
<p class="hint">Enable it in the controller's <code>controller.yaml</code>: <code>hub.enabled: true</code></p>
|
||||
{{else if eq .OverallStatus "blocked"}}
|
||||
<p class="health-status health-status-disabled">Customer is blocked</p>
|
||||
{{else}}
|
||||
{{with .Report.health}}
|
||||
<p class="health-status health-status-{{index . "status"}}">
|
||||
Status: {{index . "status"}}
|
||||
</p>
|
||||
{{$issues := index . "issues"}}
|
||||
{{if $issues}}
|
||||
<h3>Issues</h3>
|
||||
<ul class="issue-list">
|
||||
{{range $issues}}
|
||||
<li class="issue">{{.}}</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{end}}
|
||||
{{$warnings := index . "warnings"}}
|
||||
{{if $warnings}}
|
||||
<h3>Warnings</h3>
|
||||
<ul class="warning-list">
|
||||
{{range $warnings}}
|
||||
<li class="warning">{{.}}</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
{{else}}
|
||||
<!-- No reports yet -->
|
||||
{{if .HasConfig}}
|
||||
<section class="card">
|
||||
<h2>Waiting for First Report</h2>
|
||||
<p class="text-muted">This customer has been configured but no controller report has been received yet.</p>
|
||||
<p class="text-muted" style="margin-top: 0.5rem;">Use one of the setup commands below to deploy the controller on the customer node.</p>
|
||||
</section>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
<!-- Config Management -->
|
||||
{{if .HasConfig}}
|
||||
<section class="card">
|
||||
<h2>Credentials</h2>
|
||||
<div class="credential-row">
|
||||
<div>
|
||||
<span class="label">Retrieval Password</span>
|
||||
<div class="credential-box">
|
||||
<code id="retrieval-pw">{{.Config.RetrievalPassword}}</code>
|
||||
<button type="button" class="copy-btn" onclick="copyText('retrieval-pw')" title="Copy">⎘</button>
|
||||
</div>
|
||||
</div>
|
||||
<form method="POST" action="/configs/{{.CustomerID}}/regen-password" style="margin-top: 0.5rem;"
|
||||
onsubmit="return confirm('Regenerate retrieval password? The old password will stop working immediately.')">
|
||||
<button type="submit" class="btn btn-outline btn-sm">Regenerate</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="credential-row" style="margin-top: 1rem;">
|
||||
<div>
|
||||
<span class="label">API Key</span>
|
||||
<div class="credential-box">
|
||||
<code id="api-key">{{.Config.APIKey}}</code>
|
||||
<button type="button" class="copy-btn" onclick="copyText('api-key')" title="Copy">⎘</button>
|
||||
</div>
|
||||
</div>
|
||||
<span class="form-hint">Used by the controller for ongoing hub communication (reports, notifications, backups)</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>Setup Commands</h2>
|
||||
<p class="text-muted" style="margin-bottom: 1rem; font-size: 0.85rem;">Use one of these methods to configure a customer node:</p>
|
||||
|
||||
<h3>Option 1: docker-setup.sh (recommended)</h3>
|
||||
<div class="credential-box">
|
||||
<code id="cmd-setup">sudo ./docker-setup.sh --hub-customer {{.CustomerID}} --hub-password {{.Config.RetrievalPassword}}</code>
|
||||
<button type="button" class="copy-btn" onclick="copyText('cmd-setup')" title="Copy">⎘</button>
|
||||
</div>
|
||||
|
||||
<h3 style="margin-top: 1rem;">Option 2: Direct download</h3>
|
||||
<div class="credential-box">
|
||||
<code id="cmd-curl">curl -fsSL https://hub.felhom.eu/api/v1/config/{{.CustomerID}} -H "X-Retrieval-Password: {{.Config.RetrievalPassword}}" -o controller.yaml</code>
|
||||
<button type="button" class="copy-btn" onclick="copyText('cmd-curl')" title="Copy">⎘</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>YAML Preview</h2>
|
||||
<div id="yaml-preview" class="yaml-preview">
|
||||
<p class="text-muted">Loading preview...</p>
|
||||
</div>
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
{{if .HasReports}}
|
||||
<!-- Controller Update -->
|
||||
<section class="card">
|
||||
<h2>Controller Update</h2>
|
||||
<div class="info-grid">
|
||||
<div class="info-item">
|
||||
<span class="label">Current version</span>
|
||||
<span class="value">v{{.Customer.ControllerVersion}}</span>
|
||||
</div>
|
||||
{{if .LatestVersion}}
|
||||
<div class="info-item">
|
||||
<span class="label">Latest version</span>
|
||||
<span class="value">
|
||||
v{{.LatestVersion}}
|
||||
{{if .UpdateAvailable}}
|
||||
<span style="color: #4ade80; margin-left: 0.3em;">● update available</span>
|
||||
{{else}}
|
||||
<span style="color: #94a3b8; margin-left: 0.3em;">— up to date</span>
|
||||
{{end}}
|
||||
</span>
|
||||
</div>
|
||||
{{end}}
|
||||
{{if .ControllerURL}}
|
||||
<div class="info-item">
|
||||
<span class="label">Controller URL</span>
|
||||
<span class="value"><a href="{{.ControllerURL}}" target="_blank" style="color: #60a5fa;">{{.ControllerURL}}</a></span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
<div style="margin-top: 0.75em; display: flex; gap: 0.5rem; flex-wrap: wrap;">
|
||||
{{if and .ControllerURL .UpdateAvailable}}
|
||||
<button class="btn btn-sm" id="btn-trigger-update" onclick="triggerControllerUpdate('{{.CustomerID}}')">
|
||||
Trigger Update
|
||||
</button>
|
||||
{{else if and .ControllerURL (not .LatestVersion)}}
|
||||
<button class="btn btn-sm" id="btn-trigger-update" onclick="triggerControllerUpdate('{{.CustomerID}}')">
|
||||
Trigger Update
|
||||
</button>
|
||||
{{end}}
|
||||
{{if and .HasConfig .ControllerURL}}
|
||||
<button class="btn btn-outline btn-sm" id="btn-push-config" onclick="pushConfig('{{.CustomerID}}')">
|
||||
Push Config
|
||||
</button>
|
||||
{{end}}
|
||||
<span id="action-msg" style="margin-left: 0.5em; display: none;"></span>
|
||||
</div>
|
||||
{{if and .ControllerURL (not .LatestVersion)}}
|
||||
<p style="color: #94a3b8; font-size: 0.85em; margin-top: 0.3em;">Registry check not configured — cannot verify if update is available</p>
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
<!-- Notifications -->
|
||||
<section class="card">
|
||||
<h2>Notifications</h2>
|
||||
<div class="info-grid">
|
||||
<div class="info-item">
|
||||
<span class="label">Email</span>
|
||||
<span class="value">{{if .NotifPrefs}}{{if .NotifPrefs.Email}}{{.NotifPrefs.Email}}{{else}}Not set{{end}}{{else}}Not configured{{end}}</span>
|
||||
</div>
|
||||
{{if .NotifPrefs}}
|
||||
<div class="info-item">
|
||||
<span class="label">Events</span>
|
||||
<span class="value">{{if .NotifPrefs.EnabledEvents}}{{joinStrings .NotifPrefs.EnabledEvents ", "}}{{else}}None{{end}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{if .RecentNotifications}}
|
||||
<h3>Recent (last 10)</h3>
|
||||
<table class="history-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Time</th>
|
||||
<th>Event</th>
|
||||
<th>Status</th>
|
||||
<th>Message</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range .RecentNotifications}}
|
||||
<tr>
|
||||
<td>{{.CreatedAt.Format "Jan 02 15:04"}}</td>
|
||||
<td>{{.EventType}}</td>
|
||||
<td><span class="status-badge status-badge-{{.Status}}">{{.Status}}</span></td>
|
||||
<td>{{.Message}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
<!-- Report History -->
|
||||
{{if .History}}
|
||||
<section class="card">
|
||||
<h2>Report History (last 24h)</h2>
|
||||
<details>
|
||||
<summary>{{len .History}} reports</summary>
|
||||
<table class="history-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Time</th>
|
||||
<th>Status</th>
|
||||
<th>CPU</th>
|
||||
<th>Memory</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range .History}}
|
||||
<tr>
|
||||
<td>{{.ReceivedAt.Format "Jan 02 15:04"}}</td>
|
||||
<td><span class="status-badge status-badge-{{.HealthStatus}}">{{.HealthStatus}}</span></td>
|
||||
<td>{{formatFloat .CPUPercent}}%</td>
|
||||
<td>{{formatFloat .MemoryPercent}}%</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</details>
|
||||
</section>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
<footer>
|
||||
{{if .HasReports}}<p>Auto-refreshes every 60 seconds · {{end}}<a href="/">Felhom Hub</a>{{if .HasReports}}</p>{{end}}
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function copyText(elementId) {
|
||||
var el = document.getElementById(elementId);
|
||||
var text = el.textContent || el.innerText;
|
||||
navigator.clipboard.writeText(text.trim()).then(function() {
|
||||
var btn = el.parentElement.querySelector('.copy-btn');
|
||||
var orig = btn.innerHTML;
|
||||
btn.innerHTML = '✓';
|
||||
setTimeout(function() { btn.innerHTML = orig; }, 1500);
|
||||
});
|
||||
}
|
||||
|
||||
function triggerControllerUpdate(customerID) {
|
||||
if (!confirm('Trigger self-update on this controller?\n\nThe controller will be briefly unavailable during restart.')) return;
|
||||
var btn = document.getElementById('btn-trigger-update');
|
||||
var msg = document.getElementById('action-msg');
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Triggering...';
|
||||
msg.style.display = 'none';
|
||||
fetch('/customers/' + customerID + '/trigger-update', {method: 'POST'})
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(data) {
|
||||
if (data.ok) {
|
||||
msg.textContent = 'Update triggered — controller restarting';
|
||||
msg.style.display = 'inline';
|
||||
msg.style.color = '#4ade80';
|
||||
} else {
|
||||
msg.textContent = data.error || 'Failed';
|
||||
msg.style.display = 'inline';
|
||||
msg.style.color = '#f87171';
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Trigger Update';
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
msg.textContent = 'Connection error';
|
||||
msg.style.display = 'inline';
|
||||
msg.style.color = '#f87171';
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Trigger Update';
|
||||
});
|
||||
}
|
||||
|
||||
function pushConfig(customerID) {
|
||||
if (!confirm('Push the Hub configuration to this controller?\n\nThe controller will apply the new config.')) return;
|
||||
var btn = document.getElementById('btn-push-config');
|
||||
var msg = document.getElementById('action-msg');
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Pushing...';
|
||||
msg.style.display = 'none';
|
||||
fetch('/customers/' + customerID + '/push-config', {method: 'POST'})
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(data) {
|
||||
if (data.ok) {
|
||||
msg.textContent = 'Config pushed successfully';
|
||||
msg.style.display = 'inline';
|
||||
msg.style.color = '#4ade80';
|
||||
} else {
|
||||
msg.textContent = data.error || 'Failed';
|
||||
msg.style.display = 'inline';
|
||||
msg.style.color = '#f87171';
|
||||
}
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Push Config';
|
||||
})
|
||||
.catch(function() {
|
||||
msg.textContent = 'Connection error';
|
||||
msg.style.display = 'inline';
|
||||
msg.style.color = '#f87171';
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Push Config';
|
||||
});
|
||||
}
|
||||
|
||||
{{if .HasConfig}}
|
||||
// Load YAML preview
|
||||
fetch('/configs/{{.CustomerID}}/preview')
|
||||
.then(function(r) { return r.text(); })
|
||||
.then(function(yaml) {
|
||||
document.getElementById('yaml-preview').innerHTML = '<pre>' + yaml.replace(/&/g,'&').replace(/</g,'<') + '</pre>';
|
||||
})
|
||||
.catch(function() {
|
||||
document.getElementById('yaml-preview').innerHTML = '<p class="text-muted">Failed to load preview.</p>';
|
||||
});
|
||||
{{end}}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -46,16 +46,16 @@
|
||||
</td>
|
||||
<td>
|
||||
<span class="status-badge status-badge-{{.OverallStatus}}">
|
||||
{{if eq .OverallStatus "ok"}}OK{{else if eq .OverallStatus "warn"}}WARN{{else if eq .OverallStatus "disabled"}}PAUSED{{else}}DOWN{{end}}
|
||||
{{if eq .OverallStatus "ok"}}OK{{else if eq .OverallStatus "warn"}}WARN{{else if eq .OverallStatus "disabled"}}PAUSED{{else if eq .OverallStatus "pending"}}PENDING{{else}}DOWN{{end}}
|
||||
</span>
|
||||
</td>
|
||||
<td>{{timeAgo .ReceivedAt}}</td>
|
||||
<td>{{formatFloat .CPUPercent}}%</td>
|
||||
<td>{{formatFloat .MemoryPercent}}%</td>
|
||||
<td>{{.DiskSummary}}</td>
|
||||
<td>{{.ContainerRunning}}/{{.ContainerTotal}}</td>
|
||||
<td>{{if eq .OverallStatus "pending"}}—{{else}}{{timeAgo .ReceivedAt}}{{end}}</td>
|
||||
<td>{{if eq .OverallStatus "pending"}}—{{else}}{{formatFloat .CPUPercent}}%{{end}}</td>
|
||||
<td>{{if eq .OverallStatus "pending"}}—{{else}}{{formatFloat .MemoryPercent}}%{{end}}</td>
|
||||
<td>{{if eq .OverallStatus "pending"}}—{{else}}{{.DiskSummary}}{{end}}</td>
|
||||
<td>{{if eq .OverallStatus "pending"}}—{{else}}{{.ContainerRunning}}/{{.ContainerTotal}}{{end}}</td>
|
||||
<td>{{.BackupAge}}</td>
|
||||
<td><code>{{.ControllerVersion}}</code></td>
|
||||
<td>{{if .ControllerVersion}}<code>{{.ControllerVersion}}</code>{{else}}—{{end}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
|
||||
@@ -125,6 +125,35 @@ header h1 {
|
||||
.status-badge-warn { background: rgba(250, 204, 21, 0.15); color: var(--yellow); }
|
||||
.status-badge-down, .status-badge-fail { background: rgba(248, 113, 113, 0.15); color: var(--red); }
|
||||
.status-badge-disabled { background: #475569; color: #e2e8f0; }
|
||||
.status-badge-pending { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }
|
||||
.status-badge-blocked { background: rgba(248, 113, 113, 0.15); color: #f87171; }
|
||||
|
||||
/* Config badges */
|
||||
.config-badge {
|
||||
display: inline-block;
|
||||
padding: 0.15em 0.5em;
|
||||
border-radius: 4px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
.config-badge-managed { background: rgba(74, 222, 128, 0.15); color: #4ade80; }
|
||||
.config-badge-manual { background: #475569; color: #e2e8f0; }
|
||||
.config-badge-blocked { background: rgba(248, 113, 113, 0.2); color: #f87171; }
|
||||
|
||||
/* Blocked banner */
|
||||
.flash-blocked {
|
||||
background: rgba(248, 113, 113, 0.1);
|
||||
border: 1px solid rgba(248, 113, 113, 0.3);
|
||||
color: #fca5a5;
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
/* Blocked row in tables */
|
||||
.row-blocked { opacity: 0.5; }
|
||||
|
||||
/* Cards */
|
||||
.card {
|
||||
|
||||
Reference in New Issue
Block a user