[Rt-commit] rtir branch, 5.0/fix-net-whois-test-functionality, repushed
Aaron Trevena
ast at bestpractical.com
Mon Jun 29 07:17:27 EDT 2020
The branch 5.0/fix-net-whois-test-functionality was deleted and repushed:
was 67d6ab774acf97d821bcdb6344f29c34c1694109
now 28405d48fa1f43597bd123cdccb4e24960da2ae8
-: ------- > 1: 5cf0332c Hand-parse non-RIPE whois ip lookup response
1: 054c8686 ! 2: b9f3b90d Hand-parse non-RIPE server domain lookup responses
@@ -1,49 +1,13 @@
Author: Aaron Trevena <ast at bestpractical.com>
- Updated whois lookups to hand-parse responses following Net::WHOIS::RIPE
+ Hand-parse non-RIPE server domain lookup responses
- 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
---- a/html/RTIR/Tools/Elements/GetEmailFromIP
-+++ b/html/RTIR/Tools/Elements/GetEmailFromIP
-@@
-
- $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;
+ 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 for
+ responses for ip and dns lookups for servers except ripe.net
+ (https://github.com/arhuman/Net-Whois-RIPE/issues/27) so we parse
+ those responses.
diff --git a/html/RTIR/Tools/Elements/ToolResultsWhois b/html/RTIR/Tools/Elements/ToolResultsWhois
--- a/html/RTIR/Tools/Elements/ToolResultsWhois
@@ -54,29 +18,52 @@
<%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.
++# of this query for any server. The updated API replacing the attributes method call
++# with Net::Whois::Object throws fatal errors for servers other than ripe.net
+# (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";
+- 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;
++ my $content;
++ if ($WhoisServer eq 'whois.ripe.net') {
++ 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 $content = join("\n", ' ', @values);
++</%perl>
++ <b><%$attribute%></b>:
++ <& /Elements/MakeClicky,
++ ticket => $TicketObj,
++ lookup_params => "ticket=" . ($TicketObj ? $TicketObj->id : 0) . "&server=$WhoisServer",
++ content => \$content &>
++ <% $content |n %><br />
++<%perl>
++ }
++ }
++ }
++ else {
++ while ( $WhoisIterator->isnt_exhausted) {
++ my $block = $WhoisIterator->value;
++ $SavedContent .= $block . "\n";
+ my $content = join "", $block;
+ $m->comp('/Elements/MakeClicky',
+ object => $TicketObj,
+@@
+ $DoInvestigate = 1 if $content =~ /Requestorbox/ig;
</%PERL>
<pre><% $content |n %></pre><br />
-% } else {
@@ -112,6 +99,7 @@
- }
-</%perl>
+% }
++% }
+%}
%# Don't offer the option of Investigating to unless there are addresses
% if ( $DoInvestigate ) {
@@ -125,15 +113,3 @@
$WhoisServer => undef
$server => undef
-diff --git a/t/tools/lookup.t b/t/tools/lookup.t
---- a/t/tools/lookup.t
-+++ b/t/tools/lookup.t
-@@
- 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');
-
2: 67d6ab77 < -: ------- Added ip whois lookup test
-: ------- > 3: 28405d48 Add more tests for lookup tool
More information about the rt-commit
mailing list