~ Initial commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/node_modules/
|
||||
config.json
|
||||
6
defaultConfig.json
Normal file
6
defaultConfig.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"addresses": [],
|
||||
"username": "ubnt",
|
||||
"password": "ubnt",
|
||||
"payload": []
|
||||
}
|
||||
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 -----');
|
||||
})();
|
||||
}
|
||||
71
index.ts
Normal file
71
index.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
const { pathExists, copy, readJSON } = require('fs-extra');
|
||||
const { join } = require('path');
|
||||
const { Client } = require('ssh2');
|
||||
|
||||
var configPath = join(__filename, '..', 'config.json');
|
||||
var defaultConfigPath = join(__filename, '..', 'defaultConfig.json');
|
||||
|
||||
var config: Config = null;
|
||||
|
||||
pathExists(configPath, (exists, err) => {
|
||||
if (err) throw err;
|
||||
if (exists) {
|
||||
readJSON(config, (configJson, err) => {
|
||||
if (err) throw err;
|
||||
config = configJson;
|
||||
|
||||
startPrepare();
|
||||
});
|
||||
} else
|
||||
copy(defaultConfigPath, configPath, (err) => {
|
||||
if (err) throw err;
|
||||
console.log(`----- Default config has been copied -----`);
|
||||
});
|
||||
});
|
||||
|
||||
function startPrepare() {
|
||||
console.log(`----- STARTING PREPARE ON ${config.addresses.length} DEVICES -----`);
|
||||
(function handle(i = 0) {
|
||||
if (config.addresses[i]) {
|
||||
var address = config.addresses[i];
|
||||
|
||||
console.log(`Starting on device ${address}`);
|
||||
|
||||
var ip = address.split(':')[0];
|
||||
var port = address.split(':')[1] != undefined ? address.split(':')[1] : 22;
|
||||
|
||||
const conn = new Client();
|
||||
conn
|
||||
.on('ready', () => {
|
||||
console.log(' Client :: ready');
|
||||
conn.shell((err, stream) => {
|
||||
if (err) throw err;
|
||||
stream
|
||||
.on('close', () => {
|
||||
console.log(' Stream :: close');
|
||||
conn.end();
|
||||
console.log(`Finished device ${address}`);
|
||||
handle(i + 1);
|
||||
})
|
||||
.on('data', (data) => {
|
||||
console.log(' Output: ' + data);
|
||||
});
|
||||
stream.end(`${config.payload.join('\n')}\nexit\n`);
|
||||
});
|
||||
})
|
||||
.connect({
|
||||
host: ip,
|
||||
port: port,
|
||||
username: config.username,
|
||||
password: config.password
|
||||
});
|
||||
} else console.log('----- FINISHED ALL DEVICES -----');
|
||||
})();
|
||||
}
|
||||
|
||||
interface Config {
|
||||
addresses: string[];
|
||||
username: string;
|
||||
password: string;
|
||||
payload: string[];
|
||||
}
|
||||
161
package-lock.json
generated
Normal file
161
package-lock.json
generated
Normal file
@@ -0,0 +1,161 @@
|
||||
{
|
||||
"name": "ubiquitypreparetool",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "ubiquitypreparetool",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@types/fs-extra": "^11.0.1",
|
||||
"fs-extra": "^11.1.1",
|
||||
"ssh2": "^1.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ssh2": "^1.11.9"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/fs-extra": {
|
||||
"version": "11.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-11.0.1.tgz",
|
||||
"integrity": "sha512-MxObHvNl4A69ofaTRU8DFqvgzzv8s9yRtaPPm5gud9HDNvpB3GPQFvNuTWAI59B9huVGV5jXYJwbCsmBsOGYWA==",
|
||||
"dependencies": {
|
||||
"@types/jsonfile": "*",
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/jsonfile": {
|
||||
"version": "6.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/jsonfile/-/jsonfile-6.1.1.tgz",
|
||||
"integrity": "sha512-GSgiRCVeapDN+3pqA35IkQwasaCh/0YFH5dEF6S88iDvEn901DjOeH3/QPY+XYP1DFzDZPvIvfeEgk+7br5png==",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "18.15.11",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.11.tgz",
|
||||
"integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q=="
|
||||
},
|
||||
"node_modules/@types/ssh2": {
|
||||
"version": "1.11.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/ssh2/-/ssh2-1.11.9.tgz",
|
||||
"integrity": "sha512-XYMED+cBW11DfMidB/BlCcTzBsSAccaHLvdtdlVWGgDp7TlweGIfb+gHEalKptzVS2qb3jLoR0XrGCWljrIV9A==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/node": "^18.11.18"
|
||||
}
|
||||
},
|
||||
"node_modules/asn1": {
|
||||
"version": "0.2.6",
|
||||
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz",
|
||||
"integrity": "sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==",
|
||||
"dependencies": {
|
||||
"safer-buffer": "~2.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/bcrypt-pbkdf": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
|
||||
"integrity": "sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==",
|
||||
"dependencies": {
|
||||
"tweetnacl": "^0.14.3"
|
||||
}
|
||||
},
|
||||
"node_modules/buildcheck": {
|
||||
"version": "0.0.3",
|
||||
"resolved": "https://registry.npmjs.org/buildcheck/-/buildcheck-0.0.3.tgz",
|
||||
"integrity": "sha512-pziaA+p/wdVImfcbsZLNF32EiWyujlQLwolMqUQE8xpKNOH7KmZQaY8sXN7DGOEzPAElo9QTaeNRfGnf3iOJbA==",
|
||||
"optional": true,
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/cpu-features": {
|
||||
"version": "0.0.4",
|
||||
"resolved": "https://registry.npmjs.org/cpu-features/-/cpu-features-0.0.4.tgz",
|
||||
"integrity": "sha512-fKiZ/zp1mUwQbnzb9IghXtHtDoTMtNeb8oYGx6kX2SYfhnG0HNdBEBIzB9b5KlXu5DQPhfy3mInbBxFcgwAr3A==",
|
||||
"hasInstallScript": true,
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"buildcheck": "0.0.3",
|
||||
"nan": "^2.15.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/fs-extra": {
|
||||
"version": "11.1.1",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.1.tgz",
|
||||
"integrity": "sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==",
|
||||
"dependencies": {
|
||||
"graceful-fs": "^4.2.0",
|
||||
"jsonfile": "^6.0.1",
|
||||
"universalify": "^2.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.14"
|
||||
}
|
||||
},
|
||||
"node_modules/graceful-fs": {
|
||||
"version": "4.2.11",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
||||
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ=="
|
||||
},
|
||||
"node_modules/jsonfile": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
|
||||
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
|
||||
"dependencies": {
|
||||
"universalify": "^2.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"graceful-fs": "^4.1.6"
|
||||
}
|
||||
},
|
||||
"node_modules/nan": {
|
||||
"version": "2.17.0",
|
||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz",
|
||||
"integrity": "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||
},
|
||||
"node_modules/ssh2": {
|
||||
"version": "1.11.0",
|
||||
"resolved": "https://registry.npmjs.org/ssh2/-/ssh2-1.11.0.tgz",
|
||||
"integrity": "sha512-nfg0wZWGSsfUe/IBJkXVll3PEZ//YH2guww+mP88gTpuSU4FtZN7zu9JoeTGOyCNx2dTDtT9fOpWwlzyj4uOOw==",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"asn1": "^0.2.4",
|
||||
"bcrypt-pbkdf": "^1.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.16.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"cpu-features": "~0.0.4",
|
||||
"nan": "^2.16.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tweetnacl": {
|
||||
"version": "0.14.5",
|
||||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
|
||||
"integrity": "sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA=="
|
||||
},
|
||||
"node_modules/universalify": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
|
||||
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==",
|
||||
"engines": {
|
||||
"node": ">= 10.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
package.json
Normal file
17
package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "ubiquitypreparetool",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@types/fs-extra": "^11.0.1",
|
||||
"fs-extra": "^11.1.1",
|
||||
"ssh2": "^1.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ssh2": "^1.11.9"
|
||||
}
|
||||
}
|
||||
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"watch": true,
|
||||
"outFile": "index.js"
|
||||
},
|
||||
"include": [
|
||||
"index.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user