From 9c45e4da79f57faad166cd2580af02dbc65ba12e Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Mon, 2 Nov 2020 15:50:19 +0800 Subject: [PATCH] =?UTF-8?q?WAF=E6=97=A5=E5=BF=97=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=A7=84=E5=88=99=E5=88=86=E7=BB=84=E7=AD=9B?= =?UTF-8?q?=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/servers/components/waf/log.go | 49 +++++++++++++++---- .../@default/servers/components/waf/log.html | 32 +++++++----- 2 files changed, 59 insertions(+), 22 deletions(-) diff --git a/internal/web/actions/default/servers/components/waf/log.go b/internal/web/actions/default/servers/components/waf/log.go index 793ce52a..09be53fc 100644 --- a/internal/web/actions/default/servers/components/waf/log.go +++ b/internal/web/actions/default/servers/components/waf/log.go @@ -1,8 +1,11 @@ package waf import ( + "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" + "github.com/iwind/TeaGo/maps" timeutil "github.com/iwind/TeaGo/utils/time" "regexp" "strings" @@ -20,6 +23,7 @@ func (this *LogAction) RunGet(params struct { Day string RequestId string FirewallPolicyId int64 + GroupId int64 }) { if len(params.Day) == 0 { params.Day = timeutil.Format("Y-m-d") @@ -27,6 +31,7 @@ func (this *LogAction) RunGet(params struct { this.Data["path"] = this.Request.URL.Path this.Data["day"] = params.Day + this.Data["groupId"] = params.GroupId this.Data["accessLogs"] = []interface{}{} day := params.Day @@ -35,10 +40,11 @@ func (this *LogAction) RunGet(params struct { size := int64(10) resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{ - RequestId: params.RequestId, - FirewallPolicyId: params.FirewallPolicyId, - Day: day, - Size: size, + RequestId: params.RequestId, + FirewallPolicyId: params.FirewallPolicyId, + FirewallRuleGroupId: params.GroupId, + Day: day, + Size: size, }) if err != nil { this.ErrorPage(err) @@ -59,11 +65,12 @@ func (this *LogAction) RunGet(params struct { if len(params.RequestId) > 0 { this.Data["hasPrev"] = true prevResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{ - RequestId: params.RequestId, - FirewallPolicyId: params.FirewallPolicyId, - Day: day, - Size: size, - Reverse: true, + RequestId: params.RequestId, + FirewallPolicyId: params.FirewallPolicyId, + FirewallRuleGroupId: params.GroupId, + Day: day, + Size: size, + Reverse: true, }) if err != nil { this.ErrorPage(err) @@ -75,5 +82,29 @@ func (this *LogAction) RunGet(params struct { } } + // 所有分组 + policyResp, err := this.RPC().HTTPFirewallPolicyRPC().FindEnabledFirewallPolicyConfig(this.AdminContext(), &pb.FindEnabledFirewallPolicyConfigRequest{ + FirewallPolicyId: params.FirewallPolicyId, + }) + if err != nil { + this.ErrorPage(err) + return + } + policyConfig := &firewallconfigs.HTTPFirewallPolicy{} + err = json.Unmarshal(policyResp.FirewallPolicyJSON, policyConfig) + if err != nil { + this.ErrorPage(err) + return + } + + groupMaps := []maps.Map{} + for _, group := range policyConfig.AllRuleGroups() { + groupMaps = append(groupMaps, maps.Map{ + "id": group.Id, + "name": group.Name, + }) + } + this.Data["groups"] = groupMaps + this.Show() } diff --git a/web/views/@default/servers/components/waf/log.html b/web/views/@default/servers/components/waf/log.html index a3e64b83..3e828f6a 100644 --- a/web/views/@default/servers/components/waf/log.html +++ b/web/views/@default/servers/components/waf/log.html @@ -14,21 +14,27 @@
{$template "waf_menu"} - +
+ +
+ +
- - -
-
- -
-
- -
+ +
+
+
- +
+ +
+
+

暂时还没有日志。

@@ -40,10 +46,10 @@
- 上一页 + 上一页 上一页   |   - 下一页 + 下一页 下一页
\ No newline at end of file