initial rewrite

This commit is contained in:
booo 2012-02-09 02:09:17 +01:00
parent e6e81135a7
commit c19444f6c9
12 changed files with 777 additions and 697 deletions

View file

@ -1,5 +1,5 @@
/**
* The Settings Modul reads the settings out of settings.json and provides
* The Settings Modul reads the settings out of settings.json and provides
* this information to the other modules
*/
@ -23,109 +23,103 @@ var fs = require("fs");
var os = require("os");
var path = require('path');
var defaults = {};
/**
* The IP ep-lite should listen to
*/
exports.ip = "0.0.0.0";
defaults.ip = "0.0.0.0";
/**
* The Port ep-lite should listen to
*/
exports.port = 9001;
defaults.port = 9001;
/*
* The Type of the database
*/
exports.dbType = "dirty";
defaults.dbType = "dirty";
/**
* This setting is passed with dbType to ueberDB to set up the database
*/
exports.dbSettings = { "filename" : "../var/dirty.db" };
defaults.dbSettings = { "filename" : "../var/dirty.db" };
/**
* The default Text of a new pad
*/
exports.defaultPadText = "Welcome to Etherpad Lite!\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 Lite on Github: http:\/\/j.mp/ep-lite\n";
defaults.defaultPadText = "Welcome to Etherpad Lite!\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 Lite 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;
defaults.requireSession = false;
/**
* A flag that prevents users from creating new pads
*/
exports.editOnly = false;
defaults.editOnly = false;
/**
* A flag that shows if minification is enabled or not
*/
exports.minify = true;
defaults.minify = true;
/**
* The path of the abiword executable
*/
exports.abiword = null;
defaults.abiword = null;
/**
* The log level of log4js
*/
exports.loglevel = "INFO";
defaults.logLevel = "INFO";
/**
* Http basic auth, with "user:password" format
*/
exports.httpAuth = null;
defaults.httpAuth = null;
//checks if abiword is avaiable
exports.abiwordAvailable = function()
{
if(exports.abiword != null)
{
return os.type().indexOf("Windows") != -1 ? "withoutPDF" : "yes";
}
else
{
return "no";
}
}
var Settings = function(settings) {
this.ip = settings.ip || defaults.ip;
this.port = settings.port || defaults.port;
this.dbType = settings.dbType || defaults.dbType;
this.dbSettings = settings.dbSettings || defaults.dbSettings;
this.defaultPadText = settings.defaultPadText || defaults.defaultPadText;
this.requireSessions = settings.requireSessions || defaults.requireSessions;
this.editOnly = settings.editOnly || defaults.editOnly;
this.minify = settings.minify || defaults.minify;
this.abiword = settings.abiword || defaults.abiword;
this.logLevel = settings.logLevel || defaults.logLevel;
this.httpAuth = settings.httpAuth || defaults.httpAuth;
};
//TODO this is shit
Settings.prototype.abiwordAvailable = function abiwordAvailable() {
if(this.abiword != null) {
return os.type().indexOf("Windows") != -1 ? "withoutPDF" : "yes";
} else {
return "no";
}
};
exports.Settings = Settings;
//read the settings sync
var settingsPath = path.normalize(__dirname + "/../../");
var settingsStr = fs.readFileSync(settingsPath + "settings.json").toString();
//remove all comments
settingsStr = settingsStr.replace(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/gm,"").replace(/#.*/g,"").replace(/\/\/.*/g,"");
exports.parseSettings = function parseSettings(path) {
//try to parse the settings
var settings;
try
{
settings = JSON.parse(settingsStr);
}
catch(e)
{
console.error("There is a syntax error in your settings.json file");
console.error(e.message);
process.exit(1);
}
var settingsStr = fs.readFileSync(path).toString();
settingsStr = settingsStr.replace(/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+/gm,"").replace(/#.*/g,"").replace(/\/\/.*/g,"");
var pojo;
//try to parse the settings
try {
pojo = JSON.parse(settingsStr);
}
catch(e) {
console.log(e);
process.exit(1);
}
return new Settings(pojo);
};
//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 + "'");
}
//we know this setting, so we overwrite it
if(exports[i] !== undefined)
{
exports[i] = settings[i];
}
//this setting is unkown, output a warning and throw it away
else
{
console.warn("Unkown Setting: '" + i + "'");
console.warn("This setting doesn't exist or it was removed");
}
}