mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-20 04:50:26 +08:00
WAF增加通配符匹配/不匹配操作符
This commit is contained in:
@@ -127,6 +127,21 @@ func (this *Rule) Init() error {
|
|||||||
this.ipList = values.ParseStringList(this.Value, true)
|
this.ipList = values.ParseStringList(this.Value, true)
|
||||||
case RuleOperatorIPRange, RuleOperatorNotIPRange:
|
case RuleOperatorIPRange, RuleOperatorNotIPRange:
|
||||||
this.ipRangeListValue = values.ParseIPRangeList(this.Value)
|
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) {
|
if singleParamRegexp.MatchString(this.Param) {
|
||||||
@@ -369,7 +384,7 @@ func (this *Rule) Test(value interface{}) bool {
|
|||||||
} else {
|
} else {
|
||||||
return types.String(value) != this.Value
|
return types.String(value) != this.Value
|
||||||
}
|
}
|
||||||
case RuleOperatorMatch:
|
case RuleOperatorMatch, RuleOperatorWildcardMatch:
|
||||||
if value == nil {
|
if value == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -393,7 +408,7 @@ func (this *Rule) Test(value interface{}) bool {
|
|||||||
|
|
||||||
// string
|
// string
|
||||||
return utils.MatchStringCache(this.reg, types.String(value))
|
return utils.MatchStringCache(this.reg, types.String(value))
|
||||||
case RuleOperatorNotMatch:
|
case RuleOperatorNotMatch, RuleOperatorWildcardNotMatch:
|
||||||
if value == nil {
|
if value == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ const (
|
|||||||
RuleOperatorNeqString RuleOperator = "neq string"
|
RuleOperatorNeqString RuleOperator = "neq string"
|
||||||
RuleOperatorMatch RuleOperator = "match"
|
RuleOperatorMatch RuleOperator = "match"
|
||||||
RuleOperatorNotMatch RuleOperator = "not match"
|
RuleOperatorNotMatch RuleOperator = "not match"
|
||||||
|
RuleOperatorWildcardMatch RuleOperator = "wildcard match"
|
||||||
|
RuleOperatorWildcardNotMatch RuleOperator = "wildcard not match"
|
||||||
RuleOperatorContains RuleOperator = "contains"
|
RuleOperatorContains RuleOperator = "contains"
|
||||||
RuleOperatorNotContains RuleOperator = "not contains"
|
RuleOperatorNotContains RuleOperator = "not contains"
|
||||||
RuleOperatorPrefix RuleOperator = "prefix"
|
RuleOperatorPrefix RuleOperator = "prefix"
|
||||||
|
|||||||
Reference in New Issue
Block a user