mirror of https://gitgud.io/fatchan/jschan.git
commit
137e3a8809
54 changed files with 408 additions and 161 deletions
@ -1,15 +1,17 @@ |
|||||||
'use strict'; |
'use strict'; |
||||||
|
|
||||||
const escapeRegExp = require(__dirname+'/escaperegexp.js') |
const escapeRegExp = require(__dirname+'/escaperegexp.js') |
||||||
|
, { isIP } = require('net') |
||||||
, { ipHashPermLevel } = require(__dirname+'/../configs/main.js') |
, { ipHashPermLevel } = require(__dirname+'/../configs/main.js') |
||||||
|
|
||||||
module.exports = (query, permLevel) => { |
module.exports = (query, permLevel) => { |
||||||
if (query.ip && typeof query.ip === 'string') { |
if (query.ip && typeof query.ip === 'string') { |
||||||
const decoded = decodeURIComponent(query.ip); |
const decoded = decodeURIComponent(query.ip); |
||||||
const hashed = permLevel > ipHashPermLevel; |
if (permLevel <= ipHashPermLevel && isIP(decoded)) { //if perms to view raw ip, allow querying
|
||||||
if (!hashed || decoded.length === 10) { |
return decoded; |
||||||
|
} else if (decoded.length === 10) { //otherwise, only allow last 10 char substring
|
||||||
return new RegExp(`${escapeRegExp(decoded)}$`); |
return new RegExp(`${escapeRegExp(decoded)}$`); |
||||||
} |
} |
||||||
} |
} |
||||||
return null; |
return null; //else, no ip filter
|
||||||
} |
} |
||||||
|
@ -0,0 +1,12 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
module.exports = async(db, redis) => { |
||||||
|
console.log('add sageOnlyEmail option to boards'); |
||||||
|
await db.collection('boards').updateMany({}, { |
||||||
|
'$set': { |
||||||
|
'settings.sageOnlyEmail': false, |
||||||
|
} |
||||||
|
}); |
||||||
|
console.log('Cleared boards cache'); |
||||||
|
await redis.deletePattern('board:*'); |
||||||
|
}; |
@ -0,0 +1,12 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
module.exports = async(db, redis) => { |
||||||
|
console.log('add resetTrigger option to boards'); |
||||||
|
await db.collection('boards').updateMany({}, { |
||||||
|
'$set': { |
||||||
|
'settings.resetTrigger': false, |
||||||
|
} |
||||||
|
}); |
||||||
|
console.log('Cleared boards cache'); |
||||||
|
await redis.deletePattern('board:*'); |
||||||
|
}; |
@ -0,0 +1,56 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
const hashIp = require(__dirname+'/../helpers/haship.js'); |
||||||
|
|
||||||
|
module.exports = async(db, redis) => { |
||||||
|
console.log('change bans index'); |
||||||
|
await db.collection('bans').dropIndex("ip_1_board_1"); |
||||||
|
await db.collection('bans').createIndex({ 'ip.single': 1 , 'board': 1 }); |
||||||
|
console.log('adjusting ip on posts and clearing reports'); |
||||||
|
const promises = [] |
||||||
|
await db.collection('posts').find().forEach(doc => { |
||||||
|
promises.push(db.collection('posts').updateOne({ |
||||||
|
'_id':doc._id |
||||||
|
}, { |
||||||
|
'$set':{ |
||||||
|
'ip.raw': doc.ip.single, |
||||||
|
'ip.single': hashIp(doc.ip.single), |
||||||
|
'ip.qrange': hashIp(doc.ip.qrange), |
||||||
|
'ip.hrange': hashIp(doc.ip.hrange), |
||||||
|
'reports': [], //easier than fixing reports
|
||||||
|
'globalreports': [], //easier than fixing reports
|
||||||
|
} |
||||||
|
})) |
||||||
|
}); |
||||||
|
console.log('adjusting ip in modlogs') |
||||||
|
await db.collection('modlog').find().forEach(doc => { |
||||||
|
promises.push(db.collection('modlog').updateOne({ |
||||||
|
'_id':doc._id |
||||||
|
}, { |
||||||
|
'$set':{ |
||||||
|
'ip': { |
||||||
|
'raw': doc.ip, |
||||||
|
'single': hashIp(doc.ip) |
||||||
|
} |
||||||
|
} |
||||||
|
})) |
||||||
|
}); |
||||||
|
console.log('adjust ip in bans, set null type and remove saved posts') |
||||||
|
await db.collection('bans').find().forEach(doc => { |
||||||
|
promises.push(db.collection('bans').updateOne({ |
||||||
|
'_id':doc._id |
||||||
|
}, { |
||||||
|
'$set':{ |
||||||
|
'ip': { |
||||||
|
'raw': doc.ip, |
||||||
|
'single': hashIp(doc.ip) |
||||||
|
}, |
||||||
|
'type': null, |
||||||
|
'posts': null //easier than fixing all saved posts
|
||||||
|
} |
||||||
|
})) |
||||||
|
}); |
||||||
|
await Promise.all(promises); |
||||||
|
console.log('Cleared boards cache'); |
||||||
|
await redis.deletePattern('board:*'); |
||||||
|
}; |
Loading…
Reference in new issue