thelounge/src/oidentd.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

"use strict";
const fs = require("fs");
const Helper = require("./helper");
2016-04-26 22:41:08 +02:00
2016-06-11 22:03:59 +02:00
function OidentdFile(file) {
2016-04-26 22:41:08 +02:00
this.file = Helper.expandHome(file);
this.connectionId = 0;
this.connections = new Map();
2016-04-26 22:41:08 +02:00
this.refresh();
}
2016-06-11 22:03:59 +02:00
OidentdFile.prototype = {
addSocket: function(socket, user) {
const id = this.connectionId++;
2016-04-26 22:41:08 +02:00
this.connections.set(id, {socket: socket, user: user});
this.refresh();
2016-04-26 22:41:08 +02:00
return id;
},
removeSocket: function(id) {
this.connections.delete(id);
2016-04-26 22:41:08 +02:00
this.refresh();
2016-04-26 22:41:08 +02:00
},
refresh: function() {
let file = "# Warning: file generated by The Lounge: changes will be overwritten!\n";
2016-04-26 22:41:08 +02:00
this.connections.forEach((connection) => {
file += "to " + connection.socket.remoteAddress
2016-04-26 22:41:08 +02:00
+ " lport " + connection.socket.localPort
+ " from " + connection.socket.localAddress
+ " fport " + connection.socket.remotePort
+ " { reply \"" + connection.user + "\" }\n";
});
2016-04-26 22:41:08 +02:00
fs.writeFile(this.file, file, {flag: "w+"}, function(err) {
if (err) {
log.error("Failed to update oidentd file!", err);
}
});
},
};
2016-06-11 22:03:59 +02:00
module.exports = OidentdFile;