Default to NOT showing non-authenticated users in who's online / getActiveNodeList()
This commit is contained in:
parent
66abe4429c
commit
b19d06df26
|
@ -1,28 +1,39 @@
|
||||||
/* jslint node: true */
|
/* jslint node: true */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var logger = require('./logger.js');
|
// ENiGMA½
|
||||||
|
const logger = require('./logger.js');
|
||||||
|
|
||||||
var _ = require('lodash');
|
// deps
|
||||||
var moment = require('moment');
|
const _ = require('lodash');
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
exports.getActiveConnections = getActiveConnections;
|
exports.getActiveConnections = getActiveConnections;
|
||||||
exports.getActiveNodeList = getActiveNodeList;
|
exports.getActiveNodeList = getActiveNodeList;
|
||||||
exports.addNewClient = addNewClient;
|
exports.addNewClient = addNewClient;
|
||||||
exports.removeClient = removeClient;
|
exports.removeClient = removeClient;
|
||||||
|
|
||||||
var clientConnections = [];
|
const clientConnections = [];
|
||||||
exports.clientConnections = clientConnections;
|
exports.clientConnections = clientConnections;
|
||||||
|
|
||||||
function getActiveConnections() {
|
function getActiveConnections() {
|
||||||
return clientConnections;
|
return clientConnections;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getActiveNodeList() {
|
function getActiveNodeList(authUsersOnly) {
|
||||||
|
|
||||||
|
if(!_.isBoolean(authUsersOnly)) {
|
||||||
|
authUsersOnly = true;
|
||||||
|
}
|
||||||
|
|
||||||
const now = moment();
|
const now = moment();
|
||||||
|
|
||||||
return _.map(getActiveConnections(), ac => {
|
const activeConnections = getActiveConnections().filter(ac => {
|
||||||
let entry = {
|
return ((authUsersOnly && ac.user.isAuthenticated()) || !authUsersOnly);
|
||||||
|
});
|
||||||
|
|
||||||
|
return _.map(activeConnections, ac => {
|
||||||
|
const entry = {
|
||||||
node : ac.node,
|
node : ac.node,
|
||||||
authenticated : ac.user.isAuthenticated(),
|
authenticated : ac.user.isAuthenticated(),
|
||||||
userId : ac.user.userId,
|
userId : ac.user.userId,
|
||||||
|
@ -46,13 +57,13 @@ function getActiveNodeList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addNewClient(client, clientSock) {
|
function addNewClient(client, clientSock) {
|
||||||
var id = client.session.id = clientConnections.push(client) - 1;
|
const id = client.session.id = clientConnections.push(client) - 1;
|
||||||
|
|
||||||
// Create a client specific logger
|
// Create a client specific logger
|
||||||
// Note that this will be updated @ login with additional information
|
// Note that this will be updated @ login with additional information
|
||||||
client.log = logger.log.child( { clientId : id } );
|
client.log = logger.log.child( { clientId : id } );
|
||||||
|
|
||||||
var connInfo = {
|
const connInfo = {
|
||||||
ip : clientSock.remoteAddress,
|
ip : clientSock.remoteAddress,
|
||||||
serverName : client.session.serverName,
|
serverName : client.session.serverName,
|
||||||
isSecure : client.session.isSecure,
|
isSecure : client.session.isSecure,
|
||||||
|
@ -71,7 +82,7 @@ function addNewClient(client, clientSock) {
|
||||||
function removeClient(client) {
|
function removeClient(client) {
|
||||||
client.end();
|
client.end();
|
||||||
|
|
||||||
var i = clientConnections.indexOf(client);
|
const i = clientConnections.indexOf(client);
|
||||||
if(i > -1) {
|
if(i > -1) {
|
||||||
clientConnections.splice(i, 1);
|
clientConnections.splice(i, 1);
|
||||||
|
|
||||||
|
@ -84,15 +95,3 @@ function removeClient(client) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* :TODO: make a public API elsewhere
|
|
||||||
function getActiveClientInformation() {
|
|
||||||
var info = {};
|
|
||||||
|
|
||||||
clientConnections.forEach(function connEntry(cc) {
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
*/
|
|
|
@ -1,14 +1,14 @@
|
||||||
/* jslint node: true */
|
/* jslint node: true */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var MenuModule = require('../core/menu_module.js').MenuModule;
|
// ENiGMA½
|
||||||
var ViewController = require('../core/view_controller.js').ViewController;
|
const MenuModule = require('../core/menu_module.js').MenuModule;
|
||||||
var getActiveNodeList = require('../core/client_connections.js').getActiveNodeList;
|
const ViewController = require('../core/view_controller.js').ViewController;
|
||||||
|
const getActiveNodeList = require('../core/client_connections.js').getActiveNodeList;
|
||||||
|
|
||||||
var moment = require('moment');
|
// deps
|
||||||
var async = require('async');
|
const async = require('async');
|
||||||
var assert = require('assert');
|
const _ = require('lodash');
|
||||||
var _ = require('lodash');
|
|
||||||
|
|
||||||
exports.moduleInfo = {
|
exports.moduleInfo = {
|
||||||
name : 'Who\'s Online',
|
name : 'Who\'s Online',
|
||||||
|
@ -17,26 +17,9 @@ exports.moduleInfo = {
|
||||||
packageName : 'codes.l33t.enigma.whosonline'
|
packageName : 'codes.l33t.enigma.whosonline'
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
node
|
|
||||||
userName
|
|
||||||
userId
|
|
||||||
action
|
|
||||||
note
|
|
||||||
affils
|
|
||||||
timeOnSec
|
|
||||||
location
|
|
||||||
realName
|
|
||||||
serverName (Telnet, SSH, ...)
|
|
||||||
|
|
||||||
default
|
|
||||||
{node} - {username} - {action} - {timeOnSec}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.getModule = WhosOnlineModule;
|
exports.getModule = WhosOnlineModule;
|
||||||
|
|
||||||
var MciCodeIds = {
|
const MciCodeIds = {
|
||||||
OnlineList : 1,
|
OnlineList : 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,30 +30,29 @@ function WhosOnlineModule(options) {
|
||||||
require('util').inherits(WhosOnlineModule, MenuModule);
|
require('util').inherits(WhosOnlineModule, MenuModule);
|
||||||
|
|
||||||
WhosOnlineModule.prototype.mciReady = function(mciData, cb) {
|
WhosOnlineModule.prototype.mciReady = function(mciData, cb) {
|
||||||
var self = this;
|
const self = this;
|
||||||
var vc = self.viewControllers.allViews = new ViewController( { client : self.client } );
|
const vc = self.viewControllers.allViews = new ViewController( { client : self.client } );
|
||||||
|
|
||||||
async.series(
|
async.series(
|
||||||
[
|
[
|
||||||
function callParentMciReady(callback) {
|
function callParentMciReady(callback) {
|
||||||
WhosOnlineModule.super_.prototype.mciReady.call(self, mciData, callback);
|
return WhosOnlineModule.super_.prototype.mciReady.call(self, mciData, callback);
|
||||||
},
|
},
|
||||||
function loadFromConfig(callback) {
|
function loadFromConfig(callback) {
|
||||||
var loadOpts = {
|
const loadOpts = {
|
||||||
callingMenu : self,
|
callingMenu : self,
|
||||||
mciMap : mciData.menu,
|
mciMap : mciData.menu,
|
||||||
noInput : true,
|
noInput : true,
|
||||||
};
|
};
|
||||||
|
|
||||||
vc.loadFromMenuConfig(loadOpts, callback);
|
return vc.loadFromMenuConfig(loadOpts, callback);
|
||||||
},
|
},
|
||||||
function populateList(callback) {
|
function populateList(callback) {
|
||||||
var onlineListView = vc.getView(MciCodeIds.OnlineList);
|
const onlineListView = vc.getView(MciCodeIds.OnlineList);
|
||||||
|
const listFormat = self.menuConfig.config.listFormat || '{node} - {userName} - {action} - {timeOn}';
|
||||||
const listFormat = self.menuConfig.config.listFormat || '{node} - {userName} - {action} - {timeOn}';
|
const nonAuthUser = self.menuConfig.config.nonAuthUser || 'Logging In';
|
||||||
const nonAuthUser = self.menuConfig.config.nonAuthUser || 'Logging In';
|
const otherUnknown = self.menuConfig.config.otherUnknown || 'N/A';
|
||||||
const otherUnknown = self.menuConfig.config.otherUnknown || 'N/A';
|
const onlineList = getActiveNodeList(self.menuConfig.config.authUsersOnly).slice(0, onlineListView.height);
|
||||||
const onlineList = getActiveNodeList().slice(0, onlineListView.height);
|
|
||||||
|
|
||||||
onlineListView.setItems(_.map(onlineList, oe => {
|
onlineListView.setItems(_.map(onlineList, oe => {
|
||||||
if(oe.authenticated) {
|
if(oe.authenticated) {
|
||||||
|
@ -85,16 +67,16 @@ WhosOnlineModule.prototype.mciReady = function(mciData, cb) {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
onlineListView.focusItems = onlineListView.items;
|
onlineListView.focusItems = onlineListView.items;
|
||||||
|
|
||||||
onlineListView.redraw();
|
onlineListView.redraw();
|
||||||
callback(null);
|
|
||||||
|
return callback(null);
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
function complete(err) {
|
function complete(err) {
|
||||||
if(err) {
|
if(err) {
|
||||||
self.client.log.error( { error : err.toString() }, 'Error loading who\'s online');
|
self.client.log.error( { error : err.message }, 'Error loading who\'s online');
|
||||||
}
|
}
|
||||||
cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue