added notify class and mail action for inform

This commit is contained in:
olegphenomenon 2022-01-05 14:40:33 +02:00
parent b25ef62d78
commit ca9ca115eb
5 changed files with 54 additions and 1 deletions

View file

@ -28,10 +28,23 @@ class ValidateDnssecJob < ApplicationJob
domain.nameservers.each do |n|
validate(hostname: n.hostname, domain: domain)
notify_contacts(domain)
logger.info "----------------------------"
end
end
def notify_contacts(domain)
flag = domain.dnskeys.any? { |k| k.validation_datetime.present? }
return if flag
text = "DNSKEYS for #{domain.name} are invalid!"
logger.info text
ContactNotification.notify_registrar(domain: domain, text: text)
ContactNotification.notify_tech_contact(domain: domain)
end
def validate(hostname:, domain:, type: 'DNSKEY', klass: 'IN')
resolver = prepare_validator(hostname)
answer = resolver.query(domain.name, type, klass)
@ -51,16 +64,21 @@ class ValidateDnssecJob < ApplicationJob
def compare_dnssec_data(response_container:, domain:)
domain.dnskeys.each do |key|
next unless key.flags.to_s == '257'
next unless key.flags.to_s == '257' || key.validation_datetime.nil?
flag = make_magic(response_container: response_container, dnskey: key)
text = "#{key.flags} - #{key.protocol} - #{key.alg} - #{key.public_key}"
if flag
key.validation_datetime = Time.zone.now
key.save
logger.info text + " ------->> succesfully!"
else
logger.info text + " ------->> not found in zone!"
end
end
end
def make_magic(response_container:, dnskey:)

View file

@ -0,0 +1,16 @@
class ContactInformMailer < ApplicationMailer
helper_method :address_processing
def notify(contact:, subject:)
@contact = email
@subject = subject
mail(to: contact.email, subject: subject)
end
private
def address_processing
Contact.address_processing?
end
end

View file

@ -0,0 +1,17 @@
module ContactNotification
extend self
def notify_registrar(domain:, text:)
domain.registrar.notifications.create(text: text)
end
def notify_tech_contact(domain:)
text = "DNSKEYS for #{domain.name} are invalid!"
domain.tech_domain_contacts.each do |tech|
contact = Contact.find(tech.id)
ContactInformMailer.notify(contact: contact, subject: text)
end
end
end

View file

@ -0,0 +1 @@
<p>DNSKEYS for <%= @domain.name %> are invalid!</p>

View file

@ -0,0 +1 @@
<p>DNSKEYS for <%= @domain.name %> are invalid!</p>