mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 12:20:28 +08:00
当集群设置不允许记录访问日志时,在网站的访问日志查看页面提醒
This commit is contained in:
50
internal/web/actions/default/servers/server/log/base.go
Normal file
50
internal/web/actions/default/servers/server/log/base.go
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package log
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
)
|
||||
|
||||
type BaseAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *BaseAction) initClusterAccessLogConfig(serverId int64) bool {
|
||||
this.Data["clusterAccessLogIsOn"] = true
|
||||
var clusterId int64
|
||||
serverResp, err := this.RPC().ServerRPC().FindEnabledUserServerBasic(this.AdminContext(), &pb.FindEnabledUserServerBasicRequest{ServerId: serverId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return false
|
||||
}
|
||||
if serverResp.Server == nil {
|
||||
this.NotFound("Server", serverId)
|
||||
return false
|
||||
}
|
||||
if serverResp.Server.NodeCluster != nil && serverResp.Server.NodeCluster.Id > 0 {
|
||||
clusterId = serverResp.Server.NodeCluster.Id
|
||||
}
|
||||
|
||||
if clusterId > 0 {
|
||||
globalServerConfigResp, err := this.RPC().NodeClusterRPC().FindNodeClusterGlobalServerConfig(this.AdminContext(), &pb.FindNodeClusterGlobalServerConfigRequest{NodeClusterId: clusterId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return false
|
||||
}
|
||||
|
||||
if len(globalServerConfigResp.GlobalServerConfigJSON) > 0 {
|
||||
var globalServerConfig = serverconfigs.NewGlobalServerConfig()
|
||||
err = json.Unmarshal(globalServerConfigResp.GlobalServerConfigJSON, globalServerConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return false
|
||||
}
|
||||
this.Data["clusterAccessLogIsOn"] = globalServerConfig.HTTPAccessLog.IsOn
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
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"
|
||||
@@ -11,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type HistoryAction struct {
|
||||
actionutils.ParentAction
|
||||
BaseAction
|
||||
}
|
||||
|
||||
func (this *HistoryAction) Init() {
|
||||
@@ -56,6 +55,11 @@ func (this *HistoryAction) RunGet(params struct {
|
||||
this.Data["nodeId"] = params.NodeId
|
||||
this.Data["partition"] = params.Partition
|
||||
|
||||
// 检查集群全局设置
|
||||
if !this.initClusterAccessLogConfig(params.ServerId) {
|
||||
return
|
||||
}
|
||||
|
||||
var day = params.Day
|
||||
var ipList = []string{}
|
||||
var wafMaps = []maps.Map{}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package log
|
||||
|
||||
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"
|
||||
@@ -10,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
BaseAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
@@ -36,6 +35,11 @@ func (this *IndexAction) RunGet(params struct {
|
||||
this.Data["clusterId"] = params.ClusterId
|
||||
this.Data["nodeId"] = params.NodeId
|
||||
|
||||
// 检查集群全局设置
|
||||
if !this.initClusterAccessLogConfig(params.ServerId) {
|
||||
return
|
||||
}
|
||||
|
||||
// 记录最近使用
|
||||
_, err := this.RPC().LatestItemRPC().IncreaseLatestItem(this.AdminContext(), &pb.IncreaseLatestItemRequest{
|
||||
ItemType: "server",
|
||||
@@ -83,7 +87,7 @@ func (this *IndexAction) RunPost(params struct {
|
||||
|
||||
var ipList = []string{}
|
||||
var wafMaps = []maps.Map{}
|
||||
|
||||
|
||||
var accessLogs = accessLogsResp.HttpAccessLogs
|
||||
if len(accessLogs) == 0 {
|
||||
accessLogs = []*pb.HTTPAccessLog{}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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"
|
||||
@@ -9,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type TodayAction struct {
|
||||
actionutils.ParentAction
|
||||
BaseAction
|
||||
}
|
||||
|
||||
func (this *TodayAction) Init() {
|
||||
@@ -50,6 +49,11 @@ func (this *TodayAction) RunGet(params struct {
|
||||
this.Data["partition"] = params.Partition
|
||||
this.Data["day"] = timeutil.Format("Ymd")
|
||||
|
||||
// 检查集群全局设置
|
||||
if !this.initClusterAccessLogConfig(params.ServerId) {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
|
||||
Partition: params.Partition,
|
||||
RequestId: params.RequestId,
|
||||
|
||||
Reference in New Issue
Block a user