-
Notifications
You must be signed in to change notification settings - Fork 4
/
setCodePopup.go
57 lines (46 loc) · 1.31 KB
/
setCodePopup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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()
}