mirror of
https://github.com/internetee/registry.git
synced 2025-07-26 04:28:27 +02:00
Story#105418634 Update Whois body(whois is using stringified json)
This commit is contained in:
parent
176ca58551
commit
bfcf5a2a0f
1 changed files with 0 additions and 108 deletions
|
@ -1,108 +0,0 @@
|
||||||
require "erb"
|
|
||||||
class WhoisRecord < ActiveRecord::Base
|
|
||||||
belongs_to :domain
|
|
||||||
belongs_to :registrar
|
|
||||||
|
|
||||||
validates :domain, :name, :body, :json, presence: true
|
|
||||||
|
|
||||||
before_validation :populate
|
|
||||||
def populate
|
|
||||||
return if domain_id.blank?
|
|
||||||
self.json = generate_json
|
|
||||||
self.body = generated_body
|
|
||||||
self.name = json['name']
|
|
||||||
self.registrar_id = domain.registrar_id # for faster registrar updates
|
|
||||||
end
|
|
||||||
|
|
||||||
after_save :update_whois_server
|
|
||||||
|
|
||||||
class << self
|
|
||||||
def included
|
|
||||||
includes(
|
|
||||||
domain: [
|
|
||||||
:registrant,
|
|
||||||
:registrar,
|
|
||||||
:nameservers,
|
|
||||||
{ tech_contacts: :registrar },
|
|
||||||
{ admin_contacts: :registrar }
|
|
||||||
]
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# rubocop:disable Metrics/MethodLength
|
|
||||||
# rubocop:disable Metrics/AbcSize
|
|
||||||
def generate_json
|
|
||||||
h = HashWithIndifferentAccess.new
|
|
||||||
return h if domain.blank?
|
|
||||||
|
|
||||||
status_map = {
|
|
||||||
'ok' => 'ok (paid and in zone)'
|
|
||||||
}
|
|
||||||
|
|
||||||
@disclosed = []
|
|
||||||
h[:name] = domain.name
|
|
||||||
h[:status] = domain.statuses.map { |x| status_map[x] || x }
|
|
||||||
h[:registered] = domain.registered_at.try(:to_s, :iso8601)
|
|
||||||
h[:changed] = domain.updated_at.try(:to_s, :iso8601)
|
|
||||||
h[:expire] = domain.valid_to.try(:to_date).try(:to_s)
|
|
||||||
h[:outzone] = domain.outzone_at.try(:to_date).try(:to_s)
|
|
||||||
h[:delete] = domain.delete_at.try(:to_date).try(:to_s)
|
|
||||||
|
|
||||||
|
|
||||||
h[:registrant] = domain.registrant.name
|
|
||||||
h[:registrant_email] = domain.registrant.email
|
|
||||||
h[:changed] = domain.registrant.updated_at.try(:to_s, :iso8601)
|
|
||||||
|
|
||||||
h[:admin_contacts] = []
|
|
||||||
domain.admin_contacts.each do |ac|
|
|
||||||
@disclosed << [:email, ac.email]
|
|
||||||
h[:admin_contacts] << {
|
|
||||||
name: ac.name,
|
|
||||||
email: ac.email,
|
|
||||||
changed: ac.updated_at.try(:to_s, :iso8601)
|
|
||||||
}
|
|
||||||
end
|
|
||||||
h[:tech_contacts] = []
|
|
||||||
domain.tech_contacts.each do |tc|
|
|
||||||
@disclosed << [:email, tc.email]
|
|
||||||
h[:tech_contacts] << {
|
|
||||||
name: tc.name,
|
|
||||||
email: tc.email,
|
|
||||||
changed: tc.updated_at.try(:to_s, :iso8601)
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
# update registar triggers when adding new attributes
|
|
||||||
h[:registrar] = domain.registrar.name
|
|
||||||
h[:registrar_url] = domain.registrar.url
|
|
||||||
h[:registrar_phone] = domain.registrar.phone
|
|
||||||
h[:registrar_address] = domain.registrar.address
|
|
||||||
h[:registrar_changed] = domain.registrar.updated_at.try(:to_s, :iso8601)
|
|
||||||
|
|
||||||
h[:nameservers] = domain.nameservers.pluck(:hostname).uniq.select(&:present?)
|
|
||||||
h[:nameservers_changed] = domain.nameservers.pluck(:updated_at).max.try(:to_s, :iso8601)
|
|
||||||
|
|
||||||
h[:dnssec_keys] = domain.dnskeys.map{|key| "#{key.flags} #{key.protocol} #{key.alg} #{key.public_key}" }
|
|
||||||
h[:dnssec_changed] = domain.dnskeys.pluck(:updated_at).max.try(:to_s, :iso8601) rescue nil
|
|
||||||
|
|
||||||
|
|
||||||
h[:disclosed] = @disclosed
|
|
||||||
h
|
|
||||||
end
|
|
||||||
|
|
||||||
def generated_body
|
|
||||||
template = Rails.root.join("app/views/for_models/whois.erb".freeze)
|
|
||||||
ERB.new(template.read, nil, "-").result.binding
|
|
||||||
end
|
|
||||||
# rubocop:enable Metrics/MethodLength
|
|
||||||
# rubocop:enable Metrics/AbcSize
|
|
||||||
|
|
||||||
|
|
||||||
def update_whois_server
|
|
||||||
wd = Whois::Record.find_or_initialize_by(name: name)
|
|
||||||
wd.body = body
|
|
||||||
wd.json = json
|
|
||||||
wd.save
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Add table
Add a link
Reference in a new issue