mirror of https://github.com/calzoneman/sync.git
Update cloaking function so the banlist looks right
This commit is contained in:
parent
722c55e0da
commit
25ab4b62e5
|
@ -276,20 +276,22 @@
|
||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
function iphash(ip, segment, len) {
|
function iphash(data, len) {
|
||||||
var md5 = crypto.createHash("md5");
|
var md5 = crypto.createHash("md5");
|
||||||
md5.update(ip);
|
md5.update(data);
|
||||||
md5.update(segment);
|
|
||||||
return md5.digest("base64").substring(0, len);
|
return md5.digest("base64").substring(0, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
function cloakIPv4(ip) {
|
function cloakIPv4(ip) {
|
||||||
var parts = ip.split(".");
|
var parts = ip.split(".");
|
||||||
|
var accumulator = "";
|
||||||
|
|
||||||
parts = parts.map(function (segment, i) {
|
parts = parts.map(function (segment, i) {
|
||||||
if (i < 2) return segment;
|
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("*");
|
while (parts.length < 4) parts.push("*");
|
||||||
|
@ -299,11 +301,14 @@
|
||||||
function cloakIPv6(ip) {
|
function cloakIPv6(ip) {
|
||||||
var parts = ip.split(":");
|
var parts = ip.split(":");
|
||||||
parts.splice(4, 4);
|
parts.splice(4, 4);
|
||||||
|
var accumulator = "";
|
||||||
|
|
||||||
parts = parts.map(function (segment, i) {
|
parts = parts.map(function (segment, i) {
|
||||||
if (i < 2) return segment;
|
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("*");
|
while (parts.length < 4) parts.push("*");
|
||||||
|
|
Loading…
Reference in New Issue