tunnel-ssh
Advanced tools
Comparing version 2.0.1 to 2.1.1
var tunnel = require('../'); | ||
// This is a very handy way to test your next webhook ! | ||
// Please set up your /etc/hosts or change the hostname befor | ||
// running the example. | ||
// The name "local" is currently missleading since you can put | ||
// remove ports as well... | ||
var dstPort = 8000; | ||
var host = 'tunneltest.com'; | ||
tunnel.reverse({ | ||
host: 'agebrock.com', | ||
host: host, | ||
username: 'root', | ||
dstHost: '0.0.0.0', | ||
dstPort: 3000, | ||
localPort: 8000 | ||
}, function() { | ||
console.log(arguments); | ||
dstHost: '0.0.0.0', // bind to all interfaces (see hint in the readme) | ||
dstPort: dstPort, | ||
//localHost: '127.0.0.1', // default | ||
//localPort: localPort | ||
}, function(error, clientConnection) { | ||
console.log(clientConnection._forwarding); | ||
}); | ||
require('http').createServer(function(res, res){ | ||
res.end('SSH-TUNNEL: Gate to heaven !'); | ||
}).listen(localPort); | ||
console.log('Tunnel created: http://'+host+':'+localPort); |
28
index.js
@@ -5,7 +5,9 @@ var net = require('net'); | ||
var createConfig = require('./lib/config'); | ||
var reverse = require('./lib/reverse'); | ||
function bindSSHConnection(config, netConnection) { | ||
var sshConnection = new Connection(); | ||
sshConnection.on('ready', function () { | ||
sshConnection.on('ready', function() { | ||
debug('sshConnection:ready'); | ||
@@ -18,3 +20,3 @@ netConnection.emit('sshConnection', sshConnection, netConnection); | ||
config.dstHost, | ||
config.dstPort, function (err, sshStream) { | ||
config.dstPort, function(err, sshStream) { | ||
if (err) { | ||
@@ -26,3 +28,3 @@ // Bubble up the error => netConnection => server | ||
} | ||
sshStream.once('close', function () { | ||
sshStream.once('close', function() { | ||
debug('sshStream:close'); | ||
@@ -46,8 +48,9 @@ if (config.keepAlive) { | ||
server = net.createServer(function (netConnection) { | ||
server = net.createServer(function(netConnection) { | ||
netConnection.on('error', server.emit.bind(server, 'error')); | ||
server.emit('netConnection', netConnection, server); | ||
sshConnection = bindSSHConnection(config, netConnection); | ||
netConnection.on('sshStream', function (sshStream) { | ||
sshStream.once('close', function () { | ||
sshConnection.on('error', server.emit.bind(server, 'error')); | ||
netConnection.on('sshStream', function(sshStream) { | ||
sshStream.once('close', function() { | ||
debug('sshStream:close'); | ||
@@ -58,3 +61,3 @@ if (!config.keepAlive) { | ||
}); | ||
sshStream.on('error', function () { | ||
sshStream.on('error', function() { | ||
server.close(); | ||
@@ -67,4 +70,4 @@ }); | ||
server.on('close', function () { | ||
connections.forEach(function (connection) { | ||
server.on('close', function() { | ||
connections.forEach(function(connection) { | ||
connection.end(); | ||
@@ -81,3 +84,3 @@ }); | ||
var config = createConfig(configArgs); | ||
} catch (e) { | ||
} catch ( e ) { | ||
if (callback) { | ||
@@ -93,3 +96,6 @@ callback(null, e); | ||
} | ||
tunnel.reverse = require('./lib/reverse'); | ||
tunnel.reverse = function(userConfig, callback) { | ||
return reverse(createConfig(userConfig), callback); | ||
}; | ||
module.exports = tunnel; |
var Client = require('ssh2').Client; | ||
var Socket = require('net').Socket; | ||
var createConfig = require('./config'); | ||
var debug = require('debug'); | ||
function createClient(userConfig, callback) { | ||
var config = createConfig(userConfig); | ||
function createClient(config, callback) { | ||
@@ -23,3 +21,2 @@ var remoteHost = config.dstHost; | ||
} | ||
console.log('Listening for connections on server on port ' + remotePort + '!'); | ||
}); | ||
@@ -47,3 +44,3 @@ }); | ||
if (errors.length === 0) { | ||
callback(null, true); | ||
callback(null, conn); | ||
} else { | ||
@@ -56,5 +53,5 @@ callback(errors, null); | ||
return conn.connect(config); | ||
}; | ||
} | ||
module.exports = createClient; | ||
{ | ||
"name": "tunnel-ssh", | ||
"version": "2.0.1", | ||
"version": "2.1.1", | ||
"description": "Easy extendable SSH tunnel", | ||
@@ -25,9 +25,9 @@ "main": "index.js", | ||
"debug": "2.2.0", | ||
"lodash": "^3.5.0", | ||
"lodash": "4.5.1", | ||
"ssh2": "^0.4.8" | ||
}, | ||
"devDependencies": { | ||
"chai": "3.4.1", | ||
"mocha": "2.3.3" | ||
"chai": "3.5.0", | ||
"mocha": "2.4.5" | ||
} | ||
} |
@@ -11,6 +11,18 @@ Tunnel-SSH | ||
v2.0.0 Released ! | ||
We're happy to introduce "reverse Tunnel" | ||
v2.1.1 Released ! | ||
* Server now throws client exceptions see Example below Thx @joshbalfour | ||
* Improved reverse proxy and example | ||
##So what about next major version ? | ||
With version 3 we will introduce a new feature to enable the developer to use | ||
tunnel-ssh without wrapping your code, a feature i was asked very often for. | ||
We think we have found a very good solution for that, and we already testing | ||
the beta in production. | ||
We want to make next release to be as stable as v2 but way more powerful and | ||
easy to use. Until then we support both versions. | ||
Keep digging ! | ||
## Howto | ||
@@ -43,18 +55,53 @@ | ||
####catch SSH errors that occur outside of setup: | ||
```js | ||
var tunnel = require('tunnel-ssh'); | ||
//map port from remote 3306 to localhost 3306 | ||
var server = tunnel({host: '172.16.0.8', dstPort: 3306}, function (error, result) { | ||
//you can start using your resources here. (mongodb, mysql, ....) | ||
console.log('connected'); | ||
}); | ||
server.on('error', function(err){ | ||
console.error('Something bad happened:', err); | ||
}); | ||
``` | ||
####Reverse tunnel | ||
The reverse tunnel can be used to bypass network restictions, | ||
or to listen to webhocks on your local machine. | ||
The reverse tunnel can be used to bypass network restrictions, | ||
or to listen to web-hocks on your local machine. | ||
```js | ||
var tunnel = require('../'); | ||
// This is a very handy way to test your next web-hook ! | ||
// Please set up your /etc/hosts or change the hostname before | ||
// running the example. | ||
// The name "local" is currently misleading since you can put | ||
// remove ports as well... | ||
var dstPort = 8000; | ||
var host = 'tunneltest.com'; | ||
tunnel.reverse({ | ||
host: host, | ||
username: 'root', | ||
dstHost: '127.0.0.1', | ||
dstPort: 3000, | ||
localPort: 8000, | ||
host: 'remote.machine.io' | ||
}, function() { | ||
console.log(arguments); | ||
dstHost: '0.0.0.0', // bind to all interfaces (see hint in the readme) | ||
dstPort: dstPort, | ||
//localHost: '127.0.0.1', // default | ||
//localPort: localPort | ||
}, function(error, clientConnection) { | ||
console.log(clientConnection._forwarding); | ||
}); | ||
require('http').createServer(function(res, res){ | ||
res.end('SSH-TUNNEL: Gate to heaven !'); | ||
}).listen(localPort); | ||
console.log('Tunnel created: http://'+host+':'+localPort); | ||
``` | ||
@@ -74,7 +121,2 @@ | ||
You can find more examples here | ||
tunnel-ssh supports the default ssh2 configuration. | ||
@@ -81,0 +123,0 @@ ```js |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
27269
382
136
9
+ Addedlodash@4.5.1(transitive)
- Removedlodash@3.10.1(transitive)
Updatedlodash@4.5.1