Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parsers: whois.cira.ca: Add new version support for 2019 whois output #131

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 152 additions & 50 deletions lib/whois/parsers/whois.cira.ca.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,16 @@ class WhoisCiraCa < Base


property_supported :domain do
return node("Domain Name") || node("Not found") if version == "3"
node("Domain name")
end

property_not_supported :domain_id


property_supported :status do
if content_for_scanner =~ /Domain status:\s+(.+?)\n/
case node("Domain status", &:downcase)
when "registered"
:registered
when "redemption"
:registered
when "auto-renew grace"
:registered
when "to be released"
:registered
when "pending delete"
:registered
when "available"
:available
when "unavailable"
:invalid
else
Whois::Parser.bug!(ParserError, "Unknown status `#{$1}'.")
end
else
Whois::Parser.bug!(ParserError, "Unable to parse status.")
end
return status_v3 if version == "3"
status_v1
end

property_supported :available? do
Expand All @@ -72,50 +53,54 @@ class WhoisCiraCa < Base


property_supported :created_on do
node("Creation date") { |str| parse_time(str) }
node_name = if version == "3"
"Creation Date"
else
"Creation date"
end

node(node_name) { |str| parse_time(str) }
end

property_supported :updated_on do
node("Updated date") { |str| parse_time(str) }
node_name = if version == "3"
"Updated Date"
else
"Updated date"
end

node(node_name) { |str| parse_time(str) }
end

property_supported :expires_on do
node("Expiry date") { |str| parse_time(str) }
node_name = if version == "3"
"Registry Expiry Date"
else
"Expiry date"
end

node(node_name) { |str| parse_time(str) }
end


property_supported :registrar do
node("Registrar") do |hash|
Parser::Registrar.new(
id: hash["Number"],
name: hash["Name"],
organization: hash["Name"]
)
end
return registrar_v3 if version == "3"
registrar_v1
end


property_supported :registrant_contacts do
build_contact("Registrant", Parser::Contact::TYPE_REGISTRANT)
build_contact(Parser::Contact::TYPE_REGISTRANT)
end

property_supported :admin_contacts do
build_contact("Administrative contact", Parser::Contact::TYPE_ADMINISTRATIVE)
build_contact(Parser::Contact::TYPE_ADMINISTRATIVE)
end

property_supported :technical_contacts do
build_contact("Technical contact", Parser::Contact::TYPE_TECHNICAL)
end


property_supported :nameservers do
Array.wrap(node("nserver")).map do |line|
name, ipv4 = line.split(/\s+/)
Parser::Nameserver.new(:name => name, :ipv4 => ipv4)
end
build_contact(Parser::Contact::TYPE_TECHNICAL)
end


# Nameservers are listed in the following formats:
#
# ns1.google.com
Expand All @@ -125,13 +110,18 @@ class WhoisCiraCa < Base
# ns2.google.com 216.239.34.10
#
property_supported :nameservers do
Array.wrap(node("field:nameservers")).map do |line|
node_name = if version == "3"
"Name Server"
else
"field:nameservers"
end

Array.wrap(node(node_name)).map do |line|
name, ipv4 = line.strip.split(/\s+/)
Parser::Nameserver.new(:name => name, :ipv4 => ipv4)
end
end


# Attempts to detect and returns the version.
#
# TODO: This is very empiric.
Expand All @@ -141,9 +131,13 @@ class WhoisCiraCa < Base
def version
cached_properties_fetch :version do
version = if content_for_scanner =~ /^% \(c\) (.+?) Canadian Internet Registration Authority/
case $1
when "2007" then "1"
when "2010" then "2"
year = $1.to_i
if year >= 2019
"3"
elsif year >= 2010
"2"
elsif year >= 2007
"1"
end
end
version || Whois::Parser.bug!(ParserError, "Unable to detect version.")
Expand All @@ -167,7 +161,80 @@ def invalid?

private

def build_contact(element, type)
def status_v1
if content_for_scanner =~ /Domain status:\s+(.+?)\n/
case node("Domain status", &:downcase)
when "registered"
:registered
when "redemption"
:registered
when "auto-renew grace"
:registered
when "to be released"
:registered
when "pending delete"
:registered
when "available"
:available
when "unavailable"
:invalid
else
Whois::Parser.bug!(ParserError, "Unknown status `#{$1}'.")
end
else
Whois::Parser.bug!(ParserError, "Unable to parse status.")
end
end

def status_v3
if node("Not found")
:available
else
:registered
end
end

def registrar_v1
node("Registrar") do |hash|
Parser::Registrar.new(
id: hash["Number"],
name: hash["Name"],
organization: hash["Name"]
)
end
end

def registrar_v3
registrar_information = {
id: node("Registrar IANA ID"),
name: node("Registrar"),
organization: node("Registrar"),
}
registrar_information.compact!
return if registrar_information.empty?

Parser::Registrar.new(
**registrar_information,
)
end

def build_contact(type)
return build_contact_v3(type) if version == "3"
build_contact_v1(type)
end

def build_contact_v1(type)
element = case type
when Parser::Contact::TYPE_REGISTRANT
'Registrant'
when Parser::Contact::TYPE_ADMINISTRATIVE
'Administrative contact'
when Parser::Contact::TYPE_TECHNICAL
'Technical contact'
else
Whois::Parser.bug!(ParserError, "Invalid contact type #{type}.")
end

node(element) do |hash|
Parser::Contact.new(
:type => type,
Expand All @@ -186,6 +253,41 @@ def build_contact(element, type)
end
end

def build_contact_v3(type)
prefix = case type
when Parser::Contact::TYPE_REGISTRANT
'Registrant'
when Parser::Contact::TYPE_ADMINISTRATIVE
'Admin'
when Parser::Contact::TYPE_TECHNICAL
'Tech'
else
Whois::Parser.bug!(ParserError, "Invalid contact type #{type}.")
end

contact_information = {
id: node("Registry #{prefix} ID"),
name: node("#{prefix} Name"),
organization: node("#{prefix} Organization"),
address: node("#{prefix} Street"),
city: node("#{prefix} City"),
zip: node("#{prefix} Postal Code"),
state: node("#{prefix} State/Province"),
country: node("#{prefix} Country"),
country_code: node("#{prefix} Country"),
phone: node("#{prefix} Phone"),
fax: node("#{prefix} Fax"),
email: node("#{prefix} Email"),
}
contact_information.compact!
return if contact_information.empty?

Parser::Contact.new(
type: type,
**contact_information,
)
end

end

end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#status
%s == :available

#available?
%s == true

#registered?
%s == false
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Not found: u34jedzcq.ca

%
% Use of CIRA's WHOIS service is governed by the Terms of Use in its Legal
% Notice, available at http://www.cira.ca/legal-notice/?lang=en
%
% (c) 2019 Canadian Internet Registration Authority, (http://www.cira.ca/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#disclaimer
%s == "Use of CIRA's WHOIS service is governed by the Terms of Use in its Legal\nNotice, available at http://www.cira.ca/legal-notice/?lang=en\n\n(c) 2019 Canadian Internet Registration Authority, (http://www.cira.ca/)"


#domain
%s == "u34jedzcq.ca"

#domain_id
%s %ERROR{AttributeNotSupported}


#status
%s == :available

#available?
%s == true

#registered?
%s == false


#created_on
%s == nil

#updated_on
%s == nil

#expires_on
%s == nil


#registrar
%s == nil

#registrant_contacts
%s %CLASS{array}
%s == []

#admin_contacts
%s %CLASS{array}
%s == []

#technical_contacts
%s %CLASS{array}
%s == []


#nameservers
%s %CLASS{array}
%s == []


#valid?
%s == true

#invalid?
%s == false
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Not found: u34jedzcq.ca

%
% Use of CIRA's WHOIS service is governed by the Terms of Use in its Legal
% Notice, available at http://www.cira.ca/legal-notice/?lang=en
%
% (c) 2019 Canadian Internet Registration Authority, (http://www.cira.ca/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#status
%s == :available


#valid?
%s == true

#invalid?
%s == false
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Not found: mediom.ca

%
% Use of CIRA's WHOIS service is governed by the Terms of Use in its Legal
% Notice, available at http://www.cira.ca/legal-notice/?lang=en
%
% (c) 2019 Canadian Internet Registration Authority, (http://www.cira.ca/)
Loading