webui: Updated remaining display options where we do not show sysName if hostname is IP (#6585)

* webui: Updated remaining display options where we do not show sysName if hostname is IP

* renamed function + simplified
This commit is contained in:
Neil Lathwood
2017-05-05 12:25:58 +01:00
committed by Tony Murray
parent 1135bb9146
commit 34c35f3627
17 changed files with 53 additions and 53 deletions

View File

@@ -226,7 +226,7 @@ if (defined('SHOW_SETTINGS')) {
$deviceLabelOld = 'availability-map-oldview-box-down';
$host_down_count++;
}
$device_system_name = ip_to_sysname($device, $device['hostname']);
$device_system_name = format_hostname($device);
if ($config['webui']['availability_map_compact'] == 0) {
if ($directpage == "yes") {
@@ -276,7 +276,7 @@ if (defined('SHOW_SETTINGS')) {
$serviceState = "down";
$service_down_count++;
}
$service_system_name = ip_to_sysname($service, $service['hostname']);
$service_system_name = format_hostname($service);
if ($config['webui']['availability_map_compact'] == 0) {
if ($directpage == "yes") {

View File

@@ -185,8 +185,8 @@ var greenMarker = L.AwesomeMarkers.icon({
$icon = 'redMarker';
$z_offset = 10000; // move marker to foreground
}
$temp_output .= "var title = '<a href=\"" . generate_device_url($map_devices) . "\"><img src=\"".getIcon($map_devices)."\" width=\"32\" height=\"32\" alt=\"\"> ".ip_to_sysname($map_devices, $map_devices['hostname'])."</a>';
var tooltip = '".ip_to_sysname($map_devices, $map_devices['hostname'])."';
$temp_output .= "var title = '<a href=\"" . generate_device_url($map_devices) . "\"><img src=\"".getIcon($map_devices)."\" width=\"32\" height=\"32\" alt=\"\"> ".format_hostname($map_devices)."</a>';
var tooltip = '".format_hostname($map_devices)."';
var marker = L.marker(new L.LatLng(".$map_devices['lat'].", ".$map_devices['lng']."), {title: tooltip, icon: $icon, zIndexOffset: $z_offset});
marker.bindPopup(title);
markers.addLayer(marker);\n";

View File

@@ -264,7 +264,7 @@ function generate_device_link($device, $text = null, $vars = array(), $start = 0
$text = $device['hostname'];
}
$text = ip_to_sysname($device, $text);
$text = format_hostname($device, $text);
if (isset($config['os'][$device['os']]['over'])) {
$graphs = $config['os'][$device['os']]['over'];

View File

@@ -148,13 +148,13 @@ foreach ($list as $items) {
$local_device_id = $items['local_device_id'];
if (!array_key_exists($local_device_id, $devices_by_id)) {
$items['sysName'] = $items['local_sysName'];
$devices_by_id[$local_device_id] = array('id'=>$local_device_id,'label'=>shorthost(ip_to_sysname($items, $items['local_hostname']), 1),'title'=>generate_device_link($local_device, '', array(), '', '', '', 0),'shape'=>'box');
$devices_by_id[$local_device_id] = array('id'=>$local_device_id,'label'=>shorthost(format_hostname($items, $items['local_hostname']), 1),'title'=>generate_device_link($local_device, '', array(), '', '', '', 0),'shape'=>'box');
}
$remote_device_id = $items['remote_device_id'];
if (!array_key_exists($remote_device_id, $devices_by_id)) {
$items['sysName'] = $items['remote_sysName'];
$devices_by_id[$remote_device_id] = array('id'=>$remote_device_id,'label'=>shorthost(ip_to_sysname($items, $items['remote_hostname']), 1),'title'=>generate_device_link($remote_device, '', array(), '', '', '', 0),'shape'=>'box');
$devices_by_id[$remote_device_id] = array('id'=>$remote_device_id,'label'=>shorthost(format_hostname($items, $items['remote_hostname']), 1),'title'=>generate_device_link($remote_device, '', array(), '', '', '', 0),'shape'=>'box');
}
$speed = $items['local_ifspeed']/1000/1000;

View File

@@ -199,7 +199,7 @@ foreach (dbFetchRows($sql, $param) as $device) {
$os = $device['os_text'] . '<br>' . $device['version'];
$device['ip'] = inet6_ntop($device['ip']);
$uptime = formatUptime($device['uptime'], 'short');
if (ip_to_sysname($device, $device['hostname']) !== $device['sysName']) {
if (format_hostname($device) !== $device['sysName']) {
$hostname .= '<br />' . $device['sysName'];
} elseif ($device['hostname'] !== $device['ip']) {
$hostname .= '<br />' . $device['hostname'];

View File

@@ -23,7 +23,7 @@ if ($_SESSION['userlevel'] < '10') {
}
foreach (dbFetchRows('SELECT * FROM `devices` ORDER BY `hostname`') as $device) {
$devicesform .= "<option value='".$device['device_id']."'>".$device['hostname'].'</option>';
$devicesform .= "<option value='".$device['device_id']."'>".format_hostname($device).'</option>';
}
if ($updated) {

View File

@@ -22,7 +22,7 @@ if (device_permitted($vars['device']) || $permitted_by_port) {
$entity_state = get_dev_entity_state($device['device_id']);
// print_r($entity_state);
$pagetitle[] = ip_to_sysname($device, $device['hostname']);
$pagetitle[] = format_hostname($device, $device['hostname']);
$component = new LibreNMS\Component();
$component_count = $component->getComponentCount($device['device_id']);

View File

@@ -98,7 +98,7 @@ if ($_SESSION['userlevel'] != '10') {
}
if (!$done) {
echo "<option value='".$device['device_id']."'>".$device['hostname'].'</option>';
echo "<option value='".$device['device_id']."'>".format_hostname($device, $device['hostname']).'</option>';
}
}
@@ -159,7 +159,7 @@ if ($_SESSION['userlevel'] != '10') {
}
if (!$done) {
echo "<option value='".$device['device_id']."'>".$device['hostname'].'</option>';
echo "<option value='".$device['device_id']."'>".format_hostname($device, $device['hostname']).'</option>';
}
}

View File

@@ -23,15 +23,14 @@ print_optionbar_start();
<select name="device" id="device" class="form-control input-sm">
<option value="">All Devices</option>
<?php
foreach (get_all_devices() as $hostname) {
$device_id = getidbyname($hostname);
if (device_permitted($device_id)) {
echo "<option value='".$device_id."'";
if ($device_id == $_POST['device']) {
foreach (get_all_devices() as $data) {
if (device_permitted($data['device_id'])) {
echo "<option value='".$data['device_id']."'";
if ($data['device_id'] == $_POST['device']) {
echo 'selected';
}
echo '>'.$hostname.'</option>';
echo '>'.format_hostname($data).'</option>';
}
}
?>

View File

@@ -62,7 +62,7 @@ foreach (dbFetchRows('SELECT * FROM `devices` ORDER BY `hostname`') as $data) {
echo '" selected"+';
}
echo '">'.$data['hostname'].'</option>"+';
echo '">'.format_hostname($data, $data['hostname']).'</option>"+';
}
}
?>

View File

@@ -87,20 +87,20 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != "hide") || !isset($vars[
<?php
if ($_SESSION['userlevel'] >= 5) {
$results = dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` ORDER BY `hostname`");
$results = dbFetchRows("SELECT `device_id`,`hostname`, `sysName` FROM `devices` ORDER BY `hostname`");
} else {
$results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` ORDER BY `hostname`", array($_SESSION['user_id']));
$results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname`, `D`.`sysname` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` ORDER BY `hostname`", array($_SESSION['user_id']));
}
foreach ($results as $data) {
echo(' <option value="'.$data['device_id'].'"');
if ($data['device_id'] == $vars['device_id']) {
echo("selected");
}
echo(">".$data['hostname']."</option>");
echo(">".format_hostname($data)."</option>");
}
if ($_SESSION['userlevel'] < 5) {
$results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname` FROM `ports` AS `I` JOIN `devices` AS `D` ON `D`.`device_id`=`I`.`device_id` JOIN `ports_perms` AS `PP` ON `PP`.`port_id`=`I`.`port_id` WHERE `PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` ORDER BY `hostname`", array($_SESSION['user_id']));
$results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname`, `D`.`sysName` FROM `ports` AS `I` JOIN `devices` AS `D` ON `D`.`device_id`=`I`.`device_id` JOIN `ports_perms` AS `PP` ON `PP`.`port_id`=`I`.`port_id` WHERE `PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` ORDER BY `hostname`", array($_SESSION['user_id']));
} else {
$results = array();
}
@@ -109,7 +109,7 @@ foreach ($results as $data) {
if ($data['device_id'] == $vars['device_id']) {
echo("selected");
}
echo(">".$data['hostname']."</option>");
echo(">".format_hostname($data)."</option>");
}
?>
@@ -186,14 +186,15 @@ if (is_admin() === true || is_read() === true) {
$sql = "SELECT `port_descr_type` FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P`, `ports_perms` AS `PP` WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `D`.`device_id`)) AND `D`.`device_id` = `I`.`device_id` GROUP BY `port_descr_type` ORDER BY `port_descr_type`";
$param[] = array($_SESSION['user_id'],$_SESSION['user_id']);
}
$ports = dbFetchRows($sql, $param);
$ports = dbFetchRows($sql, $param);
foreach ($ports as $data) {
if ($data['port_descr_type']) {
echo(' <option value="'.$data['port_descr_type'].'"');
if ($data['port_descr_type'] == $vars['port_descr_type']) {
echo("selected");
}
echo(">".ucfirst($data['port_descr_type'])."</option>");
echo(">".ucfirst(display($data['port_descr_type']))."</option>");
}
}
?>

View File

@@ -30,7 +30,7 @@ var grid = $("#arp-search").bootgrid({
<?php
// Select the devices only with ARP tables
$sql = 'SELECT D.device_id AS device_id, `hostname` FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D';
$sql = 'SELECT D.device_id AS device_id, `hostname`, `D`.`sysName` AS `sysName` FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D';
if (is_admin() === false && is_read() === false) {
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`';
@@ -38,14 +38,14 @@ if (is_admin() === false && is_read() === false) {
$param[] = $_SESSION['user_id'];
}
$sql .= " WHERE M.port_id = P.port_id AND P.device_id = D.device_id $where GROUP BY `D`.`device_id`, `D`.`hostname` ORDER BY `hostname`";
$sql .= " WHERE M.port_id = P.port_id AND P.device_id = D.device_id $where GROUP BY `D`.`device_id`, `D`.`hostname`, `D`.`sysName` ORDER BY `hostname`";
foreach (dbFetchRows($sql, $param) as $data) {
echo '"<option value=\"'.$data['device_id'].'\""+';
if ($data['device_id'] == $_POST['device_id']) {
echo '" selected "+';
}
echo '">'.$data['hostname'].'</option>"+';
echo '">'.format_hostname($data).'</option>"+';
}
?>
"</select>"+

View File

@@ -27,7 +27,7 @@ var grid = $("#ipv4-search").bootgrid({
"<option value=\"\">All Devices</option>"+
<?php
$sql = 'SELECT `devices`.`device_id`,`hostname` FROM `devices`';
$sql = 'SELECT `devices`.`device_id`,`hostname`,`sysName` FROM `devices`';
if (is_admin() === false && is_read() === false) {
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`';
@@ -43,7 +43,7 @@ foreach (dbFetchRows($sql, $param) as $data) {
echo '" selected "+';
}
echo '">'.$data['hostname'].'</option>"+';
echo '">'.format_hostname($data, $data['hostname']).'</option>"+';
}
?>
"</select>"+

View File

@@ -26,7 +26,7 @@ var grid = $("#ipv6-search").bootgrid({
"<option value=\"\">All Devices</option>"+
<?php
$sql = 'SELECT `devices`.`device_id`,`hostname` FROM `devices`';
$sql = 'SELECT `devices`.`device_id`,`hostname`, `sysName` FROM `devices`';
if (is_admin() === false && is_read() === false) {
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`';
@@ -42,7 +42,7 @@ foreach (dbFetchRows($sql, $param) as $data) {
echo '" selected"+';
}
echo '">'.$data['hostname'].'</option>"+';
echo '">'.format_hostname($data, $data['hostname']).'</option>"+';
}
?>
"</select>"+

View File

@@ -26,7 +26,7 @@ var grid = $("#mac-search").bootgrid({
"<select name=\"device_id\" id=\"device_id\" class=\"form-control input-sm\">"+
"<option value=\"\">All Devices</option>"+
<?php
$sql = 'SELECT `devices`.`device_id`,`hostname` FROM `devices`';
$sql = 'SELECT `devices`.`device_id`,`hostname`, `sysName` FROM `devices`';
if (is_admin() === false && is_read() === false) {
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`';
@@ -41,7 +41,7 @@ foreach (dbFetchRows($sql, $param) as $data) {
echo '" selected "+';
}
echo '">'.$data['hostname'].'</option>"+';
echo '">'.format_hostname($data).'</option>"+';
}
?>
"</select>"+

View File

@@ -28,14 +28,13 @@ print_optionbar_start();
<select name="device" id="device" class="form-control input-sm">
<option value="">All Devices</option>
<?php
foreach (get_all_devices() as $hostname) {
$device_id = getidbyname($hostname);
if (device_permitted($device_id)) {
echo '"<option value="' . $device_id . '"';
if ($device_id == $vars['device']) {
foreach (get_all_devices() as $data) {
if (device_permitted($data['device_id'])) {
echo '"<option value="' . $data['device_id'] . '"';
if ($data['device_id'] == $vars['device']) {
echo ' selected';
}
echo '>' . $hostname . '</option>';
echo '>' . format_hostname($data) . '</option>';
}
}
?>

View File

@@ -206,11 +206,9 @@ function get_all_devices()
// FIXME respect $type (server, network, etc) -- needs an array fill in topnav.
if (isset($cache['devices']['hostname'])) {
$devices = array_keys($cache['devices']['hostname']);
$devices = array_keys($cache['devices']);
} else {
foreach (dbFetchRows("SELECT `hostname` FROM `devices`") as $data) {
$devices[] = $data['hostname'];
}
$devices = dbFetchRows("SELECT * FROM `devices`");
}
return $devices;
@@ -1128,21 +1126,24 @@ function inet6_ntop($ip)
}
/**
* Convert IP to use sysName
* If hostname is an ip, use return sysName
* @param array device
* @param string ip address
* @param string hostname
* @return string
**/
function ip_to_sysname($device, $ip)
function format_hostname($device, $hostname = '')
{
global $config;
if ($config['force_ip_to_sysname'] === true) {
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) == true || filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) == true) {
$ip = $device['sysName'];
if (empty($hostname)) {
$hostname = $device['hostname'];
}
if ($config['force_ip_to_sysname'] === true && !empty($device['sysName'])) {
if (filter_var($hostname, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) == true || filter_var($hostname, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) == true) {
$hostname = $device['sysName'];
}
}
return $ip;
}//end ip_to_sysname
return $hostname;
}//end format_hostname
/**
* Return valid port association modes