feat: Add new logic for judge path with *
Some checks failed
build / build (push) Failing after 1m38s
Some checks failed
build / build (push) Failing after 1m38s
This commit is contained in:
@@ -45,4 +45,5 @@ Example:
|
|||||||
```
|
```
|
||||||
**Description**
|
**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.
|
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/*")
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ package judge
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/d3m0k1d/BanForge/internal/blocker"
|
"github.com/d3m0k1d/BanForge/internal/blocker"
|
||||||
"github.com/d3m0k1d/BanForge/internal/config"
|
"github.com/d3m0k1d/BanForge/internal/config"
|
||||||
"github.com/d3m0k1d/BanForge/internal/logger"
|
"github.com/d3m0k1d/BanForge/internal/logger"
|
||||||
"github.com/d3m0k1d/BanForge/internal/storage"
|
"github.com/d3m0k1d/BanForge/internal/storage"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Judge struct {
|
type Judge struct {
|
||||||
@@ -71,7 +71,7 @@ func (j *Judge) ProcessUnviewed() error {
|
|||||||
for _, rule := range rules {
|
for _, rule := range rules {
|
||||||
if (rule.Method == "" || entry.Method == rule.Method) &&
|
if (rule.Method == "" || entry.Method == rule.Method) &&
|
||||||
(rule.Status == "" || entry.Status == rule.Status) &&
|
(rule.Status == "" || entry.Status == rule.Status) &&
|
||||||
(rule.Path == "" || entry.Path == rule.Path) {
|
matchPath(entry.Path, rule.Path) {
|
||||||
|
|
||||||
j.logger.Info(
|
j.logger.Info(
|
||||||
fmt.Sprintf(
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user