From 66f4153981d9396d25177267dad293ed26a7ac8f Mon Sep 17 00:00:00 2001 From: chaoszhu Date: Tue, 23 Jul 2024 11:27:00 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E9=9D=9E=E5=87=AD?= =?UTF-8?q?=E6=8D=AE=E7=99=BB=E5=BD=95=E7=BB=88=E7=AB=AF=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app/config/index.js | 4 ++-- server/app/socket/sftp.js | 2 ++ server/app/socket/terminal.js | 7 ++++--- server/app/utils/db-class.js | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/server/app/config/index.js b/server/app/config/index.js index f998840..b0b4bd9 100644 --- a/server/app/config/index.js +++ b/server/app/config/index.js @@ -8,9 +8,9 @@ module.exports = { uploadDir: path.join(process.cwd(),'app/db'), staticDir: path.join(process.cwd(),'app/static'), sftpCacheDir: path.join(process.cwd(),'app/socket/sftp-cache'), - sshRecordDBPath: path.join(process.cwd(),'app/db/ssh-record.db'), + credentialsDBPath: path.join(process.cwd(),'app/db/credentials.db'), keyDBPath: path.join(process.cwd(),'app/db/key.db'), - hostListDBPath: path.join(process.cwd(),'app/db/host-list.db'), + hostListDBPath: path.join(process.cwd(),'app/db/host.db'), notifyConfDBPath: path.join(process.cwd(),'app/db/notify.db'), groupConfDBPath: path.join(process.cwd(),'app/db/group.db'), emailNotifyDBPath: path.join(process.cwd(),'app/db/email.db'), diff --git a/server/app/socket/sftp.js b/server/app/socket/sftp.js index e6e7ac0..c8e0abd 100644 --- a/server/app/socket/sftp.js +++ b/server/app/socket/sftp.js @@ -226,6 +226,8 @@ module.exports = (httpServer) => { const sshRecord = sshRecordList.find(item => item._id === credentialId) authInfo.authType = sshRecord.authType authInfo[authInfo.authType] = await AESDecryptSync(sshRecord[authInfo.authType]) + } else { + authInfo[authType] = await AESDecryptSync(targetHostInfo[authType]) } consola.info('准备连接Sftp面板:', host) targetHostInfo[targetHostInfo.authType] = await AESDecryptSync(targetHostInfo[targetHostInfo.authType]) diff --git a/server/app/socket/terminal.js b/server/app/socket/terminal.js index f383683..d29ba3f 100644 --- a/server/app/socket/terminal.js +++ b/server/app/socket/terminal.js @@ -63,15 +63,16 @@ module.exports = (httpServer) => { const sshRecord = sshRecordList.find(item => item._id === credentialId) authInfo.authType = sshRecord.authType authInfo[authInfo.authType] = await AESDecryptSync(sshRecord[authInfo.authType]) + } else { + authInfo[authType] = await AESDecryptSync(targetHostInfo[authType]) } consola.info('准备连接终端:', host) targetHostInfo[targetHostInfo.authType] = await AESDecryptSync(targetHostInfo[targetHostInfo.authType]) - // :TODO: 初始化后连接失败... - // console.log('targetHostInfo:', targetHostInfo) + console.log('authInfo:', authInfo) consola.log('连接信息', { username, port, authType }) sshClient .on('ready', () => { - consola.success('已连接到终端:', host) + consola.success('连接终端成功:', host) socket.emit('connect_success', `已连接到终端:${ host }`) createTerminal(socket, sshClient) }) diff --git a/server/app/utils/db-class.js b/server/app/utils/db-class.js index effc3be..4498bbc 100644 --- a/server/app/utils/db-class.js +++ b/server/app/utils/db-class.js @@ -1,5 +1,5 @@ const Datastore = require('@seald-io/nedb') -const { sshRecordDBPath, hostListDBPath, keyDBPath, emailNotifyDBPath, notifyConfDBPath, groupConfDBPath } = require('../config') +const { credentialsDBPath, hostListDBPath, keyDBPath, emailNotifyDBPath, notifyConfDBPath, groupConfDBPath } = require('../config') module.exports.KeyDB = class KeyDB { constructor() { @@ -26,7 +26,7 @@ module.exports.HostListDB = class HostListDB { module.exports.SshRecordDB = class SshRecordDB { constructor() { if (!SshRecordDB.instance) { - SshRecordDB.instance = new Datastore({ filename: sshRecordDBPath, autoload: true }) + SshRecordDB.instance = new Datastore({ filename: credentialsDBPath, autoload: true }) } } getInstance() {