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/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", "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 // 获取当前服务所在集群的WAF设置 firewallPolicy, err := models.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicyWithServerId(this.AdminContext(), params.ServerId) if err != nil { this.ErrorPage(err) return } if firewallPolicy != nil { this.Data["firewallPolicy"] = maps.Map{ "id": firewallPolicy.Id, "name": firewallPolicy.Name, "isOn": firewallPolicy.IsOn, } } else { this.Data["firewallPolicy"] = nil } this.Show() } func (this *IndexAction) RunPost(params struct { WebId int64 FirewallJSON []byte Must *actions.Must }) { defer this.CreateLogInfo("修改Web %d 的WAF设置", params.WebId) // 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() }