ssh_tunnel_proxy 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,8 +3,39 @@ Initiate a ssh reverse tunnel proxy with forwarding ports
3
3
 
4
4
  ssh_tunnel_proxy can function as a stand-alone api or part of an electron_js app. To establish a ssh tunnel proxy a keypair is generated on the client and stored in the system keychain.
5
5
  If a ngrok api key is provided the ngrok api endpoint method is invoked to obtain the hostport of
6
- the tunnel. A list of port forwards is provided to the connect_api function and ports validated to
7
- restrict connections to system ports on the remote host to a set of pre-defined ports such as http,https.
8
- After establishing a ssh connection to the remote server, local proxy port forwards are opened. If
9
- the connection is interrupted then the ssh_connect method will attempt to re-establish the connection.
6
+ the tunnel. A list of port forwards is provided to the connect_api function and ports validated to restrict connections to system ports on the remote host to a set of pre-defined ports such as http,https. After establishing a ssh connection to the remote server, local proxy port forwards are opened. If the connection is interrupted then the ssh_connect method will attempt to re-establish the connection.
10
7
 
8
+ Example code for electron_js:
9
+ ```js
10
+ async function init_sshTunnelProxy(win) {
11
+
12
+ const SSHTunnelProxy = require('ssh_tunnel_proxy');
13
+ const sshTunnelProxy = new SSHTunnelProxy();
14
+
15
+ ipcMain.on('connect_ssh_sync', async function(event,opts) {
16
+ // only allow connection on remote server to system ports http,https,ssh and user ports >1023
17
+ const portWhitelist = {
18
+ 80:true,
19
+ 443:true,
20
+ 22:true
21
+ }
22
+ await sshTunnelProxy.connectSSH(opts, portWhitelist);
23
+ event.returnValue = 'connected';
24
+ });
25
+
26
+ ipcMain.on('generate_keypair', async (event, ...args) => await sshTunnelProxy.generateAndStoreKeypair(...args));
27
+
28
+ ipcMain.on('get_public_key', async (event, ...args) => await sshTunnelProxy.getPublicKey(...args));
29
+
30
+ ipcMain.on('network_online', (event, ...args) => sshTunnelProxy.onNetworkOnline(...args));
31
+
32
+ ipcMain.on('network_offline', (event, ...args) => sshTunnelProxy.onNetworkOffline(...args));
33
+
34
+ sshTunnelProxy.on('ready',(...args) => win.webContents.send('ready',...args));
35
+
36
+ sshTunnelProxy.on('debug',(...args) => win.webContents.send('debug',...args));
37
+
38
+ sshTunnelProxy.on('error',(...args) => win.webContents.send('error',...args));
39
+
40
+ };
41
+ ```
package/lib/index.js CHANGED
@@ -51,9 +51,6 @@ class sshTunnelProxy extends EventEmitter {
51
51
  });
52
52
  }
53
53
 
54
- // ssh client debug function for verbose ssh connection details
55
- debug_client = (debug_ssh) ? (msg) => { console.log(msg); } : null;
56
-
57
54
  // create forward out on socket connection
58
55
  setup_ssh_forward(ssh_client, socket, remote_hostname, remote_port) {
59
56
  const _this = this;
@@ -149,7 +146,7 @@ class sshTunnelProxy extends EventEmitter {
149
146
  return new Promise((resolve, reject) => {
150
147
 
151
148
  // exit if connection already established, avoid redundant connection on retry
152
- if (_this.listener[opts.server_name] && listener[opts.server_name].isConnected) reject();
149
+ if (_this.listener[opts.server_name] && _this.listener[opts.server_name].isConnected) resolve();
153
150
 
154
151
  // close open sockets on server, otherwise initialize open sockets storage
155
152
  if (_this.listener[opts.server_name]) {
@@ -334,6 +331,9 @@ class sshTunnelProxy extends EventEmitter {
334
331
  keypairStorage.get_public_key_from_keychain(...args);
335
332
  }
336
333
 
334
+ // ssh client debug function for verbose ssh connection details
335
+ debug_client = (debug_ssh) ? (msg) => { console.log(msg); } : null;
336
+
337
337
  debug = (...args) => { console.log(...args); }
338
338
 
339
339
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh_tunnel_proxy",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "obtain ngrok host port from api and establish a ssh connection",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {