From f0f5fcff54e395e9221fdfd051d913a596f07da9 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 5 Jul 2023 15:55:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E9=9B=86=E7=BE=A4=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=B8=8D=E5=85=81=E8=AE=B8=E8=AE=B0=E5=BD=95=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=97=B6=EF=BC=8C=E5=9C=A8=E7=BD=91=E7=AB=99?= =?UTF-8?q?=E7=9A=84=E8=AE=BF=E9=97=AE=E6=97=A5=E5=BF=97=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/servers/server/log/base.go | 50 +++++++++++++++++++ .../default/servers/server/log/history.go | 8 ++- .../default/servers/server/log/index.go | 10 ++-- .../default/servers/server/log/today.go | 8 ++- .../@default/servers/server/log/history.html | 6 +++ .../@default/servers/server/log/index.html | 6 +++ .../@default/servers/server/log/today.html | 6 +++ 7 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 internal/web/actions/default/servers/server/log/base.go diff --git a/internal/web/actions/default/servers/server/log/base.go b/internal/web/actions/default/servers/server/log/base.go new file mode 100644 index 00000000..34398587 --- /dev/null +++ b/internal/web/actions/default/servers/server/log/base.go @@ -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 +} diff --git a/internal/web/actions/default/servers/server/log/history.go b/internal/web/actions/default/servers/server/log/history.go index bd1187ef..9d583c74 100644 --- a/internal/web/actions/default/servers/server/log/history.go +++ b/internal/web/actions/default/servers/server/log/history.go @@ -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{} diff --git a/internal/web/actions/default/servers/server/log/index.go b/internal/web/actions/default/servers/server/log/index.go index cba2d644..53d99409 100644 --- a/internal/web/actions/default/servers/server/log/index.go +++ b/internal/web/actions/default/servers/server/log/index.go @@ -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{} diff --git a/internal/web/actions/default/servers/server/log/today.go b/internal/web/actions/default/servers/server/log/today.go index 7e5a64b6..4859c693 100644 --- a/internal/web/actions/default/servers/server/log/today.go +++ b/internal/web/actions/default/servers/server/log/today.go @@ -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, diff --git a/web/views/@default/servers/server/log/history.html b/web/views/@default/servers/server/log/history.html index b1131e14..8e7c317c 100644 --- a/web/views/@default/servers/server/log/history.html +++ b/web/views/@default/servers/server/log/history.html @@ -14,6 +14,12 @@ {$template "/left_menu_with_menu"}
+ +
+
+ 当前集群已经设置不允许网站记录访问日志,可以在"集群设置" -- "网站设置"中修改此选项。 +
+ 所有日志 错误日志 diff --git a/web/views/@default/servers/server/log/index.html b/web/views/@default/servers/server/log/index.html index 44ea2d53..0aadd572 100644 --- a/web/views/@default/servers/server/log/index.html +++ b/web/views/@default/servers/server/log/index.html @@ -12,6 +12,12 @@ {$template "/left_menu_with_menu"}
+ +
+
+ 当前集群已经设置不允许网站记录访问日志,可以在"集群设置" -- "网站设置"中修改此选项。 +
+
diff --git a/web/views/@default/servers/server/log/today.html b/web/views/@default/servers/server/log/today.html index 23db558c..737ea092 100644 --- a/web/views/@default/servers/server/log/today.html +++ b/web/views/@default/servers/server/log/today.html @@ -12,6 +12,12 @@ {$template "/left_menu_with_menu"}
+ +
+
+ 当前集群已经设置不允许网站记录访问日志,可以在"集群设置" -- "网站设置"中修改此选项。 +
+ 所有日志 错误日志