ssh2shell 2.0.3 → 2.0.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.
@@ -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();
@@ -1,87 +0,0 @@
1
- var dotenv = require('dotenv').config(),
2
- fs = require('fs')
3
-
4
- var host = {
5
- server: {
6
- host: process.env.HOST,
7
- port: process.env.PORT,
8
- userName: process.env.USER_NAME,
9
- password: process.env.PASSWORD
10
- },
11
- commands: [
12
- "msg: first",
13
- "sudo apt-get -y update",
14
- "sudo apt-get -y update",
15
- "sudo apt-get -y update",
16
- "sudo apt-get -y update",
17
- "sudo apt-get -y update",
18
- "sudo apt-get -y update",
19
- "sudo apt-get -y update",
20
- "sudo apt-get -y update",
21
- "sudo apt-get -y update",
22
- "sudo apt-get -y update",
23
- "msg: 11",
24
- "sudo apt-get -y update",
25
- "sudo apt-get -y update",
26
- "sudo apt-get -y update",
27
- "sudo apt-get -y update",
28
- "sudo apt-get -y update",
29
- "sudo apt-get -y update",
30
- "sudo apt-get -y update",
31
- "sudo apt-get -y update",
32
- "sudo apt-get -y update",
33
- "sudo apt-get -y update",
34
- "msg: 21",
35
- "sudo apt-get -y update",
36
- "sudo apt-get -y update",
37
- "sudo apt-get -y update",
38
- "sudo apt-get -y update",
39
- "sudo apt-get -y update",
40
- "sudo apt-get -y update",
41
- "sudo apt-get -y update",
42
- "sudo apt-get -y update",
43
- "sudo apt-get -y update",
44
- "sudo apt-get -y update",
45
- "sudo apt-get -y update",
46
- "sudo apt-get -y update",
47
- "sudo apt-get -y update",
48
- "sudo apt-get -y update",
49
- "sudo apt-get -y update",
50
- "sudo apt-get -y update",
51
- "sudo apt-get -y update",
52
- "sudo apt-get -y update",
53
- "sudo apt-get -y update",
54
- "sudo apt-get -y update",
55
- "sudo apt-get -y update",
56
- "sudo apt-get -y update",
57
- "sudo apt-get -y update",
58
- "sudo apt-get -y update",
59
- "sudo apt-get -y update",
60
- "sudo apt-get -y update",
61
- "sudo apt-get -y update",
62
- "sudo apt-get -y update",
63
- "sudo apt-get -y update",
64
- "sudo apt-get -y update",
65
- "sudo apt-get -y update",
66
- "sudo apt-get -y update",
67
- "sudo apt-get -y update",
68
- "sudo apt-get -y update",
69
- "sudo apt-get -y update",
70
- "sudo apt-get -y update",
71
- "sudo apt-get -y update",
72
- "sudo apt-get -y update",
73
- "sudo apt-get -y update",
74
- "sudo apt-get -y update",
75
- "sudo apt-get -y update",
76
- "sudo apt-get -y update"
77
- ]
78
- };
79
- //until npm published use the cloned dir path.
80
- var SSH2Shell = require ('../lib/ssh2shell');
81
-
82
- //run the commands in the shell session
83
- var SSH = new SSH2Shell(host),
84
- locLog = fs.createWriteStream('Lots of commands.log')
85
-
86
- SSH.pipe( locLog );
87
- SSH.connect();
@@ -1,36 +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
- },
10
- commands: [
11
- //hubot throwback
12
- "msg: using msg.send",
13
- "`All done!`",
14
- ],
15
- msg: {
16
- send: function( message ) {
17
- console.log(message);
18
- }
19
- },
20
- verbose: false,
21
- debug: false
22
- };
23
-
24
- //until npm published use the cloned dir path.
25
- var SSH2Shell = require ('../lib/ssh2shell');
26
-
27
- //run the commands in the shell session
28
- var SSH = new SSH2Shell(host);
29
-
30
- var callback = function( sessionText ){
31
- //show the full session output. This could be emailed or saved to a log file.
32
- console.log("\nThis is the full session response: \n\n" + sessionText);
33
- }
34
-
35
- SSH.connect(callback);
36
-
package/test/pipe.js DELETED
@@ -1,30 +0,0 @@
1
- var dotenv = require('dotenv').config(),
2
- fs = require('fs')
3
-
4
- var host = {
5
- server: {
6
- host: process.env.HOST,
7
- port: process.env.PORT,
8
- userName: process.env.USER_NAME,
9
- password: process.env.PASSWORD,
10
- },
11
- commands: [
12
- "echo host pipe"
13
- ],
14
- debug: false
15
- }
16
- //until npm published use the cloned dir path.
17
- var SSH2Shell = require ('../lib/ssh2shell')
18
-
19
- //run the commands in the shell session
20
- var SSH = new SSH2Shell(host),
21
- callback = function( sessionText ){
22
- console.log ( "-----Callback session text:\n" + sessionText);
23
- console.log ( "-----Callback end" );
24
- },
25
- firstLog = fs.createWriteStream('first.log'),
26
- secondLog = fs.createWriteStream('second.log')
27
-
28
- SSH.pipe(firstLog)
29
- SSH.pipe(secondLog)
30
- SSH.connect(callback)
package/test/simple.js DELETED
@@ -1,26 +0,0 @@
1
- var dotenv = require('dotenv').config(),
2
- debug = false,
3
- verbose = false
4
-
5
- var host = {
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
- commands: ["echo basic test success"],
13
- debug: debug,
14
- verbose: verbose
15
- };
16
-
17
- var SSH2Shell = require ('../lib/ssh2shell');
18
-
19
- //run the commands in the shell session
20
- var SSH = new SSH2Shell(host),
21
- callback = function( sessionText ){
22
- console.log ( "-----Callback session text:\n" + sessionText);
23
- console.log ( "-----Callback end" );
24
- }
25
-
26
- SSH.connect(callback)
@@ -1,26 +0,0 @@
1
- var dotenv = require('dotenv').config()
2
-
3
- var sshObj = {
4
- server: {
5
- host: process.env.HOST,
6
- port: process.env.PORT,
7
- userName: process.env.USER_NAME,
8
- password: process.env.PASSWORD,
9
- },
10
- commands: [
11
- "echo ssh",
12
- "ssh -V",
13
- "echo ssh middle"
14
- ],
15
- verbose: false,
16
- debug: false
17
- };
18
- //until npm published use the cloned dir path.
19
- var SSH2Shell = require ('../lib/ssh2shell');
20
-
21
- //run the commands in the shell session
22
- var SSH = new SSH2Shell(sshObj);
23
- SSH.on('end', function( sessionText, sshObj ){
24
- this.emit('msg', sessionText);
25
- })
26
- SSH.connect();
@@ -1,40 +0,0 @@
1
- var dotenv = require('dotenv').config();
2
-
3
- /*
4
- * Used `sudo visudo` to add `[username] ALL=(ALL) NOPASSWD: ALL` on the first test
5
- * server to test no password required detecting normal prompt correctly to run the
6
- * next command
7
- */
8
- var sshObj = {
9
- server: {
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
- commands: ["sudo apt-get update","sudo apt-get upgrade", "sudo apt autoremove"],
16
- userPromptSent: false,
17
- debug: true,
18
- verbose: true,
19
- onCommandProcessing: function( command, response, sshObj, stream ) {
20
- //Check the command and prompt exits and respond with a 'y' but only does it once
21
- if (response.indexOf("[Y/n]") != -1 && !sshObj.userPromptSent) {
22
- sshObj.userPromptSent = true
23
- stream.write("n\n")
24
- }
25
- },
26
- onCommandComplete: function( command, response, sshObj ) {
27
- if(sshObj.userPromptSent){
28
- sshObj.userPromptSent = false;
29
- }
30
- }
31
- }
32
- //until npm published use the cloned dir path.
33
- var SSH2Shell = require ('../lib/ssh2shell');
34
-
35
- //run the commands in the shell session
36
- var SSH = new SSH2Shell(sshObj);
37
- var callback = function(sessionText, sshObj) {
38
- console.log(`Session End: ` + sessionText);
39
- }
40
- SSH.connect(callback);
@@ -1,77 +0,0 @@
1
- var dotenv = require('dotenv').config();
2
-
3
- /*
4
- * Used `sudo visudo` to add `[username] ALL=(ALL) NOPASSWD: ALL` on the first test
5
- * server to test no password required detecting normal prompt correctly to run the
6
- * next command
7
- */
8
- var sshObj = {
9
- server: {
10
- host: process.env.HOST,
11
- port: process.env.PORT,
12
- userName: process.env.USER_NAME,
13
- password: process.env.PASSWORD
14
- },
15
- commands: [
16
- "msg:Showing current directory",
17
- "echo \$(pwd)",
18
- "ls -al",
19
- "sudo -i",
20
- "msg:Showing root home directory",
21
- "cd \~",
22
- "echo \$(pwd)",
23
- "ls -al",
24
- "msg:exiting root",
25
- "exit",
26
- "msg:Changing to " + process.env.secondaryUser + " via su [username]",
27
- "su " + process.env.secondaryUser,
28
- "msg:Showing user home directory",
29
- "cd \~",
30
- "echo \$(pwd)",
31
- "ls -al",
32
- "msg:exiting user ",
33
- "exit",
34
- "msg:Changing user via sudo -u [username] -i",
35
- "sudo -u " + process.env.USER_NAME + " -i",
36
- "msg:Showing user directory",
37
- "cd \~",
38
- "echo \$(pwd)",
39
- "ls -la"
40
- ],
41
- msg: {
42
- send: function( message ) {
43
- console.log(message);
44
- }
45
- },
46
- debug: false,
47
- verbose: false,
48
- suPassSent: false, //used by commandProcessing to only send password once
49
- rootPassSent: false,
50
- onCommandProcessing: function( command, response, sshObj, stream ) {
51
- //console.log("command processing:\ncommand: " + command + ", response: " + response + ", password sent: " + sshObj.rootPassSent + ", password: " + process.env.rootPassword);
52
-
53
- if (command === "su " + process.env.secondaryUser && response.indexOf("Password: ") != -1 && sshObj.suPassSent != true) {
54
- sshObj.commands.unshift("msg:Using secondary user password");
55
- //this is required to stop "bounce" without this the password would be sent multiple times
56
- sshObj.suPassSent = true;
57
- stream.write(process.env.secondUserPassword + "\n");
58
- }/* else if (command == "sudo -i" && response.match(/:\s$/i) && sshObj.rootPassSent != true) {
59
- sshObj.commands.unshift("msg:Using root user password");
60
- //this is required to stop "bounce" without this the password would be sent multiple times
61
- sshObj.rootPassSent = true;
62
- stream.write(process.env.PASSWORD + "\n");
63
- }*/
64
- },
65
- onEnd: function ( sessionText, sshObj ) {
66
- if(this.sshObj.debug){this.emit("msg", sshObj.server.host + ": host.onEnd")};
67
- //show the full session output. This could be emailed or saved to a log file.
68
- this.emit("msg", "\nThis is the full session responses:\n" + sessionText);
69
- }
70
- };
71
- //until npm published use the cloned dir path.
72
- var SSH2Shell = require ('../lib/ssh2shell');
73
-
74
- //run the commands in the shell session
75
- var SSH = new SSH2Shell(sshObj);
76
-
77
- SSH.connect();
@@ -1,97 +0,0 @@
1
- //Every data response from the server resets the command timeout timer
2
- //So if you use stream.write() to send something to the server from within the timeout function
3
- //and the server responds then the timer is reset and the normal process starts again
4
- //If you are using the host.onCommandTimeout to send something to the host and it doesn't
5
- //respond then the script will hang. there is no way to reset the timeout timer.
6
- //If you set the host onCommandTimeout to do nothing an attach commandTimeout to the instance
7
- //you will be able to tigger a new timeout timer by using
8
- /*
9
- self.sshObj.idleTimer = setTimeout(function(){
10
- self.emit('commandTimeout', command, response, stream, connection )
11
- }, self._idleTime)
12
- */
13
- //commandTimeout is actually a `didn't detect a defined prompt` timeout
14
-
15
- var dotenv = require('dotenv').config(),
16
- debug=false,
17
- verbose=false
18
-
19
- var conParamsHost2 = {
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
- //Host objects:
27
- var host1 = {
28
- server: conParamsHost2,
29
- commands: [ "echo host" ],
30
- connectedMessage: "Connected to host",
31
- debug: true,
32
- verbose: verbose
33
- },
34
- host = {
35
- server: {
36
- host: process.env.HOST,
37
- port: process.env.PORT,
38
- userName: process.env.USER_NAME,
39
- password: process.env.PASSWORD
40
- },
41
- commands: [
42
- "msg:Testing idle time out",
43
- "read -n 1 -p \"First prompt to put valid input (Y,n): \" test",
44
- "read -n 1 -p \"Final unhandled time out: \" test",
45
- ],
46
- //can't use # and > because prompt detection triggers in the wrong place
47
- standardPrompt: "$",
48
- verbose: verbose,
49
- debug: debug,
50
- idleTimeOut: 1000,
51
- FirstPass: false,
52
- SecondPass: false,
53
- onCommandTimeout: function( command, response, stream, connection ){
54
- //this.emit("msg", "response: [[" + response + " ]]")
55
- if(this.sshObj.debug){this.emit("msg", this.sshObj.server.host + ": host.onCommandTimeout")}
56
-
57
- var errorMessage, errorSource
58
- //this.emit("msg", this.sshObj.server.host + ": fp:" +this.sshObj.FirstPass)
59
-
60
- if (response.indexOf("(Y,n)") != -1 && this.sshObj.FirstPass != true){
61
- if(this.sshObj.debug){this.emit("msg", this.sshObj.server.host + ": First prompt using correct input: Sending 'y' to the `(y,n):` prompt")}
62
- this.sshObj.sessionText += response + this.sshObj.enter
63
- this._buffer = ""
64
- this.sshObj.FirstPass = true
65
-
66
- stream.write("y" + this.sshObj.enter)
67
- return
68
-
69
- }
70
-
71
- if(this.sshObj.debug){this.emit("msg", this.sshObj.server.host + "Final timeout: All attempts completed")}
72
- if(this.sshObj.debug){this.emit("msg", this.sshObj.server.host + ": Timeout details:" + this.sshObj.enter + "Command: " + command + " " + this.sshObj.enter + "Response: " + response)}
73
-
74
- //everything failed so update sessionText and raise an error event that closes the connection
75
- if(!errorMessage){errorMessage = "Command"}
76
- if(!errorSource){errorSource = "Command Timeout"}
77
- //this.emit("msg", this.sshObj.server.host + ": " + errorMessage + " timed out after " + (this.idleTime / 1000) + " seconds", errorSource, true)
78
- //this.emit("end", response, this.sshObj)
79
- this.sshObj.sessionText += response + this.sshObj.enter
80
- this.close()
81
- },
82
-
83
- onEnd: function( sessionText, sshObj ) {
84
- if(this.sshObj.debug){this.emit("msg", sshObj.server.host + ": host.onEnd")}
85
- //show the full session output. self could be emailed or saved to a log file.
86
- this.emit("msg", "\nThis is the full session response:\n\n" + this.sshObj.sessionText + "\n")
87
- //this.close()
88
- }
89
- }
90
- //host1.hosts=[host]
91
- //until npm published use the cloned dir path.
92
- var SSH2Shell = require ('../lib/ssh2shell')
93
-
94
- //run the commands in the shell session
95
- var SSH = new SSH2Shell(host)
96
-
97
- SSH.connect()