From 8ac9f7ac6e77dd8bad71eef8689350bf3f5d95d0 Mon Sep 17 00:00:00 2001 From: Darren Date: Wed, 10 Jul 2013 15:56:37 +0100 Subject: [PATCH] DNSBL server module --- server_modules/dnsbl.js | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 server_modules/dnsbl.js diff --git a/server_modules/dnsbl.js b/server_modules/dnsbl.js new file mode 100644 index 0000000..984c0b4 --- /dev/null +++ b/server_modules/dnsbl.js @@ -0,0 +1,62 @@ +/** + * DNS Blacklist support + * + * Check the client against a blacklist before connection to an IRC server + */ + +var dns = require('dns'), + kiwiModules = require('../server/modules'); + + +// The available DNS zones to check against +var bl_zones = { + dronebl: '.dnsbl.dronebl.org' +}; + +// The DNS zone we should use +var current_bl = 'dronebl'; + + +var module = new kiwiModules.Module('DNSBL'); + +module.on('irc connecting', function (event, event_data) { + event.wait = true; + + var client_addr = event_data.connection.state.client.websocket.handshake.real_address; + + isBlacklisted(client_addr, function(is_blocked) { + if (is_blocked) { + var err = new Error('DNSBL blocked'); + err.code = 'Blacklisted'; + + event_data.connection.emit('error', err); + event.preventDefault(); + event.callback(); + + } else { + event.callback(); + } + }); +}); + + + +// The actual checking against the DNS blacklist +function isBlacklisted(ip, callback) { + var host_lookup = reverseIp(ip) + bl_zones[current_bl]; + + dns.resolve4(host_lookup, function(err, domain) { + if (err) { + // Not blacklisted + callback(false); + } else { + // It is blacklisted + callback(true); + } + }); +} + + +function reverseIp(ip) { + return ip.split('.').reverse().join('.'); +} \ No newline at end of file -- 2.25.1