ssh2shell 1.9.6 → 1.9.9

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/lib/ssh2shell.js CHANGED
@@ -133,66 +133,74 @@
133
133
  response = this._sanitizeResponse().trim();
134
134
  passwordPrompt = this.passwordPrompt.test(response);
135
135
  standardPrompt = this.standardPrompt.test(response);
136
- if (this.sshObj.verbose) {
137
- this.emit('msg', this.sshObj.server.host + ": Password previously sent: " + this.sshObj.pwSent);
138
- }
139
136
  if (this.sshObj.debug) {
140
- this.emit('msg', this.sshObj.server.host + ": Password prompt: Password previously sent: " + this.sshObj.pwSent);
137
+ this.emit('msg', this.sshObj.server.host + ": Sudo Password prompt detected: " + passwordPrompt);
141
138
  }
142
- if (this.sshObj.verbose) {
143
- this.emit('msg', this.sshObj.server.host + ": Response: " + response);
139
+ if (this.sshObj.debug) {
140
+ this.emit('msg', this.sshObj.server.host + ": Sudo Password prompt: Password sent: " + this.sshObj.pwSent);
144
141
  }
145
- if (this.sshObj.verbose) {
146
- this.emit('msg', this.sshObj.server.host + ": Sudo Password Prompt: " + passwordPrompt);
142
+ if (this.sshObj.debug) {
143
+ this.emit('msg', this.sshObj.server.host + ": Sudo Password: " + this.sshObj.server.password);
147
144
  }
148
145
  if (this.sshObj.verbose) {
149
- this.emit('msg', this.sshObj.server.host + ": Sudo Password: " + this.sshObj.server.password);
146
+ this.emit('msg', this.sshObj.server.host + ": Sudo Response: " + response);
150
147
  }
151
- if (standardPrompt) {
152
- if (this.sshObj.debug) {
153
- this.emit('msg', this.sshObj.server.host + ": Password prompt: Standard prompt detected");
154
- }
155
- this._commandComplete();
156
- return this.sshObj.pwSent = true;
157
- } else if (!this.sshObj.pwSent) {
158
- if (passwordPrompt) {
148
+ switch (true) {
149
+ case passwordPrompt && !this.sshObj.server.password:
150
+ if (this.sshObj.debug) {
151
+ this.emit('msg', this.sshObj.server.host + ": Sudo password prompt no password");
152
+ }
153
+ return this._resetFromSudoError();
154
+ case passwordPrompt && !this.sshObj.pwSent:
159
155
  if (this.sshObj.verbose) {
160
- this.emit('msg', this.sshObj.server.host + ": Password prompt: Buffer: " + response);
156
+ this.emit('msg', this.sshObj.server.host + ": Sudo password prompt: Buffer: " + response);
161
157
  }
162
158
  if (this.sshObj.debug) {
163
- this.emit('msg', this.sshObj.server.host + ": Password prompt: Send password ");
159
+ this.emit('msg', this.sshObj.server.host + ": Sudo password prompt: Send password ");
164
160
  }
165
161
  if (this.sshObj.verbose) {
166
- this.emit('msg', this.sshObj.server.host + ": Sent password: " + this.sshObj.server.password);
162
+ this.emit('msg', this.sshObj.server.host + ": Sudo sent password: " + this.sshObj.server.password);
167
163
  }
168
164
  this.sshObj.pwSent = true;
169
165
  return this._runCommand("" + this.sshObj.server.password);
170
- } else {
166
+ case passwordPrompt && this.sshObj.pwSent:
167
+ if (this.sshObj.verbose) {
168
+ this.emit('msg', this.sshObj.server.host + ": Sudo password faied: response: " + response);
169
+ }
170
+ if (this.sshObj.debug) {
171
+ this.emit('error', this.sshObj.server.host + ": Sudo password was incorrect for " + this.sshObj.server.userName + ", Sudo authentication");
172
+ }
171
173
  if (this.sshObj.debug) {
172
- this.emit('msg', this.sshObj.server.host + ": Password prompt: not detected");
174
+ this.emit('msg', this.sshObj.server.host + ": Sudo failed password prompt: Password: [" + this.sshObj.server.password + "]");
173
175
  }
176
+ this.sshObj.pwSent = false;
177
+ return this._resetFromSudoError();
178
+ case standardPrompt:
179
+ if (this.sshObj.debug) {
180
+ this.emit('msg', this.sshObj.server.host + ": Sudo prompt: Standard prompt detected");
181
+ }
182
+ this.sshObj.pwSent = false;
174
183
  if (this.sshObj.verbose) {
175
- this.emit('msg', this.sshObj.server.host + ": Password prompt " + this.sshObj.passwordPrompt);
184
+ this.emit('msg', this.sshObj.server.host + ": Sudo Standard Response: " + response);
176
185
  }
177
- return this._runExit();
178
- }
179
- } else if (passwordPrompt) {
180
- if (this.sshObj.verbose) {
181
- this.emit('msg', this.sshObj.server.host + ": Sudo password faied: response: " + response);
182
- }
183
- if (this.sshObj.debug) {
184
- this.emit('error', this.sshObj.server.host + ": Sudo password was incorrect for " + this.sshObj.server.userName, "Sudo authentication");
185
- }
186
- if (this.sshObj.debug) {
187
- this.emit('msg', this.sshObj.server.host + ": Failed password prompt: Password: [" + this.sshObj.server.password + "]");
188
- }
189
- this.sshObj.sessionText += "" + this._buffer;
190
- this._buffer = "";
191
- this.command = "";
192
- return this._stream.write('\x03');
186
+ return this._commandComplete();
187
+ default:
188
+ return this.idleTimer = setTimeout((function(_this) {
189
+ return function() {
190
+ return _this.emit('commandTimeout', _this.command, response, _this._stream, _this._connection);
191
+ };
192
+ })(this), this.idleTime);
193
193
  }
194
194
  };
195
195
 
196
+ SSH2Shell.prototype._resetFromSudoError = function() {
197
+ this.sshObj.pwSent = false;
198
+ this.sshObj.sessionText += "" + this._buffer;
199
+ this._buffer = "";
200
+ this.command = "";
201
+ return this._stream.write('\x03');
202
+ };
203
+
196
204
  SSH2Shell.prototype._processSSHPrompt = function() {
197
205
  var passphrasePrompt, passwordPrompt, response, standardPrompt, using;
198
206
  response = this._sanitizeResponse().trim();
@@ -225,22 +233,22 @@
225
233
  return this._runCommand("" + this.sshObj.server.passPhrase);
226
234
  } else if (standardPrompt) {
227
235
  if (this.sshObj.debug) {
228
- this.emit('msg', this.sshObj.server.host + ": SSH: standard prompt: connection failed");
236
+ this.emit('msg', this.sshObj.server.host + ": SSH standard prompt: connection failed");
229
237
  }
230
238
  this.emit('msg', this.sshObj.server.host + ": SSH connection failed");
231
239
  this.emit('msg', this.sshObj.server.host + ": SSH failed response: " + response);
232
240
  this.sshObj.sessionText += this.sshObj.server.host + ": SSH failed: response: " + response;
233
241
  return this._runExit();
234
242
  } else {
235
- this.emit('msg', this.sshObj.server.host + ": SSH: no prompt was not detected");
243
+ this.emit('msg', this.sshObj.server.host + ": SSH no prompt was not detected");
236
244
  if (this.sshObj.verbose && !this.sshObj.server.hasOwnProperty("passPhrase")) {
237
- this.emit('msg', this.sshObj.server.host + ": Password prompt " + this.sshObj.passwordPrompt);
245
+ this.emit('msg', this.sshObj.server.host + ": SSH password prompt " + this.sshObj.passwordPrompt);
238
246
  }
239
247
  if (this.sshObj.verbose && this.sshObj.server.hasOwnProperty("passPhrase")) {
240
- this.emit('msg', this.sshObj.server.host + ": Passphrase prompt " + this.sshObj.passphrasePrompt);
248
+ this.emit('msg', this.sshObj.server.host + ": SSH passphrase prompt " + this.sshObj.passphrasePrompt);
241
249
  }
242
250
  if (this.sshObj.verbose) {
243
- this.emit('msg', this.sshObj.server.host + ": Standard prompt " + this.sshObj.standardPrompt);
251
+ this.emit('msg', this.sshObj.server.host + ": SSH standard prompt " + this.sshObj.standardPrompt);
244
252
  }
245
253
  return this._runExit();
246
254
  }
@@ -268,9 +276,9 @@
268
276
  using = (function() {
269
277
  switch (false) {
270
278
  case !passwordPrompt:
271
- return "password: " + this.sshObj.server.password;
279
+ return "SSH password: " + this.sshObj.server.password;
272
280
  case !passphrasePrompt:
273
- return "passphrase: " + this.sshObj.server.passPhrase;
281
+ return "SSH passphrase: " + this.sshObj.server.passPhrase;
274
282
  }
275
283
  }).call(this);
276
284
  this.emit('error', this.sshObj.server.host + ": SSH authentication failed for " + this.sshObj.server.userName + "@" + this.sshObj.server.host, "Nested host authentication");
@@ -570,6 +578,7 @@
570
578
  this._commandComplete = bind(this._commandComplete, this);
571
579
  this._processNotifications = bind(this._processNotifications, this);
572
580
  this._processSSHPrompt = bind(this._processSSHPrompt, this);
581
+ this._resetFromSudoError = bind(this._resetFromSudoError, this);
573
582
  this._processPasswordPrompt = bind(this._processPasswordPrompt, this);
574
583
  this._sanitizeResponse = bind(this._sanitizeResponse, this);
575
584
  this._onData = bind(this._onData, this);
@@ -583,7 +592,7 @@
583
592
  } else {
584
593
  this.hosts = [hosts];
585
594
  }
586
- this.ssh2Client = require('ssh2');
595
+ this.ssh2Client = require('ssh2').Client;
587
596
  this.on("newPrimmaryHost", this._nextPrimaryHost);
588
597
  this.on("data", (function(_this) {
589
598
  return function(data) {
@@ -927,34 +936,16 @@
927
936
  })(this));
928
937
  if (this.sshObj.server && this.sshObj.commands) {
929
938
  try {
930
- this.connection.connect({
931
- host: this.sshObj.server.host,
932
- port: this.sshObj.server.port,
933
- forceIPv4: this.sshObj.server.forceIPv4,
934
- forceIPv6: this.sshObj.server.forceIPv6,
935
- hostHash: this.sshObj.server.hashMethod,
936
- hostVerifier: this.sshObj.server.hostVerifier,
937
- username: this.sshObj.server.userName,
938
- password: this.sshObj.server.password,
939
- agent: this.sshObj.server.agent,
940
- agentForward: this.sshObj.server.agentForward,
941
- privateKey: this.sshObj.server.privateKey,
942
- passphrase: this.sshObj.server.passPhrase,
943
- localHostname: this.sshObj.server.localHostname,
944
- localUsername: this.sshObj.server.localUsername,
945
- localAddress: this.sshObj.server.localAddress,
946
- localPort: this.sshObj.server.localPort,
947
- authHandler: this.sshObj.server.authHandler,
948
- tryKeyboard: this.sshObj.server.tryKeyboard,
949
- keepaliveInterval: this.sshObj.server.keepaliveInterval,
950
- keepaliveCountMax: this.sshObj.server.keepaliveCountMax,
951
- readyTimeout: this.sshObj.server.readyTimeout,
952
- sock: this.sshObj.server.sock,
953
- strictVendor: this.sshObj.server.strictVendor,
954
- algorithms: this.sshObj.server.algorithms,
955
- compress: this.sshObj.server.compress,
956
- debug: this.sshObj.server.debug
957
- });
939
+ if (!this.sshObj.server.username) {
940
+ this.sshObj.server.username = this.sshObj.server.userName;
941
+ }
942
+ if (!this.sshObj.server.hostHash) {
943
+ this.sshObj.server.hostHash = this.sshObj.server.hashMethod;
944
+ }
945
+ if (!this.sshObj.server.passphrase) {
946
+ this.sshObj.server.passphrase = this.sshObj.server.passPhrase;
947
+ }
948
+ this.connection.connect(this.sshObj.server);
958
949
  } catch (error) {
959
950
  e = error;
960
951
  this.emit('error', e + " " + e.stack, "Connection.connect", true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh2shell",
3
- "version": "1.9.6",
3
+ "version": "1.9.9",
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",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "devDependencies": {
14
14
  "coffee-script": "^1.12.7",
15
- "dotenv": "^8.2.0"
15
+ "dotenv": "^8.6.0"
16
16
  },
17
17
  "scripts": {},
18
18
  "keywords": [
@@ -88,45 +88,51 @@ class SSH2Shell extends Stream
88
88
  return @_buffer.replace(@command.substr(0, @_buffer.length), "")
89
89
 
90
90
  _processPasswordPrompt: =>
91
- #First test for password prompt
91
+ #First test for password prompt
92
92
  response = @_sanitizeResponse().trim()
93
93
  passwordPrompt = @passwordPrompt.test(response)
94
94
  standardPrompt = @standardPrompt.test(response)
95
- @.emit 'msg', "#{@sshObj.server.host}: Password previously sent: #{@sshObj.pwSent}" if @sshObj.verbose
96
- @.emit 'msg', "#{@sshObj.server.host}: Password prompt: Password previously sent: #{@sshObj.pwSent}" if @sshObj.debug
97
- @.emit 'msg', "#{@sshObj.server.host}: Response: #{response}" if @sshObj.verbose
98
- @.emit 'msg', "#{@sshObj.server.host}: Sudo Password Prompt: #{passwordPrompt}" if @sshObj.verbose
99
- @.emit 'msg', "#{@sshObj.server.host}: Sudo Password: #{@sshObj.server.password}" if @sshObj.verbose
100
- #normal prompt so continue with next command
101
- if standardPrompt
102
- @.emit 'msg', "#{@sshObj.server.host}: Password prompt: Standard prompt detected" if @sshObj.debug
103
- @_commandComplete()
104
- @sshObj.pwSent = true
105
- #Password prompt detection
106
- else unless @sshObj.pwSent
107
- if passwordPrompt
108
- @.emit 'msg', "#{@sshObj.server.host}: Password prompt: Buffer: #{response}" if @sshObj.verbose
109
- @.emit 'msg', "#{@sshObj.server.host}: Password prompt: Send password " if @sshObj.debug
110
- @.emit 'msg', "#{@sshObj.server.host}: Sent password: #{@sshObj.server.password}" if @sshObj.verbose
95
+ @.emit 'msg', "#{@sshObj.server.host}: Sudo Password prompt detected: #{passwordPrompt}" if @sshObj.debug
96
+ @.emit 'msg', "#{@sshObj.server.host}: Sudo Password prompt: Password sent: #{@sshObj.pwSent}" if @sshObj.debug
97
+ @.emit 'msg', "#{@sshObj.server.host}: Sudo Password: #{@sshObj.server.password}" if @sshObj.debug
98
+ @.emit 'msg', "#{@sshObj.server.host}: Sudo Response: #{response}" if @sshObj.verbose
99
+
100
+ #Prompt detection
101
+ #no password
102
+ switch (true)
103
+ when passwordPrompt and not @sshObj.server.password
104
+ @.emit 'msg', "#{@sshObj.server.host}: Sudo password prompt no password" if @sshObj.debug
105
+ @_resetFromSudoError()
106
+ when passwordPrompt and not @sshObj.pwSent
107
+ @.emit 'msg', "#{@sshObj.server.host}: Sudo password prompt: Buffer: #{response}" if @sshObj.verbose
108
+ @.emit 'msg', "#{@sshObj.server.host}: Sudo password prompt: Send password " if @sshObj.debug
109
+ @.emit 'msg', "#{@sshObj.server.host}: Sudo sent password: #{@sshObj.server.password}" if @sshObj.verbose
111
110
  #send password
112
111
  @sshObj.pwSent = true
113
112
  @_runCommand("#{@sshObj.server.password}")
114
- else
115
- @.emit 'msg', "#{@sshObj.server.host}: Password prompt: not detected" if @sshObj.debug
116
- @.emit 'msg', "#{@sshObj.server.host}: Password prompt #{@sshObj.passwordPrompt}" if @sshObj.verbose
117
- @_runExit()
118
- #password sent so either check for failure or run next command
119
- else if passwordPrompt
113
+ when passwordPrompt and @sshObj.pwSent
120
114
  @.emit 'msg', "#{@sshObj.server.host}: Sudo password faied: response: #{response}" if @sshObj.verbose
121
- @.emit 'error', "#{@sshObj.server.host}: Sudo password was incorrect for #{@sshObj.server.userName}", "Sudo authentication" if @sshObj.debug
122
- @.emit 'msg', "#{@sshObj.server.host}: Failed password prompt: Password: [#{@sshObj.server.password}]" if @sshObj.debug
115
+ @.emit 'error', "#{@sshObj.server.host}: Sudo password was incorrect for #{@sshObj.server.userName}, Sudo authentication" if @sshObj.debug
116
+ @.emit 'msg', "#{@sshObj.server.host}: Sudo failed password prompt: Password: [#{@sshObj.server.password}]" if @sshObj.debug
117
+ @sshObj.pwSent = false
123
118
  #add buffer to sessionText so the sudo response can be seen
124
- @sshObj.sessionText += "#{@_buffer}"
125
- @_buffer = ""
126
- #@sshObj.commands = []
127
- @command = ""
128
- @_stream.write '\x03'
129
-
119
+ @_resetFromSudoError()
120
+ when standardPrompt
121
+ @.emit 'msg', "#{@sshObj.server.host}: Sudo prompt: Standard prompt detected" if @sshObj.debug
122
+ @sshObj.pwSent = false
123
+ @.emit 'msg', "#{@sshObj.server.host}: Sudo Standard Response: #{response}" if @sshObj.verbose
124
+ @_commandComplete()
125
+ else
126
+ @idleTimer = setTimeout( =>
127
+ @.emit 'commandTimeout', @.command, response, @._stream, @._connection
128
+ , @idleTime)
129
+
130
+ _resetFromSudoError: =>
131
+ @sshObj.pwSent = false
132
+ @sshObj.sessionText += "#{@_buffer}"
133
+ @_buffer = ""
134
+ @command = ""
135
+ @_stream.write '\x03'
130
136
 
131
137
  _processSSHPrompt: =>
132
138
  #not authenticated yet so detect prompts
@@ -156,16 +162,16 @@ class SSH2Shell extends Stream
156
162
  @_runCommand("#{@sshObj.server.passPhrase}")
157
163
  #normal prompt so continue with next command
158
164
  else if standardPrompt
159
- @.emit 'msg', "#{@sshObj.server.host}: SSH: standard prompt: connection failed" if @sshObj.debug
165
+ @.emit 'msg', "#{@sshObj.server.host}: SSH standard prompt: connection failed" if @sshObj.debug
160
166
  @.emit 'msg', "#{@sshObj.server.host}: SSH connection failed"
161
167
  @.emit 'msg', "#{@sshObj.server.host}: SSH failed response: #{response}"
162
168
  @sshObj.sessionText += "#{@sshObj.server.host}: SSH failed: response: #{response}"
163
169
  @_runExit()
164
170
  else
165
- @.emit 'msg', "#{@sshObj.server.host}: SSH: no prompt was not detected"
166
- @.emit 'msg', "#{@sshObj.server.host}: Password prompt #{@sshObj.passwordPrompt}" if @sshObj.verbose and not @sshObj.server.hasOwnProperty("passPhrase")
167
- @.emit 'msg', "#{@sshObj.server.host}: Passphrase prompt #{@sshObj.passphrasePrompt}" if @sshObj.verbose and @sshObj.server.hasOwnProperty("passPhrase")
168
- @.emit 'msg', "#{@sshObj.server.host}: Standard prompt #{@sshObj.standardPrompt}" if @sshObj.verbose
171
+ @.emit 'msg', "#{@sshObj.server.host}: SSH no prompt was not detected"
172
+ @.emit 'msg', "#{@sshObj.server.host}: SSH password prompt #{@sshObj.passwordPrompt}" if @sshObj.verbose and not @sshObj.server.hasOwnProperty("passPhrase")
173
+ @.emit 'msg', "#{@sshObj.server.host}: SSH passphrase prompt #{@sshObj.passphrasePrompt}" if @sshObj.verbose and @sshObj.server.hasOwnProperty("passPhrase")
174
+ @.emit 'msg', "#{@sshObj.server.host}: SSH standard prompt #{@sshObj.standardPrompt}" if @sshObj.verbose
169
175
  @_runExit()
170
176
  else
171
177
  @.emit 'msg', "#{@sshObj.server.host}: SSH post authentication prompt detection" if @sshObj.debug
@@ -183,8 +189,8 @@ class SSH2Shell extends Stream
183
189
  @.emit 'msg', "#{@sshObj.server.host}: SSH: failed response: #{response}" if @sshObj.verbose
184
190
  @sshObj.sshAuth = false
185
191
  using = switch
186
- when passwordPrompt then "password: #{@sshObj.server.password}"
187
- when passphrasePrompt then "passphrase: #{@sshObj.server.passPhrase}"
192
+ when passwordPrompt then "SSH password: #{@sshObj.server.password}"
193
+ when passphrasePrompt then "SSH passphrase: #{@sshObj.server.passPhrase}"
188
194
  @.emit 'error', "#{@sshObj.server.host}: SSH authentication failed for #{@sshObj.server.userName}@#{@sshObj.server.host}", "Nested host authentication"
189
195
  @.emit 'msg', "#{@sshObj.server.host}: SSH auth failed: Using " + using if @sshObj.debug
190
196
 
@@ -378,7 +384,7 @@ class SSH2Shell extends Stream
378
384
  @hosts = hosts
379
385
  else
380
386
  @hosts = [hosts]
381
- @ssh2Client = require('ssh2')
387
+ @ssh2Client = require('ssh2').Client
382
388
  @.on "newPrimmaryHost", @_nextPrimaryHost
383
389
  @.on "data", (data) =>
384
390
  #@.emit 'msg', "#{@sshObj.server.host}: data event: #{data}" if @sshObj.verbose
@@ -578,33 +584,10 @@ class SSH2Shell extends Stream
578
584
 
579
585
  if @sshObj.server and @sshObj.commands
580
586
  try
581
- @connection.connect
582
- host: @sshObj.server.host
583
- port: @sshObj.server.port
584
- forceIPv4: @sshObj.server.forceIPv4
585
- forceIPv6: @sshObj.server.forceIPv6
586
- hostHash: @sshObj.server.hashMethod
587
- hostVerifier: @sshObj.server.hostVerifier
588
- username: @sshObj.server.userName
589
- password: @sshObj.server.password
590
- agent: @sshObj.server.agent
591
- agentForward: @sshObj.server.agentForward
592
- privateKey: @sshObj.server.privateKey
593
- passphrase: @sshObj.server.passPhrase
594
- localHostname: @sshObj.server.localHostname
595
- localUsername: @sshObj.server.localUsername
596
- localAddress: @sshObj.server.localAddress
597
- localPort: @sshObj.server.localPort
598
- authHandler: @sshObj.server.authHandler
599
- tryKeyboard: @sshObj.server.tryKeyboard
600
- keepaliveInterval:@sshObj.server.keepaliveInterval
601
- keepaliveCountMax:@sshObj.server.keepaliveCountMax
602
- readyTimeout: @sshObj.server.readyTimeout
603
- sock: @sshObj.server.sock
604
- strictVendor: @sshObj.server.strictVendor
605
- algorithms: @sshObj.server.algorithms
606
- compress: @sshObj.server.compress
607
- debug: @sshObj.server.debug
587
+ @sshObj.server.username = @sshObj.server.userName unless @sshObj.server.username
588
+ @sshObj.server.hostHash = @sshObj.server.hashMethod unless @sshObj.server.hostHash
589
+ @sshObj.server.passphrase = @sshObj.server.passPhrase unless @sshObj.server.passphrase
590
+ @connection.connect @sshObj.server
608
591
  catch e
609
592
  @.emit 'error', "#{e} #{e.stack}", "Connection.connect", true
610
593
  else
@@ -0,0 +1,40 @@
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: false,
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("y")
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);