ssh_tunnel_proxy 1.2.5 → 1.2.6
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/.vscode/launch.json +1 -1
- package/lib/index.js +39 -5
- package/main.js +30 -23
- package/package.json +1 -1
package/.vscode/launch.json
CHANGED
package/lib/index.js
CHANGED
|
@@ -157,6 +157,29 @@ class SSHTunnelProxy extends Client {
|
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
exec_next() {
|
|
161
|
+
const _this = this;
|
|
162
|
+
const remote_exec = (err, stream) => {
|
|
163
|
+
if (err) throw err;
|
|
164
|
+
stream.on('close', () => {
|
|
165
|
+
process.stdout.write('-- exec completed --\n\n');
|
|
166
|
+
if (!_this.exec_next()) process.exit();
|
|
167
|
+
}).on('data', (data) => {
|
|
168
|
+
process.stdout.write(data);
|
|
169
|
+
}).stderr.on('data', (data) => {
|
|
170
|
+
process.stderr.write(data);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (this.exec_cmds.length > 0) {
|
|
174
|
+
const cmd = this.exec_cmds[0];
|
|
175
|
+
this.exec_cmds.shift();
|
|
176
|
+
console.log('$: ' + cmd);
|
|
177
|
+
this.exec(cmd, remote_exec);
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
|
|
160
183
|
// handle remote shell stream processing
|
|
161
184
|
remote_shell(err, stream) {
|
|
162
185
|
const _this = this;
|
|
@@ -206,16 +229,27 @@ class SSHTunnelProxy extends Client {
|
|
|
206
229
|
|
|
207
230
|
_this.on('ready', () => {
|
|
208
231
|
|
|
232
|
+
// stop any pending retry timeouts
|
|
233
|
+
if (_this._tunnelReadyTimeout) {
|
|
234
|
+
clearTimeout(this._tunnelReadyTimeout);
|
|
235
|
+
_this._tunnelReadyTimeout = undefined;
|
|
236
|
+
}
|
|
237
|
+
|
|
209
238
|
// if shell requested, enable remote terminal
|
|
210
239
|
if (opts.shell) {
|
|
211
240
|
_this.shell(_this.remote_shell);
|
|
241
|
+
|
|
242
|
+
// if exec requested, exec series of cmds
|
|
243
|
+
} else {
|
|
244
|
+
if (opts.exec && opts.exec.length > 0) {
|
|
245
|
+
_this.exec_cmds = opts.exec;
|
|
246
|
+
_this.exec_next();
|
|
247
|
+
}
|
|
212
248
|
}
|
|
213
249
|
|
|
214
|
-
// setup local forwarding ports to remote host
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
clearTimeout(this._tunnelReadyTimeout);
|
|
218
|
-
_this._tunnelReadyTimeout = undefined
|
|
250
|
+
// if local forward requested, setup local forwarding ports to remote host
|
|
251
|
+
if (opts.proxy_ports) {
|
|
252
|
+
_this.on_ssh_client_ready(opts.server_name, opts.proxy_ports, resolve);
|
|
219
253
|
}
|
|
220
254
|
});
|
|
221
255
|
|
package/main.js
CHANGED
|
@@ -5,6 +5,7 @@ const { SSHTunnelProxy, KeypairStorage } = require('./lib/index.js');
|
|
|
5
5
|
const keypairStorage = new KeypairStorage();
|
|
6
6
|
const homedir = require('os').homedir();
|
|
7
7
|
var debug = false;
|
|
8
|
+
var exec = [];
|
|
8
9
|
var proxies = [];
|
|
9
10
|
var configs = null;
|
|
10
11
|
var host = null;
|
|
@@ -51,15 +52,22 @@ function main(args) {
|
|
|
51
52
|
const cmd = arg[0];
|
|
52
53
|
const value = arg[1];
|
|
53
54
|
switch (cmd) {
|
|
54
|
-
case '
|
|
55
|
-
|
|
56
|
-
debug = true;
|
|
55
|
+
case '--a':
|
|
56
|
+
account = value;
|
|
57
57
|
break;
|
|
58
58
|
case '-c':
|
|
59
59
|
case '--config':
|
|
60
60
|
if (value) get_config(value);
|
|
61
61
|
else get_default_config();
|
|
62
62
|
break;
|
|
63
|
+
case '-d':
|
|
64
|
+
case '--debug':
|
|
65
|
+
debug = true;
|
|
66
|
+
break;
|
|
67
|
+
case '-e':
|
|
68
|
+
case '--exec':
|
|
69
|
+
exec.push(value);
|
|
70
|
+
break;
|
|
63
71
|
case '-h':
|
|
64
72
|
case '--host':
|
|
65
73
|
host = value;
|
|
@@ -68,10 +76,6 @@ function main(args) {
|
|
|
68
76
|
case '--port':
|
|
69
77
|
port = value;
|
|
70
78
|
break;
|
|
71
|
-
case '-u':
|
|
72
|
-
case '--username':
|
|
73
|
-
username = value;
|
|
74
|
-
break;
|
|
75
79
|
case '-P':
|
|
76
80
|
case '--password':
|
|
77
81
|
password = value;
|
|
@@ -80,28 +84,29 @@ function main(args) {
|
|
|
80
84
|
case '--key':
|
|
81
85
|
privateKey = value;
|
|
82
86
|
break;
|
|
83
|
-
case '-s':
|
|
84
|
-
case '--service':
|
|
85
|
-
service = value;
|
|
86
|
-
break;
|
|
87
|
-
case '-S':
|
|
88
|
-
case '--shell':
|
|
89
|
-
shell = true;
|
|
90
|
-
break;
|
|
91
|
-
case '--a':
|
|
92
|
-
account = value;
|
|
93
|
-
break;
|
|
94
87
|
case '-L':
|
|
95
88
|
case '--LocalForward':
|
|
96
89
|
forwardOut.push(value);
|
|
97
90
|
break;
|
|
91
|
+
case '-n':
|
|
92
|
+
case '--ngrok':
|
|
93
|
+
ngrokAPIKey = value;
|
|
94
|
+
break;
|
|
98
95
|
case '-R':
|
|
99
96
|
case '--RemoteForward':
|
|
100
97
|
forwardIn.push(value);
|
|
101
98
|
break;
|
|
102
|
-
case '-
|
|
103
|
-
case '--
|
|
104
|
-
|
|
99
|
+
case '-s':
|
|
100
|
+
case '--service':
|
|
101
|
+
service = value;
|
|
102
|
+
break;
|
|
103
|
+
case '-S':
|
|
104
|
+
case '--shell':
|
|
105
|
+
shell = true;
|
|
106
|
+
break;
|
|
107
|
+
case '-u':
|
|
108
|
+
case '--username':
|
|
109
|
+
username = value;
|
|
105
110
|
break;
|
|
106
111
|
default:
|
|
107
112
|
if (i > 1) console.log('Invalid argument:', arg);
|
|
@@ -145,9 +150,11 @@ function main(args) {
|
|
|
145
150
|
config.private_key = get_key_from_file(config.private_key);
|
|
146
151
|
}
|
|
147
152
|
if (shell) {
|
|
148
|
-
config.shell=true;
|
|
153
|
+
config.shell = true;
|
|
154
|
+
}
|
|
155
|
+
if (exec.length > 0) {
|
|
156
|
+
config.exec = exec;
|
|
149
157
|
}
|
|
150
|
-
|
|
151
158
|
// create new tunnel and start connection
|
|
152
159
|
var sshTunnelProxy = new SSHTunnelProxy();
|
|
153
160
|
proxies.push(sshTunnelProxy);
|