|
|
@ -16,7 +16,7 @@ const gulp = require('gulp') |
|
|
|
, pug = require('pug') |
|
|
|
, pug = require('pug') |
|
|
|
, gulppug = require('gulp-pug') |
|
|
|
, gulppug = require('gulp-pug') |
|
|
|
, { migrateVersion } = require(__dirname+'/package.json') |
|
|
|
, { migrateVersion } = require(__dirname+'/package.json') |
|
|
|
, { randomBytes } = require('crypto') |
|
|
|
, { createHash, randomBytes } = require('crypto') |
|
|
|
, paths = { |
|
|
|
, paths = { |
|
|
|
styles: { |
|
|
|
styles: { |
|
|
|
src: 'gulp/res/css/', |
|
|
|
src: 'gulp/res/css/', |
|
|
@ -58,6 +58,59 @@ async function password() { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function ips() { |
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
prune IPs from old posts (actually, rehash them with a temporary random salt to maintain |
|
|
|
|
|
|
|
post history and prevent *-by-ip action unintentionally deleting many posts) |
|
|
|
|
|
|
|
NOTE: ips may still remain in the following collections: |
|
|
|
|
|
|
|
- bans, because bans need the IP to function |
|
|
|
|
|
|
|
- modlog actioner ips, modlogs are already auto-pruned |
|
|
|
|
|
|
|
- ratelimits, these only last 1 minute |
|
|
|
|
|
|
|
- stats, these last max of 24 hours |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
const Mongo = require(__dirname+'/db/db.js') |
|
|
|
|
|
|
|
await Mongo.connect(); |
|
|
|
|
|
|
|
const Redis = require(__dirname+'/redis.js') |
|
|
|
|
|
|
|
const { Posts } = require(__dirname+'/db/'); |
|
|
|
|
|
|
|
const beforeDate = new Date(); |
|
|
|
|
|
|
|
beforeDate.setDate(beforeDate.getDate() - 7); //7 days in the past, static number for now until i implement yargs or similar
|
|
|
|
|
|
|
|
const beforeDateMongoId = Mongo.ObjectId.createFromTime(Math.floor(beforeDate.getTime()/1000)); |
|
|
|
|
|
|
|
const tempIpHashSecret = randomBytes(20).toString('base64'); |
|
|
|
|
|
|
|
const bulkWrites = []; |
|
|
|
|
|
|
|
await Posts.db.find({ |
|
|
|
|
|
|
|
_id: { |
|
|
|
|
|
|
|
$lte: beforeDateMongoId, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
'ip.pruned': { |
|
|
|
|
|
|
|
$ne: true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}).forEach(post => { |
|
|
|
|
|
|
|
const randomIP = createHash('sha256').update(tempIpHashSecret + post.ip.single).digest('base64'); |
|
|
|
|
|
|
|
bulkWrites.push({ |
|
|
|
|
|
|
|
updateOne: { |
|
|
|
|
|
|
|
filter: { |
|
|
|
|
|
|
|
_id: post._id, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
update: { |
|
|
|
|
|
|
|
$set: { |
|
|
|
|
|
|
|
'ip.pruned': true, |
|
|
|
|
|
|
|
'ip.raw': randomIP, |
|
|
|
|
|
|
|
'ip.single': randomIP, |
|
|
|
|
|
|
|
'ip.qrange': randomIP, |
|
|
|
|
|
|
|
'ip.hrange': randomIP, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
console.log(`Randomising ip on ${bulkWrites.length} posts`); |
|
|
|
|
|
|
|
if (bulkWrites.length.length > 0) { |
|
|
|
|
|
|
|
await Posts.db.bulkWrite(bulkWrites); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Redis.redisClient.quit(); |
|
|
|
|
|
|
|
return Mongo.client.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function wipe() { |
|
|
|
async function wipe() { |
|
|
|
|
|
|
|
|
|
|
|
const Mongo = require(__dirname+'/db/db.js') |
|
|
|
const Mongo = require(__dirname+'/db/db.js') |
|
|
@ -397,5 +450,6 @@ module.exports = { |
|
|
|
cache, |
|
|
|
cache, |
|
|
|
migrate, |
|
|
|
migrate, |
|
|
|
password, |
|
|
|
password, |
|
|
|
|
|
|
|
ips, |
|
|
|
default: build, |
|
|
|
default: build, |
|
|
|
}; |
|
|
|
}; |
|
|
|