mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
WAF添加规则:调整界面/增加正则表达式测试功能
This commit is contained in:
@@ -41,6 +41,7 @@ func init() {
|
||||
GetPost("/updateSetPopup", new(UpdateSetPopupAction)).
|
||||
Post("/count", new(CountAction)).
|
||||
Get("/selectPopup", new(SelectPopupAction)).
|
||||
Post("/testRegexp", new(TestRegexpAction)).
|
||||
|
||||
// IP管理
|
||||
GetPost("/ipadmin", new(ipadmin.IndexAction)).
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package waf
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type TestRegexpAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *TestRegexpAction) RunPost(params struct {
|
||||
Regexp string
|
||||
IsCaseInsensitive bool
|
||||
Body string
|
||||
}) {
|
||||
var exp = params.Regexp
|
||||
if params.IsCaseInsensitive && !strings.HasPrefix(params.Regexp, "(?i)") {
|
||||
exp = "(?i)" + exp
|
||||
}
|
||||
reg, err := regexp.Compile(exp)
|
||||
if err != nil {
|
||||
this.Data["result"] = maps.Map{
|
||||
"isOk": false,
|
||||
"message": "解析正则出错:" + err.Error(),
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
|
||||
if reg.MatchString(params.Body) {
|
||||
this.Data["result"] = maps.Map{
|
||||
"isOk": true,
|
||||
"message": "匹配成功",
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
|
||||
this.Data["result"] = maps.Map{
|
||||
"isOk": false,
|
||||
"message": "匹配失败",
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user