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() {