From 370e38ee15da6ff0b85c048486b56b173c1d4b02 Mon Sep 17 00:00:00 2001 From: tateisu Date: Thu, 25 Jun 2020 19:17:10 +0900 Subject: Add tootctl email-domain-blocks (#13589) * Add tootctl email_domains (block|unblock) * fix codeclimate issues. * fix codeclimate issues. * fix codeclimate issues. * add list subcommand, remove log_action. * fix codeclimate issues. * filter duplicate hostnames,ips before block * rebase from currnet master branch. rename email_domains_cli.rb to email_domain_blocks_cli.rb . rename Mastodon::EmailDomainsCLI to Mastodon::EmailDomainBlocksCLI . rename command email_domains to email-domain-blocks . (Thor recognizes both of - and _ ) rename subcommand block to add . rename subcommand unblock to remove . change the color in list subcommand to while for domain or cyan for childlen. don't use include() in list subcommand. suppress console output about succeeded entry. add console output about count of processed/skipped. remove capitalization in subcommand description. remove long_desc in subcommand 'remove'. remove duplicate where in subcommand 'remove'. * fix codeclimate issue. --- lib/cli.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/cli.rb') diff --git a/lib/cli.rb b/lib/cli.rb index 313a36a3d..7cab0d5a1 100644 --- a/lib/cli.rb +++ b/lib/cli.rb @@ -12,6 +12,7 @@ require_relative 'mastodon/domains_cli' require_relative 'mastodon/preview_cards_cli' require_relative 'mastodon/cache_cli' require_relative 'mastodon/upgrade_cli' +require_relative 'mastodon/email_domain_blocks_cli' require_relative 'mastodon/version' module Mastodon @@ -53,6 +54,9 @@ module Mastodon desc 'upgrade SUBCOMMAND ...ARGS', 'Various version upgrade utilities' subcommand 'upgrade', Mastodon::UpgradeCLI + desc 'email-domain-blocks SUBCOMMAND ...ARGS', 'Manage E-mail domain blocks' + subcommand 'email_domain_blocks', Mastodon::EmailDomainBlocksCLI + option :dry_run, type: :boolean desc 'self-destruct', 'Erase the server from the federation' long_desc <<~LONG_DESC -- cgit From 4662afe0756f821ce5febb90dee96887b4c247bb Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 26 Jun 2020 21:28:40 +0200 Subject: Fix help text around `tootctl email_domain_blocks` (#14147) --- lib/cli.rb | 2 +- lib/mastodon/email_domain_blocks_cli.rb | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) (limited to 'lib/cli.rb') diff --git a/lib/cli.rb b/lib/cli.rb index 7cab0d5a1..9162144cc 100644 --- a/lib/cli.rb +++ b/lib/cli.rb @@ -54,7 +54,7 @@ module Mastodon desc 'upgrade SUBCOMMAND ...ARGS', 'Various version upgrade utilities' subcommand 'upgrade', Mastodon::UpgradeCLI - desc 'email-domain-blocks SUBCOMMAND ...ARGS', 'Manage E-mail domain blocks' + desc 'email_domain_blocks SUBCOMMAND ...ARGS', 'Manage e-mail domain blocks' subcommand 'email_domain_blocks', Mastodon::EmailDomainBlocksCLI option :dry_run, type: :boolean diff --git a/lib/mastodon/email_domain_blocks_cli.rb b/lib/mastodon/email_domain_blocks_cli.rb index 8b468ed15..7fe1efaaa 100644 --- a/lib/mastodon/email_domain_blocks_cli.rb +++ b/lib/mastodon/email_domain_blocks_cli.rb @@ -13,13 +13,11 @@ module Mastodon true end - desc 'list', 'list E-mail domain blocks' - long_desc <<-LONG_DESC - list up all E-mail domain blocks. - LONG_DESC + desc 'list', 'List blocked e-mail domains' def list EmailDomainBlock.where(parent_id: nil).order(id: 'DESC').find_each do |entry| say(entry.domain.to_s, :white) + EmailDomainBlock.where(parent_id: entry.id).order(id: 'DESC').find_each do |child| say(" #{child.domain}", :cyan) end @@ -27,13 +25,17 @@ module Mastodon end option :with_dns_records, type: :boolean - desc 'add [DOMAIN...]', 'add E-mail domain blocks' + desc 'add DOMAIN...', 'Block e-mail domain(s)' long_desc <<-LONG_DESC - add E-mail domain blocks from a given DOMAIN. - - When the --with-dns-records option is given, An attempt to resolve the - given domain's DNS records will be made and the results will also be - blacklisted. + Blocking an e-mail domain prevents users from signing up + with e-mail addresses from that domain. You can provide one or + multiple domains to the command. + + When the --with-dns-records option is given, an attempt to resolve the + given domains' DNS records will be made and the results (A, AAAA and MX) will + also be blocked. This can be helpful if you are blocking an e-mail server that + has many different domains pointing to it as it allows you to essentially block + it at the root. LONG_DESC def add(*domains) if domains.empty? @@ -72,11 +74,13 @@ module Mastodon (hostnames + ips).uniq.each do |hostname| another_email_domain_block = EmailDomainBlock.new(domain: hostname, parent: email_domain_block) + if EmailDomainBlock.where(domain: hostname).exists? say("#{hostname} is already blocked.", :yellow) skipped += 1 next end + another_email_domain_block.save! processed += 1 end @@ -85,7 +89,7 @@ module Mastodon say("Added #{processed}, skipped #{skipped}", color(processed, 0)) end - desc 'remove [DOMAIN...]', 'remove E-mail domain blocks' + desc 'remove DOMAIN...', 'Remove e-mail domain blocks' def remove(*domains) if domains.empty? say('No domain(s) given', :red) @@ -98,6 +102,7 @@ module Mastodon domains.each do |domain| entry = EmailDomainBlock.find_by(domain: domain) + if entry.nil? say("#{domain} is not yet blocked.", :yellow) skipped += 1 @@ -105,12 +110,12 @@ module Mastodon end children_count = EmailDomainBlock.where(parent_id: entry.id).count - result = entry.destroy + if result processed += 1 + children_count else - say("#{domain} was not unblocked. 'destroy' returns false.", :red) + say("#{domain} could not be unblocked.", :red) failed += 1 end end -- cgit