X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=lib%2FNet%2FOpenSRS.pm;h=40f83d39d229df37fbcb546c31eee4c1c2fa9820;hb=HEAD;hp=f1db5bf5973fee21d24a911aef0b6b893d77e84d;hpb=498afdeac8e04c3fb4314bc2a90f29c5a88a1bcc;p=Net-OpenSRS.git diff --git a/lib/Net/OpenSRS.pm b/lib/Net/OpenSRS.pm index f1db5bf..40f83d3 100644 --- a/lib/Net/OpenSRS.pm +++ b/lib/Net/OpenSRS.pm @@ -150,7 +150,7 @@ use XML::Simple; use Digest::MD5; use Date::Calc qw/ Add_Delta_Days Today This_Year /; -our $VERSION = '0.04'; +our $VERSION = '0.07_01'; my $rv; *hash = \&Digest::MD5::md5_hex; @@ -636,259 +636,10 @@ sub register_domain return undef; } - my $epp_phone = $c->{phone}; - $epp_phone =~ s/[\.\-]//g; - $epp_phone = '+1.' . $epp_phone; - - # blah, this sucks. - # it would be really nice if OpenSRS figured out the country -> code - # conversion on their end of things. - my %country_codes = ( - 'Afghanistan' => 'AF', - 'Albania' => 'AL', - 'Algeria' => 'DZ', - 'American Samoa' => 'AS', - 'Andorra' => 'AD', - 'Angola' => 'AO', - 'Anguilla' => 'AI', - 'Antarctica' => 'AQ', - 'Antigua And Barbuda' => 'AG', - 'Argentina' => 'AR', - 'Armenia' => 'AM', - 'Aruba' => 'AW', - 'Australia' => 'AU', - 'Austria' => 'AT', - 'Azerbaijan' => 'AZ', - 'Bahamas' => 'BS', - 'Bahrain' => 'BH', - 'Bangladesh' => 'BD', - 'Barbados' => 'BB', - 'Belarus' => 'BY', - 'Belgium' => 'BE', - 'Belize' => 'BZ', - 'Benin' => 'BJ', - 'Bermuda' => 'BM', - 'Bhutan' => 'BT', - 'Bolivia' => 'BO', - 'Bosnia Hercegovina' => 'BA', - 'Botswana' => 'BW', - 'Bouvet Island' => 'BV', - 'Brazil' => 'BR', - 'British Indian Ocean Territory' => 'IO', - 'Brunei Darussalam' => 'BN', - 'Bulgaria' => 'BG', - 'Burkina Faso' => 'BF', - 'Burundi' => 'BI', - 'Cambodia' => 'KH', - 'Cameroon' => 'CM', - 'Canada' => 'CA', - 'Cape Verde' => 'CV', - 'Cayman Islands' => 'KY', - 'Central African Republic' => 'CF', - 'Chad' => 'TD', - 'Chile' => 'CL', - 'China' => 'CN', - 'Christmas Island' => 'CX', - 'Cocos (Keeling) Islands' => 'CC', - 'Colombia' => 'CO', - 'Comoros' => 'KM', - 'Congo' => 'CG', - 'Congo The Democratic Republic Of' => 'CD', - 'Cook Islands' => 'CK', - 'Costa Rica' => 'CR', - 'Cote D\'Ivoire' => 'CI', - 'Croatia' => 'HR', - 'Cuba' => 'CU', - 'Cyprus' => 'CY', - 'Czech Republic' => 'CZ', - 'Denmark' => 'DK', - 'Djibouti' => 'DJ', - 'Dominica' => 'DM', - 'Dominican Republic' => 'DO', - 'Ecuador' => 'EC', - 'Egypt' => 'EG', - 'El Salvador' => 'SV', - 'Equatorial Guinea' => 'GQ', - 'Eritrea' => 'ER', - 'Estonia' => 'EE', - 'Ethiopia' => 'ET', - 'Falkland Islands (Malvinas)' => 'FK', - 'Faroe Islands' => 'FO', - 'Fiji' => 'FJ', - 'Finland' => 'FI', - 'France' => 'FR', - 'French Guiana' => 'GF', - 'French Polynesia' => 'PF', - 'French Southern Territories' => 'TF', - 'Gabon' => 'GA', - 'Gambia' => 'GM', - 'Georgia' => 'GE', - 'Germany' => 'DE', - 'Ghana' => 'GH', - 'Gibraltar' => 'GI', - 'Greece' => 'GR', - 'Greenland' => 'GL', - 'Grenada' => 'GD', - 'Guadeloupe' => 'GP', - 'Guam' => 'GU', - 'Guatemela' => 'GT', - 'Guinea' => 'GN', - 'Guinea-Bissau' => 'GW', - 'Guyana' => 'GY', - 'Haiti' => 'HT', - 'Heard and McDonald Islands' => 'HM', - 'Honduras' => 'HN', - 'Hong Kong' => 'HK', - 'Hungary' => 'HU', - 'Iceland' => 'IS', - 'India' => 'IN', - 'Indonesia' => 'ID', - 'Iran (Islamic Republic Of)' => 'IR', - 'Iraq' => 'IQ', - 'Ireland' => 'IE', - 'Israel' => 'IL', - 'Italy' => 'IT', - 'Jamaica' => 'JM', - 'Japan' => 'JP', - 'Jordan' => 'JO', - 'Kazakhstan' => 'KZ', - 'Kenya' => 'KE', - 'Kiribati' => 'KI', - 'Korea, Democratic People\'s Republic Of' => 'KP', - 'Korea, Republic Of' => 'KR', - 'Kuwait' => 'KW', - 'Kyrgyzstan' => 'KG', - 'Lao People\'s Democratic Republic' => 'LA', - 'Latvia' => 'LV', - 'Lebanon' => 'LB', - 'Lesotho' => 'LS', - 'Liberia' => 'LR', - 'Libyan Arab Jamahiriya' => 'LY', - 'Liechtenstein' => 'LI', - 'Lithuania' => 'LT', - 'Luxembourg' => 'LU', - 'Macau' => 'MO', - 'Macedonia' => 'MK', - 'Madagascar' => 'MG', - 'Malawi' => 'MW', - 'Malaysia' => 'MY', - 'Maldives' => 'MV', - 'Mali' => 'ML', - 'Malta' => 'MT', - 'Marshall Islands' => 'MH', - 'Martinique' => 'MQ', - 'Mauritania' => 'MR', - 'Mauritius' => 'MU', - 'Mayotte' => 'YT', - 'Mexico' => 'MX', - 'Micronesia, Federated States Of' => 'FM', - 'Moldova, Republic Of' => 'MD', - 'Monaco' => 'MC', - 'Mongolia' => 'MN', - 'Montserrat' => 'MS', - 'Morocco' => 'MA', - 'Mozambique' => 'MZ', - 'Myanmar' => 'MM', - 'Namibia' => 'NA', - 'Nauru' => 'NR', - 'Nepal' => 'NP', - 'Netherlands' => 'NL', - 'Netherlands Antilles' => 'AN', - 'New Caledonia' => 'NC', - 'New Zealand' => 'NZ', - 'Nicaragua' => 'NI', - 'Niger' => 'NE', - 'Nigeria' => 'NG', - 'Niue' => 'NU', - 'Norfolk Island' => 'NF', - 'Northern Mariana Islands' => 'MP', - 'Norway' => 'NO', - 'Oman' => 'OM', - 'Pakistan' => 'PK', - 'Palau' => 'PW', - 'Palestine' => 'PS', - 'Panama' => 'PA', - 'Papua New Guinea' => 'PG', - 'Paraguay' => 'PY', - 'Peru' => 'PE', - 'Philippines' => 'PH', - 'Pitcairn' => 'PN', - 'Poland' => 'PL', - 'Portugal' => 'PT', - 'Puerto Rico' => 'PR', - 'Qatar' => 'QA', - 'Reunion' => 'RE', - 'Romania' => 'RO', - 'Russian Federation' => 'RU', - 'Rwanda' => 'RW', - 'Saint Helena' => 'SH', - 'Saint Kitts And Nevis' => 'KN', - 'Saint Lucia' => 'LC', - 'Saint Pierre and Miquelon' => 'PM', - 'Saint Vincent and The Grenadines' => 'VC', - 'Samoa' => 'WS', - 'San Marino' => 'SM', - 'Sao Tome and Principe' => 'ST', - 'Saudi Arabia' => 'SA', - 'Senegal' => 'SN', - 'Serbia and Montenegro' => 'CS', - 'Seychelles' => 'SC', - 'Sierra Leone' => 'SL', - 'Singapore' => 'SG', - 'Slovakia' => 'SK', - 'Slovenia' => 'SI', - 'Solomon Islands' => 'SB', - 'Somalia' => 'SO', - 'South Africa' => 'ZA', - 'South Georgia and The Sandwich Islands' => 'GS', - 'Spain' => 'ES', - 'Sri Lanka' => 'LK', - 'Sudan' => 'SD', - 'Suriname' => 'SR', - 'Svalbard and Jan Mayen Islands' => 'SJ', - 'Swaziland' => 'SZ', - 'Sweden' => 'SE', - 'Switzerland' => 'CH', - 'Syrian Arab Republic' => 'SY', - 'Taiwan' => 'TW', - 'Tajikista' => 'TJ', - 'Tanzania, United Republic Of' => 'TZ', - 'Thailand' => 'TH', - 'Timor-Leste' => 'TL', - 'Togo' => 'TG', - 'Tokelau' => 'TK', - 'Tonga' => 'TO', - 'Trinidad and Tobago' => 'TT', - 'Tunisia' => 'TN', - 'Turkey' => 'TR', - 'Turkmenistan' => 'TM', - 'Turks and Caicos Islands' => 'TC', - 'Tuvalu' => 'TV', - 'Uganda' => 'UG', - 'Ukraine' => 'UA', - 'United Arab Emirates' => 'AE', - 'United Kingdom (GB)' => 'GB', - 'United Kingdom (UK)' => 'UK', - 'United States' => 'US', - 'United States Minor Outlying Islands' => 'UM', - 'Uruguay' => 'UY', - 'Uzbekistan' => 'UZ', - 'Vanuatu' => 'VU', - 'Vatican City State' => 'VA', - 'Venezuela' => 'VE', - 'Vietnam' => 'VN', - 'Virgin Islands (British)' => 'VG', - 'Virgin Islands (U.S.)' => 'VI', - 'Wallis and Futuna Islands' => 'WF', - 'Western Sahara' => 'EH', - 'Yemen Republic of' => 'YE', - 'Zambia' => 'ZM', - 'Zimbabwe' => 'ZW' - ); # end suckage - # attempt countryname translation if needed if ( $c->{country} !~ m/^[A-Z]{2,3}$/ ) { - $c->{country} = $country_codes{$c->{country}}; + require Locales; + $c->{country} = uc( Locales->new->get_code_from_territory($c->{country}) ); unless ( defined( $c->{country} ) ) { $self->debug("Invalid country."); @@ -896,30 +647,37 @@ sub register_domain } } + my $epp_phone = _parse_phone($c->{phone}); + unless ( defined( $epp_phone ) ) { + $self->debug("Invalid phone number."); + return undef; + } + # build contact hashref from customer info. my $contact_info = { - first_name => $c->{firstname}, - last_name => $c->{lastname}, + first_name => $c->{first_name} || $c->{firstname}, + last_name => $c->{last_name} || $c->{lastname}, city => $c->{city}, state => $c->{state}, country => $c->{country}, - address1 => $c->{address}, - postal_code => $c->{zip}, + address1 => $c->{address1} || $c->{address}, + $c->{address2} ? ( address2 => $c->{address2} ) : (), + postal_code => $c->{postal_code} || $c->{zip}, email => $c->{email}, phone => $epp_phone, - org_name => $c->{company} || 'n/a', + org_name => $c->{org_name} || $c->{company} || 'n/a', }; - $rv = $self->make_request( - { + my $hashref = { action => 'sw_register', object => 'domain', attributes => { domain => $domain, - custom_nameservers => 0, + custom_nameservers => exists $c->{nameserver_list} ? 1 : 0, + exists $c->{nameserver_list} ? ( nameserver_list => $c->{nameserver_list} ) : (), custom_tech_contact => 0, - auto_renew => 0, - period => 1, + auto_renew => $c->{auto_renew} || 0, + period => $c->{period} || 1, f_lock_domain => 1, contact_set => { admin => $contact_info, @@ -931,8 +689,18 @@ sub register_domain reg_type => $transfer ? 'transfer' : 'new', reg_domain => $self->{config}->{master_domain}, # link domain to the 'master' account } - } - ); + }; + + if ( $domain =~ /\.au$/ ) { + $hashref->{'attributes'}->{'custom_tech_contact'} = 1; + $hashref->{'attributes'}->{'contact_set'}->{'tech'} = $contact_info; + my $au_registrant_info = { 'registrant_name' => $c->{'registrant_name'}, + 'eligibility_type' => $c->{'eligibility_type'}, + }; + $hashref->{'attributes'}->{'tld_data'}->{'au_registrant_info'} = $au_registrant_info; + } + + $rv = $self->make_request($hashref); $self->_set_response; return $rv->{is_success}; } @@ -1194,6 +962,24 @@ XML return $self->last_response(1); } +# encode special characters + +my %encode_hash = ( + '<' => '<', + '>' => '>', + "'" => ''', + '"' => '"', + '&' => '&', +); + +sub _encode +{ + my $arg = shift; + return $arg unless ($arg =~/\<|\>|\'|\"|\&/); + $arg =~ s/(\<|\>|\'|\"|\&)/$encode_hash{$1}/ge; + $arg +} + # format perl structs into opensrs XML sub _format { @@ -1207,8 +993,11 @@ sub _format my $c = 0; $xml .= "$sp\n"; $xml .= "$sp \n"; - foreach (sort @$val) { - $xml .= "$sp $_\n"; + foreach (map { _encode($_) } sort @$val) { +# $xml .= "$sp $_\n"; + $xml .= "$sp \n"; + $xml .= $self->_format($_); + $xml .= "$sp \n"; $c++; } $xml .= "$sp \n"; @@ -1216,16 +1005,17 @@ sub _format } elsif ( ref $val eq 'HASH' ) { - $xml .= "$sp\n"; + $xml .= "$sp\n" unless /^HASH/; $xml .= "$sp\n"; foreach (sort keys %$val) { $xml .= $self->_format( $val->{$_} ); } $xml .= "$sp\n"; - $xml .= "$sp\n"; + $xml .= "$sp\n" unless /^HASH/; } else { + $val = _encode($val); $xml .= "$sp$val\n"; } @@ -1254,20 +1044,40 @@ sub _denastify { @$array ]; } elsif ( exists( $arg->{dt_assoc} ) ) { - $value = { map { _denastify($_) } @{ $arg->{dt_assoc} } }; + my $array = $arg->{dt_assoc}; + $array = [ $array ] unless ref($array) eq 'ARRAY'; + $value = { map { _denastify($_) } @$array }; } return ( $arg->{key} => $value ); } (); } +sub _parse_phone { + require Number::Phone; + my ($phone) = shift; + my ($country, $idd) = Number::Phone::Country::phone2country_and_idd($phone); + return undef unless $country; + my $np = Number::Phone->new($phone); + $np = Number::Phone->new($country, $phone) unless defined $np; + return undef unless defined $np; + (my $epp = $np->format) =~ s/\s+/\./; + $epp =~ s/\s+//g; + return $epp; +} + =back =head1 Author -Mahlon E. Smith I for Spime Solutions Group +Original author: Mahlon E. Smith I for Spime Solutions Group I<(www.spime.net)> +Contributors: Sten Spans, Jeff Finucane and Richard Siddall for Freeside +Internet Services I<(www.freeside.biz)>, Justin Hunter. + +Current maintainer: Ivan Kohler + =cut 1;