* System stats

* Last callers rewritten using format and VM
* Some minor MCI stuff
This commit is contained in:
Bryan Ashby 2015-10-17 20:03:51 -06:00
parent d02d9e4a7c
commit 1c1f4394ca
15 changed files with 126 additions and 39 deletions

View File

@ -107,6 +107,9 @@ function initialize(cb) {
database.initializeDatabases(); database.initializeDatabases();
callback(null); callback(null);
}, },
function initSystemProperties(callback) {
require('./system_property.js').loadSystemProperties(callback);
},
function initThemes(callback) { function initThemes(callback) {
// Have to pull in here so it's after Config init // Have to pull in here so it's after Config init
var theme = require('./theme.js'); var theme = require('./theme.js');

View File

@ -3,12 +3,17 @@
var logger = require('./logger.js'); var logger = require('./logger.js');
exports.getActiveConnections = getActiveConnections;
exports.addNewClient = addNewClient; exports.addNewClient = addNewClient;
exports.removeClient = removeClient; exports.removeClient = removeClient;
var clientConnections = []; var clientConnections = [];
exports.clientConnections = clientConnections; exports.clientConnections = clientConnections;
function getActiveConnections() {
return clientConnections.length;
}
function addNewClient(client) { function addNewClient(client) {
var id = client.session.id = clientConnections.push(client) - 1; var id = client.session.id = clientConnections.push(client) - 1;

View File

@ -17,11 +17,13 @@ function getDatabasePath(name) {
} }
function initializeDatabases() { function initializeDatabases() {
// :TODO: this will need to change if more DB's are added // :TODO: this will need to change if more DB's are added ... why?
dbs.user = new sqlite3.Database(getDatabasePath('user')); dbs.user = new sqlite3.Database(getDatabasePath('user'));
dbs.message = new sqlite3.Database(getDatabasePath('message')); dbs.message = new sqlite3.Database(getDatabasePath('message'));
dbs.system = new sqlite3.Database(getDatabasePath('system'));
dbs.user.serialize(function serialized() { dbs.user.serialize(function serialized() {
createSystemTables();
createUserTables(); createUserTables();
createInitialUserValues(); createInitialUserValues();
}); });
@ -32,6 +34,15 @@ function initializeDatabases() {
}); });
} }
function createSystemTables() {
dbs.system.run(
'CREATE TABLE IF NOT EXISTS system_property (' +
' prop_name VARCHAR PRIMARY KEY NOT NULL,' +
' prop_value VARCHAR NOT NULL' +
');'
);
}
function createUserTables() { function createUserTables() {
dbs.user.run( dbs.user.run(
'CREATE TABLE IF NOT EXISTS user (' + 'CREATE TABLE IF NOT EXISTS user (' +

View File

@ -36,7 +36,7 @@ MCIViewFactory.UserViewCodes = [
'XY', 'XY',
]; ];
MCIViewFactory.prototype.createFromMCI = function(mci) { MCIViewFactory.prototype.createFromMCI = function(mci, cb) {
assert(mci.code); assert(mci.code);
assert(mci.id > 0); assert(mci.id > 0);
assert(mci.position); assert(mci.position);
@ -54,9 +54,7 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
function setOption(pos, name) { function setOption(pos, name) {
if(mci.args.length > pos && mci.args[pos].length > 0) { if(mci.args.length > pos && mci.args[pos].length > 0) {
options[name] = mci.args[pos]; options[name] = mci.args[pos];
return true;
} }
return false;
} }
function setWidth(pos) { function setWidth(pos) {
@ -65,16 +63,13 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
options.dimens = {}; options.dimens = {};
} }
options.dimens.width = parseInt(mci.args[pos], 10); options.dimens.width = parseInt(mci.args[pos], 10);
return true;
} }
return false;
} }
function setFocusOption(pos, name) { function setFocusOption(pos, name) {
if(mci.focusArgs && mci.focusArgs.length > pos && mci.focusArgs[pos].length > 0) { if(mci.focusArgs && mci.focusArgs.length > pos && mci.focusArgs[pos].length > 0) {
options[name] = mci.focusArgs[pos]; options[name] = mci.focusArgs[pos];
} }
return false;
} }
// //

View File

@ -22,7 +22,15 @@ function getAvailableMessageAreas() {
} }
function getDefaultMessageArea() { function getDefaultMessageArea() {
return getAvailableMessageAreas()[0]; //
// Return first non-private/etc. area name. This will be from config.hjson
//
var avail = getAvailableMessageAreas();
for(var i = 0; i < avail.length; ++i) {
if(Message.WellKnownAreaNames.Private !== avail[i].name) {
return avail[i];
}
}
} }
function getMessageAreaByName(areaName) { function getMessageAreaByName(areaName) {

View File

@ -4,6 +4,8 @@
var Config = require('./config.js').config; var Config = require('./config.js').config;
var Log = require('./logger.js').log; var Log = require('./logger.js').log;
var getMessageAreaByName = require('./message_area.js').getMessageAreaByName; var getMessageAreaByName = require('./message_area.js').getMessageAreaByName;
var clientConnections = require('./client_connections.js');
var sysProp = require('./system_property.js');
var packageJson = require('../package.json'); var packageJson = require('../package.json');
var assert = require('assert'); var assert = require('assert');
@ -21,7 +23,12 @@ function getPredefinedMCIValue(client, code) {
try { try {
return { return {
//
// Board
//
BN : function boardName() { return Config.general.boardName; }, BN : function boardName() { return Config.general.boardName; },
// ENiGMA
VL : function versionLabel() { return 'ENiGMA½ v' + packageJson.version; }, VL : function versionLabel() { return 'ENiGMA½ v' + packageJson.version; },
VN : function version() { return packageJson.version; }, VN : function version() { return packageJson.version; },
@ -29,6 +36,9 @@ function getPredefinedMCIValue(client, code) {
// :TODO: SysOp real name // :TODO: SysOp real name
//
// Current user / session
//
UN : function userName() { return client.user.username; }, UN : function userName() { return client.user.username; },
UI : function userId() { return client.user.userId.toString(); }, UI : function userId() { return client.user.userId.toString(); },
UG : function groups() { return _.values(client.user.groups).join(', '); }, UG : function groups() { return _.values(client.user.groups).join(', '); },
@ -42,6 +52,8 @@ function getPredefinedMCIValue(client, code) {
UF : function affils() { return client.user.properties.affiliation; }, UF : function affils() { return client.user.properties.affiliation; },
UT : function themeId() { return client.user.properties.theme_id; }, UT : function themeId() { return client.user.properties.theme_id; },
UC : function loginCount() { return client.user.properties.login_count.toString(); }, UC : function loginCount() { return client.user.properties.login_count.toString(); },
ND : function connectedNode() { return client.node.toString(); },
IP : function clientIpAddress() { return client.address().address; },
MS : function accountCreated() { return moment(client.user.properties.account_created).format(client.currentTheme.helpers.getDateFormat()); }, MS : function accountCreated() { return moment(client.user.properties.account_created).format(client.currentTheme.helpers.getDateFormat()); },
CS : function currentStatus() { return client.currentStatus; }, CS : function currentStatus() { return client.currentStatus; },
@ -58,13 +70,16 @@ function getPredefinedMCIValue(client, code) {
SH : function termHeight() { return client.term.termHeight.toString(); }, SH : function termHeight() { return client.term.termHeight.toString(); },
SW : function termWidth() { return client.term.termWidth.toString(); }, SW : function termWidth() { return client.term.termWidth.toString(); },
ND : function connectedNode() { return client.node.toString(); }, //
// Date/Time
//
// :TODO: change to CD for 'Current Date' // :TODO: change to CD for 'Current Date'
DT : function date() { return moment().format(client.currentTheme.helpers.getDateFormat()); }, DT : function date() { return moment().format(client.currentTheme.helpers.getDateFormat()); },
CT : function time() { return moment().format(client.currentTheme.helpers.getTimeFormat()) ;}, CT : function time() { return moment().format(client.currentTheme.helpers.getTimeFormat()) ;},
//
// OS/System Info
//
OS : function operatingSystem() { OS : function operatingSystem() {
return { return {
linux : 'Linux', linux : 'Linux',
@ -78,7 +93,12 @@ function getPredefinedMCIValue(client, code) {
OA : function systemArchitecture() { return os.arch(); }, OA : function systemArchitecture() { return os.arch(); },
SC : function systemCpuModel() { return os.cpus()[0].model; }, SC : function systemCpuModel() { return os.cpus()[0].model; },
IP : function clientIpAddress() { return client.address().address; }, // :TODO: cpu load average (over N seconds): http://stackoverflow.com/questions/9565912/convert-the-output-of-os-cpus-in-node-js-to-percentage
AN : function activeNodes() { return clientConnections.getActiveConnections().toString(); },
TC : function totalCalls() { return sysProp.getSystemProperty('login_count').toString(); },
}[code](); }[code]();
} catch(e) { } catch(e) {

View File

@ -3,9 +3,7 @@
var userDb = require('./database.js').dbs.user; var userDb = require('./database.js').dbs.user;
var async = require('async'); exports.getUserLoginHistory = getUserLoginHistory;
exports.getUserLoginHistory = getUserLoginHistory;
function getUserLoginHistory(numRequested, cb) { function getUserLoginHistory(numRequested, cb) {
@ -30,4 +28,3 @@ function getUserLoginHistory(numRequested, cb) {
} }
); );
} }

View File

@ -5,6 +5,7 @@ var theme = require('./theme.js');
var clientConnections = require('./client_connections.js').clientConnections; var clientConnections = require('./client_connections.js').clientConnections;
var ansi = require('./ansi_term.js'); var ansi = require('./ansi_term.js');
var userDb = require('./database.js').dbs.user; var userDb = require('./database.js').dbs.user;
var sysProp = require('./system_property.js');
var async = require('async'); var async = require('async');
var _ = require('lodash'); var _ = require('lodash');
@ -89,6 +90,11 @@ function login(callingMenu, formData, extraArgs) {
callback(null); // always non-fatal callback(null); // always non-fatal
}); });
}, },
function updateSystemLoginCount(callback) {
var sysLoginCount = sysProp.getSystemProperty('login_count') || 0;
sysLoginCount = parseInt(sysLoginCount, 10) + 1;
sysProp.persistSystemProperty('login_count', sysLoginCount, callback);
},
function recordLastLogin(callback) { function recordLastLogin(callback) {
user.persistProperty('last_login_timestamp', now.toISOString(), function persisted(err) { user.persistProperty('last_login_timestamp', now.toISOString(), function persisted(err) {
callback(err); callback(err);
@ -106,7 +112,6 @@ function login(callingMenu, formData, extraArgs) {
}); });
}, },
function recordLoginHistory(callback) { function recordLoginHistory(callback) {
userDb.serialize(function serialized() { userDb.serialize(function serialized() {
userDb.run( userDb.run(
'INSERT INTO user_login_history (user_id, user_name, timestamp) ' + 'INSERT INTO user_login_history (user_id, user_name, timestamp) ' +

View File

@ -42,6 +42,12 @@ function UserConfigModule(options) {
} }
}; };
this.menuMethods = {
exitKeyPressed : function(formData, extraArgs) {
// :TODO: save/etc.
self.client.fallbackMenuModule();
}
};
} }
require('util').inherits(UserConfigModule, MenuModule); require('util').inherits(UserConfigModule, MenuModule);

View File

@ -172,24 +172,6 @@ function ViewController(options) {
} }
} }
break; break;
/*case 'method' :
case 'systemMethod' :
if(_.isString(actionAsset.location)) {
callModuleMenuMethod(paths.join(Config.paths.mods, actionAsset.location));
} else {
if('systemMethod' === actionAsset.type) {
// :TODO: Need to pass optional args here -- conf.extraArgs and args between e.g. ()
// :TODO: Probably better as system_method.js
callModuleMenuMethod(paths.join(__dirname, 'system_menu_method.js'));
} else {
// local to current module
var currentModule = client.currentMenuModule;
if(_.isFunction(currentModule.menuMethods[actionAsset.asset])) {
currentModule.menuMethods[actionAsset.asset](formData, conf.extraArgs);
}
}
}*/
break;
default : default :
propValue = propValue = conf[propName]; propValue = propValue = conf[propName];
@ -224,7 +206,7 @@ function ViewController(options) {
highestId = viewId; highestId = viewId;
} }
var view = self.getView(viewId); var view = self.getView(viewId);
if(!view) { if(!view) {
self.client.log.warn( { viewId : viewId }, 'Cannot find view'); self.client.log.warn( { viewId : viewId }, 'Cannot find view');
@ -573,6 +555,7 @@ ViewController.prototype.loadFromMenuConfig = function(options, cb) {
}, },
function applyThemeCustomization(callback) { function applyThemeCustomization(callback) {
formConfig = formConfig || {}; formConfig = formConfig || {};
formConfig.mci = formConfig.mci || {};
//self.client.currentMenuModule.menuConfig.config = self.client.currentMenuModule.menuConfig.config || {}; //self.client.currentMenuModule.menuConfig.config = self.client.currentMenuModule.menuConfig.config || {};
//console.log('menu config.....'); //console.log('menu config.....');

View File

@ -25,7 +25,18 @@ exports.getModule = LastCallersModule;
// :TODO: // :TODO:
// * config.evenRowSGR (optional) // * config.evenRowSGR (optional)
// :TODO: convert to using %XY system for finding row count // :TODO: convert to using %XY system for finding row count
// ..or, better, use %VM1 with listFormat and noInput
/*
Available listFormat object members:
who
location
affils
ts
*/
function LastCallersModule(options) { function LastCallersModule(options) {
MenuModule.call(this, options); MenuModule.call(this, options);

View File

@ -163,6 +163,7 @@
/* /*
nua -> send sysop mail -> { active } -> matrix nua -> send sysop mail -> { active } -> matrix
-> you must active -> matrix -> you must active -> matrix
TODO: display PRINT before this (Obv/2)
*/ */
newUserApplication: { newUserApplication: {
art: NUA art: NUA
@ -367,23 +368,28 @@
} }
} }
} }
fullLoginSequenceLoginArt: { fullLoginSequenceLoginArt: {
desc: Logging In
art: LOGIN art: LOGIN
options: { pause: true } options: { pause: true }
next: fullLoginSequenceLastCallers next: fullLoginSequenceLastCallers
} }
fullLoginSequenceLastCallers: { fullLoginSequenceLastCallers: {
desc: Last Callers
module: last_callers module: last_callers
art: LASTCALL art: LASTCALL
options: { pause: true } options: { pause: true }
next: fullLoginSequenceSysStats next: fullLoginSequenceSysStats
} }
fullLoginSequenceSysStats: { fullLoginSequenceSysStats: {
desc: System Stats
art: SYSSTAT art: SYSSTAT
options: { pause: true } options: { pause: true }
next: fullLoginSequenceUserStats next: fullLoginSequenceUserStats
} }
fullLoginSequenceUserStats: { fullLoginSequenceUserStats: {
desc: User Stats
art: STATUS art: STATUS
options: { pause: true } options: { pause: true }
next: mainMenu next: mainMenu
@ -437,6 +443,10 @@
value: { command: "C" } value: { command: "C" }
action: @menu:mainMenuUserConfig action: @menu:mainMenuUserConfig
} }
{
value: { command: "S" }
action: @menu:mainMenuSystemStats
}
{ {
"value" : 1, "value" : 1,
"action" : "@menu:mainMenu" "action" : "@menu:mainMenu"
@ -452,6 +462,10 @@
art: STATUS art: STATUS
options: { pause: true } options: { pause: true }
} }
mainMenuSystemStats: {
art: SYSSTAT
options: { pause: true }
}
mainMenuUserConfig: { mainMenuUserConfig: {
module: @systemModule:user_config module: @systemModule:user_config
art: CONFSCR art: CONFSCR
@ -479,6 +493,12 @@
argName: termSize argName: termSize
} }
} }
actionKeys: [
{
keys: [ "escape" ]
action: @method:exitKeyPressed
}
]
} }
} }
} }

Binary file not shown.

View File

@ -78,9 +78,28 @@
} }
} }
mainMenuSystemStats: {
mci: {
BN1: { width: 17 }
VL2: { width: 17 }
OS3: { width: 33 }
SC4: { width: 33 }
DT5: { width: 33 }
CT6: { width: 33 }
AN7: { width: 6 }
ND8: { width: 6 }
TC9: { width: 6 }
}
}
mainMenuLastCallers: { mainMenuLastCallers: {
config: { config: {
dateTimeFormat: MMM Do H:mm a listFormat: "|00|01|36{userName:<17.17}{location:<20.20}{affils:<18.18}{ts:<15}"
dateTimeFormat: MMM Do h:mma
}
mci: {
VM1: { height: 10 }
} }
} }
@ -181,7 +200,11 @@
fullLoginSequenceLastCallers: { fullLoginSequenceLastCallers: {
config: { config: {
dateTimeFormat: MMM Do H:mm a listFormat: "|00|01|36{userName:<17.17}{location:<20.20}{affils:<18.18}{ts:<15}"
dateTimeFormat: MMM Do h:mma
}
mci: {
VM1: { height: 10 }
} }
} }