2018-08-26 14:21:03 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-27 16:56:16 -04:00
|
|
|
require 'set'
|
2018-08-26 14:21:03 -04:00
|
|
|
require_relative '../../config/boot'
|
|
|
|
require_relative '../../config/environment'
|
|
|
|
require_relative 'cli_helper'
|
|
|
|
|
|
|
|
module Mastodon
|
|
|
|
class AccountsCLI < Thor
|
2019-09-10 07:48:48 -04:00
|
|
|
include CLIHelper
|
|
|
|
|
2018-10-25 10:05:33 -04:00
|
|
|
def self.exit_on_failure?
|
|
|
|
true
|
|
|
|
end
|
2018-10-27 16:56:16 -04:00
|
|
|
|
2018-08-26 14:21:03 -04:00
|
|
|
option :all, type: :boolean
|
|
|
|
desc 'rotate [USERNAME]', 'Generate and broadcast new keys'
|
|
|
|
long_desc <<-LONG_DESC
|
|
|
|
Generate and broadcast new RSA keys as part of security
|
|
|
|
maintenance.
|
|
|
|
|
|
|
|
With the --all option, all local accounts will be subject
|
|
|
|
to the rotation. Otherwise, and by default, only a single
|
|
|
|
account specified by the USERNAME argument will be
|
|
|
|
processed.
|
|
|
|
LONG_DESC
|
|
|
|
def rotate(username = nil)
|
|
|
|
if options[:all]
|
|
|
|
processed = 0
|
|
|
|
delay = 0
|
2019-09-10 07:48:48 -04:00
|
|
|
scope = Account.local.without_suspended
|
|
|
|
progress = create_progress_bar(scope.count)
|
2018-08-26 14:21:03 -04:00
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
scope.find_in_batches do |accounts|
|
2018-08-26 14:21:03 -04:00
|
|
|
accounts.each do |account|
|
|
|
|
rotate_keys_for_account(account, delay)
|
2019-09-10 07:48:48 -04:00
|
|
|
progress.increment
|
2018-08-26 14:21:03 -04:00
|
|
|
processed += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
delay += 5.minutes
|
|
|
|
end
|
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
progress.finish
|
2018-08-26 14:21:03 -04:00
|
|
|
say("OK, rotated keys for #{processed} accounts", :green)
|
|
|
|
elsif username.present?
|
|
|
|
rotate_keys_for_account(Account.find_local(username))
|
|
|
|
say('OK', :green)
|
|
|
|
else
|
|
|
|
say('No account(s) given', :red)
|
2018-09-14 11:42:22 -04:00
|
|
|
exit(1)
|
2018-08-26 14:21:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-09 07:33:36 -04:00
|
|
|
option :email, required: true
|
|
|
|
option :confirmed, type: :boolean
|
2022-07-04 20:41:40 -04:00
|
|
|
option :role
|
2018-09-09 07:33:36 -04:00
|
|
|
option :reattach, type: :boolean
|
|
|
|
option :force, type: :boolean
|
2018-09-14 11:42:22 -04:00
|
|
|
desc 'create USERNAME', 'Create a new user'
|
2018-09-09 07:33:36 -04:00
|
|
|
long_desc <<-LONG_DESC
|
|
|
|
Create a new user account with a given USERNAME and an
|
|
|
|
e-mail address provided with --email.
|
|
|
|
|
|
|
|
With the --confirmed option, the confirmation e-mail will
|
|
|
|
be skipped and the account will be active straight away.
|
|
|
|
|
2022-07-04 20:41:40 -04:00
|
|
|
With the --role option, the role can be supplied.
|
2018-09-09 07:33:36 -04:00
|
|
|
|
|
|
|
With the --reattach option, the new user will be reattached
|
|
|
|
to a given existing username of an old account. If the old
|
|
|
|
account is still in use by someone else, you can supply
|
|
|
|
the --force option to delete the old record and reattach the
|
|
|
|
username to the new account anyway.
|
|
|
|
LONG_DESC
|
2018-09-14 11:42:22 -04:00
|
|
|
def create(username)
|
2022-07-04 20:41:40 -04:00
|
|
|
role_id = nil
|
|
|
|
|
|
|
|
if options[:role]
|
|
|
|
role = UserRole.find_by(name: options[:role])
|
|
|
|
|
|
|
|
if role.nil?
|
|
|
|
say('Cannot find user role with that name', :red)
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
role_id = role.id
|
|
|
|
end
|
|
|
|
|
2018-09-09 07:33:36 -04:00
|
|
|
account = Account.new(username: username)
|
|
|
|
password = SecureRandom.hex
|
2022-07-04 20:41:40 -04:00
|
|
|
user = User.new(email: options[:email], password: password, agreement: true, approved: true, role_id: role_id, confirmed_at: options[:confirmed] ? Time.now.utc : nil, bypass_invite_request_check: true)
|
2018-09-09 07:33:36 -04:00
|
|
|
|
|
|
|
if options[:reattach]
|
|
|
|
account = Account.find_local(username) || Account.new(username: username)
|
|
|
|
|
|
|
|
if account.user.present? && !options[:force]
|
|
|
|
say('The chosen username is currently in use', :red)
|
|
|
|
say('Use --force to reattach it anyway and delete the other user')
|
|
|
|
return
|
|
|
|
elsif account.user.present?
|
2020-09-15 08:37:58 -04:00
|
|
|
DeleteAccountService.new.call(account, reserve_email: false)
|
2018-09-09 07:33:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-14 13:05:02 -04:00
|
|
|
account.suspended_at = nil
|
|
|
|
user.account = account
|
2018-09-09 07:33:36 -04:00
|
|
|
|
|
|
|
if user.save
|
|
|
|
if options[:confirmed]
|
|
|
|
user.confirmed_at = nil
|
|
|
|
user.confirm!
|
|
|
|
end
|
|
|
|
|
|
|
|
say('OK', :green)
|
|
|
|
say("New password: #{password}")
|
|
|
|
else
|
|
|
|
user.errors.to_h.each do |key, error|
|
|
|
|
say('Failure/Error: ', :red)
|
|
|
|
say(key)
|
2022-07-04 20:41:40 -04:00
|
|
|
say(" #{error}", :red)
|
2018-09-09 07:33:36 -04:00
|
|
|
end
|
2018-09-14 11:42:22 -04:00
|
|
|
|
|
|
|
exit(1)
|
2018-09-09 07:33:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-04 20:41:40 -04:00
|
|
|
option :role
|
2018-09-14 11:42:22 -04:00
|
|
|
option :email
|
|
|
|
option :confirm, type: :boolean
|
|
|
|
option :enable, type: :boolean
|
|
|
|
option :disable, type: :boolean
|
|
|
|
option :disable_2fa, type: :boolean
|
2019-05-03 14:49:27 -04:00
|
|
|
option :approve, type: :boolean
|
2020-02-21 19:29:14 -05:00
|
|
|
option :reset_password, type: :boolean
|
2018-09-14 11:42:22 -04:00
|
|
|
desc 'modify USERNAME', 'Modify a user'
|
|
|
|
long_desc <<-LONG_DESC
|
|
|
|
Modify a user account.
|
|
|
|
|
2022-07-04 20:41:40 -04:00
|
|
|
With the --role option, update the user's role.
|
2018-09-14 11:42:22 -04:00
|
|
|
|
|
|
|
With the --email option, update the user's e-mail address. With
|
|
|
|
the --confirm option, mark the user's e-mail as confirmed.
|
|
|
|
|
|
|
|
With the --disable option, lock the user out of their account. The
|
|
|
|
--enable option is the opposite.
|
|
|
|
|
2019-05-03 14:49:27 -04:00
|
|
|
With the --approve option, the account will be approved, if it was
|
|
|
|
previously not due to not having open registrations.
|
|
|
|
|
2018-09-14 11:42:22 -04:00
|
|
|
With the --disable-2fa option, the two-factor authentication
|
|
|
|
requirement for the user can be removed.
|
2020-02-21 19:29:14 -05:00
|
|
|
|
|
|
|
With the --reset-password option, the user's password is replaced by
|
|
|
|
a randomly-generated one, printed in the output.
|
2018-09-14 11:42:22 -04:00
|
|
|
LONG_DESC
|
|
|
|
def modify(username)
|
|
|
|
user = Account.find_local(username)&.user
|
|
|
|
|
|
|
|
if user.nil?
|
|
|
|
say('No user with such username', :red)
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
if options[:role]
|
2022-07-04 20:41:40 -04:00
|
|
|
role = UserRole.find_by(name: options[:role])
|
|
|
|
|
|
|
|
if role.nil?
|
|
|
|
say('Cannot find user role with that name', :red)
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
user.role_id = role.id
|
2018-09-14 11:42:22 -04:00
|
|
|
end
|
|
|
|
|
2020-02-21 19:29:14 -05:00
|
|
|
password = SecureRandom.hex if options[:reset_password]
|
|
|
|
user.password = password if options[:reset_password]
|
2018-09-14 11:42:22 -04:00
|
|
|
user.email = options[:email] if options[:email]
|
|
|
|
user.disabled = false if options[:enable]
|
|
|
|
user.disabled = true if options[:disable]
|
2019-05-03 14:49:27 -04:00
|
|
|
user.approved = true if options[:approve]
|
2018-09-14 11:42:22 -04:00
|
|
|
user.otp_required_for_login = false if options[:disable_2fa]
|
|
|
|
user.confirm if options[:confirm]
|
|
|
|
|
|
|
|
if user.save
|
|
|
|
say('OK', :green)
|
2020-02-21 19:29:14 -05:00
|
|
|
say("New password: #{password}") if options[:reset_password]
|
2018-09-14 11:42:22 -04:00
|
|
|
else
|
|
|
|
user.errors.to_h.each do |key, error|
|
|
|
|
say('Failure/Error: ', :red)
|
|
|
|
say(key)
|
2022-07-04 20:41:40 -04:00
|
|
|
say(" #{error}", :red)
|
2018-09-14 11:42:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'delete USERNAME', 'Delete a user'
|
2018-09-09 07:33:36 -04:00
|
|
|
long_desc <<-LONG_DESC
|
|
|
|
Remove a user account with a given USERNAME.
|
|
|
|
LONG_DESC
|
2018-09-14 11:42:22 -04:00
|
|
|
def delete(username)
|
2018-09-09 07:33:36 -04:00
|
|
|
account = Account.find_local(username)
|
|
|
|
|
|
|
|
if account.nil?
|
|
|
|
say('No user with such username', :red)
|
2018-09-14 11:42:22 -04:00
|
|
|
exit(1)
|
2018-09-09 07:33:36 -04:00
|
|
|
end
|
|
|
|
|
2018-09-27 21:34:24 -04:00
|
|
|
say("Deleting user with #{account.statuses_count} statuses, this might take a while...")
|
2020-09-15 08:37:58 -04:00
|
|
|
DeleteAccountService.new.call(account, reserve_email: false)
|
2018-09-09 07:33:36 -04:00
|
|
|
say('OK', :green)
|
|
|
|
end
|
|
|
|
|
2020-11-23 11:50:16 -05:00
|
|
|
option :force, type: :boolean, aliases: [:f], description: 'Override public key check'
|
|
|
|
desc 'merge FROM TO', 'Merge two remote accounts into one'
|
|
|
|
long_desc <<-LONG_DESC
|
|
|
|
Merge two remote accounts specified by their username@domain
|
|
|
|
into one, whereby the TO account is the one being merged into
|
|
|
|
and kept, while the FROM one is removed. It is primarily meant
|
|
|
|
to fix duplicates caused by other servers changing their domain.
|
|
|
|
|
|
|
|
The command by default only works if both accounts have the same
|
|
|
|
public key to prevent mistakes. To override this, use the --force.
|
|
|
|
LONG_DESC
|
|
|
|
def merge(from_acct, to_acct)
|
|
|
|
username, domain = from_acct.split('@')
|
|
|
|
from_account = Account.find_remote(username, domain)
|
|
|
|
|
|
|
|
if from_account.nil? || from_account.local?
|
|
|
|
say("No such account (#{from_acct})", :red)
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
username, domain = to_acct.split('@')
|
|
|
|
to_account = Account.find_remote(username, domain)
|
|
|
|
|
|
|
|
if to_account.nil? || to_account.local?
|
|
|
|
say("No such account (#{to_acct})", :red)
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
if from_account.public_key != to_account.public_key && !options[:force]
|
|
|
|
say("Accounts don't have the same public key, might not be duplicates!", :red)
|
|
|
|
say('Override with --force', :red)
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
to_account.merge_with!(from_account)
|
|
|
|
from_account.destroy
|
|
|
|
|
|
|
|
say('OK', :green)
|
|
|
|
end
|
|
|
|
|
2020-12-18 17:26:26 -05:00
|
|
|
desc 'fix-duplicates', 'Find duplicate remote accounts and merge them'
|
|
|
|
option :dry_run, type: :boolean
|
|
|
|
long_desc <<-LONG_DESC
|
|
|
|
Merge known remote accounts sharing an ActivityPub actor identifier.
|
|
|
|
|
|
|
|
Such duplicates can occur when a remote server admin misconfigures their
|
|
|
|
domain configuration.
|
|
|
|
LONG_DESC
|
|
|
|
def fix_duplicates
|
2020-12-19 07:34:16 -05:00
|
|
|
Account.remote.select(:uri, 'count(*)').group(:uri).having('count(*) > 1').pluck(:uri).each do |uri|
|
2020-12-18 17:26:26 -05:00
|
|
|
say("Duplicates found for #{uri}")
|
|
|
|
begin
|
2020-12-19 07:34:16 -05:00
|
|
|
ActivityPub::FetchRemoteAccountService.new.call(uri) unless options[:dry_run]
|
2020-12-18 17:26:26 -05:00
|
|
|
rescue => e
|
|
|
|
say("Error processing #{uri}: #{e}", :red)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-27 21:34:24 -04:00
|
|
|
desc 'backup USERNAME', 'Request a backup for a user'
|
|
|
|
long_desc <<-LONG_DESC
|
|
|
|
Request a new backup for an account with a given USERNAME.
|
|
|
|
|
|
|
|
The backup will be created in Sidekiq asynchronously, and
|
|
|
|
the user will receive an e-mail with a link to it once
|
|
|
|
it's done.
|
|
|
|
LONG_DESC
|
|
|
|
def backup(username)
|
|
|
|
account = Account.find_local(username)
|
|
|
|
|
|
|
|
if account.nil?
|
|
|
|
say('No user with such username', :red)
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
backup = account.user.backups.create!
|
|
|
|
BackupWorker.perform_async(backup.id)
|
|
|
|
say('OK', :green)
|
|
|
|
end
|
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
option :concurrency, type: :numeric, default: 5, aliases: [:c]
|
2018-09-09 07:33:36 -04:00
|
|
|
option :dry_run, type: :boolean
|
2021-10-14 15:09:56 -04:00
|
|
|
desc 'cull [DOMAIN...]', 'Remove remote accounts that no longer exist'
|
2018-09-09 07:33:36 -04:00
|
|
|
long_desc <<-LONG_DESC
|
|
|
|
Query every single remote account in the database to determine
|
|
|
|
if it still exists on the origin server, and if it doesn't,
|
|
|
|
remove it from the database.
|
|
|
|
|
|
|
|
Accounts that have had confirmed activity within the last week
|
|
|
|
are excluded from the checks.
|
|
|
|
LONG_DESC
|
2021-10-14 15:09:56 -04:00
|
|
|
def cull(*domains)
|
2018-10-27 16:56:16 -04:00
|
|
|
skip_threshold = 7.days.ago
|
|
|
|
dry_run = options[:dry_run] ? ' (DRY RUN)' : ''
|
2019-09-10 07:48:48 -04:00
|
|
|
skip_domains = Concurrent::Set.new
|
2018-09-09 07:33:36 -04:00
|
|
|
|
2021-10-14 15:09:56 -04:00
|
|
|
query = Account.remote.where(protocol: :activitypub)
|
|
|
|
query = query.where(domain: domains) unless domains.empty?
|
|
|
|
|
|
|
|
processed, culled = parallelize_with_progress(query.partitioned) do |account|
|
2019-09-10 07:48:48 -04:00
|
|
|
next if account.updated_at >= skip_threshold || (account.last_webfingered_at.present? && account.last_webfingered_at >= skip_threshold) || skip_domains.include?(account.domain)
|
2018-09-09 07:33:36 -04:00
|
|
|
|
2019-04-04 10:46:27 -04:00
|
|
|
code = 0
|
2019-09-10 07:48:48 -04:00
|
|
|
|
|
|
|
begin
|
|
|
|
code = Request.new(:head, account.uri).perform(&:code)
|
2021-10-14 15:08:37 -04:00
|
|
|
rescue HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError
|
2019-09-10 07:48:48 -04:00
|
|
|
skip_domains << account.domain
|
2018-09-09 07:33:36 -04:00
|
|
|
end
|
|
|
|
|
2018-10-21 16:52:27 -04:00
|
|
|
if [404, 410].include?(code)
|
2020-11-07 18:28:39 -05:00
|
|
|
DeleteAccountService.new.call(account, reserve_username: false) unless options[:dry_run]
|
2019-09-10 07:48:48 -04:00
|
|
|
1
|
2018-09-09 07:33:36 -04:00
|
|
|
else
|
2019-09-10 07:48:48 -04:00
|
|
|
# Touch account even during dry run to avoid getting the account into the window again
|
|
|
|
account.touch
|
2018-09-09 07:33:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
say("Visited #{processed} accounts, removed #{culled}#{dry_run}", :green)
|
2018-09-09 07:33:36 -04:00
|
|
|
|
2018-10-27 16:56:16 -04:00
|
|
|
unless skip_domains.empty?
|
2019-09-10 07:48:48 -04:00
|
|
|
say('The following domains were not available during the check:', :yellow)
|
2022-07-04 20:41:40 -04:00
|
|
|
skip_domains.each { |domain| say(" #{domain}") }
|
2018-09-09 07:33:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-14 11:42:22 -04:00
|
|
|
option :all, type: :boolean
|
|
|
|
option :domain
|
2019-09-10 07:48:48 -04:00
|
|
|
option :concurrency, type: :numeric, default: 5, aliases: [:c]
|
|
|
|
option :verbose, type: :boolean, aliases: [:v]
|
|
|
|
option :dry_run, type: :boolean
|
2018-09-14 11:42:22 -04:00
|
|
|
desc 'refresh [USERNAME]', 'Fetch remote user data and files'
|
|
|
|
long_desc <<-LONG_DESC
|
|
|
|
Fetch remote user data and files for one or multiple accounts.
|
|
|
|
|
|
|
|
With the --all option, all remote accounts will be processed.
|
|
|
|
Through the --domain option, this can be narrowed down to a
|
|
|
|
specific domain only. Otherwise, a single remote account must
|
|
|
|
be specified with USERNAME.
|
|
|
|
LONG_DESC
|
|
|
|
def refresh(username = nil)
|
2019-09-10 07:48:48 -04:00
|
|
|
dry_run = options[:dry_run] ? ' (DRY RUN)' : ''
|
|
|
|
|
2018-09-14 11:42:22 -04:00
|
|
|
if options[:domain] || options[:all]
|
|
|
|
scope = Account.remote
|
|
|
|
scope = scope.where(domain: options[:domain]) if options[:domain]
|
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
processed, = parallelize_with_progress(scope) do |account|
|
|
|
|
next if options[:dry_run]
|
|
|
|
|
|
|
|
account.reset_avatar!
|
|
|
|
account.reset_header!
|
|
|
|
account.save
|
2018-09-14 11:42:22 -04:00
|
|
|
end
|
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
say("Refreshed #{processed} accounts#{dry_run}", :green, true)
|
2018-09-14 11:42:22 -04:00
|
|
|
elsif username.present?
|
|
|
|
username, domain = username.split('@')
|
|
|
|
account = Account.find_remote(username, domain)
|
|
|
|
|
|
|
|
if account.nil?
|
|
|
|
say('No such account', :red)
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
unless options[:dry_run]
|
|
|
|
account.reset_avatar!
|
|
|
|
account.reset_header!
|
|
|
|
account.save
|
|
|
|
end
|
|
|
|
|
|
|
|
say("OK#{dry_run}", :green)
|
2018-09-14 11:42:22 -04:00
|
|
|
else
|
|
|
|
say('No account(s) given', :red)
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
option :concurrency, type: :numeric, default: 5, aliases: [:c]
|
|
|
|
option :verbose, type: :boolean, aliases: [:v]
|
|
|
|
desc 'follow USERNAME', 'Make all local accounts follow account specified by USERNAME'
|
|
|
|
def follow(username)
|
|
|
|
target_account = Account.find_local(username)
|
2019-01-01 10:24:26 -05:00
|
|
|
|
|
|
|
if target_account.nil?
|
2019-09-10 07:48:48 -04:00
|
|
|
say('No such account', :red)
|
2019-01-01 10:24:26 -05:00
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
processed, = parallelize_with_progress(Account.local.without_suspended) do |account|
|
2020-12-26 17:52:46 -05:00
|
|
|
FollowService.new.call(account, target_account, bypass_limit: true)
|
2019-01-01 10:24:26 -05:00
|
|
|
end
|
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
say("OK, followed target from #{processed} accounts", :green)
|
2019-01-01 10:24:26 -05:00
|
|
|
end
|
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
option :concurrency, type: :numeric, default: 5, aliases: [:c]
|
|
|
|
option :verbose, type: :boolean, aliases: [:v]
|
2019-01-01 10:24:26 -05:00
|
|
|
desc 'unfollow ACCT', 'Make all local accounts unfollow account specified by ACCT'
|
|
|
|
def unfollow(acct)
|
2020-11-23 11:50:16 -05:00
|
|
|
username, domain = acct.split('@')
|
|
|
|
target_account = Account.find_remote(username, domain)
|
2019-01-01 10:24:26 -05:00
|
|
|
|
|
|
|
if target_account.nil?
|
2019-09-10 07:48:48 -04:00
|
|
|
say('No such account', :red)
|
2019-01-01 10:24:26 -05:00
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
2021-01-29 12:38:56 -05:00
|
|
|
processed, = parallelize_with_progress(target_account.followers.local) do |account|
|
2019-09-10 07:48:48 -04:00
|
|
|
UnfollowService.new.call(account, target_account)
|
2019-01-01 10:24:26 -05:00
|
|
|
end
|
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
say("OK, unfollowed target from #{processed} accounts", :green)
|
2019-01-01 10:24:26 -05:00
|
|
|
end
|
|
|
|
|
2019-04-08 01:46:55 -04:00
|
|
|
option :follows, type: :boolean, default: false
|
|
|
|
option :followers, type: :boolean, default: false
|
|
|
|
desc 'reset-relationships USERNAME', 'Reset all follows and/or followers for a user'
|
|
|
|
long_desc <<-LONG_DESC
|
|
|
|
Reset all follows and/or followers for a user specified by USERNAME.
|
|
|
|
|
|
|
|
With the --follows option, the command unfollows everyone that the account follows,
|
|
|
|
and then re-follows the users that would be followed by a brand new account.
|
|
|
|
|
|
|
|
With the --followers option, the command removes all followers of the account.
|
|
|
|
LONG_DESC
|
|
|
|
def reset_relationships(username)
|
|
|
|
unless options[:follows] || options[:followers]
|
|
|
|
say('Please specify either --follows or --followers, or both', :red)
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
account = Account.find_local(username)
|
|
|
|
|
|
|
|
if account.nil?
|
2019-09-10 07:48:48 -04:00
|
|
|
say('No such account', :red)
|
2019-04-08 01:46:55 -04:00
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
total = 0
|
|
|
|
total += Account.where(id: ::Follow.where(account: account).select(:target_account_id)).count if options[:follows]
|
|
|
|
total += Account.where(id: ::Follow.where(target_account: account).select(:account_id)).count if options[:followers]
|
|
|
|
progress = create_progress_bar(total)
|
|
|
|
processed = 0
|
2019-04-08 01:46:55 -04:00
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
if options[:follows]
|
|
|
|
scope = Account.where(id: ::Follow.where(account: account).select(:target_account_id))
|
2019-04-08 01:46:55 -04:00
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
scope.find_each do |target_account|
|
2019-04-08 01:46:55 -04:00
|
|
|
begin
|
|
|
|
UnfollowService.new.call(account, target_account)
|
2019-09-10 07:48:48 -04:00
|
|
|
rescue => e
|
|
|
|
progress.log pastel.red("Error processing #{target_account.id}: #{e}")
|
|
|
|
ensure
|
|
|
|
progress.increment
|
2019-04-08 01:46:55 -04:00
|
|
|
processed += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
BootstrapTimelineWorker.perform_async(account.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
if options[:followers]
|
2019-09-10 07:48:48 -04:00
|
|
|
scope = Account.where(id: ::Follow.where(target_account: account).select(:account_id))
|
2019-04-08 01:46:55 -04:00
|
|
|
|
2019-09-10 07:48:48 -04:00
|
|
|
scope.find_each do |target_account|
|
2019-04-08 01:46:55 -04:00
|
|
|
begin
|
|
|
|
UnfollowService.new.call(target_account, account)
|
2019-09-10 07:48:48 -04:00
|
|
|
rescue => e
|
|
|
|
progress.log pastel.red("Error processing #{target_account.id}: #{e}")
|
|
|
|
ensure
|
|
|
|
progress.increment
|
2019-04-08 01:46:55 -04:00
|
|
|
processed += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-10 07:48:48 -04:00
|
|
|
|
|
|
|
progress.finish
|
|
|
|
say("Processed #{processed} relationships", :green, true)
|
2019-04-08 01:46:55 -04:00
|
|
|
end
|
|
|
|
|
2019-04-05 22:47:05 -04:00
|
|
|
option :number, type: :numeric, aliases: [:n]
|
|
|
|
option :all, type: :boolean
|
|
|
|
desc 'approve [USERNAME]', 'Approve pending accounts'
|
|
|
|
long_desc <<~LONG_DESC
|
|
|
|
When registrations require review from staff, approve pending accounts,
|
|
|
|
either all of them with the --all option, or a specific number of them
|
|
|
|
specified with the --number (-n) option, or only a single specific
|
|
|
|
account identified by its username.
|
|
|
|
LONG_DESC
|
|
|
|
def approve(username = nil)
|
|
|
|
if options[:all]
|
|
|
|
User.pending.find_each(&:approve!)
|
|
|
|
say('OK', :green)
|
|
|
|
elsif options[:number]
|
|
|
|
User.pending.limit(options[:number]).each(&:approve!)
|
|
|
|
say('OK', :green)
|
|
|
|
elsif username.present?
|
|
|
|
account = Account.find_local(username)
|
|
|
|
|
|
|
|
if account.nil?
|
|
|
|
say('No such account', :red)
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
account.user&.approve!
|
|
|
|
say('OK', :green)
|
|
|
|
else
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-26 14:21:03 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def rotate_keys_for_account(account, delay = 0)
|
2018-09-14 11:42:22 -04:00
|
|
|
if account.nil?
|
|
|
|
say('No such account', :red)
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
2018-08-26 14:21:03 -04:00
|
|
|
old_key = account.private_key
|
2018-12-17 19:22:29 -05:00
|
|
|
new_key = OpenSSL::PKey::RSA.new(2048)
|
|
|
|
account.update(private_key: new_key.to_pem, public_key: new_key.public_key.to_pem)
|
2018-08-26 14:21:03 -04:00
|
|
|
ActivityPub::UpdateDistributionWorker.perform_in(delay, account.id, sign_with: old_key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|