mirror of
https://github.com/thelounge/thelounge
synced 2024-11-15 08:47:16 +00:00
Merge pull request #256 from maxpoulin64/oidentd
Add support for oidentd spoofing
This commit is contained in:
commit
9f179c7566
6 changed files with 127 additions and 12 deletions
|
@ -309,5 +309,15 @@ module.exports = {
|
|||
// @default 113
|
||||
//
|
||||
port: 113
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
// Enable oidentd support using the specified file
|
||||
//
|
||||
// Example: oidentd: "~/.oidentd.conf",
|
||||
//
|
||||
// @type string
|
||||
// @default null
|
||||
//
|
||||
oidentd: null,
|
||||
};
|
||||
|
|
|
@ -3,11 +3,18 @@ var fs = require("fs");
|
|||
var Client = require("./client");
|
||||
var mkdirp = require("mkdirp");
|
||||
var Helper = require("./helper");
|
||||
var oidentd = require("./oidentd");
|
||||
|
||||
module.exports = ClientManager;
|
||||
|
||||
function ClientManager() {
|
||||
var config = Helper.getConfig();
|
||||
|
||||
this.clients = [];
|
||||
|
||||
if (typeof config.oidentd === "string") {
|
||||
this.identHandler = new oidentd(config.oidentd);
|
||||
}
|
||||
}
|
||||
|
||||
ClientManager.prototype.findClient = function(name) {
|
||||
|
|
|
@ -2,26 +2,31 @@ var _ = require("lodash");
|
|||
var net = require("net");
|
||||
|
||||
var users = {};
|
||||
var enabled = false;
|
||||
|
||||
module.exports.start = function(port) {
|
||||
port = port || 113;
|
||||
log.info("Starting identd server on port", port);
|
||||
net.createServer(init).listen(port);
|
||||
enabled = true;
|
||||
};
|
||||
|
||||
module.exports.hook = function(stream, user) {
|
||||
var id = "";
|
||||
var socket = stream.socket || stream;
|
||||
socket.on("connect", function() {
|
||||
var ports = _.pick(socket, "localPort", "remotePort");
|
||||
id = _.values(ports).join(", ");
|
||||
users[id] = user;
|
||||
});
|
||||
var ports = _.pick(socket, "localPort", "remotePort");
|
||||
var id = _.values(ports).join(", ");
|
||||
|
||||
users[id] = user;
|
||||
|
||||
socket.on("close", function() {
|
||||
delete users[id];
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.isEnabled = function() {
|
||||
return enabled;
|
||||
};
|
||||
|
||||
function init(socket) {
|
||||
socket.on("data", function(data) {
|
||||
respond(socket, data);
|
||||
|
|
73
src/oidentd.js
Normal file
73
src/oidentd.js
Normal file
|
@ -0,0 +1,73 @@
|
|||
var fs = require("fs");
|
||||
var Helper = require("./helper");
|
||||
|
||||
function oidentdFile(file) {
|
||||
this.file = Helper.expandHome(file);
|
||||
this.connectionId = 0;
|
||||
this.connections = {};
|
||||
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
oidentdFile.prototype = {
|
||||
hookSocket: function(socket, user) {
|
||||
var that = this;
|
||||
var id = null;
|
||||
|
||||
socket.on("connect", function() {
|
||||
id = that.addSocket(socket, user);
|
||||
that.refresh();
|
||||
});
|
||||
socket.on("close", function() {
|
||||
that.removeConnection(id);
|
||||
that.refresh();
|
||||
});
|
||||
},
|
||||
|
||||
addSocket: function(socket, user) {
|
||||
var id = this.connectionId++;
|
||||
this.connections[id] = {socket: socket, user: user};
|
||||
return id;
|
||||
},
|
||||
|
||||
removeSocket: function(socket) {
|
||||
for (var id in this.connections) {
|
||||
if (this.connections[id] === socket) {
|
||||
delete this.connections[id];
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
removeConnection: function(id) {
|
||||
delete this.connections[id];
|
||||
},
|
||||
|
||||
getSockets: function() {
|
||||
return this.connections;
|
||||
},
|
||||
|
||||
refresh: function() {
|
||||
var file = "# Warning: file generated by The Lounge: changes will be overwritten!\n";
|
||||
|
||||
function makeRule(connection) {
|
||||
return "to " + connection.socket.remoteAddress
|
||||
+ " lport " + connection.socket.localPort
|
||||
+ " from " + connection.socket.localAddress
|
||||
+ " fport " + connection.socket.remotePort
|
||||
+ " { reply \"" + connection.user + "\" }\n";
|
||||
}
|
||||
|
||||
for (var id in this.connections) {
|
||||
file += makeRule(this.connections[id]);
|
||||
}
|
||||
|
||||
fs.writeFile(this.file, file, {flag: "w+"}, function(err) {
|
||||
if (err) {
|
||||
log.error("Failed to update oidentd file!", err);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = oidentdFile;
|
|
@ -4,15 +4,12 @@ var Msg = require("../../models/msg");
|
|||
|
||||
module.exports = function(irc, network) {
|
||||
var client = this;
|
||||
var identHandler = this.manager.identHandler;
|
||||
|
||||
network.channels[0].pushMessage(client, new Msg({
|
||||
text: "Network created, connecting to " + network.host + ":" + network.port + "..."
|
||||
}));
|
||||
|
||||
irc.on("raw socket connected", function() {
|
||||
identd.hook(irc.connection.socket, network.username);
|
||||
});
|
||||
|
||||
irc.on("socket connected", function() {
|
||||
network.channels[0].pushMessage(client, new Msg({
|
||||
text: "Connected to the network."
|
||||
|
@ -25,6 +22,24 @@ module.exports = function(irc, network) {
|
|||
}));
|
||||
});
|
||||
|
||||
if (identd.isEnabled()) {
|
||||
irc.on("socket connected", function() {
|
||||
identd.hook(irc.connection.socket, client.name || network.username);
|
||||
});
|
||||
}
|
||||
|
||||
if (identHandler) {
|
||||
irc.on("socket connected", function() {
|
||||
identHandler.addSocket(irc.connection.socket, client.name || network.username);
|
||||
identHandler.refresh();
|
||||
});
|
||||
|
||||
irc.on("socket close", function() {
|
||||
identHandler.removeSocket(irc.connection.socket);
|
||||
identHandler.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
irc.on("socket error", function(err) {
|
||||
log.debug("IRC socket error", err);
|
||||
network.channels[0].pushMessage(client, new Msg({
|
||||
|
|
|
@ -10,9 +10,10 @@ var dns = require("dns");
|
|||
var Helper = require("./helper");
|
||||
var config = {};
|
||||
|
||||
var manager = new ClientManager();
|
||||
var manager = null;
|
||||
|
||||
module.exports = function(options) {
|
||||
manager = new ClientManager();
|
||||
config = Helper.getConfig();
|
||||
config = _.extend(config, options);
|
||||
|
||||
|
@ -40,6 +41,10 @@ module.exports = function(options) {
|
|||
}
|
||||
|
||||
if ((config.identd || {}).enable) {
|
||||
if (manager.identHandler) {
|
||||
log.warn("Using both identd and oidentd at the same time!");
|
||||
}
|
||||
|
||||
require("./identd").start(config.identd.port);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue