From e5bcb07cf612e0a57df45ec2bf1d89f276c2a339 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 30 May 2024 15:13:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E9=81=AE=E7=BD=A9=E9=97=AE=E9=A2=98=20(#5215)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/dto/response/app.go | 1 + backend/app/repo/app_install.go | 3 + backend/app/service/app_install.go | 1 + backend/app/service/database.go | 3 + backend/app/service/database_mysql.go | 11 +++ backend/app/service/database_postgresql.go | 11 +++ backend/app/service/database_redis.go | 11 ++- frontend/src/api/interface/app.ts | 1 + frontend/src/components/app-status/index.vue | 1 + .../src/views/database/mysql/conn/index.vue | 10 +- frontend/src/views/database/mysql/index.vue | 10 +- .../views/database/postgresql/conn/index.vue | 4 +- .../src/views/database/postgresql/index.vue | 10 +- .../redis/{password => conn}/index.vue | 93 +++++++++++++++---- frontend/src/views/database/redis/index.vue | 50 ++++++---- 15 files changed, 166 insertions(+), 54 deletions(-) rename frontend/src/views/database/redis/{password => conn}/index.vue (63%) diff --git a/backend/app/dto/response/app.go b/backend/app/dto/response/app.go index 50f7c5976..69136c90e 100644 --- a/backend/app/dto/response/app.go +++ b/backend/app/dto/response/app.go @@ -73,6 +73,7 @@ type AppInstalledDTO struct { } type DatabaseConn struct { + Status string `json:"status"` Username string `json:"username"` Password string `json:"password"` ContainerName string `json:"containerName"` diff --git a/backend/app/repo/app_install.go b/backend/app/repo/app_install.go index 369719ee1..7de128f4d 100644 --- a/backend/app/repo/app_install.go +++ b/backend/app/repo/app_install.go @@ -3,6 +3,7 @@ package repo import ( "context" "encoding/json" + "github.com/1Panel-dev/1Panel/backend/constant" "gorm.io/gorm/clause" @@ -160,6 +161,7 @@ func (a *AppInstallRepo) BatchUpdateBy(maps map[string]interface{}, opts ...DBOp type RootInfo struct { ID uint `json:"id"` Name string `json:"name"` + Status string `json:"status"` Port int64 `json:"port"` HttpsPort int64 `json:"httpsPort"` UserName string `json:"userName"` @@ -234,5 +236,6 @@ func (a *AppInstallRepo) LoadBaseInfo(key string, name string) (*RootInfo, error info.Key = app.Key appInstall.App = app info.AppPath = appInstall.GetAppPath() + info.Status = appInstall.Status return &info, nil } diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index 028b02768..c9ebedd44 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -184,6 +184,7 @@ func (a *AppInstallService) LoadConnInfo(req dto.OperationWithNameAndType) (resp if err != nil { return data, nil } + data.Status = app.Status data.Username = app.UserName data.Password = app.Password data.ServiceName = app.ServiceName diff --git a/backend/app/service/database.go b/backend/app/service/database.go index f9f2a0835..5dd438ca3 100644 --- a/backend/app/service/database.go +++ b/backend/app/service/database.go @@ -70,6 +70,9 @@ func (u *DatabaseService) Get(name string) (dto.DatabaseInfo, error) { func (u *DatabaseService) List(dbType string) ([]dto.DatabaseOption, error) { dbs, err := databaseRepo.GetList(databaseRepo.WithTypeList(dbType)) + if err != nil { + return nil, err + } var datas []dto.DatabaseOption for _, db := range dbs { var item dto.DatabaseOption diff --git a/backend/app/service/database_mysql.go b/backend/app/service/database_mysql.go index 0df08b88d..fd00419ec 100644 --- a/backend/app/service/database_mysql.go +++ b/backend/app/service/database_mysql.go @@ -363,6 +363,17 @@ func (u *MysqlService) ChangePassword(req dto.ChangeDBInfo) error { if err := updateInstallInfoInDB(req.Type, req.Database, "password", req.Value); err != nil { return err } + if req.From == "local" { + remote, err := databaseRepo.Get(commonRepo.WithByName(req.Database)) + if err != nil { + return err + } + pass, err := encrypt.StringEncrypt(req.Value) + if err != nil { + return fmt.Errorf("decrypt database password failed, err: %v", err) + } + _ = databaseRepo.Update(remote.ID, map[string]interface{}{"password": pass}) + } return nil } diff --git a/backend/app/service/database_postgresql.go b/backend/app/service/database_postgresql.go index b7fafc6a5..ffea87627 100644 --- a/backend/app/service/database_postgresql.go +++ b/backend/app/service/database_postgresql.go @@ -414,5 +414,16 @@ func (u *PostgresqlService) ChangePassword(req dto.ChangeDBInfo) error { if err := updateInstallInfoInDB(req.Type, req.Database, "password", req.Value); err != nil { return err } + if req.From == "local" { + remote, err := databaseRepo.Get(commonRepo.WithByName(req.Database)) + if err != nil { + return err + } + pass, err := encrypt.StringEncrypt(req.Value) + if err != nil { + return fmt.Errorf("decrypt database password failed, err: %v", err) + } + _ = databaseRepo.Update(remote.ID, map[string]interface{}{"password": pass}) + } return nil } diff --git a/backend/app/service/database_redis.go b/backend/app/service/database_redis.go index 3c91a2311..15149f447 100644 --- a/backend/app/service/database_redis.go +++ b/backend/app/service/database_redis.go @@ -13,6 +13,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/utils/compose" "github.com/1Panel-dev/1Panel/backend/utils/docker" + "github.com/1Panel-dev/1Panel/backend/utils/encrypt" "github.com/docker/docker/api/types/container" _ "github.com/go-sql-driver/mysql" ) @@ -87,9 +88,17 @@ func (u *RedisService) ChangePassword(req dto.ChangeRedisPass) error { if err := updateInstallInfoInDB("redis", req.Database, "password", req.Value); err != nil { return err } - if err := updateInstallInfoInDB("redis-commander", "", "password", req.Value); err != nil { + remote, err := databaseRepo.Get(commonRepo.WithByName(req.Database)) + if err != nil { return err } + if remote.From == "local" { + pass, err := encrypt.StringEncrypt(req.Value) + if err != nil { + return fmt.Errorf("decrypt database password failed, err: %v", err) + } + _ = databaseRepo.Update(remote.ID, map[string]interface{}{"password": pass}) + } return nil } diff --git a/frontend/src/api/interface/app.ts b/frontend/src/api/interface/app.ts index a01c885d4..332f474ef 100644 --- a/frontend/src/api/interface/app.ts +++ b/frontend/src/api/interface/app.ts @@ -143,6 +143,7 @@ export namespace App { } export interface DatabaseConnInfo { + status: string; username: string; password: string; privilege: boolean; diff --git a/frontend/src/components/app-status/index.vue b/frontend/src/components/app-status/index.vue index 92e9f03dd..c10455595 100644 --- a/frontend/src/components/app-status/index.vue +++ b/frontend/src/components/app-status/index.vue @@ -185,6 +185,7 @@ const onCheck = async () => { .then((res) => { data.value = res.data; em('isExist', res.data); + em('update:maskShow', res.data.status !== 'Running'); operateReq.installId = res.data.appInstallId; httpPort.value = res.data.httpPort; httpsPort.value = res.data.httpsPort; diff --git a/frontend/src/views/database/mysql/conn/index.vue b/frontend/src/views/database/mysql/conn/index.vue index 94f080ae0..218cabe76 100644 --- a/frontend/src/views/database/mysql/conn/index.vue +++ b/frontend/src/views/database/mysql/conn/index.vue @@ -68,7 +68,11 @@
- + {{ $t('database.remoteConnHelper') }} {{ $t('commons.button.cancel') }} - + {{ $t('commons.button.confirm') }} @@ -134,6 +138,7 @@ const loading = ref(false); const dialogVisible = ref(false); const form = reactive({ + status: '', systemIP: '', password: '', serviceName: '', @@ -201,6 +206,7 @@ const loadSystemIP = async () => { const loadPassword = async () => { if (form.from === 'local') { const res = await GetAppConnInfo(form.type, form.database); + form.status = res.data.status; form.password = res.data.password || ''; form.port = res.data.port || 3306; form.serviceName = res.data.serviceName || ''; diff --git a/frontend/src/views/database/mysql/index.vue b/frontend/src/views/database/mysql/index.vue index f4f127289..0147e857a 100644 --- a/frontend/src/views/database/mysql/index.vue +++ b/frontend/src/views/database/mysql/index.vue @@ -70,12 +70,7 @@ > {{ $t('database.create') }} - + {{ $t('database.databaseConnInfo') }} { } for (const item of dbOptionsRemote.value) { if (item.database == currentDBName.value) { + maskShow.value = false; currentDB.value = item; break; } diff --git a/frontend/src/views/database/postgresql/conn/index.vue b/frontend/src/views/database/postgresql/conn/index.vue index cf477fde9..0f4ffc6b5 100644 --- a/frontend/src/views/database/postgresql/conn/index.vue +++ b/frontend/src/views/database/postgresql/conn/index.vue @@ -112,7 +112,7 @@ {{ $t('commons.button.cancel') }} - + {{ $t('commons.button.confirm') }} @@ -137,6 +137,7 @@ const loading = ref(false); const dialogVisible = ref(false); const form = reactive({ + status: '', systemIP: '', password: '', containerName: '', @@ -202,6 +203,7 @@ const loadSystemIP = async () => { const loadPassword = async () => { if (form.from === 'local') { const res = await GetAppConnInfo(form.type, form.database); + form.status = res.data.status; form.username = res.data.username || ''; form.password = res.data.password || ''; form.port = res.data.port || 5432; diff --git a/frontend/src/views/database/postgresql/index.vue b/frontend/src/views/database/postgresql/index.vue index 2de8e24f8..4b70e2d20 100644 --- a/frontend/src/views/database/postgresql/index.vue +++ b/frontend/src/views/database/postgresql/index.vue @@ -62,12 +62,7 @@ > {{ $t('database.create') }} - + {{ $t('database.databaseConnInfo') }} -