2020-10-06 21:02:21 +08:00
|
|
|
package firewallconfigs
|
|
|
|
|
|
2021-09-25 19:41:10 +08:00
|
|
|
import (
|
|
|
|
|
"github.com/iwind/TeaGo/logs"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
|
|
|
|
)
|
2020-10-06 21:02:21 +08:00
|
|
|
|
2021-07-14 22:46:31 +08:00
|
|
|
// HTTPFirewallActionConfig 单个动作配置
|
|
|
|
|
type HTTPFirewallActionConfig struct {
|
|
|
|
|
Code HTTPFirewallActionString `yaml:"code" json:"code"`
|
|
|
|
|
Options maps.Map `yaml:"options" json:"options"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// HTTPFirewallRuleSet 规则集定义
|
2020-10-06 21:02:21 +08:00
|
|
|
type HTTPFirewallRuleSet struct {
|
2021-07-14 22:46:31 +08:00
|
|
|
Id int64 `yaml:"id" json:"id"`
|
|
|
|
|
IsOn bool `yaml:"isOn" json:"isOn"`
|
|
|
|
|
Name string `yaml:"name" json:"name"`
|
|
|
|
|
Code string `yaml:"code" json:"code"`
|
|
|
|
|
Description string `yaml:"description" json:"description"`
|
|
|
|
|
Connector string `yaml:"connector" json:"connector"`
|
|
|
|
|
RuleRefs []*HTTPFirewallRuleRef `yaml:"ruleRefs" json:"ruleRefs"`
|
|
|
|
|
Rules []*HTTPFirewallRule `yaml:"rules" json:"rules"`
|
2021-12-02 16:08:29 +08:00
|
|
|
IgnoreLocal bool `yaml:"ignoreLocal" json:"ignoreLocal"`
|
2021-07-14 22:46:31 +08:00
|
|
|
|
|
|
|
|
Actions []*HTTPFirewallActionConfig `yaml:"actions" json:"actions"`
|
|
|
|
|
|
|
|
|
|
//Action string `yaml:"action" json:"action"` // deprecated, v0.2.5
|
|
|
|
|
//ActionOptions maps.Map `yaml:"actionOptions" json:"actionOptions"` // deprecated, v0.2.5
|
2020-10-06 21:02:21 +08:00
|
|
|
}
|
|
|
|
|
|
2021-07-14 22:46:31 +08:00
|
|
|
// Init 初始化
|
2020-10-06 21:02:21 +08:00
|
|
|
func (this *HTTPFirewallRuleSet) Init() error {
|
|
|
|
|
for _, rule := range this.Rules {
|
|
|
|
|
err := rule.Init()
|
|
|
|
|
if err != nil {
|
2021-09-25 19:41:10 +08:00
|
|
|
logs.Println("ERROR", "validate rule '"+rule.Summary()+"' failed: "+err.Error())
|
|
|
|
|
|
|
|
|
|
// 这里不阻断执行,因为先前有些用户填写了错误的规则
|
2020-10-06 21:02:21 +08:00
|
|
|
}
|
|
|
|
|
}
|
2021-07-14 22:46:31 +08:00
|
|
|
|
2020-10-06 21:02:21 +08:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-14 22:46:31 +08:00
|
|
|
// AddRule 添加规则
|
2020-10-06 21:02:21 +08:00
|
|
|
func (this *HTTPFirewallRuleSet) AddRule(rule *HTTPFirewallRule) {
|
|
|
|
|
this.Rules = append(this.Rules, rule)
|
|
|
|
|
}
|