1 package FS::part_export::domreg_opensrs;
3 use vars qw(@ISA %info %options $conf);
5 use FS::Record qw(qsearchs qsearch);
7 use FS::part_export::null;
14 FS::part_export::domreg_opensrs - Register or transfer domains with Tucows OpenSRS
18 This module handles registering and transferring domains using a registration service provider (RSP) account
19 at Tucows OpenSRS, an ICANN-approved domain registrar.
21 As a part_export, this module can be designated for use with svc_domain services. When the svc_domain object
22 is inserted into the Freeside database, registration or transferring of the domain may be initiated, depending
23 on the setting of the svc_domain's action field.
27 =item N - Register the domain
29 =item M - Transfer the domain
31 =item I - Ignore the domain for registration purposes
37 @ISA = qw(FS::part_export::null);
39 my @tldlist = qw/com net org biz info name mobi at be ca cc ch cn de dk es eu fr it mx nl tv uk us/;
41 tie %options, 'Tie::IxHash',
42 'username' => { label => 'Reseller user name at OpenSRS',
44 'privatekey' => { label => 'Private key',
46 'password' => { label => 'Password for management account',
48 'masterdomain' => { label => 'Master domain at OpenSRS',
50 'debug_level' => { label => 'Net::OpenSRS debug level',
52 options => [ 0, 1, 2, 3 ],
54 'register' => { label => 'Use for registration',
57 'transfer' => { label => 'Use for transfer',
60 'tlds' => { label => 'Use this export for these top-level domains (TLDs)',
63 size => scalar(@tldlist),
64 options => [ @tldlist ],
65 default => 'com net org' },
69 'svc' => 'svc_domain',
70 'desc' => 'Domain registration via Tucows OpenSRS',
71 'options' => \%options,
73 Registers and transfers domains via the <a href="http://opensrs.com/">Tucows OpenSRS</a> registrar (using <a href="http://search.cpan.org/dist/Net-OpenSRS">Net::OpenSRS</a>).
74 All of the Net::OpenSRS restrictions apply:
76 <LI>You must have a reseller account with Tucows.
77 <LI>You must add the public IP address of the Freeside server to the 'Script API allow' list in the OpenSRS web interface.
78 <LI>You must generate an API access key in the OpenSRS web interface and enter it below.
79 <LI>All domains are managed using the same user name and password, but you can create sub-accounts for clients.
80 <LI>The user name must be the same as your OpenSRS reseller ID.
81 <LI>You must enter a master domain that all other domains are associated with. That domain must be registered through your OpenSRS account.
83 Some top-level domains offered by OpenSRS have additional business rules not supported by this export. These TLDs cannot be registered or transfered with this export.
84 <BR><BR>Use these buttons for some useful presets:
87 <INPUT TYPE="button" VALUE="OpenSRS Live System (rr-n1-tor.opensrs.net)" onClick='
88 document.dummy.machine.value = "rr-n1-tor.opensrs.net";
89 this.form.machine.value = "rr-n1-tor.opensrs.net";
92 <INPUT TYPE="button" VALUE="OpenSRS Test System (horizon.opensrs.net)" onClick='
93 document.dummy.machine.value = "horizon.opensrs.net";
94 this.form.machine.value = "horizon.opensrs.net";
100 install_callback FS::UID sub {
101 $conf = new FS::Conf;
110 Reformats a phone number according to registry rules. Currently Freeside stores phone numbers
111 in NANPA format and the registry prefers "+CCC.NPANPXNNNN"
118 #if ($tel =~ /^(\d{3})-(\d{3})-(\d{4})( x(\d+))?$/) {
119 if ($tel =~ /^(\d{3})-(\d{3})-(\d{4})$/) {
121 # if $tel .= "$4" if $4;
130 my @invoicing_list = $co->invoicing_list_emailonly;
131 if ( $conf->exists('emailinvoiceautoalways')
132 || $conf->exists('emailinvoiceauto') && ! @invoicing_list
133 || ( $conf->exists('emailinvoiceonly') && ! @invoicing_list ) ) {
134 push @invoicing_list, $co->all_emails;
137 my $email = ($conf->exists('business-onlinepayment-email-override'))
138 ? $conf->config('business-onlinepayment-email-override')
139 : $invoicing_list[0];
142 firstname => $co->first,
143 lastname => $co->last,
144 company => $co->company,
145 address => $co->address1,
147 state => $co->state(),
149 country => uc($co->country()),
151 #phone => format_tel($co->daytime()),
152 phone => $co->daytime() || $co->night,
160 return 'live' if $self->machine eq "rr-n1-tor.opensrs.net";
161 return 'test' if $self->machine eq "horizon.opensrs.net";
166 my( $self, $svc_domain ) = ( shift, shift );
168 return if $svc_domain->action eq 'I'; # Ignoring registration, just doing DNS
170 # Get the TLD of the new domain
171 my @bits = split /\./, $svc_domain->domain;
173 return "Can't register subdomains: " . $svc_domain->domain if scalar(@bits) != 2;
177 # See if it's one this export supports
178 my @tlds = split /\s+/, $self->option('tlds');
179 @tlds = map { s/\.//; $_ } @tlds;
180 return "Can't register top-level domain $tld, restricted to: " . $self->option('tlds') if ! grep { $_ eq $tld } @tlds;
182 my $cust_main = $svc_domain->cust_svc->cust_pkg->cust_main;
184 my $c = gen_contact_info($cust_main);
186 my $srs = Net::OpenSRS->new();
188 $srs->debug_level( $self->option('debug_level') ); # Output should be in the Apache error log
190 $srs->environment( $self->testmode() );
191 $srs->set_key( $self->option('privatekey') );
193 $srs->set_manage_auth( $self->option('username'), $self->option('password') );
195 my $cookie = $srs->get_cookie( $self->option('masterdomain') );
197 return "Unable to get cookie at OpenSRS: " . $srs->last_response();
200 if ($svc_domain->action eq 'N') {
201 return "Domain registration not enabled" if !$self->option('register');
202 return $srs->last_response() if !$srs->register_domain( $svc_domain->domain, $c);
203 } elsif ($svc_domain->action eq 'M') {
204 return "Domain transfer not enabled" if !$self->option('transfer');
205 return $srs->last_response() if !$srs->transfer_domain( $svc_domain->domain, $c);
207 return "Unknown domain action " . $svc_domain->action;
210 return ''; # Should only get here if register or transfer succeeded
214 ## Domain registration exports do nothing on replace. Mainly because we haven't decided what they should do.
215 #sub _export_replace {
216 # my( $self, $new, $old ) = (shift, shift, shift);
222 ## Domain registration exports do nothing on delete. You're just removing the domain from Freeside, not the registry
223 #sub _export_delete {
224 # my( $self, $svc_domain ) = ( shift, shift );
239 L<FS::part_export_option>, L<FS::export_svc>, L<FS::svc_domain>,
240 L<FS::Record>, schema.html from the base documentation.