From 370463366b0b1675c2655fecc7a663850706f6ca Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Mon, 5 Aug 2024 18:22:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86?= =?UTF-8?q?=E7=9B=91=E6=8E=A7=E6=8E=A5=E5=8F=A3=20(#6033)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent/app/api/v1/entry.go | 1 + agent/app/api/v1/monitor.go | 104 +++++++----------- agent/app/dto/host.go | 12 ++ agent/app/repo/common.go | 7 ++ agent/app/repo/monitor.go | 74 +++++++++++++ agent/app/service/entry.go | 1 + agent/app/service/monitor.go | 96 ++++++++++++++++ agent/app/service/setting.go | 27 ----- agent/init/migration/migrations/init.go | 6 +- agent/middleware/certificate.go | 5 + agent/router/ro_host.go | 2 + agent/server/server.go | 2 +- core/app/api/v1/setting.go | 10 -- core/router/ro_setting.go | 1 - frontend/src/api/interface/host.ts | 6 + frontend/src/api/modules/host.ts | 6 + frontend/src/api/modules/setting.ts | 49 ++++----- frontend/src/lang/modules/en.ts | 3 +- frontend/src/lang/modules/tw.ts | 3 +- frontend/src/lang/modules/zh.ts | 3 +- .../src/layout/components/Sidebar/index.vue | 1 - frontend/src/utils/xpack.ts | 1 - .../src/views/host/monitor/monitor/index.vue | 42 +++---- .../views/host/monitor/setting/days/index.vue | 4 +- .../setting}/default-network/index.vue | 9 +- .../src/views/host/monitor/setting/index.vue | 30 +++-- .../host/monitor/setting/interval/index.vue | 4 +- .../src/views/login/components/login-form.vue | 1 - frontend/src/views/setting/panel/index.vue | 52 --------- 29 files changed, 331 insertions(+), 231 deletions(-) create mode 100644 agent/app/repo/monitor.go rename frontend/src/views/{setting/panel => host/monitor/setting}/default-network/index.vue (88%) diff --git a/agent/app/api/v1/entry.go b/agent/app/api/v1/entry.go index 7bdaa2801..11736d137 100644 --- a/agent/app/api/v1/entry.go +++ b/agent/app/api/v1/entry.go @@ -35,6 +35,7 @@ var ( fileService = service.NewIFileService() sshService = service.NewISSHService() firewallService = service.NewIFirewallService() + monitorService = service.NewIMonitorService() deviceService = service.NewIDeviceService() fail2banService = service.NewIFail2BanService() diff --git a/agent/app/api/v1/monitor.go b/agent/app/api/v1/monitor.go index 33ed2a449..e5b480990 100644 --- a/agent/app/api/v1/monitor.go +++ b/agent/app/api/v1/monitor.go @@ -2,21 +2,17 @@ package v1 import ( "sort" - "time" "github.com/1Panel-dev/1Panel/agent/app/api/v1/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/app/model" "github.com/1Panel-dev/1Panel/agent/constant" - "github.com/1Panel-dev/1Panel/agent/global" - "github.com/1Panel-dev/1Panel/agent/utils/common" "github.com/gin-gonic/gin" "github.com/shirou/gopsutil/v3/disk" "github.com/shirou/gopsutil/v3/net" ) // @Tags Monitor -// @Summary Load monitor datas +// @Summary Load monitor data // @Description 获取监控数据 // @Param request body dto.MonitorSearch true "request" // @Success 200 @@ -28,82 +24,60 @@ func (b *BaseApi) LoadMonitor(c *gin.Context) { return } - loc, _ := time.LoadLocation(common.LoadTimeZone()) - req.StartTime = req.StartTime.In(loc) - req.EndTime = req.EndTime.In(loc) - - var backdatas []dto.MonitorData - if req.Param == "all" || req.Param == "cpu" || req.Param == "memory" || req.Param == "load" { - var bases []model.MonitorBase - if err := global.MonitorDB. - Where("created_at > ? AND created_at < ?", req.StartTime, req.EndTime). - Find(&bases).Error; err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) - return - } - - var itemData dto.MonitorData - itemData.Param = "base" - for _, base := range bases { - itemData.Date = append(itemData.Date, base.CreatedAt) - itemData.Value = append(itemData.Value, base) - } - backdatas = append(backdatas, itemData) + data, err := monitorService.LoadMonitorData(req) + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return } - if req.Param == "all" || req.Param == "io" { - var bases []model.MonitorIO - if err := global.MonitorDB. - Where("created_at > ? AND created_at < ?", req.StartTime, req.EndTime). - Find(&bases).Error; err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) - return - } - - var itemData dto.MonitorData - itemData.Param = "io" - for _, base := range bases { - itemData.Date = append(itemData.Date, base.CreatedAt) - itemData.Value = append(itemData.Value, base) - } - backdatas = append(backdatas, itemData) - } - if req.Param == "all" || req.Param == "network" { - var bases []model.MonitorNetwork - if err := global.MonitorDB. - Where("name = ? AND created_at > ? AND created_at < ?", req.Info, req.StartTime, req.EndTime). - Find(&bases).Error; err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) - return - } - - var itemData dto.MonitorData - itemData.Param = "network" - for _, base := range bases { - itemData.Date = append(itemData.Date, base.CreatedAt) - itemData.Value = append(itemData.Value, base) - } - backdatas = append(backdatas, itemData) - } - helper.SuccessWithData(c, backdatas) + helper.SuccessWithData(c, data) } // @Tags Monitor -// @Summary Clean monitor datas +// @Summary Clean monitor data // @Description 清空监控数据 // @Success 200 // @Security ApiKeyAuth // @Router /hosts/monitor/clean [post] // @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"清空监控数据","formatEN":"clean monitor datas"} func (b *BaseApi) CleanMonitor(c *gin.Context) { - if err := global.MonitorDB.Exec("DELETE FROM monitor_bases").Error; err != nil { + if err := monitorService.CleanData(); err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } - if err := global.MonitorDB.Exec("DELETE FROM monitor_ios").Error; err != nil { + + helper.SuccessWithData(c, nil) +} + +// @Tags Monitor +// @Summary Load monitor setting +// @Description 获取默认监控设置 +// @Success 200 +// @Security ApiKeyAuth +// @Router /hosts/monitor/setting [get] +func (b *BaseApi) LoadMonitorSetting(c *gin.Context) { + setting, err := monitorService.LoadSetting() + if err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } - if err := global.MonitorDB.Exec("DELETE FROM monitor_networks").Error; err != nil { + + helper.SuccessWithData(c, setting) +} + +// @Tags Monitor +// @Summary Update monitor setting +// @Description 更新默认监控设置 +// @Param request body dto.MonitorSettingUpdate true "request" +// @Success 200 +// @Security ApiKeyAuth +// @Router /hosts/monitor/setting/update [post] +// @x-panel-log {"bodyKeys":["key", "value"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"修改默认监控网卡 [name]-[value]","formatEN":"update default monitor [name]-[value]"} +func (b *BaseApi) UpdateMonitorSetting(c *gin.Context) { + var req dto.MonitorSettingUpdate + if err := helper.CheckBindAndValidate(&req, c); err != nil { + return + } + if err := monitorService.UpdateSetting(req.Key, req.Value); err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } diff --git a/agent/app/dto/host.go b/agent/app/dto/host.go index 9853d8f34..e82f221af 100644 --- a/agent/app/dto/host.go +++ b/agent/app/dto/host.go @@ -73,3 +73,15 @@ type TreeChild struct { ID uint `json:"id"` Label string `json:"label"` } + +type MonitorSetting struct { + MonitorStatus string `json:"monitorStatus"` + MonitorStoreDays string `json:"monitorStoreDays"` + MonitorInterval string `json:"monitorInterval"` + DefaultNetwork string `json:"defaultNetwork"` +} + +type MonitorSettingUpdate struct { + Key string `json:"key" validate:"required,oneof=MonitorStatus MonitorStoreDays MonitorInterval DefaultNetwork"` + Value string `json:"value"` +} diff --git a/agent/app/repo/common.go b/agent/app/repo/common.go index 3be569252..a4694d66b 100644 --- a/agent/app/repo/common.go +++ b/agent/app/repo/common.go @@ -22,6 +22,7 @@ type ICommonRepo interface { WithLikeName(name string) DBOption WithIdsIn(ids []uint) DBOption WithByDate(startTime, endTime time.Time) DBOption + WithByCreatedAt(startTime, endTime time.Time) DBOption WithByStartDate(startTime time.Time) DBOption WithByStatus(status string) DBOption WithByFrom(from string) DBOption @@ -51,6 +52,12 @@ func (c *CommonRepo) WithByDate(startTime, endTime time.Time) DBOption { } } +func (c *CommonRepo) WithByCreatedAt(startTime, endTime time.Time) DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Where("created_at > ? AND created_at < ?", startTime, endTime) + } +} + func (c *CommonRepo) WithByStartDate(startTime time.Time) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("start_time < ?", startTime) diff --git a/agent/app/repo/monitor.go b/agent/app/repo/monitor.go new file mode 100644 index 000000000..53e609ecd --- /dev/null +++ b/agent/app/repo/monitor.go @@ -0,0 +1,74 @@ +package repo + +import ( + "time" + + "github.com/1Panel-dev/1Panel/agent/app/model" + "github.com/1Panel-dev/1Panel/agent/global" +) + +type MonitorRepo struct{} + +type IMonitorRepo interface { + GetBase(opts ...DBOption) ([]model.MonitorBase, error) + GetIO(opts ...DBOption) ([]model.MonitorIO, error) + GetNetwork(opts ...DBOption) ([]model.MonitorNetwork, error) + + CreateMonitorBase(model model.MonitorBase) error + BatchCreateMonitorIO(ioList []model.MonitorIO) error + BatchCreateMonitorNet(ioList []model.MonitorNetwork) error + DelMonitorBase(timeForDelete time.Time) error + DelMonitorIO(timeForDelete time.Time) error + DelMonitorNet(timeForDelete time.Time) error +} + +func NewIMonitorRepo() IMonitorRepo { + return &MonitorRepo{} +} + +func (u *MonitorRepo) GetBase(opts ...DBOption) ([]model.MonitorBase, error) { + var data []model.MonitorBase + db := global.DB + for _, opt := range opts { + db = opt(db) + } + err := db.Find(&data).Error + return data, err +} +func (u *MonitorRepo) GetIO(opts ...DBOption) ([]model.MonitorIO, error) { + var data []model.MonitorIO + db := global.DB + for _, opt := range opts { + db = opt(db) + } + err := db.First(&data).Error + return data, err +} +func (u *MonitorRepo) GetNetwork(opts ...DBOption) ([]model.MonitorNetwork, error) { + var data []model.MonitorNetwork + db := global.DB + for _, opt := range opts { + db = opt(db) + } + err := db.First(&data).Error + return data, err +} + +func (u *MonitorRepo) CreateMonitorBase(model model.MonitorBase) error { + return global.MonitorDB.Create(&model).Error +} +func (u *MonitorRepo) BatchCreateMonitorIO(ioList []model.MonitorIO) error { + return global.MonitorDB.CreateInBatches(ioList, len(ioList)).Error +} +func (u *MonitorRepo) BatchCreateMonitorNet(ioList []model.MonitorNetwork) error { + return global.MonitorDB.CreateInBatches(ioList, len(ioList)).Error +} +func (u *MonitorRepo) DelMonitorBase(timeForDelete time.Time) error { + return global.MonitorDB.Where("created_at < ?", timeForDelete).Delete(&model.MonitorBase{}).Error +} +func (u *MonitorRepo) DelMonitorIO(timeForDelete time.Time) error { + return global.MonitorDB.Where("created_at < ?", timeForDelete).Delete(&model.MonitorIO{}).Error +} +func (u *MonitorRepo) DelMonitorNet(timeForDelete time.Time) error { + return global.MonitorDB.Where("created_at < ?", timeForDelete).Delete(&model.MonitorNetwork{}).Error +} diff --git a/agent/app/service/entry.go b/agent/app/service/entry.go index 7b6c5d6d0..8864347fa 100644 --- a/agent/app/service/entry.go +++ b/agent/app/service/entry.go @@ -26,6 +26,7 @@ var ( commandRepo = repo.NewICommandRepo() ftpRepo = repo.NewIFtpRepo() clamRepo = repo.NewIClamRepo() + monitorRepo = repo.NewIMonitorRepo() settingRepo = repo.NewISettingRepo() backupRepo = repo.NewIBackupRepo() diff --git a/agent/app/service/monitor.go b/agent/app/service/monitor.go index 5ea0f47e6..2d87e2a5b 100644 --- a/agent/app/service/monitor.go +++ b/agent/app/service/monitor.go @@ -2,12 +2,16 @@ package service import ( "context" + "encoding/json" "fmt" "strconv" "time" + "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/model" + "github.com/1Panel-dev/1Panel/agent/constant" "github.com/1Panel-dev/1Panel/agent/global" + "github.com/1Panel-dev/1Panel/agent/utils/common" "github.com/robfig/cron/v3" "github.com/shirou/gopsutil/v3/cpu" "github.com/shirou/gopsutil/v3/disk" @@ -25,6 +29,10 @@ var monitorCancel context.CancelFunc type IMonitorService interface { Run() + LoadMonitorData(req dto.MonitorSearch) ([]dto.MonitorData, error) + LoadSetting() (*dto.MonitorSetting, error) + UpdateSetting(key, value string) error + CleanData() error saveIODataToDB(ctx context.Context, interval float64) saveNetDataToDB(ctx context.Context, interval float64) @@ -37,6 +45,94 @@ func NewIMonitorService() IMonitorService { } } +func (m *MonitorService) LoadMonitorData(req dto.MonitorSearch) ([]dto.MonitorData, error) { + loc, _ := time.LoadLocation(common.LoadTimeZone()) + req.StartTime = req.StartTime.In(loc) + req.EndTime = req.EndTime.In(loc) + + var data []dto.MonitorData + if req.Param == "all" || req.Param == "cpu" || req.Param == "memory" || req.Param == "load" { + bases, err := monitorRepo.GetBase(commonRepo.WithByCreatedAt(req.StartTime, req.EndTime)) + if err != nil { + return nil, err + } + + var itemData dto.MonitorData + itemData.Param = "base" + for _, base := range bases { + itemData.Date = append(itemData.Date, base.CreatedAt) + itemData.Value = append(itemData.Value, base) + } + data = append(data, itemData) + } + if req.Param == "all" || req.Param == "io" { + bases, err := monitorRepo.GetIO(commonRepo.WithByCreatedAt(req.StartTime, req.EndTime)) + if err != nil { + return nil, err + } + + var itemData dto.MonitorData + itemData.Param = "io" + for _, base := range bases { + itemData.Date = append(itemData.Date, base.CreatedAt) + itemData.Value = append(itemData.Value, base) + } + data = append(data, itemData) + } + if req.Param == "all" || req.Param == "network" { + bases, err := monitorRepo.GetIO(commonRepo.WithByName(req.Info), commonRepo.WithByCreatedAt(req.StartTime, req.EndTime)) + if err != nil { + return nil, err + } + + var itemData dto.MonitorData + itemData.Param = "network" + for _, base := range bases { + itemData.Date = append(itemData.Date, base.CreatedAt) + itemData.Value = append(itemData.Value, base) + } + data = append(data, itemData) + } + return data, nil +} + +func (m *MonitorService) LoadSetting() (*dto.MonitorSetting, error) { + setting, err := settingRepo.GetList() + if err != nil { + return nil, constant.ErrRecordNotFound + } + settingMap := make(map[string]string) + for _, set := range setting { + settingMap[set.Key] = set.Value + } + var info dto.MonitorSetting + arr, err := json.Marshal(settingMap) + if err != nil { + return nil, err + } + if err := json.Unmarshal(arr, &info); err != nil { + return nil, err + } + return &info, err +} + +func (m *MonitorService) UpdateSetting(key, value string) error { + return settingRepo.Update(key, value) +} + +func (m *MonitorService) CleanData() error { + if err := global.MonitorDB.Exec("DELETE FROM monitor_bases").Error; err != nil { + return err + } + if err := global.MonitorDB.Exec("DELETE FROM monitor_ios").Error; err != nil { + return err + } + if err := global.MonitorDB.Exec("DELETE FROM monitor_networks").Error; err != nil { + return err + } + return nil +} + func (m *MonitorService) Run() { var itemModel model.MonitorBase totalPercent, _ := cpu.Percent(3*time.Second, false) diff --git a/agent/app/service/setting.go b/agent/app/service/setting.go index 5d74d86fb..eaa4aa583 100644 --- a/agent/app/service/setting.go +++ b/agent/app/service/setting.go @@ -6,8 +6,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/constant" - "github.com/1Panel-dev/1Panel/agent/global" - "github.com/robfig/cron/v3" ) type SettingService struct{} @@ -45,31 +43,6 @@ func (u *SettingService) GetSettingInfo() (*dto.SettingInfo, error) { func (u *SettingService) Update(key, value string) error { switch key { - case "MonitorStatus": - if value == "enable" && global.MonitorCronID == 0 { - interval, err := settingRepo.Get(settingRepo.WithByKey("MonitorInterval")) - if err != nil { - return err - } - if err := StartMonitor(false, interval.Value); err != nil { - return err - } - } - if value == "disable" && global.MonitorCronID != 0 { - monitorCancel() - global.Cron.Remove(cron.EntryID(global.MonitorCronID)) - global.MonitorCronID = 0 - } - case "MonitorInterval": - status, err := settingRepo.Get(settingRepo.WithByKey("MonitorStatus")) - if err != nil { - return err - } - if status.Value == "enable" && global.MonitorCronID != 0 { - if err := StartMonitor(true, value); err != nil { - return err - } - } case "AppStoreLastModified": exist, _ := settingRepo.Get(settingRepo.WithByKey("AppStoreLastModified")) if exist.ID == 0 { diff --git a/agent/init/migration/migrations/init.go b/agent/init/migration/migrations/init.go index c8c4afcd1..fb7268b3d 100644 --- a/agent/init/migration/migrations/init.go +++ b/agent/init/migration/migrations/init.go @@ -145,9 +145,6 @@ var InitSetting = &gormigrate.Migration{ return err } - if err := tx.Create(&model.Setting{Key: "DefaultNetwork", Value: "all"}).Error; err != nil { - return err - } if err := tx.Create(&model.Setting{Key: "LastCleanTime", Value: ""}).Error; err != nil { return err } @@ -158,6 +155,9 @@ var InitSetting = &gormigrate.Migration{ return err } + if err := tx.Create(&model.Setting{Key: "DefaultNetwork", Value: "all"}).Error; err != nil { + return err + } if err := tx.Create(&model.Setting{Key: "MonitorStatus", Value: "enable"}).Error; err != nil { return err } diff --git a/agent/middleware/certificate.go b/agent/middleware/certificate.go index c4ca58f12..46e3a2e21 100644 --- a/agent/middleware/certificate.go +++ b/agent/middleware/certificate.go @@ -6,11 +6,16 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v1/helper" "github.com/1Panel-dev/1Panel/agent/constant" + "github.com/1Panel-dev/1Panel/agent/global" "github.com/gin-gonic/gin" ) func Certificate() gin.HandlerFunc { return func(c *gin.Context) { + if global.CurrentNode == "127.0.0.1" || len(global.CurrentNode) == 0 { + c.Next() + return + } if !c.Request.TLS.HandshakeComplete || len(c.Request.TLS.PeerCertificates) == 0 { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, errors.New("no such tls peer certificates")) return diff --git a/agent/router/ro_host.go b/agent/router/ro_host.go index e90e15254..15da26225 100644 --- a/agent/router/ro_host.go +++ b/agent/router/ro_host.go @@ -36,6 +36,8 @@ func (s *HostRouter) InitRouter(Router *gin.RouterGroup) { hostRouter.POST("/monitor/clean", baseApi.CleanMonitor) hostRouter.GET("/monitor/netoptions", baseApi.GetNetworkOptions) hostRouter.GET("/monitor/iooptions", baseApi.GetIOOptions) + hostRouter.GET("/monitor/setting", baseApi.LoadMonitorSetting) + hostRouter.POST("/monitor/setting/update", baseApi.UpdateMonitorSetting) hostRouter.GET("/ssh/conf", baseApi.LoadSSHConf) hostRouter.POST("/ssh/search", baseApi.GetSSHInfo) diff --git a/agent/server/server.go b/agent/server/server.go index c3e1afa80..c7fe46e96 100644 --- a/agent/server/server.go +++ b/agent/server/server.go @@ -44,7 +44,7 @@ func Start() { server := &http.Server{ Handler: rootRouter, } - if global.CurrentNode == "127.0.0.1" { + if len(global.CurrentNode) == 0 || global.CurrentNode == "127.0.0.1" { _ = os.Remove("/tmp/agent.sock") listener, err := net.Listen("unix", "/tmp/agent.sock") if err != nil { diff --git a/core/app/api/v1/setting.go b/core/app/api/v1/setting.go index b5bf4fe6c..d38878214 100644 --- a/core/app/api/v1/setting.go +++ b/core/app/api/v1/setting.go @@ -271,16 +271,6 @@ func (b *BaseApi) HandlePasswordExpired(c *gin.Context) { helper.SuccessWithData(c, nil) } -// @Tags System Setting -// @Summary Load local backup dir -// @Description 获取安装根目录 -// @Success 200 {string} path -// @Security ApiKeyAuth -// @Router /settings/basedir [get] -func (b *BaseApi) LoadBaseDir(c *gin.Context) { - helper.SuccessWithData(c, global.CONF.System.DataDir) -} - // @Tags System Setting // @Summary Load mfa info // @Description 获取 mfa 信息 diff --git a/core/router/ro_setting.go b/core/router/ro_setting.go index c785a5755..047af70ec 100644 --- a/core/router/ro_setting.go +++ b/core/router/ro_setting.go @@ -30,6 +30,5 @@ func (s *SettingRouter) InitRouter(Router *gin.RouterGroup) { settingRouter.POST("/upgrade", baseApi.Upgrade) settingRouter.POST("/upgrade/notes", baseApi.GetNotesByVersion) settingRouter.GET("/upgrade", baseApi.GetUpgradeInfo) - settingRouter.GET("/basedir", baseApi.LoadBaseDir) } } diff --git a/frontend/src/api/interface/host.ts b/frontend/src/api/interface/host.ts index 7cced8c08..c6f202c6e 100644 --- a/frontend/src/api/interface/host.ts +++ b/frontend/src/api/interface/host.ts @@ -128,6 +128,12 @@ export namespace Host { rules: Array; } + export interface MonitorSetting { + defaultNetwork: string; + monitorStatus: string; + monitorStoreDays: string; + monitorInterval: string; + } export interface MonitorData { param: string; date: Array; diff --git a/frontend/src/api/modules/host.ts b/frontend/src/api/modules/host.ts index 172cf55e9..9c7eeb667 100644 --- a/frontend/src/api/modules/host.ts +++ b/frontend/src/api/modules/host.ts @@ -130,6 +130,12 @@ export const getIOOptions = () => { export const cleanMonitors = () => { return http.post(`/hosts/monitor/clean`, {}); }; +export const loadMonitorSetting = () => { + return http.get(`/hosts/monitor/setting`, {}); +}; +export const updateMonitorSetting = (key: string, value: string) => { + return http.post(`/hosts/monitor/setting/update`, { key: key, value: value }); +}; // ssh export const getSSHInfo = () => { diff --git a/frontend/src/api/modules/setting.ts b/frontend/src/api/modules/setting.ts index e2847d308..17bfee87e 100644 --- a/frontend/src/api/modules/setting.ts +++ b/frontend/src/api/modules/setting.ts @@ -6,25 +6,29 @@ import { Backup } from '../interface/backup'; import { Setting } from '../interface/setting'; import { TimeoutEnum } from '@/enums/http-enum'; +// license export const UploadFileData = (params: FormData) => { return http.upload('/licenses/upload', params); }; - export const getLicense = () => { return http.get(`/licenses/get`); }; export const getLicenseStatus = () => { return http.get(`/licenses/get/status`); }; - export const syncLicense = () => { return http.post(`/licenses/sync`); }; - export const unbindLicense = () => { return http.post(`/licenses/unbind`); }; +// agent +export const loadBaseDir = () => { + return http.get(`/settings/basedir`); +}; + +// core export const getSettingInfo = () => { return http.post(`/core/settings/search`); }; @@ -33,11 +37,11 @@ export const getSystemAvailable = () => { }; export const updateSetting = (param: Setting.SettingUpdate) => { - return http.post(`/settings/update`, param); + return http.post(`/core/settings/update`, param); }; export const updateMenu = (param: Setting.SettingUpdate) => { - return http.post(`/settings/menu/update`, param); + return http.post(`/core/settings/menu/update`, param); }; export const updateProxy = (params: Setting.ProxyUpdate) => { @@ -46,60 +50,49 @@ export const updateProxy = (params: Setting.ProxyUpdate) => { request.proxyPasswd = Base64.encode(request.proxyPasswd); } request.proxyType = request.proxyType === 'close' ? '' : request.proxyType; - return http.post(`/settings/proxy/update`, request); + return http.post(`/core/settings/proxy/update`, request); }; export const updatePassword = (param: Setting.PasswordUpdate) => { - return http.post(`/settings/password/update`, param); + return http.post(`/core/settings/password/update`, param); }; export const loadInterfaceAddr = () => { - return http.get(`/settings/interface`); + return http.get(`/core/settings/interface`); }; export const updateBindInfo = (ipv6: string, bindAddress: string) => { - return http.post(`/settings/bind/update`, { ipv6: ipv6, bindAddress: bindAddress }); + return http.post(`/core/settings/bind/update`, { ipv6: ipv6, bindAddress: bindAddress }); }; export const updatePort = (param: Setting.PortUpdate) => { - return http.post(`/settings/port/update`, param); + return http.post(`/core/settings/port/update`, param); }; export const updateSSL = (param: Setting.SSLUpdate) => { - return http.post(`/settings/ssl/update`, param); + return http.post(`/core/settings/ssl/update`, param); }; export const loadSSLInfo = () => { - return http.get(`/settings/ssl/info`); + return http.get(`/core/settings/ssl/info`); }; export const downloadSSL = () => { - return http.download(`settings/ssl/download`); + return http.download(`/core/settings/ssl/download`); }; export const handleExpired = (param: Setting.PasswordUpdate) => { - return http.post(`/settings/expired/handle`, param); -}; - -export const loadTimeZone = () => { - return http.get>(`/settings/time/option`); -}; -export const syncTime = (ntpSite: string) => { - return http.post(`/settings/time/sync`, { ntpSite: ntpSite }); + return http.post(`/core/settings/expired/handle`, param); }; export const loadMFA = (param: Setting.MFARequest) => { - return http.post(`/settings/mfa`, param); + return http.post(`/core/settings/mfa`, param); }; export const loadDaemonJsonPath = () => { - return http.get(`/settings/daemonjson`, {}); + return http.get(`/core/settings/daemonjson`, {}); }; export const bindMFA = (param: Setting.MFABind) => { - return http.post(`/settings/mfa/bind`, param); -}; - -export const loadBaseDir = () => { - return http.get(`/settings/basedir`); + return http.post(`/core/settings/mfa/bind`, param); }; // backup diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 61ec05bc5..eae10e5ef 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -932,6 +932,8 @@ const message = { globalFilter: 'Global Filter', enableMonitor: 'Enable', storeDays: 'Expiration days', + defaultNetwork: 'Default Network Adapter', + defaultNetworkHelper: 'Network adapter option displayed in the default monitoring and overview interface', cleanMonitor: 'Clearing monitoring records', avgLoad: 'Average load', @@ -1381,7 +1383,6 @@ const message = { proxyPasswdKeep: 'Remember Password', systemIPWarning: 'The server address is not currently set. Please set it in the control panel first!', systemIPWarning1: 'The current server address is set to {0}, and quick redirection is not possible!', - defaultNetwork: 'Network Card', syncTime: 'Server Time', timeZone: 'Time Zone', timeZoneChangeHelper: 'Changing the time zone requires restarting the service. Do you want to continue?', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 7c5b991d1..70f02afdd 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -887,6 +887,8 @@ const message = { globalFilter: '全局過濾', enableMonitor: '監控狀態', storeDays: '保存天數', + defaultNetwork: '預設網卡', + defaultNetworkHelper: '預設監控和概覽介面顯示的網卡選項', cleanMonitor: '清空監控記錄', avgLoad: '平均負載', @@ -1307,7 +1309,6 @@ const message = { proxyPasswdKeep: '記住密碼', systemIPWarning: '當前未設置服務器地址,請先在面板設置中設置!', systemIPWarning1: '當前服務器地址設置為 {0},無法快速跳轉!', - defaultNetwork: '默認網卡', changePassword: '密碼修改', oldPassword: '原密碼', newPassword: '新密碼', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index daecd2620..a53e2c4bd 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -888,6 +888,8 @@ const message = { globalFilter: '全局过滤', enableMonitor: '监控状态', storeDays: '保存天数', + defaultNetwork: '默认网卡', + defaultNetworkHelper: '默认监控和概览界面显示的网卡选项', cleanMonitor: '清空监控记录', avgLoad: '平均负载', @@ -1309,7 +1311,6 @@ const message = { proxyPasswdKeep: '记住密码', systemIPWarning: '当前未设置服务器地址,请先在面板设置中设置!', systemIPWarning1: '当前服务器地址设置为 {0},无法快速跳转!', - defaultNetwork: '默认网卡', changePassword: '密码修改', oldPassword: '原密码', newPassword: '新密码', diff --git a/frontend/src/layout/components/Sidebar/index.vue b/frontend/src/layout/components/Sidebar/index.vue index dc8a336d5..b8c6003b2 100644 --- a/frontend/src/layout/components/Sidebar/index.vue +++ b/frontend/src/layout/components/Sidebar/index.vue @@ -136,7 +136,6 @@ const loadNodes = async () => { nodes.value = []; return; } - console.log('dqwdqwd'); nodes.value = res.data; return; } diff --git a/frontend/src/utils/xpack.ts b/frontend/src/utils/xpack.ts index 99d2ee5ff..5896d511e 100644 --- a/frontend/src/utils/xpack.ts +++ b/frontend/src/utils/xpack.ts @@ -47,7 +47,6 @@ const loadDataFromDB = async () => { const res = await getSettingInfo(); document.title = res.data.panelName; globalStore.entrance = res.data.securityEntrance; - globalStore.setDefaultNetwork(res.data.defaultNetwork); globalStore.setOpenMenuTabs(res.data.menuTabs === 'enable'); }; diff --git a/frontend/src/views/host/monitor/monitor/index.vue b/frontend/src/views/host/monitor/monitor/index.vue index e2faa8533..4ba50cbee 100644 --- a/frontend/src/views/host/monitor/monitor/index.vue +++ b/frontend/src/views/host/monitor/monitor/index.vue @@ -149,27 +149,24 @@
{{ $t('monitor.network') }} IO: - - - -
- - -
-
- diff --git a/frontend/src/views/host/monitor/setting/interval/index.vue b/frontend/src/views/host/monitor/setting/interval/index.vue index 8b4f2cce1..ecf8f278c 100644 --- a/frontend/src/views/host/monitor/setting/interval/index.vue +++ b/frontend/src/views/host/monitor/setting/interval/index.vue @@ -25,7 +25,7 @@ import i18n from '@/lang'; import { MsgSuccess } from '@/utils/message'; import { FormInstance } from 'element-plus'; import { Rules, checkNumberRange } from '@/global/form-rules'; -import { updateSetting } from '@/api/modules/setting'; +import { updateMonitorSetting } from '@/api/modules/host'; const emit = defineEmits<{ (e: 'search'): void }>(); @@ -51,7 +51,7 @@ const onSave = async (formEl: FormInstance | undefined) => { formEl.validate(async (valid) => { if (!valid) return; loading.value = true; - await updateSetting({ key: 'MonitorInterval', value: form.monitorInterval + '' }) + await updateMonitorSetting('MonitorInterval', form.monitorInterval + '') .then(() => { loading.value = false; handleClose(); diff --git a/frontend/src/views/login/components/login-form.vue b/frontend/src/views/login/components/login-form.vue index 6f2789b14..6b86f630e 100644 --- a/frontend/src/views/login/components/login-form.vue +++ b/frontend/src/views/login/components/login-form.vue @@ -361,7 +361,6 @@ const loadDataFromDB = async () => { i18n.locale.value = res.data.language; i18n.warnHtmlMessage = false; globalStore.entrance = res.data.securityEntrance; - globalStore.setDefaultNetwork(res.data.defaultNetwork); globalStore.setOpenMenuTabs(res.data.menuTabs === 'enable'); globalStore.updateLanguage(res.data.language); globalStore.setThemeConfig({ ...themeConfig.value, theme: res.data.theme, panelName: res.data.panelName }); diff --git a/frontend/src/views/setting/panel/index.vue b/frontend/src/views/setting/panel/index.vue index 316d10d0d..0287403ba 100644 --- a/frontend/src/views/setting/panel/index.vue +++ b/frontend/src/views/setting/panel/index.vue @@ -89,33 +89,6 @@ - - - - - - - - - - - - - - - @@ -179,9 +150,7 @@ import Password from '@/views/setting/panel/password/index.vue'; import UserName from '@/views/setting/panel/username/index.vue'; import Timeout from '@/views/setting/panel/timeout/index.vue'; import PanelName from '@/views/setting/panel/name/index.vue'; -import SystemIP from '@/views/setting/panel/systemip/index.vue'; import Proxy from '@/views/setting/panel/proxy/index.vue'; -import Network from '@/views/setting/panel/default-network/index.vue'; import HideMenu from '@/views/setting/panel/hidemenu/index.vue'; import { storeToRefs } from 'pinia'; import { getXpackSetting, updateXpackSettingByKey } from '@/utils/xpack'; @@ -197,19 +166,12 @@ const { switchTheme } = useTheme(); const form = reactive({ userName: '', password: '', - email: '', sessionTimeout: 0, - localTime: '', - timeZone: '', - ntpSite: '', panelName: '', - systemIP: '', theme: '', menuTabs: '', language: '', complexityVerification: '', - defaultNetwork: '', - defaultNetworkVal: '', developerMode: '', proxyShow: '', @@ -229,10 +191,8 @@ const show = ref(); const userNameRef = ref(); const passwordRef = ref(); const panelNameRef = ref(); -const systemIPRef = ref(); const proxyRef = ref(); const timeoutRef = ref(); -const networkRef = ref(); const hideMenuRef = ref(); const unset = ref(i18n.t('setting.unSetting')); @@ -250,16 +210,10 @@ const search = async () => { form.userName = res.data.userName; form.password = '******'; form.sessionTimeout = Number(res.data.sessionTimeout); - form.localTime = res.data.localTime; - form.timeZone = res.data.timeZone; - form.ntpSite = res.data.ntpSite; form.panelName = res.data.panelName; - form.systemIP = res.data.systemIP; form.menuTabs = res.data.menuTabs; form.language = res.data.language; form.complexityVerification = res.data.complexityVerification; - form.defaultNetwork = res.data.defaultNetwork; - form.defaultNetworkVal = res.data.defaultNetwork === 'all' ? i18n.t('commons.table.all') : res.data.defaultNetwork; form.proHideMenus = res.data.xpackHideMenu; form.hideMenuList = res.data.xpackHideMenu; form.developerMode = res.data.developerMode; @@ -322,9 +276,6 @@ const onChangeTitle = () => { const onChangeTimeout = () => { timeoutRef.value.acceptParams({ sessionTimeout: form.sessionTimeout }); }; -const onChangeSystemIP = () => { - systemIPRef.value.acceptParams({ systemIP: form.systemIP }); -}; const onChangeProxy = () => { proxyRef.value.acceptParams({ url: form.proxyUrl, @@ -335,9 +286,6 @@ const onChangeProxy = () => { passwdKeep: form.proxyPasswdKeep, }); }; -const onChangeNetwork = () => { - networkRef.value.acceptParams({ defaultNetwork: form.defaultNetwork }); -}; const onChangeHideMenus = () => { hideMenuRef.value.acceptParams({ menuList: form.hideMenuList });