实现WAF部分功能

This commit is contained in:
GoEdgeLab
2020-10-07 11:18:24 +08:00
parent 608777480d
commit 0b50f7beec
7 changed files with 1218 additions and 165 deletions

View File

@@ -26,3 +26,23 @@ func (this *HTTPFirewallInboundConfig) FindGroupWithCode(code string) *HTTPFirew
}
return nil
}
// 删除某个分组
func (this *HTTPFirewallInboundConfig) RemoveRuleGroup(groupId int64) {
groups := []*HTTPFirewallRuleGroup{}
refs := []*HTTPFirewallRuleGroupRef{}
for _, g := range this.Groups {
if g.Id == groupId {
continue
}
groups = append(groups, g)
}
for _, ref := range this.GroupRefs {
if ref.GroupId == groupId {
continue
}
refs = append(refs, ref)
}
this.Groups = groups
this.GroupRefs = refs
}

View File

@@ -26,3 +26,23 @@ func (this *HTTPFirewallOutboundConfig) FindGroupWithCode(code string) *HTTPFire
}
return nil
}
// 删除某个分组
func (this *HTTPFirewallOutboundConfig) RemoveRuleGroup(groupId int64) {
groups := []*HTTPFirewallRuleGroup{}
refs := []*HTTPFirewallRuleGroupRef{}
for _, g := range this.Groups {
if g.Id == groupId {
continue
}
groups = append(groups, g)
}
for _, ref := range this.GroupRefs {
if ref.GroupId == groupId {
continue
}
refs = append(refs, ref)
}
this.Groups = groups
this.GroupRefs = refs
}

View File

@@ -1,5 +1,7 @@
package firewallconfigs
import "encoding/json"
// 防火墙策略
type HTTPFirewallPolicy struct {
Id int64 `yaml:"id" json:"id"`
@@ -49,3 +51,39 @@ func (this *HTTPFirewallPolicy) FindRuleGroupWithCode(code string) *HTTPFirewall
}
return nil
}
// 删除某个分组
func (this *HTTPFirewallPolicy) RemoveRuleGroup(groupId int64) {
if this.Inbound != nil {
this.Inbound.RemoveRuleGroup(groupId)
}
if this.Outbound != nil {
this.Outbound.RemoveRuleGroup(groupId)
}
}
// Inbound JSON
func (this *HTTPFirewallPolicy) InboundJSON() ([]byte, error) {
if this.Inbound == nil {
return []byte("null"), nil
}
groups := this.Inbound.Groups
this.Inbound.Groups = nil
defer func() {
this.Inbound.Groups = groups
}()
return json.Marshal(this.Inbound)
}
// Outbound JSON
func (this *HTTPFirewallPolicy) OutboundJSON() ([]byte, error) {
if this.Inbound == nil {
return []byte("null"), nil
}
groups := this.Outbound.Groups
this.Outbound.Groups = nil
defer func() {
this.Outbound.Groups = groups
}()
return json.Marshal(this.Outbound)
}