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

Fix the parser for the .fi TLD (Closes: #42) #133

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
54 changes: 37 additions & 17 deletions lib/whois/parsers/whois.fi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class WhoisFi < Base
:reserved
elsif registered?
case node("status", &:downcase)
when "registered"
:registered
when "granted"
:registered
when "grace period"
Expand Down Expand Up @@ -76,33 +78,51 @@ class WhoisFi < Base
end


property_not_supported :registrar
property_supported :registrar do
node("Registrar") do |hash|
Parser::Registrar.new(
name: hash['registrar'],
organization: hash['registrar'],
url: hash['www']
)
end
end

property_supported :registrant_contacts do
node("descr") do |array|
address = node("address")
property_not_supported :registrant_contacts do
end

property_supported :admin_contacts do
node("Holder") do |hash|
Parser::Contact.new(
type: Parser::Contact::TYPE_REGISTRANT,
id: array[1],
name: address[0],
organization: array[0],
address: address[1],
zip: address[2],
city: address[3],
phone: node("phone")
type: Parser::Contact::TYPE_ADMINISTRATIVE,
id: hash['register number'],
name: hash['name'],
address: hash['address'][0],
zip: hash['address'][1],
city: hash['address'][2],
country: hash['country'],
phone: hash['phone'],
email: hash['holder email']
)
end
end

property_not_supported :admin_contacts

property_not_supported :technical_contacts
property_supported :technical_contacts do
node("Tech") do |hash|
Parser::Contact.new(
type: Parser::Contact::TYPE_TECHNICAL,
name: hash['name'],
email: hash['email']
)
end
end


property_supported :nameservers do
Array.wrap(node("nserver")).map do |line|
Parser::Nameserver.new(name: line.split(" ").first)
node('Nameservers') do |hash|
Array.wrap(hash['nserver']).map do |line|
Parser::Nameserver.new(name: line.split(" ").first)
end
end
end

Expand Down
43 changes: 36 additions & 7 deletions lib/whois/scanners/whois.fi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ class WhoisFi < Base
self.tokenizers += [
:skip_empty_line,
:scan_available,
:scan_disclaimer,
:scan_keyvalue,
:scan_reserved
:scan_reserved,
:scan_section,
:scan_keyvalue,
:skip_last_update,
:scan_disclaimer
]


tokenizer :scan_available do
if @input.skip(/^Domain not found/)
@ast["status:available"] = true
Expand All @@ -27,13 +29,40 @@ class WhoisFi < Base
end
end

tokenizer :scan_disclaimer do
if @input.match?(/^More information/)
@ast["field:disclaimer"] = @input.scan_until(/(.*)\n\n/).strip
tokenizer :scan_section do
if @input.scan(/^(Nameservers|DNSSEC|Holder|Registrar|Tech)\n\n/)
@tmp['_section'] = @input[1]
while scan_keyvalue
end
@tmp.delete('_section')
end
end

end
# Override scan_keyvalue to match the weird
# key.........: value -format
tokenizer :scan_keyvalue do
if @input.scan(/(.+?)(\.+):(.*?)(\n|\z)/)
key, value = @input[1].strip, @input[3].strip
target = @tmp['_section'] ? (@ast[@tmp['_section']] ||= {}) : @ast

if target[key].nil?
target[key] = value
else
target[key] = Array.wrap(target[key])
target[key] << value
end
end
end

tokenizer :skip_last_update do
@input.skip(/^>>> Last update.*<<<\n\n/)
end

tokenizer :scan_disclaimer do
@input.skip_until(/^(Copyright \(c\) Finnish Transport and Communications Agency Traficom)/)
@ast["field:disclaimer"] = @input[1]
end

end
end
end
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#disclaimer
%s == "More information is available at https://domain.fi/\nCopyright (c) Finnish Communications Regulatory Authority"
%s == "Copyright (c) Finnish Transport and Communications Agency Traficom"


#domain
%s == "oogle.fi"
%s == "kalatalousministeri.fi"

#domain_id
%s %ERROR{AttributeNotSupported}
Expand All @@ -21,51 +21,69 @@

#created_on
%s %CLASS{time}
%s %TIME{2012-06-21}
%s %TIME{2018-03-14 17:47:42}

#updated_on
%s %CLASS{time}
%s %TIME{2013-06-22}
%s %TIME{2019-11-06}

#expires_on
%s %CLASS{time}
%s %TIME{2013-06-21}
%s %TIME{2020-03-14 17:47:42}


#registrar
%s %ERROR{AttributeNotSupported}
%s.name == "Gandi SAS"
%s.url == "www.gandi.net"

#registrant_contacts
%s %ERROR{AttributeNotSupported}

#admin_contacts
%s %CLASS{array}
%s %SIZE{1}
%s[0] %CLASS{contact}
%s[0].type == Whois::Parser::Contact::TYPE_REGISTRANT
%s[0].id == "NURMI"
%s[0].name == "-"
%s[0].organization == "Minna"
%s[0].address == "Huovitie 3"
%s[0].city == "HELSINKI"
%s[0].zip == "00400"
%s[0].type == Whois::Parser::Contact::TYPE_ADMINISTRATIVE
%s[0].id == "2823344-7"
%s[0].name == "Digiteam Oy"
%s[0].address == "Myllyniityntie 71"
%s[0].city == "Lohja"
%s[0].zip == "08100"
%s[0].state == nil
%s[0].country == nil
%s[0].country == "Finland"
%s[0].country_code == nil
%s[0].phone == "+358201599789"
%s[0].phone == "+358.503716096"
%s[0].fax == nil
%s[0].email == nil
%s[0].email == ""
%s[0].created_on == nil
%s[0].updated_on == nil

#admin_contacts
%s %ERROR{AttributeNotSupported}

#technical_contacts
%s %ERROR{AttributeNotSupported}
%s %CLASS{array}
%s %SIZE{1}
%s[0] %CLASS{contact}
%s[0].type == Whois::Parser::Contact::TYPE_TECHNICAL
%s[0].id == nil
%s[0].name == "Seravo Oy"
%s[0].address == nil
%s[0].city == nil
%s[0].zip == nil
%s[0].state == nil
%s[0].country == nil
%s[0].country_code == nil
%s[0].phone == nil
%s[0].fax == nil
%s[0].email == "[email protected]"
%s[0].created_on == nil
%s[0].updated_on == nil


#nameservers
%s %CLASS{array}
%s %SIZE{2}
%s %SIZE{3}
%s[0] %CLASS{nameserver}
%s[0].name == "a.ns.netim.net"
%s[0].name == "ns-184-c.gandi.net"
%s[1] %CLASS{nameserver}
%s[1].name == "b.ns.netim.net"
%s[1].name == "ns-196-a.gandi.net"
%s[2] %CLASS{nameserver}
%s[2].name == "ns-73-b.gandi.net"
64 changes: 44 additions & 20 deletions spec/fixtures/responses/whois.fi/fi/property_status_graceperiod.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
IP: UNABLE TO RESOLVE

domain: oogle.fi
descr: Minna
descr: NURMI
address: -
address: Huovitie 3
address: 00400
address: HELSINKI
phone: +358201599789
status: Grace Period
created: 21.6.2012
modified: 22.6.2013
expires: 21.6.2013
nserver: a.ns.netim.net [Ok]
nserver: b.ns.netim.net [Ok]
dnssec: no

More information is available at https://domain.fi/
Copyright (c) Finnish Communications Regulatory Authority

domain.............: kalatalousministeri.fi
status.............: Grace Period
created............: 14.3.2018 17:47:42
expires............: 14.3.2020 17:47:42
available..........: 14.4.2020 17:47:42
modified...........: 6.11.2019
RegistryLock.......: no

Nameservers

nserver............: ns-184-c.gandi.net [OK]
nserver............: ns-196-a.gandi.net [OK]
nserver............: ns-73-b.gandi.net [OK]

DNSSEC

dnssec.............: no

Holder

name...............: Digiteam Oy
register number....: 2823344-7
address............: Myllyniityntie 71
address............: 08100
address............: Lohja
country............: Finland
phone..............: +358.503716096
holder email.......:

Registrar

registrar..........: Gandi SAS
www................: www.gandi.net

Tech

name...............: Seravo Oy
email..............: [email protected]

>>> Last update of WHOIS database: 22.3.2020 13:47:27 (EET) <<<


Copyright (c) Finnish Transport and Communications Agency Traficom

14 changes: 8 additions & 6 deletions spec/fixtures/responses/whois.fi/fi/status_available.expected
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#disclaimer
%s == "More information is available at https://domain.fi/\nCopyright (c) Finnish Communications Regulatory Authority"
%s == "Copyright (c) Finnish Transport and Communications Agency Traficom"


#domain
Expand Down Expand Up @@ -30,17 +30,19 @@


#registrar
%s %ERROR{AttributeNotSupported}
%s == nil

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

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

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



#nameservers
Expand Down
3 changes: 1 addition & 2 deletions spec/fixtures/responses/whois.fi/fi/status_available.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

Domain not found

More information is available at https://domain.fi/
Copyright (c) Finnish Communications Regulatory Authority
Copyright (c) Finnish Transport and Communications Agency Traficom

Loading