### Security-Fixes (K1–K6, W1–W4, W7, N1, N5–N6, V1, V5–V7)
- K1: CSRF-Schutz via Double-Submit-Cookie (httpapi/csrf.go + csrf_helpers.go)
- K2: requireScreenAccess() in allen manage-Handlern (Tenant-Isolation)
- K3: Tenant-Check bei DELETE /api/v1/media/{id}
- K4: requirePlaylistAccess() + GetByItemID() für JSON-API Playlist-Routen
- K5: Admin-Passwort nur noch als [gesetzt] geloggt
- K6: POST /api/v1/screens/register mit Pre-Shared-Secret (MORZ_INFOBOARD_REGISTER_SECRET)
- W1: Race Condition bei order_index behoben (atomare Subquery in AddItem)
- W2: Graceful Shutdown mit 15s Timeout auf SIGTERM/SIGINT
- W3: http.MaxBytesReader (512 MB) in allen Upload-Handlern
- W4: err.Error() nicht mehr an den Client
- W7: Template-Execution via bytes.Buffer (kein partial write bei Fehler)
- N1: Rate-Limiting auf /login (5 Versuche/Minute pro IP, httpapi/ratelimit.go)
- N5: Directory-Listing auf /uploads/ deaktiviert (neuteredFileSystem)
- N6: Uploads nach Tenant getrennt (uploads/{tenantSlug}/)
- V1: Upload-Logik konsolidiert in internal/fileutil/fileutil.go
- V5: Cookie-Name als Konstante reqcontext.SessionCookieName
- V6: Strukturiertes Logging mit log/slog + JSON-Handler
- V7: DB-Pool wird im Graceful-Shutdown geschlossen
### Phase 6: Screenshot-Erzeugung
- player/agent/internal/screenshot/screenshot.go erstellt
- Integration in app.go mit MORZ_INFOBOARD_SCREENSHOT_EVERY Config
### UX: PDF.js Integration
- pdf.min.js + pdf.worker.min.js als lokale Assets eingebettet
- Automatisches Seitendurchblättern im Player
### Ansible: Neue Rollen
- signage_base, signage_server, signage_provision erstellt
- inventory.yml und site.yml erweitert
### Konzept-Docs
- GRUPPEN-KONZEPT.md, KAMPAGNEN-AKTIVIERUNG.md, MONITORING-KONZEPT.md
- PROVISION-KONZEPT.md, TEMPLATE-EDITOR.md, WATCHDOG-KONZEPT.md
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
72 lines
2.2 KiB
Go
72 lines
2.2 KiB
Go
package manage
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"git.az-it.net/az/morz-infoboard/server/backend/internal/config"
|
|
"git.az-it.net/az/morz-infoboard/server/backend/internal/store"
|
|
)
|
|
|
|
// HandleRegisterScreen is called by the player agent on startup.
|
|
// It upserts the screen in the default tenant so that all
|
|
// deployed screens appear automatically in the admin UI.
|
|
//
|
|
// POST /api/v1/screens/register
|
|
// Body: {"slug":"info10","name":"Info10 Bildschirm","orientation":"landscape"}
|
|
//
|
|
// K6: Wenn MORZ_INFOBOARD_REGISTER_SECRET gesetzt ist, muss der Aufrufer
|
|
// den Header X-Register-Secret: <secret> mitschicken. Ohne gültiges Secret
|
|
// antwortet der Endpoint mit 403 Forbidden.
|
|
func HandleRegisterScreen(tenants *store.TenantStore, screens *store.ScreenStore, cfg config.Config) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
// K6: Secret-Prüfung, wenn konfiguriert.
|
|
if cfg.RegisterSecret != "" {
|
|
if r.Header.Get("X-Register-Secret") != cfg.RegisterSecret {
|
|
http.Error(w, "Forbidden", http.StatusForbidden)
|
|
return
|
|
}
|
|
}
|
|
|
|
var body struct {
|
|
Slug string `json:"slug"`
|
|
Name string `json:"name"`
|
|
Orientation string `json:"orientation"`
|
|
}
|
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
|
http.Error(w, "invalid json", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
body.Slug = strings.TrimSpace(body.Slug)
|
|
body.Name = strings.TrimSpace(body.Name)
|
|
if body.Slug == "" {
|
|
http.Error(w, "slug required", http.StatusBadRequest)
|
|
return
|
|
}
|
|
if body.Name == "" {
|
|
body.Name = body.Slug
|
|
}
|
|
if body.Orientation == "" {
|
|
body.Orientation = "landscape"
|
|
}
|
|
|
|
// Register under the configured default tenant.
|
|
tenant, err := tenants.Get(r.Context(), cfg.DefaultTenantSlug)
|
|
if err != nil {
|
|
http.Error(w, "default tenant not found", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
screen, err := screens.Upsert(r.Context(), tenant.ID, body.Slug, body.Name, body.Orientation)
|
|
if err != nil {
|
|
http.Error(w, "db error", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusOK) // 200 whether created or updated
|
|
json.NewEncoder(w).Encode(screen) //nolint:errcheck
|
|
}
|
|
}
|