mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 13:10:26 +08:00 
			
		
		
		
	删除不需要的文件
This commit is contained in:
		@@ -1,179 +0,0 @@
 | 
			
		||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
 | 
			
		||||
 | 
			
		||||
package ipbox
 | 
			
		||||
 | 
			
		||||
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/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
 | 
			
		||||
	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
 | 
			
		||||
 | 
			
		||||
	Must *actions.Must
 | 
			
		||||
	CSRF *actionutils.CSRF
 | 
			
		||||
}) {
 | 
			
		||||
	var policyId int64 = 0
 | 
			
		||||
	defer func() {
 | 
			
		||||
		this.CreateLogInfo("创建访问日志策略 %d", policyId)
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
	params.Must.
 | 
			
		||||
		Field("name", params.Name).
 | 
			
		||||
		Require("请输入日志策略的名称").
 | 
			
		||||
		Field("type", params.Type).
 | 
			
		||||
		Require("请选择存储类型")
 | 
			
		||||
 | 
			
		||||
	var options interface{} = nil
 | 
			
		||||
	switch params.Type {
 | 
			
		||||
	case serverconfigs.AccessLogStorageTypeFile:
 | 
			
		||||
		params.Must.
 | 
			
		||||
			Field("filePath", params.FilePath).
 | 
			
		||||
			Require("请输入日志文件路径")
 | 
			
		||||
 | 
			
		||||
		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名称").
 | 
			
		||||
			Field("esMappingType", params.EsMappingType).
 | 
			
		||||
			Require("请输入Mapping名称")
 | 
			
		||||
 | 
			
		||||
		storage := new(serverconfigs.AccessLogESStorageConfig)
 | 
			
		||||
		storage.Endpoint = params.EsEndpoint
 | 
			
		||||
		storage.Index = params.EsIndex
 | 
			
		||||
		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("请输入网络地址")
 | 
			
		||||
 | 
			
		||||
		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路径")
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		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("请输入可执行命令")
 | 
			
		||||
 | 
			
		||||
		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,
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	policyId = createResp.HttpAccessLogPolicyId
 | 
			
		||||
 | 
			
		||||
	this.Success()
 | 
			
		||||
}
 | 
			
		||||
@@ -1,26 +0,0 @@
 | 
			
		||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
 | 
			
		||||
 | 
			
		||||
package ipbox
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type DeleteAction struct {
 | 
			
		||||
	actionutils.ParentAction
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *DeleteAction) RunPost(params struct {
 | 
			
		||||
	PolicyId int64
 | 
			
		||||
}) {
 | 
			
		||||
	defer this.CreateLogInfo("删除访问日志策略 %d", params.PolicyId)
 | 
			
		||||
 | 
			
		||||
	_, err := this.RPC().HTTPAccessLogPolicyRPC().DeleteHTTPAccessLogPolicy(this.AdminContext(), &pb.DeleteHTTPAccessLogPolicyRequest{HttpAccessLogPolicyId: params.PolicyId})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.Success()
 | 
			
		||||
}
 | 
			
		||||
@@ -1,57 +0,0 @@
 | 
			
		||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
 | 
			
		||||
 | 
			
		||||
package ipbox
 | 
			
		||||
 | 
			
		||||
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().CountAllEnabledHTTPAccessLogPolicies(this.AdminContext(), &pb.CountAllEnabledHTTPAccessLogPoliciesRequest{})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	page := this.NewPage(countResp.Count)
 | 
			
		||||
	this.Data["page"] = page.AsHTML()
 | 
			
		||||
 | 
			
		||||
	policiesResp, err := this.RPC().HTTPAccessLogPolicyRPC().ListEnabledHTTPAccessLogPolicies(this.AdminContext(), &pb.ListEnabledHTTPAccessLogPoliciesRequest{
 | 
			
		||||
		Offset: page.Offset,
 | 
			
		||||
		Size:   page.Size,
 | 
			
		||||
	})
 | 
			
		||||
	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,
 | 
			
		||||
			"options":  optionsMap,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	this.Data["policies"] = policyMaps
 | 
			
		||||
 | 
			
		||||
	this.Show()
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
 | 
			
		||||
 | 
			
		||||
package ipbox
 | 
			
		||||
 | 
			
		||||
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()
 | 
			
		||||
}
 | 
			
		||||
@@ -1,49 +0,0 @@
 | 
			
		||||
// 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().FindEnabledHTTPAccessLogPolicy(parent.AdminContext(), &pb.FindEnabledHTTPAccessLogPolicyRequest{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,
 | 
			
		||||
		"options":  options,
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
@@ -1,57 +0,0 @@
 | 
			
		||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
 | 
			
		||||
 | 
			
		||||
package ipbox
 | 
			
		||||
 | 
			
		||||
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/rpc/pb"
 | 
			
		||||
	"github.com/iwind/TeaGo/actions"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.Show()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *TestAction) RunPost(params struct {
 | 
			
		||||
	PolicyId int64
 | 
			
		||||
	BodyJSON []byte
 | 
			
		||||
 | 
			
		||||
	Must *actions.Must
 | 
			
		||||
}) {
 | 
			
		||||
	defer this.CreateLogInfo("测试向访问日志策略 %d 写入数据", 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()
 | 
			
		||||
}
 | 
			
		||||
@@ -1,195 +0,0 @@
 | 
			
		||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
 | 
			
		||||
 | 
			
		||||
package ipbox
 | 
			
		||||
 | 
			
		||||
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/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
 | 
			
		||||
	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
 | 
			
		||||
 | 
			
		||||
	Must *actions.Must
 | 
			
		||||
	CSRF *actionutils.CSRF
 | 
			
		||||
}) {
 | 
			
		||||
	defer this.CreateLogInfo("修改访问日志策略 %d", params.PolicyId)
 | 
			
		||||
 | 
			
		||||
	policyResp, err := this.RPC().HTTPAccessLogPolicyRPC().FindEnabledHTTPAccessLogPolicy(this.AdminContext(), &pb.FindEnabledHTTPAccessLogPolicyRequest{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("请输入日志文件路径")
 | 
			
		||||
 | 
			
		||||
		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名称").
 | 
			
		||||
			Field("esMappingType", params.EsMappingType).
 | 
			
		||||
			Require("请输入Mapping名称")
 | 
			
		||||
 | 
			
		||||
		storage := new(serverconfigs.AccessLogESStorageConfig)
 | 
			
		||||
		storage.Endpoint = params.EsEndpoint
 | 
			
		||||
		storage.Index = params.EsIndex
 | 
			
		||||
		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("请输入网络地址")
 | 
			
		||||
 | 
			
		||||
		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路径")
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		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("请输入可执行命令")
 | 
			
		||||
 | 
			
		||||
		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,
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.Success()
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user