1.4.5.2
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
// 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/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/cmd"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
this.Data["types"] = serverconfigs.FindAllAccessLogStorageTypes()
|
||||
this.Data["syslogPriorities"] = serverconfigs.AccessLogSyslogStoragePriorities
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
Name string
|
||||
Type string
|
||||
|
||||
// file
|
||||
FilePath string
|
||||
FileAutoCreate bool
|
||||
|
||||
// es
|
||||
EsEndpoint string
|
||||
EsIndex string
|
||||
EsIsDataStream bool
|
||||
EsMappingType string
|
||||
EsUsername string
|
||||
EsPassword string
|
||||
|
||||
// mysql
|
||||
MysqlHost string
|
||||
MysqlPort int
|
||||
MysqlUsername string
|
||||
MysqlPassword string
|
||||
MysqlDatabase string
|
||||
MysqlTable string
|
||||
MysqlLogField string
|
||||
|
||||
// tcp
|
||||
TcpNetwork string
|
||||
TcpAddr string
|
||||
|
||||
// syslog
|
||||
SyslogProtocol string
|
||||
SyslogServerAddr string
|
||||
SyslogServerPort int
|
||||
SyslogSocket string
|
||||
SyslogTag string
|
||||
SyslogPriority int
|
||||
|
||||
// command
|
||||
CommandCommand string
|
||||
CommandArgs string
|
||||
CommandDir string
|
||||
|
||||
IsPublic bool
|
||||
FirewallOnly bool
|
||||
DisableDefaultDB bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var policyId int64 = 0
|
||||
defer func() {
|
||||
this.CreateLogInfo(codes.HTTPAccessLogPolicy_LogCreateHTTPAccessLogPolicy, policyId)
|
||||
}()
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入日志策略的名称").
|
||||
Field("type", params.Type).
|
||||
Require("请选择存储类型")
|
||||
|
||||
var options any = nil
|
||||
switch params.Type {
|
||||
case serverconfigs.AccessLogStorageTypeFile:
|
||||
params.Must.
|
||||
Field("filePath", params.FilePath).
|
||||
Require("请输入日志文件路径")
|
||||
|
||||
var storage = new(serverconfigs.AccessLogFileStorageConfig)
|
||||
storage.Path = params.FilePath
|
||||
storage.AutoCreate = params.FileAutoCreate
|
||||
options = storage
|
||||
case serverconfigs.AccessLogStorageTypeES:
|
||||
params.Must.
|
||||
Field("esEndpoint", params.EsEndpoint).
|
||||
Require("请输入Endpoint").
|
||||
Field("esIndex", params.EsIndex).
|
||||
Require("请输入Index名称")
|
||||
if !params.EsIsDataStream {
|
||||
params.Must.
|
||||
Field("esMappingType", params.EsMappingType).
|
||||
Require("请输入Mapping名称")
|
||||
}
|
||||
|
||||
var storage = new(serverconfigs.AccessLogESStorageConfig)
|
||||
storage.Endpoint = params.EsEndpoint
|
||||
storage.Index = params.EsIndex
|
||||
storage.IsDataStream = params.EsIsDataStream
|
||||
storage.MappingType = params.EsMappingType
|
||||
storage.Username = params.EsUsername
|
||||
storage.Password = params.EsPassword
|
||||
options = storage
|
||||
case serverconfigs.AccessLogStorageTypeTCP:
|
||||
params.Must.
|
||||
Field("tcpNetwork", params.TcpNetwork).
|
||||
Require("请选择网络协议").
|
||||
Field("tcpAddr", params.TcpAddr).
|
||||
Require("请输入网络地址")
|
||||
|
||||
var storage = new(serverconfigs.AccessLogTCPStorageConfig)
|
||||
storage.Network = params.TcpNetwork
|
||||
storage.Addr = params.TcpAddr
|
||||
options = storage
|
||||
case serverconfigs.AccessLogStorageTypeSyslog:
|
||||
switch params.SyslogProtocol {
|
||||
case serverconfigs.AccessLogSyslogStorageProtocolTCP, serverconfigs.AccessLogSyslogStorageProtocolUDP:
|
||||
params.Must.
|
||||
Field("syslogServerAddr", params.SyslogServerAddr).
|
||||
Require("请输入网络地址")
|
||||
case serverconfigs.AccessLogSyslogStorageProtocolSocket:
|
||||
params.Must.
|
||||
Field("syslogSocket", params.SyslogSocket).
|
||||
Require("请输入Socket路径")
|
||||
}
|
||||
|
||||
var storage = new(serverconfigs.AccessLogSyslogStorageConfig)
|
||||
storage.Protocol = params.SyslogProtocol
|
||||
storage.ServerAddr = params.SyslogServerAddr
|
||||
storage.ServerPort = params.SyslogServerPort
|
||||
storage.Socket = params.SyslogSocket
|
||||
storage.Tag = params.SyslogTag
|
||||
storage.Priority = params.SyslogPriority
|
||||
options = storage
|
||||
case serverconfigs.AccessLogStorageTypeCommand:
|
||||
params.Must.
|
||||
Field("commandCommand", params.CommandCommand).
|
||||
Require("请输入可执行命令")
|
||||
|
||||
var storage = new(serverconfigs.AccessLogCommandStorageConfig)
|
||||
storage.Command = params.CommandCommand
|
||||
storage.Args = cmd.ParseArgs(params.CommandArgs)
|
||||
storage.Dir = params.CommandDir
|
||||
options = storage
|
||||
}
|
||||
|
||||
if options == nil {
|
||||
this.Fail("找不到选择的存储类型")
|
||||
}
|
||||
|
||||
optionsJSON, err := json.Marshal(options)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
createResp, err := this.RPC().HTTPAccessLogPolicyRPC().CreateHTTPAccessLogPolicy(this.AdminContext(), &pb.CreateHTTPAccessLogPolicyRequest{
|
||||
Name: params.Name,
|
||||
Type: params.Type,
|
||||
OptionsJSON: optionsJSON,
|
||||
CondsJSON: nil, // TODO
|
||||
IsPublic: params.IsPublic,
|
||||
FirewallOnly: params.FirewallOnly,
|
||||
DisableDefaultDB: params.DisableDefaultDB,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
policyId = createResp.HttpAccessLogPolicyId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package accesslogs
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
PolicyId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.HTTPAccessLogPolicy_LogDeleteHTTPAccessLogPolicy, params.PolicyId)
|
||||
|
||||
_, err := this.RPC().HTTPAccessLogPolicyRPC().DeleteHTTPAccessLogPolicy(this.AdminContext(), &pb.DeleteHTTPAccessLogPolicyRequest{HttpAccessLogPolicyId: params.PolicyId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// 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
|
||||
}
|
||||
}
|
||||
policyMaps = append(policyMaps, maps.Map{
|
||||
"id": policy.Id,
|
||||
"name": policy.Name,
|
||||
"type": policy.Type,
|
||||
"typeName": serverconfigs.FindAccessLogStorageTypeName(policy.Type),
|
||||
"isOn": policy.IsOn,
|
||||
"isPublic": policy.IsPublic,
|
||||
"firewallOnly": policy.FirewallOnly,
|
||||
"disableDefaultDB": policy.DisableDefaultDB,
|
||||
"options": optionsMap,
|
||||
})
|
||||
}
|
||||
this.Data["policies"] = policyMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package accesslogs
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(plus.NewHelper(plus.ComponentCodeLog)).
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
|
||||
Prefix("/servers/accesslogs").
|
||||
Data("teaMenu", "servers").
|
||||
Data("teaSubMenu", "accesslog").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/createPopup", new(CreatePopupAction)).
|
||||
Get("/policy", new(PolicyAction)).
|
||||
GetPost("/test", new(TestAction)).
|
||||
GetPost("/update", new(UpdateAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package accesslogs
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/accesslogs/policyutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
)
|
||||
|
||||
type PolicyAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *PolicyAction) Init() {
|
||||
this.Nav("", "", "policy")
|
||||
}
|
||||
|
||||
func (this *PolicyAction) RunGet(params struct {
|
||||
PolicyId int64
|
||||
}) {
|
||||
err := policyutils.InitPolicy(this.Parent(), params.PolicyId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var policyMap = this.Data.GetMap("policy")
|
||||
if policyMap.GetString("type") == serverconfigs.AccessLogStorageTypeSyslog {
|
||||
this.Data["syslogPriorityName"] = serverconfigs.FindAccessLogSyslogStoragePriorityName(policyMap.GetMap("options").GetInt("priority"))
|
||||
} else {
|
||||
this.Data["syslogPriorityName"] = ""
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package policyutils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||
"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"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
// InitPolicy 初始化访问日志策略
|
||||
func InitPolicy(parent *actionutils.ParentAction, policyId int64) error {
|
||||
rpcClient, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
policyResp, err := rpcClient.HTTPAccessLogPolicyRPC().FindHTTPAccessLogPolicy(parent.AdminContext(), &pb.FindHTTPAccessLogPolicyRequest{HttpAccessLogPolicyId: policyId})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var policy = policyResp.HttpAccessLogPolicy
|
||||
if policy == nil {
|
||||
return errors.New("can not find policy '" + types.String(policyId) + "'")
|
||||
}
|
||||
|
||||
var options = maps.Map{}
|
||||
if len(policy.OptionsJSON) > 0 {
|
||||
err = json.Unmarshal(policy.OptionsJSON, &options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
parent.Data["policy"] = maps.Map{
|
||||
"id": policy.Id,
|
||||
"name": policy.Name,
|
||||
"type": policy.Type,
|
||||
"typeName": serverconfigs.FindAccessLogStorageTypeName(policy.Type),
|
||||
"isOn": policy.IsOn,
|
||||
"isPublic": policy.IsPublic,
|
||||
"firewallOnly": policy.FirewallOnly,
|
||||
"disableDefaultDB": policy.DisableDefaultDB,
|
||||
"options": options,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
// 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/EdgeAdmin/internal/web/actions/default/servers/accesslogs/policyutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TestAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *TestAction) Init() {
|
||||
this.Nav("", "", "test")
|
||||
}
|
||||
|
||||
func (this *TestAction) RunGet(params struct {
|
||||
PolicyId int64
|
||||
}) {
|
||||
err := policyutils.InitPolicy(this.Parent(), params.PolicyId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var now = time.Now()
|
||||
|
||||
var uri = "/doc.html"
|
||||
testJSON, err := json.MarshalIndent(&pb.HTTPAccessLog{
|
||||
RequestId: types.String(time.Now().UnixMilli()) + "1" + strconv.Itoa(1),
|
||||
UserAgent: this.Request.UserAgent(),
|
||||
Request: "GET " + uri + " HTTP/1.1",
|
||||
RequestPath: uri,
|
||||
Referer: "https://example.com/",
|
||||
RemoteAddr: "8.8.8.8",
|
||||
Timestamp: now.Unix(),
|
||||
TimeISO8601: now.Format("2006-01-02T15:04:05.000Z07:00"),
|
||||
TimeLocal: now.Format("2/Jan/2006:15:04:05 -0700"),
|
||||
}, "", " ")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["testJSON"] = string(testJSON)
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *TestAction) RunPost(params struct {
|
||||
PolicyId int64
|
||||
BodyJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.HTTPAccessLogPolicy_LogTestHTTPAccessLogPolicy, params.PolicyId)
|
||||
|
||||
var accessLog = &pb.HTTPAccessLog{}
|
||||
err := json.Unmarshal(params.BodyJSON, accessLog)
|
||||
if err != nil {
|
||||
this.Fail("发送内容不是有效的JSON:" + err.Error())
|
||||
}
|
||||
|
||||
_, err = this.RPC().HTTPAccessLogPolicyRPC().WriteHTTPAccessLogPolicy(this.AdminContext(), &pb.WriteHTTPAccessLogPolicyRequest{
|
||||
HttpAccessLogPolicyId: params.PolicyId,
|
||||
HttpAccessLog: accessLog,
|
||||
})
|
||||
if err != nil {
|
||||
this.Fail("发送失败:" + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
// 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/EdgeAdmin/internal/web/actions/default/servers/accesslogs/policyutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/cmd"
|
||||
)
|
||||
|
||||
type UpdateAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateAction) Init() {
|
||||
this.Nav("", "", "update")
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunGet(params struct {
|
||||
PolicyId int64
|
||||
}) {
|
||||
err := policyutils.InitPolicy(this.Parent(), params.PolicyId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["types"] = serverconfigs.FindAllAccessLogStorageTypes()
|
||||
this.Data["syslogPriorities"] = serverconfigs.AccessLogSyslogStoragePriorities
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunPost(params struct {
|
||||
PolicyId int64
|
||||
Name string
|
||||
|
||||
// file
|
||||
FilePath string
|
||||
FileAutoCreate bool
|
||||
|
||||
// es
|
||||
EsEndpoint string
|
||||
EsIndex string
|
||||
EsIsDataStream bool
|
||||
EsMappingType string
|
||||
EsUsername string
|
||||
EsPassword string
|
||||
|
||||
// mysql
|
||||
MysqlHost string
|
||||
MysqlPort int
|
||||
MysqlUsername string
|
||||
MysqlPassword string
|
||||
MysqlDatabase string
|
||||
MysqlTable string
|
||||
MysqlLogField string
|
||||
|
||||
// tcp
|
||||
TcpNetwork string
|
||||
TcpAddr string
|
||||
|
||||
// syslog
|
||||
SyslogProtocol string
|
||||
SyslogServerAddr string
|
||||
SyslogServerPort int
|
||||
SyslogSocket string
|
||||
SyslogTag string
|
||||
SyslogPriority int
|
||||
|
||||
// command
|
||||
CommandCommand string
|
||||
CommandArgs string
|
||||
CommandDir string
|
||||
|
||||
IsOn bool
|
||||
IsPublic bool
|
||||
FirewallOnly bool
|
||||
DisableDefaultDB bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.HTTPAccessLogPolicy_LogUpdateHTTPAccessLogPolicy, params.PolicyId)
|
||||
|
||||
policyResp, err := this.RPC().HTTPAccessLogPolicyRPC().FindHTTPAccessLogPolicy(this.AdminContext(), &pb.FindHTTPAccessLogPolicyRequest{HttpAccessLogPolicyId: params.PolicyId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var policy = policyResp.HttpAccessLogPolicy
|
||||
if policy == nil {
|
||||
this.Fail("找不到要修改的策略")
|
||||
return
|
||||
}
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入日志策略的名称")
|
||||
|
||||
var options interface{} = nil
|
||||
switch policy.Type {
|
||||
case serverconfigs.AccessLogStorageTypeFile:
|
||||
params.Must.
|
||||
Field("filePath", params.FilePath).
|
||||
Require("请输入日志文件路径")
|
||||
|
||||
var storage = new(serverconfigs.AccessLogFileStorageConfig)
|
||||
storage.Path = params.FilePath
|
||||
storage.AutoCreate = params.FileAutoCreate
|
||||
options = storage
|
||||
case serverconfigs.AccessLogStorageTypeES:
|
||||
params.Must.
|
||||
Field("esEndpoint", params.EsEndpoint).
|
||||
Require("请输入Endpoint").
|
||||
Field("esIndex", params.EsIndex).
|
||||
Require("请输入Index名称")
|
||||
|
||||
if !params.EsIsDataStream {
|
||||
params.Must.
|
||||
Field("esMappingType", params.EsMappingType).
|
||||
Require("请输入Mapping名称")
|
||||
}
|
||||
|
||||
var storage = new(serverconfigs.AccessLogESStorageConfig)
|
||||
storage.Endpoint = params.EsEndpoint
|
||||
storage.Index = params.EsIndex
|
||||
storage.IsDataStream = params.EsIsDataStream
|
||||
storage.MappingType = params.EsMappingType
|
||||
storage.Username = params.EsUsername
|
||||
storage.Password = params.EsPassword
|
||||
options = storage
|
||||
case serverconfigs.AccessLogStorageTypeTCP:
|
||||
params.Must.
|
||||
Field("tcpNetwork", params.TcpNetwork).
|
||||
Require("请选择网络协议").
|
||||
Field("tcpAddr", params.TcpAddr).
|
||||
Require("请输入网络地址")
|
||||
|
||||
var storage = new(serverconfigs.AccessLogTCPStorageConfig)
|
||||
storage.Network = params.TcpNetwork
|
||||
storage.Addr = params.TcpAddr
|
||||
options = storage
|
||||
case serverconfigs.AccessLogStorageTypeSyslog:
|
||||
switch params.SyslogProtocol {
|
||||
case serverconfigs.AccessLogSyslogStorageProtocolTCP, serverconfigs.AccessLogSyslogStorageProtocolUDP:
|
||||
params.Must.
|
||||
Field("syslogServerAddr", params.SyslogServerAddr).
|
||||
Require("请输入网络地址")
|
||||
case serverconfigs.AccessLogSyslogStorageProtocolSocket:
|
||||
params.Must.
|
||||
Field("syslogSocket", params.SyslogSocket).
|
||||
Require("请输入Socket路径")
|
||||
}
|
||||
|
||||
var storage = new(serverconfigs.AccessLogSyslogStorageConfig)
|
||||
storage.Protocol = params.SyslogProtocol
|
||||
storage.ServerAddr = params.SyslogServerAddr
|
||||
storage.ServerPort = params.SyslogServerPort
|
||||
storage.Socket = params.SyslogSocket
|
||||
storage.Tag = params.SyslogTag
|
||||
storage.Priority = params.SyslogPriority
|
||||
options = storage
|
||||
case serverconfigs.AccessLogStorageTypeCommand:
|
||||
params.Must.
|
||||
Field("commandCommand", params.CommandCommand).
|
||||
Require("请输入可执行命令")
|
||||
|
||||
var storage = new(serverconfigs.AccessLogCommandStorageConfig)
|
||||
storage.Command = params.CommandCommand
|
||||
storage.Args = cmd.ParseArgs(params.CommandArgs)
|
||||
storage.Dir = params.CommandDir
|
||||
options = storage
|
||||
}
|
||||
|
||||
if options == nil {
|
||||
this.Fail("找不到选择的存储类型")
|
||||
}
|
||||
|
||||
optionsJSON, err := json.Marshal(options)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
_, err = this.RPC().HTTPAccessLogPolicyRPC().UpdateHTTPAccessLogPolicy(this.AdminContext(), &pb.UpdateHTTPAccessLogPolicyRequest{
|
||||
HttpAccessLogPolicyId: params.PolicyId,
|
||||
Name: params.Name,
|
||||
OptionsJSON: optionsJSON,
|
||||
CondsJSON: nil, // TODO
|
||||
IsOn: params.IsOn,
|
||||
IsPublic: params.IsPublic,
|
||||
FirewallOnly: params.FirewallOnly,
|
||||
DisableDefaultDB: params.DisableDefaultDB,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user