You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
161 lines
5.5 KiB
161 lines
5.5 KiB
6 years ago
|
# frozen_string_literal: true
|
||
|
|
||
|
require 'thor'
|
||
1 year ago
|
require_relative 'media'
|
||
|
require_relative 'emoji'
|
||
|
require_relative 'accounts'
|
||
|
require_relative 'feeds'
|
||
|
require_relative 'search'
|
||
|
require_relative 'settings'
|
||
|
require_relative 'statuses'
|
||
|
require_relative 'domains'
|
||
|
require_relative 'preview_cards'
|
||
|
require_relative 'cache'
|
||
|
require_relative 'upgrade'
|
||
|
require_relative 'email_domain_blocks'
|
||
|
require_relative 'canonical_email_blocks'
|
||
|
require_relative 'ip_blocks'
|
||
|
require_relative 'maintenance'
|
||
|
require_relative '../version'
|
||
|
|
||
|
module Mastodon::CLI
|
||
|
class Main < Thor
|
||
6 years ago
|
def self.exit_on_failure?
|
||
|
true
|
||
|
end
|
||
|
|
||
6 years ago
|
desc 'media SUBCOMMAND ...ARGS', 'Manage media files'
|
||
1 year ago
|
subcommand 'media', Media
|
||
6 years ago
|
|
||
6 years ago
|
desc 'emoji SUBCOMMAND ...ARGS', 'Manage custom emoji'
|
||
1 year ago
|
subcommand 'emoji', Emoji
|
||
6 years ago
|
|
||
|
desc 'accounts SUBCOMMAND ...ARGS', 'Manage accounts'
|
||
1 year ago
|
subcommand 'accounts', Accounts
|
||
6 years ago
|
|
||
|
desc 'feeds SUBCOMMAND ...ARGS', 'Manage feeds'
|
||
1 year ago
|
subcommand 'feeds', Feeds
|
||
6 years ago
|
|
||
6 years ago
|
desc 'search SUBCOMMAND ...ARGS', 'Manage the search engine'
|
||
1 year ago
|
subcommand 'search', Search
|
||
6 years ago
|
|
||
6 years ago
|
desc 'settings SUBCOMMAND ...ARGS', 'Manage dynamic settings'
|
||
1 year ago
|
subcommand 'settings', Settings
|
||
6 years ago
|
|
||
6 years ago
|
desc 'statuses SUBCOMMAND ...ARGS', 'Manage statuses'
|
||
1 year ago
|
subcommand 'statuses', Statuses
|
||
6 years ago
|
|
||
6 years ago
|
desc 'domains SUBCOMMAND ...ARGS', 'Manage account domains'
|
||
1 year ago
|
subcommand 'domains', Domains
|
||
6 years ago
|
|
||
5 years ago
|
desc 'preview_cards SUBCOMMAND ...ARGS', 'Manage preview cards'
|
||
1 year ago
|
subcommand 'preview_cards', PreviewCards
|
||
5 years ago
|
|
||
6 years ago
|
desc 'cache SUBCOMMAND ...ARGS', 'Manage cache'
|
||
1 year ago
|
subcommand 'cache', Cache
|
||
6 years ago
|
|
||
5 years ago
|
desc 'upgrade SUBCOMMAND ...ARGS', 'Various version upgrade utilities'
|
||
1 year ago
|
subcommand 'upgrade', Upgrade
|
||
5 years ago
|
|
||
4 years ago
|
desc 'email_domain_blocks SUBCOMMAND ...ARGS', 'Manage e-mail domain blocks'
|
||
1 year ago
|
subcommand 'email_domain_blocks', EmailDomainBlocks
|
||
4 years ago
|
|
||
4 years ago
|
desc 'ip_blocks SUBCOMMAND ...ARGS', 'Manage IP blocks'
|
||
1 year ago
|
subcommand 'ip_blocks', IpBlocks
|
||
4 years ago
|
|
||
3 years ago
|
desc 'canonical_email_blocks SUBCOMMAND ...ARGS', 'Manage canonical e-mail blocks'
|
||
1 year ago
|
subcommand 'canonical_email_blocks', CanonicalEmailBlocks
|
||
3 years ago
|
|
||
4 years ago
|
desc 'maintenance SUBCOMMAND ...ARGS', 'Various maintenance utilities'
|
||
1 year ago
|
subcommand 'maintenance', Maintenance
|
||
4 years ago
|
|
||
6 years ago
|
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
|
||
|
|
||
3 years ago
|
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.')
|
||
6 years ago
|
|
||
3 years ago
|
exit(1) if prompt.no?('Are you sure you want to proceed?')
|
||
|
end
|
||
6 years ago
|
|
||
|
inboxes = Account.inboxes
|
||
|
processed = 0
|
||
|
dry_run = options[:dry_run] ? ' (DRY RUN)' : ''
|
||
|
|
||
3 years ago
|
Setting.registrations_mode = 'none' unless options[:dry_run]
|
||
|
|
||
6 years ago
|
if inboxes.empty?
|
||
3 years ago
|
Account.local.without_suspended.in_batches.update_all(suspended_at: Time.now.utc, suspension_origin: :local) unless options[:dry_run]
|
||
6 years ago
|
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...')
|
||
|
|
||
2 years ago
|
delete_account = lambda do |account|
|
||
6 years ago
|
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]
|
||
2 years ago
|
ActivityPub::DeliveryWorker.push_bulk(inboxes, limit: 1_000) do |inbox_url|
|
||
6 years ago
|
[json, account.id, inbox_url]
|
||
|
end
|
||
|
|
||
3 years ago
|
account.suspend!(block_email: false)
|
||
6 years ago
|
end
|
||
|
|
||
|
processed += 1
|
||
|
end
|
||
|
|
||
3 years ago
|
Account.local.without_suspended.find_each { |account| delete_account.call(account) }
|
||
|
Account.local.suspended.joins(:deletion_request).find_each { |account| delete_account.call(account) }
|
||
|
|
||
6 years ago
|
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
|
||
|
|
||
6 years ago
|
map %w(--version -v) => :version
|
||
|
|
||
|
desc 'version', 'Show version'
|
||
|
def version
|
||
|
say(Mastodon::Version.to_s)
|
||
|
end
|
||
6 years ago
|
end
|
||
|
end
|