mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package waf
|
|
|
|
import (
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
|
|
"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", "index")
|
|
this.SecondMenu("waf")
|
|
}
|
|
|
|
func (this *IndexAction) RunGet(params struct {
|
|
ServerId int64
|
|
}) {
|
|
webConfig, err := webutils.FindWebConfigWithServerId(this.Parent(), params.ServerId)
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
|
|
this.Data["webId"] = webConfig.Id
|
|
this.Data["firewallConfig"] = webConfig.FirewallRef
|
|
|
|
// 当前已有策略
|
|
policiesResp, err := this.RPC().HTTPFirewallPolicyRPC().FindAllEnabledHTTPFirewallPolicies(this.AdminContext(), &pb.FindAllEnabledHTTPFirewallPoliciesRequest{})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
policyMaps := []maps.Map{}
|
|
for _, p := range policiesResp.FirewallPolicies {
|
|
policyMaps = append(policyMaps, maps.Map{
|
|
"id": p.Id,
|
|
"name": p.Name,
|
|
"isOn": p.IsOn,
|
|
"description": p.Description,
|
|
})
|
|
}
|
|
this.Data["firewallPolicies"] = policyMaps
|
|
|
|
this.Show()
|
|
}
|
|
|
|
func (this *IndexAction) RunPost(params struct {
|
|
WebId int64
|
|
FirewallJSON []byte
|
|
|
|
Must *actions.Must
|
|
}) {
|
|
// TODO 检查配置
|
|
|
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebFirewall(this.AdminContext(), &pb.UpdateHTTPWebFirewallRequest{
|
|
WebId: params.WebId,
|
|
FirewallJSON: params.FirewallJSON,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
|
|
this.Success()
|
|
}
|