mirror of
https://github.com/luxfi/pics.git
synced 2026-10-30 15:22:15 +00:00
add simple regex for handling ipv4/6 instead of assuming all ipv4 actually append 4/6 to existing cloaks set type 0 on all bans/posts before applying correct types to ensure all have at least some ip type
102 lines
1.8 KiB
JavaScript
102 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
module.exports = async(db, redis) => {
|
|
|
|
console.log('changing post/report/ban ip type storage format');
|
|
|
|
await db.collection('posts').updateMany({
|
|
/* Make sure they all existing ones at least have a type
|
|
in case the site uses "dont store raw ips" */
|
|
}, {
|
|
'$set': {
|
|
'ip.type': 0,
|
|
}
|
|
});
|
|
await db.collection('posts').updateMany({
|
|
'ip.raw': /^([0-9]+(\.|$)){4}/
|
|
}, [{
|
|
'$set': {
|
|
'ip.type': 0,
|
|
'ip.cloak': {
|
|
$concat: ['$ip.cloak', '4']
|
|
}
|
|
}
|
|
}]);
|
|
await db.collection('posts').updateMany({
|
|
'ip.raw': /:/
|
|
}, [{
|
|
'$set': {
|
|
'ip.type': 1,
|
|
'ip.cloak': {
|
|
$concat: ['$ip.cloak', '6']
|
|
}
|
|
}
|
|
}]);
|
|
await db.collection('posts').updateMany({
|
|
'ip.cloak': /PRUNED$/
|
|
}, {
|
|
'$set': {
|
|
'ip.type': 3,
|
|
}
|
|
});
|
|
await db.collection('posts').updateMany({
|
|
'ip.cloak': /BP$/
|
|
}, {
|
|
'$set': {
|
|
'ip.type': 2,
|
|
}
|
|
});
|
|
await db.collection('posts').updateMany({}, {
|
|
'$set': {
|
|
reports: [],
|
|
globalreports: [],
|
|
}
|
|
});
|
|
|
|
await db.collection('bans').updateMany({
|
|
/* Make sure they all existing ones at least have a type
|
|
in case the site uses "dont store raw ips" */
|
|
}, {
|
|
'$set': {
|
|
'ip.type': 0,
|
|
}
|
|
});
|
|
await db.collection('bans').updateMany({
|
|
'ip.raw': /^([0-9]+(\.|$)){4}/
|
|
}, [{
|
|
'$set': {
|
|
'ip.type': 0,
|
|
'ip.cloak': {
|
|
$concat: ['$ip.cloak', '4']
|
|
}
|
|
}
|
|
}]);
|
|
await db.collection('bans').updateMany({
|
|
'ip.raw': /:/
|
|
}, [{
|
|
'$set': {
|
|
'ip.type': 1,
|
|
'ip.cloak': {
|
|
$concat: ['$ip.cloak', '6']
|
|
}
|
|
}
|
|
}]);
|
|
await db.collection('bans').updateMany({
|
|
'ip.cloak': /PRUNED$/
|
|
}, {
|
|
'$set': {
|
|
'ip.type': 3,
|
|
}
|
|
});
|
|
await db.collection('bans').updateMany({
|
|
'ip.cloak': /BP$/
|
|
}, {
|
|
'$set': {
|
|
'ip.type': 2,
|
|
}
|
|
});
|
|
|
|
console.log('Clearing globalsettings cache');
|
|
await redis.deletePattern('globalsettings');
|
|
};
|