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-08-11 16:26:41 +02:00
* 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" ) ;
2011-12-18 06:18:35 +01:00
var os = require ( "os" ) ;
2012-01-05 11:24:33 +01:00
var path = require ( 'path' ) ;
2012-02-21 20:20:45 +01:00
var argv = require ( './Cli' ) . argv ;
2012-02-26 13:07:51 +01:00
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" ) ;
2013-02-13 22:51:09 +01:00
var randomString = require ( 'ep_etherpad-lite/static/js/pad_utils' ) . randomString ;
2012-02-26 13:07:51 +01:00
/* Root path of the installation */
exports . root = path . normalize ( path . join ( npm . dir , ".." ) ) ;
2011-05-14 18:22:25 +02:00
2012-11-02 12:30:57 +01:00
/ * *
* The app title , visible e . g . in the browser window
* /
2013-08-23 00:32:25 +02:00
exports . title = "Etherpad" ;
2012-11-02 12:30:57 +01:00
2012-11-04 11:26:17 +01:00
/ * *
* 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 ;
2012-11-04 11:26:17 +01:00
2011-07-30 17:39:53 +02:00
/ * *
* 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
* /
2012-10-25 19:21:34 +02:00
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
* /
2011-08-17 20:26:56 +02:00
exports . dbType = "dirty" ;
2011-05-30 16:53:11 +02:00
/ * *
* This setting is passed with dbType to ueberDB to set up the database
* /
2012-04-20 22:39:16 +02:00
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" ;
2011-11-21 07:45:37 +01:00
/ * *
* 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 ;
2012-02-07 08:04:02 +01:00
/ * *
* 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
* /
2011-05-28 19:09:17 +02:00
exports . minify = true ;
2011-05-14 18:22:25 +02:00
2011-07-19 20:48:11 +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" } ] } ;
2013-02-13 22:51:09 +01:00
/ *
* Session Key , do not sure this .
* /
exports . sessionKey = false ;
2013-04-24 12:19:41 +02:00
/ *
* Trust Proxy , whether or not trust the x - forwarded - for header .
* /
exports . trustProxy = false ;
2012-04-19 14:25:12 +02:00
/ * T h i s s e t t i n g i s u s e d i f y o u n e e d a u t h e n t i c a t i o n a n d / o r
* authorization . Note : / a d m i n a l w a y s r e q u i r e s a u t h e n t i c a t i o n , a n d
* 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
2011-12-18 06:18:35 +01:00
//checks if abiword is avaiable
exports . abiwordAvailable = function ( )
{
if ( exports . abiword != null )
{
return os . type ( ) . indexOf ( "Windows" ) != - 1 ? "withoutPDF" : "yes" ;
}
else
{
return "no" ;
}
2013-03-24 01:18:44 +01:00
} ;
2011-12-18 06:18:35 +01:00
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" ) ;
2013-03-24 01:18:44 +01:00
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
2013-02-13 22:51:09 +01:00
if ( ! exports . sessionKey ) { // If the secretKey isn't set we also create yet another unique value here
2013-02-13 22:53:15 +01:00
exports . sessionKey = randomString ( 32 ) ;
2013-02-13 22:51:09 +01:00
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" ) {
2013-03-24 01:18:44 +01:00
console . warn ( "DirtyDB is used. This is fine for testing but not recommended for production." ) ;
2011-05-14 18:22:25 +02:00
}
2013-03-24 01:18:44 +01:00
} ;
2012-04-20 17:03:37 +02:00
2012-11-06 17:35:05 +01:00
// initially load settings
exports . reloadSettings ( ) ;