diff --git a/core/client.js b/core/client.js index cb6c805a..149c8725 100644 --- a/core/client.js +++ b/core/client.js @@ -11,6 +11,7 @@ var logger = require('./logger.js'); // :TODO: cleanup and just use Log. var Log = require('./logger.js').log; var user = require('./user.js'); var moduleUtil = require('./module_util.js'); +var menuUtil = require('./menu_util.js'); exports.Client = Client; @@ -196,19 +197,16 @@ Client.prototype.gotoMenuModule = function(name, cb) { self.currentMenuModule.leave(); } - moduleUtil.loadModule(name, 'mods', function onModuleLoaded(err, mod) { + menuUtil.loadMenu(name, self, function onMenuModuleLoaded(err, modInst) { if(err) { cb(err); } else { - try { - Log.debug({ moduleName : name }, 'Goto menu module'); - var modInst = new mod.getModule(); - modInst.enter(self); + // :TODO: log module info not just menu!! + Log.debug({ menuName : name }, 'Goto menu module'); - self.currentMenuModule = modInst; - } catch(e) { - cb(e); - } + modInst.enter(self); + + self.currentMenuModule = modInst; } }); }; diff --git a/core/config.js b/core/config.js index e41c36b9..5dd608b8 100644 --- a/core/config.js +++ b/core/config.js @@ -43,7 +43,7 @@ module.exports = { }, ssh : { port : 8889, - enabled : false, + enabled : true, rsaPrivateKey : paths.join(__dirname, './../misc/default_key.rsa'), dsaPrivateKey : paths.join(__dirname, './../misc/default_key.dsa'), } diff --git a/core/menu_module.js b/core/menu_module.js index 89636b9b..23fda989 100644 --- a/core/menu_module.js +++ b/core/menu_module.js @@ -1,20 +1,53 @@ /* jslint node: true */ 'use strict'; -var PluginModule = require('./plugin_module.js').PluginModule; +var PluginModule = require('./plugin_module.js').PluginModule; +var theme = require('./theme.js'); + +var async = require('async'); +var assert = require('assert'); exports.MenuModule = MenuModule; -function MenuModule() { +function MenuModule(menuConfig) { PluginModule.call(this); - this.viewControllers = []; + var self = this; + this.menuConfig = menuConfig; + + this.viewControllers = []; + + this.loadArt = function() { + async.waterfall( + [ + function displayArt(callback) { + console.log(self.menuConfig) + theme.displayThemeArt(self.menuConfig.art, self.client, function onArt(err, mciMap) { + callback(err, mciMap); + }); + }, + function artDisplayed(mciMap, callback) { + if(!mciMap) { + callback(null); + } else { + self.mciReady(mciMap); + } + } + ], + function onComplete(err) { + if(err) { + // :TODO: Log me!!! ... and what else? + } + } + ); + }; } require('util').inherits(MenuModule, PluginModule); MenuModule.prototype.enter = function(client) { - + this.client = client; + assert(typeof client !== 'undefined'); }; MenuModule.prototype.leave = function() { @@ -25,5 +58,8 @@ MenuModule.prototype.leave = function() { MenuModule.prototype.addViewController = function(vc) { this.viewControllers.push(vc); - return vc; // allow var vc = this.addViewController(new ViewController(...)); + return vc; +}; + +MenuModule.prototype.mciReady = function(mciMap) { }; \ No newline at end of file diff --git a/core/menu_util.js b/core/menu_util.js new file mode 100644 index 00000000..2f3838a8 --- /dev/null +++ b/core/menu_util.js @@ -0,0 +1,38 @@ +/* jslint node: true */ +'use strict'; + +var moduleUtil = require('./module_util.js'); +var theme = require('./theme.js'); +var async = require('async'); + +var menuJson = require('../mods/menu.json'); + +exports.loadMenu = loadMenu; + +function loadMenu(name, client, cb) { + // want client.loadMenu(...). Replace current "goto module"/etc. with "switchMenu(...)" + // load options/etc -> call menuModule.enter(client, options) + + /* + * Ensure JSON section exists + * check access / ACS + * + * ...MenuModule(menuSection) ... .enter(client) + */ + + if('object' !== typeof menuJson[name] || null === menuJson[name]) { + cb(new Error('No menu by the name of \'' + name + '\'')); + return; + } + + var menuConfig = menuJson[name]; + + moduleUtil.loadModule(menuConfig.module || 'standard_menu', 'mods', function onModule(err, mod) { + if(err) { + cb(err); + } else { + var modInst = new mod.getModule(menuConfig); + cb(null, modInst); + } + }); +} \ No newline at end of file diff --git a/core/server_module.js b/core/server_module.js index f754844b..f4e6a8b5 100644 --- a/core/server_module.js +++ b/core/server_module.js @@ -7,13 +7,10 @@ exports.ServerModule = ServerModule; function ServerModule() { PluginModule.call(this); - - this.viewControllers = []; } require('util').inherits(ServerModule, PluginModule); ServerModule.prototype.createServer = function() { - console.log('ServerModule createServer') return null; }; \ No newline at end of file diff --git a/core/servers/ssh.js b/core/servers/ssh.js index 8c1e0900..88a3d1db 100644 --- a/core/servers/ssh.js +++ b/core/servers/ssh.js @@ -2,12 +2,14 @@ 'use strict'; // ENiGMA½ -var conf = require('../config.js'); -var baseClient = require('../client.js'); -var user = require('../user.js'); +var conf = require('../config.js'); +var baseClient = require('../client.js'); +var user = require('../user.js'); +var ServerModule = require('../server_module.js').ServerModule; var ssh2 = require('ssh2'); var fs = require('fs'); +var util = require('util'); exports.moduleInfo = { name : 'SSH', @@ -15,7 +17,7 @@ exports.moduleInfo = { author : 'NuSkooler' }; -exports.createServer = createServer; +exports.getModule = SSHServerModule; function SSHClient(input, output) { baseClient.Client.apply(this, arguments); @@ -65,9 +67,17 @@ function SSHClient(input, output) { }); } -require('util').inherits(SSHClient, baseClient.Client); +util.inherits(SSHClient, baseClient.Client); + +function SSHServerModule() { + ServerModule.call(this); +} + +util.inherits(SSHServerModule, ServerModule); + +SSHServerModule.prototype.createServer = function() { + SSHServerModule.super_.prototype.createServer.call(this); -function createServer() { // :TODO: setup all options here. What should the banner, etc. really be???? var serverConf = { privateKey : fs.readFileSync(conf.config.servers.ssh.rsaPrivateKey), @@ -83,4 +93,4 @@ function createServer() { }); return server; -} +}; \ No newline at end of file diff --git a/core/servers/telnet.js b/core/servers/telnet.js index 109f08ef..6ff7de81 100644 --- a/core/servers/telnet.js +++ b/core/servers/telnet.js @@ -735,14 +735,12 @@ function createServer() { */ function TelnetServerModule() { - console.log('TelnetServerModule') ServerModule.call(this); } util.inherits(TelnetServerModule, ServerModule); TelnetServerModule.prototype.createServer = function() { - console.log('TelnetServerModule createServer') TelnetServerModule.super_.prototype.createServer.call(this); var server = net.createServer(function onConnection(sock) { diff --git a/mods/matrix.js b/mods/matrix.js index a68a9d85..a441c7b8 100644 --- a/mods/matrix.js +++ b/mods/matrix.js @@ -24,20 +24,25 @@ exports.moduleInfo = { exports.getModule = MatrixModule; -function MatrixModule() { - MenuModule.call(this); +function MatrixModule(menuConfig) { + MenuModule.call(this, menuConfig); } require('util').inherits(MatrixModule, MenuModule); MatrixModule.prototype.enter = function(client) { - MatrixModule.super_.prototype.enter.call(this); - - var self = this; + MatrixModule.super_.prototype.enter.call(this, client); client.term.write(ansi.resetScreen()); //client.term.write('\x1b[?33h'); + this.loadArt(); + + /* + + var self = this; + + theme.displayThemeArt('MATRIX', client, function onMatrix(err, mciMap) { console.log(mciMap); if(mciMap.ET1 && mciMap.ET2 && mciMap.BN1 && mciMap.BN2 && mciMap.BN3) { @@ -73,8 +78,47 @@ MatrixModule.prototype.enter = function(client) { vc.switchFocus(1); } }); +*/ }; +MatrixModule.prototype.mciReady = function(mciMap) { + MatrixModule.super_.prototype.mciReady.call(this, mciMap); + + var self = this; + + if(mciMap.ET1 && mciMap.ET2 && mciMap.BN1 && mciMap.BN2 && mciMap.BN3) { + // + // Form via EditTextViews and ButtonViews + // * ET1 - userName + // * ET2 - password + // * BN1 - Login + // * BN2 - New + // * BN3 - Bye! + // + } else if(mciMap.VM1) { + // + // Menu via VerticalMenuView + // + // * VM1 - menu with the following items: + // 0 - Login + // 1 - New + // 2 - Bye! + // + //var vc = new ViewController(client); + var vc = self.addViewController(new ViewController(self.client)); + + vc.on('submit', function onSubmit(form) { + console.log(form); + }); + + vc.loadFromMCIMap(mciMap); + vc.setViewOrder(); + // :TODO: Localize + vc.getView(1).setItems(['Login', 'New User', 'Goodbye!']); + vc.getView(1).submit = true; + vc.switchFocus(1); + } +}; /* function entryPoint(client) {