[日志审计]区分用户操作日志和管理员操作日志

This commit is contained in:
GoEdgeLab
2020-12-23 10:42:41 +08:00
parent f0709b5d14
commit 834008448c
4 changed files with 41 additions and 22 deletions

View File

@@ -23,6 +23,7 @@ func (this *ExportExcelAction) RunGet(params struct {
DayFrom string
DayTo string
Keyword string
UserType string
}) {
logsResp, err := this.RPC().LogRPC().ListLogs(this.AdminContext(), &pb.ListLogsRequest{
Offset: 0,
@@ -30,6 +31,7 @@ func (this *ExportExcelAction) RunGet(params struct {
DayFrom: params.DayFrom,
DayTo: params.DayTo,
Keyword: params.Keyword,
UserType: params.UserType,
})
if err != nil {
this.ErrorPage(err)
@@ -88,7 +90,11 @@ func (this *ExportExcelAction) RunGet(params struct {
row.SetHeight(25)
row.AddCell().SetInt64(log.Id)
row.AddCell().SetString(timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt))
if log.UserId > 0 {
row.AddCell().SetString("用户 | " + log.UserName)
} else {
row.AddCell().SetString(log.UserName)
}
row.AddCell().SetString(log.Description)
row.AddCell().SetString(log.Ip)
row.AddCell().SetString(regionName)

View File

@@ -22,6 +22,7 @@ func (this *IndexAction) RunGet(params struct {
DayFrom string
DayTo string
Keyword string
UserType string
}) {
// 读取配置
config, err := configloaders.LoadLogConfig()
@@ -34,11 +35,13 @@ func (this *IndexAction) RunGet(params struct {
this.Data["dayFrom"] = params.DayFrom
this.Data["dayTo"] = params.DayTo
this.Data["keyword"] = params.Keyword
this.Data["userType"] = params.UserType
countResp, err := this.RPC().LogRPC().CountLogs(this.AdminContext(), &pb.CountLogRequest{
DayFrom: params.DayFrom,
DayTo: params.DayTo,
Keyword: params.Keyword,
UserType: params.UserType,
})
if err != nil {
this.ErrorPage(err)
@@ -54,6 +57,7 @@ func (this *IndexAction) RunGet(params struct {
DayFrom: params.DayFrom,
DayTo: params.DayTo,
Keyword: params.Keyword,
UserType: params.UserType,
})
if err != nil {
this.ErrorPage(err)
@@ -86,6 +90,8 @@ func (this *IndexAction) RunGet(params struct {
logMaps = append(logMaps, maps.Map{
"id": log.Id,
"adminId": log.AdminId,
"userId": log.UserId,
"description": log.Description,
"userName": log.UserName,
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),

View File

@@ -23,6 +23,13 @@
<div class="ui field">
<input type="text" name="keyword" style="width:10em" v-model="keyword" placeholder="关键词"/>
</div>
<div class="ui field">
<select class="ui dropdown auto-width" name="userType" v-model="userType">
<option value="">[用户类型]</option>
<option value="admin">管理员</option>
<option value="user">用户</option>
</select>
</div>
<div class="ui field">
<button type="submit" class="ui button">查询</button>
</div>
@@ -43,7 +50,7 @@
<table class="ui table selectable" v-for="log in logs">
<tr :class="{error: log.level == 'error', warning: log.level == 'warn'}">
<td class="log-row">{{log.createdTime}} <span class="grey"> <span
v-if="log.userName.length > 0">| {{log.userName}}</span> | {{log.ip}}<span
v-if="log.userName.length > 0">| <span v-if="log.userId>0">用户 &nbsp;|&nbsp;</span> {{log.userName}}</span> | {{log.ip}}<span
v-if="log.region.length > 0"> | {{log.region}}</span> &nbsp; <a href="" @click.prevent="showMore(log)" title="显示更多">...</a> &nbsp;<span v-if="log.moreVisible">{{log.action}}</span></span>
<span class="buttons"><a v-if="logConfig.canDelete" href="" title="删除" @click.prevent="deleteLog(log.id)"><i class="icon remove small"></i></a> </span>
</td>

View File

@@ -15,7 +15,7 @@ Tea.context(function () {
this.exportExcel = function () {
let that = this
teaweb.confirm("确定要将当前列表导出到Excel吗", function () {
window.location = "/log/exportExcel?dayFrom=" + that.dayFrom + "&dayTo=" + that.dayTo + "&keyword=" + that.keyword
window.location = "/log/exportExcel?dayFrom=" + that.dayFrom + "&dayTo=" + that.dayTo + "&keyword=" + that.keyword + "&userType=" + that.userType
})
}