Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions nodes/ssh-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ module.exports = function(RED) {
conn.on('ready', () => {
isConnected = true;
updateNodeStatus();

// Notify connection established
if (enableLogging) {
node.log('SSH Connection Established');
}
Expand All @@ -58,12 +56,32 @@ module.exports = function(RED) {
node.log('SSH Shell Opened');
}

let initialOutput = ''; // Variable to collect initial output
let buffer = ''; // Use a buffer to accumulate data
let initialOutput = '';

stream.on('data', (data) => {
initialOutput += data.toString(); // Collect output
let output = data.toString();
initialOutput += data.toString();
buffer += output;

// Check for password prompt using case-insensitive regex
if (/password:/i.test(buffer)) {
// Extract the password from config or msg.payload
let password = msg.payload.password2 || config.password;

if (password) {
stream.write(password + '\n');
buffer = ''; // Clear buffer after sending password
if (enableLogging) {
node.log('Password submitted to SSH session');
}
} else {
node.warn('Password prompt detected but no password provided.');
}
}
}).on('close', () => {
// Handle stream close
isConnected = false;
updateNodeStatus(); // Update status immediately upon disconnection
});

// Delay sending the initial output to ensure collection of data
Expand All @@ -78,7 +96,6 @@ module.exports = function(RED) {
}).on('error', (err) => {
isConnected = false;
updateNodeStatus();

if (enableLogging) {
node.error('SSH Connection Error: ' + err.toString());
}
Expand Down