2014-10-09 15:46:12 +00:00
|
|
|
var _ = require("lodash");
|
|
|
|
var net = require("net");
|
|
|
|
|
2014-10-11 17:33:28 +00:00
|
|
|
var users = {};
|
2016-04-26 20:40:27 +00:00
|
|
|
var enabled = false;
|
2014-10-09 15:46:12 +00:00
|
|
|
|
2014-10-11 17:33:28 +00:00
|
|
|
module.exports.start = function(port) {
|
2016-04-16 11:32:38 +00:00
|
|
|
port = port || 113;
|
|
|
|
log.info("Starting identd server on port", port);
|
|
|
|
net.createServer(init).listen(port);
|
2016-04-26 20:40:27 +00:00
|
|
|
enabled = true;
|
2014-10-09 15:46:12 +00:00
|
|
|
};
|
|
|
|
|
2014-10-11 17:33:28 +00:00
|
|
|
module.exports.hook = function(stream, user) {
|
|
|
|
var socket = stream.socket || stream;
|
2016-04-26 20:40:27 +00:00
|
|
|
var ports = _.pick(socket, "localPort", "remotePort");
|
|
|
|
var id = _.values(ports).join(", ");
|
|
|
|
|
|
|
|
users[id] = user;
|
|
|
|
|
2014-10-11 17:33:28 +00:00
|
|
|
socket.on("close", function() {
|
|
|
|
delete users[id];
|
|
|
|
});
|
2014-10-09 15:46:12 +00:00
|
|
|
};
|
|
|
|
|
2016-04-26 20:40:27 +00:00
|
|
|
module.exports.isEnabled = function() {
|
|
|
|
return enabled;
|
|
|
|
};
|
|
|
|
|
2014-10-11 17:33:28 +00:00
|
|
|
function init(socket) {
|
|
|
|
socket.on("data", function(data) {
|
|
|
|
respond(socket, data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function respond(socket, data) {
|
|
|
|
var id = parse(data);
|
|
|
|
var response = id + " : ";
|
|
|
|
if (users[id]) {
|
|
|
|
response += "USERID : UNIX : " + users[id];
|
|
|
|
} else {
|
|
|
|
response += "ERROR : NO-USER";
|
2014-10-11 10:09:27 +00:00
|
|
|
}
|
2014-10-11 17:33:28 +00:00
|
|
|
response += "\r\n";
|
|
|
|
socket.write(response);
|
|
|
|
socket.end();
|
|
|
|
}
|
2014-10-09 15:46:12 +00:00
|
|
|
|
2014-10-11 17:33:28 +00:00
|
|
|
function parse(data) {
|
|
|
|
data = data.toString();
|
|
|
|
data = data.split(",");
|
|
|
|
return parseInt(data[0]) + ", " + parseInt(data[1]);
|
|
|
|
}
|