-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-ssh.js
More file actions
70 lines (52 loc) · 1.95 KB
/
simple-ssh.js
File metadata and controls
70 lines (52 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module.exports = function (RED) {
"use strict";
var mustache = require("mustache");
var SSH = require('simple-ssh');
function SimpleSSHNode(config) {
RED.nodes.createNode(this, config);
var node = this;
node.ip = null;
//var isTemplatedIP = (nodeIP||"").indexOf("{{") != -1;
node.on('input', function (msg) {
var preRequestTimestamp = process.hrtime();
node.status({ fill: "blue", shape: "dot", text: "httpin.status.requesting" });
node.ip = msg.ip || this.credentials.ip;
if (msg.ip && this.credentials.ip && (this.credentials.ip !== msg.ip)) { // revert change below when warning is finally removed
node.warn(RED._("common.errors.nooverride"));
}
// if (isTemplatedIP) {
// ip = mustache.render( this.credentials.ip,msg);
// }
if (!node.ip) {
node.error(RED._("httpin.errors.no-ip"), msg);
return;
}
if (!this.credentials && !this.credentials.user && !this.credentials.password) {
node.error(RED._("httpin.errors.no-auth"), msg);
return;
}
var payload = null;
var ssh = new SSH({
host: node.ip,
user: this.credentials.user,
pass: this.credentials.password,
port: this.credentials.port || 22
});
ssh
.exec('', {
out: function (stdout) {
console.log(stdout);
node.send(stdout);
}
}).start();
});
}
RED.nodes.registerType("simple-SSH", SimpleSSHNode, {
credentials: {
ip: { type: "text" },
port: { type: "text" },
user: { type: "text" },
password: { type: "password" }
}
});
}