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') }}
{
}
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/redis/password/index.vue b/frontend/src/views/database/redis/conn/index.vue
similarity index 63%
rename from frontend/src/views/database/redis/password/index.vue
rename to frontend/src/views/database/redis/conn/index.vue
index f49d640dc..32e7035eb 100644
--- a/frontend/src/views/database/redis/password/index.vue
+++ b/frontend/src/views/database/redis/conn/index.vue
@@ -12,12 +12,21 @@
-
+
- {{ form.containerName }}
-
+
+ {{ loadRedisInfo(true).substring(0, 48) }}...
+
+
+ {{ loadRedisInfo(true) }}
+
+
6379
@@ -33,8 +42,17 @@
- {{ form.systemIP }}
-
+
+ {{ loadRedisInfo(false).substring(0, 48) }}...
+
+
+ {{ loadRedisInfo(false) }}
+
+
{{ form.port }}
@@ -48,7 +66,12 @@
-
+
@@ -58,6 +81,13 @@
+
+
+
+ {{ form.password }}
+
+
+
@@ -69,7 +99,7 @@
{{ $t('commons.button.cancel') }}
-
+
{{ $t('commons.button.confirm') }}
@@ -82,7 +112,7 @@ import { reactive, ref } from 'vue';
import { Rules } from '@/global/form-rules';
import i18n from '@/lang';
import { ElForm } from 'element-plus';
-import { changeRedisPassword } from '@/api/modules/database';
+import { changeRedisPassword, getDatabase } from '@/api/modules/database';
import ConfirmDialog from '@/components/confirm-dialog/index.vue';
import { GetAppConnInfo } from '@/api/modules/app';
import { MsgSuccess } from '@/utils/message';
@@ -94,11 +124,16 @@ const loading = ref(false);
const dialogVisible = ref(false);
const form = reactive({
- database: '',
- password: '',
- containerName: '',
+ status: '',
systemIP: '',
+ password: '',
+ serviceName: '',
+ containerName: '',
port: 0,
+
+ from: '',
+ database: '',
+ remoteIP: '',
});
const confirmDialogRef = ref();
@@ -109,11 +144,13 @@ type FormInstance = InstanceType;
const formRef = ref();
interface DialogProps {
+ from: string;
database: string;
}
const acceptParams = (params: DialogProps): void => {
- form.database = params.database;
form.password = '';
+ form.from = params.from;
+ form.database = params.database;
loadPassword();
dialogVisible.value = true;
};
@@ -126,14 +163,36 @@ const random = async () => {
};
const loadPassword = async () => {
- const res = await GetAppConnInfo('redis', form.database);
- form.containerName = res.data.containerName;
+ if (form.from === 'local') {
+ const res = await GetAppConnInfo('redis', form.database);
+ form.status = res.data.status;
+ form.password = res.data.password || '';
+ form.port = res.data.port || 3306;
+ form.serviceName = res.data.serviceName || '';
+ form.containerName = res.data.containerName || '';
+ loadSystemIP();
+ return;
+ }
+ const res = await getDatabase(form.database);
+ form.password = res.data.password || '';
+ form.port = res.data.port || 3306;
form.password = res.data.password;
- form.port = res.data.port;
- const settingInfoRes = await getSettingInfo();
- form.systemIP = settingInfoRes.data.systemIP || i18n.global.t('database.localIP');
+ form.remoteIP = res.data.address;
};
+const loadSystemIP = async () => {
+ const res = await getSettingInfo();
+ form.systemIP = res.data.systemIP || i18n.global.t('database.localIP');
+};
+
+function loadRedisInfo(isContainer: boolean) {
+ if (isContainer) {
+ return form.from === 'local' ? form.containerName : form.systemIP;
+ } else {
+ return form.from === 'local' ? form.systemIP : form.remoteIP;
+ }
+}
+
const onSubmit = async () => {
loading.value = true;
emit('closeTerminal');
diff --git a/frontend/src/views/database/redis/index.vue b/frontend/src/views/database/redis/index.vue
index d25a3f8a5..7793b0936 100644
--- a/frontend/src/views/database/redis/index.vue
+++ b/frontend/src/views/database/redis/index.vue
@@ -51,15 +51,13 @@
-
-
-
- {{ $t('database.databaseConnInfo') }}
-
-
- {{ $t('database.remoteDB') }}
-
-
+
+
+ {{ $t('database.databaseConnInfo') }}
+
+
+ {{ $t('database.remoteDB') }}
+
@@ -71,13 +69,10 @@
v-show="redisStatus === 'Running' && terminalShow"
/>
{{ $t('commons.button.enable') }}
@@ -94,8 +89,15 @@
+
+ {{ $t('commons.service.serviceNotStarted', ['Redis']) }}
+
+
-
+
import Setting from '@/views/database/redis/setting/index.vue';
-import Password from '@/views/database/redis/password/index.vue';
+import Conn from '@/views/database/redis/conn/index.vue';
import Terminal from '@/components/terminal/index.vue';
import AppStatus from '@/components/app-status/index.vue';
import QuickCmd from '@/views/database/redis/command/index.vue';
@@ -184,9 +186,13 @@ const goRemoteDB = async () => {
router.push({ name: 'Redis-Remote' });
};
-const passwordRef = ref();
-const onChangePassword = async () => {
- passwordRef.value!.acceptParams({ database: currentDBName.value });
+const connRef = ref();
+const onLoadConn = async () => {
+ connRef.value!.acceptParams({
+ from: currentDB.value.from,
+ type: currentDB.value.type,
+ database: currentDBName.value,
+ });
};
const goRouter = async (target: string) => {
@@ -209,6 +215,7 @@ const changeDatabase = async () => {
}
for (const item of dbOptionsRemote.value) {
if (item.database == currentDBName.value) {
+ maskShow.value = false;
currentDB.value = item;
break;
}
@@ -255,6 +262,11 @@ const loadDBOptions = async () => {
}
};
+const loadErrMsg = () => {
+ return currentDB.value.from === 'local'
+ ? i18n.global.t('commons.service.serviceNotStarted', ['Redis'])
+ : i18n.global.t('database.redisCliHelper');
+};
const reOpenTerminal = async () => {
closeTerminal(false);
initTerminal();