Ban type ip display and storage improvement

indiachan-spamvector
Thomas Lynch 2 years ago
parent 1bba36b48e
commit bdf5da0adc
  1. 8
      lib/middleware/ip/iptypes.js
  2. 8
      lib/middleware/ip/processip.js
  3. 9
      models/forms/banposter.js
  4. 3
      models/forms/reportpost.js
  5. 5
      views/mixins/ban.pug

@ -0,0 +1,8 @@
'use strict';
module.exports = {
IPV4: 0,
IPV6: 1,
BYPASS: 2,
PRUNED: 3,
};

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

@ -24,14 +24,12 @@ module.exports = async (req, res) => {
}, {}); }, {});
for (let ip in ipPosts) { for (let ip in ipPosts) {
//should we at some point filter these to not bother banning pruned ips? //should we at some point filter these to not bother banning pruned ips?
const banType = ip.endsWith('.IP') ? 0 :
ip.endsWith('.BP') ? 1 :
2;
const thisIpPosts = ipPosts[ip]; const thisIpPosts = ipPosts[ip];
let banRange = 0; let banRange = 0;
let banIp = { let banIp = {
cloak: thisIpPosts[0].ip.cloak, cloak: thisIpPosts[0].ip.cloak,
raw: thisIpPosts[0].ip.raw, raw: thisIpPosts[0].ip.raw,
type: thisIpPosts[0].ip.type,
}; };
if (req.body.ban_h) { if (req.body.ban_h) {
banRange = 2; banRange = 2;
@ -48,7 +46,6 @@ module.exports = async (req, res) => {
} }
bans.push({ bans.push({
'range': banRange, 'range': banRange,
'type': banType,
'ip': banIp, 'ip': banIp,
'reason': banReason, 'reason': banReason,
'board': banBoard, 'board': banBoard,
@ -87,11 +84,7 @@ module.exports = async (req, res) => {
} }
ips = ips.filter(n => n); ips = ips.filter(n => n);
[...new Set(ips)].forEach(ip => { [...new Set(ips)].forEach(ip => {
const banType = ip.cloak.endsWith('.IP') ? 0 :
ip.cloak.endsWith('.BP') ? 1 :
2;
bans.push({ bans.push({
'type': banType,
'range': 0, 'range': 0,
'ip': ip, 'ip': ip,
'reason': banReason, 'reason': banReason,

@ -10,7 +10,8 @@ module.exports = (req, res) => {
'date': new Date(), 'date': new Date(),
'ip': { 'ip': {
'cloak': res.locals.ip.cloak, 'cloak': res.locals.ip.cloak,
'raw': res.locals.ip.raw 'raw': res.locals.ip.raw,
'type': res.locals.ip.type,
} }
}; };

@ -1,4 +1,5 @@
include ./post.pug include ./post.pug
mixin ban(ban, banpage) mixin ban(ban, banpage)
tr tr
td td
@ -15,8 +16,8 @@ mixin ban(ban, banpage)
td #{ip} td #{ip}
else else
td #{ip}#{'.*'.repeat(ban.range)} td #{ip}#{'.*'.repeat(ban.range)}
td #{ban.type === 0 ? 'IP' : ban.type === 1 ? 'Bypass' : 'Pruned IP'} td #{['IPV4', 'IPV6', 'Bypass', 'Pruned IP'][ban.ip.type]}
td #{ban.range === 0 ? 'Single' : ban.range === 1 ? 'Narrow' : 'Wide'} td #{['Single', 'Narrow', 'Wide'][ban.range]}
td #{(!banpage || ban.showUser === true) ? ban.issuer : 'Hidden User'} td #{(!banpage || ban.showUser === true) ? ban.issuer : 'Hidden User'}
- const banDate = new Date(ban.date); - const banDate = new Date(ban.date);
td: time.right.reltime(datetime=banDate.toISOString()) #{banDate.toLocaleString(undefined, {hourCycle:'h23'})} td: time.right.reltime(datetime=banDate.toISOString()) #{banDate.toLocaleString(undefined, {hourCycle:'h23'})}

Loading…
Cancel
Save