opnsense-portal/internal/web/handlers_static.go
2026-08-14 09:25:52 +02:00

35 lines
956 B
Go

package web
import (
"encoding/json"
"net/http"
)
// guidesData füllt guides.html.
type guidesData struct {
Guides []Guide
}
func (s *Server) handleGuides(w http.ResponseWriter, r *http.Request, sess *Session) {
s.renderPage(w, r, http.StatusOK, "guides", sess,
PageData{Data: guidesData{Guides: Guides(r.UserAgent())}})
}
// handleHealth beantwortet Monitoring-Anfragen ohne Authentifizierung und
// ohne sensible Details — nur boolesche Zustände und die Sessionzahl.
func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {
report := HealthReport{OK: true, OPNsense: true, Directory: true}
if s.d.Health != nil {
report = s.d.Health.Check(r.Context())
}
report.Sessions = s.d.Sessions.Count()
status := http.StatusOK
if !report.OK {
status = http.StatusServiceUnavailable
}
NoStore(w)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(status)
json.NewEncoder(w).Encode(report)
}