|
|
|
@ -1,28 +1,7 @@
|
|
|
|
|
const { Client } = require('ssh2');
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
test: ({ address, port, user, password }) => new Promise((resolve, reject) => {
|
|
|
|
|
const client = new Client();
|
|
|
|
|
client.on('error', ({ level: error }) => {
|
|
|
|
|
if(error === 'client-authentication')
|
|
|
|
|
reject('WRONG_CREDENTIALS');
|
|
|
|
|
else if(['client-socket', 'client-timeout'].includes(error))
|
|
|
|
|
reject('WRONG_DESTINATION');
|
|
|
|
|
else
|
|
|
|
|
reject();
|
|
|
|
|
});
|
|
|
|
|
client.on('ready', () => {
|
|
|
|
|
client.end();
|
|
|
|
|
resolve();
|
|
|
|
|
});
|
|
|
|
|
client.connect({
|
|
|
|
|
host: address,
|
|
|
|
|
port,
|
|
|
|
|
username: user,
|
|
|
|
|
password
|
|
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
chainedSession: (hostsChain, onReady, onClose, onError) => {
|
|
|
|
|
chainedSession: (hostsChain, onReady, onClose, onError, isTest) => {
|
|
|
|
|
const clients = [];
|
|
|
|
|
(async () => {
|
|
|
|
|
for(let i = 0; i < hostsChain.length; i++){
|
|
|
|
@ -36,7 +15,11 @@ module.exports = {
|
|
|
|
|
client.on('ready', () => {
|
|
|
|
|
if(nextHost) resolve();
|
|
|
|
|
else {
|
|
|
|
|
client.shell((error, clientStream) => {
|
|
|
|
|
if(isTest){
|
|
|
|
|
client.end();
|
|
|
|
|
onReady();
|
|
|
|
|
}
|
|
|
|
|
else client.shell((error, clientStream) => {
|
|
|
|
|
if(error) return onError(error);
|
|
|
|
|
clientStream.on('unpipe', () => {
|
|
|
|
|
onClose(clientStream);
|
|
|
|
|