github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/action_go_group.go (about)

     1  package waf
     2  
     3  import (
     4  	"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
     5  	"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
     6  	"github.com/iwind/TeaGo/types"
     7  	"net/http"
     8  )
     9  
    10  type GoGroupAction struct {
    11  	BaseAction
    12  
    13  	GroupId string `yaml:"groupId" json:"groupId"`
    14  }
    15  
    16  func (this *GoGroupAction) Init(waf *WAF) error {
    17  	return nil
    18  }
    19  
    20  func (this *GoGroupAction) Code() string {
    21  	return ActionGoGroup
    22  }
    23  
    24  func (this *GoGroupAction) IsAttack() bool {
    25  	return false
    26  }
    27  
    28  func (this *GoGroupAction) WillChange() bool {
    29  	return true
    30  }
    31  
    32  func (this *GoGroupAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, request requests.Request, writer http.ResponseWriter) PerformResult {
    33  	var nextGroup = waf.FindRuleGroup(types.Int64(this.GroupId))
    34  	if nextGroup == nil || !nextGroup.IsOn {
    35  		return PerformResult{
    36  			ContinueRequest: true,
    37  			GoNextSet:       true,
    38  		}
    39  	}
    40  
    41  	b, _, nextSet, err := nextGroup.MatchRequest(request)
    42  	if err != nil {
    43  		remotelogs.Error("WAF", "GO_GROUP_ACTION: "+err.Error())
    44  		return PerformResult{
    45  			ContinueRequest: true,
    46  			GoNextSet:       true,
    47  		}
    48  	}
    49  
    50  	if !b {
    51  		return PerformResult{
    52  			ContinueRequest: true,
    53  			GoNextSet:       true,
    54  		}
    55  	}
    56  
    57  	return nextSet.PerformActions(waf, nextGroup, request, writer)
    58  }