mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-04 05:00:25 +08:00
76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
package waf
|
|
|
|
import (
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/models"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"github.com/iwind/TeaGo/actions"
|
|
"github.com/iwind/TeaGo/maps"
|
|
)
|
|
|
|
type IndexAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *IndexAction) Init() {
|
|
this.Nav("", "setting", "")
|
|
this.SecondMenu("waf")
|
|
}
|
|
|
|
func (this *IndexAction) RunGet(params struct {
|
|
ClusterId int64
|
|
}) {
|
|
cluster, err := models.SharedNodeClusterDAO.FindEnabledNodeCluster(this.AdminContext(), params.ClusterId)
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
if cluster == nil {
|
|
this.NotFound("nodeCluster", params.ClusterId)
|
|
return
|
|
}
|
|
|
|
// WAF设置
|
|
this.Data["firewallPolicy"] = nil
|
|
if cluster.HttpFirewallPolicyId > 0 {
|
|
firewallPolicy, err := models.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicy(this.AdminContext(), cluster.HttpFirewallPolicyId)
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
if firewallPolicy != nil {
|
|
this.Data["firewallPolicy"] = maps.Map{
|
|
"id": firewallPolicy.Id,
|
|
"name": firewallPolicy.Name,
|
|
"isOn": firewallPolicy.IsOn,
|
|
}
|
|
}
|
|
}
|
|
|
|
this.Show()
|
|
}
|
|
|
|
func (this *IndexAction) RunPost(params struct {
|
|
ClusterId int64
|
|
HttpFirewallPolicyId int64
|
|
|
|
Must *actions.Must
|
|
CSRF *actionutils.CSRF
|
|
}) {
|
|
defer this.CreateLogInfo("设置集群 %d 的WAF策略为 %d", params.ClusterId, params.HttpFirewallPolicyId)
|
|
|
|
if params.HttpFirewallPolicyId <= 0 {
|
|
this.Fail("请选择WAF策略")
|
|
}
|
|
|
|
_, err := this.RPC().NodeClusterRPC().UpdateNodeClusterHTTPFirewallPolicyId(this.AdminContext(), &pb.UpdateNodeClusterHTTPFirewallPolicyIdRequest{
|
|
NodeClusterId: params.ClusterId,
|
|
HttpFirewallPolicyId: params.HttpFirewallPolicyId,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
this.Success()
|
|
}
|