From 176ca5855103a1122650630cda67036d796c5263 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Wed, 28 Oct 2015 20:34:40 +0200 Subject: [PATCH 1/4] Story#105418634 Add updated_at to DnsKEy model --- ...20151028183132_add_updated_at_to_dnskey.rb | 5 ++++ db/schema-read-only.rb | 29 ++++++++++--------- db/structure.sql | 5 +++- 3 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 db/migrate/20151028183132_add_updated_at_to_dnskey.rb diff --git a/db/migrate/20151028183132_add_updated_at_to_dnskey.rb b/db/migrate/20151028183132_add_updated_at_to_dnskey.rb new file mode 100644 index 000000000..63921eea4 --- /dev/null +++ b/db/migrate/20151028183132_add_updated_at_to_dnskey.rb @@ -0,0 +1,5 @@ +class AddUpdatedAtToDnskey < ActiveRecord::Migration + def change + add_column :dnskeys, :updated_at, :datetime + end +end diff --git a/db/schema-read-only.rb b/db/schema-read-only.rb index ca244af5f..c4e300fb6 100644 --- a/db/schema-read-only.rb +++ b/db/schema-read-only.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150921111842) do +ActiveRecord::Schema.define(version: 20151028183132) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -240,19 +240,20 @@ ActiveRecord::Schema.define(version: 20150921111842) do end create_table "dnskeys", force: :cascade do |t| - t.integer "domain_id" - t.integer "flags" - t.integer "protocol" - t.integer "alg" - t.text "public_key" - t.integer "delegation_signer_id" - t.string "ds_key_tag" - t.integer "ds_alg" - t.integer "ds_digest_type" - t.string "ds_digest" - t.string "creator_str" - t.string "updator_str" - t.integer "legacy_domain_id" + t.integer "domain_id" + t.integer "flags" + t.integer "protocol" + t.integer "alg" + t.text "public_key" + t.integer "delegation_signer_id" + t.string "ds_key_tag" + t.integer "ds_alg" + t.integer "ds_digest_type" + t.string "ds_digest" + t.string "creator_str" + t.string "updator_str" + t.integer "legacy_domain_id" + t.datetime "updated_at" end add_index "dnskeys", ["delegation_signer_id"], name: "index_dnskeys_on_delegation_signer_id", using: :btree diff --git a/db/structure.sql b/db/structure.sql index fbe00eb4d..0f077857c 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -745,7 +745,8 @@ CREATE TABLE dnskeys ( ds_digest character varying, creator_str character varying, updator_str character varying, - legacy_domain_id integer + legacy_domain_id integer, + updated_at timestamp without time zone ); @@ -4946,3 +4947,5 @@ INSERT INTO schema_migrations (version) VALUES ('20150921110152'); INSERT INTO schema_migrations (version) VALUES ('20150921111842'); +INSERT INTO schema_migrations (version) VALUES ('20151028183132'); + From bfcf5a2a0f17bc91fdeac87368bcf3a3e7068529 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Wed, 28 Oct 2015 20:45:49 +0200 Subject: [PATCH 2/4] Story#105418634 Update Whois body(whois is using stringified json) --- app/models/whois_record.rb | 108 ------------------------------------- 1 file changed, 108 deletions(-) diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index 898b0eb3e..e69de29bb 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -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 From 6ae65a8b42256332d58fcad76ee86c443ddb4c15 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Wed, 28 Oct 2015 20:46:16 +0200 Subject: [PATCH 3/4] Story#105418634 revert --- app/models/whois_record.rb | 114 +++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index e69de29bb..731186984 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -0,0 +1,114 @@ +require "erb" +class WhoisRecord < ActiveRecord::Base + belongs_to :domain + belongs_to :registrar + + validates :domain, :name, :body, :json, presence: true + + before_validation :populate + after_save :update_whois_server + + class << self + def included + includes( + domain: [ + :registrant, + :registrar, + :nameservers, + { tech_contacts: :registrar }, + { admin_contacts: :registrar } + ] + ) + end + end + + def generated_json + @generated_json ||= generate_json + 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 + self.json = generated_json if self.json.blank? + + 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 populate + return if domain_id.blank? + self.json = generated_json + self.body = generated_body + self.name = json['name'] + self.registrar_id = domain.registrar_id # for faster registrar updates + end + + def update_whois_server + wd = Whois::Record.find_or_initialize_by(name: name) + wd.body = body + wd.json = json + wd.save + end +end From 64942a95999e560d186b542bc6b3d4b77ec6236f Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Wed, 28 Oct 2015 20:46:43 +0200 Subject: [PATCH 4/4] Story#105418634 Update Whois body (json uses stringified_keys) --- app/views/for_models/whois.erb | 54 +++++++++++++++++----------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/app/views/for_models/whois.erb b/app/views/for_models/whois.erb index ee9768181..385368b4a 100644 --- a/app/views/for_models/whois.erb +++ b/app/views/for_models/whois.erb @@ -1,59 +1,59 @@ Estonia .ee Top Level Domain WHOIS server Domain: -name: <%= json[:name] %> -<%- for st in Array(json[:status]) -%> +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('+', ' +') %> +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] %> +name: <%= json['registrant'] %> email: Not Disclosed - Visit www.internet.ee for webbased WHOIS -changed: <%= json[:changed].to_s.tr('T',' ').sub('+', ' +') %> +changed: <%= json['changed'].to_s.tr('T',' ').sub('+', ' +') %> -<%- if json[:admin_contacts].present? -%> +<%- if json['admin_contacts'].present? -%> Administrative contact -<%- for contact in json[:admin_contacts] -%> -name: <%= contact[:name] %> +<%- 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('+', ' +') %> +changed: <%= contact['changed'].to_s.tr('T',' ').sub('+', ' +') %> <%- end -%> <%- end -%> -<% if json[:tech_contacts].present? %> +<% if json['tech_contacts'].present? %> Technical contact: -<%- for contact in json[:admin_contacts] -%> -name: <%= contact[:name] %> +<%- 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('+', ' +') %> +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('+', ' +') %> +name: <%= json['registrar'] %> +url: <%= json['registrar_url'] %> +phone: <%= json['registrar_phone'] %> +changed: <%= json['registrar_changed'].to_s.tr('T',' ').sub('+', ' +') %> -<%- if json[:nameservers].present? -%> +<%- if json['nameservers'].present? -%> Name servers: -<%- for server in json[:nameservers] -%> +<%- for server in json['nameservers'] -%> nserver: <%= server %> <%- end -%> -changed: <%= json[:nameservers_changed].to_s.tr('T',' ').sub('+', ' +') %> +changed: <%= json['nameservers_changed'].to_s.tr('T',' ').sub('+', ' +') %> <%- end -%> -<%- if json[:dnssec_keys].present? -%> +<%- if json['dnssec_keys'].present? -%> DNSSEC: -<%- for key in json[:dnssec_keys] -%> +<%- for key in json['dnssec_keys'] -%> dnskey: <%= key %> <%- end -%> -changed: <%= json[:dnssec_changed].to_s.tr('T',' ').sub('+', ' +') %> +changed: <%= json['dnssec_changed'].to_s.tr('T',' ').sub('+', ' +') %> <%- end -%> Estonia .ee Top Level Domain WHOIS server