IP名单中可以通过IP查找访问日志

This commit is contained in:
刘祥超
2021-07-18 17:09:31 +08:00
parent 63884bc836
commit 7d8f3a9d9b
4 changed files with 85 additions and 16 deletions

View File

@@ -0,0 +1,51 @@
// 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"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type AccessLogsPopupAction struct {
actionutils.ParentAction
}
func (this *AccessLogsPopupAction) Init() {
this.Nav("", "", "")
}
func (this *AccessLogsPopupAction) RunGet(params struct {
ItemId int64
}) {
itemResp, err := this.RPC().IPItemRPC().FindEnabledIPItem(this.AdminContext(), &pb.FindEnabledIPItemRequest{IpItemId: params.ItemId})
if err != nil {
this.ErrorPage(err)
return
}
var item = itemResp.IpItem
if item == nil {
this.NotFound("ipItem", params.ItemId)
return
}
this.Data["ipFrom"] = item.IpFrom
this.Data["ipTo"] = item.IpTo
accessLogsResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Day: timeutil.Format("Ymd"),
Keyword: "ip:" + item.IpFrom + "," + item.IpTo,
Size: 10,
})
if err != nil {
this.ErrorPage(err)
return
}
var accessLogs = accessLogsResp.HttpAccessLogs
if len(accessLogs) == 0 {
accessLogs = []*pb.HTTPAccessLog{}
}
this.Data["accessLogs"] = accessLogs
this.Show()
}

View File

@@ -29,6 +29,7 @@ func init() {
GetPost("/createIPPopup", new(CreateIPPopupAction)). GetPost("/createIPPopup", new(CreateIPPopupAction)).
GetPost("/updateIPPopup", new(UpdateIPPopupAction)). GetPost("/updateIPPopup", new(UpdateIPPopupAction)).
Post("/deleteIP", new(DeleteIPAction)). Post("/deleteIP", new(DeleteIPAction)).
Get("/accessLogsPopup", new(AccessLogsPopupAction)).
// 防火墙 // 防火墙
GetPost("/bindHTTPFirewallPopup", new(BindHTTPFirewallPopupAction)). GetPost("/bindHTTPFirewallPopup", new(BindHTTPFirewallPopupAction)).

View File

@@ -1,19 +1,25 @@
Vue.component("ip-list-table", { Vue.component("ip-list-table", {
props: ["v-items"], props: ["v-items"],
data: function () { data: function () {
return { return {
items: this.vItems items: this.vItems
} }
}, },
methods: { methods: {
updateItem: function (itemId) { updateItem: function (itemId) {
this.$emit("update-item", itemId) this.$emit("update-item", itemId)
}, },
deleteItem: function (itemId) { deleteItem: function (itemId) {
this.$emit("delete-item", itemId) this.$emit("delete-item", itemId)
} },
}, viewLogs: function (itemId) {
template: `<div> teaweb.popup("/servers/iplists/accessLogsPopup?itemId=" + itemId, {
width: "50em",
height: "30em"
})
}
},
template: `<div>
<table class="ui table selectable celled" v-if="items.length > 0"> <table class="ui table selectable celled" v-if="items.length > 0">
<thead> <thead>
<tr> <tr>
@@ -22,7 +28,7 @@ Vue.component("ip-list-table", {
<th>级别</th> <th>级别</th>
<th>过期时间</th> <th>过期时间</th>
<th>备注</th> <th>备注</th>
<th class="two op">操作</th> <th class="three op">操作</th>
</tr> </tr>
</thead> </thead>
<tr v-for="item in items"> <tr v-for="item in items">
@@ -54,6 +60,7 @@ Vue.component("ip-list-table", {
<span v-else class="disabled">-</span> <span v-else class="disabled">-</span>
</td> </td>
<td> <td>
<a href="" @click.prevent="viewLogs(item.id)">日志</a> &nbsp;
<a href="" @click.prevent="updateItem(item.id)">修改</a> &nbsp; <a href="" @click.prevent="updateItem(item.id)">修改</a> &nbsp;
<a href="" @click.prevent="deleteItem(item.id)">删除</a> <a href="" @click.prevent="deleteItem(item.id)">删除</a>
</td> </td>

View File

@@ -0,0 +1,10 @@
{$layout "layout_popup"}
<h3>访问日志<span v-if="ipTo.length > 0" class="grey">{{ipFrom}} - {{ipTo}}</span><span v-else class="grey">{{ipFrom}}</span></h3>
<p class="comment" v-if="accessLogs.length == 0">暂时还没有访问日志。</p>
<table class="ui table selectable" v-if="accessLogs.length > 0">
<tr v-for="accessLog in accessLogs" :key="accessLog.requestId">
<td><http-access-log-box :v-access-log="accessLog"></http-access-log-box></td>
</tr>
</table>