diff --git a/app/jobs/validate_dnssec_job.rb b/app/jobs/validate_dnssec_job.rb index 1f418e43c..3292f505d 100644 --- a/app/jobs/validate_dnssec_job.rb +++ b/app/jobs/validate_dnssec_job.rb @@ -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:) diff --git a/app/mailers/contact_inform_mailer.rb b/app/mailers/contact_inform_mailer.rb new file mode 100644 index 000000000..5c6f28f2c --- /dev/null +++ b/app/mailers/contact_inform_mailer.rb @@ -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 diff --git a/app/services/contact_notification.rb b/app/services/contact_notification.rb new file mode 100644 index 000000000..c5e8a7b0c --- /dev/null +++ b/app/services/contact_notification.rb @@ -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 diff --git a/app/views/mailers/contact_inform_mailer/notify.html.erb b/app/views/mailers/contact_inform_mailer/notify.html.erb new file mode 100644 index 000000000..224584706 --- /dev/null +++ b/app/views/mailers/contact_inform_mailer/notify.html.erb @@ -0,0 +1 @@ +

DNSKEYS for <%= @domain.name %> are invalid!

diff --git a/app/views/mailers/contact_inform_mailer/notify.text.erb b/app/views/mailers/contact_inform_mailer/notify.text.erb new file mode 100644 index 000000000..224584706 --- /dev/null +++ b/app/views/mailers/contact_inform_mailer/notify.text.erb @@ -0,0 +1 @@ +

DNSKEYS for <%= @domain.name %> are invalid!