mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-20 16:20:27 +08:00
WAF日志可以使用规则分组筛选
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user