-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh.js
111 lines (94 loc) · 2.52 KB
/
ssh.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// https://code.i-harness.com/de/q/683f2e
// https://www.dev2qa.com/node-js-read-write-file-examples/
exports.getDomains = function (filepath) {
fs = require('fs');
var encoding = 'utf8';
// var filepath = './domains.txt';
var domains = fs.readFileSync(filepath, encoding).toString().split("\r\n");
return domains;
};
exports.getCommands = function (domains, cmd) {
var line = [];
for (i in domains) {
var domain = domains[i].trim();
var new_line = cmd.replace(/{domain}/g, domain);
line.push(new_line);
}
return line;
};
exports.getCommandsOnDomain = function (cmds, domain) {
var line = [];
for (i in cmds) {
domain = domain.trim();
var cmd = cmds[i];
var new_line = cmd.replace(/{domain}/g, domain);
line.push(new_line);
}
return line;
};
exports.getCommandsOnDomains = function (cmds, domains) {
var line = [];
domains.forEach(function (domain) {
cmds.forEach(function (cmd) {
var _domain = domain.trim();
var _cmd = cmd.trim();
var _line = _cmd.replace(/{domain}/g, _domain);
line.push(_line);
});
});
return line;
};
exports.CmdsOnDoms = function (ssh, cmds, domains) {
var domains_cmds = exports.getCommandsOnDomains(cmds, domains);
console.log(domains_cmds);
exports.sshExecute(ssh, domains_cmds, console.log.bind(console));
};
exports.sshExecute = function (ssh, cmds, func) {
// var result = [];
cmds.forEach(function (item) {
console.log(item);
ssh
.exec(item, {
// out: console.log.bind(console)
out: func
})
});
ssh.start();
// return result
};
//
// function plesco(cmd) {
// plesk.sshExecute(ssh, cmd, console.log.bind(console));
// }
// function plescodom(cmds, domain) {
// var domains_cmds = plesk.getCommandsOnDomain(cmds, domain);
// console.log(domains_cmds);
// plesk.sshExecute(ssh, domains_cmds, console.log.bind(console));
// }
/*
var fileContent = '';
var length = line.length;
for(var i=0;i<length; i++)
{
fileContent += line[i] + '\n';
}
fs.writeFile("./plesk.script.txt", fileContent, (err) => {
if (err) {
console.error(err);
return;
};
console.log("File has been created");
});
*/
/*
try {
const file = fs.readFileSync(filepath, encoding);
console.log(file);
for (const row of file) {
console.log(row);
}
// console.log(flow)
} catch (e) {
console.log(e);
}
*/