feat: report preview page, sharp report logo, time to ban by blocker

The Reports page now previews the HTML report itself (same document as the
download and the print), with only Download and Print. The report logo is
the repository logo at 800 px. Survival splits fail2ban and the Urutau
second firewall.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-15 00:06:29 -03:00
1 parent 5d3374ee11
commit 9bdfdb491b
10 files changed
+245 -500

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
package server
import (
"path/filepath"
"testing"
"time"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/evlog"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
)
// Bans applied by the "urutau" jail (second firewall) are reported apart from
// the host fail2ban jails in /api/v1/survival.
func TestSurvivalByBlocker(t *testing.T) {
st := store.New(store.Config{Name: "oracle", Version: "t", Retention: 720 * time.Hour})
l, _ := evlog.Open(evlog.Options{Dir: filepath.Join(t.TempDir(), "events")})
st.SetEventLog(l)
now := time.Now()
attack := func(ip string, at time.Time) {
st.Ingest(core.Event{Time: at, IP: ip, Cat: core.Scanner, Source: "traefik", Domain: "a.example", Method: "GET", Path: "/.env", Status: 404})
}
attack("20.0.0.1", now.Add(-2*time.Hour))
st.Ingest(core.Event{Time: now.Add(-2*time.Hour + 10*time.Minute), IP: "20.0.0.1", Cat: core.Ban, Source: "fail2ban", Jail: "traefik-varredura"})
attack("20.0.0.2", now.Add(-time.Hour))
st.Ingest(core.Event{Time: now.Add(-time.Hour + time.Minute), IP: "20.0.0.2", Cat: core.Ban, Source: "fail2ban", Jail: "urutau"})
h := New(Options{Token: userTok, Version: "t", Store: st})
v := getJSON(t, h, "/api/v1/survival?range=24h", map[string]string{"Authorization": "Bearer " + userTok})
got := map[string]float64{}
for _, b := range v["by_blocker"].([]any) {
m := b.(map[string]any)
got[m["blocker"].(string)] = m["median_s"].(float64)
}
if got["fail2ban"] != 600 || got["urutau"] != 60 {
t.Fatalf("by_blocker = %v", v["by_blocker"])
}
}