2015-04-21 05:24:15 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-06-26 04:43:12 +00:00
|
|
|
// ENiGMA½
|
|
|
|
const removeClient = require('./client_connections.js').removeClient;
|
|
|
|
const ansiNormal = require('./ansi_term.js').normal;
|
|
|
|
const userLogin = require('./user_login.js').userLogin;
|
2015-04-21 05:24:15 +00:00
|
|
|
|
2016-06-26 04:43:12 +00:00
|
|
|
// deps
|
|
|
|
const _ = require('lodash');
|
|
|
|
const iconv = require('iconv-lite');
|
2015-04-21 05:24:15 +00:00
|
|
|
|
2015-08-05 04:35:59 +00:00
|
|
|
exports.login = login;
|
|
|
|
exports.logoff = logoff;
|
2015-11-04 06:15:49 +00:00
|
|
|
exports.prevMenu = prevMenu;
|
2016-06-26 04:43:12 +00:00
|
|
|
exports.nextMenu = nextMenu;
|
2015-04-21 05:24:15 +00:00
|
|
|
|
2016-06-26 04:43:12 +00:00
|
|
|
function login(callingMenu, formData) {
|
2015-04-21 05:24:15 +00:00
|
|
|
|
2016-06-26 04:43:12 +00:00
|
|
|
userLogin(callingMenu.client, formData.value.username, formData.value.password, err => {
|
2015-04-21 05:24:15 +00:00
|
|
|
if(err) {
|
2015-10-19 23:21:47 +00:00
|
|
|
// login failure
|
2015-12-07 03:54:23 +00:00
|
|
|
if(err.existingConn && _.has(callingMenu, 'menuConfig.config.tooNodeMenu')) {
|
|
|
|
callingMenu.gotoMenu(callingMenu.menuConfig.config.tooNodeMenu);
|
2015-10-19 23:21:47 +00:00
|
|
|
} else {
|
|
|
|
// Other error
|
2015-11-04 06:25:35 +00:00
|
|
|
callingMenu.prevMenu();
|
2015-08-05 04:35:59 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 23:21:47 +00:00
|
|
|
} else {
|
|
|
|
// success!
|
2015-11-04 06:15:49 +00:00
|
|
|
callingMenu.nextMenu();
|
2015-04-21 05:24:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-26 04:43:12 +00:00
|
|
|
function logoff(callingMenu) {
|
2015-08-05 04:35:59 +00:00
|
|
|
//
|
|
|
|
// Simple logoff. Note that recording of @ logoff properties/stats
|
|
|
|
// occurs elsewhere!
|
|
|
|
//
|
2016-06-26 04:43:12 +00:00
|
|
|
const client = callingMenu.client;
|
2015-04-21 05:24:15 +00:00
|
|
|
|
2016-06-26 04:43:12 +00:00
|
|
|
setTimeout( () => {
|
2015-08-21 19:47:01 +00:00
|
|
|
//
|
|
|
|
// For giggles...
|
|
|
|
//
|
|
|
|
client.term.write(
|
2016-06-26 04:43:12 +00:00
|
|
|
ansiNormal() + '\n' +
|
2015-11-01 20:55:59 +00:00
|
|
|
iconv.decode(require('crypto').randomBytes(Math.floor(Math.random() * 65) + 20), client.term.outputEncoding) +
|
2016-06-26 04:43:12 +00:00
|
|
|
'NO CARRIER', null, () => {
|
2015-08-21 19:47:01 +00:00
|
|
|
|
2016-01-02 19:10:54 +00:00
|
|
|
// after data is written, disconnect & remove the client
|
2016-06-26 04:43:12 +00:00
|
|
|
return removeClient(client);
|
|
|
|
}
|
|
|
|
);
|
2015-04-21 05:24:15 +00:00
|
|
|
}, 500);
|
2015-09-24 04:24:37 +00:00
|
|
|
}
|
|
|
|
|
2016-06-26 04:43:12 +00:00
|
|
|
function prevMenu(callingMenu) {
|
|
|
|
callingMenu.prevMenu( err => {
|
2015-09-24 04:24:37 +00:00
|
|
|
if(err) {
|
2015-11-04 06:15:49 +00:00
|
|
|
callingMenu.client.log.error( { error : err.toString() }, 'Error attempting to fallback!');
|
2015-09-24 04:24:37 +00:00
|
|
|
}
|
|
|
|
});
|
2015-09-24 05:41:06 +00:00
|
|
|
}
|
2016-06-26 04:43:12 +00:00
|
|
|
|
|
|
|
function nextMenu(callingMenu) {
|
|
|
|
callingMenu.nextMenu( err => {
|
|
|
|
if(err) {
|
|
|
|
callingMenu.client.log.error( { error : err.toString() }, 'Error attempting to go to next menu!');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|