Commit version 24.12.13800

This commit is contained in:
2025-01-06 17:35:06 -05:00
parent b7f6a79c2c
commit 55d9218816
6133 changed files with 4239740 additions and 1374287 deletions

View File

@ -6,62 +6,70 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
/**
* @var array $config
* @var string $query_permitted_device
* @var string $query_limit
* @var string $query_param
* @var string $queryString
*/
/// SEARCH DEVICES
$where = '(`hostname` LIKE ? OR `sysName` LIKE ? OR `ip` LIKE ? OR `location` LIKE ? OR `sysDescr` LIKE ? OR `os` LIKE ? OR `vendor` LIKE ? OR `purpose` LIKE ?)';
$params = [ $query_param, $query_param, $query_param, $query_param, $query_param, $query_param, $query_param, $query_param ];
$results = dbFetchRows("SELECT * FROM `devices`
WHERE $where $query_permitted_device
ORDER BY `hostname` LIMIT $query_limit", $params);
if (safe_count($results)) {
$max_len = 35;
foreach ($results as $result) {
$where = '(`hostname` LIKE ? OR `sysName` LIKE ? OR `ip` LIKE ? OR `location` LIKE ? OR `sysDescr` LIKE ? OR `os` LIKE ? OR `vendor` LIKE ? OR `purpose` LIKE ? OR `asset_tag` LIKE ?)';
$params = [ $query_param, $query_param, $query_param, $query_param, $query_param, $query_param, $query_param, $query_param, $query_param ];
$sql = "SELECT * FROM `devices`" .
generate_where_clause($where, $GLOBALS['cache']['where']['devices_permitted']) .
" ORDER BY `hostname` LIMIT $query_limit";
$results = dbFetchRows($sql, $params);
if (safe_empty($results)) {
return;
}
$max_len = 35;
foreach ($results as $result) {
humanize_device($result);
$name = truncate($result['hostname'], $max_len);
if ($_SESSION['userlevel'] >= 5 && !safe_empty($result['ip'])) {
$name .= ' ('.$result['ip'].')';
$name .= ' (' . $result['ip'] . ')';
}
$num_ports = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?", [ $result['device_id'] ]);
$num_ports = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?", [$result['device_id']]);
$descr = '';
if ($result['hostname'] != $result['sysName'] && $result['sysName']) {
$descr .= truncate($result['sysName'], $max_len);
$descr .= ' | ';
$descr .= truncate($result['sysName'], $max_len);
$descr .= ' | ';
}
if ($result['location']) {
$descr .= $result['location'] . ' | ';
$descr .= $result['location'] . ' | ';
}
if (strlen($result['purpose'])) {
$descr .= $result['purpose'] . ' | ';
$descr .= $result['purpose'] . ' | ';
}
$device_search_results[] = array(
'url' => generate_device_url($result),
'name' => $name,
'colour' => $result['html_tab_colour'], // FIXME. this colour removed from humanize_device in r6280
'row_class' => $result['row_class'],
if(strlen($result['asset_tag'])) {
$descr .= $result['asset_tag'] . ' | ';
}
$device_search_results[] = [
'url' => generate_device_url($result),
'name' => $name,
'colour' => $result['html_tab_colour'], // FIXME. this colour removed from humanize_device in r6280
'row_class' => $result['row_class'],
'html_row_class' => $result['html_row_class'],
'icon' => get_device_icon($result),
'data' => [
'icon' => get_device_icon($result),
'data' => [
escape_html($result['hardware'] . ' | ' . $config['os'][$result['os']]['text'] . ' ' . $result['version']),
html_highlight(escape_html($descr), $queryString) . $num_ports . ' ports' ],
);
}
$search_results['devices'] = array('descr' => 'Devices found', 'results' => $device_search_results);
html_highlight(escape_html($descr), $queryString) . $num_ports . ' ports'],
];
}
$search_results['devices'] = [ 'descr' => 'Devices found', 'results' => $device_search_results ];
// EOF