mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-01 04:40:54 +08:00
WAF增加通配符匹配/不匹配操作符
This commit is contained in:
@@ -127,6 +127,21 @@ func (this *Rule) Init() error {
|
||||
this.ipList = values.ParseStringList(this.Value, true)
|
||||
case RuleOperatorIPRange, RuleOperatorNotIPRange:
|
||||
this.ipRangeListValue = values.ParseIPRangeList(this.Value)
|
||||
case RuleOperatorWildcardMatch, RuleOperatorWildcardNotMatch:
|
||||
var pieces = strings.Split(this.Value, "*")
|
||||
for index, piece := range pieces {
|
||||
pieces[index] = regexp.QuoteMeta(piece)
|
||||
}
|
||||
var pattern = strings.Join(pieces, "(.*)")
|
||||
var expr = "^" + pattern + "$"
|
||||
if this.IsCaseInsensitive {
|
||||
expr = "(?i)" + expr
|
||||
}
|
||||
reg, err := re.Compile(expr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
this.reg = reg
|
||||
}
|
||||
|
||||
if singleParamRegexp.MatchString(this.Param) {
|
||||
@@ -369,7 +384,7 @@ func (this *Rule) Test(value interface{}) bool {
|
||||
} else {
|
||||
return types.String(value) != this.Value
|
||||
}
|
||||
case RuleOperatorMatch:
|
||||
case RuleOperatorMatch, RuleOperatorWildcardMatch:
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -393,7 +408,7 @@ func (this *Rule) Test(value interface{}) bool {
|
||||
|
||||
// string
|
||||
return utils.MatchStringCache(this.reg, types.String(value))
|
||||
case RuleOperatorNotMatch:
|
||||
case RuleOperatorNotMatch, RuleOperatorWildcardNotMatch:
|
||||
if value == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ const (
|
||||
RuleOperatorNeqString RuleOperator = "neq string"
|
||||
RuleOperatorMatch RuleOperator = "match"
|
||||
RuleOperatorNotMatch RuleOperator = "not match"
|
||||
RuleOperatorWildcardMatch RuleOperator = "wildcard match"
|
||||
RuleOperatorWildcardNotMatch RuleOperator = "wildcard not match"
|
||||
RuleOperatorContains RuleOperator = "contains"
|
||||
RuleOperatorNotContains RuleOperator = "not contains"
|
||||
RuleOperatorPrefix RuleOperator = "prefix"
|
||||
|
||||
Reference in New Issue
Block a user