2015-09-11 03:01:04 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// ENiGMA½
|
2018-11-24 00:41:16 +00:00
|
|
|
const Config = require('./config.js').get;
|
|
|
|
const Log = require('./logger.js').log;
|
2018-09-15 02:34:39 +00:00
|
|
|
const {
|
|
|
|
getMessageAreaByTag,
|
|
|
|
getMessageConferenceByTag
|
2018-11-24 00:41:16 +00:00
|
|
|
} = require('./message_area.js');
|
|
|
|
const clientConnections = require('./client_connections.js');
|
|
|
|
const StatLog = require('./stat_log.js');
|
|
|
|
const FileBaseFilters = require('./file_base_filter.js');
|
|
|
|
const { formatByteSize } = require('./string_util.js');
|
|
|
|
const ANSI = require('./ansi_term.js');
|
|
|
|
const UserProps = require('./user_property.js');
|
2018-06-23 03:26:46 +00:00
|
|
|
|
|
|
|
// deps
|
|
|
|
const packageJson = require('../package.json');
|
|
|
|
const os = require('os');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const moment = require('moment');
|
|
|
|
|
|
|
|
exports.getPredefinedMCIValue = getPredefinedMCIValue;
|
|
|
|
exports.init = init;
|
2016-08-11 04:48:13 +00:00
|
|
|
|
|
|
|
function init(cb) {
|
2018-06-22 05:15:04 +00:00
|
|
|
setNextRandomRumor(cb);
|
2016-08-11 04:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setNextRandomRumor(cb) {
|
2018-06-22 05:15:04 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2016-08-11 04:48:13 +00:00
|
|
|
}
|
2015-09-11 03:01:04 +00:00
|
|
|
|
2017-07-09 22:48:53 +00:00
|
|
|
function getUserRatio(client, propA, propB) {
|
2018-06-22 05:15:04 +00:00
|
|
|
const a = StatLog.getUserStatNum(client.user, propA);
|
2018-06-23 03:26:46 +00:00
|
|
|
const b = StatLog.getUserStatNum(client.user, propB);
|
|
|
|
const ratio = ~~((a / b) * 100);
|
2018-06-22 05:15:04 +00:00
|
|
|
return `${ratio}%`;
|
2017-01-19 05:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function userStatAsString(client, statName, defaultValue) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return (StatLog.getUserStat(client.user, statName) || defaultValue).toLocaleString();
|
2017-01-19 05:23:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-09 22:48:53 +00:00
|
|
|
function sysStatAsString(statName, defaultValue) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return (StatLog.getSystemStat(statName) || defaultValue).toLocaleString();
|
2017-07-09 22:48:53 +00:00
|
|
|
}
|
|
|
|
|
2017-05-11 03:17:19 +00:00
|
|
|
const PREDEFINED_MCI_GENERATORS = {
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Board
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
BN : function boardName() { return Config().general.boardName; },
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// ENiGMA
|
|
|
|
VL : function versionLabel() { return 'ENiGMA½ v' + packageJson.version; },
|
|
|
|
VN : function version() { return packageJson.version; },
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +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, ?????
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Current user / session
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
UN : function userName(client) { return client.user.username; },
|
|
|
|
UI : function userId(client) { return client.user.userId.toString(); },
|
|
|
|
UG : function groups(client) { return _.values(client.user.groups).join(', '); },
|
2018-11-24 05:02:36 +00:00
|
|
|
UR : function realName(client) { return userStatAsString(client, UserProps.RealName, ''); },
|
|
|
|
LO : function location(client) { return userStatAsString(client, UserProps.Location, ''); },
|
2018-06-23 03:26:46 +00:00
|
|
|
UA : function age(client) { return client.user.getAge().toString(); },
|
2018-11-24 00:41:16 +00:00
|
|
|
BD : function birthdate(client) { // iNiQUiTY
|
|
|
|
return moment(client.user.properties[UserProps.Birthdate]).format(client.currentTheme.helpers.getDateFormat());
|
|
|
|
},
|
2018-11-24 05:02:36 +00:00
|
|
|
US : function sex(client) { return userStatAsString(client, UserProps.Sex, ''); },
|
|
|
|
UE : function emailAddres(client) { return userStatAsString(client, UserProps.EmailAddress, ''); },
|
|
|
|
UW : function webAddress(client) { return userStatAsString(client, UserProps.WebAddress, ''); },
|
|
|
|
UF : function affils(client) { return userStatAsString(client, UserProps.Affiliations, ''); },
|
|
|
|
UT : function themeId(client) { return userStatAsString(client, UserProps.ThemeId, ''); },
|
|
|
|
UC : function loginCount(client) { return userStatAsString(client, UserProps.LoginCount, 0); },
|
2018-06-23 03:26:46 +00:00
|
|
|
ND : function connectedNode(client) { return client.node.toString(); },
|
|
|
|
IP : function clientIpAddress(client) { return client.remoteAddress.replace(/^::ffff:/, ''); }, // convert any :ffff: IPv4's to 32bit version
|
|
|
|
ST : function serverName(client) { return client.session.serverName; },
|
|
|
|
FN : function activeFileBaseFilterName(client) {
|
2018-06-22 05:15:04 +00:00
|
|
|
const activeFilter = FileBaseFilters.getActiveFilter(client);
|
2018-11-17 20:24:16 +00:00
|
|
|
return activeFilter ? activeFilter.name : '(Unknown)';
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
2018-11-24 05:02:36 +00:00
|
|
|
DN : function userNumDownloads(client) { return userStatAsString(client, UserProps.FileDlTotalCount, 0); }, // Obv/2
|
2018-06-23 03:26:46 +00:00
|
|
|
DK : function userByteDownload(client) { // Obv/2 uses DK=downloaded Kbytes
|
2018-11-24 05:02:36 +00:00
|
|
|
const byteSize = StatLog.getUserStatNum(client.user, UserProps.FileDlTotalBytes);
|
2018-06-23 03:26:46 +00:00
|
|
|
return formatByteSize(byteSize, true); // true=withAbbr
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
2018-11-24 05:02:36 +00:00
|
|
|
UP : function userNumUploads(client) { return userStatAsString(client, UserProps.FileUlTotalCount, 0); }, // Obv/2
|
2018-06-23 03:26:46 +00:00
|
|
|
UK : function userByteUpload(client) { // Obv/2 uses UK=uploaded Kbytes
|
2018-11-24 05:02:36 +00:00
|
|
|
const byteSize = StatLog.getUserStatNum(client.user, UserProps.FileUlTotalBytes);
|
2018-06-23 03:26:46 +00:00
|
|
|
return formatByteSize(byteSize, true); // true=withAbbr
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
2018-06-23 03:26:46 +00:00
|
|
|
NR : function userUpDownRatio(client) { // Obv/2
|
2018-11-24 05:02:36 +00:00
|
|
|
return getUserRatio(client, UserProps.FileUlTotalCount, UserProps.FileDlTotalCount);
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
2018-06-23 03:26:46 +00:00
|
|
|
KR : function userUpDownByteRatio(client) { // Obv/2 uses KR=upload/download Kbyte ratio
|
2018-11-24 05:02:36 +00:00
|
|
|
return getUserRatio(client, UserProps.FileUlTotalBytes, UserProps.FileDlTotalBytes);
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
|
|
|
|
2018-11-24 00:41:16 +00:00
|
|
|
MS : function accountCreatedclient(client) {
|
|
|
|
return moment(client.user.properties[UserProps.AccountCreated]).format(client.currentTheme.helpers.getDateFormat());
|
|
|
|
},
|
2018-11-24 05:02:36 +00:00
|
|
|
PS : function userPostCount(client) { return userStatAsString(client, UserProps.MessagePostCount, 0); },
|
|
|
|
PC : function userPostCallRatio(client) { return getUserRatio(client, UserProps.MessagePostCount, UserProps.LoginCount); },
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
MD : function currentMenuDescription(client) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return _.has(client, 'currentMenuModule.menuConfig.desc') ? client.currentMenuModule.menuConfig.desc : '';
|
|
|
|
},
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
MA : function messageAreaName(client) {
|
2018-11-24 00:41:16 +00:00
|
|
|
const area = getMessageAreaByTag(client.user.properties[UserProps.MessageAreaTag]);
|
2018-06-22 05:15:04 +00:00
|
|
|
return area ? area.name : '';
|
|
|
|
},
|
|
|
|
MC : function messageConfName(client) {
|
2018-11-24 00:41:16 +00:00
|
|
|
const conf = getMessageConferenceByTag(client.user.properties[UserProps.MessageConfTag]);
|
2018-06-22 05:15:04 +00:00
|
|
|
return conf ? conf.name : '';
|
|
|
|
},
|
|
|
|
ML : function messageAreaDescription(client) {
|
2018-11-24 00:41:16 +00:00
|
|
|
const area = getMessageAreaByTag(client.user.properties[UserProps.MessageAreaTag]);
|
2018-06-22 05:15:04 +00:00
|
|
|
return area ? area.desc : '';
|
|
|
|
},
|
2018-06-23 03:26:46 +00:00
|
|
|
CM : function messageConfDescription(client) {
|
2018-11-24 00:41:16 +00:00
|
|
|
const conf = getMessageConferenceByTag(client.user.properties[UserProps.MessageConfTag]);
|
2018-06-22 05:15:04 +00:00
|
|
|
return conf ? conf.desc : '';
|
|
|
|
},
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
SH : function termHeight(client) { return client.term.termHeight.toString(); },
|
|
|
|
SW : function termWidth(client) { return client.term.termWidth.toString(); },
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Date/Time
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: change to CD for 'Current Date'
|
|
|
|
DT : function date(client) { return moment().format(client.currentTheme.helpers.getDateFormat()); },
|
|
|
|
CT : function time(client) { return moment().format(client.currentTheme.helpers.getTimeFormat()) ;},
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// OS/System Info
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
OS : function operatingSystem() {
|
2018-06-22 05:15:04 +00:00
|
|
|
return {
|
2018-06-23 03:26:46 +00:00
|
|
|
linux : 'Linux',
|
|
|
|
darwin : 'Mac OS X',
|
|
|
|
win32 : 'Windows',
|
|
|
|
sunos : 'SunOS',
|
|
|
|
freebsd : 'FreeBSD',
|
2018-06-22 05:15:04 +00:00
|
|
|
}[os.platform()] || os.type();
|
|
|
|
},
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
OA : function systemArchitecture() { return os.arch(); },
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
SC : function systemCpuModel() {
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Clean up CPU strings a bit for better display
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
return os.cpus()[0].model
|
2018-11-24 00:41:16 +00:00
|
|
|
.replace(/\(R\)|\(TM\)|processor|CPU/ig, '')
|
|
|
|
.replace(/\s+(?= )/g, '')
|
|
|
|
.trim();
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: MCI for core count, e.g. os.cpus().length
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +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
|
|
|
|
NV : function nodeVersion() { return process.version; },
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
AN : function activeNodes() { return clientConnections.getActiveConnections().length.toString(); },
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
TC : function totalCalls() { return StatLog.getSystemStat('login_count').toLocaleString(); },
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
RR : function randomRumor() {
|
|
|
|
// start the process of picking another random one
|
2018-06-22 05:15:04 +00:00
|
|
|
setNextRandomRumor();
|
|
|
|
|
|
|
|
return StatLog.getSystemStat('random_rumor');
|
|
|
|
},
|
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// System File Base, Up/Download Info
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: DD - Today's # of downloads (iNiQUiTY)
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
SD : function systemNumDownloads() { return sysStatAsString('dl_total_count', 0); },
|
|
|
|
SO : function systemByteDownload() {
|
2018-06-22 05:15:04 +00:00
|
|
|
const byteSize = StatLog.getSystemStatNum('dl_total_bytes');
|
2018-06-23 03:26:46 +00:00
|
|
|
return formatByteSize(byteSize, true); // true=withAbbr
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
2018-06-23 03:26:46 +00:00
|
|
|
SU : function systemNumUploads() { return sysStatAsString('ul_total_count', 0); },
|
|
|
|
SP : function systemByteUpload() {
|
2018-06-22 05:15:04 +00:00
|
|
|
const byteSize = StatLog.getSystemStatNum('ul_total_bytes');
|
2018-06-23 03:26:46 +00:00
|
|
|
return formatByteSize(byteSize, true); // true=withAbbr
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
2018-06-23 03:26:46 +00:00
|
|
|
TF : function totalFilesOnSystem() {
|
2018-06-22 05:15:04 +00:00
|
|
|
const areaStats = StatLog.getSystemStat('file_base_area_stats');
|
|
|
|
return _.get(areaStats, 'totalFiles', 0).toLocaleString();
|
|
|
|
},
|
2018-06-23 03:26:46 +00:00
|
|
|
TB : function totalBytesOnSystem() {
|
|
|
|
const areaStats = StatLog.getSystemStat('file_base_area_stats');
|
|
|
|
const totalBytes = parseInt(_.get(areaStats, 'totalBytes', 0));
|
|
|
|
return formatByteSize(totalBytes, true); // true=withAbbr
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: PT - Messages posted *today* (Obv/2)
|
|
|
|
// -> Include FTN/etc.
|
|
|
|
// :TODO: NT - New users today (Obv/2)
|
|
|
|
// :TODO: CT - Calls *today* (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)
|
|
|
|
// -> Include FTN/etc.
|
|
|
|
// :TODO: LC - name of last caller to system (Obv/2)
|
|
|
|
// :TODO: TZ - Average *system* post/call ratio (iNiQUiTY)
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Special handling for XY
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
XY : function xyHack() { return; /* nothing */ },
|
2018-09-15 02:34:39 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Various movement by N
|
|
|
|
//
|
|
|
|
CF : function cursorForwardBy(client, n = 1) { return ANSI.forward(n); },
|
|
|
|
CB : function cursorBackBy(client, n = 1) { return ANSI.back(n); },
|
|
|
|
CU : function cursorUpBy(client, n = 1) { return ANSI.up(n); },
|
|
|
|
CD : function cursorDownBy(client, n = 1) { return ANSI.down(n); },
|
2017-05-11 03:17:19 +00:00
|
|
|
};
|
|
|
|
|
2018-09-15 02:34:39 +00:00
|
|
|
function getPredefinedMCIValue(client, code, extra) {
|
2015-09-11 03:01:04 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
if(!client || !code) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-11 03:01:04 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
const generator = PREDEFINED_MCI_GENERATORS[code];
|
2017-05-11 03:17:19 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
if(generator) {
|
|
|
|
let value;
|
|
|
|
try {
|
2018-09-15 02:34:39 +00:00
|
|
|
value = generator(client, extra);
|
2018-06-22 05:15:04 +00:00
|
|
|
} catch(e) {
|
|
|
|
Log.error( { code : code, exception : e.message }, 'Exception caught generating predefined MCI value' );
|
|
|
|
}
|
2017-05-11 03:17:19 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
return value;
|
|
|
|
}
|
2015-09-11 03:01:04 +00:00
|
|
|
}
|