2020-09-13 20:37:07 +08:00
|
|
|
package log
|
|
|
|
|
|
2020-11-10 20:30:47 +08:00
|
|
|
import (
|
2020-12-02 20:31:42 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
2020-11-10 20:30:47 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
2023-08-24 12:22:16 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
|
2023-06-28 19:07:42 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
2020-11-10 20:30:47 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
|
|
|
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
|
|
|
|
)
|
2020-09-13 20:37:07 +08:00
|
|
|
|
|
|
|
|
type IndexAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) Init() {
|
2020-12-02 20:31:42 +08:00
|
|
|
this.Nav("log", "log", "list")
|
2020-09-13 20:37:07 +08:00
|
|
|
}
|
|
|
|
|
|
2020-11-20 16:36:03 +08:00
|
|
|
func (this *IndexAction) RunGet(params struct {
|
2020-12-23 10:42:41 +08:00
|
|
|
DayFrom string
|
|
|
|
|
DayTo string
|
|
|
|
|
Keyword string
|
|
|
|
|
UserType string
|
2023-04-06 10:06:22 +08:00
|
|
|
Level string
|
2020-11-20 16:36:03 +08:00
|
|
|
}) {
|
2020-12-02 20:31:42 +08:00
|
|
|
// 读取配置
|
|
|
|
|
config, err := configloaders.LoadLogConfig()
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.Data["logConfig"] = config
|
|
|
|
|
|
2020-11-20 16:36:03 +08:00
|
|
|
this.Data["dayFrom"] = params.DayFrom
|
|
|
|
|
this.Data["dayTo"] = params.DayTo
|
|
|
|
|
this.Data["keyword"] = params.Keyword
|
2020-12-23 10:42:41 +08:00
|
|
|
this.Data["userType"] = params.UserType
|
2020-11-20 16:36:03 +08:00
|
|
|
|
2023-04-06 10:06:22 +08:00
|
|
|
// 级别
|
|
|
|
|
this.Data["level"] = params.Level
|
|
|
|
|
this.Data["levelOptions"] = []maps.Map{
|
|
|
|
|
{
|
|
|
|
|
"code": "info",
|
2023-06-30 18:08:30 +08:00
|
|
|
"name": this.Lang(codes.Level_Info),
|
2023-04-06 10:06:22 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"code": "warn",
|
2023-06-30 18:08:30 +08:00
|
|
|
"name": this.Lang(codes.Level_Warn),
|
2023-04-06 10:06:22 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"code": "error",
|
2023-06-30 18:08:30 +08:00
|
|
|
"name": this.Lang(codes.Level_Error),
|
2023-04-06 10:06:22 +08:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-20 16:36:03 +08:00
|
|
|
countResp, err := this.RPC().LogRPC().CountLogs(this.AdminContext(), &pb.CountLogRequest{
|
2020-12-23 10:42:41 +08:00
|
|
|
DayFrom: params.DayFrom,
|
|
|
|
|
DayTo: params.DayTo,
|
|
|
|
|
Keyword: params.Keyword,
|
|
|
|
|
UserType: params.UserType,
|
2023-04-06 10:06:22 +08:00
|
|
|
Level: params.Level,
|
2020-11-20 16:36:03 +08:00
|
|
|
})
|
2020-11-10 20:30:47 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-04-06 10:06:22 +08:00
|
|
|
var count = countResp.Count
|
|
|
|
|
var page = this.NewPage(count)
|
2020-11-10 20:30:47 +08:00
|
|
|
this.Data["page"] = page.AsHTML()
|
|
|
|
|
|
|
|
|
|
logsResp, err := this.RPC().LogRPC().ListLogs(this.AdminContext(), &pb.ListLogsRequest{
|
2020-12-23 10:42:41 +08:00
|
|
|
Offset: page.Offset,
|
|
|
|
|
Size: page.Size,
|
|
|
|
|
DayFrom: params.DayFrom,
|
|
|
|
|
DayTo: params.DayTo,
|
|
|
|
|
Keyword: params.Keyword,
|
|
|
|
|
UserType: params.UserType,
|
2023-04-06 10:06:22 +08:00
|
|
|
Level: params.Level,
|
2020-11-10 20:30:47 +08:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-04-06 10:06:22 +08:00
|
|
|
var logMaps = []maps.Map{}
|
2020-11-10 20:30:47 +08:00
|
|
|
for _, log := range logsResp.Logs {
|
2023-08-24 12:22:16 +08:00
|
|
|
var regionName = ""
|
|
|
|
|
var ipRegion = iplibrary.LookupIP(log.Ip)
|
|
|
|
|
if ipRegion != nil && ipRegion.IsOk() {
|
|
|
|
|
regionName = ipRegion.Summary()
|
2020-11-10 21:52:06 +08:00
|
|
|
}
|
|
|
|
|
|
2020-11-10 20:30:47 +08:00
|
|
|
logMaps = append(logMaps, maps.Map{
|
2020-12-02 20:31:42 +08:00
|
|
|
"id": log.Id,
|
2020-12-23 10:42:41 +08:00
|
|
|
"adminId": log.AdminId,
|
|
|
|
|
"userId": log.UserId,
|
2020-11-10 20:30:47 +08:00
|
|
|
"description": log.Description,
|
2020-11-10 21:52:06 +08:00
|
|
|
"userName": log.UserName,
|
2020-11-10 20:30:47 +08:00
|
|
|
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
|
|
|
|
|
"level": log.Level,
|
|
|
|
|
"type": log.Type,
|
|
|
|
|
"ip": log.Ip,
|
2020-11-10 21:52:06 +08:00
|
|
|
"region": regionName,
|
2020-11-20 16:36:03 +08:00
|
|
|
"action": log.Action,
|
2020-11-10 20:30:47 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.Data["logs"] = logMaps
|
|
|
|
|
|
2020-09-13 20:37:07 +08:00
|
|
|
this.Show()
|
|
|
|
|
}
|