From c68d0cc35c230a23079a9a9436fa01737d83bc52 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 7 Mar 2015 14:02:52 +0000 Subject: [PATCH] Be more strict about Node Search matching ports/wifi within date range --- Netdisco/Changes | 2 + .../App/Netdisco/Web/Plugin/Search/Node.pm | 44 +++++++++++++++---- Netdisco/lib/App/Netdisco/Web/Search.pm | 3 +- Netdisco/share/views/sidebar/search/node.tt | 9 ++++ 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index ffe1a76e..336a3545 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -8,6 +8,8 @@ [ENHANCEMENTS] * Show page and total records number on DataTables tables + * Be more strict about Node Search matching ports/wifi within date range + * Allow filtering out of Device Ports on Node (MAC) search [BUG FIXES] diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm index 4b199603..f369ad99 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm @@ -25,7 +25,7 @@ ajax '/ajax/content/search/node' => require_login sub { my $mac = NetAddr::MAC->new(mac => $node); my @active = (param('archived') ? () : (-bool => 'active')); - my @times = (); + my (@times, @wifitimes, @porttimes); if ($start and $end) { $start = $start . ' 00:00:00'; $end = $end . ' 23:59:59'; @@ -34,12 +34,28 @@ ajax '/ajax/content/search/node' => require_login sub { time_first => [ { '<', $start }, undef ], time_last => { '>', $end }, ]); + @wifitimes = (-or => [ + time_last => { '<', $start }, + time_last => { '>', $end }, + ]); + @porttimes = (-or => [ + creation => { '<', $start }, + creation => { '>', $end }, + ]); } else { @times = (-and => [ time_first => { '>=', $start }, time_last => { '<=', $end }, ]); + @wifitimes = (-and => [ + time_last => { '>=', $start }, + time_last => { '<=', $end }, + ]); + @porttimes = (-and => [ + creation => { '>=', $start }, + creation => { '<=', $end }, + ]); } } @@ -85,11 +101,8 @@ ajax '/ajax/content/search/node' => require_login sub { join => 'oui' }); - my $ports = schema('netdisco')->resultset('DevicePort') - ->search({ -and => [@where_mac] }); - my $wireless = schema('netdisco')->resultset('NodeWireless')->search( - { -and => [@where_mac] }, + { -and => [@where_mac, @wifitimes] }, { order_by => { '-desc' => 'time_last' }, '+columns' => [ 'oui.company', @@ -101,8 +114,10 @@ ajax '/ajax/content/search/node' => require_login sub { } ); - if ($sightings->has_rows or $ips->has_rows - or $ports->has_rows or $netbios->has_rows) { + my $rs_dp = schema('netdisco')->resultset('DevicePort'); + if ($sightings->has_rows or $ips->has_rows or $netbios->has_rows) { + my $ports = param('deviceports') + ? $rs_dp->search({ -and => [@where_mac] }) : undef; return template 'ajax/search/node_by_mac.tt', { ips => $ips, @@ -112,7 +127,20 @@ ajax '/ajax/content/search/node' => require_login sub { netbios => $netbios, }, { layout => undef }; } + else { + my $ports = param('deviceports') + ? $rs_dp->search({ -and => [@where_mac, @porttimes] }) : undef; + if (defined $ports and $ports->has_rows) { + return template 'ajax/search/node_by_mac.tt', { + ips => $ips, + sightings => $sightings, + ports => $ports, + wireless => $wireless, + netbios => $netbios, + }, { layout => undef }; + } + } my $set = schema('netdisco')->resultset('NodeNbt') ->search_by_name({nbname => $likeval, @active, @times}); @@ -133,7 +161,7 @@ ajax '/ajax/content/search/node' => require_login sub { # if the user selects Vendor search opt, then # we'll try the OUI company name as a fallback - if (not $set->has_rows and param('show_vendor')) { + if (param('show_vendor') and not $set->has_rows) { $set = schema('netdisco')->resultset('NodeIp') ->with_times ->search( diff --git a/Netdisco/lib/App/Netdisco/Web/Search.pm b/Netdisco/lib/App/Netdisco/Web/Search.pm index 72c78010..a2adb106 100644 --- a/Netdisco/lib/App/Netdisco/Web/Search.pm +++ b/Netdisco/lib/App/Netdisco/Web/Search.pm @@ -11,7 +11,8 @@ use NetAddr::MAC (); hook 'before' => sub { # view settings for node options var('node_options' => [ - { name => 'stamps', label => 'Time Stamps', default => 'on' }, + { name => 'stamps', label => 'Time Stamps', default => 'on' }, + { name => 'deviceports', label => 'Device Ports', default => 'on' }, ]); # view settings for device options diff --git a/Netdisco/share/views/sidebar/search/node.tt b/Netdisco/share/views/sidebar/search/node.tt index a73eb989..17a7c25b 100644 --- a/Netdisco/share/views/sidebar/search/node.tt +++ b/Netdisco/share/views/sidebar/search/node.tt @@ -10,6 +10,15 @@ Time Stamps +
+ + +