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", { {{item.ipFrom}} - {{item.ipTo}} *
- 添加于 {{item.createdTime}} + 添加于 {{item.createdTime}} + + @ + + [名单:{{item.list.name}}] + [名单:{{item.list.name}} + + + + [服务:{{item.policy.server.name}}] + [服务:{{item.policy.server.name}}] + + + [策略:{{item.policy.name}}] + + + +
@@ -65,11 +82,11 @@ Vue.component("ip-list-table", { -
- {{item.sourceServer.name}} + {{item.sourceServer.name}}
- {{item.sourcePolicy.name}} » {{item.sourceGroup.name}} » {{item.sourceSet.name}} - {{item.sourcePolicy.name}} » {{item.sourceGroup.name}} » {{item.sourceSet.name}} + {{item.sourcePolicy.name}} » {{item.sourceGroup.name}} » {{item.sourceSet.name}} + {{item.sourcePolicy.name}} » {{item.sourceGroup.name}} » {{item.sourceSet.name}}
diff --git a/web/views/@default/servers/iplists/@list_menu.html b/web/views/@default/servers/iplists/@list_menu.html index b20d33a8..ca7f059f 100644 --- a/web/views/@default/servers/iplists/@list_menu.html +++ b/web/views/@default/servers/iplists/@list_menu.html @@ -1,5 +1,5 @@ - {{list.typeName}} + {{list.typeName}} | "{{list.name}}"详情 IP({{list.countItems}}) diff --git a/web/views/@default/servers/iplists/@menu.html b/web/views/@default/servers/iplists/@menu.html index d40f58eb..06c6705b 100644 --- a/web/views/@default/servers/iplists/@menu.html +++ b/web/views/@default/servers/iplists/@menu.html @@ -1,8 +1,9 @@ - 黑名单 - 白名单 - | - [创建] - | - + 所有IP + 公共黑名单 + 公共白名单 + | + [创建] + | + \ No newline at end of file diff --git a/web/views/@default/servers/iplists/index.html b/web/views/@default/servers/iplists/index.html index c2fa0e5b..4e37a6ec 100644 --- a/web/views/@default/servers/iplists/index.html +++ b/web/views/@default/servers/iplists/index.html @@ -1,56 +1,22 @@ {$layout} {$template "menu"} -这里是公用的IP名单,可以在WAF策略里直接引用。 -
-
- +
- +
- -   - [清除条件] +
-

暂时还没有公用IP名单。

+
- - - - - - - - - - - - - - - - - - - -
ID名称类型备注IP数量操作
{{list.id}} - {{list.name}} -
全局
-
- 黑名单 - 白名单 - {{list.description}} - {{list.countItems}} - 0 - - 详情   - 删除 -
+

暂时还没有IP。

+ +
\ No newline at end of file diff --git a/web/views/@default/servers/iplists/index.js b/web/views/@default/servers/iplists/index.js index cbd6c0f0..9f14a3d0 100644 --- a/web/views/@default/servers/iplists/index.js +++ b/web/views/@default/servers/iplists/index.js @@ -1,27 +1,23 @@ Tea.context(function () { - this.createList = function () { - teaweb.popup(Tea.url(".createPopup", {type: this.type}), { - height: "24em", - callback: function (resp) { + this.updateItem = function (itemId) { + teaweb.popup(Tea.url(".updateIPPopup", {itemId: itemId}), { + height: "26em", + callback: function () { teaweb.success("保存成功", function () { - window.location = "/servers/iplists?type=" + resp.data.list.type + teaweb.reload() }) } }) } - this.deleteList = function (listId) { + this.deleteItem = function (itemId) { let that = this - teaweb.confirm("确定要删除此IP名单吗?", function () { - that.$post(".delete") + teaweb.confirm("确定要删除这个IP吗?", function () { + that.$post(".deleteIP") .params({ - listId: listId - }) - .success(function () { - teaweb.success("删除成功", function () { - teaweb.reload() - }) + "itemId": itemId }) + .refresh() }) } }) \ No newline at end of file diff --git a/web/views/@default/servers/iplists/lists.html b/web/views/@default/servers/iplists/lists.html new file mode 100644 index 00000000..c2fa0e5b --- /dev/null +++ b/web/views/@default/servers/iplists/lists.html @@ -0,0 +1,56 @@ +{$layout} +{$template "menu"} + +这里是公用的IP名单,可以在WAF策略里直接引用。 + +
+
+ +
+
+ +
+
+ +   + [清除条件] +
+
+
+ +

暂时还没有公用IP名单。

+ + + + + + + + + + + + + + + + + + + + +
ID名称类型备注IP数量操作
{{list.id}} + {{list.name}} +
全局
+
+ 黑名单 + 白名单 + {{list.description}} + {{list.countItems}} + 0 + + 详情   + 删除 +
+ +
\ No newline at end of file diff --git a/web/views/@default/servers/iplists/lists.js b/web/views/@default/servers/iplists/lists.js new file mode 100644 index 00000000..b79f2613 --- /dev/null +++ b/web/views/@default/servers/iplists/lists.js @@ -0,0 +1,27 @@ +Tea.context(function () { + this.createList = function () { + teaweb.popup(Tea.url(".createPopup", {type: this.type}), { + height: "24em", + callback: function (resp) { + teaweb.success("保存成功", function () { + window.location = "/servers/iplists/lists?type=" + resp.data.list.type + }) + } + }) + } + + this.deleteList = function (listId) { + let that = this + teaweb.confirm("确定要删除此IP名单吗?", function () { + that.$post(".delete") + .params({ + listId: listId + }) + .success(function () { + teaweb.success("删除成功", function () { + teaweb.reload() + }) + }) + }) + } +}) \ No newline at end of file