check / check (push) Waiting to run
Moves only. waf.go now holds the package comment, Params, Server, New, newHandler, handler and ServeHTTP. The code that answers questions and takes reports moves to questionsandreports.go, and activeBan to activeban.go. refusedWhateverTheAnswer moves to lookup.go, beside its only caller. proxy.go is gone. The only changed lines are imports and the file comment of bans.go, split between it and activeban.go. Model: opus-5-5
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package waf
|
|
|
|
// The heuristic active_ban. It reads SWW_WAF_MODE; the bans are the ban
|
|
// ledger's.
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// activeBan refuses a client a ban covers: a ban on a netblock the client is
|
|
// in, in force at now. It notes for the log line when that ban ends. A request
|
|
// that makes the ban permanent, or in observe mode would have, raises the alert
|
|
// for it. Its figures are the ban's netblock and when it ends.
|
|
type activeBan struct {
|
|
banMaker banMaker
|
|
}
|
|
|
|
func (activeBan) name() string { return "active_ban" }
|
|
|
|
func (a activeBan) check(
|
|
_ context.Context,
|
|
rq *request,
|
|
now time.Time,
|
|
) *verdict {
|
|
ledger := a.banMaker.ledger
|
|
|
|
check := ledger.Check
|
|
if a.banMaker.observe {
|
|
check = ledger.Find // the ban refuses nothing, and stays as it is
|
|
}
|
|
|
|
ban, banned, madePermanent := check(rq.client, now)
|
|
|
|
var expires string
|
|
if banned {
|
|
expires = banExpires(ban)
|
|
rq.line.BanExpires = expires
|
|
}
|
|
|
|
if madePermanent {
|
|
ban.Expires = time.Time{} // the ban made permanent, which Find leaves as it is
|
|
a.banMaker.alertBan(rq, ban)
|
|
}
|
|
|
|
if !banned {
|
|
return nil
|
|
}
|
|
|
|
return &verdict{
|
|
action: banAction(ban.Permanent()),
|
|
figures: map[string]any{
|
|
figureNetblock: ban.Netblock.String(), "ban_expires": expires,
|
|
},
|
|
}
|
|
}
|