2020-10-08 15:06:42 +08:00
|
|
|
package waf
|
|
|
|
|
|
|
|
|
|
import (
|
2022-08-25 16:44:44 +08:00
|
|
|
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
2020-10-08 15:06:42 +08:00
|
|
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
2021-11-16 16:11:05 +08:00
|
|
|
"github.com/iwind/TeaGo/types"
|
2020-10-08 15:06:42 +08:00
|
|
|
"net/http"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GoSetAction struct {
|
2022-05-21 11:17:53 +08:00
|
|
|
BaseAction
|
|
|
|
|
|
2020-10-08 15:06:42 +08:00
|
|
|
GroupId string `yaml:"groupId" json:"groupId"`
|
|
|
|
|
SetId string `yaml:"setId" json:"setId"`
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-18 15:51:49 +08:00
|
|
|
func (this *GoSetAction) Init(waf *WAF) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *GoSetAction) Code() string {
|
|
|
|
|
return ActionGoSet
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *GoSetAction) IsAttack() bool {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *GoSetAction) WillChange() bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-20 20:54:41 +08:00
|
|
|
func (this *GoSetAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, request requests.Request, writer http.ResponseWriter) PerformResult {
|
|
|
|
|
var nextGroup = waf.FindRuleGroup(types.Int64(this.GroupId))
|
2021-07-18 15:51:49 +08:00
|
|
|
if nextGroup == nil || !nextGroup.IsOn {
|
2024-01-20 20:54:41 +08:00
|
|
|
return PerformResult{
|
|
|
|
|
ContinueRequest: true,
|
|
|
|
|
GoNextSet: true,
|
|
|
|
|
}
|
2020-10-08 15:06:42 +08:00
|
|
|
}
|
2024-01-20 20:54:41 +08:00
|
|
|
var nextSet = nextGroup.FindRuleSet(types.Int64(this.SetId))
|
2021-07-18 15:51:49 +08:00
|
|
|
if nextSet == nil || !nextSet.IsOn {
|
2024-01-20 20:54:41 +08:00
|
|
|
return PerformResult{
|
|
|
|
|
ContinueRequest: true,
|
|
|
|
|
GoNextSet: true,
|
|
|
|
|
}
|
2020-10-08 15:06:42 +08:00
|
|
|
}
|
|
|
|
|
|
2022-07-16 17:05:37 +08:00
|
|
|
b, _, err := nextSet.MatchRequest(request)
|
2020-10-08 15:06:42 +08:00
|
|
|
if err != nil {
|
2022-08-25 16:44:44 +08:00
|
|
|
remotelogs.Error("WAF", "GO_GROUP_ACTION: "+err.Error())
|
2024-01-20 20:54:41 +08:00
|
|
|
return PerformResult{
|
|
|
|
|
ContinueRequest: true,
|
|
|
|
|
GoNextSet: true,
|
|
|
|
|
}
|
2020-10-08 15:06:42 +08:00
|
|
|
}
|
|
|
|
|
if !b {
|
2024-01-20 20:54:41 +08:00
|
|
|
return PerformResult{
|
|
|
|
|
ContinueRequest: true,
|
|
|
|
|
GoNextSet: true,
|
|
|
|
|
}
|
2020-10-08 15:06:42 +08:00
|
|
|
}
|
2021-07-18 15:51:49 +08:00
|
|
|
return nextSet.PerformActions(waf, nextGroup, request, writer)
|
2020-10-08 15:06:42 +08:00
|
|
|
}
|