var util = require('util'),
events = require('events'),
_ = require('underscore'),
+ config = require('./configuration.js'),
IrcConnection = require('./irc/connection.js').IrcConnection,
IrcCommands = require('./irc/commands.js'),
ClientCommands = require('./clientcommands.js');
function websocketDisconnect() {
_.each(this.irc_connections, function (irc_connection, i, cons) {
if (irc_connection) {
- irc_connection.end('QUIT :Kiwi IRC');
+ irc_connection.end('QUIT :' + (config.get().quit_message || ''));
cons[i] = null;
}
});
--- /dev/null
+var fs = require('fs');
+
+var config_filename = 'config.js',
+ config_dirs = ['/etc/kiwiirc/', __dirname + '/'],
+ environment = 'production',
+ loaded_config = Object.create(null);
+
+
+function loadConfig() {
+ var new_config,
+ conf_filepath;
+
+ // Loop through the possible config paths and find a usable one
+ for (var i in config_dirs) {
+ conf_filepath = config_dirs[i] + config_filename;
+
+ try {
+ if (fs.lstatSync(conf_filepath).isFile() === true) {
+ // Clear the loaded config cache
+ delete require.cache[require.resolve(conf_filepath)];
+
+ // Try load the new config file
+ new_config = require(conf_filepath);
+ console.log('Loaded config file ' + config_dirs[i] + config_filename);
+ break;
+ }
+ } catch (e) {
+ switch (e.code) {
+ case 'ENOENT': // No file/dir
+ break;
+ default:
+ console.log('An error occured parsing the config file ' + config_dirs[i] + config_filename + ': ' + e.message);
+ return false;
+ }
+ continue;
+ }
+ }
+
+ if (new_config) {
+ loaded_config = new_config;
+ return loaded_config;
+ } else {
+ return false;
+ }
+}
+
+
+
+module.exports.setEnvironment = function (new_environment) {
+ environment = new_environment;
+};
+
+// Get the current config. Optionally for a different environment than currently set
+module.exports.get = function (specific_environment) {
+ specific_environment = specific_environment || environment;
+
+ return loaded_config[specific_environment];
+};
+
+module.exports.loadConfig = loadConfig;
\ No newline at end of file
var fs = require('fs'),
_ = require('underscore'),
- WebListener = require('./weblistener.js');
+ WebListener = require('./weblistener.js'),
+ config = require('./configuration.js');
-/*
- * Config loading
- */
-
-var config_filename = 'config.js',
- config_dirs = ['/etc/kiwiirc/', __dirname + '/'];
-
-var config;
-
-function loadConfig() {
- var new_config,
- conf_filepath;
-
- // Loop through the possible config paths and find a usable one
- for (var i in config_dirs) {
- conf_filepath = config_dirs[i] + config_filename;
-
- try {
- if (fs.lstatSync(conf_filepath).isFile() === true) {
- // Clear the loaded config cache
- delete require.cache[require.resolve(conf_filepath)];
-
- // Try load the new config file
- new_config = require(conf_filepath).production;
- console.log('Loaded config file ' + config_dirs[i] + config_filename);
- break;
- }
- } catch (e) {
- switch (e.code) {
- case 'ENOENT': // No file/dir
- break;
- default:
- console.log('An error occured parsing the config file ' + config_dirs[i] + config_filename + ': ' + e.message);
- return false;
- }
- continue;
- }
- }
-
- return new_config;
-}
-config = loadConfig() || Object.create(null);
+config.loadConfig();
// Make sure we have a valid config file and at least 1 server
-if (Object.keys(config).length === 0) {
+if (Object.keys(config.get()).length === 0) {
console.log('Couldn\'t find a valid config file!');
process.exit(1);
}
-if ((!config.servers) || (config.servers.length < 1)) {
+if ((!config.get().servers) || (config.get().servers.length < 1)) {
console.log('No servers defined in config file');
process.exit(2);
}
var clients = [];
// Start up a weblistener for each found in the config
-_.each(config.servers, function (server) {
- var wl = new WebListener(server, config.transports);
+_.each(config.get().servers, function (server) {
+ var wl = new WebListener(server, config.get().transports);
wl.on('connection', function (client) {
clients.push(client);
});
process.title = 'kiwiirc';
// Change UID/GID
-if ((config.user) && (config.user !== '')) {
+if ((config.get().user) && (config.get().user !== '')) {
process.setuid(config.user);
}
-if ((config.group) && (config.group !== '')) {
+if ((config.get().group) && (config.get().group !== '')) {
process.setgid(config.group);
}
case 'reconfig':
(function () {
- var new_conf = loadConfig();
- if (new_conf) {
- config = new_conf;
+ if (config.loadConfig()) {
console.log('New config file loaded');
} else {
console.log("No new config file was loaded");