enigma-bbs/core/wfc.js

169 lines
5.4 KiB
JavaScript
Raw Normal View History

2020-07-14 03:08:25 +00:00
// ENiGMA½
const { MenuModule } = require('./menu_module');
2020-11-10 02:40:55 +00:00
const { getActiveConnectionList } = require('./client_connections');
const StatLog = require('./stat_log');
const SysProps = require('./system_property');
2020-09-25 21:41:21 +00:00
// deps
const async = require('async');
const _ = require('lodash');
2020-11-10 04:32:34 +00:00
const moment = require('moment');
const SysInfo = require('systeminformation');
2020-09-25 21:41:21 +00:00
2020-07-14 03:08:25 +00:00
exports.moduleInfo = {
name : 'WFC',
desc : 'Semi-Traditional Waiting For Caller',
author : 'NuSkooler',
};
2020-09-25 21:41:21 +00:00
const FormIds = {
main : 0,
};
const MciViewIds = {
main : {
2020-11-10 02:40:55 +00:00
nodeStatus : 1,
quickLogView : 2,
2020-09-25 21:41:21 +00:00
customRangeStart : 10,
}
};
// Secure + 2FA + root user + 'wfc' group.
const DefaultACS = 'SCAF2ID1GM[wfc]';
2020-07-14 03:08:25 +00:00
exports.getModule = class WaitingForCallerModule extends MenuModule {
constructor(options) {
super(options);
this.config = Object.assign({}, _.get(options, 'menuConfig.config'), { extraArgs : options.extraArgs });
2020-09-25 21:41:21 +00:00
this.config.acs = this.config.acs || DefaultACS;
if (!this.config.acs.includes('SC')) {
2020-11-10 02:40:55 +00:00
this.config.acs = 'SC' + this.config.acs; // secure connection at the very least
2020-09-25 21:41:21 +00:00
}
}
mciReady(mciData, cb) {
super.mciReady(mciData, err => {
if (err) {
return cb(err);
}
async.series(
[
(callback) => {
return this.prepViewController('main', FormIds.main, mciData.menu, callback);
},
(callback) => {
// const requiredCodes = [
// ];
// return this.validateMCIByViewIds('main', requiredCodes, callback);
return callback(null);
},
2020-11-10 04:32:34 +00:00
(callback) => {
return this._refreshStats(callback);
},
2020-11-10 02:40:55 +00:00
(callback) => {
return this._refreshNodeStatus(callback);
}
2020-09-25 21:41:21 +00:00
],
err => {
return cb(err);
}
);
});
2020-07-14 03:08:25 +00:00
}
2020-11-10 02:40:55 +00:00
_refreshStats(cb) {
2020-11-22 19:25:19 +00:00
const fileAreaStats = StatLog.getSystemStat(SysProps.FileBaseAreaStats);
2020-11-10 02:40:55 +00:00
2020-11-10 04:32:34 +00:00
// Some stats we can just fill right away
2020-11-10 02:40:55 +00:00
this.stats = {
2020-11-10 04:32:34 +00:00
// Date/Time
2020-11-22 19:25:19 +00:00
date : moment().format(this.getDateFormat()),
time : moment().format(this.getTimeFormat()),
dateTime : moment().format(this.getDateTimeFormat()),
2020-11-10 04:32:34 +00:00
// Current process (our Node.js service)
2020-11-22 19:25:19 +00:00
processUptimeSeconds : process.uptime(),
// processUptime : moment.duration(process.uptime(), 'seconds').humanize(),
2020-11-10 04:32:34 +00:00
2020-11-10 02:40:55 +00:00
// Totals
2020-11-22 19:25:19 +00:00
totalCalls : StatLog.getSystemStatNum(SysProps.LoginCount),
totalPosts : StatLog.getSystemStatNum(SysProps.MessageTotalCount),
2020-11-10 02:40:55 +00:00
//totalUsers :
2020-11-22 19:25:19 +00:00
totalFiles : fileAreaStats.totalFiles || 0,
totalFileBytes : fileAreaStats.totalFileBytes || 0,
// totalUploads :
// totalUploadBytes :
// totalDownloads :
// totalDownloadBytes :
2020-11-10 02:40:55 +00:00
// :TODO: lastCaller
// :TODO: totalMemoryBytes, freeMemoryBytes
// :TODO: CPU info/averages/load
2020-11-10 04:32:34 +00:00
2020-11-22 19:25:19 +00:00
// Today's Stats
callsToday : StatLog.getSystemStatNum(SysProps.LoginsToday),
postsToday : StatLog.getSystemStatNum(SysProps.MessagesToday),
// uploadsToday :
// uploadBytesToday :
// downloadsToday :
// downloadBytesToday :
// Current
// lastCaller :
// lastCallerDate
// lastCallerTime
2020-11-10 02:40:55 +00:00
};
2020-11-10 04:32:34 +00:00
// Some async work required...
2020-11-23 01:54:49 +00:00
// :TODO: replace with stat log stats
2020-11-10 04:32:34 +00:00
const basicSysInfo = {
mem : 'total, free',
currentLoad : 'avgload, currentLoad',
};
SysInfo.get(basicSysInfo)
.then(sysInfo => {
2020-11-22 19:25:19 +00:00
this.stats.totalMemoryBytes = sysInfo.mem.total;
this.stats.freeMemoryBytes = sysInfo.mem.free;
2020-11-10 04:32:34 +00:00
// Not avail on BSD, yet.
2020-11-22 19:25:19 +00:00
this.stats.systemAvgLoad = _.get(sysInfo, 'currentLoad.avgload', 0);
this.stats.systemCurrentLoad = _.get(sysInfo, 'currentLoad.currentLoad', 0);
2020-11-10 04:32:34 +00:00
})
.catch(err => {
return cb(err);
});
2020-11-10 02:40:55 +00:00
}
_refreshNodeStatus(cb) {
const nodeStatusView = this.getView('main', MciViewIds.main.nodeStatus);
if (!nodeStatusView) {
return cb(null);
}
const nodeStatusItems = getActiveConnectionList(false).slice(0, nodeStatusView.height).map(ac => {
// Handle pre-authenticated
if (!ac.authenticated) {
ac.text = ac.username = 'Pre Auth';
ac.action = 'Logging In';
}
return Object.assign(ac, {
timeOn : _.upperFirst(ac.timeOn.humanize()), // make friendly
});
});
nodeStatusView.setItems(nodeStatusItems);
nodeStatusView.redraw();
return cb(null);
}
2020-07-14 03:08:25 +00:00
};