WAF人机识别实现点击验证和滑动解锁验证/单个网站可以设置默认的人机识别方式

This commit is contained in:
GoEdgeLab
2023-11-15 15:12:08 +08:00
parent 9af6080607
commit d36dee39fe
4 changed files with 74 additions and 2 deletions

View File

@@ -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()
}

View File

@@ -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"` // 失败拦截时间

View File

@@ -12,9 +12,9 @@ var AllActions = []*HTTPFirewallActionDefinition{
Category: HTTPFirewallActionCategoryBlock,
},
{
Name: "Captcha验证码",
Name: "Captcha人机识别",
Code: HTTPFirewallActionCaptcha,
Description: "在浏览器使用验证码来验证客户端。",
Description: "在浏览器使用人机识别机制(比如验证码来验证客户端。",
Category: HTTPFirewallActionCategoryVerify,
},
{

View File

@@ -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 {