Prompt when already logged in

This commit is contained in:
Bryan Ashby 2018-01-21 20:49:38 -07:00
parent ddcf7f5865
commit 94f3721bf8
1 changed files with 39 additions and 37 deletions

View File

@ -48,7 +48,12 @@ function SSHClient(clientConn) {
function terminateConnection() { function terminateConnection() {
ctx.reject(); ctx.reject();
clientConn.end(); return clientConn.end();
}
function alreadyLoggedIn(username) {
ctx.prompt(`${username} is already connected to the system. Terminating connection.\n(Press any key to continue)`);
return terminateConnection();
} }
// //
@ -65,15 +70,13 @@ function SSHClient(clientConn) {
userLogin(self, ctx.username, ctx.password, function authResult(err) { userLogin(self, ctx.username, ctx.password, function authResult(err) {
if(err) { if(err) {
if(err.existingConn) { if(err.existingConn) {
// :TODO: Can we display somthing here? return alreadyLoggedIn(username);
terminateConnection(); }
return;
} else {
return ctx.reject(SSHClient.ValidAuthMethods); return ctx.reject(SSHClient.ValidAuthMethods);
} }
} else {
ctx.accept(); ctx.accept();
}
}); });
} else { } else {
if(-1 === SSHClient.ValidAuthMethods.indexOf(ctx.method)) { if(-1 === SSHClient.ValidAuthMethods.indexOf(ctx.method)) {
@ -85,7 +88,7 @@ function SSHClient(clientConn) {
return ctx.reject(); return ctx.reject();
} }
let interactivePrompt = { prompt : `${ctx.username}'s password: `, echo : false }; const interactivePrompt = { prompt : `${ctx.username}'s password: `, echo : false };
ctx.prompt(interactivePrompt, function retryPrompt(answers) { ctx.prompt(interactivePrompt, function retryPrompt(answers) {
loginAttempts += 1; loginAttempts += 1;
@ -93,12 +96,13 @@ function SSHClient(clientConn) {
userLogin(self, username, (answers[0] || ''), err => { userLogin(self, username, (answers[0] || ''), err => {
if(err) { if(err) {
if(err.existingConn) { if(err.existingConn) {
// :TODO: can we display something here? return alreadyLoggedIn(username);
terminateConnection(); }
} else {
if(loginAttempts >= Config.general.loginAttempts) { if(loginAttempts >= Config.general.loginAttempts) {
terminateConnection(); return terminateConnection();
} else { }
const artOpts = { const artOpts = {
client : self, client : self,
name : 'SSHPMPT.ASC', name : 'SSHPMPT.ASC',
@ -117,8 +121,6 @@ function SSHClient(clientConn) {
} }
return ctx.prompt(interactivePrompt, retryPrompt); return ctx.prompt(interactivePrompt, retryPrompt);
}); });
}
}
} else { } else {
ctx.accept(); ctx.accept();
} }