2020-10-06 21:02:37 +08:00
|
|
|
package waf
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/models"
|
2020-11-18 19:35:32 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
2020-10-06 21:02:37 +08:00
|
|
|
"github.com/iwind/TeaGo/maps"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type PolicyAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *PolicyAction) Init() {
|
|
|
|
|
this.Nav("", "", "index")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *PolicyAction) RunGet(params struct {
|
|
|
|
|
FirewallPolicyId int64
|
|
|
|
|
}) {
|
|
|
|
|
firewallPolicy, err := models.SharedHTTPFirewallPolicyDAO.FindEnabledPolicyConfig(this.AdminContext(), params.FirewallPolicyId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if firewallPolicy == nil {
|
|
|
|
|
this.NotFound("firewallPolicy", params.FirewallPolicyId)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internalGroups := []maps.Map{}
|
|
|
|
|
if firewallPolicy.Inbound != nil {
|
|
|
|
|
for _, group := range firewallPolicy.Inbound.Groups {
|
|
|
|
|
internalGroups = append(internalGroups, maps.Map{
|
|
|
|
|
"name": group.Name,
|
|
|
|
|
"isOn": group.IsOn,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if firewallPolicy.Outbound != nil {
|
|
|
|
|
for _, group := range firewallPolicy.Outbound.Groups {
|
|
|
|
|
internalGroups = append(internalGroups, maps.Map{
|
|
|
|
|
"name": group.Name,
|
|
|
|
|
"isOn": group.IsOn,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Data["firewallPolicy"] = maps.Map{
|
2020-11-22 16:54:31 +08:00
|
|
|
"id": firewallPolicy.Id,
|
|
|
|
|
"name": firewallPolicy.Name,
|
|
|
|
|
"isOn": firewallPolicy.IsOn,
|
|
|
|
|
"description": firewallPolicy.Description,
|
|
|
|
|
"groups": internalGroups,
|
|
|
|
|
"blockOptions": firewallPolicy.BlockOptions,
|
2020-10-06 21:02:37 +08:00
|
|
|
}
|
|
|
|
|
|
2020-12-17 15:50:44 +08:00
|
|
|
// 正在使用此策略的集群
|
|
|
|
|
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithHTTPFirewallPolicyId(this.AdminContext(), &pb.FindAllEnabledNodeClustersWithHTTPFirewallPolicyIdRequest{HttpFirewallPolicyId: params.FirewallPolicyId})
|
2020-11-18 19:35:32 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-12-17 15:50:44 +08:00
|
|
|
clusterMaps := []maps.Map{}
|
|
|
|
|
for _, cluster := range clustersResp.NodeClusters {
|
|
|
|
|
clusterMaps = append(clusterMaps, maps.Map{
|
|
|
|
|
"id": cluster.Id,
|
|
|
|
|
"name": cluster.Name,
|
2020-11-18 19:35:32 +08:00
|
|
|
})
|
|
|
|
|
}
|
2020-12-17 15:50:44 +08:00
|
|
|
this.Data["clusters"] = clusterMaps
|
2020-11-18 19:35:32 +08:00
|
|
|
|
2020-10-06 21:02:37 +08:00
|
|
|
this.Show()
|
|
|
|
|
}
|