From 58b38d1cefa6647863bab0a3eae8740c2db676ce Mon Sep 17 00:00:00 2001 From: Darren Date: Wed, 25 Jun 2014 09:49:54 +0100 Subject: [PATCH] Open proxy checker module --- server_modules/proxychecker.js | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 server_modules/proxychecker.js diff --git a/server_modules/proxychecker.js b/server_modules/proxychecker.js new file mode 100644 index 0000000..f16eccf --- /dev/null +++ b/server_modules/proxychecker.js @@ -0,0 +1,67 @@ +var util = require('util'), + kiwiModules = require('../server/modules'); + + +var module = new kiwiModules.Module('proxychecker'); + +module.on('irc connecting', function (event, event_data) { + event.wait = true; + + var client_addr = event_data.connection.state.client.websocket.meta.real_address; + + checkForOpenProxies(client_addr, function(is_proxy, host, port) { + if (is_proxy) { + var err = new Error(util.format('Proxy detected on %s:%d', client_addr, port)); + err.code = 'Blocked proxy'; + + event_data.connection.emit('error', err); + event.preventDefault(); + event.callback(); + + } else { + event.callback(); + } + }); +}); + + + +function checkForOpenProxies(host, callback) { + var net = require('net'); + + var ports = [80,8080,81,1080,6588,8000]; + var ports_completed = 0; + + var callback_called = false; + + var portFailed = function() { + ports_completed++; + this.removeAllListeners(); + this.destroy(); + + if (!callback_called && ports_completed >= ports.length) { + callback_called = true; + callback(false); + } + }; + + var portConnected = function() { + var remote_port = this.remotePort; + + ports_completed++; + this.removeAllListeners(); + this.destroy(); + + if (!callback_called) { + callback_called = true; + callback(true, host, remote_port); + } + }; + + for (var idx=0; idx< ports.length; idx++) { + net.connect({port: ports[idx], host: host}) + .on('connect', portConnected) + .on('error', portFailed) + .on('close', portFailed); + } +} \ No newline at end of file -- 2.25.1