Remove IP matching from e-mail domain blocks (#18190)
Clear out e-mail domain blocks created from automatically resolved DNS recordslocal
parent
7b0fe4aef9
commit
f6d35ed57d
9 changed files with 43 additions and 114 deletions
@ -1,31 +0,0 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class Scheduler::EmailDomainBlockRefreshScheduler |
||||
include Sidekiq::Worker |
||||
include Redisable |
||||
|
||||
sidekiq_options retry: 0 |
||||
|
||||
def perform |
||||
Resolv::DNS.open do |dns| |
||||
dns.timeouts = 5 |
||||
|
||||
EmailDomainBlock.find_each do |email_domain_block| |
||||
ips = begin |
||||
if ip?(email_domain_block.domain) |
||||
[email_domain_block.domain] |
||||
else |
||||
resources = dns.getresources(email_domain_block.domain, Resolv::DNS::Resource::IN::A).to_a + dns.getresources(email_domain_block.domain, Resolv::DNS::Resource::IN::AAAA).to_a |
||||
resources.map { |resource| resource.address.to_s } |
||||
end |
||||
end |
||||
|
||||
email_domain_block.update(ips: ips, last_refresh_at: Time.now.utc) |
||||
end |
||||
end |
||||
end |
||||
|
||||
def ip?(str) |
||||
str =~ Regexp.union([Resolv::IPv4::Regex, Resolv::IPv6::Regex]) |
||||
end |
||||
end |
@ -0,0 +1,12 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class RemoveIpsFromEmailDomainBlocks < ActiveRecord::Migration[5.2] |
||||
disable_ddl_transaction! |
||||
|
||||
def change |
||||
safety_assured do |
||||
remove_column :email_domain_blocks, :ips, :inet, array: true |
||||
remove_column :email_domain_blocks, :last_refresh_at, :datetime |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,14 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class ClearEmailDomainBlocks < ActiveRecord::Migration[5.2] |
||||
disable_ddl_transaction! |
||||
|
||||
class EmailDomainBlock < ApplicationRecord |
||||
end |
||||
|
||||
def up |
||||
EmailDomainBlock.where.not(parent_id: nil).in_batches.delete_all |
||||
end |
||||
|
||||
def down; end |
||||
end |
Loading…
Reference in new issue