* WIP on SSH2 access: Linux ssh can now connect, browse, etc.
* Still issues with other terminals such as EtherTERM which just hangs after auth. Does not seem to send the 'shell' event * Fix typo in msg_list module
This commit is contained in:
parent
0f1fe31fe5
commit
6a2d283fad
|
@ -13,6 +13,7 @@ var ssh2 = require('ssh2');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
exports.moduleInfo = {
|
exports.moduleInfo = {
|
||||||
name : 'SSH',
|
name : 'SSH',
|
||||||
|
@ -52,6 +53,22 @@ function SSHClient(clientConn) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
this.userLoginWithCredentials = function(username, password, ctx) {
|
||||||
|
userLogin(self, ctx.username, ctx.password, function authResult(err) {
|
||||||
|
if(err) {
|
||||||
|
if(err.existingConn) {
|
||||||
|
// :TODO: Already logged in - how to let the SSH client know?
|
||||||
|
//self.term.write('User already logged in');
|
||||||
|
ctx.reject();
|
||||||
|
} else {
|
||||||
|
ctx.reject();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.accept();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
clientConn.on('authentication', function authentication(ctx) {
|
clientConn.on('authentication', function authentication(ctx) {
|
||||||
self.log.trace(
|
self.log.trace(
|
||||||
{
|
{
|
||||||
|
@ -65,13 +82,7 @@ function SSHClient(clientConn) {
|
||||||
switch(ctx.method) {
|
switch(ctx.method) {
|
||||||
case 'password' :
|
case 'password' :
|
||||||
// :TODO: Proper userLogin() here
|
// :TODO: Proper userLogin() here
|
||||||
self.user.authenticate(ctx.username, ctx.password, self, function authResult(err) {
|
self.userLoginWithCredentials(ctx.username, ctx.password, ctx);
|
||||||
if(err) {
|
|
||||||
ctx.reject();
|
|
||||||
} else {
|
|
||||||
ctx.accept();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'publickey' :
|
case 'publickey' :
|
||||||
|
@ -110,11 +121,48 @@ function SSHClient(clientConn) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default :
|
default :
|
||||||
self.log.info( { method : ctx.method }, 'Unsupported SSH authentication method');
|
//
|
||||||
ctx.reject();
|
// Some terminals such as EtherTERM send a 'none' auth type, but include
|
||||||
|
// a username and password. For now, allow this. This should be looked
|
||||||
|
// into further as it may be a security issue!
|
||||||
|
//
|
||||||
|
if('none' === ctx.method && _.isString(ctx.username) && _.isString(ctx.password)) {
|
||||||
|
self.log.warn('Attempting authentication with \'none\' method');
|
||||||
|
|
||||||
|
self.userLoginWithCredentials(ctx.username, ctx.password, ctx);
|
||||||
|
} else {
|
||||||
|
self.log.warn( { method : ctx.method }, 'Unsupported SSH authentication method');
|
||||||
|
ctx.reject( [ 'password', 'keyboard-interactive' ] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.updateTermInfo = function(info) {
|
||||||
|
//
|
||||||
|
// From ssh2 docs:
|
||||||
|
// "rows and cols override width and height when rows and cols are non-zero."
|
||||||
|
//
|
||||||
|
var termHeight = 24;
|
||||||
|
var termWidth = 80;
|
||||||
|
|
||||||
|
if(info.rows > 0 && info.cols > 0) {
|
||||||
|
termHeight = info.rows;
|
||||||
|
termWidth = info.cols;
|
||||||
|
} else if(info.width > 0 && info.height > 0) {
|
||||||
|
termHeight = info.height;
|
||||||
|
termWidth = info.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(_.isObject(self.term));
|
||||||
|
|
||||||
|
self.term.termHeight = termHeight;
|
||||||
|
self.term.termWidth = termWidth;
|
||||||
|
|
||||||
|
if(_.isString(info.term) && info.term.length > 0 && 'unknown' === self.term.termType) {
|
||||||
|
self.setTermType(info.term);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
clientConn.on('ready', function clientReady() {
|
clientConn.on('ready', function clientReady() {
|
||||||
self.log.info('SSH authentication success');
|
self.log.info('SSH authentication success');
|
||||||
|
|
||||||
|
@ -123,20 +171,38 @@ function SSHClient(clientConn) {
|
||||||
var session = accept();
|
var session = accept();
|
||||||
|
|
||||||
session.on('pty', function pty(accept, reject, info) {
|
session.on('pty', function pty(accept, reject, info) {
|
||||||
console.log(info);
|
self.log.debug(info, 'SSH pty event');
|
||||||
var channel = accept();
|
|
||||||
console.log(channel)
|
|
||||||
|
|
||||||
|
if(self.input) { // do we have I/O?
|
||||||
|
self.updateTermInfo(info);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
session.on('shell', function shell(accept, reject) {
|
session.on('shell', function shell(accept, reject) {
|
||||||
|
self.log.debug('SSH shell event');
|
||||||
|
|
||||||
var channel = accept();
|
var channel = accept();
|
||||||
|
|
||||||
self.setInputOutput(channel.stdin, channel.stdout);
|
self.setInputOutput(channel.stdin, channel.stdout);
|
||||||
|
|
||||||
|
channel.stdin.on('data', function clientData(data) {
|
||||||
|
self.emit('data', data);
|
||||||
|
});
|
||||||
|
|
||||||
self.emit('ready')
|
self.emit('ready')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
session.on('subsystem', function subsystem(accept, reject, info) {
|
||||||
|
console.log('subsystem')
|
||||||
|
console.log(info)
|
||||||
|
});
|
||||||
|
|
||||||
|
session.on('window-change', function windowChange(accept, reject, info) {
|
||||||
|
self.log.debug(info, 'SSH window-change event');
|
||||||
|
|
||||||
|
self.updateTermInfo(info);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -158,8 +224,8 @@ SSHServerModule.prototype.createServer = function() {
|
||||||
|
|
||||||
var serverConf = {
|
var serverConf = {
|
||||||
privateKey : fs.readFileSync(conf.config.servers.ssh.rsaPrivateKey),
|
privateKey : fs.readFileSync(conf.config.servers.ssh.rsaPrivateKey),
|
||||||
banner : 'ENiGMA½ BBS ' + enigVersion + ' SSH Server',
|
|
||||||
ident : 'enigma-bbs-' + enigVersion + '-srv',
|
ident : 'enigma-bbs-' + enigVersion + '-srv',
|
||||||
|
// Note that sending 'banner' breaks at least EtherTerm!
|
||||||
debug : function debugSsh(dbgLine) {
|
debug : function debugSsh(dbgLine) {
|
||||||
if(true === conf.config.servers.ssh.debugConnections) {
|
if(true === conf.config.servers.ssh.debugConnections) {
|
||||||
Log.trace('SSH: ' + dbgLine);
|
Log.trace('SSH: ' + dbgLine);
|
||||||
|
|
|
@ -149,7 +149,7 @@ MessageListModule.prototype.mciReady = function(mciData, cb) {
|
||||||
msgNum = 1;
|
msgNum = 1;
|
||||||
msgListView.setFocusItems(_.map(self.messageList, function formatMsgListEntry(mle) {
|
msgListView.setFocusItems(_.map(self.messageList, function formatMsgListEntry(mle) {
|
||||||
return focusListFormat.format(getMsgFmtObj(mle));
|
return focusListFormat.format(getMsgFmtObj(mle));
|
||||||
});
|
}));
|
||||||
|
|
||||||
msgListView.on('index update', function indexUpdated(idx) {
|
msgListView.on('index update', function indexUpdated(idx) {
|
||||||
self.setViewText(MciCodesIds.MsgSelNum, (idx + 1).toString());
|
self.setViewText(MciCodesIds.MsgSelNum, (idx + 1).toString());
|
||||||
|
|
Loading…
Reference in New Issue