mirror of https://gitgud.io/fatchan/jschan.git
New dev Closes #316 and #319 See merge request fatchan/jschan!212merge-requests/218/head
commit
9351a4bd1f
34 changed files with 172 additions and 112 deletions
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 2.7 KiB |
@ -0,0 +1,12 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
module.exports = async(db, redis) => { |
||||||
|
console.log('Renaming disable onion file posting to disable anonymizer file posting'); |
||||||
|
await db.collection('boards').updateMany({}, { |
||||||
|
'$rename': { |
||||||
|
'settings.disableOnionFilePosting' : 'settings.disableAnonymizerFilePosting', |
||||||
|
} |
||||||
|
}); |
||||||
|
console.log('Cleared boards cache'); |
||||||
|
await redis.deletePattern('board:*'); |
||||||
|
}; |
@ -0,0 +1,11 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
module.exports = async(db, redis) => { |
||||||
|
console.log('fixing index for custompages'); |
||||||
|
try { |
||||||
|
await db.collection('custompages').dropIndex('board_1_url_1'); |
||||||
|
} catch (e) { |
||||||
|
// didnt have the bad index
|
||||||
|
} |
||||||
|
await db.collection('custompages').createIndex({ 'board': 1, 'page': 1 }, { unique: true }); |
||||||
|
}; |
@ -0,0 +1,53 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
/* |
||||||
|
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') |
||||||
|
, { Posts } = require(__dirname+'/../db/') |
||||||
|
, { createHash, randomBytes } = require('crypto') |
||||||
|
, { pruneIps } = require(__dirname+'/../configs/main.js'); |
||||||
|
|
||||||
|
module.exports = async (days) => { |
||||||
|
const beforeDate = new Date(); |
||||||
|
beforeDate.setDate(beforeDate.getDate() - days); |
||||||
|
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); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue