1## Domain Registry Interface, .NO Domain extensions
2##
3## Copyright (c) 2008-2010 UNINETT Norid AS, E<lt>http://www.norid.noE<gt>,
4##                    Trond Haugen E<lt>info@norid.noE<gt>
5##                    All rights reserved.
6##
7## This file is part of Net::DRI
8##
9## Net::DRI is free software; you can redistribute it and/or modify
10## it under the terms of the GNU General Public License as published by
11## the Free Software Foundation; either version 2 of the License, or
12## (at your option) any later version.
13##
14## See the LICENSE file that comes with this distribution for more details.
15#
16#
17#
18####################################################################################################
19
20package Net::DRI::Protocol::EPP::Extensions::NO::Domain;
21
22use strict;
23use Net::DRI::DRD::NO;
24use Net::DRI::Protocol::EPP::Core::Domain;
25use Net::DRI::Util;
26use Net::DRI::Exception;
27use Net::DRI::Protocol::EPP::Util;
28use Net::DRI::Protocol::EPP::Extensions::NO::Host;
29
30our $VERSION = do { my @r = ( q$Revision: 1.3 $ =~ /\d+/gmx ); sprintf( "%d" . ".%02d" x $#r, @r ); };
31
32=pod
33
34=head1 NAME
35
36Net::DRI::Protocol::EPP::Extensions::NO::Domain - .NO EPP Domain extension commands for Net::DRI
37
38=head1 DESCRIPTION
39
40Please see the README file for details.
41
42=head1 SUPPORT
43
44For now, support questions should be sent to:
45
46E<lt>netdri@dotandco.comE<gt>
47
48Please also see the SUPPORT file in the distribution.
49
50=head1 SEE ALSO
51
52E<lt>http://www.dotandco.com/services/software/Net-DRI/E<gt>
53
54=head1 AUTHOR
55
56Trond Haugen, E<lt>info@norid.noE<gt>
57
58=head1 COPYRIGHT
59
60Copyright (c) 2008-2010 UNINETT Norid AS, E<lt>http://www.norid.noE<gt>,
61Trond Haugen E<lt>info@norid.noE<gt>
62All rights reserved.
63
64This program is free software; you can redistribute it and/or modify
65it under the terms of the GNU General Public License as published by
66the Free Software Foundation; either version 2 of the License, or
67(at your option) any later version.
68
69See the LICENSE file that comes with this distribution for more details.
70
71=cut
72
73####################################################################################################
74
75sub register_commands {
76    my ( $class, $version ) = @_;
77    my %tmp = (
78       check            => [ \&facet, undef ],
79       info             => [ \&facet, undef ],
80       create           => [ \&facet, undef ],
81        transfer_cancel  => [ \&facet, undef ],
82       transfer_query   => [ \&facet, undef ],
83       renew            => [ \&facet, undef ],
84
85       update           => [ \&update, undef ],
86        delete           => [ \&delete,           undef ],
87        transfer_request => [ \&transfer_request, undef ],
88        transfer_execute => [
89            \&transfer_execute,
90            \&Net::DRI::Protocol::EPP::Core::Domain::transfer_parse
91        ],
92        withdraw         => [ \&withdraw, undef ],
93    );
94    return { 'domain' => \%tmp };
95}
96
97####################################################################################################
98
99sub build_command_extension {
100    my ( $mes, $epp, $tag ) = @_;
101
102    return $mes->command_extension_register(
103        $tag,
104        sprintf(
105            'xmlns:no-ext-domain="%s" xsi:schemaLocation="%s %s"',$mes->nsattrs('no_domain')
106        )
107    );
108}
109
110sub facet {
111    my ( $epp, $o, $rd ) = @_;
112
113    return Net::DRI::Protocol::EPP::Extensions::NO::Host::build_facets( $epp, $rd );
114}
115
116sub update {
117    my ( $epp, $domain, $todo ) = @_;
118
119    my $fs = $todo->set('facets');
120    return unless ( defined($fs) && $fs);    # No facets set
121
122    my $rd;
123    $rd->{facets} = $fs;
124    return facet($epp, $domain, $rd);
125}
126
127
128sub delete {
129    my ( $epp, $domain, $rd ) = @_;
130    my $mes = $epp->message();
131
132    my $dfd = $rd->{deletefromdns};
133    my $dfr = $rd->{deletefromregistry};
134    my $fs  = $rd->{facets};
135
136    return unless ( ( defined($dfd) || defined($dfr) || defined($fs) ) && ( $dfd || $dfr || $fs ) );
137
138    my $r;
139    if ( $dfd || $dfr ) {
140       my $eid = build_command_extension( $mes, $epp, 'no-ext-domain:delete' );
141       my @e;
142       push @e, [ 'no-ext-domain:deleteFromDNS', $dfd ] if ( defined($dfd) && $dfd );
143       push @e, [ 'no-ext-domain:deleteFromRegistry', $dfr ] if ( defined($dfr) && $dfr );
144
145       $r = $mes->command_extension( $eid, \@e ) if (@e);
146    }
147    if ($fs) {
148       $r = facet($epp, $domain, $rd);
149    }
150    return $r;
151
152}
153
154
155sub transfer_request {
156    my ( $epp, $domain, $rd ) = @_;
157    my $mes = $epp->message();
158
159    my $mp = $rd->{mobilephone};
160    my $em = $rd->{email};
161    my $fs = $rd->{facets};
162
163    return unless ( ( defined($mp) || defined($em) || defined($fs) ) && ( $mp || $em || $fs) );
164
165    my $r;
166    if ($mp || $em) {
167       my $eid = build_command_extension( $mes, $epp, 'no-ext-domain:transfer' );
168
169       my @d;
170       push @d,
171        Net::DRI::Protocol::EPP::Util::build_tel(
172           'no-ext-domain:mobilePhone', $mp )
173            if ( defined($mp) && $mp );
174       push @d, [ 'no-ext-domain:email', $em ] if ( defined($em) && $em );
175
176       my @e;
177       push @e, [ 'no-ext-domain:notify', @d ];
178       $r = $mes->command_extension( $eid, \@e );
179
180    }
181    if ($fs) {
182       $r = facet($epp, $domain, $rd);
183    }
184
185    return $r;
186
187}
188
189
190sub withdraw {
191    my ( $epp, $domain, $rd ) = @_;
192    my $mes = $epp->message();
193
194    my $transaction;
195    $transaction = $rd->{transactionname} if $rd->{transactionname};
196
197    my $fs = $rd->{facets};
198
199    return unless ( $transaction && $transaction eq 'withdraw');
200
201    Net::DRI::Exception::usererr_insufficient_parameters(
202        'Witdraw command requires a domain name')
203        unless ( defined($domain) && $domain );
204
205    my $r;
206
207    my (undef,$NS,$NSX)=$mes->nsattrs('no_domain');
208    my (undef,$ExtNS,$ExtNSX)=$mes->nsattrs('no_epp');
209
210    my $eid = $mes->command_extension_register( 'command',
211              'xmlns="'
212            . $ExtNS
213            . '" xsi:schemaLocation="'
214            . $ExtNS
215            . " $ExtNSX"
216            . '"' );
217
218    my $cltrid=$mes->cltrid();
219
220    my %domns;
221    $domns{'xmlns:domain'}       = $NS;
222    $domns{'xsi:schemaLocation'} = $NS . " $NSX";
223
224    $r=$mes->command_extension(
225        $eid,
226        [   [   'withdraw',
227                [   'domain:withdraw', [ 'domain:name', $domain ],
228                    \%domns, \%domns
229                ]
230            ],
231            [ 'clTRID', $cltrid ]
232        ]
233       );
234
235    if ( defined($fs) && $fs ) {
236       $r = facet($epp, $domain, $rd);
237    }
238
239    return $r;
240
241}
242
243sub transfer_execute {
244    my ( $epp, $domain, $rd ) = @_;
245    my $mes = $epp->message();
246
247    my $transaction;
248    $transaction = $rd->{transactionname} if $rd->{transactionname};
249
250    return unless ( $transaction && $transaction eq 'transfer_execute' );
251
252    my (undef,$NS,$NSX)=$mes->nsattrs('no_domain');
253    my (undef,$ExtNS,$ExtNSX)=$mes->nsattrs('no_epp');
254
255    my ( $auth, $du, $token, $fs );
256    $auth  = $rd->{auth}     if $rd->{auth};
257    $du    = $rd->{duration} if $rd->{duration};
258    $token = $rd->{token}    if $rd->{token};
259    $fs    = $rd->{facets}   if $rd->{facets};
260
261    # An execute must contain either an authInfo or a token, optionally also a duration
262    Net::DRI::Exception::usererr_insufficient_parameters(
263        'transfer_execute requires either an authInfo or a token')
264        unless ( defined($token) || defined($auth) && ( $token || $auth ) );
265
266    # Duration is optional
267    my $dur;
268    if (   defined($du)
269        && $du
270        && Net::DRI::Util::has_duration( $rd )
271        )
272    {
273        Net::DRI::Util::check_isa( $du, 'DateTime::Duration' );
274
275        Net::DRI::Exception->die( 0, 'DRD::NO', 3, 'Invalid duration' )
276            if Net::DRI::DRD::NO->verify_duration_renew( $du, $domain );
277        $dur = Net::DRI::Protocol::EPP::Util::build_period($du);
278    }
279
280    my $eid = $mes->command_extension_register( 'command',
281              'xmlns="'
282            . $ExtNS
283            . '" xsi:schemaLocation="'
284            . $ExtNS
285            . " $ExtNSX"
286            . '"' );
287
288
289    my $cltrid=$mes->cltrid();
290
291    my %domns;
292    $domns{'xmlns:domain'} = 'urn:ietf:params:xml:ns:domain-1.0';
293    $domns{'xsi:schemaLocation'}
294        = 'urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd';
295
296    my %domns2;
297    $domns2{'xmlns:no-ext-domain'} = $NS;
298    $domns2{'xsi:schemaLocation'}  = $NS . " $NSX";
299
300    my $r;
301
302    if ( Net::DRI::Util::has_auth( $rd )
303        && ( ref( $rd->{auth} ) eq 'HASH' ) )
304    {
305        $r=$mes->command_extension(
306            $eid,
307            [   [   'transfer',
308                    { 'op' => 'execute' },
309                    [   'domain:transfer',
310                        \%domns,
311                        [ 'domain:name', $domain ],
312                        $dur,
313                        Net::DRI::Protocol::EPP::Util::domain_build_authinfo(
314                            $epp, $rd->{auth}
315                        ),
316                    ],
317                ],
318                [ 'clTRID', $cltrid ]
319            ]
320        );
321    } elsif ($token) {
322        $r=$mes->command_extension(
323            $eid,
324            [   [   'transfer',
325                    { 'op' => 'execute' },
326                    [   'domain:transfer', \%domns,
327                        [ 'domain:name', $domain ], $dur,
328                    ],
329                ],
330                [   'extension',
331                    [   'no-ext-domain:transfer', \%domns2,
332                        [ 'no-ext-domain:token', $token ]
333                    ]
334                ],
335                [ 'clTRID', $cltrid ]
336            ]
337        );
338    }
339
340    if ( defined($fs) && $fs ) {
341       $r = facet($epp, $domain, $rd);
342    }
343
344    return $r;
345
346}
347
348####################################################################################################
3491;
350