~ Initial commit
This commit is contained in:
64
index.js
Normal file
64
index.js
Normal file
@@ -0,0 +1,64 @@
|
||||
var _a = require('fs-extra'), pathExists = _a.pathExists, copy = _a.copy, readJSON = _a.readJSON;
|
||||
var join = require('path').join;
|
||||
var Client = require('ssh2').Client;
|
||||
var configPath = join(__filename, '..', 'config.json');
|
||||
var defaultConfigPath = join(__filename, '..', 'defaultConfig.json');
|
||||
var config = null;
|
||||
pathExists(configPath, function (exists, err) {
|
||||
if (err)
|
||||
throw err;
|
||||
if (exists) {
|
||||
readJSON(config, function (configJson, err) {
|
||||
if (err)
|
||||
throw err;
|
||||
config = configJson;
|
||||
startPrepare();
|
||||
});
|
||||
}
|
||||
else
|
||||
copy(defaultConfigPath, configPath, function (err) {
|
||||
if (err)
|
||||
throw err;
|
||||
console.log("----- Default config has been copied -----");
|
||||
});
|
||||
});
|
||||
function startPrepare() {
|
||||
console.log("----- STARTING PREPARE ON ".concat(config.addresses.length, " DEVICES -----"));
|
||||
(function handle(i) {
|
||||
if (i === void 0) { i = 0; }
|
||||
if (config.addresses[i]) {
|
||||
var address = config.addresses[i];
|
||||
console.log("Starting on device ".concat(address));
|
||||
var ip = address.split(':')[0];
|
||||
var port = address.split(':')[1] != undefined ? address.split(':')[1] : 22;
|
||||
var conn_1 = new Client();
|
||||
conn_1
|
||||
.on('ready', function () {
|
||||
console.log(' Client :: ready');
|
||||
conn_1.shell(function (err, stream) {
|
||||
if (err)
|
||||
throw err;
|
||||
stream
|
||||
.on('close', function () {
|
||||
console.log(' Stream :: close');
|
||||
conn_1.end();
|
||||
console.log("Finished device ".concat(address));
|
||||
handle(i + 1);
|
||||
})
|
||||
.on('data', function (data) {
|
||||
console.log(' Output: ' + data);
|
||||
});
|
||||
stream.end("".concat(config.payload.join('\n'), "\nexit\n"));
|
||||
});
|
||||
})
|
||||
.connect({
|
||||
host: ip,
|
||||
port: port,
|
||||
username: config.username,
|
||||
password: config.password
|
||||
});
|
||||
}
|
||||
else
|
||||
console.log('----- FINISHED ALL DEVICES -----');
|
||||
})();
|
||||
}
|
||||
Reference in New Issue
Block a user