Commit 22c2e5f2 authored by Alejandro E. Rendon's avatar Alejandro E. Rendon
Browse files

Supervisor

parent 0ec38e0d
......@@ -9,7 +9,8 @@ const User = require('../models/user').User,
linuxPass,
getLinuxId,
createUser,
createUserCluster
createUserCluster,
sshKey
} = require('../helpers/user');
exports.add = (req, res) => {
......@@ -92,7 +93,6 @@ exports.new = (req, res) => {
} else {
user.state = 2;
console.log(user);
// res.redirect('/');
getLinuxId((err, uid) => {
if (err) {
console.log(err);
......@@ -113,8 +113,14 @@ exports.new = (req, res) => {
{ username: id },
{ state: user.state, uid: uid },
(err, data) => {
if (err) console.log(err);
else res.redirect('/admin/users');
if (err)
console.log(err);
else {
sshKey(user, err => {
if (err) console.log(err);
else res.redirect('/admin/users');
});
}
}
);
}
......
......@@ -110,3 +110,40 @@ exports.createUserCluster = (uid, username, callback) => {
return callback(null);
};
exports.sshKey = (user, callback) => {
const path = 'sshpass -p ' +
decrypt(user.linux) +
' ssh ' +
user.username +
'@localhost';
exec(path, (err, stdout, stderr) => {
if (err)
return callback(err);
else if (stderr)
return callaback(stderr);
else {
const pathKey = 'ssh-keygen -b 2048 -t rsa -f /tmp/sshkey -q -N ""';
exec(pathKey, (err, stdout, stderr) => {
if (err)
return callaback(err);
else if (stderr)
return callaback(stderr);
else {
const add = 'if type keychain >/dev/null 2>/dev/null; then' +
'keychain --nogui -q .ssh/id_rsa' +
'[ -f ~/.keychain/${HOSTNAME}-sh ] && . ~/.keychain/${HOSTNAME}-sh' +
'[ -f ~/.keychain/${HOSTNAME}-sh-gpg ] && . ~/.keychain/${HOSTNAME}-sh-gpg' +
'fi';
const pathSSH = add + ' >> .bashrc';
exec(pathSSH, (err, stdout, stderr) => {
if (err) return callaback(err);
else if (stderr) return callaback(stderr);
else return callaback(null);
});
}
});
}
});
};
......@@ -5,7 +5,7 @@
"main": "app.js",
"private": true,
"scripts": {
"start": "nodemon ./bin/www"
"start": "supervisor -e 'js|node|coffee|ejs|json' ./bin/www"
},
"repository": {
"type": "git",
......@@ -48,7 +48,8 @@
"passport-jwt": "^2.2.1",
"passport-local": "^1.0.0",
"serve-favicon": "~2.3.0",
"simple-ssh": "^0.9.0"
"simple-ssh": "^0.9.0",
"supervisor": "^0.12.0"
},
"devDependencies": {
"eslint": "^3.12.0"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment