From b737610be1e80eb2c9e372e1ff5293ba8581f20c Mon Sep 17 00:00:00 2001 From: Jack Allnutt Date: Wed, 31 Oct 2012 12:07:51 +0000 Subject: [PATCH] Use explicit global variable for current configuration rather than config.get() --- server/client.js | 2 +- server/configuration.js | 1 + server/httphandler.js | 2 +- server/irc/connection.js | 4 ++-- server/kiwi.js | 20 ++++++++++---------- server/weblistener.js | 8 ++++---- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/server/client.js b/server/client.js index bec0412..f016012 100755 --- a/server/client.js +++ b/server/client.js @@ -151,7 +151,7 @@ function kiwiCommand(command, callback) { function websocketDisconnect() { _.each(this.irc_connections, function (irc_connection, i, cons) { if (irc_connection) { - irc_connection.end('QUIT :' + (config.get().quit_message || '')); + irc_connection.end('QUIT :' + (global.config.quit_message || '')); irc_connection.dispose(); cons[i] = null; } diff --git a/server/configuration.js b/server/configuration.js index aaf9513..b913db6 100644 --- a/server/configuration.js +++ b/server/configuration.js @@ -37,6 +37,7 @@ function loadConfig() { if (new_config) { loaded_config = new_config; + global.config = new_config[environment]; return loaded_config; } else { return false; diff --git a/server/httphandler.js b/server/httphandler.js index 7c982c9..4c328a6 100644 --- a/server/httphandler.js +++ b/server/httphandler.js @@ -15,7 +15,7 @@ module.exports.HttpHandler = HttpHandler; HttpHandler.prototype.serve = function (request, response) { // The incoming requests base path (ie. /kiwiclient) - var base_path = config.get().http_base_path || '/kiwi', + var base_path = global.config.http_base_path || '/kiwi', base_path_regex; // Trim of any trailing slashes diff --git a/server/irc/connection.js b/server/irc/connection.js index 1a1d856..cb4b4f2 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -109,8 +109,8 @@ var connect_handler = function () { function findWebIrc(connect_data) { - var webirc_pass = config.get().webirc_pass; - var ip_as_username = config.get().ip_as_username; + var webirc_pass = global.config.webirc_pass; + var ip_as_username = global.config.ip_as_username; var tmp; // Do we have a WEBIRC password for this? diff --git a/server/kiwi.js b/server/kiwi.js index f3ce6ca..30031a9 100755 --- a/server/kiwi.js +++ b/server/kiwi.js @@ -12,9 +12,9 @@ config.loadConfig(); // If we're not running in the forground and we have a log file.. switch // console.log to output to a file -if (process.argv.indexOf('-f') === -1 && config.get().log) { +if (process.argv.indexOf('-f') === -1 && global.config.log) { (function () { - var log_file_name = config.get().log; + var log_file_name = global.config.log; if (log_file_name[0] !== '/') { log_file_name = __dirname + '/../' + log_file_name; @@ -42,12 +42,12 @@ if (process.argv.indexOf('-f') === -1 && config.get().log) { // Make sure we have a valid config file and at least 1 server -if (Object.keys(config.get()).length === 0) { +if (Object.keys(global.config).length === 0) { console.log('Couldn\'t find a valid config file!'); process.exit(1); } -if ((!config.get().servers) || (config.get().servers.length < 1)) { +if ((!global.config.servers) || (global.config.servers.length < 1)) { console.log('No servers defined in config file'); process.exit(2); } @@ -97,8 +97,8 @@ global.clients = { // Start up a weblistener for each found in the config -_.each(config.get().servers, function (server) { - var wl = new WebListener(server, config.get().transports); +_.each(global.config.servers, function (server) { + var wl = new WebListener(server, global.config.transports); wl.on('connection', function (client) { clients.add(client); @@ -121,11 +121,11 @@ _.each(config.get().servers, function (server) { process.title = 'kiwiirc'; // Change UID/GID -if ((config.get().group) && (config.get().group !== '')) { - process.setgid(config.get().group); +if ((global.config.group) && (global.config.group !== '')) { + process.setgid(global.config.group); } -if ((config.get().user) && (config.get().user !== '')) { - process.setuid(config.get().user); +if ((global.config.user) && (global.config.user !== '')) { + process.setuid(global.config.user); } diff --git a/server/weblistener.js b/server/weblistener.js index 5e893e3..b61fc98 100644 --- a/server/weblistener.js +++ b/server/weblistener.js @@ -74,7 +74,7 @@ var WebListener = function (web_config, transports) { this.ws.enable('browser client minification'); this.ws.enable('browser client etag'); this.ws.set('transports', transports); - this.ws.set('resource', (config.get().http_base_path || '') + '/transport'); + this.ws.set('resource', (global.config.http_base_path || '') + '/transport'); this.ws.of('/kiwi').authorization(authoriseConnection) .on('connection', function () { @@ -107,7 +107,7 @@ function authoriseConnection(handshakeData, callback) { // If a forwarded-for header is found, switch the source address if (handshakeData.headers['x-forwarded-for']) { // Check we're connecting from a whitelisted proxy - if (!config.get().http_proxies || config.get().http_proxies.indexOf(address) < 0) { + if (!global.config.http_proxies || global.config.http_proxies.indexOf(address) < 0) { console.log('Unlisted proxy:', address); callback(null, false); return; @@ -120,8 +120,8 @@ function authoriseConnection(handshakeData, callback) { handshakeData.real_address = address; // If enabled, don't go over the connection limit - if (config.get().max_client_conns && config.get().max_client_conns > 0) { - if (global.clients.numOnAddress(address) + 1 > config.get().max_client_conns) { + if (global.config.max_client_conns && global.config.max_client_conns > 0) { + if (global.clients.numOnAddress(address) + 1 > global.config.max_client_conns) { return callback(null, false); } } -- 2.25.1