From d36dee39fe0b0f6c692b7e1b425816f40d8cc2ba Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 15 Nov 2023 15:12:08 +0800 Subject: [PATCH] =?UTF-8?q?WAF=E4=BA=BA=E6=9C=BA=E8=AF=86=E5=88=AB?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=82=B9=E5=87=BB=E9=AA=8C=E8=AF=81=E5=92=8C?= =?UTF-8?q?=E6=BB=91=E5=8A=A8=E8=A7=A3=E9=94=81=E9=AA=8C=E8=AF=81/?= =?UTF-8?q?=E5=8D=95=E4=B8=AA=E7=BD=91=E7=AB=99=E5=8F=AF=E4=BB=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=BB=98=E8=AE=A4=E7=9A=84=E4=BA=BA=E6=9C=BA=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../firewallconfigs/captcha_types.go | 59 +++++++++++++++++++ .../http_firewall_action_captcha.go | 2 + .../http_firewall_action_utils.go | 4 +- .../firewallconfigs/http_firewall_ref.go | 11 ++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 pkg/serverconfigs/firewallconfigs/captcha_types.go diff --git a/pkg/serverconfigs/firewallconfigs/captcha_types.go b/pkg/serverconfigs/firewallconfigs/captcha_types.go new file mode 100644 index 0000000..c9cb6ce --- /dev/null +++ b/pkg/serverconfigs/firewallconfigs/captcha_types.go @@ -0,0 +1,59 @@ +// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn . + +package firewallconfigs + +import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" + +type CaptchaType = string + +const ( + CaptchaTypeDefault CaptchaType = "default" + CaptchaTypeOneClick CaptchaType = "oneClick" + CaptchaTypeSlide CaptchaType = "slide" +) + +// FindAllCaptchaTypes Find all captcha types +func FindAllCaptchaTypes() []*shared.Definition { + return []*shared.Definition{ + { + Code: CaptchaTypeDefault, + Name: "验证码", + Description: "通过输入验证码来验证人机。", + }, + { + Code: CaptchaTypeOneClick, + Name: "点击验证", + Description: "通过点击界面元素来验证人机。", + }, + { + Code: CaptchaTypeSlide, + Name: "滑动解锁", + Description: "通过滑动方块解锁来验证人机。", + }, + } +} + +func DefaultCaptchaType() *shared.Definition { + var captchaTypes = FindAllCaptchaTypes() + if len(captchaTypes) > 0 { + return captchaTypes[0] + } + return &shared.Definition{ + Code: CaptchaTypeDefault, + Name: "验证码", + } +} + +func FindCaptchaType(code CaptchaType) *shared.Definition { + if len(code) == 0 { + code = CaptchaTypeDefault + } + + for _, t := range FindAllCaptchaTypes() { + if t.Code == code { + return t + } + } + + return DefaultCaptchaType() +} diff --git a/pkg/serverconfigs/firewallconfigs/http_firewall_action_captcha.go b/pkg/serverconfigs/firewallconfigs/http_firewall_action_captcha.go index 84dfa72..6ae2c42 100644 --- a/pkg/serverconfigs/firewallconfigs/http_firewall_action_captcha.go +++ b/pkg/serverconfigs/firewallconfigs/http_firewall_action_captcha.go @@ -3,6 +3,8 @@ package firewallconfigs type HTTPFirewallCaptchaAction struct { IsPrior bool `yaml:"isPrior" json:"isPrior"` + CaptchaType CaptchaType `yaml:"captchaType" json:"captchaType"` // 类型 + Life int32 `yaml:"life" json:"life"` // 有效期 MaxFails int `yaml:"maxFails" json:"maxFails"` // 最大失败次数 FailBlockTimeout int `yaml:"failBlockTimeout" json:"failBlockTimeout"` // 失败拦截时间 diff --git a/pkg/serverconfigs/firewallconfigs/http_firewall_action_utils.go b/pkg/serverconfigs/firewallconfigs/http_firewall_action_utils.go index ff80cf7..c0028ce 100644 --- a/pkg/serverconfigs/firewallconfigs/http_firewall_action_utils.go +++ b/pkg/serverconfigs/firewallconfigs/http_firewall_action_utils.go @@ -12,9 +12,9 @@ var AllActions = []*HTTPFirewallActionDefinition{ Category: HTTPFirewallActionCategoryBlock, }, { - Name: "Captcha验证码", + Name: "Captcha人机识别", Code: HTTPFirewallActionCaptcha, - Description: "在浏览器使用验证码来验证客户端。", + Description: "在浏览器使用人机识别机制(比如验证码)来验证客户端。", Category: HTTPFirewallActionCategoryVerify, }, { diff --git a/pkg/serverconfigs/firewallconfigs/http_firewall_ref.go b/pkg/serverconfigs/firewallconfigs/http_firewall_ref.go index 7a362fb..48303b0 100644 --- a/pkg/serverconfigs/firewallconfigs/http_firewall_ref.go +++ b/pkg/serverconfigs/firewallconfigs/http_firewall_ref.go @@ -1,10 +1,21 @@ package firewallconfigs +type ServerCaptchaType = string + +const ( + ServerCaptchaTypeNone ServerCaptchaType = "none" // 不设置表示策略整体配置 + ServerCaptchaTypeDefault ServerCaptchaType = CaptchaTypeDefault + ServerCaptchaTypeOneClick ServerCaptchaType = CaptchaTypeOneClick + ServerCaptchaTypeSlide ServerCaptchaType = CaptchaTypeSlide +) + type HTTPFirewallRef struct { IsPrior bool `yaml:"isPrior" json:"isPrior"` IsOn bool `yaml:"isOn" json:"isOn"` FirewallPolicyId int64 `yaml:"firewallPolicyId" json:"firewallPolicyId"` IgnoreGlobalRules bool `yaml:"ignoreGlobalRules" json:"ignoreGlobalRules"` // 忽略系统定义的全局规则 + + DefaultCaptchaType ServerCaptchaType `yaml:"defaultCaptchaType" json:"defaultCaptchaType"` // 默认人机识别方式 } func (this *HTTPFirewallRef) Init() error {