IP名单中IP创建时保存相关节点、服务、WAF策略信息

This commit is contained in:
GoEdgeLab
2021-11-16 16:10:48 +08:00
parent 9b0033dd0d
commit b94b7399d3
4 changed files with 160 additions and 40 deletions

View File

@@ -86,6 +86,19 @@ func (this *HTTPFirewallPolicyDAO) FindHTTPFirewallPolicyName(tx *dbs.Tx, id int
FindStringCol("")
}
// FindEnabledHTTPFirewallPolicyBasic 获取WAF策略基本信息
func (this *HTTPFirewallPolicyDAO) FindEnabledHTTPFirewallPolicyBasic(tx *dbs.Tx, policyId int64) (*HTTPFirewallPolicy, error) {
result, err := this.Query(tx).
Pk(policyId).
Result("id", "name", "serverId", "isOn").
Attr("state", HTTPFirewallPolicyStateEnabled).
Find()
if result == nil {
return nil, err
}
return result.(*HTTPFirewallPolicy), err
}
// FindAllEnabledFirewallPolicies 查找所有可用策略
func (this *HTTPFirewallPolicyDAO) FindAllEnabledFirewallPolicies(tx *dbs.Tx) (result []*HTTPFirewallPolicy, err error) {
_, err = this.Query(tx).

View File

@@ -98,7 +98,21 @@ func (this *IPItemDAO) DisableOldIPItem(tx *dbs.Tx, listId int64, ipFrom string,
}
// CreateIPItem 创建IP
func (this *IPItemDAO) CreateIPItem(tx *dbs.Tx, listId int64, ipFrom string, ipTo string, expiredAt int64, reason string, itemType IPItemType, eventLevel string) (int64, error) {
func (this *IPItemDAO) CreateIPItem(tx *dbs.Tx,
listId int64,
ipFrom string,
ipTo string,
expiredAt int64,
reason string,
itemType IPItemType,
eventLevel string,
nodeId int64,
serverId int64,
sourceNodeId int64,
sourceServerId int64,
sourceHTTPFirewallPolicyId int64,
sourceHTTPFirewallRuleGroupId int64,
sourceHTTPFirewallRuleSetId int64) (int64, error) {
version, err := SharedIPListDAO.IncreaseVersion(tx)
if err != nil {
return 0, err
@@ -118,6 +132,15 @@ func (this *IPItemDAO) CreateIPItem(tx *dbs.Tx, listId int64, ipFrom string, ipT
expiredAt = 0
}
op.ExpiredAt = expiredAt
op.NodeId = nodeId
op.ServerId = serverId
op.SourceNodeId = sourceNodeId
op.SourceServerId = sourceServerId
op.SourceHTTPFirewallPolicyId = sourceHTTPFirewallPolicyId
op.SourceHTTPFirewallRuleGroupId = sourceHTTPFirewallRuleGroupId
op.SourceHTTPFirewallRuleSetId = sourceHTTPFirewallRuleSetId
op.State = IPItemStateEnabled
err = this.Save(tx, op)
if err != nil {

View File

@@ -1,38 +1,52 @@
package models
// IP
// IPItem IP
type IPItem struct {
Id uint64 `field:"id"` // ID
ListId uint32 `field:"listId"` // 所属名单ID
Type string `field:"type"` // 类型
IpFrom string `field:"ipFrom"` // 开始IP
IpTo string `field:"ipTo"` // 结束IP
IpFromLong uint64 `field:"ipFromLong"` // 开始IP整型
IpToLong uint64 `field:"ipToLong"` // 结束IP整型
Version uint64 `field:"version"` // 版本
CreatedAt uint64 `field:"createdAt"` // 创建时间
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
Reason string `field:"reason"` // 加入说明
EventLevel string `field:"eventLevel"` // 事件级别
State uint8 `field:"state"` // 状态
ExpiredAt uint64 `field:"expiredAt"` // 过期时间
Id uint64 `field:"id"` // ID
ListId uint32 `field:"listId"` // 所属名单ID
Type string `field:"type"` // 类型
IpFrom string `field:"ipFrom"` // 开始IP
IpTo string `field:"ipTo"` // 结束IP
IpFromLong uint64 `field:"ipFromLong"` // 开始IP整型
IpToLong uint64 `field:"ipToLong"` // 结束IP整型
Version uint64 `field:"version"` // 版本
CreatedAt uint64 `field:"createdAt"` // 创建时间
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
Reason string `field:"reason"` // 加入说明
EventLevel string `field:"eventLevel"` // 事件级别
State uint8 `field:"state"` // 状态
ExpiredAt uint64 `field:"expiredAt"` // 过期时间
ServerId uint32 `field:"serverId"` // 有效范围服务ID
NodeId uint32 `field:"nodeId"` // 有效范围节点ID
SourceNodeId uint32 `field:"sourceNodeId"` // 来源节点ID
SourceServerId uint32 `field:"sourceServerId"` // 来源服务ID
SourceHTTPFirewallPolicyId uint32 `field:"sourceHTTPFirewallPolicyId"` // 来源策略ID
SourceHTTPFirewallRuleGroupId uint32 `field:"sourceHTTPFirewallRuleGroupId"` // 来源规则集分组ID
SourceHTTPFirewallRuleSetId uint32 `field:"sourceHTTPFirewallRuleSetId"` // 来源规则集ID
}
type IPItemOperator struct {
Id interface{} // ID
ListId interface{} // 所属名单ID
Type interface{} // 类型
IpFrom interface{} // 开始IP
IpTo interface{} // 结束IP
IpFromLong interface{} // 开始IP整型
IpToLong interface{} // 结束IP整型
Version interface{} // 版本
CreatedAt interface{} // 创建时间
UpdatedAt interface{} // 修改时间
Reason interface{} // 加入说明
EventLevel interface{} // 事件级别
State interface{} // 状态
ExpiredAt interface{} // 过期时间
Id interface{} // ID
ListId interface{} // 所属名单ID
Type interface{} // 类型
IpFrom interface{} // 开始IP
IpTo interface{} // 结束IP
IpFromLong interface{} // 开始IP整型
IpToLong interface{} // 结束IP整型
Version interface{} // 版本
CreatedAt interface{} // 创建时间
UpdatedAt interface{} // 修改时间
Reason interface{} // 加入说明
EventLevel interface{} // 事件级别
State interface{} // 状态
ExpiredAt interface{} // 过期时间
ServerId interface{} // 有效范围服务ID
NodeId interface{} // 有效范围节点ID
SourceNodeId interface{} // 来源节点ID
SourceServerId interface{} // 来源服务ID
SourceHTTPFirewallPolicyId interface{} // 来源策略ID
SourceHTTPFirewallRuleGroupId interface{} // 来源规则集分组ID
SourceHTTPFirewallRuleSetId interface{} // 来源规则集ID
}
func NewIPItemOperator() *IPItemOperator {