mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 18:26:06 +02:00
Merge branch 'master' of github.com:domify/registry
This commit is contained in:
commit
85b6ea913e
20 changed files with 352 additions and 111 deletions
|
@ -33,6 +33,7 @@ class Domain < ActiveRecord::Base
|
|||
has_many :dnskeys, dependent: :destroy
|
||||
|
||||
has_many :keyrelays
|
||||
has_one :whois_record, dependent: :destroy
|
||||
|
||||
accepts_nested_attributes_for :dnskeys, allow_destroy: true
|
||||
|
||||
|
@ -52,7 +53,7 @@ class Domain < ActiveRecord::Base
|
|||
self.updated_at = Time.zone.now
|
||||
end
|
||||
after_save :manage_automatic_statuses
|
||||
after_save :update_whois_body
|
||||
after_save :update_whois_record
|
||||
after_save :update_whois_server
|
||||
|
||||
validates :name_dirty, domain_name: true, uniqueness: true
|
||||
|
@ -124,6 +125,7 @@ class Domain < ActiveRecord::Base
|
|||
includes(
|
||||
:registrar,
|
||||
:nameservers,
|
||||
:whois_record,
|
||||
{ tech_contacts: :registrar },
|
||||
{ admin_contacts: :registrar }
|
||||
)
|
||||
|
@ -226,6 +228,9 @@ class Domain < ActiveRecord::Base
|
|||
domain_statuses.find_by(value: DomainStatus::OK).try(:destroy)
|
||||
end
|
||||
|
||||
# otherwise domain_statuses are in old state for domain object
|
||||
domain_statuses.reload
|
||||
|
||||
# contacts.includes(:address).each(&:manage_statuses)
|
||||
end
|
||||
|
||||
|
@ -234,64 +239,20 @@ class Domain < ActiveRecord::Base
|
|||
log[:admin_contacts] = admin_contacts.map(&:attributes)
|
||||
log[:tech_contacts] = tech_contacts.map(&:attributes)
|
||||
log[:nameservers] = nameservers.map(&:attributes)
|
||||
log[:registrant] = [registrant.try(:attributes)]
|
||||
log[:registrant] = [registrant.try(:attributes)]
|
||||
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
|
||||
def update_whois_record
|
||||
self.whois_record = WhoisRecord.create if whois_record.blank?
|
||||
whois_record.update
|
||||
end
|
||||
|
||||
def update_whois_server
|
||||
wd = Whois::Domain.find_or_initialize_by(name: name)
|
||||
wd.whois_body = whois_body
|
||||
wd.save
|
||||
if whois_record.present?
|
||||
whois_record.update_whois_server
|
||||
else
|
||||
logger.info "NO WHOIS BODY for domain: #{name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -1,5 +0,0 @@
|
|||
module Whois
|
||||
class Domain < Whois::Server
|
||||
self.table_name = 'domains'
|
||||
end
|
||||
end
|
5
app/models/whois/record.rb
Normal file
5
app/models/whois/record.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
module Whois
|
||||
class Record < Whois::Server
|
||||
self.table_name = 'whois_records'
|
||||
end
|
||||
end
|
123
app/models/whois_record.rb
Normal file
123
app/models/whois_record.rb
Normal file
|
@ -0,0 +1,123 @@
|
|||
class WhoisRecord < ActiveRecord::Base
|
||||
belongs_to :domain
|
||||
|
||||
def update_whois_server
|
||||
return logger.info "NO WHOIS NAME for whois record id: #{id}" if name.blank?
|
||||
wd = Whois::Record.find_or_initialize_by(name: name)
|
||||
wd.body = body
|
||||
wd.json = json
|
||||
wd.save
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def h
|
||||
@h ||= HashWithIndifferentAccess.new
|
||||
end
|
||||
|
||||
def update
|
||||
@disclosed = []
|
||||
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|
|
||||
@disclosed << [:email, ac.email]
|
||||
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|
|
||||
@disclosed << [:email, tc.email]
|
||||
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
|
||||
|
||||
h[:disclosed] = @disclosed
|
||||
|
||||
self.name = h[:name]
|
||||
self.body = generated_body
|
||||
self.json = h
|
||||
save
|
||||
end
|
||||
|
||||
def generated_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 email: 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 email: 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
|
|
@ -1,3 +1,4 @@
|
|||
!!! 5
|
||||
%html{lang: I18n.locale.to_s}
|
||||
%head
|
||||
%meta{charset: "utf-8"}/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
!!!
|
||||
!!! 5
|
||||
%html{lang: I18n.locale.to_s}
|
||||
%head
|
||||
%meta{charset: "utf-8"}/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue