mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-08 13:44:39 +02:00
* Separate login logic vs display
* Work on SSH a bit -- major WIP, not working!
This commit is contained in:
parent
a6f15c2dfc
commit
d86d3e0119
4 changed files with 204 additions and 136 deletions
|
@ -4,12 +4,14 @@
|
|||
// ENiGMA½
|
||||
var conf = require('../config.js');
|
||||
var baseClient = require('../client.js');
|
||||
var user = require('../user.js');
|
||||
var Log = require('../logger.js').log;
|
||||
var ServerModule = require('../server_module.js').ServerModule;
|
||||
var userLogin = require('../user_login.js').userLogin;
|
||||
|
||||
var ssh2 = require('ssh2');
|
||||
var fs = require('fs');
|
||||
var util = require('util');
|
||||
var _ = require('lodash');
|
||||
|
||||
exports.moduleInfo = {
|
||||
name : 'SSH',
|
||||
|
@ -19,50 +21,84 @@ exports.moduleInfo = {
|
|||
|
||||
exports.getModule = SSHServerModule;
|
||||
|
||||
function SSHClient(input, output) {
|
||||
function SSHClient(clientConn) {
|
||||
baseClient.Client.apply(this, arguments);
|
||||
|
||||
//
|
||||
// WARNING: Until we have emit 'ready', self.input, and self.output and
|
||||
// not yet defined!
|
||||
//
|
||||
|
||||
var self = this;
|
||||
|
||||
this.input.on('authentication', function onAuthentication(ctx) {
|
||||
console.log('auth: ' + ctx.method);
|
||||
clientConn.on('authentication', function authentication(ctx) {
|
||||
self.log.trace( { context : ctx }, 'SSH authentication');
|
||||
|
||||
if('password' === ctx.method) {
|
||||
// :TODO: Log attempts
|
||||
user.authenticate(ctx.username, ctx.password, self, function onAuthResult(err) {
|
||||
if(err) {
|
||||
ctx.reject();
|
||||
} else {
|
||||
ctx.accept();
|
||||
// :TODO: check Config max failed logon attempts/etc.
|
||||
|
||||
switch(ctx.method) {
|
||||
case 'password' :
|
||||
// :TODO: Proper userLogin() here
|
||||
self.user.authenticate(ctx.username, ctx.password, self, function authResult(err) {
|
||||
if(err) {
|
||||
ctx.reject();
|
||||
} else {
|
||||
ctx.accept();
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case 'publickey' :
|
||||
// :TODO:
|
||||
ctx.reject();
|
||||
break;
|
||||
|
||||
case 'keyboard-interactive' :
|
||||
if(!_.isString(ctx.username)) {
|
||||
// :TODO: Let client know a username is required!
|
||||
ctx.reject()
|
||||
}
|
||||
});
|
||||
} else if('publickey' === ctx.method) {
|
||||
console.log('pub key path');
|
||||
} else if('keyboard-interactive' === ctx.method) {
|
||||
ctx.reject(['password']);
|
||||
// :TODO: support this. Allow users to generate a key for use or w/e
|
||||
|
||||
/*} else if('keyboard-interactive' === ctx.method) {
|
||||
console.log(ctx.submethods); // :TODO: proper logging; handle known types, etc.
|
||||
|
||||
ctx.prompt([ { prompt : 'Password: ', echo : false } ], function onPromptResponses(err, responses) {
|
||||
console.log(err);
|
||||
console.log(responses);
|
||||
});*/
|
||||
} else {
|
||||
ctx.reject();
|
||||
var PASS_PROMPT = { prompt : 'Password: ', echo : false };
|
||||
|
||||
ctx.prompt(PASS_PROMPT, function promptResponse(responses) {
|
||||
if(0 === responses.length) {
|
||||
return ctx.reject( ['keyboard-interactive'] );
|
||||
}
|
||||
|
||||
userLogin(self, ctx.username, responses[0], 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 {
|
||||
PASS_PROMPT.prompt = 'Invalid username or password\nPassword: ';
|
||||
ctx.prompt(PASS_PROMPT, promptResponse);
|
||||
}
|
||||
} else {
|
||||
ctx.accept();
|
||||
}
|
||||
});
|
||||
});
|
||||
break;
|
||||
|
||||
default :
|
||||
self.log.info( { method : ctx.method }, 'Unsupported SSH authentication method. Rejecting connection.');
|
||||
ctx.reject();
|
||||
}
|
||||
});
|
||||
|
||||
this.input.on('ready', function onReady() {
|
||||
console.log('Client authenticated');
|
||||
|
||||
self.input.on('session', function onSession(accept, reject) {
|
||||
clientConn.on('ready', function clientReady() {
|
||||
self.log.info('SSH authentication success');
|
||||
|
||||
clientConn.on('session', function sess(accept, reject) {
|
||||
self.input = accept();
|
||||
self.output = self.input;
|
||||
});
|
||||
});
|
||||
|
||||
this.input.on('end', function onEnd() {
|
||||
clientConn.on('end', function clientEnd() {
|
||||
self.emit('end');
|
||||
});
|
||||
}
|
||||
|
@ -80,15 +116,20 @@ SSHServerModule.prototype.createServer = function() {
|
|||
|
||||
// :TODO: setup all options here. What should the banner, etc. really be????
|
||||
var serverConf = {
|
||||
privateKey : fs.readFileSync(conf.config.servers.ssh.rsaPrivateKey),
|
||||
banner : 'ENiGMA½ BBS SSH Server',
|
||||
debug : function onDebug(s) { console.log(s); }
|
||||
privateKey : fs.readFileSync(conf.config.servers.ssh.rsaPrivateKey),
|
||||
banner : 'ENiGMA½ BBS SSH Server',
|
||||
debug : function debugSsh(dbgLine) {
|
||||
if(true === conf.config.servers.ssh.debugConnections) {
|
||||
self.log.trace('SSH: ' + dbgLine);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var server = ssh2.Server(serverConf);
|
||||
server.on('connection', function onConnection(conn, info) {
|
||||
console.log(info); // :TODO: Proper logging
|
||||
var client = new SSHClient(conn, conn);
|
||||
Log.info(info, 'New SSH connection');
|
||||
|
||||
var client = new SSHClient(conn);
|
||||
this.emit('client', client);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue