mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-01-06 03:55:48 +08:00
实现数据看板--WAF
This commit is contained in:
@@ -5,6 +5,8 @@ package boards
|
||||
import (
|
||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type WafAction struct {
|
||||
@@ -21,5 +23,54 @@ func (this *WafAction) RunGet(params struct{}) {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := this.RPC().FirewallRPC().ComposeFirewallGlobalBoard(this.AdminContext(), &pb.ComposeFirewallGlobalBoardRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["board"] = maps.Map{
|
||||
"countDailyLogs": resp.CountDailyLogs,
|
||||
"countDailyBlocks": resp.CountDailyBlocks,
|
||||
"countDailyCaptcha": resp.CountDailyCaptcha,
|
||||
"countWeeklyBlocks": resp.CountWeeklyBlocks,
|
||||
}
|
||||
|
||||
{
|
||||
var statMaps = []maps.Map{}
|
||||
for _, stat := range resp.HourlyStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"hour": stat.Hour,
|
||||
"countLogs": stat.CountLogs,
|
||||
"countCaptcha": stat.CountCaptcha,
|
||||
"countBlocks": stat.CountBlocks,
|
||||
})
|
||||
}
|
||||
this.Data["hourlyStats"] = statMaps
|
||||
}
|
||||
|
||||
{
|
||||
var statMaps = []maps.Map{}
|
||||
for _, stat := range resp.DailyStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"day": stat.Day,
|
||||
"countLogs": stat.CountLogs,
|
||||
"countCaptcha": stat.CountCaptcha,
|
||||
"countBlocks": stat.CountBlocks,
|
||||
})
|
||||
}
|
||||
this.Data["dailyStats"] = statMaps
|
||||
}
|
||||
|
||||
{
|
||||
var statMaps = []maps.Map{}
|
||||
for _, stat := range resp.HttpFirewallRuleGroups {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"name": stat.HttpFirewallRuleGroup.Name,
|
||||
"count": stat.Count,
|
||||
})
|
||||
}
|
||||
this.Data["groupStats"] = statMaps
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
28
internal/web/actions/default/dashboard/boards/wafLogs.go
Normal file
28
internal/web/actions/default/dashboard/boards/wafLogs.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package boards
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type WafLogsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *WafLogsAction) RunPost(params struct{}) {
|
||||
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
|
||||
HasFirewallPolicy: true,
|
||||
Reverse: false,
|
||||
Day: timeutil.Format("Ymd"),
|
||||
Size: 5,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["accessLogs"] = resp.HttpAccessLogs
|
||||
this.Success()
|
||||
}
|
||||
@@ -18,6 +18,7 @@ func init() {
|
||||
Prefix("/dashboard/boards").
|
||||
Get("", new(boards.IndexAction)).
|
||||
Get("/waf", new(boards.WafAction)).
|
||||
Post("/wafLogs", new(boards.WafLogsAction)).
|
||||
Get("/dns", new(boards.DnsAction)).
|
||||
Get("/user", new(boards.UserAction)).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user