diff options
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/hooks/express/admin.js | 7 | ||||
-rw-r--r-- | src/node/hooks/express/adminsettings.js | 54 | ||||
-rw-r--r-- | src/node/hooks/express/specialpages.js | 27 | ||||
-rw-r--r-- | src/node/utils/Settings.js | 85 |
4 files changed, 122 insertions, 51 deletions
diff --git a/src/node/hooks/express/admin.js b/src/node/hooks/express/admin.js index 83bada22..766370fc 100644 --- a/src/node/hooks/express/admin.js +++ b/src/node/hooks/express/admin.js @@ -1,5 +1,8 @@ +var eejs = require('ep_etherpad-lite/node/eejs'); + exports.expressCreateServer = function (hook_name, args, cb) { args.app.get('/admin', function(req, res) { - res.send( 501, 'Not Implemented, yet. Meanwhile go to <a href="/admin/plugins">/admin/plugins</a>' ); + res.send( eejs.require("ep_etherpad-lite/templates/admin/index.html", {}) ); }); -};
\ No newline at end of file +} + diff --git a/src/node/hooks/express/adminsettings.js b/src/node/hooks/express/adminsettings.js new file mode 100644 index 00000000..2a48d289 --- /dev/null +++ b/src/node/hooks/express/adminsettings.js @@ -0,0 +1,54 @@ +var path = require('path'); +var eejs = require('ep_etherpad-lite/node/eejs'); +var settings = require('ep_etherpad-lite/node/utils/Settings'); +var installer = require('ep_etherpad-lite/static/js/pluginfw/installer'); +var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks"); +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}); + } + }); + }); + + socket.on("saveSettings", function (settings) { + fs.writeFile('settings.json', settings, function (err) { + if (err) throw err; + socket.emit("saveprogress", "saved"); + }); + }); + + socket.on("restartServer", function () { + console.log("Admin request to restart server through a socket on /admin/settings"); + settings.reloadSettings(); + hooks.aCallAll("restartServer", {}, function () {}); + + }); + + }); +} diff --git a/src/node/hooks/express/specialpages.js b/src/node/hooks/express/specialpages.js index 50d27700..44002461 100644 --- a/src/node/hooks/express/specialpages.js +++ b/src/node/hooks/express/specialpages.js @@ -24,8 +24,20 @@ exports.expressCreateServer = function (hook_name, args, cb) { }); }); - //serve favicon.ico - args.app.get('/favicon.ico', function(req, res) + //serve pad.html under /p + args.app.get('/p/:pad', function(req, res, next) + { + res.send(eejs.require("ep_etherpad-lite/templates/pad.html", {req: req})); + }); + + //serve timeslider.html under /p/$padname/timeslider + args.app.get('/p/:pad/timeslider', function(req, res, next) + { + res.send(eejs.require("ep_etherpad-lite/templates/timeslider.html", {req: req})); + }); + + //serve favicon.ico from all path levels except as a pad name + args.app.get( /\/favicon.ico$/, function(req, res) { var filePath = path.normalize(__dirname + "/../../../static/custom/favicon.ico"); res.sendfile(filePath, function(err) @@ -39,16 +51,5 @@ exports.expressCreateServer = function (hook_name, args, cb) { }); }); - //serve pad.html under /p - args.app.get('/p/:pad', function(req, res, next) - { - res.send(eejs.require("ep_etherpad-lite/templates/pad.html", {req: req})); - }); - - //serve timeslider.html under /p/$padname/timeslider - args.app.get('/p/:pad/timeslider', function(req, res, next) - { - res.send(eejs.require("ep_etherpad-lite/templates/timeslider.html", {req: req})); - }); }
\ No newline at end of file diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js index 38c98287..2ed76d0b 100644 --- a/src/node/utils/Settings.js +++ b/src/node/utils/Settings.js @@ -35,6 +35,11 @@ exports.root = path.normalize(path.join(npm.dir, "..")); exports.title = "Etherpad Lite"; /** + * The app favicon fully specified url, visible e.g. in the browser window + */ +exports.favicon = "favicon.ico"; + +/** * The IP ep-lite should listen to */ exports.ip = "0.0.0.0"; @@ -107,50 +112,58 @@ exports.abiwordAvailable = function() } } -// Discover where the settings file lives -var settingsFilename = argv.settings || "settings.json"; -settingsFilename = path.resolve(path.join(root, settingsFilename)); -var settingsStr; -try{ - //read the settings sync - settingsStr = fs.readFileSync(settingsFilename).toString(); -} catch(e){ - console.warn('No settings file found. Continuing using defaults!'); -} -// try to parse the settings -var settings; -try { - if(settingsStr) { - settings = vm.runInContext('exports = '+settingsStr, vm.createContext(), "settings.json"); +exports.reloadSettings = function reloadSettings() { + // Discover where the settings file lives + var settingsFilename = argv.settings || "settings.json"; + settingsFilename = path.resolve(path.join(root, settingsFilename)); + + var settingsStr; + try{ + //read the settings sync + settingsStr = fs.readFileSync(settingsFilename).toString(); + } catch(e){ + console.warn('No settings file found. Continuing using defaults!'); } -}catch(e){ - console.error('There was an error processing your settings.json file: '+e.message); - process.exit(1); -} -//loop trough the settings -for(var i in settings) -{ - //test if the setting start with a low character - if(i.charAt(0).search("[a-z]") !== 0) - { - console.warn("Settings should start with a low character: '" + i + "'"); + // try to parse the settings + var settings; + try { + if(settingsStr) { + settings = vm.runInContext('exports = '+settingsStr, vm.createContext(), "settings.json"); + } + }catch(e){ + console.error('There was an error processing your settings.json file: '+e.message); + process.exit(1); } - //we know this setting, so we overwrite it - if(exports[i] !== undefined) + //loop trough the settings + for(var i in settings) { - exports[i] = settings[i]; + //test if the setting start with a low character + if(i.charAt(0).search("[a-z]") !== 0) + { + console.warn("Settings should start with a low character: '" + i + "'"); + } + + //we know this setting, so we overwrite it + //or it's a settings hash, specific to a plugin + if(exports[i] !== undefined || i.indexOf('ep_')==0) + { + exports[i] = settings[i]; + } + //this setting is unkown, output a warning and throw it away + else + { + console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed"); + } } - //this setting is unkown, output a warning and throw it away - else - { - console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed"); + + if(exports.dbType === "dirty"){ + console.warn("DirtyDB is used. This is fine for testing but not recommended for production.") } } -if(exports.dbType === "dirty"){ - console.warn("DirtyDB is used. This is fine for testing but not recommended for production.") -} +// initially load settings +exports.reloadSettings(); |