From 1f2dfce7d1068601f51520db23f54c8918bcf1b8 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 4 May 2023 14:14:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=9D=E5=A7=8B=E5=8C=96=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E6=97=B6=EF=BC=8C=E5=AF=B9=E5=AF=86=E7=A0=81=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E5=8A=A0=E5=AF=86=E6=93=8D=E4=BD=9C=20(#860)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/init/migration/migrations/init.go | 8 ++++++-- backend/init/viper/viper.go | 6 +++--- frontend/src/components/error-message/unsafe.vue | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/backend/init/migration/migrations/init.go b/backend/init/migration/migrations/init.go index 70132e721..e6f5702ba 100644 --- a/backend/init/migration/migrations/init.go +++ b/backend/init/migration/migrations/init.go @@ -8,6 +8,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/common" + "github.com/1Panel-dev/1Panel/backend/utils/encrypt" "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" @@ -61,10 +62,13 @@ var AddTableSetting = &gormigrate.Migration{ if err := tx.AutoMigrate(&model.Setting{}); err != nil { return err } + encryptKey := common.RandStr(16) if err := tx.Create(&model.Setting{Key: "UserName", Value: global.CONF.System.Username}).Error; err != nil { return err } - if err := tx.Create(&model.Setting{Key: "Password", Value: global.CONF.System.Password}).Error; err != nil { + global.CONF.System.EncryptKey = encryptKey + pass, _ := encrypt.StringEncrypt(global.CONF.System.Password) + if err := tx.Create(&model.Setting{Key: "Password", Value: pass}).Error; err != nil { return err } if err := tx.Create(&model.Setting{Key: "Email", Value: ""}).Error; err != nil { @@ -97,7 +101,7 @@ var AddTableSetting = &gormigrate.Migration{ if err := tx.Create(&model.Setting{Key: "JWTSigningKey", Value: common.RandStr(16)}).Error; err != nil { return err } - if err := tx.Create(&model.Setting{Key: "EncryptKey", Value: common.RandStr(16)}).Error; err != nil { + if err := tx.Create(&model.Setting{Key: "EncryptKey", Value: encryptKey}).Error; err != nil { return err } diff --git a/backend/init/viper/viper.go b/backend/init/viper/viper.go index 3f91a22e7..660c1070b 100644 --- a/backend/init/viper/viper.go +++ b/backend/init/viper/viper.go @@ -107,9 +107,9 @@ func loadParams(param string) string { if err != nil { panic(err) } - baseDir := strings.ReplaceAll(stdout, "\n", "") - if len(baseDir) == 0 { + info := strings.ReplaceAll(stdout, "\n", "") + if len(info) == 0 || info == `""` { panic(fmt.Sprintf("error `%s` find in /usr/bin/1pctl", param)) } - return baseDir + return info } diff --git a/frontend/src/components/error-message/unsafe.vue b/frontend/src/components/error-message/unsafe.vue index 8ef1f225a..92ea972bf 100644 --- a/frontend/src/components/error-message/unsafe.vue +++ b/frontend/src/components/error-message/unsafe.vue @@ -22,7 +22,7 @@ import { MsgSuccess } from '@/utils/message'; const onCopy = () => { let input = document.createElement('input'); - input.value = '1pcth user-info'; + input.value = '1pctl user-info'; document.body.appendChild(input); input.select(); document.execCommand('Copy');