2015-09-11 03:01:04 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-07-07 02:56:30 +00:00
|
|
|
// ENiGMA½
|
2016-07-28 03:44:27 +00:00
|
|
|
const Config = require('./config.js').config;
|
|
|
|
const Log = require('./logger.js').log;
|
|
|
|
const getMessageAreaByTag = require('./message_area.js').getMessageAreaByTag;
|
|
|
|
const getMessageConferenceByTag = require('./message_area.js').getMessageConferenceByTag;
|
|
|
|
const clientConnections = require('./client_connections.js');
|
|
|
|
const StatLog = require('./stat_log.js');
|
2016-10-25 03:49:45 +00:00
|
|
|
const FileBaseFilters = require('./file_base_filter.js');
|
2016-12-31 21:50:29 +00:00
|
|
|
const formatByteSize = require('./string_util.js').formatByteSize;
|
2016-07-07 02:56:30 +00:00
|
|
|
|
|
|
|
// 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;
|
2016-08-11 04:48:13 +00:00
|
|
|
exports.init = init;
|
|
|
|
|
|
|
|
function init(cb) {
|
|
|
|
setNextRandomRumor(cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setNextRandomRumor(cb) {
|
|
|
|
StatLog.getSystemLogEntries('system_rumorz', StatLog.Order.Random, 1, (err, entry) => {
|
|
|
|
if(entry) {
|
|
|
|
entry = entry[0];
|
|
|
|
}
|
|
|
|
const randRumor = entry && entry.log_value ? entry.log_value : '';
|
|
|
|
StatLog.setNonPeristentSystemStat('random_rumor', randRumor);
|
|
|
|
if(cb) {
|
|
|
|
return cb(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-09-11 03:01:04 +00:00
|
|
|
|
2017-01-19 05:23:53 +00:00
|
|
|
function getRatio(client, propA, propB) {
|
|
|
|
const a = StatLog.getUserStatNum(client.user, propA);
|
|
|
|
const b = StatLog.getUserStatNum(client.user, propB);
|
|
|
|
const ratio = ~~((a / b) * 100);
|
|
|
|
return `${ratio}%`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function userStatAsString(client, statName, defaultValue) {
|
|
|
|
return (StatLog.getUserStat(client.user, statName) || defaultValue).toString();
|
|
|
|
}
|
|
|
|
|
2015-09-11 03:01:04 +00:00
|
|
|
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; },
|
|
|
|
|
2016-07-28 03:44:27 +00:00
|
|
|
// +op info
|
|
|
|
SN : function opUserName() { return StatLog.getSystemStat('sysop_username'); },
|
|
|
|
SR : function opRealName() { return StatLog.getSystemStat('sysop_real_name'); },
|
|
|
|
SL : function opLocation() { return StatLog.getSystemStat('sysop_location'); },
|
|
|
|
SA : function opAffils() { return StatLog.getSystemStat('sysop_affiliation'); },
|
|
|
|
SS : function opSex() { return StatLog.getSystemStat('sysop_sex'); },
|
|
|
|
SE : function opEmail() { return StatLog.getSystemStat('sysop_email_address'); },
|
|
|
|
// :TODO: op age, web, ?????
|
2015-09-24 05:41:06 +00:00
|
|
|
|
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(', '); },
|
2017-01-19 05:23:53 +00:00
|
|
|
UR : function realName() { return userStatAsString(client, 'real_name', ''); },
|
|
|
|
LO : function location() { return userStatAsString(client, 'location', ''); },
|
2015-09-11 14:39:25 +00:00
|
|
|
UA : function age() { return client.user.getAge().toString(); },
|
2017-01-19 05:23:53 +00:00
|
|
|
BD : function birthdate() { return moment(client.user.properties.birthdate).format(client.currentTheme.helpers.getDateFormat()); }, // iNiQUiTY
|
|
|
|
US : function sex() { return userStatAsString(client, 'sex', ''); },
|
|
|
|
UE : function emailAddres() { return userStatAsString(client, 'email_address', ''); },
|
|
|
|
UW : function webAddress() { return userStatAsString(client, 'web_address', ''); },
|
|
|
|
UF : function affils() { return userStatAsString(client, 'affiliation', ''); },
|
|
|
|
UT : function themeId() { return userStatAsString(client, 'theme_id', ''); },
|
|
|
|
UC : function loginCount() { return userStatAsString(client, 'login_count', 0); },
|
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; },
|
2016-10-25 03:49:45 +00:00
|
|
|
FN : function activeFileBaseFilterName() {
|
|
|
|
const activeFilter = FileBaseFilters.getActiveFilter(client);
|
|
|
|
return activeFilter ? activeFilter.name : '';
|
|
|
|
},
|
2017-01-19 05:23:53 +00:00
|
|
|
DN : function userNumDownloads() { return userStatAsString(client, 'dl_total_count', 0); }, // Obv/2
|
|
|
|
DK : function userByteDownload() { // Obv/2 uses DK=downloaded Kbytes
|
|
|
|
const byteSize = StatLog.getUserStatNum(client.user, 'dl_total_bytes');
|
|
|
|
return formatByteSize(byteSize, true); // true=withAbbr
|
|
|
|
},
|
|
|
|
UP : function userNumUploads() { return userStatAsString(client, 'ul_total_count', 0); }, // Obv/2
|
|
|
|
UK : function userByteUpload() { // Obv/2 uses UK=uploaded Kbytes
|
|
|
|
const byteSize = StatLog.getUserStatNum(client.user, 'ul_total_bytes');
|
|
|
|
return formatByteSize(byteSize, true); // true=withAbbr
|
|
|
|
},
|
|
|
|
NR : function userUpDownRatio() { // Obv/2
|
|
|
|
return getRatio(client, 'ul_total_count', 'dl_total_count');
|
|
|
|
},
|
|
|
|
KR : function userUpDownByteRatio() { // Obv/2 uses KR=upload/download Kbyte ratio
|
|
|
|
return getRatio(client, 'ul_total_bytes', 'dl_total_bytes');
|
2016-12-31 21:50:29 +00:00
|
|
|
},
|
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; },
|
2017-01-19 05:23:53 +00:00
|
|
|
PS : function userPostCount() { return userStatAsString(client, 'post_count', 0); },
|
|
|
|
PC : function userPostCallRatio() { return getRatio(client, 'post_count', 'login_count'); },
|
2016-07-12 09:57:07 +00:00
|
|
|
|
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-07-12 09:57:07 +00:00
|
|
|
MA : function messageAreaName() {
|
2016-02-03 04:35:59 +00:00
|
|
|
const area = getMessageAreaByTag(client.user.properties.message_area_tag);
|
|
|
|
return area ? area.name : '';
|
2015-09-11 03:01:04 +00:00
|
|
|
},
|
2016-07-12 09:57:07 +00:00
|
|
|
MC : function messageConfName() {
|
|
|
|
const conf = getMessageConferenceByTag(client.user.properties.message_conf_tag);
|
|
|
|
return conf ? conf.name : '';
|
|
|
|
},
|
2016-07-07 02:56:30 +00:00
|
|
|
ML : function messageAreaDescription() {
|
|
|
|
const area = getMessageAreaByTag(client.user.properties.message_area_tag);
|
|
|
|
return area ? area.desc : '';
|
|
|
|
},
|
2016-07-28 03:44:27 +00:00
|
|
|
CM : function messageConfDescription() {
|
|
|
|
const conf = getMessageConferenceByTag(client.user.properties.message_conf_tag);
|
|
|
|
return conf ? conf.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(); },
|
2016-07-28 03:44:27 +00:00
|
|
|
SC : function systemCpuModel() {
|
2015-10-18 03:39:54 +00:00
|
|
|
//
|
|
|
|
// 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
|
2016-07-28 03:44:27 +00:00
|
|
|
NV : function nodeVersion() { return process.version; },
|
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
|
|
|
|
2016-07-28 03:44:27 +00:00
|
|
|
TC : function totalCalls() { return StatLog.getSystemStat('login_count').toString(); },
|
2016-07-07 02:56:30 +00:00
|
|
|
|
2016-08-11 04:48:13 +00:00
|
|
|
RR : function randomRumor() {
|
|
|
|
// start the process of picking another random one
|
|
|
|
setNextRandomRumor();
|
|
|
|
|
|
|
|
return StatLog.getSystemStat('random_rumor');
|
|
|
|
},
|
|
|
|
|
2016-12-31 21:50:29 +00:00
|
|
|
//
|
|
|
|
// System File Base, Up/Download Info
|
|
|
|
//
|
|
|
|
// :TODO: DD - Today's # of downloads (iNiQUiTY)
|
|
|
|
//
|
2017-01-19 05:23:53 +00:00
|
|
|
// :TODO: System stat log for total ul/dl, total ul/dl bytes
|
2016-12-31 21:50:29 +00:00
|
|
|
|
2017-01-22 05:09:29 +00:00
|
|
|
// :TODO: PT - Messages posted *today* (Obv/2)
|
|
|
|
// :TODO: NT - New users today (Obv/2)
|
|
|
|
// :TODO: CT - Calls *today* (Obv/2)
|
|
|
|
// :TODO: TF - Total files on the system (Obv/2)
|
|
|
|
// :TODO: FT - Files uploaded/added *today* (Obv/2)
|
|
|
|
// :TODO: DD - Files downloaded *today* (iNiQUiTY)
|
|
|
|
// :TODO: TP - total message/posts on the system (Obv/2)
|
|
|
|
// :TODO: LC - name of last caller to system (Obv/2)
|
|
|
|
// :TODO: TZ - Average *system* post/call ratio (iNiQUiTY)
|
|
|
|
|
|
|
|
|
2016-07-07 02:56:30 +00:00
|
|
|
//
|
|
|
|
// Special handling for XY
|
|
|
|
//
|
|
|
|
XY : function xyHack() { return; /* nothing */ },
|
2016-07-12 09:57:07 +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
|
|
|
}
|
|
|
|
}
|