]> cat aescling's git repositories - mastodon.git/blob - lib/cli.rb
Monkey patch Rack::Session to send secure cookies to onions (#15725)
[mastodon.git] / lib / cli.rb
1 # frozen_string_literal: true
2
3 require 'thor'
4 require_relative 'mastodon/media_cli'
5 require_relative 'mastodon/emoji_cli'
6 require_relative 'mastodon/accounts_cli'
7 require_relative 'mastodon/feeds_cli'
8 require_relative 'mastodon/search_cli'
9 require_relative 'mastodon/settings_cli'
10 require_relative 'mastodon/statuses_cli'
11 require_relative 'mastodon/domains_cli'
12 require_relative 'mastodon/preview_cards_cli'
13 require_relative 'mastodon/cache_cli'
14 require_relative 'mastodon/upgrade_cli'
15 require_relative 'mastodon/email_domain_blocks_cli'
16 require_relative 'mastodon/ip_blocks_cli'
17 require_relative 'mastodon/maintenance_cli'
18 require_relative 'mastodon/version'
19
20 module Mastodon
21 class CLI < Thor
22 def self.exit_on_failure?
23 true
24 end
25
26 desc 'media SUBCOMMAND ...ARGS', 'Manage media files'
27 subcommand 'media', Mastodon::MediaCLI
28
29 desc 'emoji SUBCOMMAND ...ARGS', 'Manage custom emoji'
30 subcommand 'emoji', Mastodon::EmojiCLI
31
32 desc 'accounts SUBCOMMAND ...ARGS', 'Manage accounts'
33 subcommand 'accounts', Mastodon::AccountsCLI
34
35 desc 'feeds SUBCOMMAND ...ARGS', 'Manage feeds'
36 subcommand 'feeds', Mastodon::FeedsCLI
37
38 desc 'search SUBCOMMAND ...ARGS', 'Manage the search engine'
39 subcommand 'search', Mastodon::SearchCLI
40
41 desc 'settings SUBCOMMAND ...ARGS', 'Manage dynamic settings'
42 subcommand 'settings', Mastodon::SettingsCLI
43
44 desc 'statuses SUBCOMMAND ...ARGS', 'Manage statuses'
45 subcommand 'statuses', Mastodon::StatusesCLI
46
47 desc 'domains SUBCOMMAND ...ARGS', 'Manage account domains'
48 subcommand 'domains', Mastodon::DomainsCLI
49
50 desc 'preview_cards SUBCOMMAND ...ARGS', 'Manage preview cards'
51 subcommand 'preview_cards', Mastodon::PreviewCardsCLI
52
53 desc 'cache SUBCOMMAND ...ARGS', 'Manage cache'
54 subcommand 'cache', Mastodon::CacheCLI
55
56 desc 'upgrade SUBCOMMAND ...ARGS', 'Various version upgrade utilities'
57 subcommand 'upgrade', Mastodon::UpgradeCLI
58
59 desc 'email_domain_blocks SUBCOMMAND ...ARGS', 'Manage e-mail domain blocks'
60 subcommand 'email_domain_blocks', Mastodon::EmailDomainBlocksCLI
61
62 desc 'ip_blocks SUBCOMMAND ...ARGS', 'Manage IP blocks'
63 subcommand 'ip_blocks', Mastodon::IpBlocksCLI
64
65 desc 'maintenance SUBCOMMAND ...ARGS', 'Various maintenance utilities'
66 subcommand 'maintenance', Mastodon::MaintenanceCLI
67
68 option :dry_run, type: :boolean
69 desc 'self-destruct', 'Erase the server from the federation'
70 long_desc <<~LONG_DESC
71 Erase the server from the federation by broadcasting account delete
72 activities to all known other servers. This allows a "clean exit" from
73 running a Mastodon server, as it leaves next to no cache behind on
74 other servers.
75
76 This command is always interactive and requires confirmation twice.
77
78 No local data is actually deleted, because emptying the
79 database or removing files is much faster through other, external
80 means, such as e.g. deleting the entire VPS. However, because other
81 servers will delete data about local users, but no local data will be
82 updated (such as e.g. followers), there will be a state mismatch
83 that will lead to glitches and issues if you then continue to run and use
84 the server.
85
86 So either you know exactly what you are doing, or you are starting
87 from a blank slate afterwards by manually clearing out all the local
88 data!
89 LONG_DESC
90 def self_destruct
91 require 'tty-prompt'
92
93 prompt = TTY::Prompt.new
94
95 exit(1) unless prompt.ask('Type in the domain of the server to confirm:', required: true) == Rails.configuration.x.local_domain
96
97 prompt.warn('This operation WILL NOT be reversible. It can also take a long time.')
98 prompt.warn('While the data won\'t be erased locally, the server will be in a BROKEN STATE afterwards.')
99 prompt.warn('A running Sidekiq process is required. Do not shut it down until queues clear.')
100
101 exit(1) if prompt.no?('Are you sure you want to proceed?')
102
103 inboxes = Account.inboxes
104 processed = 0
105 dry_run = options[:dry_run] ? ' (DRY RUN)' : ''
106
107 if inboxes.empty?
108 prompt.ok('It seems like your server has not federated with anything')
109 prompt.ok('You can shut it down and delete it any time')
110 return
111 end
112
113 prompt.warn('Do NOT interrupt this process...')
114
115 Setting.registrations_mode = 'none'
116
117 Account.local.without_suspended.find_each do |account|
118 payload = ActiveModelSerializers::SerializableResource.new(
119 account,
120 serializer: ActivityPub::DeleteActorSerializer,
121 adapter: ActivityPub::Adapter
122 ).as_json
123
124 json = Oj.dump(ActivityPub::LinkedDataSignature.new(payload).sign!(account))
125
126 unless options[:dry_run]
127 ActivityPub::DeliveryWorker.push_bulk(inboxes) do |inbox_url|
128 [json, account.id, inbox_url]
129 end
130
131 account.suspend!
132 end
133
134 processed += 1
135 end
136
137 prompt.ok("Queued #{inboxes.size * processed} items into Sidekiq for #{processed} accounts#{dry_run}")
138 prompt.ok('Wait until Sidekiq processes all items, then you can shut everything down and delete the data')
139 rescue TTY::Reader::InputInterrupt
140 exit(1)
141 end
142
143 map %w(--version -v) => :version
144
145 desc 'version', 'Show version'
146 def version
147 say(Mastodon::Version.to_s)
148 end
149 end
150 end
This page took 0.151696 seconds and 4 git commands to generate.