From 144ecfcfc7d9974117f1563084409a9558290a60 Mon Sep 17 00:00:00 2001 From: Starfall Date: Sat, 11 Apr 2020 20:04:46 -0500 Subject: Revert "Revert "Merge branch 'glitch'"" This reverts commit 12d35783db1bb302d7540d8d3690ab6eed3dac3b. --- lib/mastodon/accounts_cli.rb | 7 +++++++ lib/mastodon/migration_helpers.rb | 8 ++------ lib/mastodon/redis_config.rb | 4 +++- lib/mastodon/version.rb | 2 +- lib/tasks/mastodon.rake | 15 ++++++++++++++- 5 files changed, 27 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/mastodon/accounts_cli.rb b/lib/mastodon/accounts_cli.rb index 6dbb75689..8c91c3013 100644 --- a/lib/mastodon/accounts_cli.rb +++ b/lib/mastodon/accounts_cli.rb @@ -120,6 +120,7 @@ module Mastodon option :disable, type: :boolean option :disable_2fa, type: :boolean option :approve, type: :boolean + option :reset_password, type: :boolean desc 'modify USERNAME', 'Modify a user' long_desc <<-LONG_DESC Modify a user account. @@ -138,6 +139,9 @@ module Mastodon With the --disable-2fa option, the two-factor authentication requirement for the user can be removed. + + With the --reset-password option, the user's password is replaced by + a randomly-generated one, printed in the output. LONG_DESC def modify(username) user = Account.find_local(username)&.user @@ -152,6 +156,8 @@ module Mastodon user.moderator = options[:role] == 'moderator' end + password = SecureRandom.hex if options[:reset_password] + user.password = password if options[:reset_password] user.email = options[:email] if options[:email] user.disabled = false if options[:enable] user.disabled = true if options[:disable] @@ -161,6 +167,7 @@ module Mastodon if user.save say('OK', :green) + say("New password: #{password}") if options[:reset_password] else user.errors.to_h.each do |key, error| say('Failure/Error: ', :red) diff --git a/lib/mastodon/migration_helpers.rb b/lib/mastodon/migration_helpers.rb index 146eba8ec..bf2314ecb 100644 --- a/lib/mastodon/migration_helpers.rb +++ b/lib/mastodon/migration_helpers.rb @@ -886,16 +886,12 @@ module Mastodon Your database user is not allowed to create, drop, or execute triggers on the table #{table}. -If you are using PostgreSQL you can solve this by logging in to the GitLab +If you are using PostgreSQL you can solve this by logging in to the Mastodon database (#{dbname}) using a super user and running: ALTER USER #{user} WITH SUPERUSER -For MySQL you instead need to run: - - GRANT ALL PRIVILEGES ON *.* TO #{user}@'%' - -Both queries will grant the user super user permissions, ensuring you don't run +The query will grant the user super user permissions, ensuring you don't run into similar problems in the future (e.g. when new tables are created). EOF end diff --git a/lib/mastodon/redis_config.rb b/lib/mastodon/redis_config.rb index f11d94a45..e9db9122f 100644 --- a/lib/mastodon/redis_config.rb +++ b/lib/mastodon/redis_config.rb @@ -14,7 +14,9 @@ def setup_redis_env_url(prefix = nil, defaults = true) ENV[prefix + 'REDIS_URL'] = if [password, host, port, db].all?(&:nil?) ENV['REDIS_URL'] else - "redis://#{password.blank? ? '' : ":#{password}@"}#{host}:#{port}/#{db}" + Addressable::URI.parse("redis://#{host}:#{port}/#{db}").tap do |uri| + uri.password = password if password.present? + end.normalize.to_str end end diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb index c3e288eee..49fe73043 100644 --- a/lib/mastodon/version.rb +++ b/lib/mastodon/version.rb @@ -13,7 +13,7 @@ module Mastodon end def patch - 0 + 2 end def flags diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake index 2e92e8ded..a873335d4 100644 --- a/lib/tasks/mastodon.rake +++ b/lib/tasks/mastodon.rake @@ -336,7 +336,20 @@ namespace :mastodon do if prompt.yes?('Save configuration?') cmd = TTY::Command.new(printer: :quiet) - File.write(Rails.root.join('.env.production'), "# Generated with mastodon:setup on #{Time.now.utc}\n\n" + env.each_pair.map { |key, value| "#{key}=#{value}" }.join("\n") + "\n") + env_contents = env.each_pair.map do |key, value| + if value.is_a?(String) && value =~ /[\s\#\\"]/ + if value =~ /[']/ + value = value.to_s.gsub(/[\\"\$]/) { |x| "\\#{x}" } + "#{key}=\"#{value}\"" + else + "#{key}='#{value}'" + end + else + "#{key}=#{value}" + end + end.join("\n") + + File.write(Rails.root.join('.env.production'), "# Generated with mastodon:setup on #{Time.now.utc}\n\n" + env_contents + "\n") if using_docker prompt.ok 'Below is your configuration, save it to an .env.production file outside Docker:' -- cgit