summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McLear <john@mclear.co.uk>2015-12-02 11:55:09 +0000
committerJohn McLear <john@mclear.co.uk>2015-12-02 11:55:09 +0000
commit01335bcf8dc00107a66a65e2c1d70c28f1dec718 (patch)
tree62b0a26c47b87927896b0ff6f4e8366fea83ee88
parent1a303f06b6429a710fd6d58cdfa2c2e30731afec (diff)
parent98016665e4acc0cc91ebf9ada53a1c3d52f20ba8 (diff)
downloadetherpad-lite-01335bcf8dc00107a66a65e2c1d70c28f1dec718.zip
Merge pull request #2851 from ether/plugin-hook-for-settings-earlier
Plugin hook for settings earlier
-rw-r--r--.gitignore1
-rw-r--r--settings.json.template3
-rwxr-xr-xsrc/node/server.js10
-rw-r--r--src/node/utils/Settings.js48
4 files changed, 51 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore
index 52d60dca..46773455 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,3 +17,4 @@ npm-debug.log
*.crt
*.key
bin/etherpad-1.deb
+credentials.json
diff --git a/settings.json.template b/settings.json.template
index f29bcbc0..ceb9efb3 100644
--- a/settings.json.template
+++ b/settings.json.template
@@ -2,6 +2,9 @@
This file must be valid JSON. But comments are allowed
Please edit settings.json, not settings.json.template
+
+ To still commit settings without credentials you can
+ store any credential settings in credentials.json
*/
{
// Name your instance!
diff --git a/src/node/server.js b/src/node/server.js
index 3cca9912..a8a49e17 100755
--- a/src/node/server.js
+++ b/src/node/server.js
@@ -74,16 +74,6 @@ async.waterfall([
// Call loadSettings hook
hooks.aCallAll("loadSettings", { settings: settings });
- // Call applySettings hook
- hooks.aCallAll("applySettings", settings, function(err, newSettings){
- if(!newSettings) return;
- newSettings.forEach(function (settingsBlob){
- for (var setting in settingsBlob){
- settings[setting] = settingsBlob[setting];
- };
- });
- });
- callback();
},
//initalize the http server
diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js
index f76cebdc..325a997a 100644
--- a/src/node/utils/Settings.js
+++ b/src/node/utils/Settings.js
@@ -255,13 +255,20 @@ exports.reloadSettings = function reloadSettings() {
// Discover where the settings file lives
var settingsFilename = argv.settings || "settings.json";
+ // Discover if a credential file exists
+ var credentialsFilename = argv.credentials || "credentials.json";
+
if (path.resolve(settingsFilename)===settingsFilename) {
settingsFilename = path.resolve(settingsFilename);
} else {
settingsFilename = path.resolve(path.join(exports.root, settingsFilename));
}
- var settingsStr;
+ if (path.resolve(credentialsFilename)===credentialsFilename) {
+ credentialsFilename = path.resolve(credentialsFilename);
+ }
+
+ var settingsStr, credentialsStr;
try{
//read the settings sync
settingsStr = fs.readFileSync(settingsFilename).toString();
@@ -269,8 +276,16 @@ exports.reloadSettings = function reloadSettings() {
console.warn('No settings file found. Continuing using defaults!');
}
+ try{
+ //read the credentials sync
+ credentialsStr = fs.readFileSync(credentialsFilename).toString();
+ } catch(e){
+ // Doesn't matter if no credentials file found..
+ }
+
// try to parse the settings
var settings;
+ var credentials;
try {
if(settingsStr) {
settingsStr = jsonminify(settingsStr).replace(",]","]").replace(",}","}");
@@ -281,6 +296,11 @@ exports.reloadSettings = function reloadSettings() {
process.exit(1);
}
+ if(credentialsStr) {
+ credentialsStr = jsonminify(credentialsStr).replace(",]","]").replace(",}","}");
+ credentials = JSON.parse(credentialsStr);
+ }
+
//loop trough the settings
for(var i in settings)
{
@@ -307,6 +327,32 @@ exports.reloadSettings = function reloadSettings() {
}
}
+ //loop trough the settings
+ for(var i in credentials)
+ {
+ //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)
+ {
+ if (_.isObject(credentials[i]) && !_.isArray(credentials[i])) {
+ exports[i] = _.defaults(credentials[i], exports[i]);
+ } else {
+ exports[i] = credentials[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");
+ }
+ }
+
log4js.configure(exports.logconfig);//Configure the logging appenders
log4js.setGlobalLogLevel(exports.loglevel);//set loglevel
process.env['DEBUG'] = 'socket.io:' + exports.loglevel; // Used by SocketIO for Debug