From 5bba09805339718f5f1ea7df8e2816d2df51a70e Mon Sep 17 00:00:00 2001 From: Darren Date: Fri, 24 Jan 2014 11:50:23 +0000 Subject: [PATCH] proxy binding to local interfaces --- server/irc/connection.js | 1 + server/proxy.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/server/irc/connection.js b/server/irc/connection.js index 2458c54..c0ca216 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -220,6 +220,7 @@ IrcConnection.prototype.connect = function () { } else if (that.proxy) { that.socket = new Proxy.ProxySocket(that.proxy.port, host, { username: that.username, + interface: that.proxy.interface }, {ssl: that.proxy.ssl}); if (that.ssl) { diff --git a/server/proxy.js b/server/proxy.js index fae5c58..1dfaa9b 100644 --- a/server/proxy.js +++ b/server/proxy.js @@ -171,15 +171,25 @@ ProxyPipe.prototype.kiwiSocketOnReadable = function() { ProxyPipe.prototype.makeIrcConnection = function() { debug('[KiwiProxy] Opening proxied connection to: ' + this.meta.host + ':' + this.meta.port.toString()); + + var local_address = this.meta.interface ? + this.meta.interface : + '0.0.0.0'; + if (this.meta.ssl) { this.irc_socket = tls.connect({ port: parseInt(this.meta.port, 10), host: this.meta.host, rejectUnauthorized: global.config.reject_unauthorised_certificates, + localAddress: local_address }, this._onSocketConnect.bind(this)); } else { - this.irc_socket = net.connect(parseInt(this.meta.port, 10), this.meta.host, this._onSocketConnect.bind(this)); + this.irc_socket = net.connect({ + port: parseInt(this.meta.port, 10), + host: this.meta.host, + localAddress: local_address + }, this._onSocketConnect.bind(this)); } this.irc_socket.setTimeout(10000); @@ -268,7 +278,8 @@ function ProxySocket(proxy_port, proxy_addr, meta, proxy_opts) { this.proxy_addr = proxy_addr; this.proxy_port = proxy_port; this.proxy_opts = proxy_opts || {}; - this.meta = meta || {}; + + this.setMeta(meta || {}); this.state = 'disconnected'; } -- 2.25.1