| 1 | ## Domain Registry Interface, RRP Domain commands | ||
| 2 | ## | ||
| 3 | ## Copyright (c) 2005,2006,2008,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::RRP::Core::Domain; | ||
| 16 | |||
| 17 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | |||
| 20 | 1 | ▶ | use Net::DRI::Data::Hosts; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 1 | ▶ | use Net::DRI::Protocol::RRP::Core::Status; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | 1 | ▶ | use Net::DRI::Protocol::RRP; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 23 | use Net::DRI::Util; | ||
| 24 | |||
| 25 | =pod | ||
| 26 | |||
| 27 | =head1 NAME | ||
| 28 | |||
| 29 | Net::DRI::Protocol::RRP::Core::Domain - RRP Domain commands for Net::DRI | ||
| 30 | |||
| 31 | =head1 DESCRIPTION | ||
| 32 | |||
| 33 | Please see the README file for details. | ||
| 34 | |||
| 35 | =head1 SUPPORT | ||
| 36 | |||
| 37 | For now, support questions should be sent to: | ||
| 38 | |||
| 39 | E<lt>netdri@dotandco.comE<gt> | ||
| 40 | |||
| 41 | Please also see the SUPPORT file in the distribution. | ||
| 42 | |||
| 43 | =head1 SEE ALSO | ||
| 44 | |||
| 45 | E<lt>http://www.dotandco.com/services/software/Net-DRI/E<gt> | ||
| 46 | |||
| 47 | =head1 AUTHOR | ||
| 48 | |||
| 49 | Patrick Mevzek, E<lt>netdri@dotandco.comE<gt> | ||
| 50 | |||
| 51 | =head1 COPYRIGHT | ||
| 52 | |||
| 53 | Copyright (c) 2005,2006,2008,2013 Patrick Mevzek <netdri@dotandco.com>. | ||
| 54 | All rights reserved. | ||
| 55 | |||
| 56 | This program is free software; you can redistribute it and/or modify | ||
| 57 | it under the terms of the GNU General Public License as published by | ||
| 58 | the Free Software Foundation; either version 2 of the License, or | ||
| 59 | (at your option) any later version. | ||
| 60 | |||
| 61 | See the LICENSE file that comes with this distribution for more details. | ||
| 62 | |||
| 63 | =cut | ||
| 64 | |||
| 65 | |||
| 66 | ########################################################## | ||
| 67 | |||
| 68 | sub register_commands | ||
| 69 | { | ||
| 70 | my ($class,$version)=@_; | ||
| 71 | my %tmp=( create => [ \&add, \&add_parse ], | ||
| 72 | check => [ \&check, \&check_parse ], | ||
| 73 | info => [ \&status, \&status_parse ], | ||
| 74 | delete => [ \&del ], | ||
| 75 | renew => [ \&renew, \&renew_parse ], | ||
| 76 | update => [ \&mod ], | ||
| 77 | transfer_request => [ \&transfer_request ], | ||
| 78 | transfer_answer => [ \&transfer_answer ], | ||
| 79 | ); | ||
| 80 | |||
| 81 | $tmp{transfer_cancel}=[ \&transfer_answer ] if ($version eq "2.0"); | ||
| 82 | return { 'domain' => \%tmp }; | ||
| 83 | } | ||
| 84 | |||
| 85 | sub build_msg | ||
| 86 | { | ||
| 87 | my ($msg,$command,$domain)=@_; | ||
| 88 | Net::DRI::Exception->die(1,'protocol/RRP',2,"Domain name needed") unless defined($domain) && $domain; | ||
| 89 | Net::DRI::Exception->die(1,'protocol/RRP',10,"Invalid domain name") unless ($domain=~m/^[a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?\.[a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?$/i); ## from RRP grammar | ||
| 90 | $msg->command($command) if defined($command); | ||
| 91 | $msg->entities('EntityName','Domain'); | ||
| 92 | $msg->entities('DomainName',uc $domain); | ||
| 93 | return; | ||
| 94 | } | ||
| 95 | |||
| 96 | sub add | ||
| 97 | { | ||
| 98 | my ($rrp,$domain,$rd)=@_; | ||
| 99 | my $mes=$rrp->message(); | ||
| 100 | build_msg($mes,'add',$domain); | ||
| 101 | |||
| 102 | ## (MAY) | ||
| 103 | if (Net::DRI::Util::has_duration($rd)) | ||
| 104 | { | ||
| 105 | my $period=$rd->{duration}->years(); | ||
| 106 | Net::DRI::Exceptions::usererr_invalid_parameters('period must be an integer') unless Net::DRI::Util::isint($period); | ||
| 107 | $mes->options('Period',$period); | ||
| 108 | } | ||
| 109 | ## (MAY) 1 to 13 nameservers | ||
| 110 | if (Net::DRI::Util::has_ns($rd)) | ||
| 111 | { | ||
| 112 | foreach ($rd->{ns}->get_names(13)) { $mes->entities('NameServer',$_); } | ||
| 113 | } | ||
| 114 | return; | ||
| 115 | } | ||
| 116 | |||
| 117 | sub add_parse | ||
| 118 | { | ||
| 119 | my ($po,$otype,$oaction,$oname,$rinfo)=@_; | ||
| 120 | my $mes=$po->message(); | ||
| 121 | return unless $mes->is_success(); | ||
| 122 | |||
| 123 | ## Create a new DataTime object | ||
| 124 | my $d='registration expiration date'; | ||
| 125 | $rinfo->{domain}->{$oname}->{$Net::DRI::Protocol::RRP::DATES{$d}}=$po->{dt_parse}->parse_datetime($mes->entities($d)); | ||
| 126 | $rinfo->{domain}->{$oname}->{status}=Net::DRI::Protocol::RRP::Core::Status->new($mes); | ||
| 127 | $rinfo->{domain}->{$oname}->{exist}=1; | ||
| 128 | $rinfo->{domain}->{$oname}->{action}='create'; | ||
| 129 | return; | ||
| 130 | } | ||
| 131 | |||
| 132 | sub renew_parse | ||
| 133 | { | ||
| 134 | my ($po,$otype,$oaction,$oname,$rinfo)=@_; | ||
| 135 | add_parse($po,$otype,$oaction,$oname,$rinfo); | ||
| 136 | $rinfo->{domain}->{$oname}->{action}='renew' if (exists($rinfo->{domain}->{$oname}->{action})); | ||
| 137 | return; | ||
| 138 | } | ||
| 139 | |||
| 140 | sub _basic_command | ||
| 141 | { | ||
| 142 | my ($command,$rrp,$domain)=@_; | ||
| 143 | my $mes=$rrp->message(); | ||
| 144 | build_msg($mes,$command,$domain); | ||
| 145 | return; | ||
| 146 | } | ||
| 147 | |||
| 148 | sub check { my (@args)=@_; return _basic_command('check',@args); } | ||
| 149 | sub status { my (@args)=@_; return _basic_command('status',@args); } | ||
| 150 | sub del { my (@args)=@_; return _basic_command('del',@args); } | ||
| 151 | sub transfer_request { my (@args)=@_; return _basic_command('transfer',@args); } | ||
| 152 | |||
| 153 | sub check_parse | ||
| 154 | { | ||
| 155 | my ($po,$otype,$oaction,$oname,$rinfo)=@_; | ||
| 156 | my $mes=$po->message(); | ||
| 157 | return unless $mes->is_success(); | ||
| 158 | |||
| 159 | if ($mes->errcode() == 211) ## domain exists | ||
| 160 | { | ||
| 161 | $rinfo->{domain}->{$oname}->{exist}=1; | ||
| 162 | } elsif ($mes->errcode() == 210) ## domain available | ||
| 163 | { | ||
| 164 | $rinfo->{domain}->{$oname}->{exist}=0; | ||
| 165 | } | ||
| 166 | $rinfo->{domain}->{$oname}->{action}='check'; | ||
| 167 | return; | ||
| 168 | } | ||
| 169 | |||
| 170 | sub status_parse | ||
| 171 | { | ||
| 172 | my ($po,$otype,$oaction,$oname,$rinfo)=@_; | ||
| 173 | my $mes=$po->message(); | ||
| 174 | return unless $mes->is_success(); | ||
| 175 | |||
| 176 | $rinfo->{domain}->{$oname}->{exist}=1; | ||
| 177 | $rinfo->{domain}->{$oname}->{action}='info'; | ||
| 178 | |||
| 179 | while(my ($k,$v)=each(%Net::DRI::Protocol::RRP::DATES)) | ||
| 180 | { | ||
| 181 | my $d=$mes->entities($k); | ||
| 182 | next unless $d; | ||
| 183 | $rinfo->{domain}->{$oname}->{$v}=$po->{dt_parse}->parse_datetime($d); | ||
| 184 | } | ||
| 185 | |||
| 186 | while(my ($k,$v)=each(%Net::DRI::Protocol::RRP::IDS)) | ||
| 187 | { | ||
| 188 | my $d=$mes->entities($k); | ||
| 189 | next unless $d; | ||
| 190 | $rinfo->{domain}->{$oname}->{$v}=$d; | ||
| 191 | } | ||
| 192 | |||
| 193 | $rinfo->{domain}->{$oname}->{status}=Net::DRI::Protocol::RRP::Core::Status->new($mes); | ||
| 194 | |||
| 195 | my @ns=$mes->entities('nameserver'); | ||
| 196 | $rinfo->{domain}->{$oname}->{ns}=Net::DRI::Data::Hosts->new_set(@ns); | ||
| 197 | return; | ||
| 198 | } | ||
| 199 | |||
| 200 | sub transfer_answer | ||
| 201 | { | ||
| 202 | my ($rrp,$domain,$rd)=@_; | ||
| 203 | my $mes=$rrp->message(); | ||
| 204 | build_msg($mes,'transfer',$domain); | ||
| 205 | |||
| 206 | $mes->entities('Approve',(defined($rd) && ref($rd) && exists($rd->{approve}) && $rd->{approve})? 'Yes' : 'No'); | ||
| 207 | return; | ||
| 208 | } | ||
| 209 | |||
| 210 | sub mod | ||
| 211 | { | ||
| 212 | my ($rrp,$domain,$todo)=@_; | ||
| 213 | my $mes=$rrp->message(); | ||
| 214 | build_msg($mes,'mod',$domain); | ||
| 215 | |||
| 216 | Net::DRI::Exception::usererr_invalid_parameters($todo.' must be a Net::DRI::Data::Changes object') unless Net::DRI::Util::isa_changes($todo); | ||
| 217 | if ((grep { ! /^(?:ns|status)$/ } $todo->types()) || | ||
| 218 | (grep { ! /^(?:add|del)$/ } $todo->types('ns')) || | ||
| 219 | (grep { ! /^(?:add|del)$/ } $todo->types('status')) | ||
| 220 | ) | ||
| 221 | { | ||
| 222 | Net::DRI::Exception->die(0,'protocol/RRP',11,'Only ns/status add/del available for domain'); | ||
| 223 | } | ||
| 224 | |||
| 225 | my $nsadd=$todo->add('ns'); | ||
| 226 | my $nsdel=$todo->del('ns'); | ||
| 227 | my $statadd=$todo->add('status'); | ||
| 228 | my $statdel=$todo->del('status'); | ||
| 229 | |||
| 230 | ## $nsadd/$nsdel are Net::DRI::Data::Hosts objects | ||
| 231 | ## Up to 13 nameservers only | ||
| 232 | if (defined($nsadd) && !$nsadd->is_empty()) { foreach ($nsadd->get_names(13)) { $mes->entities('NameServer',$_) } } | ||
| 233 | if (defined($nsdel) && !$nsdel->is_empty()) { foreach ($nsdel->get_names(13)) { $mes->entities('NameServer',$_.'=') } } | ||
| 234 | |||
| 235 | ## $statadd/$statdel are Net::DRI::Protocol::RRP::Core::Status objects | ||
| 236 | if (defined($statadd)) { foreach ($statadd->list_status()) { $mes->entities('Status',$_) } } | ||
| 237 | if (defined($statdel)) { foreach ($statdel->list_status()) { $mes->entities('Status',$_.'=') } } | ||
| 238 | return; | ||
| 239 | } | ||
| 240 | |||
| 241 | sub renew | ||
| 242 | { | ||
| 243 | my ($rrp,$domain,$rd)=@_; | ||
| 244 | my ($period,$curexp); | ||
| 245 | if (defined($rd) && (ref($rd) eq 'HASH') && keys(%$rd)) | ||
| 246 | { | ||
| 247 | $period=$rd->{duration}; | ||
| 248 | $curexp=$rd->{current_expiration}; | ||
| 249 | } | ||
| 250 | Net::DRI::Exceptions::usererr_insufficient_parameters("current expiration year and period must be both defined or not at all") if (defined($curexp) xor defined($period)); ## both or none should be defined | ||
| 251 | if (defined($curexp)) | ||
| 252 | { | ||
| 253 | Net::DRI::Util::check_isa($period,'DateTime::Duration'); | ||
| 254 | $period=$period->years(); | ||
| 255 | Net::DRI::Exceptions::usererr_invalid_parameters("period must be an integer") unless Net::DRI::Util::isint($period); | ||
| 256 | $curexp=$curexp->year() if (ref($curexp) && $curexp->can('year')); ## for DateTime objects | ||
| 257 | Net::DRI::Exceptions::usererr_invalid_parameters("current expiration year must be a 4 digits integer") unless $curexp=~m/^\d{4}$/; | ||
| 258 | } | ||
| 259 | |||
| 260 | my $mes=$rrp->message(); | ||
| 261 | build_msg($mes,'renew',$domain); | ||
| 262 | $mes->options({Period=>$period,CurrentExpirationYear=>$curexp}) if (defined($period) && defined($curexp)); | ||
| 263 | return; | ||
| 264 | } | ||
| 265 | |||
| 266 | #################################################################################################### | ||
| 267 | 1; | ||