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

     1  package waf
     2  
     3  import (
     4  	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
     5  	"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
     6  )
     7  
     8  func Template() (*WAF, error) {
     9  	var config = firewallconfigs.HTTPFirewallTemplate()
    10  	if config.Inbound != nil {
    11  		config.Inbound.IsOn = true
    12  	}
    13  
    14  	for _, group := range config.AllRuleGroups() {
    15  		if group.Code == "cc" || group.Code == "cc2" {
    16  			continue
    17  		}
    18  		group.IsOn = true
    19  
    20  		for _, set := range group.Sets {
    21  			set.IsOn = true
    22  		}
    23  	}
    24  
    25  	instance, err := SharedWAFManager.ConvertWAF(config)
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  
    30  	for _, group := range instance.Inbound {
    31  		for _, set := range group.RuleSets {
    32  			for _, rule := range set.Rules {
    33  				rule.cacheLife = utils.CacheDisabled // for performance test
    34  				_ = rule
    35  			}
    36  		}
    37  	}
    38  
    39  	return instance, nil
    40  }