diff --git a/internal/web/actions/default/servers/components/waf/init.go b/internal/web/actions/default/servers/components/waf/init.go index dcf79c6b..84bd73df 100644 --- a/internal/web/actions/default/servers/components/waf/init.go +++ b/internal/web/actions/default/servers/components/waf/init.go @@ -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)). diff --git a/internal/web/actions/default/servers/components/waf/testRegexp.go b/internal/web/actions/default/servers/components/waf/testRegexp.go new file mode 100644 index 00000000..e2345b7e --- /dev/null +++ b/internal/web/actions/default/servers/components/waf/testRegexp.go @@ -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() +} diff --git a/web/views/@default/servers/components/waf/createRulePopup.html b/web/views/@default/servers/components/waf/createRulePopup.html index 61a18e96..86be3393 100644 --- a/web/views/@default/servers/components/waf/createRulePopup.html +++ b/web/views/@default/servers/components/waf/createRulePopup.html @@ -8,7 +8,7 @@ - + - - - - - - @@ -89,7 +81,7 @@ - + - - - - - + + + + + + + + + + + + + +
参数参数 *
编解码 - -
操作符操作符 *
开启大小写不敏感 -
- - -
-

开启后忽略英文字母大小写

-
对比值 + 正则表达式 + 对比值 +
@@ -121,9 +106,41 @@
- +
正则表达式测试 + [输入测试字符串] +
+ +

+ {{regexpTestResult.message}} + {{regexpTestResult.message}} + +   [结束测试] +

+
+
不区分大小写 +
+ + +
+

开启后忽略英文字母大小写

+
编解码 + +
diff --git a/web/views/@default/servers/components/waf/createRulePopup.js b/web/views/@default/servers/components/waf/createRulePopup.js index 6b8d6863..dc23a0a1 100644 --- a/web/views/@default/servers/components/waf/createRulePopup.js +++ b/web/views/@default/servers/components/waf/createRulePopup.js @@ -68,4 +68,57 @@ Tea.context(function () { } }; this.changeOperator() + + /** + * caseInsensitive + */ + this.changeCaseInsensitive = function () { + if (this.rule.operator == "match" || this.rule.operator == "not match") { + if (this.regexpTestIsOn) { + this.changeRegexpTestBody() + } + } + } + + /** + * value + */ + this.changeRuleValue = function () { + if (this.rule.operator == "match" || this.rule.operator == "not match") { + if (this.regexpTestIsOn) { + this.changeRegexpTestBody() + } + } else { + this.regexpTestIsOn = false + this.regexpTestResult = {isOk: false, message: ""} + } + } + + /** + * 正则测试 + */ + this.regexpTestIsOn = false + this.regexpTestBody = "" + this.regexpTestResult = {isOk: false, message: ""} + + this.changeRegexpTestIsOn = function () { + this.regexpTestIsOn = !this.regexpTestIsOn + if (this.regexpTestIsOn) { + this.$delay(function () { + this.$refs.regexpTestBody.focus() + }) + } + } + + this.changeRegexpTestBody = function () { + this.$post(".testRegexp") + .params({ + "regexp": this.rule.value, + "body": this.regexpTestBody, + "isCaseInsensitive": this.rule.isCaseInsensitive + }) + .success(function (resp) { + this.regexpTestResult = resp.data.result + }) + } }) \ No newline at end of file