mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 11:38:30 +02:00
Refactored whois from domain into whois body
This commit is contained in:
parent
920b3e71e0
commit
3d0d98d9b1
7 changed files with 204 additions and 51 deletions
|
@ -238,55 +238,10 @@ class Domain < ActiveRecord::Base
|
|||
log
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def update_whois_body
|
||||
self.whois_body = <<-EOS
|
||||
Estonia .ee Top Level Domain WHOIS server
|
||||
|
||||
domain: #{name}
|
||||
registrant: #{registrant.name}
|
||||
status: #{domain_statuses.map(&:value).join(', ')}
|
||||
registered: #{registered_at and registered_at.to_s(:db)}
|
||||
changed: #{updated_at and updated_at.to_s(:db)}
|
||||
expire: #{valid_to and valid_to.to_s(:db)}
|
||||
outzone:
|
||||
delete:
|
||||
|
||||
#{contacts_body}
|
||||
|
||||
nsset:
|
||||
nserver:
|
||||
|
||||
registrar: #{registrar}
|
||||
phone: #{registrar.phone}
|
||||
address: #{registrar.address}
|
||||
created: #{registrar.created_at.to_s(:db)}
|
||||
changed: #{registrar.updated_at.to_s(:db)}
|
||||
|
||||
Estonia .ee Top Level Domain WHOIS server
|
||||
More information at http://internet.ee
|
||||
EOS
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def contacts_body
|
||||
out = ''
|
||||
admin_contacts.each do |c|
|
||||
out << 'Admin contact:'
|
||||
out << "name: #{c.name}"
|
||||
out << "email: #{c.email}"
|
||||
out << "registrar: #{c.registrar}"
|
||||
out << "created: #{c.created_at.to_s(:db)}"
|
||||
end
|
||||
|
||||
tech_contacts.each do |c|
|
||||
out << 'Tech contact:'
|
||||
out << "name: #{c.name}"
|
||||
out << "email: #{c.email}"
|
||||
out << "registrar: #{c.registrar}"
|
||||
out << "created: #{c.created_at.to_s(:db)}"
|
||||
end
|
||||
out
|
||||
whois = Whois::Body.new(self)
|
||||
self.whois_json = whois.whois_json
|
||||
self.whois_body = whois.whois_body
|
||||
end
|
||||
|
||||
def update_whois_server
|
||||
|
|
|
@ -109,6 +109,15 @@ class DomainStatus < ActiveRecord::Base
|
|||
CLIENT_STATUSES.include?(value)
|
||||
end
|
||||
|
||||
def human_value
|
||||
case value
|
||||
when 'ok'
|
||||
'ok (paid and in zone)'
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
def statuses_for_client
|
||||
CLIENT_STATUSES.map { |x| x.sub('client', '') }
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
module Whois
|
||||
end
|
107
app/models/whois/body.rb
Normal file
107
app/models/whois/body.rb
Normal file
|
@ -0,0 +1,107 @@
|
|||
class Whois::Body
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def h
|
||||
@h ||= HashWithIndifferentAccess.new
|
||||
end
|
||||
|
||||
def initialize(domain)
|
||||
h[:name] = domain.name
|
||||
h[:registrant] = domain.registrant.name
|
||||
h[:status] = domain.domain_statuses.map(&:human_value).join(', ')
|
||||
h[:registered] = domain.registered_at and domain.registered_at.to_s(:db)
|
||||
h[:updated_at] = domain.updated_at and domain.updated_at.to_s(:db)
|
||||
h[:valid_to] = domain.valid_to and domain.valid_to.to_s(:db)
|
||||
|
||||
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.to_s(:db)
|
||||
h[:admin_contacts] = []
|
||||
domain.admin_contacts.each do |ac|
|
||||
h[:admin_contacts] << {
|
||||
name: ac.name,
|
||||
email: ac.email,
|
||||
registrar: ac.registrar.name,
|
||||
created_at: ac.created_at.to_s(:db)
|
||||
}
|
||||
end
|
||||
h[:tech_contacts] = []
|
||||
domain.tech_contacts.each do |tc|
|
||||
h[:tech_contacts] << {
|
||||
name: tc.name,
|
||||
email: tc.email,
|
||||
registrar: tc.registrar.name,
|
||||
created_at: tc.created_at.to_s(:db)
|
||||
}
|
||||
end
|
||||
h[:nameservers] = []
|
||||
domain.nameservers.each do |ns|
|
||||
h[:nameservers] << {
|
||||
hostname: ns.hostname,
|
||||
updated_at: ns.updated_at.to_s(:db)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def whois_json
|
||||
h
|
||||
end
|
||||
|
||||
def whois_body
|
||||
<<-EOS
|
||||
Estonia .ee Top Level Domain WHOIS server
|
||||
|
||||
Domain:
|
||||
name: #{h[:name]}
|
||||
registrant: #{h[:registrant]}
|
||||
status: #{h[:status]}
|
||||
registered: #{h[:registered]}
|
||||
changed: #{h[:updated_at]}
|
||||
expire: #{h[:valid_to]}
|
||||
outzone:
|
||||
delete:
|
||||
#{contacts_body(h[:admin_contacts], h[:tech_contacts])}
|
||||
Registrar:
|
||||
name: #{h[:registrar]}
|
||||
phone: #{h[:registrar_phone]}
|
||||
address: #{h[:registrar_address]}
|
||||
changed: #{h[:registrar_update_at]}
|
||||
#{nameservers_body(h[:nameservers])}
|
||||
Estonia .ee Top Level Domain WHOIS server
|
||||
More information at http://internet.ee
|
||||
EOS
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def contacts_body(admins, techs)
|
||||
out = ''
|
||||
out << (admins.size > 1 ? "\nAdministrative contacts" : "\nAdministrative contact")
|
||||
admins.each do |c|
|
||||
out << "\n name: #{c[:name]}"
|
||||
out << "\n e-mail: Not Disclosed - Visit www.internet.ee for webbased WHOIS"
|
||||
out << "\n registrar: #{c[:registrar]}"
|
||||
out << "\n created: #{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 e-mail: Not Disclosed - Visit www.internet.ee for webbased WHOIS"
|
||||
out << "\n registrar: #{c[:registrar]}"
|
||||
out << "\n created: #{c[:created_at]}"
|
||||
out << "\n"
|
||||
end
|
||||
out
|
||||
end
|
||||
|
||||
def nameservers_body(nservers)
|
||||
out = "\nName servers:"
|
||||
nservers.each do |ns|
|
||||
out << "\n nserver: #{ns[:hostname]}"
|
||||
out << "\n changed: #{ns[:updated_at]}"
|
||||
out << "\n"
|
||||
end
|
||||
out
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue