From adefb6bd727007708adbd60ac210dc86910f5d03 Mon Sep 17 00:00:00 2001 From: Darren Date: Thu, 21 Mar 2013 15:01:34 +0000 Subject: [PATCH] Built in identd server --- config.example.js | 9 +++++++++ server/identd.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ server/kiwi.js | 16 +++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 server/identd.js diff --git a/config.example.js b/config.example.js index d0026e1..fadbd48 100644 --- a/config.example.js +++ b/config.example.js @@ -35,6 +35,15 @@ conf.servers.push({ +// Do we want to enable the built in Identd server? +conf.identd = { + enabled: false, + port: 113, + address: "0.0.0.0" +}; + + + diff --git a/server/identd.js b/server/identd.js new file mode 100644 index 0000000..2a8bfa5 --- /dev/null +++ b/server/identd.js @@ -0,0 +1,46 @@ +var net = require('net'); + +function IdentdServer(opts) { + + // Option defaults + opts = opts || {}; + opts.bind_addr = opts.bind_addr || '0.0.0.0'; + opts.bind_port = opts.bind_port || 113; + opts.system_id = opts.system_id || 'UNIX-KiwiIRC'; + opts.user_id = opts.user_id || 'kiwi'; + + + var server = net.createServer(function(socket) { + var user, system; + + if (typeof opts.user_id === 'function') { + user = opts.user_id(socket).toString(); + } else { + user = opts.user_id.toString(); + } + + if (typeof opts.system_id === 'function') { + system = opts.system_id(socket).toString(); + } else { + system = opts.system_id.toString(); + } + + socket.end('25,25 : USERID : ' + system + ' : ' + user); + }); + + server.on('listening', function() { + console.log('Ident Server listening on ' + server.address().address + ':' + server.address().port); + }); + + + this.start = function() { + server.listen(opts.bind_port, opts.bind_addr); + }; + + this.stop = function(callback) { + server.close(callback); + }; +} + + +module.exports = IdentdServer; \ No newline at end of file diff --git a/server/kiwi.js b/server/kiwi.js index 3f426a9..a464a35 100755 --- a/server/kiwi.js +++ b/server/kiwi.js @@ -3,7 +3,8 @@ var fs = require('fs'), WebListener = require('./weblistener.js'), config = require('./configuration.js'), rehash = require('./rehash.js'), - modules = require('./modules.js'); + modules = require('./modules.js'), + Identd = require('./identd.js'); @@ -111,6 +112,19 @@ global.clients = { +/* + * Identd server + */ +if (global.config.identd && global.config.identd.enabled) { + new Identd({ + bind_addr: global.config.identd.address, + bind_port: global.config.identd.port + }).start(); +} + + + + /* * Web listeners */ -- 2.25.1