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 {