#721 redux - Port Search handles VLAN and MAC addr properly
This commit is contained in:
@@ -7,6 +7,9 @@ use Dancer::Plugin::Auth::Extensible;
|
|||||||
use App::Netdisco::Web::Plugin;
|
use App::Netdisco::Web::Plugin;
|
||||||
use App::Netdisco::Util::Web 'sql_match';
|
use App::Netdisco::Util::Web 'sql_match';
|
||||||
|
|
||||||
|
use Regexp::Common 'net';
|
||||||
|
use NetAddr::MAC ();
|
||||||
|
|
||||||
register_search_tab({
|
register_search_tab({
|
||||||
tag => 'port',
|
tag => 'port',
|
||||||
label => 'Port',
|
label => 'Port',
|
||||||
@@ -41,34 +44,38 @@ get '/ajax/content/search/port' => require_login sub {
|
|||||||
send_error( 'Missing query', 400 ) unless $q;
|
send_error( 'Missing query', 400 ) unless $q;
|
||||||
my $rs;
|
my $rs;
|
||||||
|
|
||||||
if ( $q =~ m/^\d+$/ ) {
|
if ($q =~ m/^[0-9]+$/ and $q < 4096) {
|
||||||
$rs
|
$rs = schema('netdisco')->resultset('DevicePort')
|
||||||
= schema('netdisco')->resultset('DevicePort')
|
->columns( [qw/ ip port name up up_admin speed /] )->search({
|
||||||
->columns( [qw/ ip port name up up_admin speed /] )->search({
|
"port_vlans.vlan" => $q,
|
||||||
"port_vlans.vlan" => $q,
|
( param('uplink') ? () : (-or => [
|
||||||
( param('uplink') ? () : (-or => [
|
{-not_bool => "me.is_uplink"},
|
||||||
{-not_bool => "me.is_uplink"},
|
{"me.is_uplink" => undef},
|
||||||
{"me.is_uplink" => undef},
|
]) ),
|
||||||
]) ),
|
( param('ethernet') ? ("me.type" => 'ethernetCsmacd') : () ),
|
||||||
( param('ethernet') ? ("me.type" => 'ethernetCsmacd') : () ),
|
},{ '+columns' => [qw/ device.dns device.name port_vlans.vlan /],
|
||||||
},{ '+columns' => [qw/ device.dns device.name port_vlans.vlan /],
|
join => [qw/ port_vlans device /]
|
||||||
join => [qw/ port_vlans device /]
|
}
|
||||||
}
|
)->with_times;
|
||||||
)->with_times;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my ( $likeval, $likeclause ) = sql_match($q);
|
my ( $likeval, $likeclause ) = sql_match($q);
|
||||||
|
my $mac = NetAddr::MAC->new($q);
|
||||||
|
|
||||||
$rs
|
undef $mac if
|
||||||
= schema('netdisco')->resultset('DevicePort')
|
($mac and $mac->as_ieee
|
||||||
|
and (($mac->as_ieee eq '00:00:00:00:00:00')
|
||||||
|
or ($mac->as_ieee !~ m/$RE{net}{MAC}/)));
|
||||||
|
|
||||||
|
$rs = schema('netdisco')->resultset('DevicePort')
|
||||||
->columns( [qw/ ip port name up up_admin speed /] )
|
->columns( [qw/ ip port name up up_admin speed /] )
|
||||||
->search({
|
->search({
|
||||||
-and => [
|
-and => [
|
||||||
-or => [
|
-or => [
|
||||||
{ "me.name" => ( param('partial') ? $likeclause : $q ) },
|
{ "me.name" => ( param('partial') ? $likeclause : $q ) },
|
||||||
( length $q == 17
|
( ((!defined $mac) or $mac->errstr)
|
||||||
? { "me.mac" => $q }
|
? \[ 'me.mac::text ILIKE ?', $likeval ]
|
||||||
: \[ 'me.mac::text ILIKE ?', $likeval ]
|
: { 'me.mac' => $mac->as_ieee }
|
||||||
),
|
),
|
||||||
( param('uplink') ? (
|
( param('uplink') ? (
|
||||||
{ "me.remote_id" => $likeclause },
|
{ "me.remote_id" => $likeclause },
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ get '/search' => require_login sub {
|
|||||||
->search({
|
->search({
|
||||||
-or => [
|
-or => [
|
||||||
{name => $likeclause},
|
{name => $likeclause},
|
||||||
((!defined $mac or $mac->errstr)
|
(((!defined $mac) or $mac->errstr)
|
||||||
? \['mac::text ILIKE ?', $likeval]
|
? \['mac::text ILIKE ?', $likeval]
|
||||||
: {mac => $mac->as_ieee}),
|
: {mac => $mac->as_ieee}),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user