2018-08-25 21:25:39 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'thor'
|
|
|
|
require_relative 'mastodon/media_cli'
|
2018-08-27 00:53:06 +10:00
|
|
|
require_relative 'mastodon/emoji_cli'
|
2018-08-27 04:21:03 +10:00
|
|
|
require_relative 'mastodon/accounts_cli'
|
2018-09-15 01:42:22 +10:00
|
|
|
require_relative 'mastodon/feeds_cli'
|
2019-03-28 12:16:11 +11:00
|
|
|
require_relative 'mastodon/search_cli'
|
2018-10-05 00:05:54 +10:00
|
|
|
require_relative 'mastodon/settings_cli'
|
2019-03-11 23:45:17 +11:00
|
|
|
require_relative 'mastodon/statuses_cli'
|
2018-10-28 07:56:16 +11:00
|
|
|
require_relative 'mastodon/domains_cli'
|
2019-07-28 21:48:19 +10:00
|
|
|
require_relative 'mastodon/preview_cards_cli'
|
2019-05-04 09:02:57 +10:00
|
|
|
require_relative 'mastodon/cache_cli'
|
2020-04-27 07:29:08 +10:00
|
|
|
require_relative 'mastodon/upgrade_cli'
|
2020-06-25 20:17:10 +10:00
|
|
|
require_relative 'mastodon/email_domain_blocks_cli'
|
Backport fixes to 3.2 (#15360)
* Fix 2FA/sign-in token sessions being valid after password change (#14802)
If someone tries logging in to an account and is prompted for a 2FA
code or sign-in token, even if the account's password or e-mail is
updated in the meantime, the session will show the prompt and allow
the login process to complete with a valid 2FA code or sign-in token
* Fix Move handler not being triggered when failing to fetch target (#15107)
When failing to fetch the target account, the ProcessingWorker fails
as expected, but since it hasn't cleared the `move_in_progress` flag,
the next attempt at processing skips the `Move` activity altogether.
This commit changes it to clear the flag when encountering any
unexpected error on fetching the target account. This is likely to
occur because, of, e.g., a timeout, when many instances query the
same actor at the same time.
* Fix slow distinct queries where grouped queries are faster (#15287)
About 2x speed-up on inboxes query
* Fix possible inconsistencies in tag search (#14906)
Do not downcase the queried tag before passing it to postgres when searching:
- tags are not downcased on creation
- `arel_table[:name].lower.matches(pattern)` generates an ILIKE anyway
- if Postgres and Rails happen to use different case-folding rules,
downcasing before query but not before insertion may mean that some
tags with some casings are not searchable
* Fix updating account counters when account_stat is not yet created (#15108)
* Fix account processing failing because of large collections (#15027)
Fixes #15025
* Fix downloading remote media files when server returns empty filename (#14867)
Fixes #14817
* Fix webfinger redirect handling in ResolveAccountService (#15187)
* Fix webfinger redirect handling in ResolveAccountService
ResolveAccountService#process_webfinger! handled a one-step webfinger
redirection, but only accepting the result if it matched the exact URI passed
as input, defeating the point of a redirection check.
Instead, use the same logic as in `ActivityPub::FetchRemoteAccountService`,
updating the resulting `acct:` URI with the result of the first webfinger
query.
* Add tests
* Remove dependency on unused and unmaintained http_parser.rb gem (#14574)
It seems that years ago, the “http” gem dependend on the “http_parser.rb” gem
(it now depends on the “http-parser” gem), and, still years ago, we pulled
it from git in order to benefit from a bugfix that wasn't released yet (#7467).
* Add tootctl maintenance fix-duplicates (#14860, #15201, #15264, #15349, #15359)
* Fix old migration script not being able to run if it fails midway (#15361)
* Fix old migration script not being able to run if it fails midway
Improve the robustness of a migration script likely to fail because of database
corruption so it can run again once database corruptions are fixed.
* Display a specific error message in case of index corruption
Co-authored-by: Eugen Rochko <eugen@zeonfederated.com>
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
Co-authored-by: Eugen Rochko <eugen@zeonfederated.com>
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
2020-12-19 09:31:14 +11:00
|
|
|
require_relative 'mastodon/maintenance_cli'
|
2019-01-18 07:32:55 +11:00
|
|
|
require_relative 'mastodon/version'
|
2018-09-15 01:42:22 +10:00
|
|
|
|
2018-08-25 21:25:39 +10:00
|
|
|
module Mastodon
|
|
|
|
class CLI < Thor
|
2018-10-26 01:05:33 +11:00
|
|
|
def self.exit_on_failure?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2018-08-27 04:21:03 +10:00
|
|
|
desc 'media SUBCOMMAND ...ARGS', 'Manage media files'
|
2018-08-25 21:25:39 +10:00
|
|
|
subcommand 'media', Mastodon::MediaCLI
|
2018-08-27 00:53:06 +10:00
|
|
|
|
2018-08-27 04:21:03 +10:00
|
|
|
desc 'emoji SUBCOMMAND ...ARGS', 'Manage custom emoji'
|
2018-08-27 00:53:06 +10:00
|
|
|
subcommand 'emoji', Mastodon::EmojiCLI
|
2018-08-27 04:21:03 +10:00
|
|
|
|
|
|
|
desc 'accounts SUBCOMMAND ...ARGS', 'Manage accounts'
|
|
|
|
subcommand 'accounts', Mastodon::AccountsCLI
|
2018-09-15 01:42:22 +10:00
|
|
|
|
|
|
|
desc 'feeds SUBCOMMAND ...ARGS', 'Manage feeds'
|
|
|
|
subcommand 'feeds', Mastodon::FeedsCLI
|
2018-10-05 00:05:54 +10:00
|
|
|
|
2019-03-28 12:16:11 +11:00
|
|
|
desc 'search SUBCOMMAND ...ARGS', 'Manage the search engine'
|
|
|
|
subcommand 'search', Mastodon::SearchCLI
|
|
|
|
|
2018-10-05 00:05:54 +10:00
|
|
|
desc 'settings SUBCOMMAND ...ARGS', 'Manage dynamic settings'
|
|
|
|
subcommand 'settings', Mastodon::SettingsCLI
|
2018-10-28 07:56:16 +11:00
|
|
|
|
2019-03-11 23:45:17 +11:00
|
|
|
desc 'statuses SUBCOMMAND ...ARGS', 'Manage statuses'
|
|
|
|
subcommand 'statuses', Mastodon::StatusesCLI
|
|
|
|
|
2018-10-28 07:56:16 +11:00
|
|
|
desc 'domains SUBCOMMAND ...ARGS', 'Manage account domains'
|
|
|
|
subcommand 'domains', Mastodon::DomainsCLI
|
2019-01-18 07:32:55 +11:00
|
|
|
|
2019-07-28 21:48:19 +10:00
|
|
|
desc 'preview_cards SUBCOMMAND ...ARGS', 'Manage preview cards'
|
|
|
|
subcommand 'preview_cards', Mastodon::PreviewCardsCLI
|
|
|
|
|
2019-05-04 09:02:57 +10:00
|
|
|
desc 'cache SUBCOMMAND ...ARGS', 'Manage cache'
|
|
|
|
subcommand 'cache', Mastodon::CacheCLI
|
|
|
|
|
2020-04-27 07:29:08 +10:00
|
|
|
desc 'upgrade SUBCOMMAND ...ARGS', 'Various version upgrade utilities'
|
|
|
|
subcommand 'upgrade', Mastodon::UpgradeCLI
|
|
|
|
|
2020-06-27 05:28:40 +10:00
|
|
|
desc 'email_domain_blocks SUBCOMMAND ...ARGS', 'Manage e-mail domain blocks'
|
2020-06-25 20:17:10 +10:00
|
|
|
subcommand 'email_domain_blocks', Mastodon::EmailDomainBlocksCLI
|
|
|
|
|
Backport fixes to 3.2 (#15360)
* Fix 2FA/sign-in token sessions being valid after password change (#14802)
If someone tries logging in to an account and is prompted for a 2FA
code or sign-in token, even if the account's password or e-mail is
updated in the meantime, the session will show the prompt and allow
the login process to complete with a valid 2FA code or sign-in token
* Fix Move handler not being triggered when failing to fetch target (#15107)
When failing to fetch the target account, the ProcessingWorker fails
as expected, but since it hasn't cleared the `move_in_progress` flag,
the next attempt at processing skips the `Move` activity altogether.
This commit changes it to clear the flag when encountering any
unexpected error on fetching the target account. This is likely to
occur because, of, e.g., a timeout, when many instances query the
same actor at the same time.
* Fix slow distinct queries where grouped queries are faster (#15287)
About 2x speed-up on inboxes query
* Fix possible inconsistencies in tag search (#14906)
Do not downcase the queried tag before passing it to postgres when searching:
- tags are not downcased on creation
- `arel_table[:name].lower.matches(pattern)` generates an ILIKE anyway
- if Postgres and Rails happen to use different case-folding rules,
downcasing before query but not before insertion may mean that some
tags with some casings are not searchable
* Fix updating account counters when account_stat is not yet created (#15108)
* Fix account processing failing because of large collections (#15027)
Fixes #15025
* Fix downloading remote media files when server returns empty filename (#14867)
Fixes #14817
* Fix webfinger redirect handling in ResolveAccountService (#15187)
* Fix webfinger redirect handling in ResolveAccountService
ResolveAccountService#process_webfinger! handled a one-step webfinger
redirection, but only accepting the result if it matched the exact URI passed
as input, defeating the point of a redirection check.
Instead, use the same logic as in `ActivityPub::FetchRemoteAccountService`,
updating the resulting `acct:` URI with the result of the first webfinger
query.
* Add tests
* Remove dependency on unused and unmaintained http_parser.rb gem (#14574)
It seems that years ago, the “http” gem dependend on the “http_parser.rb” gem
(it now depends on the “http-parser” gem), and, still years ago, we pulled
it from git in order to benefit from a bugfix that wasn't released yet (#7467).
* Add tootctl maintenance fix-duplicates (#14860, #15201, #15264, #15349, #15359)
* Fix old migration script not being able to run if it fails midway (#15361)
* Fix old migration script not being able to run if it fails midway
Improve the robustness of a migration script likely to fail because of database
corruption so it can run again once database corruptions are fixed.
* Display a specific error message in case of index corruption
Co-authored-by: Eugen Rochko <eugen@zeonfederated.com>
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
Co-authored-by: Eugen Rochko <eugen@zeonfederated.com>
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
2020-12-19 09:31:14 +11:00
|
|
|
desc 'maintenance SUBCOMMAND ...ARGS', 'Various maintenance utilities'
|
|
|
|
subcommand 'maintenance', Mastodon::MaintenanceCLI
|
|
|
|
|
2019-03-29 03:56:25 +11: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
|
|
|
|
|
|
|
|
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.')
|
|
|
|
|
|
|
|
exit(1) if prompt.no?('Are you sure you want to proceed?')
|
|
|
|
|
|
|
|
inboxes = Account.inboxes
|
|
|
|
processed = 0
|
|
|
|
dry_run = options[:dry_run] ? ' (DRY RUN)' : ''
|
|
|
|
|
|
|
|
if inboxes.empty?
|
|
|
|
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...')
|
|
|
|
|
2020-01-22 04:56:18 +11:00
|
|
|
Setting.registrations_mode = 'none'
|
|
|
|
|
2019-03-29 03:56:25 +11:00
|
|
|
Account.local.without_suspended.find_each do |account|
|
|
|
|
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
|
|
|
|
|
2019-05-15 03:05:02 +10:00
|
|
|
account.suspend!
|
2019-03-29 03:56:25 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
processed += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
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-18 07:32:55 +11:00
|
|
|
map %w(--version -v) => :version
|
|
|
|
|
|
|
|
desc 'version', 'Show version'
|
|
|
|
def version
|
|
|
|
say(Mastodon::Version.to_s)
|
|
|
|
end
|
2018-08-25 21:25:39 +10:00
|
|
|
end
|
|
|
|
end
|