2014-04-05 01:09:40 +00:00
|
|
|
// Generated by CoffeeScript 1.7.1
|
|
|
|
|
|
2013-11-28 15:05:47 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
Request Handler
|
|
|
|
|
============
|
2014-02-19 13:14:08 +00:00
|
|
|
> The request handler (surprisingly) handles requests made through HTTP to
|
|
|
|
|
> the [HTTP Listener](http-listener.html). It will handle user requests for
|
|
|
|
|
> pages as well as POST requests such as user login, module storing, event
|
|
|
|
|
> invocation and also admin commands.
|
2014-04-05 01:09:40 +00:00
|
|
|
*/
|
2013-11-28 15:05:47 +00:00
|
|
|
|
|
|
|
|
(function() {
|
2014-04-21 12:42:26 +00:00
|
|
|
var crypto, db, dirHandlers, exports, fs, getHandlerPath, getRemoteScripts, getScript, getTemplate, mustache, path, pathUsers, qs, renderPage;
|
2013-11-28 15:05:47 +00:00
|
|
|
|
2014-02-13 17:16:03 +00:00
|
|
|
db = require('./persistence');
|
2013-11-28 15:05:47 +00:00
|
|
|
|
|
|
|
|
fs = require('fs');
|
|
|
|
|
|
|
|
|
|
path = require('path');
|
|
|
|
|
|
|
|
|
|
qs = require('querystring');
|
|
|
|
|
|
|
|
|
|
mustache = require('mustache');
|
|
|
|
|
|
|
|
|
|
crypto = require('crypto-js');
|
|
|
|
|
|
2014-04-21 12:42:26 +00:00
|
|
|
pathUsers = path.resolve(__dirname, '..', 'config', 'users.json');
|
|
|
|
|
|
2014-02-21 16:18:58 +00:00
|
|
|
dirHandlers = path.resolve(__dirname, '..', 'webpages', 'handlers');
|
|
|
|
|
|
2014-04-05 01:09:40 +00:00
|
|
|
exports = module.exports = (function(_this) {
|
|
|
|
|
return function(args) {
|
2014-04-06 19:36:34 +00:00
|
|
|
var fStoreUser, oUser, user, users;
|
2014-04-05 01:09:40 +00:00
|
|
|
_this.log = args.logger;
|
|
|
|
|
_this.userRequestHandler = args['request-service'];
|
|
|
|
|
_this.objAdminCmds = {
|
|
|
|
|
shutdown: function(obj, cb) {
|
|
|
|
|
var data;
|
|
|
|
|
data = {
|
|
|
|
|
code: 200,
|
|
|
|
|
message: 'Shutting down... BYE!'
|
|
|
|
|
};
|
|
|
|
|
setTimeout(args['shutdown-function'], 500);
|
|
|
|
|
return cb(null, data);
|
2014-04-21 12:42:26 +00:00
|
|
|
},
|
|
|
|
|
newuser: function(obj, cb) {
|
|
|
|
|
var data, err, fPersistNewUser, oUser, roles;
|
|
|
|
|
data = {
|
|
|
|
|
code: 200,
|
|
|
|
|
message: 'User stored thank you!'
|
|
|
|
|
};
|
|
|
|
|
if (obj.username && obj.password) {
|
|
|
|
|
if (obj.roles) {
|
|
|
|
|
try {
|
|
|
|
|
roles = JSON.parse(obj.roles);
|
|
|
|
|
} catch (_error) {
|
|
|
|
|
err = _error;
|
|
|
|
|
this.log('RH | error parsing newuser roles: ' + err.message);
|
|
|
|
|
roles = [];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
roles = [];
|
|
|
|
|
}
|
|
|
|
|
oUser = {
|
|
|
|
|
username: obj.username,
|
|
|
|
|
password: obj.password,
|
|
|
|
|
roles: roles
|
|
|
|
|
};
|
|
|
|
|
db.storeUser(oUser);
|
|
|
|
|
fPersistNewUser = function(username, password, roles) {
|
|
|
|
|
return function(err, data) {
|
|
|
|
|
var users;
|
|
|
|
|
users = JSON.parse(data);
|
|
|
|
|
users[username] = {
|
|
|
|
|
password: password,
|
|
|
|
|
roles: roles
|
|
|
|
|
};
|
|
|
|
|
return fs.writeFile(pathUsers, JSON.stringify(users, void 0, 2), 'utf8', function(err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
this.log.error("RH | Unable to write new user file! ");
|
|
|
|
|
return this.log.error(err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
fs.readFile(pathUsers, 'utf8', fPersistNewUser(obj.username, obj.password, roles));
|
|
|
|
|
} else {
|
|
|
|
|
data.code = 401;
|
|
|
|
|
data.message = 'Missing parameter for this command';
|
|
|
|
|
}
|
|
|
|
|
return cb(null, data);
|
2014-04-05 01:09:40 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
db(args);
|
2014-04-21 12:42:26 +00:00
|
|
|
users = JSON.parse(fs.readFileSync(pathUsers, 'utf8'));
|
2014-04-05 01:09:40 +00:00
|
|
|
fStoreUser = function(username, oUser) {
|
|
|
|
|
oUser.username = username;
|
|
|
|
|
return db.storeUser(oUser);
|
|
|
|
|
};
|
|
|
|
|
for (user in users) {
|
2014-04-06 19:36:34 +00:00
|
|
|
oUser = users[user];
|
|
|
|
|
fStoreUser(user, oUser);
|
2014-02-20 16:22:56 +00:00
|
|
|
}
|
2014-04-05 01:09:40 +00:00
|
|
|
return module.exports;
|
2014-02-20 16:22:56 +00:00
|
|
|
};
|
2014-04-05 01:09:40 +00:00
|
|
|
})(this);
|
|
|
|
|
|
2013-11-28 15:05:47 +00:00
|
|
|
|
|
|
|
|
/*
|
2013-11-28 18:14:05 +00:00
|
|
|
Handles possible events that were posted to this server and pushes them into the
|
|
|
|
|
event queue.
|
2013-11-28 15:05:47 +00:00
|
|
|
|
|
|
|
|
*Requires
|
|
|
|
|
the [request](http://nodejs.org/api/http.html#http_class_http_clientrequest)
|
|
|
|
|
and [response](http://nodejs.org/api/http.html#http_class_http_serverresponse)
|
|
|
|
|
objects.*
|
|
|
|
|
|
|
|
|
|
@public handleEvent( *req, resp* )
|
2014-04-05 01:09:40 +00:00
|
|
|
*/
|
2013-11-28 15:05:47 +00:00
|
|
|
|
|
|
|
|
exports.handleEvent = function(req, resp) {
|
|
|
|
|
var body;
|
|
|
|
|
body = '';
|
|
|
|
|
req.on('data', function(data) {
|
|
|
|
|
return body += data;
|
|
|
|
|
});
|
|
|
|
|
return req.on('end', function() {
|
2014-03-24 11:15:49 +00:00
|
|
|
var answ, err, obj, rand, timestamp;
|
2014-04-16 15:42:56 +00:00
|
|
|
try {
|
|
|
|
|
obj = JSON.parse(body);
|
|
|
|
|
} catch (_error) {
|
|
|
|
|
err = _error;
|
|
|
|
|
resp.send(400, 'Badly formed event!');
|
|
|
|
|
}
|
|
|
|
|
if (obj && obj.event && !err) {
|
2014-04-19 20:35:05 +00:00
|
|
|
timestamp = (new Date()).toISOString();
|
2014-04-16 15:42:56 +00:00
|
|
|
rand = (Math.floor(Math.random() * 10e9)).toString(16).toUpperCase();
|
2014-04-20 23:34:49 +00:00
|
|
|
obj.eventid = "" + obj.event + "_UTC|" + timestamp + "_" + rand;
|
2014-04-16 15:42:56 +00:00
|
|
|
answ = {
|
|
|
|
|
code: 200,
|
|
|
|
|
message: "Thank you for the event: " + obj.eventid
|
|
|
|
|
};
|
|
|
|
|
resp.send(answ.code, answ);
|
|
|
|
|
return db.pushEvent(obj);
|
2013-11-28 15:05:47 +00:00
|
|
|
} else {
|
2014-04-16 15:42:56 +00:00
|
|
|
return resp.send(400, 'Your event was missing important parameters!');
|
2013-11-28 15:05:47 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-05 01:09:40 +00:00
|
|
|
|
2013-11-28 15:05:47 +00:00
|
|
|
/*
|
2014-02-21 16:18:58 +00:00
|
|
|
Associates the user object with the session if login is successful.
|
2013-11-28 15:05:47 +00:00
|
|
|
|
|
|
|
|
*Requires
|
|
|
|
|
the [request](http://nodejs.org/api/http.html#http_class_http_clientrequest)
|
|
|
|
|
and [response](http://nodejs.org/api/http.html#http_class_http_serverresponse)
|
|
|
|
|
objects.*
|
|
|
|
|
|
|
|
|
|
@public handleLogin( *req, resp* )
|
2014-04-05 01:09:40 +00:00
|
|
|
*/
|
2014-04-02 21:08:05 +00:00
|
|
|
|
2014-04-05 01:09:40 +00:00
|
|
|
exports.handleLogin = (function(_this) {
|
|
|
|
|
return function(req, resp) {
|
|
|
|
|
var body;
|
|
|
|
|
body = '';
|
|
|
|
|
req.on('data', function(data) {
|
|
|
|
|
return body += data;
|
2014-04-05 00:05:51 +00:00
|
|
|
});
|
2014-04-05 01:09:40 +00:00
|
|
|
return req.on('end', function() {
|
|
|
|
|
var obj;
|
2014-04-06 19:36:34 +00:00
|
|
|
obj = JSON.parse(body);
|
2014-04-05 01:09:40 +00:00
|
|
|
return db.loginUser(obj.username, obj.password, function(err, usr) {
|
|
|
|
|
if (err) {
|
|
|
|
|
_this.log.warn("RH | AUTH-UH-OH ( " + obj.username + " ): " + err.message);
|
|
|
|
|
} else {
|
|
|
|
|
req.session.user = usr;
|
|
|
|
|
}
|
|
|
|
|
if (req.session.user) {
|
|
|
|
|
return resp.send('OK!');
|
|
|
|
|
} else {
|
|
|
|
|
return resp.send(401, 'NO!');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
})(this);
|
|
|
|
|
|
2013-11-28 15:05:47 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
A post request retrieved on this handler causes the user object to be
|
|
|
|
|
purged from the session, thus the user will be logged out.
|
|
|
|
|
|
|
|
|
|
*Requires
|
|
|
|
|
the [request](http://nodejs.org/api/http.html#http_class_http_clientrequest)
|
|
|
|
|
and [response](http://nodejs.org/api/http.html#http_class_http_serverresponse)
|
|
|
|
|
objects.*
|
|
|
|
|
|
|
|
|
|
@public handleLogout( *req, resp* )
|
2014-04-05 01:09:40 +00:00
|
|
|
*/
|
2013-11-28 15:05:47 +00:00
|
|
|
|
|
|
|
|
exports.handleLogout = function(req, resp) {
|
|
|
|
|
if (req.session) {
|
|
|
|
|
req.session.user = null;
|
|
|
|
|
return resp.send('Bye!');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-05 01:09:40 +00:00
|
|
|
|
2013-11-28 18:14:05 +00:00
|
|
|
/*
|
|
|
|
|
Resolves the path to a handler webpage.
|
|
|
|
|
|
|
|
|
|
@private getHandlerPath( *name* )
|
|
|
|
|
@param {String} name
|
2014-04-05 01:09:40 +00:00
|
|
|
*/
|
2013-11-28 18:14:05 +00:00
|
|
|
|
2013-11-28 15:05:47 +00:00
|
|
|
getHandlerPath = function(name) {
|
2014-02-21 16:18:58 +00:00
|
|
|
return path.join(dirHandlers, name + '.html');
|
2013-11-28 15:05:47 +00:00
|
|
|
};
|
|
|
|
|
|
2014-04-05 01:09:40 +00:00
|
|
|
|
2013-11-28 18:14:05 +00:00
|
|
|
/*
|
2014-02-21 16:18:58 +00:00
|
|
|
Fetches a template.
|
2013-11-28 18:14:05 +00:00
|
|
|
|
2014-02-21 16:18:58 +00:00
|
|
|
@private getTemplate( *name* )
|
2013-11-28 18:14:05 +00:00
|
|
|
@param {String} name
|
2014-04-05 01:09:40 +00:00
|
|
|
*/
|
2013-11-28 18:14:05 +00:00
|
|
|
|
2014-02-21 16:18:58 +00:00
|
|
|
getTemplate = function(name) {
|
|
|
|
|
var pth;
|
|
|
|
|
pth = path.join(dirHandlers, 'templates', name + '.html');
|
|
|
|
|
return fs.readFileSync(pth, 'utf8');
|
2013-11-28 15:05:47 +00:00
|
|
|
};
|
|
|
|
|
|
2014-04-05 01:09:40 +00:00
|
|
|
|
2014-02-10 21:28:10 +00:00
|
|
|
/*
|
2014-02-21 16:18:58 +00:00
|
|
|
Fetches a script.
|
2014-02-10 21:28:10 +00:00
|
|
|
|
2014-02-21 16:18:58 +00:00
|
|
|
@private getScript( *name* )
|
2014-02-10 21:28:10 +00:00
|
|
|
@param {String} name
|
2014-04-05 01:09:40 +00:00
|
|
|
*/
|
2014-02-10 21:28:10 +00:00
|
|
|
|
2014-02-21 16:18:58 +00:00
|
|
|
getScript = function(name) {
|
2014-02-10 21:28:10 +00:00
|
|
|
var pth;
|
2014-02-21 16:18:58 +00:00
|
|
|
pth = path.join(dirHandlers, 'js', name + '.js');
|
2014-02-10 21:28:10 +00:00
|
|
|
return fs.readFileSync(pth, 'utf8');
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-05 01:09:40 +00:00
|
|
|
|
2013-11-28 15:05:47 +00:00
|
|
|
/*
|
2014-02-21 16:18:58 +00:00
|
|
|
Fetches remote scripts snippets.
|
2013-11-29 17:41:55 +00:00
|
|
|
|
2014-02-21 16:18:58 +00:00
|
|
|
@private getRemoteScripts( *name* )
|
2013-11-29 17:41:55 +00:00
|
|
|
@param {String} name
|
2014-04-05 01:09:40 +00:00
|
|
|
*/
|
2013-11-29 17:41:55 +00:00
|
|
|
|
2014-02-21 16:18:58 +00:00
|
|
|
getRemoteScripts = function(name) {
|
|
|
|
|
var pth;
|
|
|
|
|
pth = path.join(dirHandlers, 'remote-scripts', name + '.html');
|
|
|
|
|
return fs.readFileSync(pth, 'utf8');
|
2013-11-29 17:41:55 +00:00
|
|
|
};
|
|
|
|
|
|
2014-04-05 01:09:40 +00:00
|
|
|
|
2013-11-29 17:41:55 +00:00
|
|
|
/*
|
2014-02-21 16:18:58 +00:00
|
|
|
Renders a page, with helps of mustache, depending on the user session and returns it.
|
2013-11-28 15:05:47 +00:00
|
|
|
|
2014-02-21 16:18:58 +00:00
|
|
|
@private renderPage( *name, sess, msg* )
|
|
|
|
|
@param {String} name
|
|
|
|
|
@param {Object} sess
|
|
|
|
|
@param {Object} msg
|
2014-04-05 01:09:40 +00:00
|
|
|
*/
|
2013-11-28 15:05:47 +00:00
|
|
|
|
2014-02-21 16:18:58 +00:00
|
|
|
renderPage = function(name, req, resp, msg) {
|
2014-02-23 23:59:49 +00:00
|
|
|
var code, content, data, err, menubar, page, pageElements, pathSkel, remote_scripts, script, skeleton;
|
2014-02-21 16:18:58 +00:00
|
|
|
pathSkel = path.join(dirHandlers, 'skeleton.html');
|
|
|
|
|
skeleton = fs.readFileSync(pathSkel, 'utf8');
|
|
|
|
|
code = 200;
|
|
|
|
|
data = {
|
2014-02-23 23:59:49 +00:00
|
|
|
message: msg,
|
|
|
|
|
user: req.session.user
|
2014-02-21 16:18:58 +00:00
|
|
|
};
|
|
|
|
|
try {
|
|
|
|
|
script = getScript(name);
|
|
|
|
|
} catch (_error) {}
|
|
|
|
|
try {
|
|
|
|
|
remote_scripts = getRemoteScripts(name);
|
|
|
|
|
} catch (_error) {}
|
|
|
|
|
try {
|
|
|
|
|
content = getTemplate(name);
|
|
|
|
|
} catch (_error) {
|
|
|
|
|
err = _error;
|
|
|
|
|
content = getTemplate('error');
|
|
|
|
|
script = getScript('error');
|
|
|
|
|
code = 404;
|
2014-02-23 23:59:49 +00:00
|
|
|
data.message = 'Invalid Page!';
|
2014-02-10 21:28:10 +00:00
|
|
|
}
|
2014-02-21 16:18:58 +00:00
|
|
|
if (req.session.user) {
|
|
|
|
|
menubar = getTemplate('menubar');
|
2013-11-28 15:05:47 +00:00
|
|
|
}
|
2014-02-23 23:59:49 +00:00
|
|
|
pageElements = {
|
2014-02-21 16:18:58 +00:00
|
|
|
content: content,
|
|
|
|
|
script: script,
|
|
|
|
|
remote_scripts: remote_scripts,
|
|
|
|
|
menubar: menubar
|
|
|
|
|
};
|
2014-02-23 23:59:49 +00:00
|
|
|
page = mustache.render(skeleton, pageElements);
|
|
|
|
|
return resp.send(code, mustache.render(page, data));
|
2013-11-29 17:41:55 +00:00
|
|
|
};
|
|
|
|
|
|
2014-04-05 01:09:40 +00:00
|
|
|
|
2013-11-29 17:41:55 +00:00
|
|
|
/*
|
2014-02-21 16:18:58 +00:00
|
|
|
Present the desired forge page to the user.
|
2013-11-29 17:41:55 +00:00
|
|
|
|
|
|
|
|
*Requires
|
|
|
|
|
the [request](http://nodejs.org/api/http.html#http_class_http_clientrequest)
|
|
|
|
|
and [response](http://nodejs.org/api/http.html#http_class_http_serverresponse)
|
|
|
|
|
objects.*
|
|
|
|
|
|
2014-02-21 16:18:58 +00:00
|
|
|
@public handleForge( *req, resp* )
|
2014-04-05 01:09:40 +00:00
|
|
|
*/
|
2013-11-29 17:41:55 +00:00
|
|
|
|
2014-02-21 16:18:58 +00:00
|
|
|
exports.handleForge = function(req, resp) {
|
|
|
|
|
var page;
|
|
|
|
|
page = req.query.page;
|
|
|
|
|
if (!req.session.user) {
|
|
|
|
|
page = 'login';
|
|
|
|
|
}
|
|
|
|
|
return renderPage(page, req, resp);
|
2013-11-29 17:41:55 +00:00
|
|
|
};
|
|
|
|
|
|
2014-04-05 01:09:40 +00:00
|
|
|
|
2013-12-08 21:59:04 +00:00
|
|
|
/*
|
|
|
|
|
Handles the user command requests.
|
|
|
|
|
|
|
|
|
|
*Requires
|
|
|
|
|
the [request](http://nodejs.org/api/http.html#http_class_http_clientrequest)
|
|
|
|
|
and [response](http://nodejs.org/api/http.html#http_class_http_serverresponse)
|
|
|
|
|
objects.*
|
|
|
|
|
|
|
|
|
|
@public handleUser( *req, resp* )
|
2014-04-05 01:09:40 +00:00
|
|
|
*/
|
2014-04-02 21:08:05 +00:00
|
|
|
|
2014-04-05 01:09:40 +00:00
|
|
|
exports.handleUserCommand = (function(_this) {
|
|
|
|
|
return function(req, resp) {
|
|
|
|
|
var body;
|
|
|
|
|
if (req.session && req.session.user) {
|
|
|
|
|
body = '';
|
|
|
|
|
req.on('data', function(data) {
|
|
|
|
|
return body += data;
|
2014-04-05 00:05:51 +00:00
|
|
|
});
|
2014-04-05 01:09:40 +00:00
|
|
|
return req.on('end', function() {
|
|
|
|
|
var obj;
|
|
|
|
|
obj = qs.parse(body);
|
|
|
|
|
return _this.userRequestHandler(req.session.user, obj, function(obj) {
|
|
|
|
|
return resp.send(obj.code, obj);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
return resp.send(401, 'Login first!');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
})(this);
|
|
|
|
|
|
2013-12-08 21:59:04 +00:00
|
|
|
|
2013-11-29 17:41:55 +00:00
|
|
|
/*
|
2014-02-21 16:18:58 +00:00
|
|
|
Present the admin console to the user if he's allowed to see it.
|
2013-11-28 15:05:47 +00:00
|
|
|
|
|
|
|
|
*Requires
|
|
|
|
|
the [request](http://nodejs.org/api/http.html#http_class_http_clientrequest)
|
|
|
|
|
and [response](http://nodejs.org/api/http.html#http_class_http_serverresponse)
|
|
|
|
|
objects.*
|
|
|
|
|
|
2014-02-21 16:18:58 +00:00
|
|
|
@public handleForge( *req, resp* )
|
2014-04-05 01:09:40 +00:00
|
|
|
*/
|
2013-11-28 15:05:47 +00:00
|
|
|
|
|
|
|
|
exports.handleAdmin = function(req, resp) {
|
2014-02-21 16:18:58 +00:00
|
|
|
var msg, page;
|
|
|
|
|
if (!req.session.user) {
|
|
|
|
|
page = 'login';
|
2014-04-21 12:42:26 +00:00
|
|
|
} else if (req.session.user.roles.indexOf("admin") === -1) {
|
2014-02-21 16:18:58 +00:00
|
|
|
page = 'login';
|
2014-04-21 12:42:26 +00:00
|
|
|
msg = 'You need to be admin for this page!';
|
2014-02-21 16:18:58 +00:00
|
|
|
} else {
|
|
|
|
|
page = 'admin';
|
|
|
|
|
}
|
|
|
|
|
return renderPage(page, req, resp, msg);
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-05 01:09:40 +00:00
|
|
|
|
2014-02-21 16:18:58 +00:00
|
|
|
/*
|
|
|
|
|
Handles the admin command requests.
|
|
|
|
|
|
|
|
|
|
*Requires
|
|
|
|
|
the [request](http://nodejs.org/api/http.html#http_class_http_clientrequest)
|
|
|
|
|
and [response](http://nodejs.org/api/http.html#http_class_http_serverresponse)
|
|
|
|
|
objects.*
|
|
|
|
|
|
|
|
|
|
@public handleAdminCommand( *req, resp* )
|
2014-04-05 01:09:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
exports.handleAdminCommand = (function(_this) {
|
|
|
|
|
return function(req, resp) {
|
|
|
|
|
var body;
|
2014-04-21 12:42:26 +00:00
|
|
|
if (req.session && req.session.user && req.session.user.roles.indexOf("admin") > -1) {
|
2014-04-05 01:09:40 +00:00
|
|
|
body = '';
|
|
|
|
|
req.on('data', function(data) {
|
|
|
|
|
return body += data;
|
|
|
|
|
});
|
|
|
|
|
return req.on('end', function() {
|
2014-04-21 12:42:26 +00:00
|
|
|
var arrCmd, arrKV, arrParams, keyVal, oParams, obj, _i, _len;
|
2014-04-05 01:09:40 +00:00
|
|
|
obj = qs.parse(body);
|
|
|
|
|
_this.log.info('RH | Received admin request: ' + obj.command);
|
2014-04-21 12:42:26 +00:00
|
|
|
arrCmd = obj.command.split(' ');
|
|
|
|
|
if (!arrCmd[0] || !_this.objAdminCmds[arrCmd[0]]) {
|
|
|
|
|
return resp.send(404, 'Command unknown!');
|
|
|
|
|
} else {
|
|
|
|
|
arrParams = arrCmd.slice(1);
|
|
|
|
|
oParams = {};
|
|
|
|
|
for (_i = 0, _len = arrParams.length; _i < _len; _i++) {
|
|
|
|
|
keyVal = arrParams[_i];
|
|
|
|
|
arrKV = keyVal.split(":");
|
|
|
|
|
if (arrKV.length === 2) {
|
|
|
|
|
oParams[arrKV[0]] = arrKV[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return _this.objAdminCmds[arrCmd[0]](oParams, function(err, obj) {
|
2014-04-05 01:09:40 +00:00
|
|
|
return resp.send(obj.code, obj);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
return resp.send(401, 'You need to be logged in as admin!');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
})(this);
|
2013-11-28 15:05:47 +00:00
|
|
|
|
|
|
|
|
}).call(this);
|