From 9556a028ce816938f82ae1f8276a10d89c5daae1 Mon Sep 17 00:00:00 2001 From: Darren Date: Thu, 23 Jan 2014 20:04:35 +0000 Subject: [PATCH] Proxy server type in config file --- server/kiwi.js | 62 ++++++++++++++++++++++++++++++++++--------------- server/proxy.js | 6 +++-- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/server/kiwi.js b/server/kiwi.js index 0255e1a..0a54e5d 100755 --- a/server/kiwi.js +++ b/server/kiwi.js @@ -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 diff --git a/server/proxy.js b/server/proxy.js index 8f43426..9ff2ff8 100644 --- a/server/proxy.js +++ b/server/proxy.js @@ -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); -- 2.25.1