(waf *WAF)
| 47 | } |
| 48 | |
| 49 | func (this *RuleSet) Init(waf *WAF) error { |
| 50 | this.hasRules = len(this.Rules) > 0 |
| 51 | if this.hasRules { |
| 52 | for _, rule := range this.Rules { |
| 53 | err := rule.Init() |
| 54 | if err != nil { |
| 55 | return fmt.Errorf("init rule '%s %s %s' failed: %w", rule.Param, rule.Operator, types.String(rule.Value), err) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // sort by priority |
| 60 | sort.Slice(this.Rules, func(i, j int) bool { |
| 61 | return this.Rules[i].Priority > this.Rules[j].Priority |
| 62 | }) |
| 63 | } |
| 64 | |
| 65 | // action codes |
| 66 | var actionCodes = []string{} |
| 67 | for _, action := range this.Actions { |
| 68 | if action.Code == ActionAllow { |
| 69 | this.hasAllowActions = true |
| 70 | if action.Options != nil { |
| 71 | this.allowScope = action.Options.GetString("scope") |
| 72 | } |
| 73 | } |
| 74 | if !lists.ContainsString(actionCodes, action.Code) { |
| 75 | actionCodes = append(actionCodes, action.Code) |
| 76 | } |
| 77 | } |
| 78 | this.actionCodes = actionCodes |
| 79 | |
| 80 | // action instances |
| 81 | this.actionInstances = []ActionInterface{} |
| 82 | for _, action := range this.Actions { |
| 83 | var instance = FindActionInstance(action.Code, action.Options) |
| 84 | if instance == nil { |
| 85 | remotelogs.Error("WAF_RULE_SET", "can not find instance for action '"+action.Code+"'") |
| 86 | continue |
| 87 | } |
| 88 | |
| 89 | err := instance.Init(waf) |
| 90 | if err != nil { |
| 91 | remotelogs.Error("WAF_RULE_SET", "init action '"+action.Code+"' failed: "+err.Error()) |
| 92 | continue |
| 93 | } |
| 94 | |
| 95 | this.actionInstances = append(this.actionInstances, instance) |
| 96 | waf.AddAction(instance) |
| 97 | } |
| 98 | |
| 99 | // sort actions |
| 100 | sort.Slice(this.actionInstances, func(i, j int) bool { |
| 101 | var instance1 = this.actionInstances[i] |
| 102 | if !instance1.WillChange() { |
| 103 | return true |
| 104 | } |
| 105 | if instance1.Code() == ActionRecordIP { |
| 106 | return true |
nothing calls this directly
no test coverage detected