mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 12:20:28 +08:00
IP名单增加未读数、按未读筛选等操作
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ListsAction struct {
|
||||
@@ -109,6 +110,7 @@ func (this *ListsAction) RunGet(params struct {
|
||||
"sourceGroup": sourceGroupMap,
|
||||
"sourceSet": sourceSetMap,
|
||||
"sourceServer": sourceServerMap,
|
||||
"lifeSeconds": item.ExpiredAt - time.Now().Unix(),
|
||||
})
|
||||
}
|
||||
this.Data["items"] = itemMaps
|
||||
|
||||
@@ -113,6 +113,7 @@ func (this *AllowListAction) RunGet(params struct {
|
||||
"ipTo": item.IpTo,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
|
||||
"expiredTime": expiredTime,
|
||||
"lifeSeconds": item.ExpiredAt - time.Now().Unix(),
|
||||
"reason": item.Reason,
|
||||
"type": item.Type,
|
||||
"isExpired": item.ExpiredAt > 0 && item.ExpiredAt < time.Now().Unix(),
|
||||
|
||||
@@ -113,6 +113,7 @@ func (this *DenyListAction) RunGet(params struct {
|
||||
"ipTo": item.IpTo,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
|
||||
"expiredTime": expiredTime,
|
||||
"lifeSeconds": item.ExpiredAt - time.Now().Unix(),
|
||||
"reason": item.Reason,
|
||||
"type": item.Type,
|
||||
"isExpired": item.ExpiredAt > 0 && item.ExpiredAt < time.Now().Unix(),
|
||||
|
||||
@@ -22,14 +22,28 @@ func (this *IndexAction) Init() {
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
Ip string
|
||||
GlobalOnly bool
|
||||
Unread bool
|
||||
}) {
|
||||
this.Data["type"] = ""
|
||||
this.Data["ip"] = params.Ip
|
||||
this.Data["globalOnly"] = params.GlobalOnly
|
||||
this.Data["unread"] = params.Unread
|
||||
|
||||
countUnreadResp, err := this.RPC().IPItemRPC().CountAllEnabledIPItems(this.AdminContext(), &pb.CountAllEnabledIPItemsRequest{
|
||||
Ip: params.Ip,
|
||||
GlobalOnly: params.GlobalOnly,
|
||||
Unread: true,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["countUnread"] = countUnreadResp.Count
|
||||
|
||||
countResp, err := this.RPC().IPItemRPC().CountAllEnabledIPItems(this.AdminContext(), &pb.CountAllEnabledIPItemsRequest{
|
||||
Ip: params.Ip,
|
||||
GlobalOnly: params.GlobalOnly,
|
||||
Unread: params.Unread,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
@@ -42,6 +56,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
itemsResp, err := this.RPC().IPItemRPC().ListAllEnabledIPItems(this.AdminContext(), &pb.ListAllEnabledIPItemsRequest{
|
||||
Ip: params.Ip,
|
||||
GlobalOnly: params.GlobalOnly,
|
||||
Unread: params.Unread,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
@@ -127,6 +142,8 @@ func (this *IndexAction) RunGet(params struct {
|
||||
"expiredTime": expiredTime,
|
||||
"reason": item.Reason,
|
||||
"type": item.Type,
|
||||
"isRead": item.IsRead,
|
||||
"lifeSeconds": item.ExpiredAt - time.Now().Unix(),
|
||||
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
||||
"sourcePolicy": sourcePolicyMap,
|
||||
"sourceGroup": sourceGroupMap,
|
||||
|
||||
@@ -32,6 +32,7 @@ func init() {
|
||||
GetPost("/updateIPPopup", new(UpdateIPPopupAction)).
|
||||
Post("/deleteIP", new(DeleteIPAction)).
|
||||
Get("/accessLogsPopup", new(AccessLogsPopupAction)).
|
||||
Post("/readAll", new(ReadAllAction)).
|
||||
|
||||
// 防火墙
|
||||
GetPost("/bindHTTPFirewallPopup", new(BindHTTPFirewallPopupAction)).
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ItemsAction struct {
|
||||
@@ -112,6 +113,7 @@ func (this *ItemsAction) RunGet(params struct {
|
||||
"sourceGroup": sourceGroupMap,
|
||||
"sourceSet": sourceSetMap,
|
||||
"sourceServer": sourceServerMap,
|
||||
"lifeSeconds": item.ExpiredAt - time.Now().Unix(),
|
||||
})
|
||||
}
|
||||
this.Data["items"] = itemMaps
|
||||
|
||||
24
internal/web/actions/default/servers/iplists/readAll.go
Normal file
24
internal/web/actions/default/servers/iplists/readAll.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright 2022 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"
|
||||
)
|
||||
|
||||
type ReadAllAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ReadAllAction) RunPost(params struct{}) {
|
||||
defer this.CreateLogInfo("将IP名单置为已读")
|
||||
|
||||
_, err := this.RPC().IPItemRPC().UpdateIPItemsRead(this.AdminContext(), &pb.UpdateIPItemsReadRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -113,6 +113,7 @@ func (this *AllowListAction) RunGet(params struct {
|
||||
"ipTo": item.IpTo,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
|
||||
"expiredTime": expiredTime,
|
||||
"lifeSeconds": item.ExpiredAt - time.Now().Unix(),
|
||||
"reason": item.Reason,
|
||||
"type": item.Type,
|
||||
"isExpired": item.ExpiredAt > 0 && item.ExpiredAt < time.Now().Unix(),
|
||||
|
||||
@@ -113,6 +113,7 @@ func (this *DenyListAction) RunGet(params struct {
|
||||
"ipTo": item.IpTo,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
|
||||
"expiredTime": expiredTime,
|
||||
"lifeSeconds": item.ExpiredAt - time.Now().Unix(),
|
||||
"reason": item.Reason,
|
||||
"type": item.Type,
|
||||
"isExpired": item.ExpiredAt > 0 && item.ExpiredAt < time.Now().Unix(),
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
func FindAllMenuMaps(nodeLogsType string, countUnreadNodeLogs int64) []maps.Map {
|
||||
func FindAllMenuMaps(nodeLogsType string, countUnreadNodeLogs int64, countUnreadIPItems int64) []maps.Map {
|
||||
return []maps.Map{
|
||||
{
|
||||
"code": "dashboard",
|
||||
@@ -50,9 +50,10 @@ func FindAllMenuMaps(nodeLogsType string, countUnreadNodeLogs int64) []maps.Map
|
||||
"code": "waf",
|
||||
},
|
||||
{
|
||||
"name": "IP名单",
|
||||
"url": "/servers/iplists",
|
||||
"code": "iplist",
|
||||
"name": "IP名单",
|
||||
"url": "/servers/iplists",
|
||||
"code": "iplist",
|
||||
"badge": countUnreadIPItems,
|
||||
},
|
||||
{
|
||||
"name": "统计指标",
|
||||
|
||||
@@ -171,16 +171,21 @@ func (this *userMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramNam
|
||||
|
||||
// 菜单配置
|
||||
func (this *userMustAuth) modules(actionPtr actions.ActionWrapper, adminId int64) []maps.Map {
|
||||
// 运行日志
|
||||
var countUnreadNodeLogs int64 = 0
|
||||
var nodeLogsType = ""
|
||||
|
||||
// IP名单
|
||||
var countUnreadIPItems int64 = 0
|
||||
|
||||
// 父级动作
|
||||
parentAction, ok := actionPtr.(actionutils.ActionInterface)
|
||||
if ok {
|
||||
var action = actionPtr.Object()
|
||||
|
||||
// 未读日志数
|
||||
if action.Data.GetString("teaMenu") == "clusters" {
|
||||
var mainMenu = action.Data.GetString("teaMenu")
|
||||
if mainMenu == "clusters" {
|
||||
countNodeLogsResp, err := parentAction.RPC().NodeLogRPC().CountNodeLogs(parentAction.AdminContext(), &pb.CountNodeLogsRequest{
|
||||
Role: nodeconfigs.NodeRoleNode,
|
||||
IsUnread: true,
|
||||
@@ -197,11 +202,18 @@ func (this *userMustAuth) modules(actionPtr actions.ActionWrapper, adminId int64
|
||||
nodeLogsType = "unread"
|
||||
}
|
||||
}
|
||||
} else if mainMenu == "servers" {
|
||||
countUnreadIPItemsResp, err := parentAction.RPC().IPItemRPC().CountAllEnabledIPItems(parentAction.AdminContext(), &pb.CountAllEnabledIPItemsRequest{Unread: true})
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
} else {
|
||||
countUnreadIPItems = countUnreadIPItemsResp.Count
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result := []maps.Map{}
|
||||
for _, m := range FindAllMenuMaps(nodeLogsType, countUnreadNodeLogs) {
|
||||
for _, m := range FindAllMenuMaps(nodeLogsType, countUnreadNodeLogs, countUnreadIPItems) {
|
||||
if m.GetString("code") == "finance" && !configloaders.ShowFinance() {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -70,6 +70,18 @@ Vue.component("ip-list-table", {
|
||||
.success(function () {
|
||||
teaweb.successToast("批量删除成功", 1200, teaweb.reload)
|
||||
})
|
||||
},
|
||||
formatSeconds: function (seconds) {
|
||||
if (seconds < 60) {
|
||||
return seconds + "秒"
|
||||
}
|
||||
if (seconds < 3600) {
|
||||
return Math.ceil(seconds / 60) + "分钟"
|
||||
}
|
||||
if (seconds < 86400) {
|
||||
return Math.ceil(seconds / 3600) + "小时"
|
||||
}
|
||||
return Math.ceil(seconds / 86400) + "天"
|
||||
}
|
||||
},
|
||||
template: `<div>
|
||||
@@ -103,7 +115,7 @@ Vue.component("ip-list-table", {
|
||||
</td>
|
||||
<td>
|
||||
<span v-if="item.type != 'all'">
|
||||
<keyword :v-word="keyword">{{item.ipFrom}}</keyword> <span> <a :href="'/servers/iplists?ip=' + item.ipFrom" v-if="vShowSearchButton" title="搜索此IP"><span><i class="icon search small" style="color: #ccc"></i></span></a></span>
|
||||
<keyword :v-word="keyword">{{item.ipFrom}}</keyword> <span> <span class="small red" v-if="item.isRead != null && !item.isRead"> New </span> <a :href="'/servers/iplists?ip=' + item.ipFrom" v-if="vShowSearchButton" title="搜索此IP"><span><i class="icon search small" style="color: #ccc"></i></span></a></span>
|
||||
<span v-if="item.ipTo.length > 0"> - <keyword :v-word="keyword">{{item.ipTo}}</keyword></span></span>
|
||||
<span v-else class="disabled">*</span>
|
||||
<div v-if="item.createdTime != null">
|
||||
@@ -143,6 +155,9 @@ Vue.component("ip-list-table", {
|
||||
<div v-if="item.isExpired" style="margin-top: 0.5em">
|
||||
<span class="ui label tiny basic red">已过期</span>
|
||||
</div>
|
||||
<div v-if="item.lifeSeconds != null && item.lifeSeconds > 0">
|
||||
<span class="small grey">{{formatSeconds(item.lifeSeconds)}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<span v-else class="disabled">不过期</span>
|
||||
</td>
|
||||
|
||||
@@ -13,10 +13,22 @@
|
||||
<label>自动拦截名单</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui field" v-if="countUnread > 0">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="unread" value="1" v-model="unread"/>
|
||||
<label><span class="red">New</span></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<button class="ui button" type="submit">搜索</button>
|
||||
|
||||
<a href="/servers/iplists" v-if="ip.length > 0 || globalOnly">[清除条件]</a>
|
||||
<a href="/servers/iplists" v-if="ip.length > 0 || globalOnly || unread">[清除条件]</a>
|
||||
</div>
|
||||
<div class="ui field" v-if="countUnread > 0">
|
||||
<span class="disabled">|</span>
|
||||
</div>
|
||||
<div class="ui field" v-if="countUnread > 0">
|
||||
<a href="" @click.prevent="readAllItems" title="消除未读标记New">[全部已读]</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -20,4 +20,11 @@ Tea.context(function () {
|
||||
.refresh()
|
||||
})
|
||||
}
|
||||
|
||||
this.readAllItems = function () {
|
||||
this.$post(".readAll")
|
||||
.success(function () {
|
||||
teaweb.reload()
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user