|
|
|
"use strict";
|
|
|
|
|
|
|
|
var groups = require('../groups'),
|
|
|
|
meta = require('../meta'),
|
|
|
|
plugins = require('../plugins'),
|
|
|
|
widgets = require('../widgets'),
|
|
|
|
user = require('../user'),
|
|
|
|
topics = require('../topics'),
|
|
|
|
categories = require('../categories'),
|
|
|
|
logger = require('../logger'),
|
|
|
|
events = require('../events'),
|
|
|
|
db = require('../database'),
|
|
|
|
async = require('async'),
|
|
|
|
winston = require('winston'),
|
|
|
|
index = require('./index'),
|
|
|
|
|
|
|
|
SocketAdmin = {
|
|
|
|
user: require('./admin/user'),
|
|
|
|
categories: require('./admin/categories'),
|
|
|
|
groups: require('./admin/groups'),
|
|
|
|
themes: {},
|
|
|
|
plugins: {},
|
|
|
|
widgets: {},
|
|
|
|
config: {},
|
|
|
|
settings: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.before = function(socket, next) {
|
|
|
|
user.isAdministrator(socket.uid, function(err, isAdmin) {
|
|
|
|
if (!err && isAdmin) {
|
|
|
|
next();
|
|
|
|
} else {
|
|
|
|
winston.warn('[socket.io] Call to admin method blocked (accessed by uid ' + socket.uid + ')');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.restart = function(socket, data, callback) {
|
|
|
|
meta.restart();
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.getVisitorCount = function(socket, data, callback) {
|
|
|
|
var terms = {
|
|
|
|
day: 86400000,
|
|
|
|
week: 604800000,
|
|
|
|
month: 2592000000
|
|
|
|
};
|
|
|
|
var now = Date.now();
|
|
|
|
async.parallel({
|
|
|
|
day: function(next) {
|
|
|
|
db.sortedSetCount('ip:recent', now - terms.day, now, next);
|
|
|
|
},
|
|
|
|
week: function(next) {
|
|
|
|
db.sortedSetCount('ip:recent', now - terms.week, now, next);
|
|
|
|
},
|
|
|
|
month: function(next) {
|
|
|
|
db.sortedSetCount('ip:recent', now - terms.month, now, next);
|
|
|
|
},
|
|
|
|
alltime: function(next) {
|
|
|
|
db.sortedSetCount('ip:recent', 0, now, next);
|
|
|
|
}
|
|
|
|
}, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.fireEvent = function(socket, data, callback) {
|
|
|
|
index.server.sockets.emit(data.name, data.payload || {});
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.themes.getInstalled = function(socket, data, callback) {
|
|
|
|
meta.themes.get(callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.themes.set = function(socket, data, callback) {
|
|
|
|
if(!data) {
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
}
|
|
|
|
|
|
|
|
widgets.reset(function(err) {
|
|
|
|
meta.themes.set(data, function() {
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.themes.updateBranding = function(socket, data, callback) {
|
|
|
|
meta.css.updateBranding();
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.plugins.toggleActive = function(socket, plugin_id, callback) {
|
|
|
|
plugins.toggleActive(plugin_id, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.plugins.toggleInstall = function(socket, plugin_id, callback) {
|
|
|
|
plugins.toggleInstall(plugin_id, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.widgets.set = function(socket, data, callback) {
|
|
|
|
if(!data) {
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
}
|
|
|
|
|
|
|
|
widgets.setArea(data, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.config.get = function(socket, data, callback) {
|
|
|
|
meta.configs.list(callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.config.set = function(socket, data, callback) {
|
|
|
|
if(!data) {
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
}
|
|
|
|
|
|
|
|
meta.configs.set(data.key, data.value, function(err) {
|
|
|
|
if(err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
|
|
|
|
plugins.fireHook('action:config.set', {
|
|
|
|
key: data.key,
|
|
|
|
value: data.value
|
|
|
|
});
|
|
|
|
|
|
|
|
logger.monitorConfig({io: index.server}, data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.config.remove = function(socket, key) {
|
|
|
|
meta.configs.remove(key);
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.settings.get = function(socket, data, callback) {
|
|
|
|
meta.settings.get(data.hash, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
SocketAdmin.settings.set = function(socket, data, callback) {
|
|
|
|
meta.settings.set(data.hash, data.values, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SocketAdmin;
|