操作日志中显示地区和ISP信息

This commit is contained in:
GoEdgeLab
2020-11-10 21:52:06 +08:00
parent 35f728515e
commit d4b9030657
2 changed files with 29 additions and 2 deletions

View File

@@ -3,8 +3,10 @@ package log
import ( import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time" timeutil "github.com/iwind/TeaGo/utils/time"
"strings"
) )
type IndexAction struct { type IndexAction struct {
@@ -35,13 +37,38 @@ func (this *IndexAction) RunGet(params struct{}) {
} }
logMaps := []maps.Map{} logMaps := []maps.Map{}
for _, log := range logsResp.Logs { for _, log := range logsResp.Logs {
regionName := ""
log.Ip = "123.123.88.220" // TODO
regionResp, err := this.RPC().IPLibraryRPC().LookupIPRegion(this.AdminContext(), &pb.LookupIPRegionRequest{Ip: log.Ip})
if err != nil {
this.ErrorPage(err)
return
}
if regionResp.Region != nil {
pieces := []string{}
if len(regionResp.Region.Country) > 0 {
pieces = append(pieces, regionResp.Region.Country)
}
if len(regionResp.Region.Province) > 0 && !lists.ContainsString(pieces, regionResp.Region.Province) {
pieces = append(pieces, regionResp.Region.Province)
}
if len(regionResp.Region.City) > 0 && !lists.ContainsString(pieces, regionResp.Region.City) && !lists.ContainsString(pieces, strings.TrimSuffix(regionResp.Region.Province, "市")) {
pieces = append(pieces, regionResp.Region.City)
}
if len(regionResp.Region.Isp) > 0 && !lists.ContainsString(pieces, regionResp.Region.Isp) {
pieces = append(pieces, regionResp.Region.Isp)
}
regionName = strings.Join(pieces, " ")
}
logMaps = append(logMaps, maps.Map{ logMaps = append(logMaps, maps.Map{
"description": log.Description, "description": log.Description,
"userName": log.Description, "userName": log.UserName,
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt), "createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
"level": log.Level, "level": log.Level,
"type": log.Type, "type": log.Type,
"ip": log.Ip, "ip": log.Ip,
"region": regionName,
}) })
} }
this.Data["logs"] = logMaps this.Data["logs"] = logMaps

View File

@@ -4,7 +4,7 @@
<table class="ui table selectable" v-for="log in logs"> <table class="ui table selectable" v-for="log in logs">
<tr> <tr>
<td>{{log.createdTime}} <span v-if="log.userName.length > 0">@ {{log.userName}}</span> @ {{log.ip}}</td> <td>{{log.createdTime}} <span class="grey"> <span v-if="log.userName.length > 0">| {{log.userName}}</span> | {{log.ip}}<span v-if="log.region.length > 0"> | {{log.region}}</span></span></td>
</tr> </tr>
<tr> <tr>
<td>{{log.description}}</td> <td>{{log.description}}</td>