Add support for hexip ilines
This commit is contained in:
parent
b7ff814d8b
commit
708788338c
@ -109,6 +109,17 @@ module.exports = {
|
|||||||
//
|
//
|
||||||
lockNetwork: false,
|
lockNetwork: false,
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hex IP
|
||||||
|
//
|
||||||
|
// If enabled, clients' username will be set to their IP encoded has hex.
|
||||||
|
// This is done to share the real user IP address with the server for host masking purposes.
|
||||||
|
//
|
||||||
|
// @type boolean
|
||||||
|
// @default false
|
||||||
|
//
|
||||||
|
useHexIp: false,
|
||||||
|
|
||||||
//
|
//
|
||||||
// WEBIRC support
|
// WEBIRC support
|
||||||
//
|
//
|
||||||
|
@ -260,7 +260,7 @@ Client.prototype.connect = function(args) {
|
|||||||
host: network.host,
|
host: network.host,
|
||||||
port: network.port,
|
port: network.port,
|
||||||
nick: nick,
|
nick: nick,
|
||||||
username: network.username,
|
username: config.useHexIp ? Helper.ip2hex(client.ip) : network.username,
|
||||||
gecos: network.realname,
|
gecos: network.realname,
|
||||||
password: network.password,
|
password: network.password,
|
||||||
tls: network.tls,
|
tls: network.tls,
|
||||||
|
@ -5,6 +5,7 @@ var _ = require("lodash");
|
|||||||
var path = require("path");
|
var path = require("path");
|
||||||
var os = require("os");
|
var os = require("os");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
var net = require("net");
|
||||||
var bcrypt = require("bcrypt-nodejs");
|
var bcrypt = require("bcrypt-nodejs");
|
||||||
|
|
||||||
var Helper = {
|
var Helper = {
|
||||||
@ -15,6 +16,7 @@ var Helper = {
|
|||||||
setHome: setHome,
|
setHome: setHome,
|
||||||
getVersion: getVersion,
|
getVersion: getVersion,
|
||||||
getGitCommit: getGitCommit,
|
getGitCommit: getGitCommit,
|
||||||
|
ip2hex: ip2hex,
|
||||||
|
|
||||||
password: {
|
password: {
|
||||||
hash: passwordHash,
|
hash: passwordHash,
|
||||||
@ -75,6 +77,23 @@ function getUserLogsPath(name, network) {
|
|||||||
return path.join(this.HOME, "logs", name, network);
|
return path.join(this.HOME, "logs", name, network);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ip2hex(address) {
|
||||||
|
// no ipv6 support
|
||||||
|
if (!net.isIPv4(address)) {
|
||||||
|
return "00000000";
|
||||||
|
}
|
||||||
|
|
||||||
|
return address.split(".").map(function(octet) {
|
||||||
|
var hex = parseInt(octet, 10).toString(16);
|
||||||
|
|
||||||
|
if (hex.length === 1) {
|
||||||
|
hex = "0" + hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hex;
|
||||||
|
}).join("");
|
||||||
|
}
|
||||||
|
|
||||||
function expandHome(shortenedPath) {
|
function expandHome(shortenedPath) {
|
||||||
var home;
|
var home;
|
||||||
|
|
||||||
|
@ -148,6 +148,10 @@ function init(socket, client) {
|
|||||||
});
|
});
|
||||||
client.clientAttach(socket.id);
|
client.clientAttach(socket.id);
|
||||||
|
|
||||||
|
if (!client.ip) {
|
||||||
|
client.ip = getClientIp(socket.request);
|
||||||
|
}
|
||||||
|
|
||||||
socket.on(
|
socket.on(
|
||||||
"input",
|
"input",
|
||||||
function(data) {
|
function(data) {
|
||||||
|
19
test/tests/hexip.js
Normal file
19
test/tests/hexip.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const expect = require("chai").expect;
|
||||||
|
const Helper = require("../../src/helper");
|
||||||
|
|
||||||
|
describe("HexIP", function() {
|
||||||
|
it("should correctly convert IPv4 to hex", function() {
|
||||||
|
expect(Helper.ip2hex("66.124.160.150")).to.equal("427ca096");
|
||||||
|
expect(Helper.ip2hex("127.0.0.1")).to.equal("7f000001");
|
||||||
|
expect(Helper.ip2hex("0.0.0.255")).to.equal("000000ff");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("unsupported addresses return default", function() {
|
||||||
|
expect(Helper.ip2hex("0.0.0.999")).to.equal("00000000");
|
||||||
|
expect(Helper.ip2hex("localhost")).to.equal("00000000");
|
||||||
|
expect(Helper.ip2hex("::1")).to.equal("00000000");
|
||||||
|
expect(Helper.ip2hex("2606:2800:220:1:248:1893:25c8:1946")).to.equal("00000000");
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user