| 1 | # Updated: 11/30/05 by Jeff Mercer <riffer@vaxer.net> | ||
| 2 | # Note: Only tested against corenic.net domain name, so the address | ||
| 3 | # parsing has not been fully tested. May need tweaking. --jcm, 11/30/05 | ||
| 4 | |||
| 5 | package Net::ParseWhois::Domain::Registrar::CoreNic; | ||
| 6 | |||
| 7 | require 5.004; | ||
| 8 | use strict; | ||
| 9 | |||
| 10 | @Net::ParseWhois::Domain::Registrar::CoreNic::ISA = qw(Net::ParseWhois::Domain::Registrar); | ||
| 11 | $Net::ParseWhois::Domain::Registrar::CoreNic::VERSION = 0.2; | ||
| 12 | |||
| 13 | sub rdebug { 0 } | ||
| 14 | sub regex_no_match { 'The requested domain (.*) is available$' } | ||
| 15 | sub regex_domain { '^Domain Name:\s*(.*)$' } | ||
| 16 | sub regex_org_start { '^Domain ID:\s*(.*)$' } | ||
| 17 | sub regex_org { '^Registrant Name:\s*(.*)$' } | ||
| 18 | sub regex_tag { '^Domain ID:\s*(.*)$' } | ||
| 19 | sub regex_address { '^Registrant Address:\s*(.*)$' } | ||
| 20 | sub regex_city { '^Registrant City:\s*(.*)$' } | ||
| 21 | sub regex_state { '^Registrant State/Province:\s*(.*)$' } | ||
| 22 | sub regex_zip { '^Registrant Postal Code:\s*(.*)$' } | ||
| 23 | sub regex_country { '^Registrant Country:\s*(.*)$' } | ||
| 24 | sub regex_admin_start { '^Admin ID:\s*(.*)$' } | ||
| 25 | sub regex_admin { '^Admin .*:\s*(.*)$' } | ||
| 26 | sub regex_tech_start { '^Tech ID:\s*(.*)$' } | ||
| 27 | sub regex_tech { '^Tech .*:\s*(.*)$' } | ||
| 28 | sub regex_zone_start { '^Zone ID:\s*(.*)$' } | ||
| 29 | sub regex_zone { '^Zone .*:\s*(.*)$' } | ||
| 30 | sub regex_created { '^Creation Date:\s*(.*)$' } | ||
| 31 | sub regex_updated { '^Last Modification Date:\s*(.*)$' } | ||
| 32 | sub regex_expires { '^Expiration Date:\s*(.*)$' } | ||
| 33 | sub regex_nserver { '^Name Server:\s*(\S*)$' } | ||
| 34 | sub regex_registrar { '^registrar:\s*(.*)$' } | ||
| 35 | sub my_nameservers_noips { 1 } | ||
| 36 | sub my_contacts { [ qw(Administrative Technical Zone) ] } | ||
| 37 | sub my_data { [ qw(my_contacts my_nameservers_noips regex_no_match regex_domain regex_org_start regex_org regex_tag regex_address regex_city regex_state regex_zip regex_country regex_admin_start regex_tech_start regex_zone_start regex_admin regex_tech regex_zone regex_created regex_updated regex_expires regex_nserver regex_registrar) ] } | ||
| 38 | |||
| 39 | sub parse_text { | ||
| 40 | my $self = shift; | ||
| 41 | my $text = shift; # array ref, one line per element | ||
| 42 | |||
| 43 | $self->dump_text($text) if $self->rdebug; | ||
| 44 | |||
| 45 | $self->parse_start($text); | ||
| 46 | |||
| 47 | return $self; | ||
| 48 | } | ||
| 49 | |||
| 50 | # This should probably all be in parse_text but it seemed nicer to | ||
| 51 | # break it out | ||
| 52 | sub parse_start { | ||
| 53 | my $self = shift; | ||
| 54 | my $text = shift; | ||
| 55 | my $t = shift @{$text}; | ||
| 56 | warn "DEBUG: parse_start() running...\n" if $self->rdebug; | ||
| 57 | |||
| 58 | # Keep going through raw text until we find our starting point | ||
| 59 | warn "DEBUG: Skipping boilerplate\n" if $self->rdebug; | ||
| 60 | until (!defined $t || $t =~ /$self->{'regex_org_start'}/ || | ||
| 61 | $t =~ /$self->{'regex_no_match'}/) { | ||
| 62 | warn "DEBUG: skip t = $t\n" if $self->rdebug; | ||
| 63 | $t = shift @{$text}; | ||
| 64 | } | ||
| 65 | |||
| 66 | warn "DEBUG: skip t = $t\n" if $self->rdebug; | ||
| 67 | warn "DEBUG: Done skipping\n" if $self->rdebug; | ||
| 68 | $self->dump_text if $self->rdebug; | ||
| 69 | |||
| 70 | # the first line should contian regex_no_match or else good data | ||
| 71 | if ($t =~ /$self->{'regex_org_start'}/) { | ||
| 72 | warn "DEBUG: Domain matched\n" if $self->rdebug; | ||
| 73 | $self->{'MATCH'} = 1; | ||
| 74 | $self->{'TAG'} = $1; | ||
| 75 | } else { | ||
| 76 | $self->{'MATCH'} = 0; | ||
| 77 | warn "DEBUG: Matched against regex_no_match\n" if $self->rdebug; | ||
| 78 | return 0; | ||
| 79 | } | ||
| 80 | |||
| 81 | warn "DEBUG: Starting parsing loop...\n" if $self->rdebug; | ||
| 82 | for (@{$text}) { | ||
| 83 | warn "DEBUG: _ = $_\n" if $self->rdebug; | ||
| 84 | |||
| 85 | /$self->{'regex_domain'}/ && do { $self->{'DOMAIN'} = $1; next; }; | ||
| 86 | /$self->{'regex_org'}/ && do { $self->{'NAME'} = $1; next; }; | ||
| 87 | /$self->{'regex_address'}/ && do { | ||
| 88 | push @{$self->{'ADDRESS'}}, $1; next; }; | ||
| 89 | /$self->{'regex_city'}/ && do { | ||
| 90 | push @{$self->{'ADDRESS'}}, $1; next; }; | ||
| 91 | /$self->{'regex_state'}/ && do { | ||
| 92 | ${$self->{'ADDRESS'}}[$#{$self->{'ADDRESS'}}] .= ", $1"; next; }; | ||
| 93 | /$self->{'regex_zip'}/ && do { | ||
| 94 | ${$self->{'ADDRESS'}}[$#{$self->{'ADDRESS'}}] .= " $1"; next; }; | ||
| 95 | /$self->{'regex_country'}/ && do { $self->{'COUNTRY'} = $1; next; }; | ||
| 96 | /$self->{'regex_admin_start'}/ && do { | ||
| 97 | ${$self->{'CONTACTS'}}{uc ${$self->{'my_contacts'}}[0]} | ||
| 98 | = [ $self->parse_contacts($self->{'regex_admin'}, $text) ]; | ||
| 99 | next; }; | ||
| 100 | /$self->{'regex_tech_start'}/ && do { | ||
| 101 | ${$self->{'CONTACTS'}}{uc ${$self->{'my_contacts'}}[1]} | ||
| 102 | = [ $self->parse_contacts($self->{'regex_tech'}, $text) ]; | ||
| 103 | next; }; | ||
| 104 | /$self->{'regex_zone_start'}/ && do { | ||
| 105 | ${$self->{'CONTACTS'}}{uc ${$self->{'my_contacts'}}[2]} | ||
| 106 | = [ $self->parse_contacts($self->{'regex_zone'}, $text) ]; | ||
| 107 | next; }; | ||
| 108 | /$self->{'regex_created'}/ && do { | ||
| 109 | $self->{'RECORD_CREATED'} = $1; next; }; | ||
| 110 | /$self->{'regex_updated'}/ && do { | ||
| 111 | $self->{'RECORD_UPDATED'} = $1; next; }; | ||
| 112 | /$self->{'regex_expires'}/ && do { | ||
| 113 | $self->{'RECORD_EXPIRES'} = $1; next; }; | ||
| 114 | /$self->{'regex_nserver'}/ && do { | ||
| 115 | push @{$self->{'SERVERS'}}, [$1, $self->na]; next; }; | ||
| 116 | } | ||
| 117 | |||
| 118 | warn "DEBUG: parse_start() ending...\n" if $self->rdebug; | ||
| 119 | } | ||
| 120 | |||
| 121 | |||
| 122 | # this goes out and gets the contact info | ||
| 123 | # Only doesn't work that way anymore, so this is completely different now. | ||
| 124 | # --jcm, 11/30/05 | ||
| 125 | sub parse_contacts { | ||
| 126 | my $self = shift; | ||
| 127 | warn "DEBUG: parse_contacts() starting...\n" if $self->rdebug; | ||
| 128 | my $contactid = shift; | ||
| 129 | my $text = shift; | ||
| 130 | my ($t, @cont, $i); | ||
| 131 | |||
| 132 | warn "DEBUG: contactid = $contactid\n" if $self->rdebug; | ||
| 133 | warn "DEBUG: text = $text\n" if $self->rdebug; | ||
| 134 | |||
| 135 | # foreach (@{$text}) { | ||
| 136 | # warn "DEBUG: _ = $_\n" if $self->rdebug; | ||
| 137 | # if (/$contactid/) { push @cont, $1; } | ||
| 138 | # } | ||
| 139 | |||
| 140 | for ($i=0; $i <= $#{$text}; $i++) { | ||
| 141 | if (${$text}[$i] =~ /$contactid/) { | ||
| 142 | push @cont, (split(/: /, ${$text}[$i+1]))[1]; | ||
| 143 | push @cont, (split(/: /, ${$text}[$i+2]))[1]; | ||
| 144 | push @cont, (split(/: /, ${$text}[$i+3]))[1]; | ||
| 145 | push @cont, (split(/: /, ${$text}[$i+4]))[1].", ".(split(/: /, ${$text}[$i+5]))[1]." ".(split(/: /, ${$text}[$i+6]))[1]; | ||
| 146 | push @cont, (split(/: /, ${$text}[$i+7]))[1]; | ||
| 147 | push @cont, "Phone: ".(split(/: /, ${$text}[$i+8]))[1]." FAX: ".(split(/: /, ${$text}[$i+9]))[1]; | ||
| 148 | push @cont, (split(/: /, ${$text}[$i+10]))[1]; | ||
| 149 | |||
| 150 | last; | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | return @cont; | ||
| 155 | } | ||
| 156 | |||
| 157 | 1; |