pad.libre-service.eu-etherpad/src/node/utils/Settings.js

210 lines
5.8 KiB
JavaScript
Raw Normal View History

2011-05-14 18:42:04 +02:00
/**
2011-05-30 16:53:11 +02:00
* The Settings Modul reads the settings out of settings.json and provides
* this information to the other modules
*/
/*
* 2011 Peter 'Pita' Martischka (Primary Technology Ltd)
2011-05-14 18:42:04 +02:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2011-05-14 18:22:25 +02:00
var fs = require("fs");
var os = require("os");
var path = require('path');
var argv = require('./Cli').argv;
var npm = require("npm/lib/npm.js");
2012-07-08 18:59:46 +02:00
var vm = require('vm');
2013-01-13 12:20:49 +01:00
var log4js = require("log4js");
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
/* Root path of the installation */
exports.root = path.normalize(path.join(npm.dir, ".."));
2011-05-14 18:22:25 +02:00
/**
* The app title, visible e.g. in the browser window
*/
2013-08-23 00:32:25 +02:00
exports.title = "Etherpad";
/**
* The app favicon fully specified url, visible e.g. in the browser window
*/
exports.favicon = "favicon.ico";
2012-11-30 23:50:54 +01:00
exports.faviconPad = "../" + exports.favicon;
exports.faviconTimeslider = "../../" + exports.favicon;
/**
* The IP ep-lite should listen to
*/
exports.ip = "0.0.0.0";
2011-05-30 16:53:11 +02:00
/**
* The Port ep-lite should listen to
*/
exports.port = process.env.PORT || 9001;
2012-11-22 10:12:58 +01:00
/**
* The SSL signed server key and the Certificate Authority's own certificate
* default case: ep-lite does *not* use SSL. A signed server key is not required in this case.
*/
exports.ssl = false;
2012-12-02 18:28:28 +01:00
/**
2012-12-02 18:44:39 +01:00
* socket.io transport methods
2012-12-02 18:28:28 +01:00
**/
exports.socketTransportProtocols = ['xhr-polling', 'jsonp-polling', 'htmlfile'];
2011-05-30 16:53:11 +02:00
/*
* The Type of the database
*/
exports.dbType = "dirty";
2011-05-30 16:53:11 +02:00
/**
* This setting is passed with dbType to ueberDB to set up the database
*/
exports.dbSettings = { "filename" : path.join(exports.root, "dirty.db") };
2012-07-08 18:59:46 +02:00
2011-05-30 16:53:11 +02:00
/**
* The default Text of a new pad
*/
2013-08-23 00:32:25 +02:00
exports.defaultPadText = "Welcome to Etherpad!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nEtherpad on Github: http:\/\/j.mp/ep-lite\n";
/**
* A flag that requires any user to have a valid session (via the api) before accessing a pad
*/
exports.requireSession = false;
2011-11-21 18:44:33 +01:00
/**
* A flag that prevents users from creating new pads
*/
exports.editOnly = false;
/**
* Max age that responses will have (affects caching layer).
*/
exports.maxAge = 1000*60*60*6; // 6 hours
2011-05-30 16:53:11 +02:00
/**
* A flag that shows if minification is enabled or not
*/
exports.minify = true;
2011-05-14 18:22:25 +02:00
/**
* The path of the abiword executable
*/
exports.abiword = null;
2011-08-17 18:45:47 +02:00
/**
* The log level of log4js
*/
exports.loglevel = "INFO";
2013-01-13 12:20:49 +01:00
/*
* log4js appender configuration
*/
exports.logconfig = { appenders: [{ type: "console" }]};
/*
* Session Key, do not sure this.
*/
exports.sessionKey = false;
/*
* Trust Proxy, whether or not trust the x-forwarded-for header.
*/
exports.trustProxy = false;
2012-04-19 14:25:12 +02:00
/* This setting is used if you need authentication and/or
* authorization. Note: /admin always requires authentication, and
* either authorization by a module, or a user with is_admin set */
exports.requireAuthentication = false;
exports.requireAuthorization = false;
exports.users = {};
2012-04-02 18:45:37 +02:00
//checks if abiword is avaiable
exports.abiwordAvailable = function()
{
if(exports.abiword != null)
{
return os.type().indexOf("Windows") != -1 ? "withoutPDF" : "yes";
}
else
{
return "no";
}
};
2012-11-06 17:35:05 +01:00
exports.reloadSettings = function reloadSettings() {
// Discover where the settings file lives
var settingsFilename = argv.settings || "settings.json";
2013-03-16 09:47:10 +01:00
settingsFilename = path.resolve(path.join(exports.root, settingsFilename));
2012-11-06 17:35:05 +01:00
var settingsStr;
try{
//read the settings sync
settingsStr = fs.readFileSync(settingsFilename).toString();
} catch(e){
console.warn('No settings file found. Continuing using defaults!');
2012-07-08 18:59:46 +02:00
}
2011-05-14 18:22:25 +02:00
2012-11-06 17:35:05 +01:00
// try to parse the settings
var settings;
try {
if(settingsStr) {
settings = vm.runInContext('exports = '+settingsStr, vm.createContext(), "settings.json");
settings = JSON.parse(JSON.stringify(settings)); // fix objects having constructors of other vm.context
2012-11-06 17:35:05 +01:00
}
}catch(e){
console.error('There was an error processing your settings.json file: '+e.message);
process.exit(1);
2011-05-14 18:22:25 +02:00
}
2012-11-06 17:35:05 +01:00
//loop trough the settings
for(var i in settings)
2011-05-14 18:22:25 +02:00
{
2012-11-06 17:35:05 +01:00
//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");
}
2011-05-14 18:22:25 +02:00
}
2013-01-13 12:20:49 +01:00
log4js.configure(exports.logconfig);//Configure the logging appenders
log4js.setGlobalLogLevel(exports.loglevel);//set loglevel
log4js.replaceConsole();
2012-11-06 17:35:05 +01:00
if(!exports.sessionKey){ // If the secretKey isn't set we also create yet another unique value here
exports.sessionKey = randomString(32);
console.warn("You need to set a sessionKey value in settings.json, this will allow your users to reconnect to your Etherpad Instance if your instance restarts");
}
2012-11-06 17:35:05 +01:00
if(exports.dbType === "dirty"){
console.warn("DirtyDB is used. This is fine for testing but not recommended for production.");
2011-05-14 18:22:25 +02:00
}
};
2012-04-20 17:03:37 +02:00
2012-11-06 17:35:05 +01:00
// initially load settings
exports.reloadSettings();