| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | ## Domain Registry Interface, VeriSign Zone Management EPP extension | 
| 2 |  |  |  |  |  |  | ## | 
| 3 |  |  |  |  |  |  | ## Copyright (c) 2012,2015 Patrick Mevzek . 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::EPP::Extensions::VeriSign::ZoneManagement; | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 1 |  |  | 1 |  | 771 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 31 |  | 
| 18 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 20 |  | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 1 |  |  | 1 |  | 3 | use Net::DRI::Util; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 14 |  | 
| 21 | 1 |  |  | 1 |  | 3 | use Net::DRI::Exception; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 662 |  | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | #################################################################################################### | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | sub register_commands | 
| 26 |  |  |  |  |  |  | { | 
| 27 | 0 |  |  | 0 | 0 |  | my ($class,$version)=@_; | 
| 28 | 0 |  |  |  |  |  | return { 'domain' => { create => [ \&domain_create_generate, undef ], | 
| 29 |  |  |  |  |  |  | info   => [ undef, \&domain_info_parse ], | 
| 30 |  |  |  |  |  |  | update => [ \&domain_update_generate, undef ] }, | 
| 31 |  |  |  |  |  |  | }; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | sub setup | 
| 35 |  |  |  |  |  |  | { | 
| 36 | 0 |  |  | 0 | 0 |  | my ($class,$po,$version)=@_; | 
| 37 | 0 |  |  |  |  |  | $po->ns({ 'zoneMgt' => [ 'http://www.verisign.com/epp/zoneMgt-1.0','zoneMgt-1.0.xsd' ], | 
| 38 |  |  |  |  |  |  | }); | 
| 39 | 0 |  |  |  |  |  | return; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | #################################################################################################### | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | sub _generate_rrecs | 
| 45 |  |  |  |  |  |  | { | 
| 46 | 0 |  |  | 0 |  |  | my ($rr)=@_; | 
| 47 | 0 | 0 |  |  |  |  | my @d=ref $rr eq 'ARRAY' ? @$rr : ($rr); | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 0 | 0 |  |  |  |  | Net::DRI::Exception::usererr_invalid_parameters('RRs must be array of ref hashes') if grep { ref $_ ne 'HASH' } @d; | 
|  | 0 |  |  |  |  |  |  | 
| 50 | 0 |  |  |  |  |  | my @r; | 
| 51 | 0 |  |  |  |  |  | foreach my $r (@d) | 
| 52 |  |  |  |  |  |  | { | 
| 53 | 0 |  |  |  |  |  | my @rr; | 
| 54 | 0 | 0 |  |  |  |  | Net::DRI::Exception::usererr_insufficient_parameters('In RR, "type" key must exist') unless Net::DRI::Util::has_key($r,'type'); | 
| 55 | 0 | 0 |  |  |  |  | Net::DRI::Exception::usererr_invalid_parameters('In RR, for key "type", value must be an XML token') unless Net::DRI::Util::xml_is_token($r->{type}); | 
| 56 | 0 |  |  |  |  |  | push @rr,['zoneMgt:type',$r->{type}]; | 
| 57 | 0 | 0 |  |  |  |  | if (Net::DRI::Util::has_key($r,'class')) | 
| 58 |  |  |  |  |  |  | { | 
| 59 | 0 | 0 |  |  |  |  | Net::DRI::Exception::usererr_invalid_parameters('In RR, for key "class", value must be an XML token, if provided') unless Net::DRI::Util::xml_is_token($r->{class}); | 
| 60 | 0 |  |  |  |  |  | push @rr,['zoneMgt:class',$r->{class}]; | 
| 61 |  |  |  |  |  |  | } else | 
| 62 |  |  |  |  |  |  | { | 
| 63 | 0 |  |  |  |  |  | push @rr,['zoneMgt:class','IN']; | 
| 64 |  |  |  |  |  |  | } | 
| 65 | 0 | 0 |  |  |  |  | if (Net::DRI::Util::has_key($r,'ttl')) | 
| 66 |  |  |  |  |  |  | { | 
| 67 | 0 | 0 |  |  |  |  | Net::DRI::Exception::usererr_invalid_parameters('In RR, for key "ttl", value must be an XML integeter, if provided') unless Net::DRI::Util::verify_int($r->{ttl}); | 
| 68 | 0 |  |  |  |  |  | push @rr,['zoneMgt:ttl',$r->{ttl}]; | 
| 69 |  |  |  |  |  |  | } | 
| 70 | 0 | 0 |  |  |  |  | Net::DRI::Exception::usererr_insufficient_parameters('In RR, "rdata" key must exist') unless Net::DRI::Util::has_key($r,'rdata'); | 
| 71 | 0 | 0 |  |  |  |  | Net::DRI::Exception::usererr_invalid_parameters('In RR, for key "rdata", value must be an XML token') unless Net::DRI::Util::xml_is_token($r->{rdata}); | 
| 72 | 0 |  |  |  |  |  | push @rr,['zoneMgt:rdata',$r->{rdata}]; | 
| 73 | 0 |  |  |  |  |  | push @r,['zoneMgt:rrec',@rr]; | 
| 74 |  |  |  |  |  |  | } | 
| 75 | 0 |  |  |  |  |  | return @r; | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | sub domain_create_generate | 
| 79 |  |  |  |  |  |  | { | 
| 80 | 0 |  |  | 0 | 0 |  | my ($epp,$domain,$rp)=@_; | 
| 81 | 0 |  |  |  |  |  | my $mes=$epp->message(); | 
| 82 |  |  |  |  |  |  |  | 
| 83 | 0 | 0 |  |  |  |  | return unless Net::DRI::Util::has_key($rp,'zone'); | 
| 84 |  |  |  |  |  |  |  | 
| 85 | 0 |  |  |  |  |  | my $eid=$mes->command_extension_register('zoneMgt','create'); | 
| 86 | 0 |  |  |  |  |  | $mes->command_extension($eid,[_generate_rrecs($rp->{zone})]); | 
| 87 | 0 |  |  |  |  |  | return; | 
| 88 |  |  |  |  |  |  | } | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | sub domain_info_parse | 
| 91 |  |  |  |  |  |  | { | 
| 92 | 0 |  |  | 0 | 0 |  | my ($po,$otype,$oaction,$oname,$rinfo)=@_; | 
| 93 | 0 |  |  |  |  |  | my $mes=$po->message(); | 
| 94 | 0 | 0 |  |  |  |  | return unless $mes->is_success(); | 
| 95 |  |  |  |  |  |  |  | 
| 96 | 0 |  |  |  |  |  | my $data=$mes->get_response('zoneMgt','infData'); | 
| 97 | 0 | 0 |  |  |  |  | return unless defined $data; | 
| 98 |  |  |  |  |  |  |  | 
| 99 | 0 |  |  |  |  |  | my @r; | 
| 100 | 0 |  |  |  |  |  | foreach my $el (Net::DRI::Util::xml_list_children($data)) | 
| 101 |  |  |  |  |  |  | { | 
| 102 | 0 |  |  |  |  |  | my ($name,$c)=@$el; | 
| 103 | 0 |  |  |  |  |  | my %r; | 
| 104 | 0 | 0 |  |  |  |  | if ($name eq 'rrec') | 
| 105 |  |  |  |  |  |  | { | 
| 106 | 0 |  |  |  |  |  | foreach my $subel (Net::DRI::Util::xml_list_children($c)) | 
| 107 |  |  |  |  |  |  | { | 
| 108 | 0 |  |  |  |  |  | my ($subname,$subc)=@$subel; | 
| 109 | 0 | 0 |  |  |  |  | if ($subname=~m/^(type|class|ttl|rdata)$/) | 
| 110 |  |  |  |  |  |  | { | 
| 111 | 0 |  |  |  |  |  | $r{$1}=$subc->textContent(); | 
| 112 |  |  |  |  |  |  | } | 
| 113 |  |  |  |  |  |  | } | 
| 114 | 0 |  |  |  |  |  | push @r,\%r; | 
| 115 |  |  |  |  |  |  | } | 
| 116 |  |  |  |  |  |  | } | 
| 117 |  |  |  |  |  |  |  | 
| 118 | 0 |  |  |  |  |  | $rinfo->{domain}->{$oname}->{zone}=\@r; | 
| 119 | 0 |  |  |  |  |  | return; | 
| 120 |  |  |  |  |  |  | } | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | sub domain_update_generate | 
| 123 |  |  |  |  |  |  | { | 
| 124 | 0 |  |  | 0 | 0 |  | my ($epp,$domain,$todo,$rp)=@_; | 
| 125 |  |  |  |  |  |  |  | 
| 126 | 0 | 0 |  |  |  |  | if (grep { ! /^(?:add|del)$/ } $todo->types('zone')) | 
|  | 0 |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | { | 
| 128 | 0 |  |  |  |  |  | Net::DRI::Exception->die(0,'protocol/EPP',11,'Only zone add/del available for domain'); | 
| 129 |  |  |  |  |  |  | } | 
| 130 |  |  |  |  |  |  |  | 
| 131 | 0 |  |  |  |  |  | my $zadd=$todo->add('zone'); | 
| 132 | 0 |  |  |  |  |  | my $zdel=$todo->del('zone'); | 
| 133 | 0 | 0 | 0 |  |  |  | return unless $zadd || $zdel; | 
| 134 |  |  |  |  |  |  |  | 
| 135 | 0 |  |  |  |  |  | my @n; | 
| 136 | 0 | 0 |  |  |  |  | push @n,['zoneMgt:add',_generate_rrecs($zadd)] if $zadd; | 
| 137 | 0 | 0 |  |  |  |  | push @n,['zoneMgt:rem',_generate_rrecs($zdel)] if $zdel; | 
| 138 |  |  |  |  |  |  |  | 
| 139 | 0 |  |  |  |  |  | my $mes=$epp->message(); | 
| 140 | 0 |  |  |  |  |  | my $eid=$mes->command_extension_register('zoneMgt','update'); | 
| 141 | 0 |  |  |  |  |  | $mes->command_extension($eid,\@n); | 
| 142 | 0 |  |  |  |  |  | return; | 
| 143 |  |  |  |  |  |  | } | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | #################################################################################################### | 
| 146 |  |  |  |  |  |  | 1; | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | __END__ |