mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
check mx records for disposable emails
This commit is contained in:
parent
b9fa24e479
commit
383bb2e672
2 changed files with 25 additions and 3 deletions
|
@ -84,6 +84,11 @@ post '/create' do
|
|||
return {result: 'error'}.to_json
|
||||
end
|
||||
|
||||
if Site.disposable_mx_record?(@site.email)
|
||||
flash[:error] = 'Cannot use a disposable email address.'
|
||||
return {result: 'error'}.to_json
|
||||
end
|
||||
|
||||
@site.email_confirmed = true if self.class.development?
|
||||
@site.save
|
||||
|
||||
|
|
|
@ -546,16 +546,33 @@ class Site < Sequel::Model
|
|||
!username.empty? && username.match(/^[a-zA-Z0-9_\-]+$/i)
|
||||
end
|
||||
|
||||
def self.disposable_email_domains
|
||||
File.readlines(DISPOSABLE_EMAIL_BLACKLIST_PATH).collect {|d| d.strip}
|
||||
end
|
||||
|
||||
def self.disposable_mx_record?(email)
|
||||
email_domain = email.match(/@(.+)/).captures.first
|
||||
|
||||
begin
|
||||
email_mx = Resolv::DNS.new.getresource(email_domain, Resolv::DNS::Resource::IN::MX).exchange.to_s
|
||||
email_root_domain = email_mx.match(/\.(.+)$/).captures.first
|
||||
rescue => e
|
||||
# Guess this is your lucky day.
|
||||
return false
|
||||
end
|
||||
|
||||
return true if disposable_email_domains.include? email_root_domain
|
||||
false
|
||||
end
|
||||
|
||||
def self.disposable_email?(email)
|
||||
return false unless File.exist?(DISPOSABLE_EMAIL_BLACKLIST_PATH)
|
||||
return false if email.blank?
|
||||
|
||||
email.strip!
|
||||
|
||||
disposable_email_domains = File.readlines DISPOSABLE_EMAIL_BLACKLIST_PATH
|
||||
|
||||
disposable_email_domains.each do |disposable_email_domain|
|
||||
return true if email.match /@#{disposable_email_domain.strip}$/i
|
||||
return true if email.match /@#{disposable_email_domain}$/i
|
||||
end
|
||||
|
||||
false
|
||||
|
|
Loading…
Add table
Reference in a new issue