mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-03 10:20:25 +08:00
实现公用的IP名单
This commit is contained in:
59
internal/web/actions/default/servers/iplists/httpFirewall.go
Normal file
59
internal/web/actions/default/servers/iplists/httpFirewall.go
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package iplists
|
||||
|
||||
import (
|
||||
"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"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ipconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
// HttpFirewallAction 显示已经绑定的IP名单
|
||||
type HttpFirewallAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *HttpFirewallAction) RunPost(params struct {
|
||||
HttpFirewallPolicyId int64
|
||||
Type string
|
||||
}) {
|
||||
inboundConfig, err := dao.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicyInboundConfig(this.AdminContext(), params.HttpFirewallPolicyId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if inboundConfig == nil {
|
||||
inboundConfig = &firewallconfigs.HTTPFirewallInboundConfig{IsOn: true}
|
||||
}
|
||||
var refs []*ipconfigs.IPListRef
|
||||
switch params.Type {
|
||||
case ipconfigs.IPListTypeBlack:
|
||||
refs = inboundConfig.PublicDenyListRefs
|
||||
case ipconfigs.IPListTypeWhite:
|
||||
refs = inboundConfig.PublicAllowListRefs
|
||||
}
|
||||
|
||||
listMaps := []maps.Map{}
|
||||
for _, ref := range refs {
|
||||
listResp, err := this.RPC().IPListRPC().FindEnabledIPList(this.AdminContext(), &pb.FindEnabledIPListRequest{IpListId: ref.ListId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var list = listResp.IpList
|
||||
if list == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
listMaps = append(listMaps, maps.Map{
|
||||
"id": list.Id,
|
||||
"name": list.Name,
|
||||
})
|
||||
}
|
||||
this.Data["lists"] = listMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user