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')
, { 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) {

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

@ -10,7 +10,8 @@ module.exports = (req, res) => {
'date': new Date(),
'ip': {
'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
mixin ban(ban, banpage)
tr
td
@ -15,8 +16,8 @@ mixin ban(ban, banpage)
td #{ip}
else
td #{ip}#{'.*'.repeat(ban.range)}
td #{ban.type === 0 ? 'IP' : ban.type === 1 ? 'Bypass' : 'Pruned IP'}
td #{ban.range === 0 ? 'Single' : ban.range === 1 ? 'Narrow' : 'Wide'}
td #{['IPV4', 'IPV6', 'Bypass', 'Pruned IP'][ban.ip.type]}
td #{['Single', 'Narrow', 'Wide'][ban.range]}
td #{(!banpage || ban.showUser === true) ? ban.issuer : 'Hidden User'}
- const banDate = new Date(ban.date);
td: time.right.reltime(datetime=banDate.toISOString()) #{banDate.toLocaleString(undefined, {hourCycle:'h23'})}

Loading…
Cancel
Save