[日志审计]增加删除、清理和别的一些设置

This commit is contained in:
GoEdgeLab
2020-12-02 20:31:42 +08:00
parent ee999435e4
commit 68baf8ee60
28 changed files with 485 additions and 78 deletions

View File

@@ -0,0 +1,5 @@
package configloaders
import "sync"
var locker sync.Mutex

View File

@@ -0,0 +1,83 @@
package configloaders
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/iwind/TeaGo/logs"
"reflect"
)
var sharedLogConfig *systemconfigs.LogConfig = nil
const (
LogSettingName = "adminLogConfig"
)
func LoadLogConfig() (*systemconfigs.LogConfig, error) {
locker.Lock()
defer locker.Unlock()
config, err := loadLogConfig()
if err != nil {
return nil, err
}
v := reflect.Indirect(reflect.ValueOf(config)).Interface().(systemconfigs.LogConfig)
return &v, nil
}
func UpdateLogConfig(logConfig *systemconfigs.LogConfig) error {
locker.Lock()
defer locker.Unlock()
var rpcClient, err = rpc.SharedRPC()
if err != nil {
return err
}
valueJSON, err := json.Marshal(logConfig)
if err != nil {
return err
}
_, err = rpcClient.SysSettingRPC().UpdateSysSetting(rpcClient.Context(0), &pb.UpdateSysSettingRequest{
Code: LogSettingName,
ValueJSON: valueJSON,
})
if err != nil {
return err
}
sharedLogConfig = logConfig
return nil
}
func loadLogConfig() (*systemconfigs.LogConfig, error) {
if sharedLogConfig != nil {
return sharedLogConfig, nil
}
var rpcClient, err = rpc.SharedRPC()
if err != nil {
return nil, err
}
resp, err := rpcClient.SysSettingRPC().ReadSysSetting(rpcClient.Context(0), &pb.ReadSysSettingRequest{
Code: LogSettingName,
})
if err != nil {
return nil, err
}
if len(resp.ValueJSON) == 0 {
sharedLogConfig = systemconfigs.DefaultLogConfig()
return sharedLogConfig, nil
}
config := &systemconfigs.LogConfig{}
err = json.Unmarshal(resp.ValueJSON, config)
if err != nil {
logs.Println("[LOG_MANAGER]" + err.Error())
sharedLogConfig = systemconfigs.DefaultLogConfig()
return sharedLogConfig, nil
}
sharedLogConfig = config
return sharedLogConfig, nil
}

View File

@@ -1,17 +1,15 @@
package securitymanager
package configloaders
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/events"
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/iwind/TeaGo/logs"
"reflect"
"sync"
)
var locker sync.Mutex
const (
SecuritySettingName = "adminSecurityConfig"
@@ -20,16 +18,9 @@ const (
FrameSameOrigin = "SAMEORIGIN"
)
var sharedSecurityConfig *SecurityConfig = nil
var sharedSecurityConfig *systemconfigs.SecurityConfig = nil
type SecurityConfig struct {
Frame string `json:"frame"`
AllowCountryIds []int64 `json:"allowCountryIds"`
AllowProvinceIds []int64 `json:"allowProvinceIds"`
AllowLocal bool `json:"allowLocal"`
}
func LoadSecurityConfig() (*SecurityConfig, error) {
func LoadSecurityConfig() (*systemconfigs.SecurityConfig, error) {
locker.Lock()
defer locker.Unlock()
@@ -38,11 +29,11 @@ func LoadSecurityConfig() (*SecurityConfig, error) {
return nil, err
}
v := reflect.Indirect(reflect.ValueOf(config)).Interface().(SecurityConfig)
v := reflect.Indirect(reflect.ValueOf(config)).Interface().(systemconfigs.SecurityConfig)
return &v, nil
}
func UpdateSecurityConfig(securityConfig *SecurityConfig) error {
func UpdateSecurityConfig(securityConfig *systemconfigs.SecurityConfig) error {
locker.Lock()
defer locker.Unlock()
@@ -69,7 +60,7 @@ func UpdateSecurityConfig(securityConfig *SecurityConfig) error {
return nil
}
func loadSecurityConfig() (*SecurityConfig, error) {
func loadSecurityConfig() (*systemconfigs.SecurityConfig, error) {
if sharedSecurityConfig != nil {
return sharedSecurityConfig, nil
}
@@ -88,7 +79,7 @@ func loadSecurityConfig() (*SecurityConfig, error) {
return sharedSecurityConfig, nil
}
config := &SecurityConfig{}
config := &systemconfigs.SecurityConfig{}
err = json.Unmarshal(resp.ValueJSON, config)
if err != nil {
logs.Println("[SECURITY_MANAGER]" + err.Error())
@@ -99,8 +90,8 @@ func loadSecurityConfig() (*SecurityConfig, error) {
return sharedSecurityConfig, nil
}
func defaultSecurityConfig() *SecurityConfig {
return &SecurityConfig{
func defaultSecurityConfig() *systemconfigs.SecurityConfig {
return &systemconfigs.SecurityConfig{
Frame: FrameSameOrigin,
AllowLocal: true,
}

View File

@@ -1,4 +1,4 @@
package securitymanager
package configloaders
import (
_ "github.com/iwind/TeaGo/bootstrap"

View File

@@ -1,30 +1,21 @@
package uimanager
package configloaders
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/iwind/TeaGo/logs"
"reflect"
"sync"
)
var sharedUIConfig *UIConfig = nil
var locker sync.Mutex
var sharedUIConfig *systemconfigs.UIConfig = nil
const (
UISettingName = "adminUIConfig"
)
type UIConfig struct {
ProductName string `json:"productName"` // 产品名
AdminSystemName string `json:"adminSystemName"` // 管理员系统名称
ShowOpenSourceInfo bool `json:"showOpenSourceInfo"` // 是否显示开源信息
ShowVersion bool `json:"showVersion"` // 是否显示版本号
Version string `json:"version"` // 显示的版本号
}
func LoadUIConfig() (*UIConfig, error) {
func LoadUIConfig() (*systemconfigs.UIConfig, error) {
locker.Lock()
defer locker.Unlock()
@@ -33,11 +24,11 @@ func LoadUIConfig() (*UIConfig, error) {
return nil, err
}
v := reflect.Indirect(reflect.ValueOf(config)).Interface().(UIConfig)
v := reflect.Indirect(reflect.ValueOf(config)).Interface().(systemconfigs.UIConfig)
return &v, nil
}
func UpdateUIConfig(uiConfig *UIConfig) error {
func UpdateUIConfig(uiConfig *systemconfigs.UIConfig) error {
locker.Lock()
defer locker.Unlock()
@@ -61,7 +52,7 @@ func UpdateUIConfig(uiConfig *UIConfig) error {
return nil
}
func loadUIConfig() (*UIConfig, error) {
func loadUIConfig() (*systemconfigs.UIConfig, error) {
if sharedUIConfig != nil {
return sharedUIConfig, nil
}
@@ -80,7 +71,7 @@ func loadUIConfig() (*UIConfig, error) {
return sharedUIConfig, nil
}
config := &UIConfig{}
config := &systemconfigs.UIConfig{}
err = json.Unmarshal(resp.ValueJSON, config)
if err != nil {
logs.Println("[UI_MANAGER]" + err.Error())
@@ -91,8 +82,8 @@ func loadUIConfig() (*UIConfig, error) {
return sharedUIConfig, nil
}
func defaultUIConfig() *UIConfig {
return &UIConfig{
func defaultUIConfig() *systemconfigs.UIConfig {
return &systemconfigs.UIConfig{
ProductName: "GoEdge",
AdminSystemName: "GoEdge管理员系统",
ShowOpenSourceInfo: true,

View File

@@ -1,4 +1,4 @@
package uimanager
package configloaders
import (
_ "github.com/iwind/TeaGo/bootstrap"
@@ -6,7 +6,7 @@ import (
"time"
)
func TestLoadSecurityConfig(t *testing.T) {
func TestLoadUIConfig(t *testing.T) {
for i := 0; i < 10; i++ {
before := time.Now()
config, err := LoadUIConfig()

View File

@@ -2,11 +2,11 @@ package index
import (
"fmt"
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
"github.com/TeaOSLab/EdgeAdmin/internal/setup"
"github.com/TeaOSLab/EdgeAdmin/internal/uimanager"
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
@@ -50,7 +50,7 @@ func (this *IndexAction) RunGet(params struct {
this.Data["token"] = stringutil.Md5(TokenSalt+timestamp) + timestamp
this.Data["from"] = params.From
config, err := uimanager.LoadUIConfig()
config, err := configloaders.LoadUIConfig()
if err != nil {
this.ErrorPage(err)
return

View File

@@ -0,0 +1,100 @@
package log
import (
"fmt"
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
)
type CleanAction struct {
actionutils.ParentAction
}
func (this *CleanAction) Init() {
this.Nav("", "", "clean")
}
func (this *CleanAction) RunGet(params struct{}) {
// 读取配置
config, err := configloaders.LoadLogConfig()
if err != nil {
this.ErrorPage(err)
return
}
if !config.CanClean {
this.WriteString("已设置不能清理")
return
}
this.Data["logConfig"] = config
sizeResp, err := this.RPC().LogRPC().SumLogsSize(this.AdminContext(), &pb.SumLogsSizeRequest{})
if err != nil {
this.ErrorPage(err)
return
}
sizeHuman := ""
if sizeResp.SizeBytes < 1024 {
sizeHuman = numberutils.FormatInt64(sizeResp.SizeBytes) + "字节"
} else if sizeResp.SizeBytes < 1024*1024 {
sizeHuman = fmt.Sprintf("%.2fK", float64(sizeResp.SizeBytes)/1024)
} else if sizeResp.SizeBytes < 1024*1024*1024 {
sizeHuman = fmt.Sprintf("%.2fM", float64(sizeResp.SizeBytes)/1024/1024)
} else {
sizeHuman = fmt.Sprintf("%.2fG", float64(sizeResp.SizeBytes)/1024/1024/1024)
}
this.Data["size"] = sizeHuman
this.Show()
}
func (this *CleanAction) RunPost(params struct {
Type string
Days int32
Must *actions.Must
CSRF *actionutils.CSRF
}) {
// 读取配置
config, err := configloaders.LoadLogConfig()
if err != nil {
this.ErrorPage(err)
return
}
if !config.CanClean {
this.WriteString("已设置不能清理")
return
}
switch params.Type {
case "all":
defer this.CreateLogInfo("清除全部日志")
_, err := this.RPC().LogRPC().CleanLogsPermanently(this.AdminContext(), &pb.CleanLogsPermanentlyRequest{
Days: 0,
ClearAll: true,
})
if err != nil {
this.ErrorPage(err)
return
}
case "days":
defer this.CreateLogInfo("清除 %d 以前的日志", params.Days)
_, err := this.RPC().LogRPC().CleanLogsPermanently(this.AdminContext(), &pb.CleanLogsPermanentlyRequest{
Days: params.Days,
ClearAll: false,
})
if err != nil {
this.ErrorPage(err)
return
}
default:
this.Fail("不支持的清理方式 '" + params.Type + "'")
}
this.Success()
}

View File

@@ -0,0 +1,37 @@
package log
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"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 {
LogId int64
}) {
// 读取配置
config, err := configloaders.LoadLogConfig()
if err != nil {
this.ErrorPage(err)
return
}
if !config.CanDelete {
this.Fail("已设置不能删除")
}
// 记录日志
defer this.CreateLogInfo("删除单个操作日志 %d", params.LogId)
// 执行删除
_, err = this.RPC().LogRPC().DeleteLogPermanently(this.AdminContext(), &pb.DeleteLogPermanentlyRequest{LogId: params.LogId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -1,6 +1,7 @@
package log
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/lists"
@@ -14,7 +15,7 @@ type IndexAction struct {
}
func (this *IndexAction) Init() {
this.Nav("log", "log", "")
this.Nav("log", "log", "list")
}
func (this *IndexAction) RunGet(params struct {
@@ -22,6 +23,14 @@ func (this *IndexAction) RunGet(params struct {
DayTo string
Keyword string
}) {
// 读取配置
config, err := configloaders.LoadLogConfig()
if err != nil {
this.ErrorPage(err)
return
}
this.Data["logConfig"] = config
this.Data["dayFrom"] = params.DayFrom
this.Data["dayTo"] = params.DayTo
this.Data["keyword"] = params.Keyword
@@ -76,6 +85,7 @@ func (this *IndexAction) RunGet(params struct {
}
logMaps = append(logMaps, maps.Map{
"id": log.Id,
"description": log.Description,
"userName": log.UserName,
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),

View File

@@ -13,6 +13,9 @@ func init() {
Prefix("/log").
Get("", new(IndexAction)).
Get("/exportExcel", new(ExportExcelAction)).
Post("/delete", new(DeleteAction)).
GetPost("/clean", new(CleanAction)).
GetPost("/settings", new(SettingsAction)).
EndAll()
})

View File

@@ -0,0 +1,63 @@
package log
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/actions"
)
type SettingsAction struct {
actionutils.ParentAction
}
func (this *SettingsAction) Init() {
this.Nav("", "", "setting")
}
func (this *SettingsAction) RunGet(params struct{}) {
config, err := configloaders.LoadLogConfig()
if err != nil {
this.ErrorPage(err)
return
}
this.Data["logConfig"] = config
this.Show()
}
func (this *SettingsAction) RunPost(params struct {
CanDelete bool
CanClean bool
CapacityJSON []byte
Days int
Must *actions.Must
CSRF *actionutils.CSRF
}) {
capacity := &shared.SizeCapacity{}
err := json.Unmarshal(params.CapacityJSON, capacity)
if err != nil {
this.ErrorPage(err)
return
}
config, err := configloaders.LoadLogConfig()
if err != nil {
this.ErrorPage(err)
return
}
config.CanDelete = params.CanDelete
config.CanClean = params.CanClean
config.Days = params.Days
config.Capacity = capacity
err = configloaders.UpdateLogConfig(config)
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -2,7 +2,7 @@ package security
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/securitymanager"
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
@@ -18,7 +18,7 @@ func (this *IndexAction) Init() {
}
func (this *IndexAction) RunGet(params struct{}) {
config, err := securitymanager.LoadSecurityConfig()
config, err := configloaders.LoadSecurityConfig()
if err != nil {
this.ErrorPage(err)
return
@@ -75,7 +75,7 @@ func (this *IndexAction) RunPost(params struct {
}) {
defer this.CreateLogInfo("修改管理界面安全设置")
config, err := securitymanager.LoadSecurityConfig()
config, err := configloaders.LoadSecurityConfig()
if err != nil {
this.ErrorPage(err)
return
@@ -109,7 +109,7 @@ func (this *IndexAction) RunPost(params struct {
// 允许本地
config.AllowLocal = params.AllowLocal
err = securitymanager.UpdateSecurityConfig(config)
err = configloaders.UpdateSecurityConfig(config)
if err != nil {
this.ErrorPage(err)
return

View File

@@ -1,7 +1,7 @@
package server
import (
"github.com/TeaOSLab/EdgeAdmin/internal/uimanager"
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
)
@@ -15,7 +15,7 @@ func (this *IndexAction) Init() {
}
func (this *IndexAction) RunGet(params struct{}) {
config, err := uimanager.LoadUIConfig()
config, err := configloaders.LoadUIConfig()
if err != nil {
this.ErrorPage(err)
return
@@ -41,7 +41,7 @@ func (this *IndexAction) RunPost(params struct {
Field("adminSystemName", params.AdminSystemName).
Require("请输入管理员系统名称")
config, err := uimanager.LoadUIConfig()
config, err := configloaders.LoadUIConfig()
if err != nil {
this.ErrorPage(err)
return
@@ -51,7 +51,7 @@ func (this *IndexAction) RunPost(params struct {
config.ShowOpenSourceInfo = params.ShowOpenSourceInfo
config.ShowVersion = params.ShowVersion
config.Version = params.Version
err = uimanager.UpdateUIConfig(config)
err = configloaders.UpdateUIConfig(config)
if err != nil {
this.ErrorPage(err)
return

View File

@@ -1,11 +1,10 @@
package helpers
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
nodes "github.com/TeaOSLab/EdgeAdmin/internal/rpc"
"github.com/TeaOSLab/EdgeAdmin/internal/securitymanager"
"github.com/TeaOSLab/EdgeAdmin/internal/setup"
"github.com/TeaOSLab/EdgeAdmin/internal/uimanager"
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
@@ -28,7 +27,7 @@ func (this *UserMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramNam
var action = actionPtr.Object()
// 安全相关
securityConfig, _ := securitymanager.LoadSecurityConfig()
securityConfig, _ := configloaders.LoadSecurityConfig()
if securityConfig == nil {
action.AddHeader("X-Frame-Options", "SAMEORIGIN")
} else if len(securityConfig.Frame) > 0 {
@@ -84,7 +83,7 @@ func (this *UserMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramNam
return true
}
config, err := uimanager.LoadUIConfig()
config, err := configloaders.LoadUIConfig()
if err != nil {
action.WriteString(err.Error())
return false
@@ -206,16 +205,16 @@ func (this *UserMustAuth) modules() []maps.Map {
},
},
},
{
"code": "log",
"name": "日志审计",
"icon": "history",
},
{
"code": "settings",
"name": "系统设置",
"icon": "setting",
},
{
"code": "log",
"name": "操作日志",
"icon": "history",
},
}
}

View File

@@ -1,7 +1,7 @@
package helpers
import (
"github.com/TeaOSLab/EdgeAdmin/internal/securitymanager"
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
"github.com/iwind/TeaGo/actions"
"net/http"
@@ -16,7 +16,7 @@ func (this *UserShouldAuth) BeforeAction(actionPtr actions.ActionWrapper, paramN
// 安全相关
action := this.action
securityConfig, _ := securitymanager.LoadSecurityConfig()
securityConfig, _ := configloaders.LoadSecurityConfig()
if securityConfig == nil {
action.AddHeader("X-Frame-Options", "SAMEORIGIN")
} else if len(securityConfig.Frame) > 0 {

View File

@@ -3,8 +3,8 @@ package helpers
import (
"github.com/TeaOSLab/EdgeAdmin/internal/events"
nodes "github.com/TeaOSLab/EdgeAdmin/internal/rpc"
"github.com/TeaOSLab/EdgeAdmin/internal/securitymanager"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/logs"
"net"
@@ -23,7 +23,7 @@ func init() {
}
// 检查用户IP并支持缓存
func checkIP(config *securitymanager.SecurityConfig, ipAddr string) bool {
func checkIP(config *systemconfigs.SecurityConfig, ipAddr string) bool {
ipCacheLocker.Lock()
ipCache, ok := ipCacheMap[ipAddr]
if ok && ipCache {
@@ -46,7 +46,7 @@ func checkIP(config *securitymanager.SecurityConfig, ipAddr string) bool {
}
// 检查用户IP
func checkIPWithoutCache(config *securitymanager.SecurityConfig, ipAddr string) bool {
func checkIPWithoutCache(config *systemconfigs.SecurityConfig, ipAddr string) bool {
if config == nil {
return true
}

View File

@@ -1,5 +1,5 @@
Vue.component("size-capacity-box", {
props: ["v-name", "v-value", "v-count", "v-unit"],
props: ["v-name", "v-value", "v-count", "v-unit", "size", "maxlength"],
data: function () {
let v = this.vValue
if (v == null) {
@@ -11,38 +11,51 @@ Vue.component("size-capacity-box", {
if (typeof (v["count"]) != "number") {
v["count"] = -1
}
let vSize = this.size
if (vSize == null) {
vSize = 6
}
let vMaxlength = this.maxlength
if (vMaxlength == null) {
vMaxlength = 10
}
return {
size: v,
countString: (v.count >= 0) ? v.count.toString() : ""
capacity: v,
countString: (v.count >= 0) ? v.count.toString() : "",
vSize: vSize,
vMaxlength: vMaxlength
}
},
watch: {
"countString": function (newValue) {
let value = newValue.trim()
if (value.length == 0) {
this.size.count = -1
this.capacity.count = -1
this.change()
return
}
let count = parseInt(value)
if (!isNaN(count)) {
this.size.count = count
this.capacity.count = count
}
this.change()
}
},
methods: {
change: function () {
this.$emit("change", this.size)
this.$emit("change", this.capacity)
}
},
template: `<div class="ui fields inline">
<input type="hidden" :name="vName" :value="JSON.stringify(size)"/>
<input type="hidden" :name="vName" :value="JSON.stringify(capacity)"/>
<div class="ui field">
<input type="text" v-model="countString" maxlength="11" size="11"/>
<input type="text" v-model="countString" :maxlength="vMaxlength" :size="vSize"/>
</div>
<div class="ui field">
<select class="ui dropdown" v-model="size.unit" @change="change">
<select class="ui dropdown" v-model="capacity.unit" @change="change">
<option value="byte">字节</option>
<option value="kb">KB</option>
<option value="mb">MB</option>

View File

@@ -0,0 +1,5 @@
<first-menu>
<menu-item href="/log" code="list">查询</menu-item>
<menu-item href="/log/clean" code="clean" v-if="logConfig.canClean">清理</menu-item>
<menu-item href="/log/settings" code="setting">设置</menu-item>
</first-menu>

View File

@@ -0,0 +1,31 @@
{$layout}
{$template "menu"}
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token>
<table class="ui table definition selectable">
<!--<tr>
<td>当前用量</td>
<td>{{size}}</td>
</tr>-->
<tr>
<td class="title" :class="{'color-border':cleanType == 'days'}">清理方式</td>
<td>
<radio name="type" v-model="cleanType" :v-value="'all'">全部清除</radio> &nbsp; &nbsp;
<radio name="type" v-model="cleanType" :v-value="'days'">按天数清除</radio>
</td>
</tr>
<tr v-show="cleanType == 'days'">
<td :class="{'color-border':cleanType == 'days'}">天数</td>
<td>
<div class="ui input right labeled">
<input type="text" name="days" v-model="days" style="width:5em" maxlength="3"/>
<span class="ui label">天以外</span>
</div>
<p class="comment">表示清除此天数以外的日志数据。</p>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>

View File

@@ -0,0 +1,6 @@
Tea.context(function () {
this.cleanType = "all"
this.days = 30
this.success = NotifyReloadSuccess("清理完成")
})

View File

@@ -0,0 +1,8 @@
.log-row {
position: relative;
}
.log-row .buttons {
position: absolute;
right: 1em;
}
/*# sourceMappingURL=index.css.map */

View File

@@ -0,0 +1 @@
{"version":3,"sources":["index.less"],"names":[],"mappings":"AAAA;EACC,kBAAA;;AADD,QAGC;EACC,kBAAA;EACA,UAAA","file":"index.css"}

View File

@@ -1,4 +1,5 @@
{$layout}
{$template "menu"}
{$var "header"}
<!-- datepicker -->
@@ -9,7 +10,6 @@
<link rel="stylesheet" href="/js/pikaday.triangle.css"/>
{$end}
<div class="margin"></div>
<form method="get" action="/log" class="ui form" autocomplete="off">
@@ -42,9 +42,11 @@
<table class="ui table selectable" v-for="log in logs">
<tr :class="{error: log.level == 'error', warning: log.level == 'warn'}">
<td>{{log.createdTime}} <span class="grey"> <span
<td class="log-row">{{log.createdTime}} <span class="grey"> <span
v-if="log.userName.length > 0">| {{log.userName}}</span> | {{log.ip}}<span
v-if="log.region.length > 0"> | {{log.region}}</span> &nbsp; <a href="" @click.prevent="showMore(log)" title="显示更多">...</a> &nbsp;<span v-if="log.moreVisible">{{log.action}}</span></span></td>
v-if="log.region.length > 0"> | {{log.region}}</span> &nbsp; <a href="" @click.prevent="showMore(log)" title="显示更多">...</a> &nbsp;<span v-if="log.moreVisible">{{log.action}}</span></span>
<span class="buttons"><a v-if="logConfig.canDelete" href="" title="删除" @click.prevent="deleteLog(log.id)"><i class="icon remove small"></i></a> </span>
</td>
</tr>
<tr :class="{error: log.level == 'error', warning: log.level == 'warn'}">
<td>{{log.description}}</td>

View File

@@ -18,4 +18,15 @@ Tea.context(function () {
window.location = "/log/exportExcel?dayFrom=" + that.dayFrom + "&dayTo=" + that.dayTo + "&keyword=" + that.keyword
})
}
this.deleteLog = function (logId) {
let that = this
teaweb.confirm("确定要删除此日志吗?", function () {
that.$post(".delete")
.params({
logId: logId
})
.refresh()
})
}
})

View File

@@ -0,0 +1,8 @@
.log-row {
position: relative;
.buttons {
position: absolute;
right: 1em;
}
}

View File

@@ -0,0 +1,37 @@
{$layout}
{$template "menu"}
<form method="post" class="ui form" data-tea-success="success" data-tea-action="$">
<csrf-token></csrf-token>
<table class="ui table definition selectable">
<tr>
<td class="title">是否可以手动删除日志</td>
<td>
<checkbox name="canDelete" v-model="logConfig.canDelete"></checkbox>
</td>
</tr>
<tr>
<td>是否可以手动清理</td>
<td>
<checkbox name="canClean" v-model="logConfig.canClean"></checkbox>
</td>
</tr>
<tr>
<td>日志保留天数</td>
<td>
<input type="text" name="days" v-model="logConfig.days" style="width:5em" maxlength="3"/>
<p class="comment">超过此天数的日志将会被自动清理0表示不自动清理。</p>
</td>
</tr>
<tr>
<td>最大容量限制</td>
<td>
<size-capacity-box :v-name="'capacityJSON'" :v-value="logConfig.capacity"></size-capacity-box>
<p class="comment">超出此容量限制后将会发送提醒。</p>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>

View File

@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
})