Search user private chats as administrator
-
Is there any way to find specific text in all users' private chats as an administrator, either via ACP or by searching the Redis database?
I'll explain why, since there can't be too many non-nefarious reasons for doing this
We had some phishing attempts carried out on users via private chat. I want to find all instances of when a particular URL was sent to anyone via private chat, so I can go through and remove all traces of the URL.
-
You can do this with a custom script like below, take a backup of your database just in case. Then place this script in the root folder of your NodeBB and run it with
node <script_name>
. I've added some comments to the script to explain what's going on./* eslint-disable no-await-in-loop */ 'use strict'; const nconf = require('nconf'); nconf.file({ file: 'config.json', }); nconf.defaults({ base_dir: __dirname, views_dir: './build/public/templates', upload_path: 'public/uploads', }); const db = require('./src/database'); const replace = 'https://somebadlink.com'; const replaceWith = ''; db.init(async (err) => { if (err) { console.log(`NodeBB could not connect to your database. Error: ${err.message}`); process.exit(); } await replaceUrlsInMessages(); console.log('done'); process.exit(); }); function escapeRegExp(text) { return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); } async function replaceUrlsInMessages() { const batch = require('./src/batch'); // go through all chat messages using the batch module // so we don't load all messages in the database at once await batch.processSortedSet('messages:mid', async (mids) => { // load the data for the current batch const msgData = await db.getObjects(mids.map(mid => `message:${mid}`)); // filter messages to the ones that contain the replacement string const msgsToReplace = msgData.filter(m => m && String(m.content).includes(replace)); // replace the content of messages with something else msgsToReplace.forEach((m) => { m.content = m.content.replace( new RegExp(escapeRegExp(replace)), replaceWith ); }); // save back the messages to the database const bulkSet = msgsToReplace.map(m => [`message:${m.mid}`, { content: m.content }]); await db.setObjectBulk(bulkSet); }, { // we are processing 500 messages on each iteration batch: 500, }); }
-
Don't know specifically about radis but there is such a plugin!
https://github.com/yossizahn/nodebb-plugin-chat-perms -