From 1b862253bd1c3e678b8151f3bda40646fc6ee2a7 Mon Sep 17 00:00:00 2001 From: ssongliu Date: Wed, 8 Mar 2023 17:02:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=88=E7=AB=AF=E6=94=AF=E6=8C=81=20h?= =?UTF-8?q?ttps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{backup_database.go => backup_mysql.go} | 0 backend/app/service/backup_redis.go | 5 +++-- backend/app/service/cronjob_helper.go | 15 ++++++++++----- backend/constant/errs.go | 5 +++++ backend/i18n/lang/en.yaml | 5 ++++- backend/i18n/lang/zh.yaml | 5 ++++- frontend/auto-imports.d.ts | 4 ++-- .../views/container/container/terminal/index.vue | 3 ++- .../src/views/database/redis/terminal/index.vue | 3 ++- .../views/host/file-management/process/index.vue | 3 ++- .../src/views/host/terminal/terminal/terminal.vue | 3 ++- 11 files changed, 36 insertions(+), 15 deletions(-) rename backend/app/service/{backup_database.go => backup_mysql.go} (100%) diff --git a/backend/app/service/backup_database.go b/backend/app/service/backup_mysql.go similarity index 100% rename from backend/app/service/backup_database.go rename to backend/app/service/backup_mysql.go diff --git a/backend/app/service/backup_redis.go b/backend/app/service/backup_redis.go index 1a91c0cb6..6dbb5134f 100644 --- a/backend/app/service/backup_redis.go +++ b/backend/app/service/backup_redis.go @@ -11,6 +11,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/model" "github.com/1Panel-dev/1Panel/backend/app/repo" + "github.com/1Panel-dev/1Panel/backend/buserr" "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/cmd" @@ -108,7 +109,7 @@ func handleRedisRecover(redisInfo *repo.RootInfo, recoverFile string, isRollback return err } if (appendonly == "yes" && !strings.HasSuffix(recoverFile, ".tar.gz")) || (appendonly != "yes" && !strings.HasSuffix(recoverFile, ".rdb")) { - return fmt.Errorf("recover redis with appendonly=%s from file %s format error", appendonly, recoverFile) + return buserr.New(constant.ErrTypeOfRedis) } global.LOG.Infof("appendonly in redis conf is %s", appendonly) isOk := false @@ -140,7 +141,7 @@ func handleRedisRecover(redisInfo *repo.RootInfo, recoverFile string, isRollback return err } if appendonly == "yes" { - redisDataDir := fmt.Sprintf("%s/%s/%s/data/", constant.AppInstallDir, "redis", redisInfo.Name) + redisDataDir := fmt.Sprintf("%s/%s/%s/data", constant.AppInstallDir, "redis", redisInfo.Name) if err := handleUnTar(recoverFile, redisDataDir); err != nil { return err } diff --git a/backend/app/service/cronjob_helper.go b/backend/app/service/cronjob_helper.go index 89d488422..40b0f8e70 100644 --- a/backend/app/service/cronjob_helper.go +++ b/backend/app/service/cronjob_helper.go @@ -245,10 +245,12 @@ func handleTar(sourceDir, targetDir, name, exclusionRules string) error { path = sourceDir } - global.LOG.Debugf("tar zcvf %s %s %s \n", targetDir+"/"+name, excludeRules, path) - stdout, err := cmd.Execf("tar zcvf %s %s %s", targetDir+"/"+name, excludeRules, path) + commands := fmt.Sprintf("tar zcvf %s %s %s", targetDir+"/"+name, excludeRules, path) + global.LOG.Debug(commands) + stdout, err := cmd.Exec(commands) if err != nil { - return errors.New(string(stdout)) + global.LOG.Errorf("do handle tar failed, stdout: %s, err: %v", stdout, err) + return errors.New(stdout) } return nil } @@ -260,9 +262,12 @@ func handleUnTar(sourceFile, targetDir string) error { } } - stdout, err := cmd.Execf("tar zxvfC %s %s", sourceFile, targetDir) + commands := fmt.Sprintf("tar zxvfC %s %s", sourceFile, targetDir) + global.LOG.Debug(commands) + stdout, err := cmd.Exec(commands) if err != nil { - return errors.New(string(stdout)) + global.LOG.Errorf("do handle untar failed, stdout: %s, err: %v", stdout, err) + return errors.New(stdout) } return nil } diff --git a/backend/constant/errs.go b/backend/constant/errs.go index 51e7d0cfb..c76911822 100644 --- a/backend/constant/errs.go +++ b/backend/constant/errs.go @@ -87,3 +87,8 @@ var ( ErrUserIsExist = "ErrUserIsExist" ErrDatabaseIsExist = "ErrDatabaseIsExist" ) + +//redis +var ( + ErrTypeOfRedis = "ErrTypeOfRedis" +) diff --git a/backend/i18n/lang/en.yaml b/backend/i18n/lang/en.yaml index 62e3ad2be..f715dfc41 100644 --- a/backend/i18n/lang/en.yaml +++ b/backend/i18n/lang/en.yaml @@ -46,4 +46,7 @@ ErrEmailIsExist: 'Email is already exist' #mysql ErrUserIsExist: "The current user already exists. Please enter a new user" -ErrDatabaseIsExist: "The current database already exists. Please enter a new database" \ No newline at end of file +ErrDatabaseIsExist: "The current database already exists. Please enter a new database" + +#redis +ErrTypeOfRedis: "The recovery file type does not match the current persistence mode. Modify the file type and try again" \ No newline at end of file diff --git a/backend/i18n/lang/zh.yaml b/backend/i18n/lang/zh.yaml index f69712ace..682d34da6 100644 --- a/backend/i18n/lang/zh.yaml +++ b/backend/i18n/lang/zh.yaml @@ -46,4 +46,7 @@ ErrEmailIsExist: '邮箱已存在' #mysql ErrUserIsExist: "当前用户已存在,请重新输入" -ErrDatabaseIsExist: "当前数据库已存在,请重新输入" \ No newline at end of file +ErrDatabaseIsExist: "当前数据库已存在,请重新输入" + +#redis +ErrTypeOfRedis: "恢复文件类型与当前持久化方式不符,请修改后重试" \ No newline at end of file diff --git a/frontend/auto-imports.d.ts b/frontend/auto-imports.d.ts index cf8e88c6e..fd8cc86b8 100644 --- a/frontend/auto-imports.d.ts +++ b/frontend/auto-imports.d.ts @@ -1,6 +1,6 @@ // Generated by 'unplugin-auto-import' // We suggest you to commit this file into source control declare global { - const ElMessageBox: typeof import('element-plus/es')['ElMessageBox'] + const ElMessageBox: typeof import('element-plus/es')['ElMessageBox']; } -export {} +export {}; diff --git a/frontend/src/views/container/container/terminal/index.vue b/frontend/src/views/container/container/terminal/index.vue index 213ea6381..741f201b6 100644 --- a/frontend/src/views/container/container/terminal/index.vue +++ b/frontend/src/views/container/container/terminal/index.vue @@ -115,6 +115,7 @@ const initTerm = (formEl: FormInstance | undefined) => { formEl.validate(async (valid) => { if (!valid) return; let href = window.location.href; + let protocol = href.split('//')[0] === 'http:' ? 'ws' : 'wss'; let ipLocal = href.split('//')[1].split('/')[0]; terminalOpen.value = true; let ifm = document.getElementById('terminal-exec') as HTMLInputElement | null; @@ -133,7 +134,7 @@ const initTerm = (formEl: FormInstance | undefined) => { if (ifm) { term.open(ifm); terminalSocket = new WebSocket( - `ws://${ipLocal}/api/v1/containers/exec?containerid=${form.containerID}&cols=${term.cols}&rows=${term.rows}&user=${form.user}&command=${form.command}`, + `${protocol}://${ipLocal}/api/v1/containers/exec?containerid=${form.containerID}&cols=${term.cols}&rows=${term.rows}&user=${form.user}&command=${form.command}`, ); terminalSocket.onopen = runRealTerminal; terminalSocket.onmessage = onWSReceive; diff --git a/frontend/src/views/database/redis/terminal/index.vue b/frontend/src/views/database/redis/terminal/index.vue index 5cf7168a6..fa50e04cc 100644 --- a/frontend/src/views/database/redis/terminal/index.vue +++ b/frontend/src/views/database/redis/terminal/index.vue @@ -61,6 +61,7 @@ const closeRealTerminal = (ev: CloseEvent) => { const initTerm = () => { let ifm = document.getElementById('terminal-exec') as HTMLInputElement | null; let href = window.location.href; + let protocol = href.split('//')[0] === 'http:' ? 'ws' : 'wss'; let ipLocal = href.split('//')[1].split('/')[0]; term = new Terminal({ lineHeight: 1.2, @@ -77,7 +78,7 @@ const initTerm = () => { if (ifm) { term.open(ifm); terminalSocket = new WebSocket( - `ws://${ipLocal}/api/v1/databases/redis/exec?cols=${term.cols}&rows=${term.rows}`, + `${protocol}://${ipLocal}/api/v1/databases/redis/exec?cols=${term.cols}&rows=${term.rows}`, ); terminalSocket.onopen = runRealTerminal; terminalSocket.onmessage = onWSReceive; diff --git a/frontend/src/views/host/file-management/process/index.vue b/frontend/src/views/host/file-management/process/index.vue index ed18f44d1..ed097d723 100644 --- a/frontend/src/views/host/file-management/process/index.vue +++ b/frontend/src/views/host/file-management/process/index.vue @@ -54,8 +54,9 @@ const onClose = () => {}; const initProcess = () => { let href = window.location.href; + let protocol = href.split('//')[0] === 'http:' ? 'ws' : 'wss'; let ipLocal = href.split('//')[1].split('/')[0]; - processSocket = new WebSocket(`ws://${ipLocal}/api/v1/files/ws`); + processSocket = new WebSocket(`${protocol}://${ipLocal}/api/v1/files/ws`); processSocket.onopen = onOpenProcess; processSocket.onmessage = onMessage; processSocket.onerror = onerror; diff --git a/frontend/src/views/host/terminal/terminal/terminal.vue b/frontend/src/views/host/terminal/terminal/terminal.vue index c353441fd..1e916e451 100644 --- a/frontend/src/views/host/terminal/terminal/terminal.vue +++ b/frontend/src/views/host/terminal/terminal/terminal.vue @@ -84,6 +84,7 @@ const initErrorTerm = (errorInfo: string) => { const initTerm = () => { let ifm = document.getElementById('terminal-' + terminalID.value) as HTMLInputElement | null; let href = window.location.href; + let protocol = href.split('//')[0] === 'http:' ? 'ws' : 'wss'; let ipLocal = href.split('//')[1].split('/')[0]; term = new Terminal({ lineHeight: 1.2, @@ -100,7 +101,7 @@ const initTerm = () => { if (ifm) { term.open(ifm); terminalSocket = new WebSocket( - `ws://${ipLocal}/api/v1/terminals?id=${wsID.value}&cols=${term.cols}&rows=${term.rows}`, + `${protocol}://${ipLocal}/api/v1/terminals?id=${wsID.value}&cols=${term.cols}&rows=${term.rows}`, ); terminalSocket.onopen = runRealTerminal; terminalSocket.onmessage = onWSReceive;