From 1215e3bb30c1b2f5ae6aefc89b5c328cc15e294c Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:14:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=87=E6=8D=A2=E5=AD=90=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E8=AF=B7=E6=B1=82=E6=96=B9=E5=BC=8F=20(#6195)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 4 + agent/app/api/v2/backup.go | 16 +-- agent/app/api/v2/health.go | 4 +- agent/app/service/backup.go | 6 +- agent/configs/system.go | 31 +++-- agent/constant/session.go | 5 - agent/init/hook/hook.go | 5 - agent/init/migration/migrations/init.go | 52 ++------ agent/router/ro_setting.go | 9 -- agent/utils/http/master.go | 57 --------- agent/utils/xpack/xpack.go | 8 ++ core/app/api/v2/backup.go | 29 ----- core/init/router/router.go | 11 +- core/router/ro_agent.go | 16 --- core/utils/encrypt/encrypt.go | 14 +++ core/utils/xpack/xpack.go | 2 + frontend/src/api/modules/setting.ts | 78 ------------ frontend/src/components/backup/index.vue | 10 +- frontend/src/components/upload/index.vue | 3 +- .../app-store/installed/backup/index.vue | 96 --------------- .../app-store/installed/recover/index.vue | 116 ------------------ frontend/src/views/cronjob/backup/index.vue | 2 +- frontend/src/views/cronjob/operate/index.vue | 2 +- .../redis/setting/persistence/index.vue | 4 +- .../views/setting/snapshot/import/index.vue | 10 +- frontend/src/views/setting/snapshot/index.vue | 2 +- 26 files changed, 83 insertions(+), 509 deletions(-) delete mode 100644 agent/constant/session.go delete mode 100644 agent/utils/http/master.go delete mode 100644 core/router/ro_agent.go delete mode 100644 frontend/src/views/app-store/installed/backup/index.vue delete mode 100644 frontend/src/views/app-store/installed/recover/index.vue diff --git a/Makefile b/Makefile index f50c34daa..3ac4a887e 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,10 @@ build_agent_xpack_on_darwin: cd $(AGENT_PATH) \ && GOOS=linux GOARCH=amd64 $(GOBUILD) -tags=xpack -trimpath -ldflags '-s -w' -o $(BUILD_PATH)/$(AGENT_NAME) $(AGENT_MAIN) +build_agent_xpack_on_linux: + cd $(AGENT_PATH) \ + && GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBUILD) -tags=xpack -trimpath -ldflags '-s -w' -o $(BUILD_PATH)/$(AGENT_NAME) $(AGENT_MAIN) + build_all: build_frontend build_core_on_linux build_agent_on_linux build_on_local: clean_assets build_frontend build_core_on_darwin build_agent_on_darwin upx_bin diff --git a/agent/app/api/v2/backup.go b/agent/app/api/v2/backup.go index 3b2f1bf63..a66dde142 100644 --- a/agent/app/api/v2/backup.go +++ b/agent/app/api/v2/backup.go @@ -32,7 +32,7 @@ func (b *BaseApi) CheckBackupUsed(c *gin.Context) { // @Param request body dto.RecordSearch true "request" // @Success 200 // @Security ApiKeyAuth -// @Router /settings/backup/record/search [post] +// @Router /backup/record/search [post] func (b *BaseApi) SearchBackupRecords(c *gin.Context) { var req dto.RecordSearch if err := helper.CheckBindAndValidate(&req, c); err != nil { @@ -58,7 +58,7 @@ func (b *BaseApi) SearchBackupRecords(c *gin.Context) { // @Param request body dto.RecordSearchByCronjob true "request" // @Success 200 // @Security ApiKeyAuth -// @Router /settings/backup/record/search/bycronjob [post] +// @Router /backup/record/search/bycronjob [post] func (b *BaseApi) SearchBackupRecordsByCronjob(c *gin.Context) { var req dto.RecordSearchByCronjob if err := helper.CheckBindAndValidate(&req, c); err != nil { @@ -84,7 +84,7 @@ func (b *BaseApi) SearchBackupRecordsByCronjob(c *gin.Context) { // @Param request body dto.DownloadRecord true "request" // @Success 200 // @Security ApiKeyAuth -// @Router /settings/backup/record/download [post] +// @Router /backup/record/download [post] // @x-panel-log {"bodyKeys":["source","fileName"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"下载备份记录 [source][fileName]","formatEN":"download backup records [source][fileName]"} func (b *BaseApi) DownloadRecord(c *gin.Context) { var req dto.DownloadRecord @@ -107,7 +107,7 @@ func (b *BaseApi) DownloadRecord(c *gin.Context) { // @Param request body dto.BatchDeleteReq true "request" // @Success 200 // @Security ApiKeyAuth -// @Router /settings/backup/record/del [post] +// @Router /record/del [post] // @x-panel-log {"bodyKeys":["ids"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"ids","isList":true,"db":"backup_records","output_column":"file_name","output_value":"files"}],"formatZH":"删除备份记录 [files]","formatEN":"delete backup records [files]"} func (b *BaseApi) DeleteBackupRecord(c *gin.Context) { var req dto.BatchDeleteReq @@ -129,7 +129,7 @@ func (b *BaseApi) DeleteBackupRecord(c *gin.Context) { // @Param request body dto.OperateByID true "request" // @Success 200 {array} string // @Security ApiKeyAuth -// @Router /settings/backup/search/files [post] +// @Router /backup/search/files [post] func (b *BaseApi) LoadFilesFromBackup(c *gin.Context) { var req dto.OperateByID if err := helper.CheckBindAndValidate(&req, c); err != nil { @@ -147,7 +147,7 @@ func (b *BaseApi) LoadFilesFromBackup(c *gin.Context) { // @Param request body dto.CommonBackup true "request" // @Success 200 // @Security ApiKeyAuth -// @Router /settings/backup/backup [post] +// @Router /backup/backup [post] // @x-panel-log {"bodyKeys":["type","name","detailName"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"备份 [type] 数据 [name][detailName]","formatEN":"backup [type] data [name][detailName]"} func (b *BaseApi) Backup(c *gin.Context) { var req dto.CommonBackup @@ -192,7 +192,7 @@ func (b *BaseApi) Backup(c *gin.Context) { // @Param request body dto.CommonRecover true "request" // @Success 200 // @Security ApiKeyAuth -// @Router /settings/backup/recover [post] +// @Router /backup/recover [post] // @x-panel-log {"bodyKeys":["type","name","detailName","file"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"从 [file] 恢复 [type] 数据 [name][detailName]","formatEN":"recover [type] data [name][detailName] from [file]"} func (b *BaseApi) Recover(c *gin.Context) { var req dto.CommonRecover @@ -247,7 +247,7 @@ func (b *BaseApi) Recover(c *gin.Context) { // @Param request body dto.CommonRecover true "request" // @Success 200 // @Security ApiKeyAuth -// @Router /settings/backup/recover/byupload [post] +// @Router /backup/recover/byupload [post] // @x-panel-log {"bodyKeys":["type","name","detailName","file"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"从 [file] 恢复 [type] 数据 [name][detailName]","formatEN":"recover [type] data [name][detailName] from [file]"} func (b *BaseApi) RecoverByUpload(c *gin.Context) { var req dto.CommonRecover diff --git a/agent/app/api/v2/health.go b/agent/app/api/v2/health.go index a80dae235..2d5603847 100644 --- a/agent/app/api/v2/health.go +++ b/agent/app/api/v2/health.go @@ -5,12 +5,12 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/constant" - httpUtils "github.com/1Panel-dev/1Panel/agent/utils/http" + "github.com/1Panel-dev/1Panel/agent/utils/xpack" "github.com/gin-gonic/gin" ) func (b *BaseApi) CheckHealth(c *gin.Context) { - _, err := httpUtils.RequestToMaster("/api/v2/agent/health", http.MethodGet, nil) + _, err := xpack.RequestToMaster("/api/v2/agent/health", http.MethodGet, nil) if err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return diff --git a/agent/app/service/backup.go b/agent/app/service/backup.go index 4577a6c71..8335af6cc 100644 --- a/agent/app/service/backup.go +++ b/agent/app/service/backup.go @@ -21,7 +21,7 @@ import ( "github.com/1Panel-dev/1Panel/agent/global" "github.com/1Panel-dev/1Panel/agent/utils/cloud_storage" "github.com/1Panel-dev/1Panel/agent/utils/encrypt" - httpUtils "github.com/1Panel-dev/1Panel/agent/utils/http" + "github.com/1Panel-dev/1Panel/agent/utils/xpack" "github.com/jinzhu/copier" "github.com/pkg/errors" ) @@ -277,7 +277,7 @@ func NewBackupClientWithID(id uint) (*model.BackupAccount, cloud_storage.CloudSt if err != nil { return nil, nil, err } - data, err := httpUtils.RequestToMaster("/api/v2/agent/backup", http.MethodPost, bytes.NewReader(bodyItem)) + data, err := xpack.RequestToMaster("/api/v2/agent/backup", http.MethodPost, bytes.NewReader(bodyItem)) if err != nil { return nil, nil, err } @@ -342,7 +342,7 @@ func NewBackupClientMap(ids []string) (map[string]backupClientHelper, error) { if err != nil { return nil, err } - data, err := httpUtils.RequestToMaster("/api/v2/agent/backup/list", http.MethodPost, bytes.NewReader(bodyItem)) + data, err := xpack.RequestToMaster("/api/v2/agent/backup/list", http.MethodPost, bytes.NewReader(bodyItem)) if err != nil { return nil, err } diff --git a/agent/configs/system.go b/agent/configs/system.go index 2135cd7a7..721dba88b 100644 --- a/agent/configs/system.go +++ b/agent/configs/system.go @@ -1,20 +1,19 @@ package configs type System struct { - MasterAddr string `mapstructure:"master_addr"` - MasterToken string `mapstructure:"master_token"` - DbFile string `mapstructure:"db_agent_file"` - DbPath string `mapstructure:"db_path"` - LogPath string `mapstructure:"log_path"` - DataDir string `mapstructure:"data_dir"` - TmpDir string `mapstructure:"tmp_dir"` - Cache string `mapstructure:"cache"` - Backup string `mapstructure:"backup"` - EncryptKey string `mapstructure:"encrypt_key"` - BaseDir string `mapstructure:"base_dir"` - Mode string `mapstructure:"mode"` - RepoUrl string `mapstructure:"repo_url"` - Version string `mapstructure:"version"` - IsDemo bool `mapstructure:"is_demo"` - AppRepo string `mapstructure:"app_repo"` + MasterAddr string `mapstructure:"master_addr"` + DbFile string `mapstructure:"db_agent_file"` + DbPath string `mapstructure:"db_path"` + LogPath string `mapstructure:"log_path"` + DataDir string `mapstructure:"data_dir"` + TmpDir string `mapstructure:"tmp_dir"` + Cache string `mapstructure:"cache"` + Backup string `mapstructure:"backup"` + EncryptKey string `mapstructure:"encrypt_key"` + BaseDir string `mapstructure:"base_dir"` + Mode string `mapstructure:"mode"` + RepoUrl string `mapstructure:"repo_url"` + Version string `mapstructure:"version"` + IsDemo bool `mapstructure:"is_demo"` + AppRepo string `mapstructure:"app_repo"` } diff --git a/agent/constant/session.go b/agent/constant/session.go deleted file mode 100644 index 189fdb62c..000000000 --- a/agent/constant/session.go +++ /dev/null @@ -1,5 +0,0 @@ -package constant - -const ( - JWTHeaderName = "PanelAuthorization" -) diff --git a/agent/init/hook/hook.go b/agent/init/hook/hook.go index 6f4a99576..f2d7cc45b 100644 --- a/agent/init/hook/hook.go +++ b/agent/init/hook/hook.go @@ -35,11 +35,6 @@ func Init() { global.LOG.Fatalf("load master addr before start failed, err: %v", err) } global.CONF.System.MasterAddr = masterAddr.Value - token, err := settingRepo.Get(settingRepo.WithByKey("Token")) - if err != nil { - global.LOG.Fatalf("load token before start failed, err: %v", err) - } - global.CONF.System.MasterToken, _ = encrypt.StringDecrypt(token.Value) } handleCronjobStatus() diff --git a/agent/init/migration/migrations/init.go b/agent/init/migration/migrations/init.go index e17ff08f8..2cebc92fe 100644 --- a/agent/init/migration/migrations/init.go +++ b/agent/init/migration/migrations/init.go @@ -1,7 +1,6 @@ package migrations import ( - "encoding/json" "os" "github.com/1Panel-dev/1Panel/agent/app/dto/request" @@ -10,7 +9,7 @@ import ( "github.com/1Panel-dev/1Panel/agent/constant" "github.com/1Panel-dev/1Panel/agent/global" "github.com/1Panel-dev/1Panel/agent/utils/common" - "github.com/1Panel-dev/1Panel/agent/utils/encrypt" + "github.com/1Panel-dev/1Panel/agent/utils/xpack" "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" @@ -73,53 +72,18 @@ var AddMonitorTable = &gormigrate.Migration{ var InitSetting = &gormigrate.Migration{ ID: "20240722-init-setting", Migrate: func(tx *gorm.DB) error { - encryptKey := common.RandStr(16) - global.CONF.System.EncryptKey = encryptKey - if err := tx.Create(&model.Setting{Key: "EncryptKey", Value: encryptKey}).Error; err != nil { + global.CONF.System.EncryptKey = common.RandStr(16) + isMaster, currentNode, err := xpack.InitNodeData(tx) + if err != nil { return err } - currentNode := "" - if _, err := os.Stat("/opt/1panel/nodeJson"); err == nil { - type nodeInfo struct { - MasterAddr string `json:"masterAddr"` - Token string `json:"token"` - ServerCrt string `json:"serverCrt"` - ServerKey string `json:"serverKey"` - CurrentNode string `json:"currentNode"` - } - nodeJson, err := os.ReadFile("/opt/1panel/nodeJson") - if err != nil { - return err - } - var node nodeInfo - if err := json.Unmarshal(nodeJson, &node); err != nil { - return err - } - itemKey, _ := encrypt.StringEncryptWithBase64(node.ServerKey) - if err := tx.Create(&model.Setting{Key: "ServerKey", Value: itemKey}).Error; err != nil { - return err - } - itemCrt, _ := encrypt.StringEncryptWithBase64(node.ServerCrt) - if err := tx.Create(&model.Setting{Key: "ServerCrt", Value: itemCrt}).Error; err != nil { - return err - } - itemToken, _ := encrypt.StringEncryptWithBase64(node.Token) - if err := tx.Create(&model.Setting{Key: "Token", Value: itemToken}).Error; err != nil { - return err - } - if err := tx.Create(&model.Setting{Key: "MasterAddr", Value: node.MasterAddr}).Error; err != nil { - return err - } - global.CONF.System.MasterAddr = node.MasterAddr - global.CONF.System.MasterToken = itemToken - global.IsMaster = false - currentNode = node.CurrentNode - } else { - global.IsMaster = true - } + global.IsMaster = isMaster if err := tx.Create(&model.Setting{Key: "CurrentNode", Value: currentNode}).Error; err != nil { return err } + if err := tx.Create(&model.Setting{Key: "EncryptKey", Value: global.CONF.System.EncryptKey}).Error; err != nil { + return err + } if err := tx.Create(&model.Setting{Key: "SystemIP", Value: ""}).Error; err != nil { return err diff --git a/agent/router/ro_setting.go b/agent/router/ro_setting.go index 0a7c547b2..67ecd12ea 100644 --- a/agent/router/ro_setting.go +++ b/agent/router/ro_setting.go @@ -24,15 +24,6 @@ func (s *SettingRouter) InitRouter(Router *gin.RouterGroup) { settingRouter.POST("/snapshot/rollback", baseApi.RollbackSnapshot) settingRouter.POST("/snapshot/description/update", baseApi.UpdateSnapDescription) - settingRouter.POST("/backup/backup", baseApi.Backup) - settingRouter.POST("/backup/recover", baseApi.Recover) - settingRouter.POST("/backup/recover/byupload", baseApi.RecoverByUpload) - settingRouter.POST("/backup/search/files", baseApi.LoadFilesFromBackup) - settingRouter.POST("/backup/record/search", baseApi.SearchBackupRecords) - settingRouter.POST("/backup/record/search/bycronjob", baseApi.SearchBackupRecordsByCronjob) - settingRouter.POST("/backup/record/download", baseApi.DownloadRecord) - settingRouter.POST("/backup/record/del", baseApi.DeleteBackupRecord) - settingRouter.GET("/basedir", baseApi.LoadBaseDir) } } diff --git a/agent/utils/http/master.go b/agent/utils/http/master.go deleted file mode 100644 index 050b8f5ea..000000000 --- a/agent/utils/http/master.go +++ /dev/null @@ -1,57 +0,0 @@ -package http - -import ( - "encoding/json" - "fmt" - "io" - "net/http" - "net/url" - "time" - - "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" - "github.com/1Panel-dev/1Panel/agent/global" -) - -func RequestToMaster(reqUrl, reqMethod string, reqBody io.Reader) (interface{}, error) { - client := &http.Client{ - Timeout: time.Second * 5, - } - parsedURL, err := url.Parse(global.CONF.System.MasterAddr) - if err != nil { - return nil, fmt.Errorf("handle url Parse failed, err: %v \n", err) - } - rURL := &url.URL{ - Scheme: "http", - Path: reqUrl, - Host: parsedURL.Host, - } - req, err := http.NewRequest(reqMethod, rURL.String(), reqBody) - if err != nil { - return nil, fmt.Errorf("handle request failed, err: %v \n", err) - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set(constant.JWTHeaderName, global.CONF.System.MasterToken) - - resp, err := client.Do(req) - if err != nil { - return nil, fmt.Errorf("client do request failed, err: %v", err) - } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("do request failed, err: %v", resp.Status) - } - bodyByte, err := io.ReadAll(resp.Body) - if err != nil { - return nil, fmt.Errorf("read resp body from request failed, err: %v", err) - } - var respJson dto.Response - if err := json.Unmarshal(bodyByte, &respJson); err != nil { - return nil, fmt.Errorf("json unmarshal resp data failed, err: %v", err) - } - if respJson.Code != http.StatusOK { - return nil, fmt.Errorf("do request success but handle failed, err: %v", respJson.Message) - } - return respJson.Data, nil -} diff --git a/agent/utils/xpack/xpack.go b/agent/utils/xpack/xpack.go index 19ea1843b..b85ccb523 100644 --- a/agent/utils/xpack/xpack.go +++ b/agent/utils/xpack/xpack.go @@ -4,6 +4,7 @@ package xpack import ( "crypto/tls" + "io" "net" "net/http" "time" @@ -11,6 +12,7 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/model" "github.com/1Panel-dev/1Panel/agent/buserr" "github.com/1Panel-dev/1Panel/agent/constant" + "gorm.io/gorm" ) func RemoveTamper(website string) {} @@ -35,3 +37,9 @@ func LoadGpuInfo() []interface{} { func StartClam(startClam model.Clam, isUpdate bool) (int, error) { return 0, buserr.New(constant.ErrXpackNotFound) } + +func InitNodeData(tx *gorm.DB) (bool, string, error) { return true, "127.0.0.1", nil } + +func RequestToMaster(reqUrl, reqMethod string, reqBody io.Reader) (interface{}, error) { + return nil, nil +} diff --git a/core/app/api/v2/backup.go b/core/app/api/v2/backup.go index 2b9a27397..29a75c259 100644 --- a/core/app/api/v2/backup.go +++ b/core/app/api/v2/backup.go @@ -179,32 +179,3 @@ func (b *BaseApi) GetLocalDir(c *gin.Context) { helper.SuccessWithData(c, dir) } - -func (b *BaseApi) GetBackup(c *gin.Context) { - var req dto.OperateByID - if err := helper.CheckBindAndValidate(&req, c); err != nil { - return - } - - data, err := backupService.Get(req) - if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) - return - } - - helper.SuccessWithData(c, data) -} -func (b *BaseApi) ListBackup(c *gin.Context) { - var req dto.OperateByIDs - if err := helper.CheckBindAndValidate(&req, c); err != nil { - return - } - - list, err := backupService.List(req) - if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) - return - } - - helper.SuccessWithData(c, list) -} diff --git a/core/init/router/router.go b/core/init/router/router.go index 181dd2aa8..35579bb18 100644 --- a/core/init/router/router.go +++ b/core/init/router/router.go @@ -6,13 +6,11 @@ import ( "github.com/1Panel-dev/1Panel/cmd/server/docs" "github.com/1Panel-dev/1Panel/cmd/server/web" - "github.com/1Panel-dev/1Panel/core/app/dto" - "github.com/1Panel-dev/1Panel/core/constant" "github.com/1Panel-dev/1Panel/core/global" "github.com/1Panel-dev/1Panel/core/i18n" "github.com/1Panel-dev/1Panel/core/middleware" - "github.com/1Panel-dev/1Panel/core/router" rou "github.com/1Panel-dev/1Panel/core/router" + "github.com/1Panel-dev/1Panel/core/utils/xpack" "github.com/gin-contrib/gzip" "github.com/gin-gonic/gin" swaggerfiles "github.com/swaggo/files" @@ -54,12 +52,7 @@ func Routers() *gin.Engine { } agentRouter := Router.Group("/api/v2/agent") - agentRouter.Use(middleware.JwtAuth()) - var agent router.AgentRouter - agent.InitRouter(agentRouter) - agentRouter.GET("/health", func(c *gin.Context) { - c.JSON(200, dto.Response{Code: constant.CodeSuccess, Data: "ok"}) - }) + xpack.InitAgentRouter(agentRouter) Router.Use(middleware.OperationLog()) if global.CONF.System.IsDemo { diff --git a/core/router/ro_agent.go b/core/router/ro_agent.go deleted file mode 100644 index cdce23d8a..000000000 --- a/core/router/ro_agent.go +++ /dev/null @@ -1,16 +0,0 @@ -package router - -import ( - v2 "github.com/1Panel-dev/1Panel/core/app/api/v2" - "github.com/gin-gonic/gin" -) - -type AgentRouter struct{} - -func (s *AgentRouter) InitRouter(Router *gin.RouterGroup) { - baseApi := v2.ApiGroupApp.BaseApi - { - Router.POST("/backup", baseApi.GetBackup) - Router.POST("/backup/list", baseApi.ListBackup) - } -} diff --git a/core/utils/encrypt/encrypt.go b/core/utils/encrypt/encrypt.go index 68cea03ef..10aaec350 100644 --- a/core/utils/encrypt/encrypt.go +++ b/core/utils/encrypt/encrypt.go @@ -45,6 +45,13 @@ func StringEncrypt(text string) (string, error) { global.CONF.System.EncryptKey = encryptSetting.Value } key := global.CONF.System.EncryptKey + return StringEncryptWithKey(text, key) +} + +func StringEncryptWithKey(text, key string) (string, error) { + if len(text) == 0 || len(key) == 0 { + return "", nil + } pass := []byte(text) xpass, err := aesEncryptWithSalt([]byte(key), pass) if err == nil { @@ -66,6 +73,13 @@ func StringDecrypt(text string) (string, error) { global.CONF.System.EncryptKey = encryptSetting.Value } key := global.CONF.System.EncryptKey + return StringDecryptWithKey(text, key) +} + +func StringDecryptWithKey(text, key string) (string, error) { + if len(text) == 0 { + return "", nil + } bytesPass, err := base64.StdEncoding.DecodeString(text) if err != nil { return "", err diff --git a/core/utils/xpack/xpack.go b/core/utils/xpack/xpack.go index 503a20e5b..dfb5f4a0b 100644 --- a/core/utils/xpack/xpack.go +++ b/core/utils/xpack/xpack.go @@ -17,3 +17,5 @@ func UpdateGroup(name string, group, newGroup uint) error { func CheckBackupUsed(id uint) error { return nil } + +func InitAgentRouter(Router *gin.RouterGroup) {} diff --git a/frontend/src/api/modules/setting.ts b/frontend/src/api/modules/setting.ts index 78dacacac..298b65a7d 100644 --- a/frontend/src/api/modules/setting.ts +++ b/frontend/src/api/modules/setting.ts @@ -2,9 +2,7 @@ import http from '@/api'; import { deepCopy } from '@/utils/util'; import { Base64 } from 'js-base64'; import { ResPage, SearchWithPage, DescriptionUpdate } from '../interface'; -import { Backup } from '../interface/backup'; import { Setting } from '../interface/setting'; -import { TimeoutEnum } from '@/enums/http-enum'; // license export const UploadFileData = (params: FormData) => { @@ -83,82 +81,6 @@ export const bindMFA = (param: Setting.MFABind) => { return http.post(`/core/settings/mfa/bind`, param); }; -// backup-agent -export const handleBackup = (params: Backup.Backup) => { - return http.post(`/settings/backup/backup`, params, TimeoutEnum.T_1H); -}; -export const handleRecover = (params: Backup.Recover) => { - return http.post(`/settings/backup/recover`, params, TimeoutEnum.T_1D); -}; -export const handleRecoverByUpload = (params: Backup.Recover) => { - return http.post(`/settings/backup/recover/byupload`, params, TimeoutEnum.T_1D); -}; -export const downloadBackupRecord = (params: Backup.RecordDownload) => { - return http.post(`/settings/backup/record/download`, params, TimeoutEnum.T_10M); -}; -export const deleteBackupRecord = (params: { ids: number[] }) => { - return http.post(`/settings/backup/record/del`, params); -}; -export const searchBackupRecords = (params: Backup.SearchBackupRecord) => { - return http.post>(`/settings/backup/record/search`, params, TimeoutEnum.T_5M); -}; -export const searchBackupRecordsByCronjob = (params: Backup.SearchBackupRecordByCronjob) => { - return http.post>(`/settings/backup/record/search/bycronjob`, params, TimeoutEnum.T_5M); -}; -export const getFilesFromBackup = (type: string) => { - return http.post>(`/settings/backup/search/files`, { type: type }); -}; - -// backup-core -export const refreshOneDrive = () => { - return http.post(`/core/backup/refresh/onedrive`, {}); -}; -export const getBackupList = () => { - return http.get>(`/core/backup/options`); -}; -export const getLocalBackupDir = () => { - return http.get(`/core/backup/local`); -}; -export const searchBackup = (params: Backup.SearchWithType) => { - return http.post>(`/core/backup/search`, params); -}; -export const getOneDriveInfo = () => { - return http.get(`/core/backup/onedrive`); -}; -export const addBackup = (params: Backup.BackupOperate) => { - let request = deepCopy(params) as Backup.BackupOperate; - if (request.accessKey) { - request.accessKey = Base64.encode(request.accessKey); - } - if (request.credential) { - request.credential = Base64.encode(request.credential); - } - return http.post(`/core/backup`, request, TimeoutEnum.T_60S); -}; -export const editBackup = (params: Backup.BackupOperate) => { - let request = deepCopy(params) as Backup.BackupOperate; - if (request.accessKey) { - request.accessKey = Base64.encode(request.accessKey); - } - if (request.credential) { - request.credential = Base64.encode(request.credential); - } - return http.post(`/core/backup/update`, request); -}; -export const deleteBackup = (params: { id: number }) => { - return http.post(`/core/backup/del`, params); -}; -export const listBucket = (params: Backup.ForBucket) => { - let request = deepCopy(params) as Backup.BackupOperate; - if (request.accessKey) { - request.accessKey = Base64.encode(request.accessKey); - } - if (request.credential) { - request.credential = Base64.encode(request.credential); - } - return http.post(`/core/backup/buckets`, request); -}; - // snapshot export const snapshotCreate = (param: Setting.SnapshotCreate) => { return http.post(`/settings/snapshot`, param); diff --git a/frontend/src/components/backup/index.vue b/frontend/src/components/backup/index.vue index 85a323fd8..364adf704 100644 --- a/frontend/src/components/backup/index.vue +++ b/frontend/src/components/backup/index.vue @@ -101,9 +101,15 @@ - diff --git a/frontend/src/views/app-store/installed/recover/index.vue b/frontend/src/views/app-store/installed/recover/index.vue deleted file mode 100644 index ce2678c05..000000000 --- a/frontend/src/views/app-store/installed/recover/index.vue +++ /dev/null @@ -1,116 +0,0 @@ - - - - diff --git a/frontend/src/views/cronjob/backup/index.vue b/frontend/src/views/cronjob/backup/index.vue index 128fa6ea6..7f8736323 100644 --- a/frontend/src/views/cronjob/backup/index.vue +++ b/frontend/src/views/cronjob/backup/index.vue @@ -51,7 +51,7 @@ import { reactive, ref } from 'vue'; import { computeSize, dateFormat, downloadFile } from '@/utils/util'; import i18n from '@/lang'; -import { downloadBackupRecord, searchBackupRecordsByCronjob } from '@/api/modules/setting'; +import { downloadBackupRecord, searchBackupRecordsByCronjob } from '@/api/modules/backup'; import { Backup } from '@/api/interface/backup'; const selects = ref([]); diff --git a/frontend/src/views/cronjob/operate/index.vue b/frontend/src/views/cronjob/operate/index.vue index 73de12901..f876257d6 100644 --- a/frontend/src/views/cronjob/operate/index.vue +++ b/frontend/src/views/cronjob/operate/index.vue @@ -332,7 +332,7 @@ import { reactive, ref } from 'vue'; import { Rules } from '@/global/form-rules'; import FileList from '@/components/file-list/index.vue'; -import { getBackupList } from '@/api/modules/setting'; +import { getBackupList } from '@/api/modules/backup'; import i18n from '@/lang'; import { ElForm } from 'element-plus'; import { Cronjob } from '@/api/interface/cronjob'; diff --git a/frontend/src/views/database/redis/setting/persistence/index.vue b/frontend/src/views/database/redis/setting/persistence/index.vue index 7462c9550..07f703388 100644 --- a/frontend/src/views/database/redis/setting/persistence/index.vue +++ b/frontend/src/views/database/redis/setting/persistence/index.vue @@ -116,7 +116,7 @@ import ConfirmDialog from '@/components/confirm-dialog/index.vue'; import { Database } from '@/api/interface/database'; import { redisPersistenceConf, updateRedisPersistenceConf } from '@/api/modules/database'; -import { deleteBackupRecord, handleBackup, handleRecover, searchBackupRecords } from '@/api/modules/setting'; +import { deleteBackupRecord, handleBackup, handleRecover, searchBackupRecords } from '@/api/modules/backup'; import { Rules } from '@/global/form-rules'; import { dateFormat } from '@/utils/util'; import i18n from '@/lang'; @@ -205,7 +205,7 @@ const onBackup = async () => { }; const onRecover = async () => { let param = { - source: currentRow.value.source, + downloadAccountID: currentRow.value.source, type: 'redis', name: database.value, detailName: '', diff --git a/frontend/src/views/setting/snapshot/import/index.vue b/frontend/src/views/setting/snapshot/import/index.vue index 942a12b87..a31ff8941 100644 --- a/frontend/src/views/setting/snapshot/import/index.vue +++ b/frontend/src/views/setting/snapshot/import/index.vue @@ -46,7 +46,7 @@ import { reactive, ref } from 'vue'; import { FormInstance } from 'element-plus'; import i18n from '@/lang'; import { snapshotImport } from '@/api/modules/setting'; -import { getBackupList, getFilesFromBackup } from '@/api/modules/setting'; +import { getBackupList, getFilesFromBackup } from '@/api/modules/backup'; import { Rules } from '@/global/form-rules'; import { MsgSuccess } from '@/utils/message'; import router from '@/routers'; @@ -125,13 +125,7 @@ const loadBackups = async () => { loading.value = false; backupOptions.value = []; for (const item of res.data) { - if (item.id !== 0) { - backupOptions.value.push({ label: i18n.global.t('setting.' + item.type), value: item.type }); - } - if (item.type === 'LOCAL') { - item.varsJson = JSON.parse(item.vars); - backupPath.value = item.varsJson['dir'] + '/system_snapshot'; - } + backupOptions.value.push({ label: i18n.global.t('setting.' + item.type), value: item.type }); } }) .catch(() => { diff --git a/frontend/src/views/setting/snapshot/index.vue b/frontend/src/views/setting/snapshot/index.vue index 76d6d40bd..42799fd97 100644 --- a/frontend/src/views/setting/snapshot/index.vue +++ b/frontend/src/views/setting/snapshot/index.vue @@ -191,7 +191,7 @@ import IgnoreRule from '@/views/setting/snapshot/ignore-rule/index.vue'; import SnapStatus from '@/views/setting/snapshot/snap_status/index.vue'; import RecoverStatus from '@/views/setting/snapshot/status/index.vue'; import SnapshotImport from '@/views/setting/snapshot/import/index.vue'; -import { getBackupList } from '@/api/modules/setting'; +import { getBackupList } from '@/api/modules/backup'; import { MsgSuccess } from '@/utils/message'; const loading = ref(false);