From 2588c9ee2ed4c29c9778ea38f067cb283365619c Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 12 Dec 2021 20:56:25 +0800 Subject: [PATCH] =?UTF-8?q?WAF=E6=B7=BB=E5=8A=A0=E8=A7=84=E5=88=99?= =?UTF-8?q?=EF=BC=9A=E8=B0=83=E6=95=B4=E7=95=8C=E9=9D=A2/=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/servers/components/waf/init.go | 1 + .../servers/components/waf/testRegexp.go | 48 +++++++++++++++ .../components/waf/createRulePopup.html | 61 ++++++++++++------- .../servers/components/waf/createRulePopup.js | 53 ++++++++++++++++ 4 files changed, 141 insertions(+), 22 deletions(-) create mode 100644 internal/web/actions/default/servers/components/waf/testRegexp.go 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