Commit 8388ce5e authored by Alejandro E. Rendon's avatar Alejandro E. Rendon
Browse files

Fixing create user with ssh Key

parent f5c955b7
......@@ -58,15 +58,6 @@ exports.remove = (req, res) => {
};
exports.getUsers = (req, res) => {
getLinuxId((err, uid) => {
if (err)
console.log(err);
else {
console.log(uid);
userid = uid;
}
});
const page = req.params.id;
User.find((err, docs) => {
......@@ -98,33 +89,49 @@ exports.new = (req, res) => {
console.log(err);
res.redirect('/');
} else {
console.log(uid);
createUser(uid, user, err => {
if (err) {
console.log(err);
res.redirect('/');
} else {
createUserCluster(uid, user, err => {
console.log('here');
User.update({ username: id }, { state: user.state, uid: uid }, (
err,
data
) => {
if (err) {
console.log(err);
res.redirect('/');
// res.redirect('/');
} else {
console.log('CREATED');
User.update(
{ username: id },
{ state: user.state, uid: uid },
(err, data) => {
if (err)
console.log(err);
else {
sshKey(user, err => {
if (err) console.log(err);
else res.redirect('/admin/users');
});
}
}
);
sshKey(user, err => {
if (err) console.log(err);
else res.redirect('/admin/users');
});
}
});
// createUserCluster(uid, user, err => {
// if (err) {
// console.log(err);
// res.redirect('/');
// } else {
// console.log('CREATED');
// User.update(
// { username: id },
// { state: user.state, uid: uid },
// (err, data) => {
// if (err)
// console.log(err);
// else {
// sshKey(user, err => {
// if (err) console.log(err);
// else res.redirect('/admin/users');
// });
// }
// }
// );
// }
// });
}
});
}
......
......@@ -118,21 +118,11 @@ exports.sshKey = (user, callback) => {
pass: decrypt(user.linux)
});
const pathKey = 'ssh-keygen -b 2048 -t rsa -f /homeshare/' +
user.username +
'/.ssh/id_rsa -q -N ""',
autKeys = 'cat /homeshare/' +
user.username +
'/.ssh/id_rsa.pub >> /homeshare/' +
user.username +
'/.ssh/authorized_keys',
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',
pathSSH = add + ' >> /homeshare/' + user.username + '/.bashrc';
const pathKey = `ssh-keygen -b 2048 -t rsa -f /homeshare/${user.username}/.ssh/id_rsa -q -N ""`,
autKeys = `cat /homeshare/${user.username}/.ssh/id_rsa.pub >> /homeshare/${user.username}/.ssh/authorized_keys`,
add = `'if type keychain >/dev/null 2>/dev/null; then'`,
pathSSH = 'echo ' + add + ' >> /homeshare/' + user.username + '/.bashrc';
console.log(pathSSH);
ssh
.exec(pathKey, {
err: stderr => {
......@@ -140,48 +130,19 @@ exports.sshKey = (user, callback) => {
return callback(stderr);
}
})
.exec(autKeys, {
err: stderr => {
console.log(stderr);
return callback(stderr);
}
})
.exec(pathSSH, {
err: stderr => {
console.log(stderr);
return callback(stderr);
}
})
// .exec(autKeys, {
// err: stderr => {
// console.log(stderr);
// return callback(stderr);
// }
// })
// .exec(pathSSH, {
// err: stderr => {
// console.log(stderr);
// return callback(stderr);
// }
// })
.start();
return callback(null);
// 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);
// });
// }
// });
// }
// });
};
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