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

+44 -5
View File
@@ -103,6 +103,7 @@ type SurvivalOut struct {
P90ToBanS *int64 `json:"p90_to_ban_s"`
KM []KMPoint `json:"km"`
ByFamily []FamTTB `json:"by_family"`
ByBlocker []BlockerTTB `json:"by_blocker"`
Recidivists []Recidivist `json:"recidivists"`
RecidivismPct float64 `json:"recidivism_pct"`
}
@@ -149,6 +150,7 @@ func anPareto(sorted []AnItem, total uint64) []AnItem {
type anSubject struct {
T int64
Event bool
Ban int64 // time of the ban that ended the episode (Event only)
}
// anKaplanMeier returns the survival curve (starting at t=0, S=1) with one
@@ -436,9 +438,26 @@ func (s *Store) Survival(from, to int64, host string) SurvivalOut {
}
type anIPState struct {
mal []int64
bans []int64
fam string
mal []int64
bans []int64
banJail map[int64]string
fam string
}
// BlockerTTB is the time to ban of the bans applied by one blocker: the host
// fail2ban jails, or Urutau's second firewall (its "urutau" jail).
type BlockerTTB struct {
Blocker string `json:"blocker"` // "fail2ban" or "urutau"
Bans int `json:"bans"`
MedianS int64 `json:"median_s"`
P90S int64 `json:"p90_s"`
}
func blockerOf(jail string) string {
if jail == "urutau" {
return "urutau"
}
return "fail2ban"
}
// anEpisodes splits the activity of one address into attack episodes. An
@@ -472,7 +491,7 @@ func anEpisodes(mal, bans []int64, end int64) []anSubject {
}
i = j
if next >= 0 && next-last <= episodeGap {
out = append(out, anSubject{next - start, true})
out = append(out, anSubject{T: next - start, Event: true, Ban: next})
prev = next
bi++
continue
@@ -485,7 +504,7 @@ func anEpisodes(mal, bans []int64, end int64) []anSubject {
if d < 0 {
d = 0
}
out = append(out, anSubject{d, false})
out = append(out, anSubject{T: d})
prev = last
}
return out
@@ -514,6 +533,12 @@ func (s *Store) survival(from, to int64, host string) SurvivalOut {
}
if isBan {
st.bans = append(st.bans, r.T)
if r.Jail != "" {
if st.banJail == nil {
st.banJail = map[int64]string{}
}
st.banJail[r.T] = r.Jail
}
return true
}
if len(st.mal) < 5000 {
@@ -530,6 +555,7 @@ func (s *Store) survival(from, to int64, host string) SurvivalOut {
}
var subs []anSubject
famT := map[string][]int64{}
blockT := map[string][]int64{}
var banned, recid, attackers int
var rec []Recidivist
for ip, st := range ips {
@@ -540,6 +566,10 @@ func (s *Store) survival(from, to int64, host string) SurvivalOut {
eps := anEpisodes(st.mal, st.bans, end)
subs = append(subs, eps...)
for _, e := range eps {
if e.Event {
b := blockerOf(st.banJail[e.Ban])
blockT[b] = append(blockT[b], e.T)
}
if e.Event && st.fam != "" {
famT[st.fam] = append(famT[st.fam], e.T)
}
@@ -557,6 +587,15 @@ func (s *Store) survival(from, to int64, host string) SurvivalOut {
if banned > 0 {
out.RecidivismPct = math.Round(float64(recid)/float64(banned)*1000) / 10
}
out.ByBlocker = []BlockerTTB{}
for _, b := range []string{"fail2ban", "urutau"} {
v := blockT[b]
if len(v) == 0 {
continue
}
sort.Slice(v, func(i, j int) bool { return v[i] < v[j] })
out.ByBlocker = append(out.ByBlocker, BlockerTTB{b, len(v), anQuant(v, .5), anQuant(v, .9)})
}
for f, v := range famT {
sort.Slice(v, func(i, j int) bool { return v[i] < v[j] })
out.ByFamily = append(out.ByFamily, FamTTB{f, anQuant(v, .25), anQuant(v, .5), anQuant(v, .75), len(v)})