Files
EdgeAdmin/internal/web/actions/default/servers/components/waf/groups.go

75 lines
1.7 KiB
Go
Raw Normal View History

2020-10-06 21:02:37 +08:00
package waf
2020-10-07 11:18:07 +08:00
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2020-12-23 09:52:31 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
2020-10-07 11:18:07 +08:00
"github.com/iwind/TeaGo/maps"
)
2020-10-06 21:02:37 +08:00
type GroupsAction struct {
actionutils.ParentAction
}
func (this *GroupsAction) Init() {
2020-10-07 11:18:07 +08:00
this.Nav("", "", this.ParamString("type"))
2020-10-06 21:02:37 +08:00
}
2020-10-07 11:18:07 +08:00
func (this *GroupsAction) RunGet(params struct {
FirewallPolicyId int64
Type string
}) {
this.Data["type"] = params.Type
2020-12-23 09:52:31 +08:00
firewallPolicy, err := dao.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicyConfig(this.AdminContext(), params.FirewallPolicyId)
2020-10-07 11:18:07 +08:00
if err != nil {
this.ErrorPage(err)
return
}
if firewallPolicy == nil {
this.NotFound("firewallPolicy", params.FirewallPolicyId)
return
}
groupMaps := []maps.Map{}
// inbound
if params.Type == "inbound" {
if firewallPolicy.Inbound != nil {
for _, g := range firewallPolicy.Inbound.Groups {
groupMaps = append(groupMaps, maps.Map{
"id": g.Id,
"name": g.Name,
"code": g.Code,
"isOn": g.IsOn,
"description": g.Description,
"countSets": len(g.Sets),
"isTemplate": g.IsTemplate,
"canDelete": !g.IsTemplate,
2020-10-07 11:18:07 +08:00
})
}
}
}
// outbound
if params.Type == "outbound" {
if firewallPolicy.Outbound != nil {
for _, g := range firewallPolicy.Outbound.Groups {
groupMaps = append(groupMaps, maps.Map{
"id": g.Id,
"name": g.Name,
"code": g.Code,
"isOn": g.IsOn,
"description": g.Description,
"countSets": len(g.Sets),
"isTemplate": g.IsTemplate,
"canDelete": !g.IsTemplate,
2020-10-07 11:18:07 +08:00
})
}
}
}
this.Data["groups"] = groupMaps
2020-10-06 21:02:37 +08:00
this.Show()
}