66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
|
|
package accesslogs
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
"github.com/iwind/TeaGo/maps"
|
|
)
|
|
|
|
type IndexAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *IndexAction) Init() {
|
|
this.Nav("", "", "index")
|
|
}
|
|
|
|
func (this *IndexAction) RunGet(params struct{}) {
|
|
countResp, err := this.RPC().HTTPAccessLogPolicyRPC().CountAllHTTPAccessLogPolicies(this.AdminContext(), &pb.CountAllHTTPAccessLogPoliciesRequest{})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
var page = this.NewPage(countResp.Count)
|
|
this.Data["page"] = page.AsHTML()
|
|
|
|
policiesResp, err := this.RPC().HTTPAccessLogPolicyRPC().ListHTTPAccessLogPolicies(this.AdminContext(), &pb.ListHTTPAccessLogPoliciesRequest{
|
|
Offset: page.Offset,
|
|
Size: page.Size,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
|
|
var policyMaps = []maps.Map{}
|
|
for _, policy := range policiesResp.HttpAccessLogPolicies {
|
|
var optionsMap = maps.Map{}
|
|
if len(policy.OptionsJSON) > 0 {
|
|
err = json.Unmarshal(policy.OptionsJSON, &optionsMap)
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
}
|
|
typeDisplay := policy.Type
|
|
policyMaps = append(policyMaps, maps.Map{
|
|
"id": policy.Id,
|
|
"name": policy.Name,
|
|
"type": policy.Type,
|
|
"typeName": serverconfigs.FindAccessLogStorageTypeName(typeDisplay),
|
|
"isOn": policy.IsOn,
|
|
"isPublic": policy.IsPublic,
|
|
"firewallOnly": policy.FirewallOnly,
|
|
"disableDefaultDB": policy.DisableDefaultDB,
|
|
"options": optionsMap,
|
|
})
|
|
}
|
|
this.Data["policies"] = policyMaps
|
|
|
|
this.Show()
|
|
}
|