[Rt-commit] rtir branch, 5.0/fix-net-whois-test-functionality, created. 4.0.1rc1-199-g054c8686

Aaron Trevena ast at bestpractical.com
Tue Jun 23 06:38:09 EDT 2020


The branch, 5.0/fix-net-whois-test-functionality has been created
        at  054c86861a28c84ba9d8acfcefd74b30688182bb (commit)

- Log -----------------------------------------------------------------
commit 054c86861a28c84ba9d8acfcefd74b30688182bb
Author: Aaron Trevena <ast at bestpractical.com>
Date:   Fri Jun 12 11:43:45 2020 +0100

    Updated whois lookups to hand-parse responses following Net::WHOIS::RIPE
    
    Prior to upgrading to Net::Whois::RIPE 2.x we could iterate through attributes for the result of queries.
    The updated API replacing the attributes method call with Net::Whois::Object throws fatal errors on verisign
    responses for ip and dns lookups (https://github.com/arhuman/Net-Whois-RIPE/issues/27) so we parse response here.
    
    Also removed code using Net::Whois::Object in Tools/Lookup.html that was almost never called as the
    handparse flag was defaulted to true, and was never provided as false. check was pretty much always returning true.

diff --git a/html/RTIR/Tools/Elements/GetEmailFromIP b/html/RTIR/Tools/Elements/GetEmailFromIP
index 0d768be7..d92f9215 100644
--- a/html/RTIR/Tools/Elements/GetEmailFromIP
+++ b/html/RTIR/Tools/Elements/GetEmailFromIP
@@ -62,13 +62,26 @@ unless ( $iterator ) {
 
 $field ||= 'notify';
 
-my @objects = Net::Whois::Object->new($iterator);
-my @res;
-foreach my $obj (@objects) {
-    foreach my $attr ( grep lc $_ eq lc $field, $obj->attributes ) {
-        push @res, $obj->$attr();
+# Prior to upgrading to Net::Whois::RIPE 2.x we could iterate through attributes for the result
+# of this query. The updated API replacing the attributes method call with Net::Whois::Object throws
+# fatal errors on verisign responses for ip lookups, so we parse response here.
+# (https://github.com/arhuman/Net-Whois-RIPE/issues/27)
+
+my @res = ( );
+while ( ! $iterator->is_exhausted() ) {
+    foreach my $line ( split /\n/, $iterator->value() ) {
+        # Parse simple "Field: Value" lines in response, ignoring spaces at start
+        # as Net::Whois::Object can't parse and fails with a fatal error
+        if ( $line =~ /^\s*(\S+\s?\S*):\s*(.*)/ ) {
+            my ($attribute, $value) = ($1,$2);
+            next unless (defined($attribute) && $attribute);
+            if (lc $attribute eq lc $field) {
+                push(@res, $value);
+            }
+        }
     }
 }
+
 unless ( @res ) {
     $$error = loc("Whois server response did not include field '[_1]'", $field);
     return;
diff --git a/html/RTIR/Tools/Elements/ToolResultsWhois b/html/RTIR/Tools/Elements/ToolResultsWhois
index 9e7110d3..f8817173 100644
--- a/html/RTIR/Tools/Elements/ToolResultsWhois
+++ b/html/RTIR/Tools/Elements/ToolResultsWhois
@@ -57,53 +57,27 @@
 <b><% $WhoisError %></b>
 % }
 <%PERL>
+
+# Prior to upgrading to Net::Whois::RIPE 2.x we could iterate through attributes for the result
+# of this query. The updated API replacing the attributes method call with Net::Whois::Object throws
+# fatal errors on verisign & other responses for lookups, so we parse response here.
+# (https://github.com/arhuman/Net-Whois-RIPE/issues/27)
+
 my $DoInvestigate = 0;
 if ($WhoisIterator) {
     while ( $WhoisIterator->isnt_exhausted) {
         my $block = $WhoisIterator->value;
         $SavedContent .= $block . "\n";
-        my @lines_starting_with_space = grep /^(\s+)(\w+)/, $block;
-        if ($handparse || $#lines_starting_with_space >= 4) {    #we couldn't parse that. suck
-            my $content = join "", $block;
-            $m->comp('/Elements/MakeClicky',
-                     object        => $TicketObj,
-                     lookup_params => "ticket=" . ($TicketObj ? $TicketObj->id : 0) . "&server=$WhoisServer",
-                     content       => \$content,);
-            $DoInvestigate = 1 if $content =~ /Requestorbox/ig;
+        my $content = join "", $block;
+        $m->comp('/Elements/MakeClicky',
+                 object        => $TicketObj,
+                 lookup_params => "ticket=" . ($TicketObj ? $TicketObj->id : 0) . "&server=$WhoisServer",
+                 content       => \$content,);
+        $DoInvestigate = 1 if $content =~ /Requestorbox/ig;
 </%PERL>
 <pre><% $content |n %></pre><br />
-%       } else {
-Structured RIPE whois data returned.
-Click <a href="Lookup.html?q=<% $q |u %>&server=<% $WhoisServer |u %>&handparse=1">here</a> to manually parse this data.
-<%perl>
-my @objects = Net::Whois::Object->new($WhoisIterator);
-foreach my $object ( @objects ) {
-   my %seen;
-   foreach my $attribute ($object->attributes()) {
-       next if ($seen{$attribute});
-       $seen{$attribute} = 1;
-       my @values;
-       foreach my $value ( $object->$attribute() ) {
-         next unless ($value);
-         push (@values, (ref($value) eq 'ARRAY' ) ? @$value : $value);
-       }
-       next unless (scalar @values);
-       my $value = join("\n", ' ', @values);
-</%perl>
-     <b><%$attribute%></b>: 
-<& /Elements/MakeClicky, 
-    ticket => $TicketObj, 
-    lookup_params => "ticket=".$TicketObj->id, 
-    content => \$value &>
-<% $value |n %><br />
-<%perl>
-     }
-   }
-
-  }
- }
- }
-</%perl>
+%  }
+%}
 %# Don't offer the option of Investigating to unless there are addresses
 % if ( $DoInvestigate ) {
 <& /Elements/Submit,
@@ -136,7 +110,6 @@ foreach my $object ( @objects ) {
 
 <%args>
 $q =>  undef
-$handparse => 1
 $TicketObj => undef
 $WhoisServer => undef
 $server => undef
diff --git a/t/tools/lookup.t b/t/tools/lookup.t
index d62c2dd2..fa86ec81 100644
--- a/t/tools/lookup.t
+++ b/t/tools/lookup.t
@@ -20,7 +20,6 @@ unless ($agent->status == 200){
 diag "Test Lookup page directly";
 {
     $agent->get_ok("/RTIR/Tools/Lookup.html", "Loaded Lookup page");
-
 SKIP:{
     skip "No network", 3 if $no_network;
     $agent->form_name('ToolFormWhois');

-----------------------------------------------------------------------


More information about the rt-commit mailing list