Files
EdgeAdmin/internal/web/actions/default/servers/iplists/unbindHTTPFirewall.go

61 lines
1.7 KiB
Go
Raw Normal View History

2021-06-23 13:12:33 +08:00
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package iplists
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
)
type UnbindHTTPFirewallAction struct {
actionutils.ParentAction
}
func (this *UnbindHTTPFirewallAction) RunPost(params struct {
HttpFirewallPolicyId int64
ListId int64
}) {
2021-06-27 21:59:06 +08:00
defer this.CreateLogInfo("接触绑定IP名单 %d WAF策略 %d", params.ListId, params.HttpFirewallPolicyId)
2021-06-23 13:12:33 +08:00
// List类型
listResp, err := this.RPC().IPListRPC().FindEnabledIPList(this.AdminContext(), &pb.FindEnabledIPListRequest{IpListId: params.ListId})
if err != nil {
this.ErrorPage(err)
return
}
var list = listResp.IpList
if list == nil {
this.Fail("找不到要使用的IP名单")
}
// 已经绑定的
inboundConfig, err := dao.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicyInboundConfig(this.AdminContext(), params.HttpFirewallPolicyId)
if err != nil {
this.ErrorPage(err)
return
}
if inboundConfig == nil {
inboundConfig = &firewallconfigs.HTTPFirewallInboundConfig{IsOn: true}
}
inboundConfig.RemovePublicList(list.Id, list.Type)
inboundJSON, err := json.Marshal(inboundConfig)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPFirewallPolicyRPC().UpdateHTTPFirewallInboundConfig(this.AdminContext(), &pb.UpdateHTTPFirewallInboundConfigRequest{
HttpFirewallPolicyId: params.HttpFirewallPolicyId,
InboundJSON: inboundJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}