The code powering m.abunchtell.com https://m.abunchtell.com
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

56 wiersze
1.5 KiB

  1. # frozen_string_literal: true
  2. require 'rubygems/package'
  3. require_relative '../../config/boot'
  4. require_relative '../../config/environment'
  5. require_relative 'cli_helper'
  6. module Mastodon
  7. class AccountsCLI < Thor
  8. option :all, type: :boolean
  9. desc 'rotate [USERNAME]', 'Generate and broadcast new keys'
  10. long_desc <<-LONG_DESC
  11. Generate and broadcast new RSA keys as part of security
  12. maintenance.
  13. With the --all option, all local accounts will be subject
  14. to the rotation. Otherwise, and by default, only a single
  15. account specified by the USERNAME argument will be
  16. processed.
  17. LONG_DESC
  18. def rotate(username = nil)
  19. if options[:all]
  20. processed = 0
  21. delay = 0
  22. Account.local.without_suspended.find_in_batches do |accounts|
  23. accounts.each do |account|
  24. rotate_keys_for_account(account, delay)
  25. processed += 1
  26. say('.', :green, false)
  27. end
  28. delay += 5.minutes
  29. end
  30. say
  31. say("OK, rotated keys for #{processed} accounts", :green)
  32. elsif username.present?
  33. rotate_keys_for_account(Account.find_local(username))
  34. say('OK', :green)
  35. else
  36. say('No account(s) given', :red)
  37. end
  38. end
  39. private
  40. def rotate_keys_for_account(account, delay = 0)
  41. old_key = account.private_key
  42. new_key = OpenSSL::PKey::RSA.new(2048).to_pem
  43. account.update(private_key: new_key)
  44. ActivityPub::UpdateDistributionWorker.perform_in(delay, account.id, sign_with: old_key)
  45. end
  46. end
  47. end