Revert "Global search by IP address (#11165)" (#11166)

This reverts commit c273ab28af.
This commit is contained in:
Kevin Krumm
2020-02-19 12:35:55 -06:00
committed by GitHub
parent 441262e739
commit c136e1ad6c
2 changed files with 12 additions and 23 deletions

View File

@@ -29,7 +29,7 @@ if (isset($_REQUEST['search'])) {
}
if ($_REQUEST['type'] == 'group') {
foreach (dbFetchRows("SELECT id, name FROM device_groups WHERE name LIKE ?", ["%$search%"]) as $group) {
foreach (dbFetchRows("SELECT id,name FROM device_groups WHERE name LIKE ?", ["%$search%"]) as $group) {
if ($_REQUEST['map']) {
$results[] = array(
'name' => 'g:'.$group['name'],
@@ -50,23 +50,13 @@ if (isset($_REQUEST['search'])) {
} elseif ($_REQUEST['type'] == 'device') {
// Device search
if (Auth::user()->hasGlobalRead()) {
if (\LibreNMS\Util\IPv4::isValid($search, false) || \LibreNMS\Util\IPv6::isValid($search, false)) {
// Device search ip, overwrite_ip, or hostname by address; sort by ip
$results = dbFetchRows(
"SELECT *, inet6_ntoa(`ip`) as `ntoa_ip` FROM `devices` LEFT JOIN `locations` on `locations`.`id` = `devices`.`location_id` WHERE inet6_ntoa(`devices`.`ip`) LIKE ? OR `devices`.`overwrite_ip` LIKE ? OR `devices`.`hostname` LIKE ? ORDER BY `ip`, `hostname` LIMIT ?",
["$search%", "$search%", "$search%", $limit]
);
} else {
// Device search ip, overwrite_ip, hostname, location, sysname, purpose, or notes; sort by hostname
$results = dbFetchRows(
"SELECT *, inet6_ntoa(ip) as `ntoa_ip` FROM `devices` LEFT JOIN `locations` ON `locations`.`id` = `devices`.`location_id` WHERE inet6_ntoa(`devices`.`ip`) LIKE ? OR `devices`.`overwrite_ip` LIKE ? OR `devices`.`hostname` LIKE ? OR `locations`.`location` LIKE ? OR `devices`.`sysName` LIKE ? OR `devices`.`purpose` LIKE ? OR `devices`.`notes` LIKE ? ORDER BY `devices`.`hostname` LIMIT ?",
["%$search%", "%$search%", "%$search%", "%$search%", "%$search%", "%$search%", "%$search%", $limit]
);
}
} else {
// Device search hostname, sysname, or location by non-address for users without global read access
$results = dbFetchRows(
"SELECT *, inet6_ntoa(ip) as `ntoa_ip` FROM `devices` AS `D` LEFT JOIN `locations` ON `locations`.`id` = `D`.`location_id` WHERE $perms_sql AND (D.`hostname` LIKE ? OR D.`sysName` LIKE ? OR `locations`.`location` LIKE ?) ORDER BY hostname LIMIT ?",
"SELECT * FROM `devices` LEFT JOIN `locations` ON `locations`.`id` = `devices`.`location_id` WHERE `devices`.`hostname` LIKE ? OR `locations`.`location` LIKE ? OR `devices`.`sysName` LIKE ? OR `devices`.`purpose` LIKE ? OR `devices`.`notes` LIKE ? ORDER BY `devices`.hostname LIMIT ?",
["%$search%", "%$search%", "%$search%", "%$search%", "%$search%", $limit]
);
} else {
$results = dbFetchRows(
"SELECT * FROM `devices` AS `D` LEFT JOIN `locations` ON `locations`.`id` = `D`.`location_id` WHERE $perms_sql AND (D.`hostname` LIKE ? OR D.`sysName` LIKE ? OR `locations`.`location` LIKE ?) ORDER BY hostname LIMIT ?",
array_merge($device_ids, ["%$search%", "%$search%", "%$search%", $limit])
);
}
@@ -92,6 +82,7 @@ if (isset($_REQUEST['search'])) {
$num_ports = dbFetchCell('SELECT COUNT(*) FROM `ports` AS `I`, `devices` AS `D` WHERE ' . $perms_sql . ' AND `I`.`device_id` = `D`.`device_id` AND `I`.`ignore` = 0 AND `I`.`deleted` = 0 AND `D`.`device_id` = ?', array_merge($device_ids, [$result['device_id']]));
$device[] = array(
'name' => $name,
'device_id' => $result['device_id'],
@@ -100,10 +91,9 @@ if (isset($_REQUEST['search'])) {
'device_ports' => $num_ports,
'device_image' => getIcon($result),
'device_hardware' => $result['hardware'],
'device_os' => \LibreNMS\Config::getOsSetting($result['os'], 'text'),
'device_os' => \LibreNMS\Config::getOsSetting($result['os'], 'text'),
'version' => $result['version'],
'location' => $result['location'],
'device_ip' => $result['ntoa_ip']
);
}//end foreach
}//end if

View File

@@ -582,7 +582,6 @@
device_image: device.device_image,
url: device.url,
name: device.name,
device_ip: device.device_ip,
device_os: device.device_os,
version: device.version,
device_hardware: device.device_hardware,
@@ -663,7 +662,7 @@
valueKey: 'name',
templates: {
header: '<h5><strong>&nbsp;Devices</strong></h5>',
suggestion: Handlebars.compile('<p><a href="@{{url}}"><img src="@{{device_image}}" border="0"> <small><strong>@{{name}}</strong>@{{#if device_ip}} | <i>@{{device_ip}}</i>@{{/if}}@{{#if device_os}} | @{{device_os}}@{{/if}}@{{#if version}} @{{version}}@{{/if}}@{{#if device_hardware}} | @{{device_hardware}}@{{/if}}@{{#if device_ports}} with @{{device_ports}} port(s)@{{/if}}@{{#if location}} | @{{location}}@{{/if}}</small></a></p>')
suggestion: Handlebars.compile('<p><a href="@{{url}}"><img src="@{{device_image}}" border="0"> <small><strong>@{{name}}</strong> | @{{device_os}} | @{{version}} | @{{device_hardware}} with @{{device_ports}} port(s) | @{{location}}</small></a></p>')
}
},
{
@@ -674,7 +673,7 @@
valueKey: 'name',
templates: {
header: '<h5><strong>&nbsp;Ports</strong></h5>',
suggestion: Handlebars.compile('<p><a href="@{{url}}"><small><i class="fa fa-link fa-sm icon-theme" aria-hidden="true"></i> <strong>@{{name}}</strong> - @{{hostname}}@{{#if description}} <i>@{{description}}</i>@{{/if}}</small></a></p>')
suggestion: Handlebars.compile('<p><a href="@{{url}}"><small><i class="fa fa-link fa-sm icon-theme" aria-hidden="true"></i> <strong>@{{name}}</strong> @{{hostname}}<br /><i>@{{description}}</i></small></a></p>')
}
},
{
@@ -685,7 +684,7 @@
valueKey: 'name',
templates: {
header: '<h5><strong>&nbsp;BGP Sessions</strong></h5>',
suggestion: Handlebars.compile('<p><a href="@{{url}}"><small><i class="@{{bgp_image}}" aria-hidden="true"></i> @{{name}} - @{{hostname}} - AS@{{localas}} -> AS@{{remoteas}}</small></a></p>')
suggestion: Handlebars.compile('<p><a href="@{{url}}"><small><i class="@{{bgp_image}}" aria-hidden="true"></i> @{{name}} - @{{hostname}}<br />AS@{{localas}} -> AS@{{remoteas}}</small></a></p>')
}
}).on('typeahead:select', function (ev, suggestion) {
window.location.href = suggestion.url;