Proxy server type in config file
authorDarren <darren@darrenwhitlen.com>
Thu, 23 Jan 2014 20:04:35 +0000 (20:04 +0000)
committerDarren <darren@darrenwhitlen.com>
Thu, 23 Jan 2014 20:04:35 +0000 (20:04 +0000)
server/kiwi.js
server/proxy.js

index 0255e1a62290864ba40192315b7ea9f8e763c4c8..0a54e5d41df0e2528cd8624db53ca72305e9f4c7 100755 (executable)
@@ -5,6 +5,7 @@ var fs          = require('fs'),
     config      = require('./configuration.js'),
     modules     = require('./modules.js'),
     Identd      = require('./identd.js'),
+    Proxy       = require('./proxy.js'),
     ControlInterface = require('./controlinterface.js');
 
 
@@ -229,26 +230,49 @@ if (global.config.identd && global.config.identd.enabled) {
 
 // Start up a weblistener for each found in the config
 _.each(global.config.servers, function (server) {
-    var wl = new WebListener(server, global.config.transports);
+    if (server.type == 'proxy') {
+        // Start up a kiwi proxy server
+        var serv = new Proxy.ProxyServer();
+        serv.listen(server.port, server.address);
+
+        serv.on('listening', function() {
+            console.log('Kiwi proxy listening on %s:%s %s SSL', server.address, server.port, (server.ssl ? 'with' : 'without'));
+        });
+
+        serv.on('connection_open', function(pipe) {
+            pipe.identd_pair = pipe.irc_socket.localPort.toString() + '_' + pipe.irc_socket.remotePort.toString();
+            console.log('[IDENTD] opened ' + pipe.identd_pair);
+            global.clients.port_pairs[pipe.identd_pair] = pipe.meta;
+        });
+
+        serv.on('connection_close', function(pipe) {
+            console.log('[IDENTD] closed ' + pipe.identd_pair);
+            delete global.clients.port_pairs[pipe.identd_pair];
+        });
 
-    wl.on('connection', function (client) {
-        clients.add(client);
-    });
-
-    wl.on('client_dispose', function (client) {
-        clients.remove(client);
-    });
-
-    wl.on('listening', function () {
-        console.log('Listening on %s:%s %s SSL', server.address, server.port, (server.ssl ? 'with' : 'without'));
-        webListenerRunning();
-    });
-
-    wl.on('error', function (err) {
-        console.log('Error listening on %s:%s: %s', server.address, server.port, err.code);
-        // TODO: This should probably be refactored. ^JA
-        webListenerRunning();
-    });
+    } else {
+        // Start up a kiwi web server
+        var wl = new WebListener(server, global.config.transports);
+
+        wl.on('connection', function (client) {
+            clients.add(client);
+        });
+
+        wl.on('client_dispose', function (client) {
+            clients.remove(client);
+        });
+
+        wl.on('listening', function () {
+            console.log('Listening on %s:%s %s SSL', server.address, server.port, (server.ssl ? 'with' : 'without'));
+            webListenerRunning();
+        });
+
+        wl.on('error', function (err) {
+            console.log('Error listening on %s:%s: %s', server.address, server.port, err.code);
+            // TODO: This should probably be refactored. ^JA
+            webListenerRunning();
+        });
+    }
 });
 
 // Once all the listeners are listening, set the processes UID/GID
index 8f43426670be87abfc5fd2c54c555c55a7ecb77f..9ff2ff87baa88c29c2022231ace5898905e133c8 100644 (file)
@@ -11,7 +11,7 @@ module.exports = {
 };
 
 function debug() {
-    console.log.apply(console, arguments);
+    //console.log.apply(console, arguments);
 }
 
 // Socket connection responses
@@ -40,7 +40,9 @@ ProxyServer.prototype.listen = function(listen_port, listen_addr) {
 
     // Start listening for proxy connections connections
     this.server = new net.Server();
-    this.server.listen(listen_port, listen_addr);
+    this.server.listen(listen_port, listen_addr, function() {
+        that.emit('listening');
+    });
 
     this.server.on('connection', function(socket) {
         new ProxyPipe(socket, that);