1#!/usr/bin/perl -w 2# 3# 4# A Net::DRI example for .COOP : creation of contacts, hosts, domains, and deleting domain 5 6use strict; 7 8use Net::DRI; 9use DateTime::Duration; 10 11## Fill these variables : your registrar id, password, and contact prefix 12my $CLID=''; 13my $PASS=''; 14my $CID_PREFIX=''; ## The registry mandates all contacts ID to start with a specific prefix, tied to your account 15 16 17my $dri=Net::DRI->new({cache_ttl=>10,logging=>'files'}); 18 19eval { 20############################################################################################################ 21$dri->add_registry('COOP',{clid=>$CLID}); 22 23## This connects to .COOP server for tests : make sure you have local files key.pem and cert.pem 24my $rc=$dri->target('COOP')->add_current_profile('profile1','epp',{ssl_key_file=>'./key.pem',ssl_cert_file=>'./cert.pem',ssl_ca_file=>'./cert.pem',client_login=>$CLID,client_password=>$PASS}); 25 26die($rc) unless $rc->is_success(); ## Here we catch all errors during setup of transport, such as authentication errors 27 28my $t1=time()%100; 29my $c1=new_contact($dri); ## sponsor 1 30$c1->srid($CID_PREFIX.'1s'.$t1); 31my $c2=new_contact($dri); ## sponsor 2 32$c2->srid($CID_PREFIX.'s'.($t1+1)); 33my $c3=new_contact($dri); 34$c3->srid($CID_PREFIX.'r'.($t1+2)); 35$c3->sponsors([$c1->srid(),$c2->srid()]); ## $c3 will be used as registrant, hence it needs 2 sponsors ! 36$c3->mailing_list(1); 37my $c4=new_contact($dri); 38$c4->srid($CID_PREFIX.'c'.($t1+3)); ## will be used as billing/technical/admin 39$c4->mailing_list(0); 40 41$rc=$dri->contact_create($c1); 42die($rc) unless $rc->is_success(); 43my $id=$dri->get_info('id'); 44print "Contact1 created, id=$id\n"; 45$rc=$dri->contact_create($c2); 46die($rc) unless $rc->is_success(); 47$id=$dri->get_info('id'); 48print "Contact2 created, id=$id\n"; 49$rc=$dri->contact_create($c3); 50die($rc) unless $rc->is_success(); 51$id=$dri->get_info('id'); 52print "Contact3 created, id=$id\n"; 53$rc=$dri->contact_create($c4); 54die($rc) unless $rc->is_success(); 55$id=$dri->get_info('id'); 56print "Contact3 created, id=$id\n"; 57 58 59my $nso=$dri->local_object('hosts'); 60foreach my $ns (qw/ns1.example.com ns2.example.com/) 61{ 62 print "Attempting to create host $ns "; 63 my $e=$dri->host_exist($ns); 64 if ($e==0) 65 { 66 $rc=$dri->host_create($ns); 67 print $rc->is_success()? "OK\n" : "KO\n"; 68 } else 69 { 70 print "EXIST already\n"; 71 } 72 $nso->add($ns); 73} 74 75my $dom='toto-'.time().'.coop'; 76$rc=$dri->domain_check($dom); 77print "$dom exists: ".($dri->get_info('exist')? 'YES' : 'NO')."\n"; 78my $cs=$dri->local_object('contactset'); 79$cs->set($c3,'registrant'); 80$cs->set($c4,'billing'); 81$cs->set($c4,'tech'); 82$cs->set($c4,'admin'); 83print "Attempting to create domain $dom\n"; 84$rc=$dri->domain_create($dom,{pure_create=>1,duration=>DateTime::Duration->new(years =>2),ns=>$nso,contact=>$cs,auth=>{pw=>'whatever'}}); 85print "$dom created successfully:".($rc->is_success()? 'YES' : 'NO')."\n"; 86 87$rc=$dri->domain_check($dom); 88print "$dom does exists now: ".($dri->get_info('exist')? 'YES' : 'NO')."\n"; 89$rc=$dri->domain_info($dom); 90print "$dom domain_info: ".($rc->is_success()? 'YES' : 'NO')."\n"; 91 92$rc=$dri->domain_delete($dom,{pure_delete => 1}); 93print "$dom domain_delete: ".($rc->is_success()? 'YES' : 'NO')."\n"; 94 95$rc=$dri->contact_delete($c3); 96print 'Contact3 deleted successfully: '.($rc->is_success()? 'YES' : 'NO')."\n"; 97$rc=$dri->contact_delete($c1); 98print 'Contact1 deleted successfully: '.($rc->is_success()? 'YES' : 'NO')."\n"; 99$rc=$dri->contact_delete($c2); 100print 'Contact2 deleted successfully: '.($rc->is_success()? 'YES' : 'NO')."\n"; 101$rc=$dri->contact_delete($c4); 102print 'Contact4 deleted successfully: '.($rc->is_success()? 'YES' : 'NO')."\n"; 103 104 105$dri->end(); 106}; 107 108if ($@) 109{ 110 print "\n\nAn EXCEPTION happened !\n"; 111 if (ref($@)) 112 { 113 $@->print(); 114 } else 115 { 116 print($@); 117 } 118} else 119{ 120 print "\n\nNo exception happened, everything seems OK !"; 121} 122 123print "\n"; 124exit 0; 125 126###################################################### 127 128sub new_contact 129{ 130 my ($dri)=@_; 131 my $c=$dri->local_object('contact'); 132 $c->name('My Name'); 133 $c->org('My Organisation àé æ'.time()); 134 $c->street(['My Address']); 135 $c->city('My city'); 136 $c->pc(11111); 137 $c->cc('FR'); 138 $c->email('test@example.com'); 139 $c->voice('+33.1111111'); 140 $c->fax('+33.2222222'); 141 $c->auth({pw => 'whatever'}); 142 $c->lang('fr'); 143 $c->loc2int(); ## registry operator needs internationalized & localized forms (not just internationalized alone) 144 return $c; 145} 146