在网站WAF中,可以导出和导入规则集代码,优化修改规则集交互

This commit is contained in:
GoEdgeLab
2024-05-06 20:25:36 +08:00
parent a573eb5608
commit 5fb2990735
11 changed files with 293 additions and 98 deletions

View File

@@ -0,0 +1,57 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package waf
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
)
type SetCodePopupAction struct {
actionutils.ParentAction
}
func (this *SetCodePopupAction) Init() {
this.Nav("", "", "")
}
func (this *SetCodePopupAction) RunGet(params struct {
SetId int64
}) {
setResp, err := this.RPC().HTTPFirewallRuleSetRPC().FindEnabledHTTPFirewallRuleSetConfig(this.AdminContext(), &pb.FindEnabledHTTPFirewallRuleSetConfigRequest{FirewallRuleSetId: params.SetId})
if err != nil {
this.ErrorPage(err)
return
}
if len(setResp.FirewallRuleSetJSON) == 0 {
this.NotFound("httpFirewallRuleSet", params.SetId)
return
}
var ruleSet = &firewallconfigs.HTTPFirewallRuleSet{}
err = json.Unmarshal(setResp.FirewallRuleSetJSON, ruleSet)
if err != nil {
this.ErrorPage(err)
return
}
ruleSet.RuleRefs = nil
ruleSet.Id = 0
for _, rule := range ruleSet.Rules {
rule.Id = 0
}
this.Data["setName"] = ruleSet.Name
codeJSON, err := json.MarshalIndent(ruleSet, "", " ")
if err != nil {
this.ErrorPage(err)
return
}
this.Data["code"] = string(codeJSON)
this.Show()
}