From 0c06cec8e3924d5276d36b478e6064d055e0e35e Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Wed, 28 Oct 2015 15:13:59 +0200 Subject: [PATCH 1/3] Story#105418634 Update Whois json --- app/models/whois_record.rb | 58 +++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index 5113b331f..3276b6947 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -36,50 +36,56 @@ class WhoisRecord < ActiveRecord::Base return h if domain.blank? status_map = { - 'ok' => 'ok (paid and in zone)' + 'ok' => 'ok (paid and in zone)' } @disclosed = [] - h[:name] = domain.name - h[:registrant] = domain.registrant.name - h[:status] = domain.statuses.map { |x| status_map[x] || x }.join(', ') + h[:name] = domain.name + h[:status] = domain.statuses.map { |x| status_map[x] || x } h[:registered] = domain.registered_at.try(:to_s, :iso8601) - h[:updated_at] = domain.updated_at.try(:to_s, :iso8601) - h[:valid_to] = domain.valid_to.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] = nil + h[:delete] = domain.force_delete_at.try(:to_s, :iso8601) - # update registar triggers when adding new attributes - h[:registrar] = domain.registrar.name - h[:registrar_phone] = domain.registrar.phone - h[:registrar_address] = domain.registrar.address - h[:registrar_update_at] = domain.registrar.updated_at.try(:to_s, :iso8601) + + 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, - registrar: ac.registrar.name, - created_at: ac.created_at.try(:to_s, :iso8601) + name: ac.name, + email: ac.email, + created_at: ac.created_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, - registrar: tc.registrar.name, - created_at: tc.created_at.try(:to_s, :iso8601) - } - end - h[:nameservers] = [] - domain.nameservers.each do |ns| - h[:nameservers] << { - hostname: ns.hostname, - updated_at: ns.updated_at.try(:to_s, :iso8601) + name: tc.name, + email: tc.email, + created_at: tc.created_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 From a5bce579157714dbc7100446503599d988a78aa2 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Wed, 28 Oct 2015 15:23:29 +0200 Subject: [PATCH 2/3] Story#105418634 Update Whois json (set delete and outzone) --- app/models/whois_record.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index 3276b6947..582b71cc9 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -45,8 +45,8 @@ class WhoisRecord < ActiveRecord::Base 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] = nil - h[:delete] = domain.force_delete_at.try(:to_s, :iso8601) + h[:outzone] = domain.outzone_at.try(:to_s, :iso8601) + h[:delete] = domain.delete_at.try(:to_s, :iso8601) h[:registrant] = domain.registrant.name From a2d039bb2e58e924620cb62b53c907f1eb813ae3 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Wed, 28 Oct 2015 20:10:12 +0200 Subject: [PATCH 3/3] Story#105418634 Update Whois body --- app/models/whois_record.rb | 69 ++++------------------------------ app/views/for_models/whois.erb | 60 +++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 62 deletions(-) create mode 100644 app/views/for_models/whois.erb diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index 582b71cc9..898b0eb3e 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -1,3 +1,4 @@ +require "erb" class WhoisRecord < ActiveRecord::Base belongs_to :domain belongs_to :registrar @@ -45,8 +46,8 @@ class WhoisRecord < ActiveRecord::Base 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_s, :iso8601) - h[:delete] = domain.delete_at.try(:to_s, :iso8601) + 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 @@ -59,7 +60,7 @@ class WhoisRecord < ActiveRecord::Base h[:admin_contacts] << { name: ac.name, email: ac.email, - created_at: ac.created_at.try(:to_s, :iso8601) + changed: ac.updated_at.try(:to_s, :iso8601) } end h[:tech_contacts] = [] @@ -68,7 +69,7 @@ class WhoisRecord < ActiveRecord::Base h[:tech_contacts] << { name: tc.name, email: tc.email, - created_at: tc.created_at.try(:to_s, :iso8601) + changed: tc.updated_at.try(:to_s, :iso8601) } end @@ -91,68 +92,12 @@ class WhoisRecord < ActiveRecord::Base end def generated_body - <<-EOS -Estonia .ee Top Level Domain WHOIS server - -Domain: - name: #{json['name']} - registrant: #{json['registrant']} - status: #{json['status']} - registered: #{Time.zone.parse(json['registered'])} - changed: #{Time.zone.parse(json['updated_at'])} - expire: #{Time.zone.parse(json['valid_to'])} - outzone: - delete: -#{contacts_body(json['admin_contacts'], json['tech_contacts'])} -Registrar: - name: #{json['registrar']} - phone: #{json['registrar_phone']} - address: #{json['registrar_address']} - changed: #{Time.zone.parse(json['registrar_update_at'])} -#{nameservers_body(json['nameservers'])} -Estonia .ee Top Level Domain WHOIS server -More information at http://internet.ee - EOS + 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 contacts_body(admins, techs) - admins ||= [] - techs ||= [] - - out = '' - out << (admins.size > 1 ? "\nAdministrative contacts" : "\nAdministrative contact") - admins.each do |c| - out << "\n name: #{c['name']}" - out << "\n email: Not Disclosed - Visit www.internet.ee for webbased WHOIS" - out << "\n registrar: #{c['registrar']}" - out << "\n created: #{Time.zone.parse(c['created_at'])}" - out << "\n" - end - - out << (techs.size > 1 ? "\nTechnical contacts" : "\nTechnical contact:") - techs.each do |c| - out << "\n name: #{c['name']}" - out << "\n email: Not Disclosed - Visit www.internet.ee for webbased WHOIS" - out << "\n registrar: #{c['registrar']}" - out << "\n created: #{Time.zone.parse(c['created_at'])}" - out << "\n" - end - out - end - - def nameservers_body(nservers) - nservers ||= [] - - out = "\nName servers:" - nservers.each do |ns| - out << "\n nserver: #{ns['hostname']}" - out << "\n changed: #{Time.zone.parse(ns['updated_at'])}" - out << "\n" - end - out - end def update_whois_server wd = Whois::Record.find_or_initialize_by(name: name) diff --git a/app/views/for_models/whois.erb b/app/views/for_models/whois.erb new file mode 100644 index 000000000..ee9768181 --- /dev/null +++ b/app/views/for_models/whois.erb @@ -0,0 +1,60 @@ +Estonia .ee Top Level Domain WHOIS server + +Domain: +name: <%= json[:name] %> +<%- for st in Array(json[:status]) -%> +status: <%= st %> +<%- end -%> +registered: <%= json[:registered].to_s.tr('T',' ').sub('+', ' +') %> +changed: <%= json[:changed].to_s.tr('T',' ').sub('+', ' +') %> +expire: <%= json[:expire].to_s.tr('T',' ').sub('+', ' +') %> +outzone: <%= json[:outzone].to_s.tr('T',' ').sub('+', ' +') %> +delete: <%= json[:delete].to_s.tr('T',' ').sub('+', ' +') %> + +Registrant: +name: <%= json[:registrant] %> +email: Not Disclosed - Visit www.internet.ee for webbased WHOIS +changed: <%= json[:changed].to_s.tr('T',' ').sub('+', ' +') %> + +<%- if json[:admin_contacts].present? -%> +Administrative contact +<%- for contact in json[:admin_contacts] -%> +name: <%= contact[:name] %> +email: Not Disclosed - Visit www.internet.ee for webbased WHOIS +changed: <%= contact[:changed].to_s.tr('T',' ').sub('+', ' +') %> +<%- end -%> + +<%- end -%> +<% if json[:tech_contacts].present? %> +Technical contact: +<%- for contact in json[:admin_contacts] -%> +name: <%= contact[:name] %> +email: Not Disclosed - Visit www.internet.ee for webbased WHOIS +changed: <%= contact[:changed].to_s.tr('T',' ').sub('+', ' +') %> +<%- end -%> + +<%- end -%> +Registrar: +name: <%= json[:registrar] %> +url: <%= json[:registrar_url] %> +phone: <%= json[:registrar_phone] %> +changed: <%= json[:registrar_changed].to_s.tr('T',' ').sub('+', ' +') %> + +<%- if json[:nameservers].present? -%> +Name servers: +<%- for server in json[:nameservers] -%> +nserver: <%= server %> +<%- end -%> +changed: <%= json[:nameservers_changed].to_s.tr('T',' ').sub('+', ' +') %> + +<%- end -%> +<%- if json[:dnssec_keys].present? -%> +DNSSEC: +<%- for key in json[:dnssec_keys] -%> +dnskey: <%= key %> +<%- end -%> +changed: <%= json[:dnssec_changed].to_s.tr('T',' ').sub('+', ' +') %> + +<%- end -%> +Estonia .ee Top Level Domain WHOIS server +More information at http://internet.ee \ No newline at end of file