ssh2shell 2.0.3 → 2.0.4

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
@@ -4,6 +4,31 @@ ssh2shell
4
4
 
5
5
  Ssh2shell uses [ssh2](https://www.npmjs.org/package/ssh2) to open a ssh shell session to a host/s to run multiple commands and process the responses.
6
6
 
7
+ Index:
8
+ ------------
9
+ * [Instalation](https://github.com/cmp-202/ssh2shell#installation)
10
+ * [Minimal Example](https://github.com/cmp-202/ssh2shell#minimal-example)
11
+ * [Host Configuration](https://github.com/cmp-202/ssh2shell#host-configuration)
12
+ * [ssh2shell API](https://github.com/cmp-202/ssh2shell#ssh2shell-api)
13
+ * [Connecting to a single host](https://github.com/cmp-202/ssh2shell#connecting-to-a-single-host)
14
+ * [Authentication](https://github.com/cmp-202/ssh2shell#authentication)
15
+ * [Default Cyphers](https://github.com/cmp-202/ssh2shell#default-cyphers)
16
+ * [Fingerprint Validation](https://github.com/cmp-202/ssh2shell#fingerprint-validation)
17
+ * [Keyboard-interactive](https://github.com/cmp-202/ssh2shell#keyboard-interactive)
18
+ * [Trouble shooting](https://github.com/cmp-202/ssh2shell#trouble-shooting)
19
+ * [Verbose and Debug](https://github.com/cmp-202/ssh2shell#verbose-and-debug)
20
+ * [Notification commands](https://github.com/cmp-202/ssh2shell#notification-commands)
21
+ * [Sudo and su Commands](https://github.com/cmp-202/ssh2shell#sudo-and-su-commands)
22
+ * [Prompt detection override](https://github.com/cmp-202/ssh2shell#prompt-detection-override)
23
+ * [Text regular expression filters](https://github.com/cmp-202/ssh2shell#text-regular-expression-filters)
24
+ * [Responding to non-standard command prompts](https://github.com/cmp-202/ssh2shell#responding-to-non-standard-command-prompts)
25
+ * [Command Time-out event](https://github.com/cmp-202/ssh2shell#command-time-out-event)
26
+ * [Multiple Primary Hosts](https://github.com/cmp-202/ssh2shell#multiple-primary-hosts)
27
+ * [Tunnelling nested host objects](https://github.com/cmp-202/ssh2shell#tunnelling-nested-host-objects)
28
+ * [Event Handlers](https://github.com/cmp-202/ssh2shell#event-handlers)
29
+ * [Bash scripts on the fly](https://github.com/cmp-202/ssh2shell#bash-scripts-on-the-fly)
30
+
31
+
7
32
  Installation:
8
33
  ------------
9
34
  ```
@@ -109,8 +134,9 @@ host = {
109
134
  readyMessage: "Ready",
110
135
  closedMessage: "Closed",
111
136
 
112
- //Optional: Host event handlers .
113
- //Host defined event handlers are set as the default event handlers.
137
+ //Optional: Host event handlers.
138
+ //Host defined event handlers are cleared with each change of host.
139
+ //Default and instance event handlers are global to all hosts and are not cleared.
114
140
 
115
141
  //Optional:
116
142
  onKeyboardInteractive: function(name, instructions, instructionsLang, prompts, finish){
@@ -611,6 +637,78 @@ SSH.connect();
611
637
  ```
612
638
 
613
639
 
640
+ Multiple Primary Hosts:
641
+ -----------------------
642
+ Multiple hosts can be connected to one after the other as you would connecting to a single host.
643
+ Each host config is independant of each other but can share thingsa like commands and handlers.
644
+ Each host config is added to an array of hosts that is passed to the constructor.
645
+ The final `sessionText` contains the output from all the hosts.
646
+
647
+ ```javascript
648
+ var dotenv = require('dotenv').config(),
649
+ debug = false,
650
+ verbose = false
651
+
652
+
653
+ //Host objects:
654
+ var host1 = {
655
+ server: {
656
+ host: process.env.HOST,
657
+ port: process.env.PORT,
658
+ userName: process.env.USER_NAME,
659
+ password: process.env.PASSWORD
660
+ },
661
+ commands: ["echo Host_1"],
662
+ connectedMessage: "Connected to host1",
663
+ debug: debug,
664
+ verbose: verbose
665
+ },
666
+
667
+ host2 = {
668
+ server: {
669
+ host: process.env.SERVER2_HOST,
670
+ port: process.env.PORT,
671
+ userName: process.env.SERVER2_USER_NAME,
672
+ password: process.env.SERVER2_PASSWORD
673
+ },
674
+ commands: ["echo Host_2"],
675
+ connectedMessage: "Connected to host2",
676
+ debug: debug,
677
+ verbose: verbose
678
+ },
679
+
680
+ host3 = {
681
+ server: {
682
+ host: process.env.SERVER3_HOST,
683
+ port: process.env.PORT,
684
+ userName: process.env.SERVER3_USER_NAME,
685
+ password: process.env.SERVER3_PASSWORD
686
+ },
687
+ commands: ["echo Host_3"],
688
+ connectedMessage: "Connected to host3",
689
+ debug: debug,
690
+ verbose: verbose,
691
+ //Event handler only used by this host
692
+ onCommandComplete: function( command, response, sshObj ) {
693
+ this.emit("msg", sshObj.server.host + ": commandComplete only used on this host");
694
+ }
695
+ }
696
+
697
+ var SSH2Shell = require ('ssh2shell'),
698
+ SSH = new SSH2Shell([host1,host2,host3]),
699
+ callback = function( sessionText ){
700
+ console.log ( "-----Callback session text:\n" + sessionText);
701
+ console.log ( "-----Callback end" );
702
+ }
703
+
704
+ SSH.on ('end', function( sessionText, sshObj ) {
705
+ this.emit("msg", sshObj.server.host + ": onEnd every host");
706
+ })
707
+
708
+ SSH.connect(callback);
709
+ ```
710
+
711
+
614
712
  Tunnelling nested host objects:
615
713
  ---------------------------------
616
714
  `hosts: [ host1, host2]` setting can make multiple host connections possible.
package/first.log ADDED
@@ -0,0 +1,30 @@
1
+ Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-191-generic x86_64)
2
+
3
+ * Documentation: https://help.ubuntu.com
4
+ * Management: https://landscape.canonical.com
5
+ * Support: https://ubuntu.com/advantage
6
+
7
+ System information as of Wed Aug 17 20:13:26 NZST 2022
8
+
9
+ System load: 0.29 Processes: 100
10
+ Usage of /: 63.3% of 6.28GB Users logged in: 0
11
+ Memory usage: 5% IP address for enp0s3: 192.168.0.117
12
+ Swap usage: 0%
13
+
14
+ * Super-optimized for small spaces - read how we shrank the memory
15
+ footprint of MicroK8s to make it the smallest full K8s around.
16
+
17
+ https://ubuntu.com/blog/microk8s-memory-optimisation
18
+
19
+ 130 packages can be updated.
20
+ 3 updates are security updates.
21
+
22
+ New release '20.04.4 LTS' available.
23
+ Run 'do-release-upgrade' to upgrade to it.
24
+
25
+
26
+ banner content
27
+ Last login: Wed Aug 17 20:13:10 2022 from 192.168.0.6
28
+ user@ubuntu:~$ echo host pipe
29
+ host pipe
30
+ user@ubuntu:~$
package/lib/ssh2shell.js CHANGED
@@ -420,7 +420,7 @@
420
420
  if (this.sshObj.debug) {
421
421
  this.emit('msg', this.sshObj.server.host + ": Remove previous event handlers");
422
422
  }
423
- this._removeEvents();
423
+ this._removeListeners();
424
424
  this._connections.push(this.sshObj);
425
425
  this.sshObj = nextHost;
426
426
  return this._initiate(this._sshConnect);
@@ -435,7 +435,8 @@
435
435
  if (this.sshObj.debug) {
436
436
  this.emit('msg', this.sshObj.server.host + ": Remove previous event handlers");
437
437
  }
438
- this._removeEvents();
438
+ this.emit('end', this._primaryhostSessionText, this.sshObj);
439
+ this._removeListeners();
439
440
  }
440
441
  this.sshObj = this._hosts.shift();
441
442
  this._primaryhostSessionText = this.sshObj.server.host + ": ";
@@ -553,7 +554,7 @@
553
554
  return this._stream.close();
554
555
  };
555
556
 
556
- SSH2Shell.prototype._removeEvents = function() {
557
+ SSH2Shell.prototype._removeListeners = function() {
557
558
 
558
559
  /*
559
560
  if @sshObj.debug
@@ -568,19 +569,36 @@
568
569
  @.emit 'msg', "commandTimeout: " + (@.listenerCount 'commandTimeout')
569
570
  @.emit 'msg', "msg: " + (@.listenerCount 'msg')
570
571
  */
572
+ if (typeof this.sshObj.onKeyboardInteractive === 'function') {
573
+ this.removeListener("keyboard-interactive", this.sshObj.onKeyboardInteractive);
574
+ }
575
+ if (typeof this.sshObj.onStderrData === 'function') {
576
+ this.removeListener("stderrData", this.sshObj.onStderrData);
577
+ }
571
578
  if (typeof this.sshObj.onData === 'function') {
572
579
  this.removeListener("data", this.sshObj.onData);
573
580
  }
574
- this.removeAllListeners("error");
581
+ if (typeof this.sshObj.onError === 'function') {
582
+ this.removeListener("error", this.sshObj.onError);
583
+ }
575
584
  if (typeof this.sshObj.onStderrData === 'function') {
576
585
  this.removeListener("stderrData", this.sshObj.onStderrData);
577
586
  }
578
- this.removeAllListeners('end');
579
- this.removeAllListeners('keyboard-interactive');
580
- this.removeAllListeners('commandProcessing');
581
- this.removeAllListeners('commandComplete');
582
- this.removeAllListeners('commandTimeout');
583
- this.removeAllListeners('msg');
587
+ if (typeof this.sshObj.onEnd === 'function') {
588
+ this.removeListener("end", this.sshObj.onEnd);
589
+ }
590
+ if (typeof this.sshObj.onCommandProcessing === 'function') {
591
+ this.removeListener("commandProcessing", this.sshObj.onCommandProcessing);
592
+ }
593
+ if (typeof this.sshObj.onCommandComplete === 'function') {
594
+ this.removeListener("commandComplete", this.sshObj.onCommandComplete);
595
+ }
596
+ if (typeof this.sshObj.onCommandTimeout === 'function') {
597
+ this.removeListener("commandTimeout", this.sshObj.onCommandTimeout);
598
+ }
599
+ if (typeof this.sshObj.msg === 'function') {
600
+ this.removeListener("msg", this.sshObj.msg);
601
+ }
584
602
  if (this.idleTimer) {
585
603
  clearTimeout(this.idleTimer);
586
604
  }
@@ -594,7 +612,7 @@
594
612
  this.connect = bind(this.connect, this);
595
613
  this._loadDefaults = bind(this._loadDefaults, this);
596
614
  this._initiate = bind(this._initiate, this);
597
- this._removeEvents = bind(this._removeEvents, this);
615
+ this._removeListeners = bind(this._removeListeners, this);
598
616
  this.close = bind(this.close, this);
599
617
  this._runExit = bind(this._runExit, this);
600
618
  this._sshConnect = bind(this._sshConnect, this);
@@ -623,6 +641,11 @@
623
641
  this._hosts = [hosts];
624
642
  }
625
643
  this.ssh2Client = require('ssh2').Client;
644
+ this.on("msg", (function(_this) {
645
+ return function(message) {
646
+ return console.log(message);
647
+ };
648
+ })(this));
626
649
  this.on("newPrimmaryHost", this._nextPrimaryHost);
627
650
  this.on("data", (function(_this) {
628
651
  return function(data) {
@@ -684,8 +707,12 @@
684
707
  SSH2Shell.prototype._loadDefaults = function() {
685
708
  var ref, ref1, ref2, ref3, ref4, ref5, ref6;
686
709
  if (this.sshObj.msg && this.sshObj.msg.send && typeof this.sshObj.msg.send === 'function') {
687
- this.on("msg", this.sshObj.msg.send);
688
- } else if (this.sshObj.msg && typeof this.sshObj.msg === 'function') {
710
+ this.sshObj.msg = this.sshObj.msg.send;
711
+ }
712
+ if (this.listenerCount("msg") > 0) {
713
+ this.removeAllListeners("msg");
714
+ }
715
+ if (typeof this.sshObj.msg === 'function') {
689
716
  this.on("msg", this.sshObj.msg);
690
717
  } else {
691
718
  this.on("msg", (function(_this) {
@@ -831,7 +858,7 @@
831
858
  if (typeof this.sshObj.onEnd === 'function') {
832
859
  this.on("end", this.sshObj.onEnd);
833
860
  }
834
- if (this.sshObj.verbose) {
861
+ if (this.sshObj.debug) {
835
862
  this.emit('msg', this.sshObj.server.host + ": Host loaded");
836
863
  }
837
864
  if (this.sshObj.verbose) {
@@ -913,9 +940,8 @@
913
940
  _this._primaryhostSessionText += _this.sshObj.sessionText + "\n";
914
941
  _this._allSessions += _this._primaryhostSessionText;
915
942
  if (_this._hosts.length === 0) {
916
- _this.emit('end', _this._allSessions, _this.sshObj);
943
+ return _this.emit('end', _this._allSessions, _this.sshObj);
917
944
  }
918
- return _this._removeEvents();
919
945
  });
920
946
  return _this._stream.on("close", function(code, signal) {
921
947
  if (_this.sshObj.debug) {
@@ -952,7 +978,8 @@
952
978
  }
953
979
  if (_this._hosts.length === 0) {
954
980
  if (typeof _this._callback === 'function') {
955
- return _this._callback(_this._allSessions);
981
+ _this._callback(_this._allSessions);
982
+ return _this._removeListeners();
956
983
  }
957
984
  } else {
958
985
  return _this.emit("newPrimaryHost", _this._nextPrimaryHost(_this._connect));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh2shell",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "author": "cmp-202",
5
5
  "description": "A wrapper class for ssh2 to run multiple sequential commands in an SSH shell session, handle command responses, and tunnel through to other hosts using nested host objects",
6
6
  "main": "./lib/ssh2shell.js",
package/second.log ADDED
@@ -0,0 +1,30 @@
1
+ Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-191-generic x86_64)
2
+
3
+ * Documentation: https://help.ubuntu.com
4
+ * Management: https://landscape.canonical.com
5
+ * Support: https://ubuntu.com/advantage
6
+
7
+ System information as of Wed Aug 17 20:13:26 NZST 2022
8
+
9
+ System load: 0.29 Processes: 100
10
+ Usage of /: 63.3% of 6.28GB Users logged in: 0
11
+ Memory usage: 5% IP address for enp0s3: 192.168.0.117
12
+ Swap usage: 0%
13
+
14
+ * Super-optimized for small spaces - read how we shrank the memory
15
+ footprint of MicroK8s to make it the smallest full K8s around.
16
+
17
+ https://ubuntu.com/blog/microk8s-memory-optimisation
18
+
19
+ 130 packages can be updated.
20
+ 3 updates are security updates.
21
+
22
+ New release '20.04.4 LTS' available.
23
+ Run 'do-release-upgrade' to upgrade to it.
24
+
25
+
26
+ banner content
27
+ Last login: Wed Aug 17 20:13:10 2022 from 192.168.0.6
28
+ user@ubuntu:~$ echo host pipe
29
+ host pipe
30
+ user@ubuntu:~$
@@ -284,7 +284,7 @@ class SSH2Shell extends Stream
284
284
  @.emit 'msg', "#{@sshObj.server.host}: SSH to #{nextHost.server.host}" if @sshObj.debug
285
285
  @.emit 'msg', "#{@sshObj.server.host}: Clearing previous event handlers" if @sshObj.debug
286
286
  @.emit 'msg', "#{@sshObj.server.host}: Remove previous event handlers" if @sshObj.debug
287
- @_removeEvents()
287
+ @_removeListeners()
288
288
 
289
289
  @_connections.push(@sshObj)
290
290
 
@@ -294,16 +294,17 @@ class SSH2Shell extends Stream
294
294
 
295
295
 
296
296
  _nextPrimaryHost: ( connect )=>
297
-
298
297
  if @_hosts.length > 0
299
- if @sshObj.server
298
+ #check this is not loading the first primary host before removing listeners
299
+ if @sshObj.server
300
300
  @.emit 'msg', "#{@sshObj.server.host}: Current primary host" if @sshObj.debug
301
301
  @.emit 'msg', "#{@sshObj.server.host}: Remove previous event handlers" if @sshObj.debug
302
- @_removeEvents()
303
- @sshObj = @_hosts.shift()
304
- @_primaryhostSessionText = "#{@sshObj.server.host}: "
302
+ @.emit 'end', @_primaryhostSessionText, @sshObj
303
+ @_removeListeners()
304
+ @sshObj = @_hosts.shift()
305
+ @_primaryhostSessionText = "#{@sshObj.server.host}: "
305
306
 
306
- @.emit 'msg', "#{@sshObj.server.host}: Next primary host" if @sshObj.debug
307
+ @.emit 'msg', "#{@sshObj.server.host}: Next primary host" if @sshObj.debug
307
308
 
308
309
  @_initiate(connect)
309
310
  else
@@ -369,7 +370,7 @@ class SSH2Shell extends Stream
369
370
  @.emit 'msg', "#{@sshObj.server.host}: Exit command: Stream: close" if @sshObj.debug
370
371
  @_stream.close() #"exit#{@sshObj.enter}"
371
372
 
372
- _removeEvents: =>
373
+ _removeListeners: =>
373
374
  ###
374
375
  if @sshObj.debug
375
376
  @.emit 'msg', "#{@sshObj.server.host}: Event handler count:"
@@ -383,15 +384,17 @@ class SSH2Shell extends Stream
383
384
  @.emit 'msg', "commandTimeout: " + (@.listenerCount 'commandTimeout')
384
385
  @.emit 'msg', "msg: " + (@.listenerCount 'msg')
385
386
  ###
387
+ #changed to removing host defined listeners instead of all listeners
388
+ @.removeListener "keyboard-interactive", @sshObj.onKeyboardInteractive if typeof @sshObj.onKeyboardInteractive == 'function'
389
+ @.removeListener "stderrData", @sshObj.onStderrData if typeof @sshObj.onStderrData == 'function'
386
390
  @.removeListener "data", @sshObj.onData if typeof @sshObj.onData == 'function'
387
- @.removeAllListeners "error"
391
+ @.removeListener "error", @sshObj.onError if typeof @sshObj.onError == 'function'
388
392
  @.removeListener "stderrData", @sshObj.onStderrData if typeof @sshObj.onStderrData == 'function'
389
- @.removeAllListeners 'end'
390
- @.removeAllListeners 'keyboard-interactive'
391
- @.removeAllListeners 'commandProcessing'
392
- @.removeAllListeners 'commandComplete'
393
- @.removeAllListeners 'commandTimeout'
394
- @.removeAllListeners 'msg'
393
+ @.removeListener "end", @sshObj.onEnd if typeof @sshObj.onEnd == 'function'
394
+ @.removeListener "commandProcessing", @sshObj.onCommandProcessing if typeof @sshObj.onCommandProcessing == 'function'
395
+ @.removeListener "commandComplete", @sshObj.onCommandComplete if typeof @sshObj.onCommandComplete == 'function'
396
+ @.removeListener "commandTimeout", @sshObj.onCommandTimeout if typeof @sshObj.onCommandTimeout == 'function'
397
+ @.removeListener "msg", @sshObj.msg if typeof @sshObj.msg == 'function'
395
398
 
396
399
  clearTimeout @idleTimer if @idleTimer
397
400
  clearTimeout @dataReceivedTimer if @dataReceivedTimer
@@ -402,15 +405,20 @@ class SSH2Shell extends Stream
402
405
  @_hosts = hosts
403
406
  else
404
407
  @_hosts = [hosts]
408
+
405
409
  @ssh2Client = require('ssh2').Client
406
410
 
411
+ #defined here to support msg events before the host is loaded
412
+ @.on "msg", ( message ) =>
413
+ console.log message
414
+
407
415
  @.on "newPrimmaryHost", @_nextPrimaryHost
408
416
 
409
- @.on "data", (data) =>
417
+ @.on "data", (data) =>
410
418
  @_onData( data )
411
419
 
412
420
  @.on "stderrData", (data) =>
413
- console.error data
421
+ console.error data
414
422
 
415
423
  @.on "error", (err, type, close = false, callback) =>
416
424
  @.emit 'msg', "Class.error: #{err}, #{type}" if @sshObj.debug
@@ -444,9 +452,14 @@ class SSH2Shell extends Stream
444
452
 
445
453
  _loadDefaults: () =>
446
454
 
455
+ #old hubot leftovers
447
456
  if @sshObj.msg and @sshObj.msg.send and typeof @sshObj.msg.send == 'function'
448
- @.on "msg", @sshObj.msg.send
449
- else if @sshObj.msg and typeof @sshObj.msg == 'function'
457
+ @sshObj.msg = @sshObj.msg.send
458
+
459
+ if @.listenerCount("msg") > 0
460
+ @.removeAllListeners "msg"
461
+
462
+ if typeof @sshObj.msg == 'function'
450
463
  @.on "msg", @sshObj.msg
451
464
  else
452
465
  @.on "msg", ( message ) =>
@@ -514,7 +527,7 @@ class SSH2Shell extends Stream
514
527
  @.on "commandTimeout", @sshObj.onCommandTimeout
515
528
  @.on "end", @sshObj.onEnd if typeof @sshObj.onEnd == 'function'
516
529
 
517
- @.emit 'msg', "#{@sshObj.server.host}: Host loaded" if @sshObj.verbose
530
+ @.emit 'msg', "#{@sshObj.server.host}: Host loaded" if @sshObj.debug
518
531
  @.emit 'msg', @sshObj if @sshObj.verbose
519
532
 
520
533
 
@@ -570,9 +583,7 @@ class SSH2Shell extends Stream
570
583
  @_primaryhostSessionText += @sshObj.sessionText+"\n"
571
584
  @_allSessions += @_primaryhostSessionText
572
585
  if @_hosts.length == 0
573
- @.emit 'end', @_allSessions, @sshObj
574
- @_removeEvents()
575
-
586
+ @.emit 'end', @_allSessions, @sshObj
576
587
 
577
588
  @_stream.on "close", (code, signal) =>
578
589
  @.emit 'msg', "#{@sshObj.server.host}: Stream.close" if @sshObj.debug
@@ -595,7 +606,8 @@ class SSH2Shell extends Stream
595
606
  if @_hosts.length == 0
596
607
  if typeof @_callback == 'function'
597
608
  @_callback @_allSessions
598
- else
609
+ @_removeListeners()
610
+ else
599
611
  @.emit "newPrimaryHost", @_nextPrimaryHost(@_connect)
600
612
 
601
613
 
package/test/.ignore DELETED
File without changes
@@ -1,66 +0,0 @@
1
- var dotenv = require('dotenv').config()
2
-
3
- var conParamsHost1 = {
4
- host: process.env.HOST,
5
- port: process.env.PORT,
6
- userName: process.env.USER_NAME,
7
- password: process.env.PASSWORD
8
- },
9
- conParamsHost2 = {
10
- host: process.env.SERVER2_HOST,
11
- port: process.env.PORT,
12
- userName: process.env.SERVER2_USER_NAME,
13
- password: process.env.SERVER2_PASSWORD
14
- },
15
- //set to fail
16
- conParamsHost3 = {
17
- host: process.env.SERVER3_HOST,
18
- port: process.env.PORT,
19
- userName: process.env.SERVER3_USER_NAME,
20
- password: process.env.SERVER3_PASSWORD
21
- },
22
- debug = true,
23
- verbose = false
24
-
25
- //Host objects:
26
- var host1 = {
27
- server: conParamsHost1,
28
- commands: ["echo Host_1"],
29
- connectedMessage: "Connected to host1",
30
- debug: debug,
31
- verbose: verbose
32
- },
33
-
34
- host2 = {
35
- server: conParamsHost2,
36
- commands: ["echo Host_2"],
37
- debug: debug,
38
- verbose: verbose
39
- },
40
-
41
- host3 = {
42
- server: conParamsHost3,
43
- commands: ["echo Host_3"],
44
- debug: debug,
45
- verbose: verbose
46
- }
47
-
48
-
49
- //or the alternative nested tunnelling method outlined above:
50
- //host2.hosts = [ host3 ];ssh -q george@192.168.0.129 "echo 2>&1" && echo OK || echo NOK
51
- //host1.hosts = [ host2 ];
52
-
53
- //Create the new instance
54
- //or SSH2Shell = require ('ssh2shell')
55
- var SSH2Shell = require ('../lib/ssh2shell'),
56
- SSH = new SSH2Shell([host1,host2,host3]),
57
- callback = function( sessionText ){
58
- console.log ( "-----Callback session text:\n" + sessionText);
59
- console.log ( "-----Callback end" );
60
- }
61
-
62
-
63
- //Start the process
64
- SSH.connect(callback);
65
-
66
-
package/test/devtest.js DELETED
@@ -1,51 +0,0 @@
1
- var dotenv = require('dotenv').config()
2
-
3
- var host = {
4
- server: {
5
- host: process.env.HOST,
6
- port: process.env.PORT,
7
- userName: process.env.USER_NAME,
8
- password: process.env.PASSWORD,
9
- tryKeyboard: true
10
- },
11
- commands: [
12
- "`Test session text message: passed`",
13
- "msg:console test notification: passed",
14
- "ls -la"
15
- ],
16
- msg: {
17
- send: function( message ) {
18
- console.log(message);
19
- }
20
- },
21
- verbose: true,
22
- debug: true,
23
- onKeyboardInteractive: function(name, instructions, instructionsLang, prompts, finish){
24
- console.log("host Event");
25
- console.log(name);
26
- console.log(instructions);
27
- console.log(prompts);
28
- var str = JSON.stringify(prompts, null, 4);
29
- console.log(str);
30
- finish([process.env.PASSWORD] );
31
- },
32
- commands: [ "ls -l" ]
33
- //standardPrompt: "abc",//">$%#"
34
- /*onCommandProcessing: function( command, response, sshObj, stream ){
35
- if ( response.indexOf(“Connected”) != -1 ){
36
- stream.write(“\n”);
37
- }
38
- }*/
39
-
40
- };
41
- //until npm published use the cloned dir path.
42
- var SSH2Shell = require ('../lib/ssh2shell');
43
-
44
- //run the commands in the shell session
45
- var SSH = new SSH2Shell(host);
46
-
47
- SSH.on('end', function( sessionText, sshObj ){
48
- this.emit('msg', "Session Text " + sessionText);
49
- })
50
-
51
- SSH.connect();
package/test/issue69.js DELETED
@@ -1,57 +0,0 @@
1
- var dotenv = require('dotenv').config(),
2
- debug = true,
3
- verbose = true
4
-
5
- var host1 = {
6
- server: {
7
- host: process.env.HOST,
8
- port: process.env.PORT,
9
- userName: process.env.USER_NAME,
10
- password: process.env.PASSWORD
11
- },
12
- connectedMessage:'connected to host1',
13
- debug: debug,
14
- verbose: verbose
15
-
16
- };
17
-
18
- var host2 = {
19
- server: {
20
- host: process.env.SERVER2_HOST,
21
- port: process.env.PORT,
22
- userName: process.env.SERVER2_USER_NAME,
23
- password: process.env.SERVER2_PASSWORD
24
-
25
- },
26
- connectedMessage: 'connected to host2',
27
- debug: debug,
28
- verbose: verbose
29
- };
30
-
31
- var host3 = {
32
- server: {
33
- host: process.env.SERVER3_HOST,
34
- port: process.env.PORT,
35
- userName: process.env.SERVER3_USER_NAME,
36
- password: process.env.SERVER3_PASSWORD
37
-
38
- },
39
- commands: ['echo server3'],
40
- connectedMessage:'connected to host3',
41
- debug: debug,
42
- verbose: verbose
43
- };
44
-
45
- host2.hosts = [host3];
46
- host1.hosts = [host2];
47
-
48
- var SSH2Shell = require ('../lib/ssh2shell'),
49
-
50
- SSH = new SSH2Shell(host1);
51
-
52
- var callback = function( sessionText ){
53
- console.log ( "-----Callback session text:\n" + sessionText);
54
- console.log ( "-----Callback end" );
55
- }
56
-
57
- SSH.connect(callback);
@@ -1,26 +0,0 @@
1
- var dotenv = require('dotenv').config()
2
-
3
- var host = {
4
- server: {
5
- host: process.env.HOST,
6
- port: process.env.PORT,
7
- userName: process.env.USER_NAME,
8
- password: process.env.PASSWORD,
9
- tryKeyboard: true
10
- },
11
- commands: [
12
- "ls -la"
13
- ],
14
- verbose: false,
15
- debug: false,
16
- onEnd: function( sessionText, sshObj ){
17
- this.emit("msg", sessionText);
18
- }
19
- };
20
- //until npm published use the cloned dir path.
21
- var SSH2Shell = require ('../lib/ssh2shell');
22
-
23
- //run the commands in the shell session
24
- var SSH = new SSH2Shell(host);
25
-
26
- SSH.connect();