2018-08-25 13:25:39 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'thor'
|
|
|
|
require_relative 'mastodon/media_cli'
|
2018-08-26 16:53:06 +02:00
|
|
|
require_relative 'mastodon/emoji_cli'
|
2018-08-26 20:21:03 +02:00
|
|
|
require_relative 'mastodon/accounts_cli'
|
2018-09-14 17:42:22 +02:00
|
|
|
require_relative 'mastodon/feeds_cli'
|
2019-03-28 02:16:11 +01:00
|
|
|
require_relative 'mastodon/search_cli'
|
2018-10-04 16:05:54 +02:00
|
|
|
require_relative 'mastodon/settings_cli'
|
2019-03-11 13:45:17 +01:00
|
|
|
require_relative 'mastodon/statuses_cli'
|
2018-10-27 22:56:16 +02:00
|
|
|
require_relative 'mastodon/domains_cli'
|
2019-07-28 13:48:19 +02:00
|
|
|
require_relative 'mastodon/preview_cards_cli'
|
2019-05-04 01:02:57 +02:00
|
|
|
require_relative 'mastodon/cache_cli'
|
2020-04-26 23:29:08 +02:00
|
|
|
require_relative 'mastodon/upgrade_cli'
|
2020-06-25 12:17:10 +02:00
|
|
|
require_relative 'mastodon/email_domain_blocks_cli'
|
2021-12-17 23:02:14 +01:00
|
|
|
require_relative 'mastodon/canonical_email_blocks_cli'
|
2020-10-12 16:33:49 +02:00
|
|
|
require_relative 'mastodon/ip_blocks_cli'
|
2020-11-19 17:37:49 +01:00
|
|
|
require_relative 'mastodon/maintenance_cli'
|
2019-01-17 21:32:55 +01:00
|
|
|
require_relative 'mastodon/version'
|
2018-09-14 17:42:22 +02:00
|
|
|
|
2018-08-25 13:25:39 +02:00
|
|
|
module Mastodon
|
|
|
|
class CLI < Thor
|
2018-10-25 16:05:33 +02:00
|
|
|
def self.exit_on_failure?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2018-08-26 20:21:03 +02:00
|
|
|
desc 'media SUBCOMMAND ...ARGS', 'Manage media files'
|
2018-08-25 13:25:39 +02:00
|
|
|
subcommand 'media', Mastodon::MediaCLI
|
2018-08-26 16:53:06 +02:00
|
|
|
|
2018-08-26 20:21:03 +02:00
|
|
|
desc 'emoji SUBCOMMAND ...ARGS', 'Manage custom emoji'
|
2018-08-26 16:53:06 +02:00
|
|
|
subcommand 'emoji', Mastodon::EmojiCLI
|
2018-08-26 20:21:03 +02:00
|
|
|
|
|
|
|
desc 'accounts SUBCOMMAND ...ARGS', 'Manage accounts'
|
|
|
|
subcommand 'accounts', Mastodon::AccountsCLI
|
2018-09-14 17:42:22 +02:00
|
|
|
|
|
|
|
desc 'feeds SUBCOMMAND ...ARGS', 'Manage feeds'
|
|
|
|
subcommand 'feeds', Mastodon::FeedsCLI
|
2018-10-04 16:05:54 +02:00
|
|
|
|
2019-03-28 02:16:11 +01:00
|
|
|
desc 'search SUBCOMMAND ...ARGS', 'Manage the search engine'
|
|
|
|
subcommand 'search', Mastodon::SearchCLI
|
|
|
|
|
2018-10-04 16:05:54 +02:00
|
|
|
desc 'settings SUBCOMMAND ...ARGS', 'Manage dynamic settings'
|
|
|
|
subcommand 'settings', Mastodon::SettingsCLI
|
2018-10-27 22:56:16 +02:00
|
|
|
|
2019-03-11 13:45:17 +01:00
|
|
|
desc 'statuses SUBCOMMAND ...ARGS', 'Manage statuses'
|
|
|
|
subcommand 'statuses', Mastodon::StatusesCLI
|
|
|
|
|
2018-10-27 22:56:16 +02:00
|
|
|
desc 'domains SUBCOMMAND ...ARGS', 'Manage account domains'
|
|
|
|
subcommand 'domains', Mastodon::DomainsCLI
|
2019-01-17 21:32:55 +01:00
|
|
|
|
2019-07-28 13:48:19 +02:00
|
|
|
desc 'preview_cards SUBCOMMAND ...ARGS', 'Manage preview cards'
|
|
|
|
subcommand 'preview_cards', Mastodon::PreviewCardsCLI
|
|
|
|
|
2019-05-04 01:02:57 +02:00
|
|
|
desc 'cache SUBCOMMAND ...ARGS', 'Manage cache'
|
|
|
|
subcommand 'cache', Mastodon::CacheCLI
|
|
|
|
|
2020-04-26 23:29:08 +02:00
|
|
|
desc 'upgrade SUBCOMMAND ...ARGS', 'Various version upgrade utilities'
|
|
|
|
subcommand 'upgrade', Mastodon::UpgradeCLI
|
|
|
|
|
2020-06-26 21:28:40 +02:00
|
|
|
desc 'email_domain_blocks SUBCOMMAND ...ARGS', 'Manage e-mail domain blocks'
|
2020-06-25 12:17:10 +02:00
|
|
|
subcommand 'email_domain_blocks', Mastodon::EmailDomainBlocksCLI
|
|
|
|
|
2020-10-12 16:33:49 +02:00
|
|
|
desc 'ip_blocks SUBCOMMAND ...ARGS', 'Manage IP blocks'
|
|
|
|
subcommand 'ip_blocks', Mastodon::IpBlocksCLI
|
|
|
|
|
2021-12-17 23:02:14 +01:00
|
|
|
desc 'canonical_email_blocks SUBCOMMAND ...ARGS', 'Manage canonical e-mail blocks'
|
|
|
|
subcommand 'canonical_email_blocks', Mastodon::CanonicalEmailBlocksCLI
|
|
|
|
|
2020-11-19 17:37:49 +01:00
|
|
|
desc 'maintenance SUBCOMMAND ...ARGS', 'Various maintenance utilities'
|
|
|
|
subcommand 'maintenance', Mastodon::MaintenanceCLI
|
|
|
|
|
2019-03-28 17:56:25 +01:00
|
|
|
option :dry_run, type: :boolean
|
|
|
|
desc 'self-destruct', 'Erase the server from the federation'
|
|
|
|
long_desc <<~LONG_DESC
|
|
|
|
Erase the server from the federation by broadcasting account delete
|
|
|
|
activities to all known other servers. This allows a "clean exit" from
|
|
|
|
running a Mastodon server, as it leaves next to no cache behind on
|
|
|
|
other servers.
|
|
|
|
|
|
|
|
This command is always interactive and requires confirmation twice.
|
|
|
|
|
|
|
|
No local data is actually deleted, because emptying the
|
|
|
|
database or removing files is much faster through other, external
|
|
|
|
means, such as e.g. deleting the entire VPS. However, because other
|
|
|
|
servers will delete data about local users, but no local data will be
|
|
|
|
updated (such as e.g. followers), there will be a state mismatch
|
|
|
|
that will lead to glitches and issues if you then continue to run and use
|
|
|
|
the server.
|
|
|
|
|
|
|
|
So either you know exactly what you are doing, or you are starting
|
|
|
|
from a blank slate afterwards by manually clearing out all the local
|
|
|
|
data!
|
|
|
|
LONG_DESC
|
|
|
|
def self_destruct
|
|
|
|
require 'tty-prompt'
|
|
|
|
|
|
|
|
prompt = TTY::Prompt.new
|
|
|
|
|
|
|
|
exit(1) unless prompt.ask('Type in the domain of the server to confirm:', required: true) == Rails.configuration.x.local_domain
|
|
|
|
|
2021-10-14 19:59:28 +02:00
|
|
|
unless options[:dry_run]
|
|
|
|
prompt.warn('This operation WILL NOT be reversible. It can also take a long time.')
|
|
|
|
prompt.warn('While the data won\'t be erased locally, the server will be in a BROKEN STATE afterwards.')
|
|
|
|
prompt.warn('A running Sidekiq process is required. Do not shut it down until queues clear.')
|
2019-03-28 17:56:25 +01:00
|
|
|
|
2021-10-14 19:59:28 +02:00
|
|
|
exit(1) if prompt.no?('Are you sure you want to proceed?')
|
|
|
|
end
|
2019-03-28 17:56:25 +01:00
|
|
|
|
|
|
|
inboxes = Account.inboxes
|
|
|
|
processed = 0
|
|
|
|
dry_run = options[:dry_run] ? ' (DRY RUN)' : ''
|
|
|
|
|
2021-10-14 19:59:28 +02:00
|
|
|
Setting.registrations_mode = 'none' unless options[:dry_run]
|
|
|
|
|
2019-03-28 17:56:25 +01:00
|
|
|
if inboxes.empty?
|
2021-10-14 19:59:28 +02:00
|
|
|
Account.local.without_suspended.in_batches.update_all(suspended_at: Time.now.utc, suspension_origin: :local) unless options[:dry_run]
|
2019-03-28 17:56:25 +01:00
|
|
|
prompt.ok('It seems like your server has not federated with anything')
|
|
|
|
prompt.ok('You can shut it down and delete it any time')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
prompt.warn('Do NOT interrupt this process...')
|
|
|
|
|
2023-02-18 12:39:00 +01:00
|
|
|
delete_account = lambda do |account|
|
2019-03-28 17:56:25 +01:00
|
|
|
payload = ActiveModelSerializers::SerializableResource.new(
|
|
|
|
account,
|
|
|
|
serializer: ActivityPub::DeleteActorSerializer,
|
|
|
|
adapter: ActivityPub::Adapter
|
|
|
|
).as_json
|
|
|
|
|
|
|
|
json = Oj.dump(ActivityPub::LinkedDataSignature.new(payload).sign!(account))
|
|
|
|
|
|
|
|
unless options[:dry_run]
|
|
|
|
ActivityPub::DeliveryWorker.push_bulk(inboxes) do |inbox_url|
|
|
|
|
[json, account.id, inbox_url]
|
|
|
|
end
|
|
|
|
|
2021-10-14 19:59:28 +02:00
|
|
|
account.suspend!(block_email: false)
|
2019-03-28 17:56:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
processed += 1
|
|
|
|
end
|
|
|
|
|
2021-10-14 19:59:28 +02:00
|
|
|
Account.local.without_suspended.find_each { |account| delete_account.call(account) }
|
|
|
|
Account.local.suspended.joins(:deletion_request).find_each { |account| delete_account.call(account) }
|
|
|
|
|
2019-03-28 17:56:25 +01:00
|
|
|
prompt.ok("Queued #{inboxes.size * processed} items into Sidekiq for #{processed} accounts#{dry_run}")
|
|
|
|
prompt.ok('Wait until Sidekiq processes all items, then you can shut everything down and delete the data')
|
|
|
|
rescue TTY::Reader::InputInterrupt
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
2019-01-17 21:32:55 +01:00
|
|
|
map %w(--version -v) => :version
|
|
|
|
|
|
|
|
desc 'version', 'Show version'
|
|
|
|
def version
|
|
|
|
say(Mastodon::Version.to_s)
|
|
|
|
end
|
2018-08-25 13:25:39 +02:00
|
|
|
end
|
|
|
|
end
|