Update cloaking function so the banlist looks right

This commit is contained in:
calzoneman 2014-08-14 21:57:38 -05:00
parent 722c55e0da
commit 25ab4b62e5

View file

@ -276,20 +276,22 @@
return ip;
}
function iphash(ip, segment, len) {
function iphash(data, len) {
var md5 = crypto.createHash("md5");
md5.update(ip);
md5.update(segment);
md5.update(data);
return md5.digest("base64").substring(0, len);
}
function cloakIPv4(ip) {
var parts = ip.split(".");
var accumulator = "";
parts = parts.map(function (segment, i) {
if (i < 2) return segment;
return iphash(ip, segment + i, 3);
var part = iphash(accumulator + segment + i, 3);
accumulator += segment;
return part;
});
while (parts.length < 4) parts.push("*");
@ -299,11 +301,14 @@
function cloakIPv6(ip) {
var parts = ip.split(":");
parts.splice(4, 4);
var accumulator = "";
parts = parts.map(function (segment, i) {
if (i < 2) return segment;
return iphash(ip, segment + i, 4);
var part = iphash(accumulator + segment + i, 4);
accumulator += segment;
return part;
});
while (parts.length < 4) parts.push("*");