|
|
|
@ -22,22 +22,49 @@ module.exports = {
|
|
|
|
|
password
|
|
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
session: ({ address, port, user, password }, onReady, onClose, onError) => {
|
|
|
|
|
const client = new Client();
|
|
|
|
|
client.on('ready', () => client.shell((error, clientStream) => {
|
|
|
|
|
if(error) return onError(error);
|
|
|
|
|
clientStream.on('unpipe', () => {
|
|
|
|
|
onClose(clientStream);
|
|
|
|
|
client.end();
|
|
|
|
|
});
|
|
|
|
|
onReady(clientStream);
|
|
|
|
|
}));
|
|
|
|
|
client.on('error', onError);
|
|
|
|
|
client.connect({
|
|
|
|
|
host: address,
|
|
|
|
|
port,
|
|
|
|
|
username: user,
|
|
|
|
|
password
|
|
|
|
|
});
|
|
|
|
|
chainedSession: (hostsChain, onReady, onClose, onError) => {
|
|
|
|
|
const clients = [];
|
|
|
|
|
(async () => {
|
|
|
|
|
for(let i = 0; i < hostsChain.length; i++){
|
|
|
|
|
const
|
|
|
|
|
prevClient = clients[i-1],
|
|
|
|
|
{ address, port, user, password } = hostsChain[i],
|
|
|
|
|
nextHost = hostsChain[i+1],
|
|
|
|
|
client = clients[i] = new Client();
|
|
|
|
|
client.on('error', onError);
|
|
|
|
|
await new Promise(resolve => {
|
|
|
|
|
client.on('ready', () => {
|
|
|
|
|
if(nextHost) resolve();
|
|
|
|
|
else {
|
|
|
|
|
client.shell((error, clientStream) => {
|
|
|
|
|
if(error) return onError(error);
|
|
|
|
|
clientStream.on('unpipe', () => {
|
|
|
|
|
onClose(clientStream);
|
|
|
|
|
client.end();
|
|
|
|
|
});
|
|
|
|
|
onReady(clientStream);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if(prevClient){
|
|
|
|
|
client.on('end', () => prevClient.end());
|
|
|
|
|
prevClient.forwardOut('127.0.0.1', 12345 + i, address, port, (error, prevClientStream) => {
|
|
|
|
|
if(error) onError(error);
|
|
|
|
|
client.connect({
|
|
|
|
|
sock: prevClientStream,
|
|
|
|
|
username: user,
|
|
|
|
|
password
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else client.connect({
|
|
|
|
|
host: address,
|
|
|
|
|
port,
|
|
|
|
|
username: user,
|
|
|
|
|
password
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
}
|
|
|
|
|
};
|