* New user reserved names now direct to applicaiton process for SSH

This commit is contained in:
Bryan Ashby
2015-10-22 12:22:03 -06:00
parent 93cff52c1f
commit e9836e18db
5 changed files with 130 additions and 24 deletions

View File

@@ -180,9 +180,6 @@ function startListening() {
return;
}
// servers require 'firstMenu'
assert(module.runtime.config.firstMenu, 'Server missing \'firstMenu\' member!');
var moduleInst = new module.getModule();
var server = moduleInst.createServer();
@@ -202,13 +199,13 @@ function startListening() {
clientConns.addNewClient(client, clientSock);
client.on('ready', function onClientReady() {
client.on('ready', function clientReady(readyOptions) {
client.startIdleMonitor();
// Go to module -- use default error handler
prepareClient(client, function onPrepared() {
require('./connect.js').connectEntry(client, module.runtime.config.firstMenu);
prepareClient(client, function clientPrepared() {
require('./connect.js').connectEntry(client, readyOptions.firstMenu);
});
});

View File

@@ -62,6 +62,8 @@ function getDefaultConfig() {
general : {
boardName : 'Another Fine ENiGMA½ BBS',
closedSystem : false, // is the system closed to new users?
loginAttempts : 3,
},
@@ -127,11 +129,12 @@ function getDefaultConfig() {
firstMenu : 'telnetConnected',
},
ssh : {
port : 8889,
enabled : true,
rsaPrivateKey : paths.join(__dirname, './../misc/default_key.rsa'),
dsaPrivateKey : paths.join(__dirname, './../misc/default_key.dsa'),
firstMenu : 'sshConnected',
port : 8889,
enabled : true,
rsaPrivateKey : paths.join(__dirname, './../misc/default_key.rsa'),
dsaPrivateKey : paths.join(__dirname, './../misc/default_key.dsa'),
firstMenu : 'sshConnected',
firstMenuNewUser : 'sshConnectedNewUser',
}
},

View File

@@ -2,7 +2,7 @@
'use strict';
// ENiGMA½
var conf = require('../config.js');
var Config = require('../config.js').config;
var baseClient = require('../client.js');
var Log = require('../logger.js').log;
var ServerModule = require('../server_module.js').ServerModule;
@@ -45,16 +45,25 @@ function SSHClient(clientConn) {
var loginAttempts = 0;
clientConn.on('authentication', function authAttempt(ctx) {
self.log.trace( { method : ctx.method, username : ctx.username }, 'SSH authentication attempt');
var username = ctx.username || '';
var password = ctx.password || '';
self.isNewUser = (Config.users.newUserNames || []).indexOf(username) > -1;
self.log.trace( { method : ctx.method, username : username, newUser : self.isNewUser }, 'SSH authentication attempt');
function termConnection() {
ctx.reject();
clientConn.end();
}
//
// If the system is open and |isNewUser| is true, the login
// sequence is hijacked in order to start the applicaiton process.
//
if(false === Config.general.closedSystem && self.isNewUser) {
return ctx.accept();
}
if(username.length > 0 && password.length > 0) {
loginAttempts += 1;
@@ -76,8 +85,6 @@ function SSHClient(clientConn) {
return ctx.reject(SSHClient.ValidAuthMethods);
}
console.log(ctx.method)
if(0 === username.length) {
// :TODO: can we display something here?
return ctx.reject();
@@ -94,7 +101,7 @@ function SSHClient(clientConn) {
// :TODO: can we display something here?
termConnection();
} else {
if(loginAttempts >= conf.config.general.loginAttempts) {
if(loginAttempts >= Config.general.loginAttempts) {
termConnection();
} else {
var artOpts = {
@@ -106,7 +113,7 @@ function SSHClient(clientConn) {
if(err) {
interactivePrompt.prompt = 'Access denied\n' + ctx.username + '\'s password: ';
} else {
var newUserNameList = '"' + (conf.config.users.newUserNames || []).join(', ') + '"';
var newUserNameList = '"' + (Config.users.newUserNames || []).join(', ') + '"';
interactivePrompt.prompt =
'Access denied\n' +
artInfo.data.format( { newUserNames : newUserNameList } ) +
@@ -194,7 +201,8 @@ function SSHClient(clientConn) {
}
// we're ready!
self.emit('ready');
var firstMenu = self.isNewUser ? Config.servers.ssh.firstMenuNewUser : Config.servers.ssh.firstMenu;
self.emit('ready', { firstMenu : firstMenu } );
});
session.on('window-change', function windowChange(accept, reject, info) {
@@ -231,11 +239,11 @@ SSHServerModule.prototype.createServer = function() {
SSHServerModule.super_.prototype.createServer.call(this);
var serverConf = {
privateKey : fs.readFileSync(conf.config.servers.ssh.rsaPrivateKey),
privateKey : fs.readFileSync(Config.servers.ssh.rsaPrivateKey),
ident : 'enigma-bbs-' + enigVersion + '-srv',
// Note that sending 'banner' breaks at least EtherTerm!
debug : function debugSsh(dbgLine) {
if(true === conf.config.servers.ssh.debugConnections) {
if(true === Config.servers.ssh.debugConnections) {
Log.trace('SSH: ' + dbgLine);
}
},

View File

@@ -5,6 +5,7 @@
var baseClient = require('../client.js');
var Log = require('../logger.js').log;
var ServerModule = require('../server_module.js').ServerModule;
var Config = require('../config.js').config;
var net = require('net');
var buffers = require('buffers');
@@ -583,7 +584,7 @@ TelnetClient.prototype.handleSbCommand = function(evt) {
if(!self.didReady) {
self.didReady = true;
self.emit('ready');
self.emit('ready', { firstMenu : Config.servers.telnet.firstMenu } );
}
} else if('new environment' === evt.option) {
//