实现公用的IP名单

This commit is contained in:
刘祥超
2021-06-23 13:12:33 +08:00
parent c99547d9e3
commit 8e4ee54f03
88 changed files with 2060 additions and 69 deletions

View File

@@ -0,0 +1,58 @@
// 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
}) {
// 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()
}