From ac0b278ca900e6a0c29cefdaf4d73b58c06bd150 Mon Sep 17 00:00:00 2001 From: Jack Allnutt Date: Sat, 23 Mar 2013 12:30:22 +0000 Subject: [PATCH] SOCKS proxy conf and integration * Configuration details in conf.example.js - Can be configured to use SOCKS for all outgoing connections or just for specific hosts * Integrated in to IrcConnection object * Minor tweak to IrcConnection: use call instead of apply to avoid accessing the arguments object, which isn't used by socketConnectHandler --- config.example.js | 25 +++++++++++++++++++++++++ server/irc/connection.js | 21 ++++++++++++++++----- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/config.example.js b/config.example.js index 286ee21..06d077d 100644 --- a/config.example.js +++ b/config.example.js @@ -104,6 +104,31 @@ conf.http_proxy_ip_header = "x-forwarded-for"; conf.http_base_path = "/kiwi"; +/* + * SOCKS proxy settings + */ +conf.socks_proxy = {}; + +// Enable proxying outbound connections through a SOCKS proxy +conf.socks_proxy.enabled = false; + +// Proxy *all* outbound connections through a SOCKS proxy +conf.socks_proxy.all = false; + +// Use SOCKS proxy for these hosts only (if conf.sock_proxy.all === false) +conf.socks_proxy.proxy_hosts = [ + "irc.example.com" +]; + +// Host and port for the SOCKS proxy +conf.socks_proxy.address = '127.0.0.1'; +conf.socks_proxy.port = 1080; + +// Username and password for the SOCKS proxy +// Set user to null to disable password authentication +conf.socks_proxy.user = null; +conf.socks_proxy.pass = null; + // Enabled transports for the browser to use conf.transports = [ diff --git a/server/irc/connection.js b/server/irc/connection.js index 62f3e3a..c48346b 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -7,7 +7,7 @@ var net = require('net'), IrcServer = require('./server.js'), IrcChannel = require('./channel.js'), IrcUser = require('./user.js'), - SocksConnection = require('./socks.js'); + SocksConnection = require('../socks.js'); var IrcConnection = function (hostname, port, ssl, nick, user, pass, state) { @@ -51,8 +51,17 @@ var IrcConnection = function (hostname, port, ssl, nick, user, pass, state) { this.ssl = !(!ssl); // SOCKS proxy details - // TODO: read proxy details from configuration - this.socks = false; + // TODO: Wildcard matching of hostnames and/or CIDR ranges of IP addresses + if ((global.config.socks_proxy && global.config.socks_proxy.enabled) && ((global.config.socks_proxy.all) || (_.contains(global.config.socks_proxy.proxy_hosts, this.irc_host.hostname)))) { + this.socks = { + host: global.config.socks_proxy.address, + port: global.config.socks_proxy.port, + user: global.config.socks_proxy.user, + pass: global.config.socks_proxy.pass + }; + } else { + this.socks = false; + } // Options sent by the IRCd this.options = Object.create(null); @@ -123,9 +132,11 @@ IrcConnection.prototype.connect = function () { pass: this.socks.pass }); - socks.on('connect', function (socket){ + socks.on('connect', function (socket) { that.socket = socket; setupSocket.call(that); + that.connected = true; + socketConnectHandler.call(that); }); } else { // Open either a secure or plain text socket @@ -147,7 +158,7 @@ IrcConnection.prototype.connect = function () { this.socket.on(socket_connect_event_name, function () { that.connected = true; - socketConnectHandler.apply(that, arguments); + socketConnectHandler.call(that); }); setupSocket.call(this); -- 2.25.1