Merge branch 'backbone_ui' of https://github.com/M2Ys4U/KiwiIRC into backbone_ui
authorDarren <darren@darrenwhitlen.com>
Wed, 31 Oct 2012 17:54:59 +0000 (17:54 +0000)
committerDarren <darren@darrenwhitlen.com>
Wed, 31 Oct 2012 17:54:59 +0000 (17:54 +0000)
config.js
server/client.js
server/configuration.js
server/httphandler.js
server/irc/connection.js
server/kiwi.js
server/weblistener.js

index 57aaf6c6081da9d147f7e800c713f7800d7a8865..946bd26d3e5672580d60a0724957df109ace1903 100644 (file)
--- a/config.js
+++ b/config.js
@@ -62,7 +62,8 @@ conf.ip_as_username = [
        "127.0.0.1"
 ];
 
-
+// Whether to verify IRC servers' SSL certificates against built-in well-known certificate authorities
+conf.reject_unauthorised_certificates = false;
 
 
 // Whitelisted HTTP proxies
index bec0412122dbbdd64955909850aa9bab6e5e0764..f016012cf125d668a80da717e98ed1de8fe319da 100755 (executable)
@@ -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;
         }
index aaf9513757ed294cc2fe0b9078c7da566a71dd77..b913db667e7ac66823f2ef7d367e4fbb2cd81470 100644 (file)
@@ -37,6 +37,7 @@ function loadConfig() {
 
     if (new_config) {
         loaded_config = new_config;
+        global.config = new_config[environment];
         return loaded_config;
     } else {
         return false;
index 7c982c98e0a8cbc3fed274937f8ed26ae445740b..4c328a6ebf037a7abf4554ead39394a94c8294cd 100644 (file)
@@ -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
index 1a1d8562bfba61608c189503013a5497a2fc7e3b..3d7c7ca35d82414fdf16870ce6305b50c29c685d 100644 (file)
@@ -10,7 +10,7 @@ var IrcConnection = function (hostname, port, ssl, nick, user, pass) {
     events.EventEmitter.call(this);
     
     if (ssl) {
-        this.socket = tls.connect(port, hostname, {}, connect_handler);
+        this.socket = tls.connect({host: hostname, port: port, rejectUnauthorized: global.config.reject_unauthorised_certificates}, connect_handler);
     } else {
         this.socket = net.createConnection(port, hostname);
         this.socket.on('connect', function () {
@@ -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?
index f3ce6ca716c471bc182ec8dcf02622453dc1f8b0..30031a9e01577b134f797ef7636a6723764d0cb9 100755 (executable)
@@ -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);
 }
 
 
index 5e893e30cf135a622ed6757bbf884d87480da6b7..b61fc987a2bf950ec1f1fac0093278dbd6cc81f1 100644 (file)
@@ -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);
         }
     }