diff --git a/internal/web/actions/default/servers/iplists/index.go b/internal/web/actions/default/servers/iplists/index.go
index e5096ca1..aa0d1464 100644
--- a/internal/web/actions/default/servers/iplists/index.go
+++ b/internal/web/actions/default/servers/iplists/index.go
@@ -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()
}
diff --git a/internal/web/actions/default/servers/iplists/init.go b/internal/web/actions/default/servers/iplists/init.go
index 6c7238a9..aa567d7b 100644
--- a/internal/web/actions/default/servers/iplists/init.go
+++ b/internal/web/actions/default/servers/iplists/init.go
@@ -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()
})
}
diff --git a/internal/web/actions/default/servers/iplists/lists.go b/internal/web/actions/default/servers/iplists/lists.go
new file mode 100644
index 00000000..4d3c5429
--- /dev/null
+++ b/internal/web/actions/default/servers/iplists/lists.go
@@ -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()
+}
diff --git a/web/public/js/components/iplist/ip-list-table.js b/web/public/js/components/iplist/ip-list-table.js
index b64f10bd..998200d1 100644
--- a/web/public/js/components/iplist/ip-list-table.js
+++ b/web/public/js/components/iplist/ip-list-table.js
@@ -38,7 +38,24 @@ Vue.component("ip-list-table", {
暂时还没有公用IP名单。
+ -| ID | -名称 | -类型 | -备注 | -IP数量 | -操作 | -
|---|---|---|---|---|---|
| {{list.id}} | -
- |
- - 黑名单 - 白名单 - | -{{list.description}} | -- {{list.countItems}} - 0 - | -- 详情 - 删除 - | -
暂时还没有IP。
+ +暂时还没有公用IP名单。
+ +| ID | +名称 | +类型 | +备注 | +IP数量 | +操作 | +
|---|---|---|---|---|---|
| {{list.id}} | +
+ |
+ + 黑名单 + 白名单 + | +{{list.description}} | ++ {{list.countItems}} + 0 + | ++ 详情 + 删除 + | +