|
| 1 | +const { loadConfig } = require('./common') |
| 2 | +const blacklistService = require('../../lib/services/blacklist-service') |
| 3 | +const AccountManager = require('../../lib/models/account-manager') |
| 4 | +const LDP = require('../../lib/ldp') |
| 5 | +const SolidHost = require('../../lib/models/solid-host') |
| 6 | + |
| 7 | +module.exports = function (program) { |
| 8 | + program |
| 9 | + .command('blacklist') |
| 10 | + .option('--notify', 'Will notify users with usernames that are blacklisted') |
| 11 | + .option('--delete', 'Will delete users with usernames that are blacklisted') |
| 12 | + .description('Manage usernames that are blacklisted') |
| 13 | + .action(async (options) => { |
| 14 | + const config = await loadConfig(program, options) |
| 15 | + if (!config.multiuser) { |
| 16 | + return console.error('You are running a single user server, no need to check for blacklisted users') |
| 17 | + } |
| 18 | + const host = SolidHost.from({ port: config.port, serverUri: config.serverUri }) |
| 19 | + |
| 20 | + const ldp = new LDP(config) |
| 21 | + const accountManager = AccountManager.from({ |
| 22 | + // authMethod: argv.auth, |
| 23 | + // emailService: app.locals.emailService, |
| 24 | + // tokenService: app.locals.tokenService, |
| 25 | + host, |
| 26 | + // accountTemplatePath: argv.templates.account, |
| 27 | + store: ldp, |
| 28 | + multiuser: config.multiuser |
| 29 | + }) |
| 30 | + const blacklistedUsernames = await getBlacklistedUsernames(accountManager) |
| 31 | + if (blacklistedUsernames.length === 0) { |
| 32 | + console.log('No blacklisted username was found') |
| 33 | + } |
| 34 | + console.log(`These blacklisted usernames were found:${blacklistedUsernames.map(username => `\n- ${username}`)}`) |
| 35 | + }) |
| 36 | +} |
| 37 | + |
| 38 | +async function getBlacklistedUsernames (accountManager) { |
| 39 | + const blacklistedUsernames = [] |
| 40 | + await Promise.all(blacklistService.list.map(async (word) => { |
| 41 | + const accountExists = await accountManager.accountExists(word) |
| 42 | + if (accountExists) { |
| 43 | + blacklistedUsernames.push(word) |
| 44 | + } |
| 45 | + })) |
| 46 | + return blacklistedUsernames |
| 47 | +} |
0 commit comments