| 1 | ## Domain Registry Interface, RRP Host 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::Host; | ||
| 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::Protocol::RRP; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 21 | use Net::DRI::Data::Hosts; | ||
| 22 | use Net::DRI::Util; | ||
| 23 | |||
| 24 | =pod | ||
| 25 | |||
| 26 | =head1 NAME | ||
| 27 | |||
| 28 | Net::DRI::Protocol::RRP::Core::Host - RRP Host commands 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) 2005,2006,2008,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 | my %tmp=( create => [ \&add ], | ||
| 70 | check => [ \&check, \&check_parse ], | ||
| 71 | info => [ \&status, \&status_parse ], | ||
| 72 | delete => [ \&del ], | ||
| 73 | update => [ \&mod ], | ||
| 74 | ); | ||
| 75 | |||
| 76 | return { 'host' => \%tmp }; | ||
| 77 | } | ||
| 78 | |||
| 79 | sub build_msg | ||
| 80 | { | ||
| 81 | my ($msg,$command,$hostname)=@_; | ||
| 82 | ($hostname)=$hostname->get_names(1) if (defined($hostname) && ref($hostname)); | ||
| 83 | Net::DRI::Exception->die(1,'protocol/RRP',3,"Host name needed") unless defined($hostname) && $hostname; | ||
| 84 | Net::DRI::Exception->die(1,'protocol/RRP',10,"Invalid host name") unless ($hostname=~m/^([a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?\.)*[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 | ||
| 85 | $msg->command($command) if defined($command); | ||
| 86 | $msg->entities('EntityName','NameServer'); | ||
| 87 | $msg->entities('NameServer',uc $hostname); | ||
| 88 | return; | ||
| 89 | } | ||
| 90 | |||
| 91 | sub add | ||
| 92 | { | ||
| 93 | my ($rrp,$ns)=@_; | ||
| 94 | my $mes=$rrp->message(); | ||
| 95 | build_msg($mes,'add',$ns); | ||
| 96 | add_ip($mes,$ns,$rrp->version()); | ||
| 97 | return; | ||
| 98 | } | ||
| 99 | |||
| 100 | sub _basic_command | ||
| 101 | { | ||
| 102 | my ($command,$rrp,$ns)=@_; | ||
| 103 | my $mes=$rrp->message(); | ||
| 104 | build_msg($mes,$command,$ns); | ||
| 105 | return; | ||
| 106 | } | ||
| 107 | |||
| 108 | sub check { my (@args)=@_; return _basic_command('check',@args); } | ||
| 109 | sub status { my (@args)=@_; return _basic_command('status',@args); } | ||
| 110 | sub del { my (@args)=@_; return _basic_command('del',@args); } | ||
| 111 | |||
| 112 | sub check_parse | ||
| 113 | { | ||
| 114 | my ($po,$otype,$oaction,$oname,$rinfo)=@_; | ||
| 115 | my $mes=$po->message(); | ||
| 116 | return unless $mes->is_success(); | ||
| 117 | |||
| 118 | $rinfo->{host}->{$oname}->{action}='check'; | ||
| 119 | if ($mes->errcode() == 213) ## nameserver exists | ||
| 120 | { | ||
| 121 | my @ip=$mes->entities('ipaddress'); | ||
| 122 | $rinfo->{host}->{$oname}->{self}=Net::DRI::Data::Hosts->new($oname,\@ip); | ||
| 123 | $rinfo->{host}->{$oname}->{exist}=1; | ||
| 124 | } elsif ($mes->errcode() == 212) ## nameserver available | ||
| 125 | { | ||
| 126 | $rinfo->{host}->{$oname}->{exist}=0; | ||
| 127 | } | ||
| 128 | return; | ||
| 129 | } | ||
| 130 | |||
| 131 | sub status_parse | ||
| 132 | { | ||
| 133 | my ($po,$otype,$oaction,$oname,$rinfo)=@_; | ||
| 134 | my $mes=$po->message(); | ||
| 135 | return unless $mes->is_success(); ## if operation succeeds, information should be there | ||
| 136 | |||
| 137 | $rinfo->{host}->{$oname}->{exist}=1; | ||
| 138 | $rinfo->{host}->{$oname}->{action}='info'; | ||
| 139 | while(my ($k,$v)=each(%Net::DRI::Protocol::RRP::DATES)) | ||
| 140 | { | ||
| 141 | my $d=$mes->entities($k); | ||
| 142 | next unless $d; | ||
| 143 | $rinfo->{host}->{$oname}->{$v}=$po->{dt_parse}->parse_datetime($d); | ||
| 144 | } | ||
| 145 | |||
| 146 | while(my ($k,$v)=each(%Net::DRI::Protocol::RRP::IDS)) | ||
| 147 | { | ||
| 148 | my $d=$mes->entities($k); | ||
| 149 | next unless $d; | ||
| 150 | $rinfo->{host}->{$oname}->{$v}=$d; | ||
| 151 | } | ||
| 152 | |||
| 153 | my @ip=$mes->entities('ipaddress'); | ||
| 154 | $rinfo->{host}->{$oname}->{self}=Net::DRI::Data::Hosts->new($oname,\@ip); | ||
| 155 | return; | ||
| 156 | } | ||
| 157 | |||
| 158 | sub mod | ||
| 159 | { | ||
| 160 | my ($rrp,$hostname,$todo)=@_; | ||
| 161 | my $mes=$rrp->message(); | ||
| 162 | |||
| 163 | Net::DRI::Exception::usererr_invalid_parameters($todo.' must be a Net::DRI::Data::Changes object') unless Net::DRI::Util::isa_changes($todo); | ||
| 164 | if ((grep { ! /^(?:ip|name)$/ } $todo->types()) || | ||
| 165 | (grep { ! /^(?:add|del)$/ } $todo->types('ip')) || | ||
| 166 | (grep { ! /^(?:set)$/ } $todo->types('name')) | ||
| 167 | ) | ||
| 168 | { | ||
| 169 | Net::DRI::Exception->die(0,'protocol/RRP',11,'Only IP add/del or name set available for host'); | ||
| 170 | } | ||
| 171 | |||
| 172 | my $nsadd=$todo->add('ip'); | ||
| 173 | my $nsdel=$todo->del('ip'); | ||
| 174 | my $newname=$todo->set('name'); | ||
| 175 | |||
| 176 | unless (defined($hostname) && $hostname) | ||
| 177 | { | ||
| 178 | $hostname=$nsadd->get_names(1) if (defined($nsadd) && ref($nsadd) && $nsadd->can('get_names')); | ||
| 179 | $hostname=$nsdel->get_names(1) if (defined($nsdel) && ref($nsdel) && $nsdel->can('get_names')); | ||
| 180 | } | ||
| 181 | build_msg($mes,'mod',$hostname); | ||
| 182 | |||
| 183 | my $version=$rrp->version(); | ||
| 184 | add_ip($mes,$nsadd,$version); | ||
| 185 | add_ip($mes,$nsdel,$version,'='); | ||
| 186 | $mes->entities('NewNameServer',ref($newname)? $newname->get_names(1) : $newname) if (defined($newname) && $newname); | ||
| 187 | return; | ||
| 188 | } | ||
| 189 | |||
| 190 | sub add_ip | ||
| 191 | { | ||
| 192 | my ($mes,$ns,$version,$extra)=@_; | ||
| 193 | $extra||=''; | ||
| 194 | return unless (defined($ns) && ref($ns)); | ||
| 195 | my ($name,$r4,$r6)=$ns->get_details(1); | ||
| 196 | my $c=1; | ||
| 197 | foreach my $ip (@$r4) { last if $c++>13; $mes->entities('IPAddress',$_.$extra); }; | ||
| 198 | $c=1; | ||
| 199 | if ($version eq '2.0') { foreach my $ip (@$r6) { last if $c++>13; $mes->entities('IPAddress',$_.$extra); } } | ||
| 200 | return; | ||
| 201 | } | ||
| 202 | |||
| 203 | ######################################################################################### | ||
| 204 | 1; | ||