From 0617f8168917ff6b7fe559bef386a225d0c75721 Mon Sep 17 00:00:00 2001 From: John McLear Date: Wed, 2 Dec 2015 11:53:41 +0000 Subject: [PATCH 1/2] remove applySettings hook and allow credentials.json to be part of core --- .gitignore | 1 + settings.json.template | 3 +++ 2 files changed, 4 insertions(+) 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! From 98016665e4acc0cc91ebf9ada53a1c3d52f20ba8 Mon Sep 17 00:00:00 2001 From: John McLear Date: Wed, 2 Dec 2015 11:54:37 +0000 Subject: [PATCH 2/2] working logic --- src/node/server.js | 10 -------- src/node/utils/Settings.js | 48 +++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 11 deletions(-) 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