mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-07 15:20:25 +08:00
服务日志:增加区域信息
This commit is contained in:
@@ -68,21 +68,21 @@ func (this *ExportExcelAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if regionResp.Region != nil {
|
||||
if regionResp.IpRegion != nil {
|
||||
pieces := []string{}
|
||||
if len(regionResp.Region.Country) > 0 {
|
||||
pieces = append(pieces, regionResp.Region.Country)
|
||||
if len(regionResp.IpRegion.Country) > 0 {
|
||||
pieces = append(pieces, regionResp.IpRegion.Country)
|
||||
}
|
||||
if len(regionResp.Region.Province) > 0 && !lists.ContainsString(pieces, regionResp.Region.Province) {
|
||||
pieces = append(pieces, regionResp.Region.Province)
|
||||
if len(regionResp.IpRegion.Province) > 0 && !lists.ContainsString(pieces, regionResp.IpRegion.Province) {
|
||||
pieces = append(pieces, regionResp.IpRegion.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.IpRegion.City) > 0 && !lists.ContainsString(pieces, regionResp.IpRegion.City) && !lists.ContainsString(pieces, strings.TrimSuffix(regionResp.IpRegion.Province, "市")) {
|
||||
pieces = append(pieces, regionResp.IpRegion.City)
|
||||
}
|
||||
regionName = strings.Join(pieces, " ")
|
||||
|
||||
if len(regionResp.Region.Isp) > 0 {
|
||||
ispName = regionResp.Region.Isp
|
||||
if len(regionResp.IpRegion.Isp) > 0 {
|
||||
ispName = regionResp.IpRegion.Isp
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,19 +71,10 @@ func (this *IndexAction) RunGet(params struct {
|
||||
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)
|
||||
if regionResp.IpRegion != nil {
|
||||
pieces := []string{regionResp.IpRegion.Summary}
|
||||
if len(regionResp.IpRegion.Isp) > 0 && !lists.ContainsString(pieces, regionResp.IpRegion.Isp) {
|
||||
pieces = append(pieces, "| "+regionResp.IpRegion.Isp)
|
||||
}
|
||||
regionName = strings.Join(pieces, " ")
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package log
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"regexp"
|
||||
"strings"
|
||||
@@ -34,6 +35,8 @@ func (this *HistoryAction) RunGet(params struct {
|
||||
this.Data["hasError"] = params.HasError
|
||||
|
||||
day := params.Day
|
||||
ipList := []string{}
|
||||
|
||||
if len(day) > 0 && regexp.MustCompile(`\d{4}-\d{2}-\d{2}`).MatchString(day) {
|
||||
day = strings.ReplaceAll(day, "-", "")
|
||||
size := int64(10)
|
||||
@@ -56,6 +59,13 @@ func (this *HistoryAction) RunGet(params struct {
|
||||
this.Data["accessLogs"] = []interface{}{}
|
||||
} else {
|
||||
this.Data["accessLogs"] = resp.AccessLogs
|
||||
for _, accessLog := range resp.AccessLogs {
|
||||
if len(accessLog.RemoteAddr) > 0 {
|
||||
if !lists.ContainsString(ipList, accessLog.RemoteAddr) {
|
||||
ipList = append(ipList, accessLog.RemoteAddr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Data["hasMore"] = resp.HasMore
|
||||
this.Data["nextRequestId"] = resp.RequestId
|
||||
@@ -83,5 +93,21 @@ func (this *HistoryAction) RunGet(params struct {
|
||||
}
|
||||
}
|
||||
|
||||
// 根据IP查询区域
|
||||
regionMap := map[string]string{} // ip => region
|
||||
if len(ipList) > 0 {
|
||||
resp, err := this.RPC().IPLibraryRPC().LookupIPRegions(this.AdminContext(), &pb.LookupIPRegionsRequest{IpList: ipList})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if resp.IpRegionMap != nil {
|
||||
for ip, region := range resp.IpRegionMap {
|
||||
regionMap[ip] = region.Summary
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Data["regions"] = regionMap
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
@@ -45,9 +46,18 @@ func (this *IndexAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
ipList := []string{}
|
||||
accessLogs := accessLogsResp.AccessLogs
|
||||
if len(accessLogs) == 0 {
|
||||
accessLogs = []*pb.HTTPAccessLog{}
|
||||
} else {
|
||||
for _, accessLog := range accessLogs {
|
||||
if len(accessLog.RemoteAddr) > 0 {
|
||||
if !lists.ContainsString(ipList, accessLog.RemoteAddr) {
|
||||
ipList = append(ipList, accessLog.RemoteAddr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Data["accessLogs"] = accessLogs
|
||||
if len(accessLogs) > 0 {
|
||||
@@ -57,5 +67,21 @@ func (this *IndexAction) RunPost(params struct {
|
||||
}
|
||||
this.Data["hasMore"] = accessLogsResp.HasMore
|
||||
|
||||
// 根据IP查询区域
|
||||
regionMap := map[string]string{} // ip => region
|
||||
if len(ipList) > 0 {
|
||||
resp, err := this.RPC().IPLibraryRPC().LookupIPRegions(this.AdminContext(), &pb.LookupIPRegionsRequest{IpList: ipList})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if resp.IpRegionMap != nil {
|
||||
for ip, region := range resp.IpRegionMap {
|
||||
regionMap[ip] = region.Summary
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Data["regions"] = regionMap
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package log
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
@@ -37,10 +38,18 @@ func (this *TodayAction) RunGet(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
ipList := []string{}
|
||||
if len(resp.AccessLogs) == 0 {
|
||||
this.Data["accessLogs"] = []interface{}{}
|
||||
} else {
|
||||
this.Data["accessLogs"] = resp.AccessLogs
|
||||
for _, accessLog := range resp.AccessLogs {
|
||||
if len(accessLog.RemoteAddr) > 0 {
|
||||
if !lists.ContainsString(ipList, accessLog.RemoteAddr) {
|
||||
ipList = append(ipList, accessLog.RemoteAddr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Data["hasMore"] = resp.HasMore
|
||||
this.Data["nextRequestId"] = resp.RequestId
|
||||
@@ -67,5 +76,21 @@ func (this *TodayAction) RunGet(params struct {
|
||||
}
|
||||
}
|
||||
|
||||
// 根据IP查询区域
|
||||
regionMap := map[string]string{} // ip => region
|
||||
if len(ipList) > 0 {
|
||||
resp, err := this.RPC().IPLibraryRPC().LookupIPRegions(this.AdminContext(), &pb.LookupIPRegionsRequest{IpList: ipList})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if resp.IpRegionMap != nil {
|
||||
for ip, region := range resp.IpRegionMap {
|
||||
regionMap[ip] = region.Summary
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Data["regions"] = regionMap
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ViewPopupAction struct {
|
||||
@@ -90,23 +89,10 @@ func (this *ViewPopupAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
region := regionResp.Region
|
||||
region := regionResp.IpRegion
|
||||
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, " "),
|
||||
"full": region.Summary,
|
||||
"isp": region.Isp,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,13 +78,13 @@ func checkIPWithoutCache(config *systemconfigs.SecurityConfig, ipAddr string) bo
|
||||
logs.Println("[USER_MUST_AUTH][ERROR]" + err.Error())
|
||||
return false
|
||||
}
|
||||
if resp.Region == nil {
|
||||
if resp.IpRegion == nil {
|
||||
return true
|
||||
}
|
||||
if len(config.AllowCountryIds) > 0 && !lists.ContainsInt64(config.AllowCountryIds, resp.Region.CountryId) {
|
||||
if len(config.AllowCountryIds) > 0 && !lists.ContainsInt64(config.AllowCountryIds, resp.IpRegion.CountryId) {
|
||||
return false
|
||||
}
|
||||
if len(config.AllowProvinceIds) > 0 && !lists.ContainsInt64(config.AllowProvinceIds, resp.Region.ProvinceId) {
|
||||
if len(config.AllowProvinceIds) > 0 && !lists.ContainsInt64(config.AllowProvinceIds, resp.IpRegion.ProvinceId) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ Vue.component("http-access-log-box", {
|
||||
}
|
||||
},
|
||||
template: `<div :style="{'color': (accessLog.status >= 400) ? '#dc143c' : ''}" ref="box">
|
||||
{{accessLog.remoteAddr}} [{{accessLog.timeLocal}}] <em>"{{accessLog.requestMethod}} {{accessLog.scheme}}://{{accessLog.host}}{{accessLog.requestURI}} <a :href="accessLog.scheme + '://' + accessLog.host + accessLog.requestURI" target="_blank" title="新窗口打开" class="disabled"><i class="external icon tiny"></i> </a> {{accessLog.proto}}" </em> {{accessLog.status}} <span v-if="accessLog.attrs != null && accessLog.attrs['cache_cached'] == '1'">[cached]</span> <span v-if="accessLog.attrs != null && accessLog.attrs['waf.action'] != null && accessLog.attrs['waf.action'].length > 0">[waf {{accessLog.attrs['waf.action']}}]</span> - 耗时:{{formatCost(accessLog.requestTime)}} ms
|
||||
<span v-if="accessLog.region != null && accessLog.region.length > 0" class="grey">[{{accessLog.region}}]</span> {{accessLog.remoteAddr}} [{{accessLog.timeLocal}}] <em>"{{accessLog.requestMethod}} {{accessLog.scheme}}://{{accessLog.host}}{{accessLog.requestURI}} <a :href="accessLog.scheme + '://' + accessLog.host + accessLog.requestURI" target="_blank" title="新窗口打开" class="disabled"><i class="external icon tiny"></i> </a> {{accessLog.proto}}" </em> {{accessLog.status}} <span v-if="accessLog.attrs != null && accessLog.attrs['cache_cached'] == '1'">[cached]</span> <span v-if="accessLog.attrs != null && accessLog.attrs['waf.action'] != null && accessLog.attrs['waf.action'].length > 0">[waf {{accessLog.attrs['waf.action']}}]</span> - 耗时:{{formatCost(accessLog.requestTime)}} ms
|
||||
<a href="" @click.prevent="showLog" title="查看详情"><i class="icon expand"></i></a>
|
||||
</div>`
|
||||
})
|
||||
@@ -1,8 +1,17 @@
|
||||
Tea.context(function () {
|
||||
this.$delay(function () {
|
||||
let that = this
|
||||
teaweb.datepicker("day-input", function (day) {
|
||||
that.day = day
|
||||
})
|
||||
})
|
||||
this.$delay(function () {
|
||||
let that = this
|
||||
teaweb.datepicker("day-input", function (day) {
|
||||
that.day = day
|
||||
})
|
||||
})
|
||||
|
||||
let that = this
|
||||
this.accessLogs.forEach(function (accessLog) {
|
||||
if (typeof (that.regions[accessLog.remoteAddr]) == "string") {
|
||||
accessLog.region = that.regions[accessLog.remoteAddr]
|
||||
} else {
|
||||
accessLog.region = ""
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -15,6 +15,16 @@ Tea.context(function () {
|
||||
})
|
||||
.success(function (resp) {
|
||||
this.accessLogs = resp.data.accessLogs.concat(this.accessLogs)
|
||||
|
||||
// 添加区域信息
|
||||
this.accessLogs.forEach(function (accessLog) {
|
||||
if (typeof (resp.data.regions[accessLog.remoteAddr]) == "string") {
|
||||
accessLog.region = resp.data.regions[accessLog.remoteAddr]
|
||||
} else {
|
||||
accessLog.region = ""
|
||||
}
|
||||
})
|
||||
|
||||
let max = 100
|
||||
if (this.accessLogs.length > max) {
|
||||
this.accessLogs = this.accessLogs.slice(0, max)
|
||||
|
||||
10
web/views/@default/servers/server/log/today.js
Normal file
10
web/views/@default/servers/server/log/today.js
Normal file
@@ -0,0 +1,10 @@
|
||||
Tea.context(function () {
|
||||
let that = this
|
||||
this.accessLogs.forEach(function (accessLog) {
|
||||
if (typeof (that.regions[accessLog.remoteAddr]) == "string") {
|
||||
accessLog.region = that.regions[accessLog.remoteAddr]
|
||||
} else {
|
||||
accessLog.region = ""
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user