访问日志增加区域和ISP信息

This commit is contained in:
刘祥超
2020-11-05 11:51:42 +08:00
parent a166d7e5f6
commit 7edd234d46
2 changed files with 38 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
"net/http"
"strings"
)
type ViewPopupAction struct {
@@ -82,5 +83,34 @@ func (this *ViewPopupAction) RunGet(params struct {
}
this.Data["wafInfo"] = wafMap
// 地域相关
var regionMap maps.Map = nil
regionResp, err := this.RPC().IPLibraryRPC().LookupIPRegion(this.AdminContext(), &pb.LookupIPRegionRequest{Ip: accessLog.RemoteAddr})
if err != nil {
this.ErrorPage(err)
return
}
region := regionResp.Region
if region != nil {
pieces := []string{}
if len(region.Country) > 0 {
pieces = append(pieces, region.Country)
}
if len(region.Region) > 0 {
pieces = append(pieces, region.Region)
}
if len(region.Province) > 0 {
pieces = append(pieces, region.Province)
}
if len(region.City) > 0 {
pieces = append(pieces, region.City)
}
regionMap = maps.Map{
"full": strings.Join(pieces, " "),
"isp": region.Isp,
}
}
this.Data["region"] = regionMap
this.Show()
}