diff --git a/app/daemon.go b/app/daemon.go index f4b8e6e..f258a66 100644 --- a/app/daemon.go +++ b/app/daemon.go @@ -62,6 +62,12 @@ func runCommands(commands [][]string, moment string) bool { } func (p *Pattern) notAnIgnore(match *string) bool { + for _, regex := range p.compiledIgnoreRegex { + if regex.MatchString(*match) { + return false + } + } + for _, ignore := range p.Ignore { if ignore == *match { return false diff --git a/app/example.yml b/app/example.yml index f3e34c5..06e953e 100644 --- a/app/example.yml +++ b/app/example.yml @@ -23,6 +23,9 @@ patterns: ignore: - 127.0.0.1 - ::1 + # Patterns can be ignored based on regexes, it will try to match the whole string detected by the pattern + # ignoreregex: + # - '10\.0\.[0-9]{1,3}\.[0-9]{1,3}' # Those commands will be executed in order at start, before everything else start: diff --git a/app/startup.go b/app/startup.go index 1364d8b..beeac0b 100644 --- a/app/startup.go +++ b/app/startup.go @@ -39,6 +39,17 @@ func (c *Conf) setup() { logger.Fatalf("Bad configuration: pattern ignore '%v' doesn't match pattern %v! It should be fixed or removed.", ignore, pattern.nameWithBraces) } } + + // Compile ignore regexes + for _, regex := range pattern.IgnoreRegex { + // Enclose the regex to make sure that it matches the whole detected string + compiledRegex, err := regexp.Compile("^" + regex + "$") + if err != nil { + log.Fatalf("%vBad configuration: in ignoreregex of pattern %s: %v", logger.FATAL, pattern.name, err) + } + + pattern.compiledIgnoreRegex = append(pattern.compiledIgnoreRegex, *compiledRegex) + } } if len(c.Streams) == 0 { diff --git a/app/types.go b/app/types.go index dd8b72a..62072fb 100644 --- a/app/types.go +++ b/app/types.go @@ -19,6 +19,9 @@ type Pattern struct { Regex string `json:"regex"` Ignore []string `json:"ignore"` + IgnoreRegex []string `json:"ignoreregex"` + compiledIgnoreRegex []regexp.Regexp `json:"-"` + name string `json:"-"` nameWithBraces string `json:"-"` } diff --git a/config/example.jsonnet b/config/example.jsonnet index 25075a1..ed42964 100644 --- a/config/example.jsonnet +++ b/config/example.jsonnet @@ -29,6 +29,8 @@ local banFor(time) = { // simple version: regex: @'(?:(?:[0-9]{1,3}\.){3}[0-9]{1,3})|(?:[0-9a-fA-F:]{2,90})', regex: @'(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}|(?:(?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(?::[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(?:ffff(?::0{1,4}){0,1}:){0,1}(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9]))', ignore: ['127.0.0.1', '::1'], + // Patterns can be ignored based on regexes, it will try to match the whole string detected by the pattern + // ignoreregex: [@'10\.0\.[0-9]{1,3}\.[0-9]{1,3}'], }, },