From 68baf8ee60b788b2b05062f10190fa0b27807424 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 2 Dec 2020 20:31:42 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=97=A5=E5=BF=97=E5=AE=A1=E8=AE=A1]=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=88=A0=E9=99=A4=E3=80=81=E6=B8=85=E7=90=86=E5=92=8C?= =?UTF-8?q?=E5=88=AB=E7=9A=84=E4=B8=80=E4=BA=9B=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/configloaders/locker.go | 5 + internal/configloaders/log_config.go | 83 +++++++++++++++ .../security_config.go | 29 ++--- .../security_config_test.go | 2 +- .../{uimanager => configloaders}/ui_config.go | 29 ++--- .../ui_config_test.go | 4 +- internal/web/actions/default/index/index.go | 4 +- internal/web/actions/default/log/clean.go | 100 ++++++++++++++++++ internal/web/actions/default/log/delete.go | 37 +++++++ internal/web/actions/default/log/index.go | 12 ++- internal/web/actions/default/log/init.go | 3 + internal/web/actions/default/log/settings.go | 63 +++++++++++ .../default/settings/security/index.go | 8 +- .../web/actions/default/settings/ui/index.go | 8 +- internal/web/helpers/user_must_auth.go | 17 ++- internal/web/helpers/user_should_auth.go | 4 +- internal/web/helpers/utils.go | 6 +- .../js/components/common/size-capacity-box.js | 31 ++++-- web/views/@default/log/@menu.html | 5 + web/views/@default/log/clean.html | 31 ++++++ web/views/@default/log/clean.js | 6 ++ web/views/@default/log/index.css | 8 ++ web/views/@default/log/index.css.map | 1 + web/views/@default/log/index.html | 8 +- web/views/@default/log/index.js | 11 ++ web/views/@default/log/index.less | 8 ++ web/views/@default/log/settings.html | 37 +++++++ web/views/@default/log/settings.js | 3 + 28 files changed, 485 insertions(+), 78 deletions(-) create mode 100644 internal/configloaders/locker.go create mode 100644 internal/configloaders/log_config.go rename internal/{securitymanager => configloaders}/security_config.go (72%) rename internal/{securitymanager => configloaders}/security_config_test.go (95%) rename internal/{uimanager => configloaders}/ui_config.go (66%) rename internal/{uimanager => configloaders}/ui_config_test.go (87%) create mode 100644 internal/web/actions/default/log/clean.go create mode 100644 internal/web/actions/default/log/delete.go create mode 100644 internal/web/actions/default/log/settings.go create mode 100644 web/views/@default/log/@menu.html create mode 100644 web/views/@default/log/clean.html create mode 100644 web/views/@default/log/clean.js create mode 100644 web/views/@default/log/index.css create mode 100644 web/views/@default/log/index.css.map create mode 100644 web/views/@default/log/index.less create mode 100644 web/views/@default/log/settings.html create mode 100644 web/views/@default/log/settings.js diff --git a/internal/configloaders/locker.go b/internal/configloaders/locker.go new file mode 100644 index 00000000..e0976cdf --- /dev/null +++ b/internal/configloaders/locker.go @@ -0,0 +1,5 @@ +package configloaders + +import "sync" + +var locker sync.Mutex diff --git a/internal/configloaders/log_config.go b/internal/configloaders/log_config.go new file mode 100644 index 00000000..c6283570 --- /dev/null +++ b/internal/configloaders/log_config.go @@ -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 +} diff --git a/internal/securitymanager/security_config.go b/internal/configloaders/security_config.go similarity index 72% rename from internal/securitymanager/security_config.go rename to internal/configloaders/security_config.go index ca24342e..6861ad2b 100644 --- a/internal/securitymanager/security_config.go +++ b/internal/configloaders/security_config.go @@ -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, } diff --git a/internal/securitymanager/security_config_test.go b/internal/configloaders/security_config_test.go similarity index 95% rename from internal/securitymanager/security_config_test.go rename to internal/configloaders/security_config_test.go index 5927bdc2..b685fc71 100644 --- a/internal/securitymanager/security_config_test.go +++ b/internal/configloaders/security_config_test.go @@ -1,4 +1,4 @@ -package securitymanager +package configloaders import ( _ "github.com/iwind/TeaGo/bootstrap" diff --git a/internal/uimanager/ui_config.go b/internal/configloaders/ui_config.go similarity index 66% rename from internal/uimanager/ui_config.go rename to internal/configloaders/ui_config.go index 8c151abb..566a8b48 100644 --- a/internal/uimanager/ui_config.go +++ b/internal/configloaders/ui_config.go @@ -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, diff --git a/internal/uimanager/ui_config_test.go b/internal/configloaders/ui_config_test.go similarity index 87% rename from internal/uimanager/ui_config_test.go rename to internal/configloaders/ui_config_test.go index 331e0d8f..bdd805a0 100644 --- a/internal/uimanager/ui_config_test.go +++ b/internal/configloaders/ui_config_test.go @@ -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() diff --git a/internal/web/actions/default/index/index.go b/internal/web/actions/default/index/index.go index 1750c885..f6cd8fd2 100644 --- a/internal/web/actions/default/index/index.go +++ b/internal/web/actions/default/index/index.go @@ -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 diff --git a/internal/web/actions/default/log/clean.go b/internal/web/actions/default/log/clean.go new file mode 100644 index 00000000..7ac0e4e5 --- /dev/null +++ b/internal/web/actions/default/log/clean.go @@ -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() +} diff --git a/internal/web/actions/default/log/delete.go b/internal/web/actions/default/log/delete.go new file mode 100644 index 00000000..accd97bc --- /dev/null +++ b/internal/web/actions/default/log/delete.go @@ -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() +} diff --git a/internal/web/actions/default/log/index.go b/internal/web/actions/default/log/index.go index c1196453..f5513ac7 100644 --- a/internal/web/actions/default/log/index.go +++ b/internal/web/actions/default/log/index.go @@ -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), diff --git a/internal/web/actions/default/log/init.go b/internal/web/actions/default/log/init.go index 145631ad..14c428a2 100644 --- a/internal/web/actions/default/log/init.go +++ b/internal/web/actions/default/log/init.go @@ -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() }) diff --git a/internal/web/actions/default/log/settings.go b/internal/web/actions/default/log/settings.go new file mode 100644 index 00000000..928b5bbd --- /dev/null +++ b/internal/web/actions/default/log/settings.go @@ -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() +} diff --git a/internal/web/actions/default/settings/security/index.go b/internal/web/actions/default/settings/security/index.go index 68f4d100..ae96eb0e 100644 --- a/internal/web/actions/default/settings/security/index.go +++ b/internal/web/actions/default/settings/security/index.go @@ -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 diff --git a/internal/web/actions/default/settings/ui/index.go b/internal/web/actions/default/settings/ui/index.go index b15801b1..891d372d 100644 --- a/internal/web/actions/default/settings/ui/index.go +++ b/internal/web/actions/default/settings/ui/index.go @@ -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 diff --git a/internal/web/helpers/user_must_auth.go b/internal/web/helpers/user_must_auth.go index 961c1971..a6b4e363 100644 --- a/internal/web/helpers/user_must_auth.go +++ b/internal/web/helpers/user_must_auth.go @@ -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", - }, } } diff --git a/internal/web/helpers/user_should_auth.go b/internal/web/helpers/user_should_auth.go index f78eab13..c6917c10 100644 --- a/internal/web/helpers/user_should_auth.go +++ b/internal/web/helpers/user_should_auth.go @@ -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 { diff --git a/internal/web/helpers/utils.go b/internal/web/helpers/utils.go index 420cf7e6..eaac2d28 100644 --- a/internal/web/helpers/utils.go +++ b/internal/web/helpers/utils.go @@ -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 } diff --git a/web/public/js/components/common/size-capacity-box.js b/web/public/js/components/common/size-capacity-box.js index c912e03f..0f6751e5 100644 --- a/web/public/js/components/common/size-capacity-box.js +++ b/web/public/js/components/common/size-capacity-box.js @@ -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: `
- +
- +
- diff --git a/web/views/@default/log/@menu.html b/web/views/@default/log/@menu.html new file mode 100644 index 00000000..a189e2b6 --- /dev/null +++ b/web/views/@default/log/@menu.html @@ -0,0 +1,5 @@ + + 查询 + 清理 + 设置 + \ No newline at end of file diff --git a/web/views/@default/log/clean.html b/web/views/@default/log/clean.html new file mode 100644 index 00000000..dc76bffe --- /dev/null +++ b/web/views/@default/log/clean.html @@ -0,0 +1,31 @@ +{$layout} +{$template "menu"} + +
+ + + + + + + + + + + + +
清理方式 + 全部清除     + 按天数清除 +
天数 +
+ + 天以外 +
+

表示清除此天数以外的日志数据。

+
+ +
\ No newline at end of file diff --git a/web/views/@default/log/clean.js b/web/views/@default/log/clean.js new file mode 100644 index 00000000..261091d3 --- /dev/null +++ b/web/views/@default/log/clean.js @@ -0,0 +1,6 @@ +Tea.context(function () { + this.cleanType = "all" + this.days = 30 + + this.success = NotifyReloadSuccess("清理完成") +}) \ No newline at end of file diff --git a/web/views/@default/log/index.css b/web/views/@default/log/index.css new file mode 100644 index 00000000..5b702f89 --- /dev/null +++ b/web/views/@default/log/index.css @@ -0,0 +1,8 @@ +.log-row { + position: relative; +} +.log-row .buttons { + position: absolute; + right: 1em; +} +/*# sourceMappingURL=index.css.map */ \ No newline at end of file diff --git a/web/views/@default/log/index.css.map b/web/views/@default/log/index.css.map new file mode 100644 index 00000000..09181fef --- /dev/null +++ b/web/views/@default/log/index.css.map @@ -0,0 +1 @@ +{"version":3,"sources":["index.less"],"names":[],"mappings":"AAAA;EACC,kBAAA;;AADD,QAGC;EACC,kBAAA;EACA,UAAA","file":"index.css"} \ No newline at end of file diff --git a/web/views/@default/log/index.html b/web/views/@default/log/index.html index 2eb90768..1131695b 100644 --- a/web/views/@default/log/index.html +++ b/web/views/@default/log/index.html @@ -1,4 +1,5 @@ {$layout} +{$template "menu"} {$var "header"} @@ -9,7 +10,6 @@ {$end} -
@@ -42,9 +42,11 @@ - + v-if="log.region.length > 0"> | {{log.region}}   ...  {{log.action}} + + diff --git a/web/views/@default/log/index.js b/web/views/@default/log/index.js index efc3671c..432ce5b7 100644 --- a/web/views/@default/log/index.js +++ b/web/views/@default/log/index.js @@ -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() + }) + } }) \ No newline at end of file diff --git a/web/views/@default/log/index.less b/web/views/@default/log/index.less new file mode 100644 index 00000000..3b928eb5 --- /dev/null +++ b/web/views/@default/log/index.less @@ -0,0 +1,8 @@ +.log-row { + position: relative; + + .buttons { + position: absolute; + right: 1em; + } +} \ No newline at end of file diff --git a/web/views/@default/log/settings.html b/web/views/@default/log/settings.html new file mode 100644 index 00000000..e5bda586 --- /dev/null +++ b/web/views/@default/log/settings.html @@ -0,0 +1,37 @@ +{$layout} +{$template "menu"} + + + + +
{{log.createdTime}} {{log.createdTime}} | {{log.userName}} | {{log.ip}} | {{log.region}}   ...  {{log.action}}
{{log.description}}
+ + + + + + + + + + + + + + + + +
是否可以手动删除日志 + +
是否可以手动清理 + +
日志保留天数 + +

超过此天数的日志将会被自动清理,0表示不自动清理。

+
最大容量限制 + +

超出此容量限制后将会发送提醒。

+
+ + +
\ No newline at end of file diff --git a/web/views/@default/log/settings.js b/web/views/@default/log/settings.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/log/settings.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file