| 1 | ## Domain Registry Interface, Whois commands for .US (RFC3912) | ||
| 2 | ## | ||
| 3 | ## Copyright (c) 2008,2009,2013 Patrick Mevzek <netdri@dotandco.com>. All rights reserved. | ||
| 4 | ## | ||
| 5 | ## This file is part of Net::DRI | ||
| 6 | ## | ||
| 7 | ## Net::DRI is free software; you can redistribute it and/or modify | ||
| 8 | ## it under the terms of the GNU General Public License as published by | ||
| 9 | ## the Free Software Foundation; either version 2 of the License, or | ||
| 10 | ## (at your option) any later version. | ||
| 11 | ## | ||
| 12 | ## See the LICENSE file that comes with this distribution for more details. | ||
| 13 | #################################################################################################### | ||
| 14 | |||
| 15 | package Net::DRI::Protocol::Whois::Domain::US; | ||
| 16 | |||
| 17 | use strict; | ||
| 18 | use warnings; | ||
| 19 | |||
| 20 | use Net::DRI::Exception; | ||
| 21 | use Net::DRI::Util; | ||
| 22 | use Net::DRI::Protocol::Whois::Domain::common; | ||
| 23 | |||
| 24 | =pod | ||
| 25 | |||
| 26 | =head1 NAME | ||
| 27 | |||
| 28 | Net::DRI::Protocol::Whois::Domain::US - .US Whois commands (RFC3912) for Net::DRI | ||
| 29 | |||
| 30 | =head1 DESCRIPTION | ||
| 31 | |||
| 32 | Please see the README file for details. | ||
| 33 | |||
| 34 | =head1 SUPPORT | ||
| 35 | |||
| 36 | For now, support questions should be sent to: | ||
| 37 | |||
| 38 | E<lt>netdri@dotandco.comE<gt> | ||
| 39 | |||
| 40 | Please also see the SUPPORT file in the distribution. | ||
| 41 | |||
| 42 | =head1 SEE ALSO | ||
| 43 | |||
| 44 | E<lt>http://www.dotandco.com/services/software/Net-DRI/E<gt> | ||
| 45 | |||
| 46 | =head1 AUTHOR | ||
| 47 | |||
| 48 | Patrick Mevzek, E<lt>netdri@dotandco.comE<gt> | ||
| 49 | |||
| 50 | =head1 COPYRIGHT | ||
| 51 | |||
| 52 | Copyright (c) 2008,2009,2013 Patrick Mevzek <netdri@dotandco.com>. | ||
| 53 | All rights reserved. | ||
| 54 | |||
| 55 | This program is free software; you can redistribute it and/or modify | ||
| 56 | it under the terms of the GNU General Public License as published by | ||
| 57 | the Free Software Foundation; either version 2 of the License, or | ||
| 58 | (at your option) any later version. | ||
| 59 | |||
| 60 | See the LICENSE file that comes with this distribution for more details. | ||
| 61 | |||
| 62 | =cut | ||
| 63 | |||
| 64 | #################################################################################################### | ||
| 65 | |||
| 66 | sub register_commands | ||
| 67 | { | ||
| 68 | my ($class,$version)=@_; | ||
| 69 | return { 'domain' => { info => [ \&info, \&info_parse ] } }; | ||
| 70 | } | ||
| 71 | |||
| 72 | sub info | ||
| 73 | { | ||
| 74 | my ($po,$domain,$rd)=@_; | ||
| 75 | my $mes=$po->message(); | ||
| 76 | Net::DRI::Exception->die(1,'protocol/whois',10,'Invalid domain name: '.$domain) unless Net::DRI::Util::is_hostname($domain); | ||
| 77 | $mes->command('domain '.lc($domain)); | ||
| 78 | return; | ||
| 79 | } | ||
| 80 | |||
| 81 | sub info_parse | ||
| 82 | { | ||
| 83 | my ($po,$otype,$oaction,$oname,$rinfo)=@_; | ||
| 84 | my $mes=$po->message(); | ||
| 85 | return unless $mes->is_success(); | ||
| 86 | |||
| 87 | my $rr=$mes->response(); | ||
| 88 | my $rd=$mes->response_raw(); | ||
| 89 | my ($domain,$exist)=parse_domain($po,$rr,$rd,$rinfo); | ||
| 90 | $rinfo->{domain}->{$domain}->{exist}=$exist; | ||
| 91 | $rinfo->{domain}->{$domain}->{action}='info'; | ||
| 92 | |||
| 93 | return unless $exist; | ||
| 94 | |||
| 95 | parse_registrars($po,$domain,$rr,$rinfo); | ||
| 96 | parse_dates($po,$domain,$rr,$rinfo); | ||
| 97 | Net::DRI::Protocol::Whois::Domain::common::epp_parse_status($po,$domain,$rr,$rinfo); | ||
| 98 | Net::DRI::Protocol::Whois::Domain::common::epp_parse_contacts($po,$domain,$rr,$rinfo,{registrant => 'Registrant',admin => 'Administrative Contact', billing => 'Billing Contact', tech => 'Technical Contact'}); | ||
| 99 | Net::DRI::Protocol::Whois::Domain::common::epp_parse_ns($po,$domain,$rr,$rinfo); | ||
| 100 | return; | ||
| 101 | } | ||
| 102 | |||
| 103 | sub parse_domain | ||
| 104 | { | ||
| 105 | my ($po,$rr,$rd,$rinfo)=@_; | ||
| 106 | my ($dom,$e); | ||
| 107 | if (exists($rr->{'Domain Name'})) | ||
| 108 | { | ||
| 109 | $e=1; | ||
| 110 | $dom=lc($rr->{'Domain Name'}->[0]); | ||
| 111 | $rinfo->{domain}->{$dom}->{roid}=$rr->{'Domain ID'}->[0]; | ||
| 112 | } else | ||
| 113 | { | ||
| 114 | $e=0; | ||
| 115 | ($dom)=grep { m/^Not found: domain (\S+)\s*$/ } @$rd; | ||
| 116 | $dom=~s/domain (\S+)\s*$/$1/; | ||
| 117 | $dom=lc($dom); | ||
| 118 | } | ||
| 119 | return ($dom,$e); | ||
| 120 | } | ||
| 121 | |||
| 122 | sub parse_registrars | ||
| 123 | { | ||
| 124 | my ($po,$domain,$rr,$rinfo)=@_; | ||
| 125 | |||
| 126 | $rinfo->{domain}->{$domain}->{clName}=$rr->{'Sponsoring Registrar'}->[0]; | ||
| 127 | $rinfo->{domain}->{$domain}->{crName}=$rr->{'Created by Registrar'}->[0]; | ||
| 128 | $rinfo->{domain}->{$domain}->{upName}=$rr->{'Last Updated by Registrar'}->[0]; | ||
| 129 | return; | ||
| 130 | } | ||
| 131 | |||
| 132 | sub parse_dates | ||
| 133 | { | ||
| 134 | my ($po,$domain,$rr,$rinfo)=@_; | ||
| 135 | my $strp=$po->build_strptime_parser(pattern => '%a %b %d %T GMT %Y', locale => 'en_US', time_zone => 'UTC'); | ||
| 136 | $rinfo->{domain}->{$domain}->{crDate}=$strp->parse_datetime($rr->{'Domain Registration Date'}->[0]); | ||
| 137 | $rinfo->{domain}->{$domain}->{exDate}=$strp->parse_datetime($rr->{'Domain Expiration Date'}->[0]); | ||
| 138 | $rinfo->{domain}->{$domain}->{upDate}=$strp->parse_datetime($rr->{'Domain Last Updated Date'}->[0]); | ||
| 139 | return; | ||
| 140 | } | ||
| 141 | |||
| 142 | #################################################################################################### | ||
| 143 | 1; |