Commit version 24.12.13800
This commit is contained in:
@ -6,36 +6,38 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
/// SEARCH ACCESSPOINTS
|
||||
$results = dbFetchRows("SELECT * FROM `wifi_aps`
|
||||
WHERE `ap_name` LIKE ? $query_permitted_device
|
||||
ORDER BY `ap_name` LIMIT $query_limit", array($query_param));
|
||||
$results = dbFetchRows("SELECT * FROM `wifi_aps`" .
|
||||
generate_where_clause('`ap_name` LIKE ?', $GLOBALS['cache']['where']['devices_permitted']) .
|
||||
" ORDER BY `ap_name` LIMIT $query_limit", [ $query_param ]);
|
||||
|
||||
if (!safe_empty($results)) {
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
if (safe_empty($results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
$name = truncate($result['ap_name']);
|
||||
|
||||
/// FIXME: once we have alerting, colour this to the sensor's status
|
||||
$tab_colour = '#194B7F'; // FIXME: This colour pulled from functions.inc.php humanize_device, maybe set it centrally in definitions?
|
||||
|
||||
$ap_search_results[] = array(
|
||||
'url' => generate_url(array('page' => 'device', 'device' => $result['device_id'], 'tab' => 'wifi', 'view' => 'accesspoints', 'accesspoint' => $result['wifi_ap_id'])),
|
||||
'name' => $name,
|
||||
'colour' => $tab_colour,
|
||||
'icon' => $config['icon']['wifi'],
|
||||
'data' => array(
|
||||
$result['ap_name'],
|
||||
escape_html($result['ap_location']) . ' | Access point'),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$search_results['accesspoints'] = array('descr' => 'APs found', 'results' => $ap_search_results);
|
||||
$ap_search_results[] = [
|
||||
'url' => generate_url(['page' => 'device', 'device' => $result['device_id'], 'tab' => 'wifi', 'view' => 'accesspoints', 'accesspoint' => $result['wifi_ap_id']]),
|
||||
'name' => $name,
|
||||
'colour' => $tab_colour,
|
||||
'icon' => $config['icon']['wifi'],
|
||||
'data' => [
|
||||
$result['ap_name'],
|
||||
escape_html($result['ap_location']) . ' | Access point'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$search_results['accesspoints'] = ['descr' => 'APs found', 'results' => $ap_search_results];
|
||||
|
||||
// EOF
|
||||
|
@ -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
|
||||
|
@ -4,32 +4,40 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
if ($_SESSION['userlevel'] >= 5) {
|
||||
/// Search Groups
|
||||
$results = dbFetchRows('SELECT * FROM `groups`
|
||||
$results = dbFetchRows('SELECT * FROM `groups`
|
||||
WHERE `group_name` LIKE ? OR `group_descr` LIKE ?
|
||||
ORDER BY `group_name` LIMIT ' . $query_limit, array($query_param, $query_param));
|
||||
ORDER BY `group_name` LIMIT ' . $query_limit, [$query_param, $query_param]);
|
||||
|
||||
$group_search_results = [];
|
||||
$group_search_results = [];
|
||||
|
||||
if (!safe_empty($results)) {
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
$name = truncate($result['group_name'], $max_len);
|
||||
if (!safe_empty($results)) {
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
$name = truncate($result['group_name'], $max_len);
|
||||
|
||||
$entity_type = $config['entities'][$result['entity_type']];
|
||||
$entity_type = $config['entities'][$result['entity_type']];
|
||||
|
||||
/// FIXME: always blue
|
||||
$tab_colour = '#194B7F'; // FIXME: This colour pulled from functions.inc.php humanize_device, maybe set it centrally in definitions?
|
||||
/// FIXME: always blue
|
||||
$tab_colour = '#194B7F'; // FIXME: This colour pulled from functions.inc.php humanize_device, maybe set it centrally in definitions?
|
||||
|
||||
$group_search_results[] = array('url' => generate_url(array('page' => 'group', 'group_id' => $result['group_id'])), 'name' => $name, 'colour' => $tab_colour, 'icon' => $entity_type['icon'], 'data' => array('', escape_html($result['group_descr']) . ' | '.nicecase($result['entity_type']).' Group'),);
|
||||
$group_search_results[] = [
|
||||
'url' => generate_url(['page' => 'group', 'group_id' => $result['group_id']]),
|
||||
'name' => $name,
|
||||
'colour' => $tab_colour,
|
||||
'icon' => $entity_type['icon'],
|
||||
'data' => ['', escape_html($result['group_descr']) . ' | ' . nicecase($result['entity_type']) . ' Group']
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$search_results['groups'] = array('descr' => 'Groups found', 'results' => $group_search_results);
|
||||
$search_results['groups'] = ['descr' => 'Groups found', 'results' => $group_search_results];
|
||||
}
|
||||
}
|
@ -6,51 +6,57 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
/// SEARCH STATUS
|
||||
$results = dbFetchRows("SELECT * FROM `entPhysical`
|
||||
LEFT JOIN `devices` USING (`device_id`)
|
||||
WHERE `deleted` IS NULL AND (`entPhysicalSerialNum` LIKE ? OR `entPhysicalModelName` LIKE ?) $query_permitted_device
|
||||
ORDER BY `entPhysicalName` LIMIT $query_limit", [ $query_param, $query_param ]);
|
||||
$where = [ '(`entPhysicalSerialNum` LIKE ? OR `entPhysicalModelName` LIKE ? OR `entPhysicalAssetID` LIKE ?)' ];
|
||||
$where[] = '`deleted` IS NULL';
|
||||
|
||||
if (!safe_empty($results)) {
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
$name = truncate($result['entPhysicalPhysicalName'], $max_len);
|
||||
$sql = "SELECT * FROM `entPhysical` LEFT JOIN `devices` USING (`device_id`)" .
|
||||
generate_where_clause($where, $GLOBALS['cache']['where']['devices_permitted']) .
|
||||
" ORDER BY `entPhysicalName` LIMIT $query_limit";
|
||||
$results = dbFetchRows($sql, [ $query_param, $query_param, $query_param ]);
|
||||
|
||||
if (safe_empty($results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
$name = truncate($result['entPhysicalPhysicalName'], $max_len);
|
||||
$device_name = truncate($result['hostname'], $max_len);
|
||||
if ($result['hostname'] != $result['sysName'] && $result['sysName']) {
|
||||
$device_name .= ' | ' . truncate($result['sysName'], $max_len);
|
||||
$device_name .= ' | ' . truncate($result['sysName'], $max_len);
|
||||
}
|
||||
|
||||
if (strlen($result['entPhysicalModelName'])) {
|
||||
$model = $result['entPhysicalModelName'];
|
||||
$model = $result['entPhysicalModelName'];
|
||||
} elseif (strlen($result['entPhysicalDescr'])) {
|
||||
$model = $result['entPhysicalDescr'];
|
||||
$model = $result['entPhysicalDescr'];
|
||||
} elseif (strlen($result['entPhysicalName'])) {
|
||||
$model = $result['entPhysicalName'];
|
||||
$model = $result['entPhysicalName'];
|
||||
} else {
|
||||
$model = "";
|
||||
$model = "";
|
||||
}
|
||||
|
||||
/// FIXME: once we have alerting, colour this to the sensor's status
|
||||
$tab_colour = '#194B7F'; // FIXME: This colour pulled from functions.inc.php humanize_device, maybe set it centrally in definitions?
|
||||
|
||||
$status_search_results[] = array('url' => generate_device_url($result, array('tab' => 'entphysical')),
|
||||
'name' => $name, 'colour' => $tab_colour,
|
||||
'icon' => $config['icon']['inventory'],
|
||||
'data' => array(
|
||||
escape_html($device_name),
|
||||
html_highlight(escape_html($model) . ' | SN: ' . escape_html($result['entPhysicalSerialNum']), $queryString)
|
||||
)
|
||||
);
|
||||
$status_search_results[] = [
|
||||
'url' => generate_device_url($result, ['tab' => 'entphysical']),
|
||||
'name' => $name, 'colour' => $tab_colour,
|
||||
'icon' => $config['icon']['inventory'],
|
||||
'data' => [
|
||||
escape_html($device_name),
|
||||
html_highlight(escape_html($model) . ' | SN: ' . escape_html($result['entPhysicalSerialNum']), $queryString)
|
||||
]
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$search_results['status'] = array('descr' => 'Inventory entry found', 'results' => $status_search_results);
|
||||
}
|
||||
|
||||
$search_results['status'] = [ 'descr' => 'Inventory entry found', 'results' => $status_search_results ];
|
||||
|
||||
// EOF
|
||||
|
||||
|
@ -6,86 +6,86 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
/// SEARCH IP ADDRESSES
|
||||
|
||||
list($addr, $mask) = explode('/', $queryString);
|
||||
[$addr, $mask] = explode('/', $queryString);
|
||||
|
||||
if (preg_match('/^(?:(?<both>\d+)|(?<ipv6>[\d\:abcdef]+)|(?<ipv4>[\d\.]+))$/i', $addr, $matches)) {
|
||||
$query_ipv4 = 'SELECT `device_id`, `port_id`, `ipv4_address` AS `ip_address`, `ipv4_prefixlen` AS `ip_prefixlen` FROM `ipv4_addresses`';
|
||||
$query_ipv4 .= ' WHERE `ipv4_address` LIKE ?';
|
||||
$query_ipv4 = 'SELECT `device_id`, `port_id`, `ipv4_address` AS `ip_address`, `ipv4_prefixlen` AS `ip_prefixlen` FROM `ipv4_addresses`';
|
||||
$query_ipv4 .= generate_where_clause($GLOBALS['cache']['where']['devices_permitted'], '`ipv4_address` LIKE ?');
|
||||
|
||||
$query_ipv6 = 'SELECT `device_id`, `port_id`, `ipv6_compressed` AS `ip_address`, `ipv6_prefixlen` AS `ip_prefixlen` FROM `ipv6_addresses`';
|
||||
$query_ipv6 .= ' WHERE (`ipv6_address` LIKE ? OR `ipv6_compressed` LIKE ?)';
|
||||
$query_ipv6 = 'SELECT `device_id`, `port_id`, `ipv6_compressed` AS `ip_address`, `ipv6_prefixlen` AS `ip_prefixlen` FROM `ipv6_addresses`';
|
||||
$query_ipv6 .= generate_where_clause($GLOBALS['cache']['where']['devices_permitted'], '(`ipv6_address` LIKE ? OR `ipv6_compressed` LIKE ?)');
|
||||
|
||||
$query_end = $query_permitted_port . " ORDER BY `ip_address` LIMIT $query_limit";
|
||||
$query_param = "%$addr%";
|
||||
if (isset($matches['ipv4'])) {
|
||||
// IPv4 only
|
||||
$results = dbFetchRows($query_ipv4 . $query_end, array($query_param));
|
||||
} elseif (isset($matches['ipv6'])) {
|
||||
// IPv6 only
|
||||
$results = dbFetchRows($query_ipv6 . $query_end, array($query_param, $query_param));
|
||||
} else {
|
||||
// Both
|
||||
$results_ipv4 = dbFetchRows($query_ipv4 . $query_end, array($query_param));
|
||||
$results_ipv6 = dbFetchRows($query_ipv6 . $query_end, array($query_param, $query_param));
|
||||
$coiunt_ipv6 = safe_count($results_ipv6);
|
||||
if ((safe_count($results_ipv4) + $coiunt_ipv6) > $query_limit)
|
||||
{
|
||||
// Ya.. it's not simple
|
||||
$count_ipv4 = $query_limit - min($coiunt_ipv6, (int)($query_limit / 2));
|
||||
$results_ipv4 = array_slice($results_ipv4, 0, $count_ipv4);
|
||||
$results_ipv6 = array_slice($results_ipv6, 0, $query_limit - $count_ipv4);
|
||||
$query_end = " ORDER BY `ip_address` LIMIT $query_limit";
|
||||
$query_param = "%$addr%";
|
||||
if (isset($matches['ipv4'])) {
|
||||
// IPv4 only
|
||||
$results = dbFetchRows($query_ipv4 . $query_end, [$query_param]);
|
||||
} elseif (isset($matches['ipv6'])) {
|
||||
// IPv6 only
|
||||
$results = dbFetchRows($query_ipv6 . $query_end, [$query_param, $query_param]);
|
||||
} else {
|
||||
// Both
|
||||
$results_ipv4 = dbFetchRows($query_ipv4 . $query_end, [$query_param]);
|
||||
$results_ipv6 = dbFetchRows($query_ipv6 . $query_end, [$query_param, $query_param]);
|
||||
$count_ipv6 = safe_count($results_ipv6);
|
||||
if ((safe_count($results_ipv4) + $count_ipv6) > $query_limit) {
|
||||
// Ya.. it's not simple
|
||||
$count_ipv4 = $query_limit - min($count_ipv6, (int)($query_limit / 2));
|
||||
$results_ipv4 = array_slice($results_ipv4, 0, $count_ipv4);
|
||||
$results_ipv6 = array_slice($results_ipv6, 0, $query_limit - $count_ipv4);
|
||||
}
|
||||
$results = array_merge($results_ipv4, $results_ipv6);
|
||||
}
|
||||
$results = array_merge($results_ipv4, $results_ipv6);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
$results = array();
|
||||
$results = [];
|
||||
}
|
||||
|
||||
if (!safe_empty($results)) {
|
||||
$max_len = 35;
|
||||
foreach ($results as $result)
|
||||
{
|
||||
$port = get_port_by_id_cache($result['port_id']);
|
||||
$device = device_by_id_cache($result['device_id']);
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
$port = get_port_by_id_cache($result['port_id']);
|
||||
$device = device_by_id_cache($result['device_id']);
|
||||
|
||||
$descr = strlen($device['location']) ? $device['location'] . ' | ' : '';
|
||||
$descr .= $port['port_label'];
|
||||
$descr = strlen($device['location']) ? $device['location'] . ' | ' : '';
|
||||
$descr .= $port['port_label'];
|
||||
|
||||
$name = $result['ip_address'].'/'.$result['ip_prefixlen'];
|
||||
if (strlen($name) > 35) { $name = substr($name, 0, 35) . "..."; }
|
||||
$name = $result['ip_address'] . '/' . $result['ip_prefixlen'];
|
||||
if (strlen($name) > 35) {
|
||||
$name = substr($name, 0, 35) . "...";
|
||||
}
|
||||
|
||||
$device_name = truncate($device['hostname'], $max_len);
|
||||
if ($device['hostname'] != $device['sysName'] && $device['sysName']) {
|
||||
$device_name .= ' | ' . truncate($device['sysName'], $max_len);
|
||||
}
|
||||
|
||||
$tab_colour = '#194B7F'; // FIXME: This colour pulled from functions.inc.php humanize_device, maybe set it centrally in definitions?
|
||||
|
||||
$view = str_contains($result['ip_address'], '.') ? 'ipv4' : 'ipv6';
|
||||
$ip_search_results[] = [
|
||||
'url' => $port ? generate_port_url($port) : generate_device_url($device, ['tab' => 'ports', 'view' => $view]),
|
||||
'name' => $name,
|
||||
'colour' => $tab_colour,
|
||||
'icon' => $config['icon'][$view],
|
||||
'data' => [
|
||||
'| ' . escape_html($device_name),
|
||||
escape_html($descr)],
|
||||
];
|
||||
|
||||
$device_name = truncate($device['hostname'], $max_len);
|
||||
if ($device['hostname'] != $device['sysName'] && $device['sysName']) {
|
||||
$device_name .= ' | ' . truncate($device['sysName'], $max_len);
|
||||
}
|
||||
|
||||
$tab_colour = '#194B7F'; // FIXME: This colour pulled from functions.inc.php humanize_device, maybe set it centrally in definitions?
|
||||
// FIXME after array-ization, we're missing "on x ports"; is this important? need to amend the "framework" a little, then.
|
||||
// Counter data came from: foreach ($results as $result) {$addr_ports[$result['port_id']][] = $result; }
|
||||
// echo('<li class="nav-header">IPs found: '.count($results).' (on '.count($addr_ports).' ports)</li>');
|
||||
|
||||
$view = str_contains($result['ip_address'], '.') ? 'ipv4' : 'ipv6';
|
||||
$ip_search_results[] = [
|
||||
'url' => $port ? generate_port_url($port) : generate_device_url($device, [ 'tab' => 'ports', 'view' => $view ]),
|
||||
'name' => $name,
|
||||
'colour' => $tab_colour,
|
||||
'icon' => $config['icon'][$view],
|
||||
'data' => [
|
||||
'| ' . escape_html($device_name),
|
||||
escape_html($descr) ],
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
// FIXME after array-ization, we're missing "on x ports"; is this important? need to amend the "framework" a little, then.
|
||||
// Counter data came from: foreach ($results as $result) {$addr_ports[$result['port_id']][] = $result; }
|
||||
// echo('<li class="nav-header">IPs found: '.count($results).' (on '.count($addr_ports).' ports)</li>');
|
||||
|
||||
$search_results['ip-addresses'] = [ 'descr' => 'IPs found', 'results' => $ip_search_results ];
|
||||
$search_results['ip-addresses'] = ['descr' => 'IPs found', 'results' => $ip_search_results];
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -6,43 +6,47 @@
|
||||
*
|
||||
* @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 NEIGHBOURS
|
||||
$sql = "SELECT * FROM `neighbours` WHERE `active` = ? AND (`remote_hostname` LIKE ? OR `remote_address` LIKE ? OR `remote_platform` LIKE ?)" .
|
||||
" $query_permitted_device ORDER BY `last_change` DESC LIMIT $query_limit";
|
||||
$params = [ 1, $query_param, $query_param, $query_param ];
|
||||
$results = dbFetchRows($sql, $params);
|
||||
$where = [ '(`remote_hostname` LIKE ? OR `remote_address` LIKE ? OR `remote_platform` LIKE ?)' ];
|
||||
$where[] = '`active` = 1';
|
||||
|
||||
if (!safe_empty($results)) {
|
||||
$sql = "SELECT * FROM `neighbours`" .
|
||||
generate_where_clause($where, $GLOBALS['cache']['where']['devices_permitted']) .
|
||||
" ORDER BY `last_change` DESC LIMIT $query_limit";
|
||||
$results = dbFetchRows($sql, [ $query_param, $query_param, $query_param ]);
|
||||
|
||||
$max_len = 35;
|
||||
$protocol_classmap = [
|
||||
if (safe_empty($results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$max_len = 35;
|
||||
$protocol_classmap = [
|
||||
'cdp' => 'success',
|
||||
'lldp' => 'warning',
|
||||
'amap' => 'primary',
|
||||
'mndp' => 'error',
|
||||
'fdp' => 'delayed',
|
||||
'edp' => 'suppressed'
|
||||
];
|
||||
];
|
||||
|
||||
foreach ($results as $result) {
|
||||
foreach ($results as $result) {
|
||||
$result_device = device_by_id_cache($result['device_id']);
|
||||
$result_port = get_port_by_id_cache($result['port_id']);
|
||||
$result_port = get_port_by_id_cache($result['port_id']);
|
||||
|
||||
$name = truncate($result_device['hostname'], $max_len);
|
||||
if ($result_device['hostname'] != $result_device['sysName'] && $result_device['sysName']) {
|
||||
$name .= ' | ' . truncate($result_device['sysName'], $max_len);
|
||||
$name .= ' | ' . truncate($result_device['sysName'], $max_len);
|
||||
}
|
||||
|
||||
//$num_ports = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE device_id = ?", array($result['device_id']));
|
||||
@ -50,36 +54,35 @@ if (!safe_empty($results)) {
|
||||
$remote_host = truncate($result['remote_hostname'], $max_len);
|
||||
$remote_host .= ' | ';
|
||||
if ($result['remote_address'] && $result['remote_address'] !== '0.0.0.0') {
|
||||
$remote_host .= $result['remote_address'] . ' | ';
|
||||
$remote_host .= $result['remote_address'] . ' | ';
|
||||
}
|
||||
if (strlen($result['remote_port'])) {
|
||||
$remote_host .= $result['remote_port'] . ' | ';
|
||||
$remote_host .= $result['remote_port'] . ' | ';
|
||||
}
|
||||
|
||||
$remote_descr = $result['remote_platform'] . ' | ';
|
||||
if ($len = strlen($result['remote_version'])) {
|
||||
$result['remote_version'] = truncate($result['remote_version'], 35);
|
||||
$remote_descr .= $result['remote_version'] . ' | ';
|
||||
$result['remote_version'] = truncate($result['remote_version'], 35);
|
||||
$remote_descr .= $result['remote_version'] . ' | ';
|
||||
}
|
||||
|
||||
$protocol_class = isset($protocol_classmap[$result['protocol']]) ? 'label-'.$protocol_classmap[$result['protocol']] : '';
|
||||
$protocol_class = isset($protocol_classmap[$result['protocol']]) ? 'label-' . $protocol_classmap[$result['protocol']] : '';
|
||||
|
||||
$neighbours_search_results[] = array(
|
||||
'url' => generate_device_url($result_device, [ 'tab' => 'ports', 'view' => 'neighbours' ]),
|
||||
'name' => $name,
|
||||
'colour' => $result_device['html_tab_colour'], // FIXME. this colour removed from humanize_device in r6280
|
||||
'row_class' => $result_device['row_class'],
|
||||
'html_row_class' => $result_device['html_row_class'],
|
||||
'icon' => get_device_icon($result_device),
|
||||
'data' => [
|
||||
escape_html($result_port['port_label']) . ' <span class="label '.$protocol_class.'">' . strtoupper($result['protocol']) . '</span>',
|
||||
html_highlight(escape_html($remote_host), $queryString),
|
||||
'<span class="text-wrap">'.html_highlight(escape_html($remote_descr), $queryString) . '</span>',
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
$search_results['neighbours'] = array('descr' => 'Neighbours found', 'results' => $neighbours_search_results);
|
||||
$neighbours_search_results[] = [
|
||||
'url' => generate_device_url($result_device, ['tab' => 'ports', 'view' => 'neighbours']),
|
||||
'name' => $name,
|
||||
'colour' => $result_device['html_tab_colour'], // FIXME. this colour removed from humanize_device in r6280
|
||||
'row_class' => $result_device['row_class'],
|
||||
'html_row_class' => $result_device['html_row_class'],
|
||||
'icon' => get_device_icon($result_device),
|
||||
'data' => [
|
||||
escape_html($result_port['port_label']) . ' <span class="label ' . $protocol_class . '">' . strtoupper($result['protocol']) . '</span>',
|
||||
html_highlight(escape_html($remote_host), $queryString),
|
||||
'<span class="text-wrap">' . html_highlight(escape_html($remote_descr), $queryString) . '</span>',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$search_results['neighbours'] = ['descr' => 'Neighbours found', 'results' => $neighbours_search_results];
|
||||
|
||||
// EOF
|
||||
|
@ -4,58 +4,62 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
/// SEARCH PORTS
|
||||
$where = '`ifAlias` LIKE ? OR `port_label` LIKE ?';
|
||||
$params = [ $query_param, $query_param ];
|
||||
$where = '`ifAlias` LIKE ? OR `port_label` LIKE ?';
|
||||
$params = [ $query_param, $query_param ];
|
||||
$by_mac = preg_match('/^[a-f0-9]{2}[a-f0-9\.\-:]{1,15}/i', $queryString);
|
||||
if ($by_mac) { // Check if query string is like mac-address (maximal 17 chars)
|
||||
$where .= ' OR `ifPhysAddress` LIKE ?';
|
||||
$params[] = '%' . str_replace([ '.', '-', ':' ], '', $queryString) . '%';
|
||||
if ($by_mac) {
|
||||
// Check if query string is like mac-address (maximal 17 chars)
|
||||
$where .= ' OR `ifPhysAddress` LIKE ?';
|
||||
$params[] = '%' . str_replace(['.', '-', ':'], '', $queryString) . '%';
|
||||
}
|
||||
$results = dbFetchRows("SELECT * FROM `ports`
|
||||
LEFT JOIN `devices` USING (`device_id`)
|
||||
WHERE ($where) $query_permitted_port
|
||||
ORDER BY `ifDescr` LIMIT $query_limit", $params);
|
||||
$sql = "SELECT * FROM `ports` LEFT JOIN `devices` USING (`device_id`)" .
|
||||
generate_where_clause("($where)", $GLOBALS['cache']['where']['ports_permitted']) .
|
||||
" ORDER BY `ifDescr` LIMIT $query_limit";
|
||||
$results = dbFetchRows($sql, $params);
|
||||
|
||||
if (!safe_empty($results)) {
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
if (safe_empty($results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
humanize_port($result);
|
||||
|
||||
//FIXME - messy
|
||||
|
||||
$name = truncate($result['port_label'], $max_len);
|
||||
$name = truncate($result['port_label'], $max_len);
|
||||
$device_name = truncate($result['hostname'], $max_len);
|
||||
if ($result['hostname'] != $result['sysName'] && $result['sysName']) {
|
||||
$device_name .= ' | ' . truncate($result['sysName'], $max_len);
|
||||
$device_name .= ' | ' . truncate($result['sysName'], $max_len);
|
||||
}
|
||||
|
||||
$descr = !safe_empty($result['ifAlias']) ? truncate($result['ifAlias'], 80) : '';
|
||||
$type = rewrite_iftype($result['ifType']);
|
||||
$type = rewrite_iftype($result['ifType']);
|
||||
if (!safe_empty($result['ifPhysAddress'])) {
|
||||
$mac = ' | ' . html_highlight(format_mac($result['ifPhysAddress']), $queryString);
|
||||
$mac = ' | ' . html_highlight(format_mac($result['ifPhysAddress']), $queryString);
|
||||
} else {
|
||||
$mac = '';
|
||||
$mac = '';
|
||||
}
|
||||
|
||||
$port_search_results[] = [
|
||||
'url' => generate_port_url($result),
|
||||
'name' => $name,
|
||||
'colour' => $result['table_tab_colour'],
|
||||
'icon' => $config['icon']['port'],
|
||||
'data' => [
|
||||
escape_html($device_name),
|
||||
$type . $mac . ' | ' . html_highlight(escape_html($descr), $queryString) ],
|
||||
'url' => generate_port_url($result),
|
||||
'name' => $name,
|
||||
'colour' => $result['table_tab_colour'],
|
||||
'icon' => $config['icon']['port'],
|
||||
'data' => [
|
||||
escape_html($device_name),
|
||||
$type . $mac . ' | ' . html_highlight(escape_html($descr), $queryString)
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$search_results['ports'] = [ 'descr' => 'Ports found', 'results' => $port_search_results ];
|
||||
}
|
||||
|
||||
$search_results['ports'] = [ 'descr' => 'Ports found', 'results' => $port_search_results ];
|
||||
|
||||
// EOF
|
||||
|
@ -4,44 +4,48 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
/// SEARCH SENSORS
|
||||
$results = dbFetchRows("SELECT * FROM `sensors`
|
||||
LEFT JOIN `devices` USING (`device_id`)
|
||||
WHERE `sensor_descr` LIKE ? $query_permitted_device
|
||||
ORDER BY `sensor_descr` LIMIT $query_limit", [ $query_param ]);
|
||||
$sql = "SELECT * FROM `sensors` LEFT JOIN `devices` USING (`device_id`)" .
|
||||
generate_where_clause('`sensor_descr` LIKE ?', $GLOBALS['cache']['where']['devices_permitted']) .
|
||||
" ORDER BY `sensor_descr` LIMIT $query_limit";
|
||||
$results = dbFetchRows($sql, [ $query_param ]);
|
||||
|
||||
if (!safe_empty($results)) {
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
$name = truncate($result['sensor_descr'], $max_len);
|
||||
if (safe_empty($results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
$name = truncate($result['sensor_descr'], $max_len);
|
||||
$device_name = truncate($result['hostname'], $max_len);
|
||||
if ($result['hostname'] != $result['sysName'] && $result['sysName']) {
|
||||
$device_name .= ' | ' . truncate($result['sysName'], $max_len);
|
||||
$device_name .= ' | ' . truncate($result['sysName'], $max_len);
|
||||
}
|
||||
|
||||
$descr = strlen($result['location']) ? escape_html($result['location']) . ' | ' : '';
|
||||
$descr .= nicecase($result['sensor_class']).' sensor';
|
||||
$descr .= nicecase($result['sensor_class']) . ' sensor';
|
||||
|
||||
/// FIXME: once we have alerting, colour this to the sensor's status
|
||||
$tab_colour = '#194B7F'; // FIXME: This colour pulled from functions.inc.php humanize_device, maybe set it centrally in definitions?
|
||||
|
||||
$sensor_search_results[] = array('url' => 'graphs/type=sensor_' . $result['sensor_class'] . '/id=' . $result['sensor_id'] . '/',
|
||||
'name' => $name,
|
||||
'colour' => $tab_colour,
|
||||
'icon' => $config['sensor_types'][$result['sensor_class']]['icon'],
|
||||
'data' => [
|
||||
'| ' . escape_html($device_name),
|
||||
$descr ]
|
||||
);
|
||||
}
|
||||
|
||||
$search_results['sensors'] = [ 'descr' => 'Sensors found', 'results' => $sensor_search_results ];
|
||||
$sensor_search_results[] = [
|
||||
'url' => 'graphs/type=sensor_' . $result['sensor_class'] . '/id=' . $result['sensor_id'] . '/',
|
||||
'name' => $name,
|
||||
'colour' => $tab_colour,
|
||||
'icon' => $config['sensor_types'][$result['sensor_class']]['icon'],
|
||||
'data' => [
|
||||
'| ' . escape_html($device_name),
|
||||
$descr
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$search_results['sensors'] = [ 'descr' => 'Sensors found', 'results' => $sensor_search_results ];
|
||||
|
||||
// EOF
|
||||
|
@ -6,40 +6,43 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
/// SEARCH SENSORS
|
||||
$results = dbFetchRows("SELECT * FROM `slas` LEFT JOIN `devices` USING (`device_id`) WHERE (`sla_target` LIKE ? OR `sla_index` LIKE ? OR `sla_tag` LIKE ?) $query_permitted_device ORDER BY `sla_target` LIMIT $query_limit", array($query_param, $query_param, $query_param));
|
||||
$where = [ '(`sla_target` LIKE ? OR `sla_index` LIKE ? OR `sla_tag` LIKE ?)' ];
|
||||
$where[] = '`slas`.`deleted` = 0';
|
||||
|
||||
$sql = "SELECT * FROM `slas` LEFT JOIN `devices` USING (`device_id`)" .
|
||||
generate_where_clause($where, $GLOBALS['cache']['where']['devices_permitted']) .
|
||||
" ORDER BY `sla_target` LIMIT $query_limit";
|
||||
$results = dbFetchRows($sql, [ $query_param, $query_param, $query_param ]);
|
||||
if (safe_empty($results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!safe_empty($results)) {
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
humanize_sla($result);
|
||||
|
||||
$device_name = truncate($result['hostname'], $max_len);
|
||||
if ($result['hostname'] != $result['sysName'] && $result['sysName']) {
|
||||
$device_name .= ' | ' . truncate($result['sysName'], $max_len);
|
||||
$device_name .= ' | ' . truncate($result['sysName'], $max_len);
|
||||
}
|
||||
$descr = strlen($result['location']) ? escape_html($result['location']) . ' | ' : '';
|
||||
$descr .= $result['rtt_label'];
|
||||
$descr = strlen($result['location']) ? escape_html($result['location']) . ' | ' : '';
|
||||
$descr .= $result['rtt_label'];
|
||||
$tab_colour = '#194B7F';
|
||||
|
||||
$sla_search_results[] = [
|
||||
'url' => generate_url(array('page' => 'device', 'device' => $result['device_id'], 'tab' => 'slas', 'id' => $result['sla_id'])),
|
||||
'name' => $result['sla_descr'],
|
||||
'url' => generate_url(['page' => 'device', 'device' => $result['device_id'], 'tab' => 'slas', 'id' => $result['sla_id']]),
|
||||
'name' => $result['sla_descr'],
|
||||
'colour' => $tab_colour,
|
||||
'icon' => $config['icon']['sla'],
|
||||
'data' => [
|
||||
'| ' . escape_html($device_name),
|
||||
$descr,
|
||||
]
|
||||
'icon' => $config['icon']['sla'],
|
||||
'data' => ['| ' . escape_html($device_name), $descr]
|
||||
];
|
||||
}
|
||||
|
||||
$search_results['slas'] = [ 'descr' => 'SLAs found', 'results' => $sla_search_results ];
|
||||
}
|
||||
|
||||
$search_results['slas'] = ['descr' => 'SLAs found', 'results' => $sla_search_results];
|
||||
|
||||
// EOF
|
@ -6,23 +6,26 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
/// SEARCH STATUS
|
||||
$results = dbFetchRows("SELECT * FROM `status`
|
||||
LEFT JOIN `devices` USING (`device_id`)
|
||||
WHERE `status_descr` LIKE ? $query_permitted_device
|
||||
ORDER BY `status_descr` LIMIT $query_limit", array($query_param));
|
||||
$sql = "SELECT * FROM `status` LEFT JOIN `devices` USING (`device_id`)" .
|
||||
generate_where_clause('`status_descr` LIKE ?', $GLOBALS['cache']['where']['devices_permitted']) .
|
||||
" ORDER BY `status_descr` LIMIT $query_limit";
|
||||
$results = dbFetchRows($sql, [ $query_param ]);
|
||||
|
||||
if (!safe_empty($results)) {
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
$name = truncate($result['status_descr'], $max_len);
|
||||
if (safe_empty($results)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$max_len = 35;
|
||||
foreach ($results as $result) {
|
||||
$name = truncate($result['status_descr'], $max_len);
|
||||
$device_name = truncate($result['hostname'], $max_len);
|
||||
if ($result['hostname'] != $result['sysName'] && $result['sysName']) {
|
||||
$device_name .= ' | ' . truncate($result['sysName'], $max_len);
|
||||
$device_name .= ' | ' . truncate($result['sysName'], $max_len);
|
||||
}
|
||||
$descr = strlen($result['location']) ? escape_html($result['location']) . ' | ' : '';
|
||||
$descr .= nicecase($result['entPhysicalClass']) . ' status';
|
||||
@ -31,18 +34,15 @@ if (!safe_empty($results)) {
|
||||
$tab_colour = '#194B7F'; // FIXME: This colour pulled from functions.inc.php humanize_device, maybe set it centrally in definitions?
|
||||
|
||||
$status_search_results[] = [
|
||||
'url' => 'graphs/type=status_graph/id=' . $result['status_id'] . '/',
|
||||
'name' => $name,
|
||||
'colour' => $tab_colour,
|
||||
'icon' => $config['icon']['status'],
|
||||
'data' => [
|
||||
'| ' . escape_html($device_name),
|
||||
$descr ]
|
||||
'url' => 'graphs/type=status_graph/id=' . $result['status_id'] . '/',
|
||||
'name' => $name,
|
||||
'colour' => $tab_colour,
|
||||
'icon' => $config['icon']['status'],
|
||||
'data' => ['| ' . escape_html($device_name), $descr]
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$search_results['status'] = [ 'descr' => 'Status Indicators found', 'results' => $status_search_results ];
|
||||
}
|
||||
|
||||
$search_results['status'] = [ 'descr' => 'Status Indicators found', 'results' => $status_search_results ];
|
||||
|
||||
// EOF
|
||||
|
Reference in New Issue
Block a user