Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tunnel-ssh

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tunnel-ssh - npm Package Compare versions

Comparing version 5.0.4 to 5.0.5

75

index.js

@@ -5,6 +5,6 @@ const net = require('net');

function autoClose(server, connection){
connection.on('close',()=>{
server.getConnections((error, count)=>{
if(count === 0){
function autoClose(server, connection) {
connection.on('close', () => {
server.getConnections((error, count) => {
if (count === 0) {
server.close();

@@ -16,13 +16,20 @@ }

async function createServer(options){
return new Promise(function(resolve, reject){
async function createServer(options) {
return new Promise((resolve, reject) => {
let server = net.createServer();
let errorHandler = function (error) {
reject(error);
};
server.on('error', errorHandler);
process.on('uncaughtException', errorHandler);
server.listen(options);
server.on('listening', ()=> resolve(server));
server.on('error', reject);
server.on('listening', () => {
process.removeListener('uncaughtException', errorHandler);
resolve(server);
});
});
}
async function createClient(config){
return new Promise(function(resolve, reject){
async function createClient(config) {
return new Promise(function (resolve, reject) {
let conn = new Client();

@@ -35,27 +42,35 @@ conn.on('ready', () => resolve(conn));

async function createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions){
async function createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions) {
return new Promise(function(resolve, reject){
createServer(serverOptions).then(function(server, reject){
createClient(sshOptions).then(function(conn){
server.on('connection',(connection)=>{
if(tunnelOptions.autoClose){
autoClose(server, connection);
}
return new Promise(async function (resolve, reject) {
let server, conn;
try {
server = await createServer(serverOptions);
} catch (e) {
return reject(e);
}
conn.forwardOut(
forwardOptions.srcAddr,
forwardOptions.srcPort,
forwardOptions.dstAddr,
forwardOptions.dstPort, (err, stream) => {
connection.pipe(stream).pipe(connection);
});
try {
conn = await createClient(sshOptions);
} catch (e) {
return reject(e);
}
server.on('connection', (connection) => {
if (tunnelOptions.autoClose) {
autoClose(server, connection);
}
conn.forwardOut(
forwardOptions.srcAddr,
forwardOptions.srcPort,
forwardOptions.dstAddr,
forwardOptions.dstPort, (err, stream) => {
connection.pipe(stream).pipe(connection);
});
server.on('close',()=> conn.end());
resolve([server, conn]);
});
});
server.on('close', () => conn.end());
resolve([server, conn]);
});

@@ -62,0 +77,0 @@ }

2

package.json
{
"name": "tunnel-ssh",
"version": "5.0.4",
"version": "5.0.5",
"description": "Easy extendable SSH tunnel",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc