2015-09-11 03:01:04 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-07-07 02:56:30 +00:00
|
|
|
// ENiGMA½
|
|
|
|
const Config = require('./config.js').config;
|
|
|
|
const Log = require('./logger.js').log;
|
|
|
|
const getMessageAreaByTag = require('./message_area.js').getMessageAreaByTag;
|
|
|
|
const clientConnections = require('./client_connections.js');
|
|
|
|
const sysProp = require('./system_property.js');
|
|
|
|
|
|
|
|
// deps
|
|
|
|
const packageJson = require('../package.json');
|
|
|
|
const os = require('os');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const moment = require('moment');
|
2015-09-11 03:01:04 +00:00
|
|
|
|
|
|
|
exports.getPredefinedMCIValue = getPredefinedMCIValue;
|
|
|
|
|
|
|
|
function getPredefinedMCIValue(client, code) {
|
|
|
|
|
|
|
|
if(!client || !code) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
return {
|
2015-10-18 02:03:51 +00:00
|
|
|
//
|
|
|
|
// Board
|
|
|
|
//
|
2015-09-11 14:39:25 +00:00
|
|
|
BN : function boardName() { return Config.general.boardName; },
|
2015-10-18 02:03:51 +00:00
|
|
|
|
|
|
|
// ENiGMA
|
2015-09-11 14:39:25 +00:00
|
|
|
VL : function versionLabel() { return 'ENiGMA½ v' + packageJson.version; },
|
|
|
|
VN : function version() { return packageJson.version; },
|
|
|
|
|
2015-09-24 05:41:06 +00:00
|
|
|
// :TODO: SysOp username
|
|
|
|
// :TODO: SysOp real name
|
|
|
|
|
|
|
|
|
2015-10-18 02:03:51 +00:00
|
|
|
//
|
|
|
|
// Current user / session
|
|
|
|
//
|
2015-09-11 14:39:25 +00:00
|
|
|
UN : function userName() { return client.user.username; },
|
|
|
|
UI : function userId() { return client.user.userId.toString(); },
|
|
|
|
UG : function groups() { return _.values(client.user.groups).join(', '); },
|
|
|
|
UR : function realName() { return client.user.properties.real_name; },
|
|
|
|
LO : function location() { return client.user.properties.location; },
|
|
|
|
UA : function age() { return client.user.getAge().toString(); },
|
|
|
|
UB : function birthdate() { return moment(client.user.properties.birthdate).format(client.currentTheme.helpers.getDateFormat()); },
|
|
|
|
US : function sex() { return client.user.properties.sex; },
|
|
|
|
UE : function emailAddres() { return client.user.properties.email_address; },
|
|
|
|
UW : function webAddress() { return client.user.properties.web_address; },
|
|
|
|
UF : function affils() { return client.user.properties.affiliation; },
|
|
|
|
UT : function themeId() { return client.user.properties.theme_id; },
|
|
|
|
UC : function loginCount() { return client.user.properties.login_count.toString(); },
|
2015-10-18 02:03:51 +00:00
|
|
|
ND : function connectedNode() { return client.node.toString(); },
|
|
|
|
IP : function clientIpAddress() { return client.address().address; },
|
2015-10-22 06:03:18 +00:00
|
|
|
ST : function serverName() { return client.session.serverName; },
|
2015-09-11 14:39:25 +00:00
|
|
|
|
|
|
|
MS : function accountCreated() { return moment(client.user.properties.account_created).format(client.currentTheme.helpers.getDateFormat()); },
|
|
|
|
CS : function currentStatus() { return client.currentStatus; },
|
2015-09-11 03:01:04 +00:00
|
|
|
|
|
|
|
MD : function currentMenuDescription() {
|
2015-09-11 14:39:25 +00:00
|
|
|
return _.has(client, 'currentMenuModule.menuConfig.desc') ? client.currentMenuModule.menuConfig.desc : '';
|
2015-09-11 03:01:04 +00:00
|
|
|
},
|
|
|
|
|
2016-02-03 04:35:59 +00:00
|
|
|
MA : function messageAreaName() {
|
|
|
|
const area = getMessageAreaByTag(client.user.properties.message_area_tag);
|
|
|
|
return area ? area.name : '';
|
2015-09-11 03:01:04 +00:00
|
|
|
},
|
2016-02-03 04:35:59 +00:00
|
|
|
|
2016-07-07 02:56:30 +00:00
|
|
|
ML : function messageAreaDescription() {
|
|
|
|
const area = getMessageAreaByTag(client.user.properties.message_area_tag);
|
|
|
|
return area ? area.desc : '';
|
|
|
|
},
|
2015-09-11 03:01:04 +00:00
|
|
|
|
2015-09-11 14:39:25 +00:00
|
|
|
SH : function termHeight() { return client.term.termHeight.toString(); },
|
|
|
|
SW : function termWidth() { return client.term.termWidth.toString(); },
|
2015-09-11 03:01:04 +00:00
|
|
|
|
2015-10-18 02:03:51 +00:00
|
|
|
//
|
|
|
|
// Date/Time
|
|
|
|
//
|
2015-09-11 03:01:04 +00:00
|
|
|
// :TODO: change to CD for 'Current Date'
|
2015-09-11 14:39:25 +00:00
|
|
|
DT : function date() { return moment().format(client.currentTheme.helpers.getDateFormat()); },
|
|
|
|
CT : function time() { return moment().format(client.currentTheme.helpers.getTimeFormat()) ;},
|
2015-09-11 03:01:04 +00:00
|
|
|
|
2015-10-18 02:03:51 +00:00
|
|
|
//
|
|
|
|
// OS/System Info
|
|
|
|
//
|
2015-09-11 03:01:04 +00:00
|
|
|
OS : function operatingSystem() {
|
|
|
|
return {
|
|
|
|
linux : 'Linux',
|
|
|
|
darwin : 'Mac OS X',
|
|
|
|
win32 : 'Windows',
|
|
|
|
sunos : 'SunOS',
|
|
|
|
freebsd : 'FreeBSD',
|
|
|
|
}[os.platform()] || os.type();
|
|
|
|
},
|
|
|
|
|
2015-09-11 14:39:25 +00:00
|
|
|
OA : function systemArchitecture() { return os.arch(); },
|
2015-10-18 03:39:54 +00:00
|
|
|
SC : function systemCpuModel() {
|
|
|
|
//
|
|
|
|
// Clean up CPU strings a bit for better display
|
|
|
|
//
|
2015-11-04 06:15:49 +00:00
|
|
|
return os.cpus()[0].model.replace(/\(R\)|\(TM\)|processor|CPU/g, '')
|
|
|
|
.replace(/\s+(?= )/g, '');
|
2015-10-18 03:39:54 +00:00
|
|
|
},
|
2015-09-11 03:01:04 +00:00
|
|
|
|
2015-11-04 06:15:49 +00:00
|
|
|
// :TODO: MCI for core count, e.g. os.cpus().length
|
|
|
|
|
2015-10-18 02:03:51 +00:00
|
|
|
// :TODO: cpu load average (over N seconds): http://stackoverflow.com/questions/9565912/convert-the-output-of-os-cpus-in-node-js-to-percentage
|
2015-10-19 16:50:35 +00:00
|
|
|
// :TODO: Node version/info
|
2015-10-18 02:03:51 +00:00
|
|
|
|
2015-11-26 01:03:47 +00:00
|
|
|
AN : function activeNodes() { return clientConnections.getActiveConnections().length.toString(); },
|
2015-10-18 02:03:51 +00:00
|
|
|
|
|
|
|
TC : function totalCalls() { return sysProp.getSystemProperty('login_count').toString(); },
|
2016-07-07 02:56:30 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Special handling for XY
|
|
|
|
//
|
|
|
|
XY : function xyHack() { return; /* nothing */ },
|
2015-10-18 02:03:51 +00:00
|
|
|
|
2015-12-31 05:29:41 +00:00
|
|
|
}[code](); // :TODO: Just call toString() here and remove above - DRY
|
2015-09-11 03:01:04 +00:00
|
|
|
|
|
|
|
} catch(e) {
|
|
|
|
// Don't use client.log here as we may not have a client logger established yet!!
|
2015-09-11 14:39:25 +00:00
|
|
|
Log.warn( { code : code, exception : e.message }, 'Exception caught attempting to construct predefined MCI value');
|
2015-09-11 03:01:04 +00:00
|
|
|
}
|
|
|
|
}
|