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 0.0.2 to 0.0.3

94

index.js

@@ -13,4 +13,3 @@ /**

self._config = config;
self._shutdown = false;
if(callback){
if (callback) {
self.connect(callback);

@@ -20,23 +19,2 @@ }

SSHTunnel.prototype.create = function (callback) {
var self = this;
var remotePort = self._config.remotePort;
var c = new Connection();
c.on('ready', function () {
c.forwardOut('127.0.0.1', remotePort, '127.0.0.1', remotePort, callback);
});
c.on('error', function (err) {
self.log('Connection :: error :: ' + err);
});
c.on('end', function () {
self.log('Connection :: end');
});
c.on('close', function (err) {
self.log('Connection :: close');
c.end();
});
c.connect(self._config.sshConfig);
};
SSHTunnel.prototype.log = function () {

@@ -48,5 +26,10 @@ if (this._verbose) {

SSHTunnel.prototype.end = function () {
SSHTunnel.prototype.close = function (callback) {
var self = this;
self.server.end();
this.server.close(function(error){
self.connection.end();
if(callback){
callback(error);
}
});
};

@@ -56,24 +39,57 @@

var self = this;
self.server = net.createServer(function (connection) {
self.create(function(error, stream){
connection.pipe(stream);
stream.pipe(connection);
var remotePort = self._config.remotePort;
var localPort = self._config.localPort;
var c = self.connection = new Connection();
stream.on('data', function (data) {
self.log('TCP :: DATA: ' + data);
});
c.on('ready', function () {
stream.on('error', function (err) {
self.log('TCP :: ERROR: ' + err);
self.log('RECONNECTING');
});
self.server = net.createServer(function (connection) {
var buffers = [];
stream.on('close', function (err) {
console.log('STREAM::close');
var addBuffer = function (data) {
buffers.push(data);
};
connection.on('data', addBuffer);
c.forwardOut('', 0, '127.0.0.1', remotePort, function (error, ssh) {
while (buffers.length) {
ssh.write(buffers.shift());
}
connection.removeListener('data', addBuffer);
ssh.on('data', function (buf) {
connection.write(buf);
});
connection.on('data', function (buf) {
ssh.write(buf);
});
connection.on('end', function () {
self.log('connection::end');
ssh.removeAllListeners();
ssh.end();
});
ssh.on('end', function () {
self.log('ssh::end');
connection.removeAllListeners();
connection.end();
});
});
});
self.server.listen(localPort, callback);
});
self.server.listen(self._config.localPort, callback);
c.on('error', function (err) {
self.log('ssh2::error:: ' + err);
});
c.on('end', function () {
self.log('ssh2::end');
});
c.on('close', function (err) {
self.log('ssh2::close');
});
c.connect(self._config.sshConfig);
};
module.exports = SSHTunnel;
{
"name": "tunnel-ssh",
"version": "0.0.2",
"version": "0.0.3",
"description": "Easy ssh tunneling",

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

@@ -15,3 +15,3 @@ Tunnel-SSH

verbose: true, // dump information to stdout
sshConfig: { //ssh2 configuration
sshConfig: { //ssh2 configuration (https://github.com/mscdex/ssh2)
host: '<yourRemoteIp>',

@@ -25,9 +25,11 @@ port: 22,

var x = new Tunnel(config);
x.connect(function (error) {
var tunnel = new Tunnel(config);
tunnel.connect(function (error) {
console.log(error);
// start useing the tunnel
// Bsp. Try mongo shell "#mongo"
//or start your remote connection here ....
//mongoose.connect(...);
//or start your mongo connection here ....
//close tunnel to exit script
tunnel.close();
});
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