diff options
Diffstat (limited to 'lib/policy/bot.go')
| -rw-r--r-- | lib/policy/bot.go | 35 |
1 files changed, 4 insertions, 31 deletions
diff --git a/lib/policy/bot.go b/lib/policy/bot.go index e656d9a..3a43655 100644 --- a/lib/policy/bot.go +++ b/lib/policy/bot.go @@ -2,45 +2,18 @@ package policy import ( "fmt" - "regexp" - "strings" "github.com/TecharoHQ/anubis/internal" "github.com/TecharoHQ/anubis/lib/policy/config" - "github.com/yl2chen/cidranger" ) type Bot struct { Name string - UserAgent *regexp.Regexp - Path *regexp.Regexp - Headers map[string]*regexp.Regexp - Action config.Rule `json:"action"` + Action config.Rule Challenge *config.ChallengeRules - Ranger cidranger.Ranger + Rules Checker } -func (b Bot) Hash() (string, error) { - var pathRex string - if b.Path != nil { - pathRex = b.Path.String() - } - var userAgentRex string - if b.UserAgent != nil { - userAgentRex = b.UserAgent.String() - } - var headersRex string - if len(b.Headers) > 0 { - var sb strings.Builder - sb.Grow(len(b.Headers) * 64) - - for name, expr := range b.Headers { - sb.WriteString(name) - sb.WriteString(expr.String()) - } - - headersRex = sb.String() - } - - return internal.SHA256sum(fmt.Sprintf("%s::%s::%s::%s", b.Name, pathRex, userAgentRex, headersRex)), nil +func (b Bot) Hash() string { + return internal.SHA256sum(fmt.Sprintf("%s::%s", b.Name, b.Rules.Hash())) } |
