* SSH is now functional for 'ssh', PuTTY, SyncTerm, EtherTerm, and hopefully most others

* Explicit detect of syncterm as ANSI
* Add serverType (TELNET, SSH) MCI: %ST
This commit is contained in:
Bryan Ashby 2015-10-21 22:51:35 -06:00
parent e7e9746a85
commit ad4eea6ba7
12 changed files with 101 additions and 43 deletions

View File

@ -193,6 +193,8 @@ function startListening() {
client.session = {};
}
client.session.serverType = moduleInst.getServerType();
clientConns.addNewClient(client, clientSock);
client.on('ready', function onClientReady() {

View File

@ -425,7 +425,15 @@ Client.prototype.end = function () {
clearInterval(this.idleCheck);
try {
//
// We can end up calling 'end' before TTY/etc. is established, e.g. with SSH
//
// :TODO: is this OK?
return this.output.end.apply(this.output, arguments);
} catch(e) {
// TypeError
}
};
Client.prototype.destroy = function () {

View File

@ -20,7 +20,10 @@ function addNewClient(client, clientSock) {
// Create a client specific logger
client.log = logger.log.child( { clientId : id } );
var connInfo = { ip : clientSock.remoteAddress };
var connInfo = {
ip : clientSock.remoteAddress,
serverType : client.session.serverType,
};
if(client.log.debug()) {
connInfo.port = clientSock.localPort;

View File

@ -74,6 +74,17 @@ function ClientTerminal(output) {
// SCREEN
// * ConnectBot
//
// syncterm
// *
//
// Reports from various terminals
// SyncTERM
// * syncterm
//
// PuTTY
// * xterm
//
//
if(this.isANSI()) {
this.outputEncoding = 'cp437';
} else {
@ -125,7 +136,7 @@ function ClientTerminal(output) {
ClientTerminal.prototype.isANSI = function() {
// :TODO: Others??
return [ 'ansi', 'pc-ansi', 'qansi', 'scoansi' ].indexOf(this.termType) > -1;
return [ 'ansi', 'pc-ansi', 'qansi', 'scoansi', 'syncterm' ].indexOf(this.termType) > -1;
};
// :TODO: probably need to update these to convert IAC (0xff) -> IACIAC (escape it)

View File

@ -61,6 +61,8 @@ function getDefaultConfig() {
return {
general : {
boardName : 'Another Fine ENiGMA½ BBS',
loginAttempts : 3,
},
firstMenu : 'connected',

View File

@ -54,6 +54,7 @@ function getPredefinedMCIValue(client, code) {
UC : function loginCount() { return client.user.properties.login_count.toString(); },
ND : function connectedNode() { return client.node.toString(); },
IP : function clientIpAddress() { return client.address().address; },
ST : function serverType() { return client.session.serverType; },
MS : function accountCreated() { return moment(client.user.properties.account_created).format(client.currentTheme.helpers.getDateFormat()); },
CS : function currentStatus() { return client.currentStatus; },

View File

@ -12,5 +12,7 @@ function ServerModule() {
require('util').inherits(ServerModule, PluginModule);
ServerModule.prototype.createServer = function() {
return null;
};
ServerModule.prototype.getServerType = function() {
};

View File

@ -40,29 +40,36 @@ function SSHClient(clientConn) {
var self = this;
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 || '';
if(0 === username.length > 0 && password.length > 0) {
function termConnection() {
ctx.reject();
clientConn.end();
}
if(username.length > 0 && password.length > 0) {
loginAttempts += 1;
userLogin(self, ctx.username, ctx.password, function authResult(err) {
if(err) {
if(err.existingConn) {
// :TODO: Can we display somthing here?
ctx.reject();
clientConn.end();
termConnection();
return;
}
} else {
ctx.accept();
}
});
}
if('keyboard-interactive' !== ctx.method) {
return ctx.reject( ['keyboard-interactive'] );
} else {
if(-1 === SSHClient.ValidAuthMethods.indexOf(ctx.method)) {
return ctx.reject(SSHClient.ValidAuthMethods);
}
if(0 === username.length) {
@ -73,21 +80,28 @@ function SSHClient(clientConn) {
var interactivePrompt = { prompt: ctx.username + '\'s password: ', echo : false };
ctx.prompt(interactivePrompt, function retryPrompt(answers) {
loginAttempts += 1;
userLogin(self, username, (answers[0] || ''), function authResult(err) {
if(err) {
if(err.existingConn) {
// :TODO: can we display something here?
ctx.reject();
clientConn.end();
termConnection();
} else {
interactivePrompt.prompt = 'Access denied\n' + ctx.username + '\'s password: ';
if(loginAttempts >= conf.config.general.loginAttempts) {
termConnection();
} else {
interactivePrompt.prompt = 'Access denied\n' + interactivePrompt.prompt;
return ctx.prompt(interactivePrompt, retryPrompt);
}
}
} else {
ctx.accept();
}
});
});
}
});
this.updateTermInfo = function(info) {
@ -125,14 +139,16 @@ function SSHClient(clientConn) {
clientConn.once('ready', function clientReady() {
self.log.info('SSH authentication success');
clientConn.once('session', function sess(accept, reject) {
clientConn.on('session', function sess(accept, reject) {
var session = accept();
session.once('pty', function pty(accept, reject, info) {
session.on('pty', function pty(accept, reject, info) {
self.log.debug(info, 'SSH pty event');
if(_.isFunction(accept)) {
accept();
}
if(self.input) { // do we have I/O?
self.updateTermInfo(info);
@ -141,7 +157,7 @@ function SSHClient(clientConn) {
}
});
session.once('shell', function shell(accept, reject) {
session.on('shell', function shell(accept, reject) {
self.log.debug('SSH shell event');
var channel = accept();
@ -164,6 +180,8 @@ function SSHClient(clientConn) {
session.on('window-change', function windowChange(accept, reject, info) {
self.log.debug(info, 'SSH window-change event');
console.log('window-change: ' + accept)
self.updateTermInfo(info);
});
@ -175,13 +193,14 @@ function SSHClient(clientConn) {
});
clientConn.on('error', function connError(err) {
// :TODO: what to do here?
console.log(err)
self.log.warn( { error : err.toString(), code : err.code }, 'SSH connection error');
});
}
util.inherits(SSHClient, baseClient.Client);
SSHClient.ValidAuthMethods = [ 'password', 'keyboard-interactive' ];
function SSHServerModule() {
ServerModule.call(this);
}
@ -213,3 +232,7 @@ SSHServerModule.prototype.createServer = function() {
return server;
};
SSHServerModule.prototype.getServerType = function() {
return 'SSH';
};

View File

@ -785,3 +785,7 @@ TelnetServerModule.prototype.createServer = function() {
return server;
};
TelnetServerModule.prototype.getServerType = function() {
return 'TELNET';
};

View File

@ -5,7 +5,7 @@ var MenuModule = require('../core/menu_module.js').MenuModule;
var userDb = require('../core/database.js').dbs.user;
var ViewController = require('../core/view_controller.js').ViewController;
var TextView = require('../core/text_view.js').TextView;
var getUserLoginHistory = require('../core/stats.js').getUserLoginHistory;
var getSystemLoginHistory = require('../core/stats.js').getSystemLoginHistory;
var util = require('util');
var moment = require('moment');
@ -92,7 +92,7 @@ LastCallersModule.prototype.mciReady = function(mciData, cb) {
});
},
function fetchHistory(callback) {
getUserLoginHistory(self.rows, function historyRetrieved(err, lh) {
getSystemLoginHistory(self.rows, function historyRetrieved(err, lh) {
loginHistory = lh;
callback(err);
});

View File

@ -75,6 +75,7 @@
UG5: { width: 17 }
UT6: { width: 17 }
UC7: { width: 17 }
ST8: { width: 17 }
}
}
@ -233,6 +234,7 @@
UG5: { width: 17 }
UT6: { width: 17 }
UC7: { width: 17 }
ST8: { width: 17 }
}
}
}