diff --git a/docs/config.md b/docs/config.md index 69a0053..0586616 100644 --- a/docs/config.md +++ b/docs/config.md @@ -45,4 +45,5 @@ Example: ``` **Description** The [[rule]] section require name and one of the following parameters: service, path, status, method. To add a rule, create a [[rule]] block and specify the parameters. -ban_time require in format "1m", "1h", "1d", "1M", "1y" +ban_time require in format "1m", "1h", "1d", "1M", "1y". +If you want to ban all requests to PHP files (e.g., path = "*.php") or requests to the admin panel (e.g., path = "/admin/*") diff --git a/internal/judge/judge.go b/internal/judge/judge.go index 84a9881..a41b69c 100644 --- a/internal/judge/judge.go +++ b/internal/judge/judge.go @@ -2,12 +2,12 @@ package judge import ( "fmt" - "time" - "github.com/d3m0k1d/BanForge/internal/blocker" "github.com/d3m0k1d/BanForge/internal/config" "github.com/d3m0k1d/BanForge/internal/logger" "github.com/d3m0k1d/BanForge/internal/storage" + "strings" + "time" ) type Judge struct { @@ -71,7 +71,7 @@ func (j *Judge) ProcessUnviewed() error { for _, rule := range rules { if (rule.Method == "" || entry.Method == rule.Method) && (rule.Status == "" || entry.Status == rule.Status) && - (rule.Path == "" || entry.Path == rule.Path) { + matchPath(entry.Path, rule.Path) { j.logger.Info( fmt.Sprintf( @@ -141,3 +141,18 @@ func (j *Judge) UnbanChecker() { } } } + +func matchPath(path string, rulePath string) bool { + if rulePath == "" { + return true + } + if strings.HasPrefix(rulePath, "/*") { + prefix := strings.TrimPrefix(rulePath, "*") + return strings.HasPrefix(path, prefix) + } + if strings.HasSuffix(rulePath, "*") { + suffix := strings.TrimSuffix(rulePath, "*") + return strings.HasSuffix(path, suffix) + } + return path == rulePath +}