parent
f29458da1d
commit
3afd59df0f
|
@ -32,9 +32,9 @@ module Mastodon
|
||||||
multiple domains to the command.
|
multiple domains to the command.
|
||||||
|
|
||||||
When the --with-dns-records option is given, an attempt to resolve the
|
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
|
given domains' MX records will be made and the results will also be blocked.
|
||||||
also be blocked. This can be helpful if you are blocking an e-mail server that
|
This can be helpful if you are blocking an e-mail server that has many
|
||||||
has many different domains pointing to it as it allows you to essentially block
|
different domains pointing to it as it allows you to essentially block
|
||||||
it at the root.
|
it at the root.
|
||||||
LONG_DESC
|
LONG_DESC
|
||||||
def add(*domains)
|
def add(*domains)
|
||||||
|
@ -53,26 +53,19 @@ module Mastodon
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
email_domain_block = EmailDomainBlock.new(domain: domain, with_dns_records: options[:with_dns_records] || false)
|
other_domains = []
|
||||||
email_domain_block.save!
|
if options[:with_dns_records]
|
||||||
processed += 1
|
Resolv::DNS.open do |dns|
|
||||||
|
dns.timeouts = 5
|
||||||
next unless email_domain_block.with_dns_records?
|
other_domains = dns.getresources(@email_domain_block.domain, Resolv::DNS::Resource::IN::MX).to_a
|
||||||
|
|
||||||
hostnames = []
|
|
||||||
ips = []
|
|
||||||
|
|
||||||
Resolv::DNS.open do |dns|
|
|
||||||
dns.timeouts = 5
|
|
||||||
hostnames = dns.getresources(email_domain_block.domain, Resolv::DNS::Resource::IN::MX).to_a.map { |e| e.exchange.to_s }
|
|
||||||
|
|
||||||
([email_domain_block.domain] + hostnames).uniq.each do |hostname|
|
|
||||||
ips.concat(dns.getresources(hostname, Resolv::DNS::Resource::IN::A).to_a.map { |e| e.address.to_s })
|
|
||||||
ips.concat(dns.getresources(hostname, Resolv::DNS::Resource::IN::AAAA).to_a.map { |e| e.address.to_s })
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
(hostnames + ips).uniq.each do |hostname|
|
email_domain_block = EmailDomainBlock.new(domain: domain, other_domains: other_domains)
|
||||||
|
email_domain_block.save!
|
||||||
|
processed += 1
|
||||||
|
|
||||||
|
(email_domain_block.other_domains || []).uniq.each do |hostname|
|
||||||
another_email_domain_block = EmailDomainBlock.new(domain: hostname, parent: email_domain_block)
|
another_email_domain_block = EmailDomainBlock.new(domain: hostname, parent: email_domain_block)
|
||||||
|
|
||||||
if EmailDomainBlock.where(domain: hostname).exists?
|
if EmailDomainBlock.where(domain: hostname).exists?
|
||||||
|
|
Loading…
Reference in a new issue