Wildcard support on Node name/MAC Search
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
|
||||
[ENHANCEMENTS]
|
||||
|
||||
* Partial search on Device Port MAC address
|
||||
* Wildcard support on Device Port MAC Search
|
||||
* Wildcard support on Node name/MAC Search
|
||||
|
||||
2.024003 - 2014-02-27
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ use NetAddr::IP::Lite ':lower';
|
||||
use Net::MAC ();
|
||||
|
||||
use App::Netdisco::Web::Plugin;
|
||||
use App::Netdisco::Util::Web 'sql_match';
|
||||
|
||||
register_search_tab({ tag => 'node', label => 'Node' });
|
||||
|
||||
@@ -42,21 +43,51 @@ ajax '/ajax/content/search/node' => require_login sub {
|
||||
}
|
||||
}
|
||||
|
||||
if (! $mac->get_error) {
|
||||
my ($likeval, $likeclause) = sql_match($node, not param('partial'));
|
||||
my $using_wildcards = (($likeval ne $node) ? 1 : 0);
|
||||
|
||||
my @where_mac =
|
||||
($using_wildcards ? \['me.mac::text ILIKE ?', $likeval]
|
||||
: ($mac->get_error ? \'0=1' : ('me.mac' => $mac->as_IEEE)) );
|
||||
|
||||
my $sightings = schema('netdisco')->resultset('Node')
|
||||
->search_by_mac({mac => $mac->as_IEEE, @active, @times});
|
||||
->search({-and => [@where_mac, @active, @times]}, {
|
||||
order_by => {'-desc' => 'time_last'},
|
||||
'+columns' => [
|
||||
'device.dns',
|
||||
{ time_first_stamp => \"to_char(time_first, 'YYYY-MM-DD HH24:MI')" },
|
||||
{ time_last_stamp => \"to_char(time_last, 'YYYY-MM-DD HH24:MI')" },
|
||||
],
|
||||
join => 'device',
|
||||
});
|
||||
|
||||
my $ips = schema('netdisco')->resultset('NodeIp')
|
||||
->search_by_mac({mac => $mac->as_IEEE, @active, @times});
|
||||
->search({-and => [@where_mac, @active, @times]}, {
|
||||
order_by => {'-desc' => 'time_last'},
|
||||
'+columns' => [
|
||||
'oui.company',
|
||||
{ time_first_stamp => \"to_char(time_first, 'YYYY-MM-DD HH24:MI')" },
|
||||
{ time_last_stamp => \"to_char(time_last, 'YYYY-MM-DD HH24:MI')" },
|
||||
],
|
||||
join => 'oui'
|
||||
});
|
||||
|
||||
my $netbios = schema('netdisco')->resultset('NodeNbt')
|
||||
->search_by_mac({mac => $mac->as_IEEE, @active, @times});
|
||||
->search({-and => [@where_mac, @active, @times]}, {
|
||||
order_by => {'-desc' => 'time_last'},
|
||||
'+columns' => [
|
||||
'oui.company',
|
||||
{ time_first_stamp => \"to_char(time_first, 'YYYY-MM-DD HH24:MI')" },
|
||||
{ time_last_stamp => \"to_char(time_last, 'YYYY-MM-DD HH24:MI')" },
|
||||
],
|
||||
join => 'oui'
|
||||
});
|
||||
|
||||
my $ports = schema('netdisco')->resultset('DevicePort')
|
||||
->search({mac => $mac->as_IEEE});
|
||||
->search({ -and => [@where_mac] });
|
||||
|
||||
my $wireless = schema('netdisco')->resultset('NodeWireless')->search(
|
||||
{ mac => $mac->as_IEEE },
|
||||
{ -and => [@where_mac] },
|
||||
{ order_by => { '-desc' => 'time_last' },
|
||||
'+columns' => [
|
||||
{
|
||||
@@ -65,12 +96,10 @@ ajax '/ajax/content/search/node' => require_login sub {
|
||||
}
|
||||
);
|
||||
|
||||
return unless $sightings->has_rows
|
||||
or $ips->has_rows
|
||||
or $ports->has_rows
|
||||
or $netbios->has_rows;
|
||||
if ($sightings->has_rows or $ips->has_rows
|
||||
or $ports->has_rows or $netbios->has_rows) {
|
||||
|
||||
template 'ajax/search/node_by_mac.tt', {
|
||||
return template 'ajax/search/node_by_mac.tt', {
|
||||
ips => $ips,
|
||||
sightings => $sightings,
|
||||
ports => $ports,
|
||||
@@ -78,15 +107,10 @@ ajax '/ajax/content/search/node' => require_login sub {
|
||||
netbios => $netbios,
|
||||
}, { layout => undef };
|
||||
}
|
||||
else {
|
||||
my $set;
|
||||
my $name = $node;
|
||||
|
||||
if (param('partial')) {
|
||||
$name = "\%$name\%" if $name !~ m/%/;
|
||||
}
|
||||
|
||||
$set = schema('netdisco')->resultset('NodeNbt')
|
||||
my $name = (param('partial') ? $likeval : $node);
|
||||
my $set = schema('netdisco')->resultset('NodeNbt')
|
||||
->search_by_name({nbname => $name, @active, @times});
|
||||
|
||||
unless ( $set->has_rows ) {
|
||||
@@ -96,13 +120,11 @@ ajax '/ajax/content/search/node' => require_login sub {
|
||||
->search_by_ip({ip => $ip, @active, @times});
|
||||
}
|
||||
else {
|
||||
if ($name !~ m/%/ and setting('domain_suffix')) {
|
||||
$name .= setting('domain_suffix')
|
||||
if index($name, setting('domain_suffix')) == -1;
|
||||
}
|
||||
$likeval .= setting('domain_suffix')
|
||||
if index($node, setting('domain_suffix')) == -1;
|
||||
|
||||
$set = schema('netdisco')->resultset('NodeIp')
|
||||
->search_by_dns({dns => $name, @active, @times});
|
||||
->search_by_dns({dns => $likeval, @active, @times});
|
||||
|
||||
# if the user selects Vendor search opt, then
|
||||
# we'll try the OUI company name as a fallback
|
||||
@@ -111,7 +133,7 @@ ajax '/ajax/content/search/node' => require_login sub {
|
||||
$set = schema('netdisco')->resultset('NodeIp')
|
||||
->with_times
|
||||
->search(
|
||||
{'oui.company' => { -ilike => "\%$node\%"}, @times},
|
||||
{'oui.company' => { -ilike => ''.sql_match($node)}, @times},
|
||||
{'prefetch' => 'oui'},
|
||||
);
|
||||
}
|
||||
@@ -125,7 +147,6 @@ ajax '/ajax/content/search/node' => require_login sub {
|
||||
macs => $set,
|
||||
archive_filter => {@active},
|
||||
}, { layout => undef };
|
||||
}
|
||||
};
|
||||
|
||||
true;
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
name="partial"[% ' checked="checked"' IF params.partial %]/>
|
||||
</label>
|
||||
<label class="nd_checkboxlabel" for="node_partial">
|
||||
<span class="nd_searchcheckbox uneditable-input">Partial Name</span>
|
||||
<span class="nd_searchcheckbox uneditable-input">Partial Match</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="clearfix">
|
||||
|
||||
Reference in New Issue
Block a user