|
|
|
@ -3,6 +3,7 @@ |
|
|
|
|
const config = require(__dirname+'/../../misc/config.js') |
|
|
|
|
, { createCIDR, parse } = require('ip6addr') |
|
|
|
|
, hashIp = require(__dirname+'/../../misc/haship.js') |
|
|
|
|
, ipTypes = require(__dirname+'/iptypes.js') |
|
|
|
|
, { ObjectId } = require(__dirname+'/../../../db/db.js'); |
|
|
|
|
|
|
|
|
|
module.exports = (req, res, next) => { |
|
|
|
@ -14,6 +15,7 @@ module.exports = (req, res, next) => { |
|
|
|
|
res.locals.ip = { |
|
|
|
|
raw: `${pseudoIp}.BP`, |
|
|
|
|
cloak: `${pseudoIp}.BP`, |
|
|
|
|
type: ipTypes.BYPASS, |
|
|
|
|
}; |
|
|
|
|
return next(); |
|
|
|
|
} |
|
|
|
@ -30,18 +32,22 @@ module.exports = (req, res, next) => { |
|
|
|
|
zeroPad: false, |
|
|
|
|
}); |
|
|
|
|
let qrange |
|
|
|
|
, hrange; |
|
|
|
|
, hrange |
|
|
|
|
, type; |
|
|
|
|
if (ipKind === 'ipv4') { |
|
|
|
|
qrange = createCIDR(ipStr, 24).toString(); |
|
|
|
|
hrange = createCIDR(ipStr, 16).toString(); |
|
|
|
|
type = ipTypes.IPV4; |
|
|
|
|
} else { |
|
|
|
|
qrange = createCIDR(ipStr, 64).toString(); |
|
|
|
|
hrange = createCIDR(ipStr, 48).toString(); |
|
|
|
|
type = ipTypes.IPV6; |
|
|
|
|
} |
|
|
|
|
const cloak = `${hashIp(hrange).substring(0,8)}.${hashIp(qrange).substring(0,7)}.${hashIp(ipStr).substring(0,7)}.IP${ipKind.charAt(3)}`; |
|
|
|
|
res.locals.ip = { |
|
|
|
|
raw: dontStoreRawIps === true ? cloak : ipStr, |
|
|
|
|
cloak, |
|
|
|
|
type, |
|
|
|
|
}; |
|
|
|
|
next(); |
|
|
|
|
} catch(e) { |
|
|
|
|