mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-16 13:46:35 +08:00
操作日志中显示地区和ISP信息
This commit is contained in:
@@ -3,8 +3,10 @@ package log
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
@@ -35,13 +37,38 @@ func (this *IndexAction) RunGet(params struct{}) {
|
||||
}
|
||||
logMaps := []maps.Map{}
|
||||
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{
|
||||
"description": log.Description,
|
||||
"userName": log.Description,
|
||||
"userName": log.UserName,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
|
||||
"level": log.Level,
|
||||
"type": log.Type,
|
||||
"ip": log.Ip,
|
||||
"region": regionName,
|
||||
})
|
||||
}
|
||||
this.Data["logs"] = logMaps
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<table class="ui table selectable" v-for="log in logs">
|
||||
<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>
|
||||
<td>{{log.description}}</td>
|
||||
|
||||
Reference in New Issue
Block a user