增加全局查看、检索IP功能

This commit is contained in:
GoEdgeLab
2021-11-17 19:50:52 +08:00
parent 65c43e72e0
commit 347d36b8bd
10 changed files with 303 additions and 106 deletions

View File

@@ -5,8 +5,9 @@ package iplists
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ipconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type IndexAction struct {
@@ -18,60 +19,116 @@ func (this *IndexAction) Init() {
}
func (this *IndexAction) RunGet(params struct {
Type string
Keyword string
Ip string
}) {
if len(params.Type) == 0 {
params.Type = ipconfigs.IPListTypeBlack
}
this.Data["type"] = params.Type
this.Data["keyword"] = params.Keyword
this.Data["type"] = ""
this.Data["ip"] = params.Ip
countResp, err := this.RPC().IPListRPC().CountAllEnabledIPLists(this.AdminContext(), &pb.CountAllEnabledIPListsRequest{
Type: params.Type,
IsPublic: true,
Keyword: params.Keyword,
})
countResp, err := this.RPC().IPItemRPC().CountAllEnabledIPItems(this.AdminContext(), &pb.CountAllEnabledIPItemsRequest{Ip: params.Ip})
if err != nil {
this.ErrorPage(err)
return
}
count := countResp.Count
page := this.NewPage(count)
var count = countResp.Count
var page = this.NewPage(count)
this.Data["page"] = page.AsHTML()
listsResp, err := this.RPC().IPListRPC().ListEnabledIPLists(this.AdminContext(), &pb.ListEnabledIPListsRequest{
Type: params.Type,
IsPublic: true,
Keyword: params.Keyword,
Offset: page.Offset,
Size: page.Size,
itemsResp, err := this.RPC().IPItemRPC().ListAllEnabledIPItems(this.AdminContext(), &pb.ListAllEnabledIPItemsRequest{
Ip: params.Ip,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var listMaps = []maps.Map{}
for _, list := range listsResp.IpLists {
// 包含的IP数量
countItemsResp, err := this.RPC().IPItemRPC().CountIPItemsWithListId(this.AdminContext(), &pb.CountIPItemsWithListIdRequest{IpListId: list.Id})
if err != nil {
this.ErrorPage(err)
return
}
var countItems = countItemsResp.Count
listMaps = append(listMaps, maps.Map{
"id": list.Id,
"isOn": list.IsOn,
"name": list.Name,
"description": list.Description,
"countItems": countItems,
"type": list.Type,
"isGlobal": list.IsGlobal,
var itemMaps = []maps.Map{}
for _, result := range itemsResp.Results {
var item = result.IpItem
expiredTime := ""
if item.ExpiredAt > 0 {
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
}
// policy
var sourcePolicyMap = maps.Map{"id": 0}
if item.SourceHTTPFirewallPolicy != nil {
sourcePolicyMap = maps.Map{
"id": item.SourceHTTPFirewallPolicy.Id,
"name": item.SourceHTTPFirewallPolicy.Name,
"serverId": item.SourceHTTPFirewallPolicy.ServerId,
}
}
// group
var sourceGroupMap = maps.Map{"id": 0}
if item.SourceHTTPFirewallRuleGroup != nil {
sourceGroupMap = maps.Map{
"id": item.SourceHTTPFirewallRuleGroup.Id,
"name": item.SourceHTTPFirewallRuleGroup.Name,
}
}
// set
var sourceSetMap = maps.Map{"id": 0}
if item.SourceHTTPFirewallRuleSet != nil {
sourceSetMap = maps.Map{
"id": item.SourceHTTPFirewallRuleSet.Id,
"name": item.SourceHTTPFirewallRuleSet.Name,
}
}
// server
var sourceServerMap = maps.Map{"id": 0}
if item.SourceServer != nil {
sourceServerMap = maps.Map{
"id": item.SourceServer.Id,
"name": item.SourceServer.Name,
}
}
// IP名单
var listMap = maps.Map{"id": 0}
if result.IpList != nil {
listMap = maps.Map{
"id": result.IpList.Id,
"name": result.IpList.Name,
"type": result.IpList.Type,
}
}
// policy
var policyMap = maps.Map{"id": 0}
if result.HttpFirewallPolicy != nil {
policyMap = maps.Map{
"id": result.HttpFirewallPolicy.Id,
"name": result.HttpFirewallPolicy.Name,
}
if result.Server != nil {
policyMap["server"] = maps.Map{"id": result.Server.Id, "name": result.Server.Name}
}
}
itemMaps = append(itemMaps, maps.Map{
"id": item.Id,
"ipFrom": item.IpFrom,
"ipTo": item.IpTo,
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
"expiredTime": expiredTime,
"reason": item.Reason,
"type": item.Type,
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
"sourcePolicy": sourcePolicyMap,
"sourceGroup": sourceGroupMap,
"sourceSet": sourceSetMap,
"sourceServer": sourceServerMap,
"list": listMap,
"policy": policyMap,
})
}
this.Data["lists"] = listMaps
this.Data["items"] = itemMaps
this.Show()
}

View File

@@ -14,6 +14,7 @@ func init() {
Data("teaSubMenu", "iplist").
Prefix("/servers/iplists").
Get("", new(IndexAction)).
Get("/lists", new(ListsAction)).
GetPost("/createPopup", new(CreatePopupAction)).
Get("/list", new(ListAction)).
GetPost("/import", new(ImportAction)).
@@ -38,7 +39,6 @@ func init() {
// 选项数据
Post("/levelOptions", new(LevelOptionsAction)).
EndAll()
})
}

View File

@@ -0,0 +1,77 @@
// 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/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ipconfigs"
"github.com/iwind/TeaGo/maps"
)
type ListsAction struct {
actionutils.ParentAction
}
func (this *ListsAction) Init() {
this.Nav("", "", "lists")
}
func (this *ListsAction) RunGet(params struct {
Type string
Keyword string
}) {
if len(params.Type) == 0 {
params.Type = ipconfigs.IPListTypeBlack
}
this.Data["type"] = params.Type
this.Data["keyword"] = params.Keyword
countResp, err := this.RPC().IPListRPC().CountAllEnabledIPLists(this.AdminContext(), &pb.CountAllEnabledIPListsRequest{
Type: params.Type,
IsPublic: true,
Keyword: params.Keyword,
})
if err != nil {
this.ErrorPage(err)
return
}
count := countResp.Count
page := this.NewPage(count)
this.Data["page"] = page.AsHTML()
listsResp, err := this.RPC().IPListRPC().ListEnabledIPLists(this.AdminContext(), &pb.ListEnabledIPListsRequest{
Type: params.Type,
IsPublic: true,
Keyword: params.Keyword,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var listMaps = []maps.Map{}
for _, list := range listsResp.IpLists {
// 包含的IP数量
countItemsResp, err := this.RPC().IPItemRPC().CountIPItemsWithListId(this.AdminContext(), &pb.CountIPItemsWithListIdRequest{IpListId: list.Id})
if err != nil {
this.ErrorPage(err)
return
}
var countItems = countItemsResp.Count
listMaps = append(listMaps, maps.Map{
"id": list.Id,
"isOn": list.IsOn,
"name": list.Name,
"description": list.Description,
"countItems": countItems,
"type": list.Type,
"isGlobal": list.IsGlobal,
})
}
this.Data["lists"] = listMaps
this.Show()
}