summaryrefslogtreecommitdiff
path: root/src/node/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'src/node/hooks')
-rw-r--r--src/node/hooks/express/adminplugins.js51
-rw-r--r--src/node/hooks/express/specialpages.js16
-rw-r--r--src/node/hooks/express/static.js17
-rw-r--r--src/node/hooks/express/webaccess.js29
4 files changed, 96 insertions, 17 deletions
diff --git a/src/node/hooks/express/adminplugins.js b/src/node/hooks/express/adminplugins.js
new file mode 100644
index 00000000..fa7e7077
--- /dev/null
+++ b/src/node/hooks/express/adminplugins.js
@@ -0,0 +1,51 @@
+var path = require('path');
+var eejs = require('ep_etherpad-lite/node/eejs');
+var installer = require('ep_etherpad-lite/static/js/pluginfw/installer');
+var plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins');
+
+exports.expressCreateServer = function (hook_name, args, cb) {
+ args.app.get('/admin/plugins', function(req, res) {
+ var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
+ var render_args = {
+ plugins: plugins.plugins,
+ search_results: {},
+ errors: [],
+ };
+
+ res.send(eejs.require(
+ "ep_etherpad-lite/templates/admin/plugins.html",
+ render_args), {});
+ });
+}
+
+exports.socketio = function (hook_name, args, cb) {
+ var io = args.io.of("/pluginfw/installer");
+ io.on('connection', function (socket) {
+ socket.on("load", function (query) {
+ socket.emit("installed-results", {results: plugins.plugins});
+ });
+
+ socket.on("search", function (query) {
+ socket.emit("progress", {progress:0, message:'Fetching results...'});
+ installer.search(query, function (progress) {
+ if (progress.results)
+ socket.emit("search-result", progress);
+ socket.emit("progress", progress);
+ });
+ });
+
+ socket.on("install", function (plugin_name) {
+ socket.emit("progress", {progress:0, message:'Downloading and installing ' + plugin_name + "..."});
+ installer.install(plugin_name, function (progress) {
+ socket.emit("progress", progress);
+ });
+ });
+
+ socket.on("uninstall", function (plugin_name) {
+ socket.emit("progress", {progress:0, message:'Uninstalling ' + plugin_name + "..."});
+ installer.uninstall(plugin_name, function (progress) {
+ socket.emit("progress", progress);
+ });
+ });
+ });
+}
diff --git a/src/node/hooks/express/specialpages.js b/src/node/hooks/express/specialpages.js
index 13cfd821..474f475e 100644
--- a/src/node/hooks/express/specialpages.js
+++ b/src/node/hooks/express/specialpages.js
@@ -1,32 +1,32 @@
var path = require('path');
+var eejs = require('ep_etherpad-lite/node/eejs');
exports.expressCreateServer = function (hook_name, args, cb) {
//serve index.html under /
args.app.get('/', function(req, res)
{
- var filePath = path.normalize(__dirname + "/../../../static/index.html");
- res.sendfile(filePath, { maxAge: exports.maxAge });
+ res.send(eejs.require("ep_etherpad-lite/templates/index.html"));
});
//serve robots.txt
args.app.get('/robots.txt', function(req, res)
{
var filePath = path.normalize(__dirname + "/../../../static/robots.txt");
- res.sendfile(filePath, { maxAge: exports.maxAge });
+ res.sendfile(filePath);
});
//serve favicon.ico
args.app.get('/favicon.ico', function(req, res)
{
var filePath = path.normalize(__dirname + "/../../../static/custom/favicon.ico");
- res.sendfile(filePath, { maxAge: exports.maxAge }, function(err)
+ res.sendfile(filePath, function(err)
{
//there is no custom favicon, send the default favicon
if(err)
{
filePath = path.normalize(__dirname + "/../../../static/favicon.ico");
- res.sendfile(filePath, { maxAge: exports.maxAge });
+ res.sendfile(filePath);
}
});
});
@@ -34,15 +34,13 @@ exports.expressCreateServer = function (hook_name, args, cb) {
//serve pad.html under /p
args.app.get('/p/:pad', function(req, res, next)
{
- var filePath = path.normalize(__dirname + "/../../../static/pad.html");
- res.sendfile(filePath, { maxAge: exports.maxAge });
+ res.send(eejs.require("ep_etherpad-lite/templates/pad.html"));
});
//serve timeslider.html under /p/$padname/timeslider
args.app.get('/p/:pad/timeslider', function(req, res, next)
{
- var filePath = path.normalize(__dirname + "/../../../static/timeslider.html");
- res.sendfile(filePath, { maxAge: exports.maxAge });
+ res.send(eejs.require("ep_etherpad-lite/templates/timeslider.html"));
});
} \ No newline at end of file
diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js
index 9209967c..f284e478 100644
--- a/src/node/hooks/express/static.js
+++ b/src/node/hooks/express/static.js
@@ -6,6 +6,7 @@ var settings = require("../../utils/Settings");
var Yajsml = require('yajsml');
var fs = require("fs");
var ERR = require("async-stacktrace");
+var _ = require("underscore");
exports.expressCreateServer = function (hook_name, args, cb) {
// Cache both minified and static.
@@ -35,8 +36,22 @@ exports.expressCreateServer = function (hook_name, args, cb) {
// serve plugin definitions
// not very static, but served here so that client can do require("pluginfw/static/js/plugin-definitions.js");
args.app.get('/pluginfw/plugin-definitions.json', function (req, res, next) {
+
+ var clientParts = _(plugins.parts)
+ .filter(function(part){ return _(part).has('client_hooks') });
+
+ var clientPlugins = {};
+
+ _(clientParts).chain()
+ .map(function(part){ return part.plugin })
+ .uniq()
+ .each(function(name){
+ clientPlugins[name] = _(plugins.plugins[name]).clone();
+ delete clientPlugins[name]['package'];
+ });
+
res.header("Content-Type","application/json; charset=utf-8");
- res.write(JSON.stringify({"plugins": plugins.plugins, "parts": plugins.parts}));
+ res.write(JSON.stringify({"plugins": clientPlugins, "parts": clientParts}));
res.end();
});
}
diff --git a/src/node/hooks/express/webaccess.js b/src/node/hooks/express/webaccess.js
index 8e9f967a..d0e28737 100644
--- a/src/node/hooks/express/webaccess.js
+++ b/src/node/hooks/express/webaccess.js
@@ -6,14 +6,30 @@ var settings = require('../../utils/Settings');
//checks for basic http auth
exports.basicAuth = function (req, res, next) {
- if (req.headers.authorization && req.headers.authorization.search('Basic ') === 0) {
- // fetch login and password
- if (new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString() == settings.httpAuth) {
- next();
- return;
+
+ // When handling HTTP-Auth, an undefined password will lead to no authorization at all
+ var pass = settings.httpAuth || '';
+
+ if (req.path.indexOf('/admin') == 0) {
+ var pass = settings.adminHttpAuth;
+
+ }
+
+ // Just pass if password is an empty string
+ if (pass === '') {
+ return next();
+ }
+
+
+ // If a password has been set and auth headers are present...
+ if (pass && req.headers.authorization && req.headers.authorization.search('Basic ') === 0) {
+ // ...check login and password
+ if (new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString() === pass) {
+ return next();
}
}
+ // Otherwise return Auth required Headers, delayed for 1 second, if auth failed.
res.header('WWW-Authenticate', 'Basic realm="Protected Area"');
if (req.headers.authorization) {
setTimeout(function () {
@@ -25,8 +41,7 @@ exports.basicAuth = function (req, res, next) {
}
exports.expressConfigure = function (hook_name, args, cb) {
- // Activate http basic auth if it has been defined in settings.json
- if(settings.httpAuth != null) args.app.use(exports.basicAuth);
+ args.app.use(exports.basicAuth);
// If the log level specified in the config file is WARN or ERROR the application server never starts listening to requests as reported in issue #158.
// Not installing the log4js connect logger when the log level has a higher severity than INFO since it would not log at that level anyway.