2012-11-02 14:16:15 +01:00
|
|
|
var path = require('path');
|
|
|
|
var eejs = require('ep_etherpad-lite/node/eejs');
|
|
|
|
var installer = require('ep_etherpad-lite/static/js/pluginfw/installer');
|
2012-11-02 16:21:12 +01:00
|
|
|
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
|
2012-11-02 14:16:15 +01:00
|
|
|
var fs = require('fs');
|
|
|
|
|
|
|
|
exports.expressCreateServer = function (hook_name, args, cb) {
|
|
|
|
args.app.get('/admin/settings', function(req, res) {
|
|
|
|
|
|
|
|
var render_args = {
|
|
|
|
settings: "",
|
|
|
|
search_results: {},
|
|
|
|
errors: []
|
|
|
|
};
|
|
|
|
|
|
|
|
res.send( eejs.require("ep_etherpad-lite/templates/admin/settings.html", render_args) );
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.socketio = function (hook_name, args, cb) {
|
|
|
|
var io = args.io.of("/settings");
|
|
|
|
io.on('connection', function (socket) {
|
|
|
|
if (!socket.handshake.session.user || !socket.handshake.session.user.is_admin) return;
|
|
|
|
|
|
|
|
socket.on("load", function (query) {
|
|
|
|
fs.readFile('settings.json', 'utf8', function (err,data) {
|
|
|
|
if (err) {
|
|
|
|
return console.log(err);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
socket.emit("settings", {results: data});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-11-02 16:10:01 +01:00
|
|
|
socket.on("saveSettings", function (settings) {
|
|
|
|
fs.writeFile('settings.json', settings, function (err) {
|
|
|
|
if (err) throw err;
|
|
|
|
socket.emit("saveprogress", "saved");
|
2012-11-02 14:16:15 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-11-02 16:21:12 +01:00
|
|
|
socket.on("restartServer", function () {
|
|
|
|
console.log("Admin request to restart server through a socket on /admin/settings");
|
|
|
|
hooks.aCallAll("restartServer", {}, function () {});
|
2012-11-02 14:16:15 +01:00
|
|
|
|
|
|
|
});
|
2012-11-02 16:21:12 +01:00
|
|
|
|
2012-11-02 14:16:15 +01:00
|
|
|
});
|
|
|
|
}
|