实现点击访问日志显示详情窗口

This commit is contained in:
刘祥超
2020-11-02 21:15:25 +08:00
parent 05af5d66dd
commit 1239712e97
11 changed files with 251 additions and 4 deletions

View File

@@ -15,6 +15,7 @@ func init() {
GetPost("", new(IndexAction)).
GetPost("/today", new(TodayAction)).
GetPost("/history", new(HistoryAction)).
Get("/viewPopup", new(ViewPopupAction)).
EndAll()
})
}

View File

@@ -0,0 +1,86 @@
package log
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
"net/http"
)
type ViewPopupAction struct {
actionutils.ParentAction
}
func (this *ViewPopupAction) Init() {
this.Nav("", "", "")
}
func (this *ViewPopupAction) RunGet(params struct {
RequestId string
}) {
accessLogResp, err := this.RPC().HTTPAccessLogRPC().FindHTTPAccessLog(this.AdminContext(), &pb.FindHTTPAccessLogRequest{RequestId: params.RequestId})
if err != nil {
this.ErrorPage(err)
return
}
accessLog := accessLogResp.AccessLog
if accessLog == nil {
this.WriteString("not found: " + params.RequestId)
return
}
// 状态
if len(accessLog.StatusMessage) == 0 {
accessLog.StatusMessage = http.StatusText(int(accessLog.Status))
}
this.Data["accessLog"] = accessLog
// WAF相关
var wafMap maps.Map = nil
if accessLog.FirewallPolicyId > 0 {
policyResp, err := this.RPC().HTTPFirewallPolicyRPC().FindEnabledFirewallPolicy(this.AdminContext(), &pb.FindEnabledFirewallPolicyRequest{FirewallPolicyId: accessLog.FirewallPolicyId})
if err != nil {
this.ErrorPage(err)
return
}
if policyResp.FirewallPolicy != nil {
wafMap = maps.Map{
"policy": maps.Map{
"id": policyResp.FirewallPolicy.Id,
"name": policyResp.FirewallPolicy.Name,
},
}
if accessLog.FirewallRuleGroupId > 0 {
groupResp, err := this.RPC().HTTPFirewallRuleGroupRPC().FindEnabledHTTPFirewallRuleGroup(this.AdminContext(), &pb.FindEnabledHTTPFirewallRuleGroupRequest{FirewallRuleGroupId: accessLog.FirewallRuleGroupId})
if err != nil {
this.ErrorPage(err)
return
}
if groupResp.FirewallRuleGroup != nil {
wafMap["group"] = maps.Map{
"id": groupResp.FirewallRuleGroup.Id,
"name": groupResp.FirewallRuleGroup.Name,
}
if accessLog.FirewallRuleSetId > 0 {
setResp, err := this.RPC().HTTPFirewallRuleSetRPC().FindEnabledHTTPFirewallRuleSet(this.AdminContext(), &pb.FindEnabledHTTPFirewallRuleSetRequest{FirewallRuleSetId: accessLog.FirewallRuleSetId})
if err != nil {
this.ErrorPage(err)
return
}
if setResp.FirewallRuleSet != nil {
wafMap["set"] = maps.Map{
"id": setResp.FirewallRuleSet.Id,
"name": setResp.FirewallRuleSet.Name,
}
}
}
}
}
}
}
this.Data["wafInfo"] = wafMap
this.Show()
}