mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-28 06:40:33 +08:00
实现公用的IP名单
This commit is contained in:
@@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user