2020-09-13 20:37:07 +08:00
|
|
|
package waf
|
|
|
|
|
|
|
|
|
|
import (
|
2020-10-06 21:02:37 +08:00
|
|
|
"encoding/json"
|
2020-09-13 20:37:07 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
2020-10-06 21:02:37 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
2020-09-13 20:37:07 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type IndexAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) Init() {
|
|
|
|
|
this.FirstMenu("index")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) RunGet(params struct{}) {
|
2020-12-17 15:50:44 +08:00
|
|
|
countResp, err := this.RPC().HTTPFirewallPolicyRPC().CountAllEnabledHTTPFirewallPolicies(this.AdminContext(), &pb.CountAllEnabledHTTPFirewallPoliciesRequest{})
|
2020-10-06 21:02:37 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
count := countResp.Count
|
|
|
|
|
page := this.NewPage(count)
|
|
|
|
|
|
2020-12-17 15:50:44 +08:00
|
|
|
listResp, err := this.RPC().HTTPFirewallPolicyRPC().ListEnabledHTTPFirewallPolicies(this.AdminContext(), &pb.ListEnabledHTTPFirewallPoliciesRequest{
|
2020-10-06 21:02:37 +08:00
|
|
|
Offset: page.Offset,
|
|
|
|
|
Size: page.Size,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
policyMaps := []maps.Map{}
|
2020-12-17 15:50:44 +08:00
|
|
|
for _, policy := range listResp.HttpFirewallPolicies {
|
2020-10-06 21:02:37 +08:00
|
|
|
countInbound := 0
|
|
|
|
|
countOutbound := 0
|
|
|
|
|
if len(policy.InboundJSON) > 0 {
|
|
|
|
|
inboundConfig := &firewallconfigs.HTTPFirewallInboundConfig{}
|
|
|
|
|
err = json.Unmarshal(policy.InboundJSON, inboundConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
countInbound = len(inboundConfig.GroupRefs)
|
|
|
|
|
}
|
|
|
|
|
if len(policy.OutboundJSON) > 0 {
|
|
|
|
|
outboundConfig := &firewallconfigs.HTTPFirewallInboundConfig{}
|
|
|
|
|
err = json.Unmarshal(policy.OutboundJSON, outboundConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
countOutbound = len(outboundConfig.GroupRefs)
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 15:50:44 +08:00
|
|
|
countClustersResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithHTTPFirewallPolicyId(this.AdminContext(), &pb.CountAllEnabledNodeClustersWithHTTPFirewallPolicyIdRequest{HttpFirewallPolicyId: policy.Id})
|
2020-10-06 21:02:37 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-12-17 15:50:44 +08:00
|
|
|
countClusters := countClustersResp.Count
|
2020-10-06 21:02:37 +08:00
|
|
|
|
|
|
|
|
policyMaps = append(policyMaps, maps.Map{
|
|
|
|
|
"id": policy.Id,
|
|
|
|
|
"isOn": policy.IsOn,
|
|
|
|
|
"name": policy.Name,
|
|
|
|
|
"countInbound": countInbound,
|
|
|
|
|
"countOutbound": countOutbound,
|
2020-12-17 15:50:44 +08:00
|
|
|
"countClusters": countClusters,
|
2020-10-06 21:02:37 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Data["policies"] = policyMaps
|
|
|
|
|
|
|
|
|
|
this.Data["page"] = page.AsHTML()
|
2020-09-13 20:37:07 +08:00
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
}
|