Prompt when already logged in
This commit is contained in:
parent
ddcf7f5865
commit
94f3721bf8
|
@ -41,14 +41,19 @@ function SSHClient(clientConn) {
|
||||||
clientConn.on('authentication', function authAttempt(ctx) {
|
clientConn.on('authentication', function authAttempt(ctx) {
|
||||||
const username = ctx.username || '';
|
const username = ctx.username || '';
|
||||||
const password = ctx.password || '';
|
const password = ctx.password || '';
|
||||||
|
|
||||||
self.isNewUser = (Config.users.newUserNames || []).indexOf(username) > -1;
|
self.isNewUser = (Config.users.newUserNames || []).indexOf(username) > -1;
|
||||||
|
|
||||||
self.log.trace( { method : ctx.method, username : username, newUser : self.isNewUser }, 'SSH authentication attempt');
|
self.log.trace( { method : ctx.method, username : username, newUser : self.isNewUser }, 'SSH authentication attempt');
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ctx.accept();
|
return ctx.reject(SSHClient.ValidAuthMethods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,37 +96,36 @@ 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) {
|
|
||||||
terminateConnection();
|
|
||||||
} else {
|
|
||||||
const artOpts = {
|
|
||||||
client : self,
|
|
||||||
name : 'SSHPMPT.ASC',
|
|
||||||
readSauce : false,
|
|
||||||
};
|
|
||||||
|
|
||||||
theme.getThemeArt(artOpts, (err, artInfo) => {
|
|
||||||
if(err) {
|
|
||||||
interactivePrompt.prompt = `Access denied\n${ctx.username}'s password: `;
|
|
||||||
} else {
|
|
||||||
const newUserNameList = _.has(Config, 'users.newUserNames') && Config.users.newUserNames.length > 0 ?
|
|
||||||
Config.users.newUserNames.map(newName => '"' + newName + '"').join(', ') :
|
|
||||||
'(No new user names enabled!)';
|
|
||||||
|
|
||||||
interactivePrompt.prompt = `Access denied\n${stringFormat(artInfo.data, { newUserNames : newUserNameList })}\n${ctx.username}'s password'`;
|
|
||||||
}
|
|
||||||
return ctx.prompt(interactivePrompt, retryPrompt);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(loginAttempts >= Config.general.loginAttempts) {
|
||||||
|
return terminateConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
const artOpts = {
|
||||||
|
client : self,
|
||||||
|
name : 'SSHPMPT.ASC',
|
||||||
|
readSauce : false,
|
||||||
|
};
|
||||||
|
|
||||||
|
theme.getThemeArt(artOpts, (err, artInfo) => {
|
||||||
|
if(err) {
|
||||||
|
interactivePrompt.prompt = `Access denied\n${ctx.username}'s password: `;
|
||||||
|
} else {
|
||||||
|
const newUserNameList = _.has(Config, 'users.newUserNames') && Config.users.newUserNames.length > 0 ?
|
||||||
|
Config.users.newUserNames.map(newName => '"' + newName + '"').join(', ') :
|
||||||
|
'(No new user names enabled!)';
|
||||||
|
|
||||||
|
interactivePrompt.prompt = `Access denied\n${stringFormat(artInfo.data, { newUserNames : newUserNameList })}\n${ctx.username}'s password'`;
|
||||||
|
}
|
||||||
|
return ctx.prompt(interactivePrompt, retryPrompt);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
ctx.accept();
|
ctx.accept();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue