rename ip.single -> ip.cloak

merge-requests/341/head
Thomas Lynch 2 years ago
parent 363b87a498
commit 92c504e59c
  1. 2
      controllers/forms/boardsettings.js
  2. 2
      controllers/forms/editpost.js
  3. 10
      db/bans.js
  4. 8
      db/posts.js
  5. 2
      gulpfile.js
  6. 2
      helpers/captcha/verify.js
  7. 4
      helpers/checks/spamcheck.js
  8. 8
      helpers/processip.js
  9. 6
      models/forms/actionhandler.js
  10. 2
      models/forms/appeal.js
  11. 12
      models/forms/banposter.js
  12. 4
      models/forms/editpost.js
  13. 12
      models/forms/makepost.js
  14. 2
      models/forms/reportpost.js
  15. 2
      models/pages/captcha.js
  16. 2
      models/pages/globalmanage/logs.js
  17. 2
      models/pages/manage/recent.js
  18. 4
      schedules/tasks/ips.js
  19. 2
      views/mixins/ban.pug
  20. 4
      views/mixins/post.pug
  21. 2
      views/mixins/report.pug
  22. 2
      views/pages/globalmanagelogs.pug
  23. 2
      views/pages/managelogs.pug
  24. 2
      views/pages/managerecent.pug

@ -85,7 +85,7 @@ module.exports = {
if (res.locals.permLevel > 1) { //if not global staff or above
const ratelimitBoard = await Ratelimits.incrmentQuota(req.params.board, 'settings', rateLimitCost.boardSettings); //2 changes a minute
const ratelimitIp = res.locals.anonymizer ? 0 : (await Ratelimits.incrmentQuota(res.locals.ip.single, 'settings', rateLimitCost.boardSettings));
const ratelimitIp = res.locals.anonymizer ? 0 : (await Ratelimits.incrmentQuota(res.locals.ip.cloak, 'settings', rateLimitCost.boardSettings));
if (ratelimitBoard > 100 || ratelimitIp > 100) {
return dynamicResponse(req, res, 429, 'message', {
'title': 'Ratelimited',

@ -43,7 +43,7 @@ module.exports = {
if (res.locals.permLevel > 1) { //if not global staff or above
const ratelimitUser = await Ratelimits.incrmentQuota(req.session.user, 'edit', rateLimitCost.editPost);
const ratelimitIp = res.locals.anonymizer ? 0 : (await Ratelimits.incrmentQuota(res.locals.ip.single, 'edit', rateLimitCost.editPost));
const ratelimitIp = res.locals.anonymizer ? 0 : (await Ratelimits.incrmentQuota(res.locals.ip.cloak, 'edit', rateLimitCost.editPost));
if (ratelimitUser > 100 || ratelimitIp > 100) {
return dynamicResponse(req, res, 429, 'message', {
'title': 'Ratelimited',

@ -13,16 +13,16 @@ module.exports = {
if (typeof ip === 'object') {
ipQuery = {
'$in': [
ip.single, //full ip
ip.single.split('.').slice(0,2).join('.'), //qrange
ip.single.split('.').slice(0,1).join('.'), //hrange
ip.cloak, //full ip
ip.cloak.split('.').slice(0,2).join('.'), //qrange
ip.cloak.split('.').slice(0,1).join('.'), //hrange
],
}
} else {
ipQuery = ip;
}
return db.find({
'ip.single': ipQuery,
'ip.cloak': ipQuery,
'board': {
'$in': [board, null]
}
@ -46,7 +46,7 @@ module.exports = {
'_id': {
'$in': ids
},
'ip.single': ip,
'ip.cloak': ip,
'allowAppeal': true,
'appeal': null
}, {

@ -40,7 +40,7 @@ module.exports = {
if (isIP(ip)) {
query['ip.raw'] = ip;
} else {
query['ip.single'] = ip;
query['ip.cloak'] = ip;
}
}
if (permLevel > config.get.ipHashPermLevel) {
@ -467,7 +467,7 @@ module.exports = {
//insert the post itself
const postMongoId = await db.insertOne(data).then(result => result.insertedId); //_id of post
const statsIp = (config.get.statsCountAnonymizers === false && res.locals.anonymizer === true) ? null : data.ip.single;
const statsIp = (config.get.statsCountAnonymizers === false && res.locals.anonymizer === true) ? null : data.ip.cloak;
await Stats.updateOne(board._id, statsIp, data.thread == null);
//add backlinks to the posts this post quotes
@ -559,8 +559,8 @@ module.exports = {
];
} else {
query['$or'] = [
{ 'ip.single': ip },
{ 'globalreports.ip.single': ip }
{ 'ip.cloak': ip },
{ 'globalreports.ip.cloak': ip }
];
}
}

@ -192,7 +192,7 @@ async function wipe() {
await CustomPages.db.createIndex({ 'board': 1, 'page': 1 }, { unique: true })
await Modlogs.db.createIndex({ 'board': 1 })
await Files.db.createIndex({ 'count': 1 })
await Bans.db.createIndex({ 'ip.single': 1 , 'board': 1 })
await Bans.db.createIndex({ 'ip.cloak': 1 , 'board': 1 })
await Bans.db.createIndex({ 'expireAt': 1 }, { expireAfterSeconds: 0 }) //custom expiry, i.e. it will expire when current date > than this date
await Bypass.db.createIndex({ 'expireAt': 1 }, { expireAfterSeconds: 0 })
await Captchas.db.createIndex({ 'expireAt': 1 }, { expireAfterSeconds: 300 }) //captchas valid for 5 minutes

@ -50,7 +50,7 @@ module.exports = async (req, res, next) => {
//for builtin captchas, clear captchaid cookie, delete file and reset quota
res.clearCookie('captchaid');
await Promise.all([
!res.locals.anonymizer && Ratelimits.resetQuota(res.locals.ip.single, 'captcha'),
!res.locals.anonymizer && Ratelimits.resetQuota(res.locals.ip.cloak, 'captcha'),
remove(`${uploadDirectory}/captcha/${captchaId}.jpg`)
]);
}

@ -57,7 +57,7 @@ module.exports = async (req, res) => {
'_id': {
'$gt': sameContentSameIpMongoId
},
'ip.single': res.locals.ip.single,
'ip.cloak': res.locals.ip.cloak,
'$or': contentOr
});
}
@ -69,7 +69,7 @@ module.exports = async (req, res) => {
'_id': {
'$gt': anyContentSameIpMongoId
},
'ip.single': res.locals.ip.single
'ip.cloak': res.locals.ip.cloak
})
}

@ -13,7 +13,7 @@ module.exports = (req, res, next) => {
const pseudoIp = res.locals.preFetchedBypassId || req.signedCookies.bypassid;
res.locals.ip = {
raw: `${pseudoIp}.BP`,
single: `${pseudoIp}.BP`,
cloak: `${pseudoIp}.BP`,
};
return next();
}
@ -38,10 +38,10 @@ module.exports = (req, res, next) => {
qrange = createCIDR(ipStr, 64).toString();
hrange = createCIDR(ipStr, 48).toString();
}
const single = `${hashIp(hrange).substring(0,8)}.${hashIp(qrange).substring(0,7)}.${hashIp(ipStr).substring(0,7)}.IP`;
const cloak = `${hashIp(hrange).substring(0,8)}.${hashIp(qrange).substring(0,7)}.${hashIp(ipStr).substring(0,7)}.IP`;
res.locals.ip = {
raw: ipHashPermLevel === -1 ? single : ipStr,
single,
raw: ipHashPermLevel === -1 ? cloak : ipStr,
cloak,
}
next();
} catch(e) {

@ -118,13 +118,13 @@ module.exports = async (req, res, next) => {
}
const postsBefore = res.locals.posts.length;
if (req.body.delete_ip_board || req.body.delete_ip_global || req.body.delete_ip_thread) {
const deletePostIps = res.locals.posts.map(x => x.ip.single);
const deletePostIps = res.locals.posts.map(x => x.ip.cloak);
const deletePostMongoIds = res.locals.posts.map(x => x._id)
let query = {
'_id': {
'$nin': deletePostMongoIds
},
'ip.single': {
'ip.cloak': {
'$in': deletePostIps
}
};
@ -314,7 +314,7 @@ module.exports = async (req, res, next) => {
message: message,
user: logUser,
ip: {
single: res.locals.ip.single,
cloak: res.locals.ip.cloak,
raw: res.locals.ip.raw
}
};

@ -4,6 +4,6 @@ const { Bans } = require(__dirname+'/../../db/');
module.exports = async (req, res, next) => {
return Bans.appeal(res.locals.ip.single, req.body.checkedbans, req.body.message).then(r => r.modifiedCount);
return Bans.appeal(res.locals.ip.cloak, req.body.checkedbans, req.body.message).then(r => r.modifiedCount);
}

@ -16,28 +16,28 @@ module.exports = async (req, res, next) => {
if (req.body.ban || req.body.global_ban) {
const banBoard = req.body.global_ban ? null : req.params.board;
const ipPosts = res.locals.posts.reduce((acc, post) => {
if (!acc[post.ip.single]) {
acc[post.ip.single] = [];
if (!acc[post.ip.cloak]) {
acc[post.ip.cloak] = [];
}
acc[post.ip.single].push(post);
acc[post.ip.cloak].push(post);
return acc;
}, {});
for (let ip in ipPosts) {
const thisIpPosts = ipPosts[ip];
let type = 'single';
let banIp = {
single: thisIpPosts[0].ip.single,
cloak: thisIpPosts[0].ip.cloak,
raw: thisIpPosts[0].ip.raw,
};
if (req.body.ban_h) {
type = 'half';
banIp.single = thisIpPosts[0].ip.single
banIp.cloak = thisIpPosts[0].ip.cloak
.split('.')
.slice(0,1)
.join('.');
} else if (req.body.ban_q) {
type = 'quarter';
banIp.single = thisIpPosts[0].ip.single
banIp.cloak = thisIpPosts[0].ip.cloak
.split('.')
.slice(0,2)
.join('.');

@ -51,7 +51,7 @@ todo: handle some more situations
const banExpiry = new Date(globalSettings.filterBanDuration + banDate.getTime());
const ban = {
'ip': {
'single': res.locals.ip.single,
'cloak': res.locals.ip.cloak,
'raw': res.locals.ip.raw,
},
'type': 'single',
@ -163,7 +163,7 @@ todo: handle some more situations
message: req.body.log_message || null,
user: req.session.user,
ip: {
single: res.locals.ip.single,
cloak: res.locals.ip.cloak,
raw: res.locals.ip.raw,
}
});

@ -144,7 +144,7 @@ ${res.locals.numFiles > 0 ? req.files.file.map(f => f.name+'|'+(f.phash || '')).
const banExpiry = new Date(useFilterBanDuration + banDate.getTime());
const ban = {
'ip': {
'single': res.locals.ip.single,
'cloak': res.locals.ip.cloak,
'raw': res.locals.ip.raw,
},
'type': 'single',
@ -612,15 +612,15 @@ ${res.locals.numFiles > 0 ? req.files.file.map(f => f.name+'|'+(f.phash || '')).
//dont emit thread to this socket, because the room onyl exists when the thread is open
Socketio.emitRoom(`${res.locals.board._id}-${data.thread}`, 'newPost', projectedPost);
}
const { raw, single } = data.ip;
const { raw, cloak } = data.ip;
//but emit it to manage pages because they need to get all posts through socket including thread
Socketio.emitRoom('globalmanage-recent-hashed', 'newPost', { ...projectedPost, ip: { single, raw: null } });
Socketio.emitRoom(`${res.locals.board._id}-manage-recent-hashed`, 'newPost', { ...projectedPost, ip: { single, raw: null } });
Socketio.emitRoom('globalmanage-recent-hashed', 'newPost', { ...projectedPost, ip: { cloak, raw: null } });
Socketio.emitRoom(`${res.locals.board._id}-manage-recent-hashed`, 'newPost', { ...projectedPost, ip: { cloak, raw: null } });
if (ipHashPermLevel > -1) {
//small optimisation for boards where this is manually set to -1 for privacy, no need to emit to rooms that cant be accessed
//even if they are empty it will create extra communication noise in redis, socket adapter, etc.
Socketio.emitRoom('globalmanage-recent-raw', 'newPost', { ...projectedPost, ip: { single, raw } });
Socketio.emitRoom(`${res.locals.board._id}-manage-recent-raw`, 'newPost', { ...projectedPost, ip: { single, raw } });
Socketio.emitRoom('globalmanage-recent-raw', 'newPost', { ...projectedPost, ip: { cloak, raw } });
Socketio.emitRoom(`${res.locals.board._id}-manage-recent-raw`, 'newPost', { ...projectedPost, ip: { cloak, raw } });
}
//now add other pages to be built in background

@ -9,7 +9,7 @@ module.exports = (req, res) => {
'reason': req.body.report_reason,
'date': new Date(),
'ip': {
'single': res.locals.ip.single,
'cloak': res.locals.ip.cloak,
'raw': res.locals.ip.raw
}
}

@ -21,7 +21,7 @@ module.exports = async (req, res, next) => {
let maxAge = 5*60*1000;
try {
if (!res.locals.anonymizer) {
const ratelimit = await Ratelimits.incrmentQuota(res.locals.ip.single, 'captcha', rateLimitCost.captcha);
const ratelimit = await Ratelimits.incrmentQuota(res.locals.ip.cloak, 'captcha', rateLimitCost.captcha);
if (ratelimit > 100) {
return res.status(429).redirect('/file/ratelimit.png');
}

@ -24,7 +24,7 @@ module.exports = async (req, res, next) => {
if (isIP(ipMatch)) {
filter['ip.raw'] = ipMatch;
} else {
filter['ip.single'] = ipMatch;
filter['ip.cloak'] = ipMatch;
}
}

@ -13,7 +13,7 @@ module.exports = async (req, res, next) => {
if (postId && +postId === parseInt(postId) && Number.isSafeInteger(+postId)) {
const fetchedPost = await Posts.getPost(req.params.board, +postId, true);
if (fetchedPost) {
ip = decodeQueryIP({ ip: fetchedPost.ip.single }, res.locals.permlevel);
ip = decodeQueryIP({ ip: fetchedPost.ip.cloak }, res.locals.permlevel);
}
}

@ -22,7 +22,7 @@ module.exports = {
$ne: true
}
}).forEach(post => {
const randomIP = createHash('sha256').update(tempIpHashSecret + post.ip.single).digest('base64');
const randomIP = createHash('sha256').update(tempIpHashSecret + post.ip.cloak).digest('base64');
bulkWrites.push({
updateOne: {
filter: {
@ -32,7 +32,7 @@ module.exports = {
$set: {
'ip.pruned': true,
'ip.raw': `${randomIP.slice(-10)}.PRUNED`,
'ip.single': `${randomIP.slice(-10)}.PRUNED`,
'ip.cloak': `${randomIP.slice(-10)}.PRUNED`,
}
}
}

@ -10,7 +10,7 @@ mixin ban(ban, banpage)
else
| Global
td= ban.reason
- const ip = permLevel > ipHashPermLevel ? ban.ip.single : ban.ip.raw;
- const ip = permLevel > ipHashPermLevel ? ban.ip.cloak : ban.ip.raw;
if permLevel > ipHashPermLevel
td #{ip}#{ban.type === 'half' ? '.*.*' : (ban.type === 'quarter' ? '.*' : '')}
else

@ -20,12 +20,12 @@ mixin post(post, truncate, manage=false, globalmanage=false, ban=false, overboar
input.post-check(type='checkbox', name='checkedposts' value=post.postId)
|
if manage
- const ip = permLevel > ipHashPermLevel ? post.ip.single : post.ip.raw;
- const ip = permLevel > ipHashPermLevel ? post.ip.cloak : post.ip.raw;
a.bold(href=`${upLevel ? '../' : ''}recent.html?ip=${encodeURIComponent(ip)}`) [#{ip}]
else if modview
a.bold(href=`${upLevel ? '../' : ''}recent.html?postid=${post.postId}`) [+]
else if globalmanage
- const ip = permLevel > ipHashPermLevel ? post.ip.single : post.ip.raw;
- const ip = permLevel > ipHashPermLevel ? post.ip.cloak : post.ip.raw;
a.bold(href=`?ip=${encodeURIComponent(ip)}`) [#{ip}]
|
if !post.thread

@ -2,7 +2,7 @@ mixin report(r, manage=false)
.reports.post-container
input.post-check(type='checkbox', name='checkedreports' value=r.id)
|
- const ip = permLevel > ipHashPermLevel ? r.ip.single : r.ip.raw;
- const ip = permLevel > ipHashPermLevel ? r.ip.cloak : r.ip.raw;
a.bold(href=`${manage ? 'recent.html' : ''}?ip=${encodeURIComponent(ip)}`) [#{ip}]
|
- const reportDate = new Date(r.date);

@ -52,7 +52,7 @@ block content
|
a(href=`?username=${log.user}`) [+]
td
- const logIp = permLevel > ipHashPermLevel ? log.ip.single : log.ip.raw;
- const logIp = permLevel > ipHashPermLevel ? log.ip.cloak : log.ip.raw;
a(href=`recent.html?ip=${encodeURIComponent(logIp)}`) #{logIp}
|
a(href=`?ip=${encodeURIComponent(logIp)}`) [+]

@ -40,7 +40,7 @@ block content
|
a(href=`?username=${log.user}`) [+]
td
- const logIp = permLevel > ipHashPermLevel ? log.ip.single : log.ip.raw;
- const logIp = permLevel > ipHashPermLevel ? log.ip.cloak : log.ip.raw;
| #{logIp}
td #{log.actions}
td

@ -23,7 +23,7 @@ block content
if posts.length === 0
p No posts.
else
- const ip = permLevel > ipHashPermLevel ? posts[0].ip.single : posts[0].ip.raw;
- const ip = permLevel > ipHashPermLevel ? posts[0].ip.cloak : posts[0].ip.raw;
if postId || (queryIp && queryIp === ip)
h4.no-m-p Post history for #{ip}
|

Loading…
Cancel
Save