mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 08:02:41 +02:00
small cleanups etc, plus allow sysLocation override
git-svn-id: http://www.observium.org/svn/observer/trunk@2000 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -124,7 +124,7 @@ function permissions_cache($user_id)
|
||||
|
||||
function bill_permitted($bill_id)
|
||||
{
|
||||
global $_SESSION, $permissions;
|
||||
global $permissions;
|
||||
|
||||
if ($_SESSION['userlevel'] >= "5") {
|
||||
$allowed = TRUE;
|
||||
@@ -139,7 +139,7 @@ function bill_permitted($bill_id)
|
||||
|
||||
function port_permitted($interface_id, $device_id = NULL)
|
||||
{
|
||||
global $_SESSION, $permissions;
|
||||
global $permissions;
|
||||
|
||||
if (!is_numeric($device_id)) { $device_id = get_device_id_by_interface_id($interface_id); }
|
||||
|
||||
@@ -159,7 +159,7 @@ function port_permitted($interface_id, $device_id = NULL)
|
||||
|
||||
function application_permitted($app_id, $device_id = NULL)
|
||||
{
|
||||
global $_SESSION, $permissions;
|
||||
global $permissions;
|
||||
if (is_numeric($app_id))
|
||||
{
|
||||
if (!$device_id) { $device_id = device_by_id_cache ($app_id); }
|
||||
@@ -181,7 +181,7 @@ function application_permitted($app_id, $device_id = NULL)
|
||||
|
||||
function device_permitted($device_id)
|
||||
{
|
||||
global $_SESSION, $permissions;
|
||||
global $permissions;
|
||||
|
||||
if ($_SESSION['userlevel'] >= "5")
|
||||
{
|
||||
@@ -355,4 +355,42 @@ function devclass($device)
|
||||
return $class;
|
||||
}
|
||||
|
||||
function getlocations()
|
||||
{
|
||||
# Fetch override locations, not through get_dev_attrib, this would be a huge number of queries
|
||||
$result = mysql_query("SELECT attrib_type,attrib_value,device_id FROM devices_attribs WHERE attrib_type LIKE 'override_sysLocation%' ORDER BY attrib_type");
|
||||
while ($row = mysql_fetch_assoc($result))
|
||||
{
|
||||
if ($row['attrib_type'] == 'override_sysLocation_bool' && $row['attrib_value'] == 1)
|
||||
{
|
||||
$ignore_dev_location[$row['device_id']] = 1;
|
||||
}
|
||||
# We can do this because of the ORDER BY, "bool" will be handled before "string"
|
||||
elseif ($row['attrib_type'] == 'override_sysLocation_string' && $ignore_dev_location[$row['device_id']] == 1)
|
||||
{
|
||||
if (!in_array($row['location'],$locations)) { $locations[] = $row['attrib_value']; }
|
||||
}
|
||||
}
|
||||
|
||||
# Fetch regular locations
|
||||
if ($_SESSION['userlevel'] >= '5')
|
||||
{
|
||||
$result = mysql_query("SELECT D.device_id,location FROM devices AS D GROUP BY location ORDER BY location");
|
||||
} else {
|
||||
$result = mysql_query("SELECT D.device_id,location FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' GROUP BY location ORDER BY location");
|
||||
}
|
||||
|
||||
while ($row = mysql_fetch_assoc($result))
|
||||
{
|
||||
# Only add it as a location if it wasn't overridden (and not already there)
|
||||
if ($row['location'] != '' && !$ignore_dev_location[$row['device_id']])
|
||||
{
|
||||
if (!in_array($row['location'],$locations)) { $locations[] = $row['location']; }
|
||||
}
|
||||
}
|
||||
|
||||
sort($locations);
|
||||
return $locations;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,43 +1,52 @@
|
||||
<?php
|
||||
|
||||
if ($bg == $list_colour_b) { $bg = $list_colour_a; } else { $bg = $list_colour_b; }
|
||||
if ($device['status'] == '0') { $class = "list-device-down"; $bg_image = "images/warning-background.png"; } else { $class = "list-device"; unset ($bg_image); }
|
||||
if ($device['ignore'] == '1') {
|
||||
$class = "list-device-ignored";
|
||||
if ($device['status'] == '1') { $class = "list-device-ignored-up"; }
|
||||
}
|
||||
if ($bg == $list_colour_b) { $bg = $list_colour_a; } else { $bg = $list_colour_b; }
|
||||
if ($device['status'] == '0') { $class = "list-device-down"; $bg_image = "images/warning-background.png"; } else { $class = "list-device"; unset ($bg_image); }
|
||||
if ($device['ignore'] == '1')
|
||||
{
|
||||
$class = "list-device-ignored";
|
||||
if ($device['status'] == '1') { $class = "list-device-ignored-up"; }
|
||||
}
|
||||
|
||||
$type = strtolower($device['os']);
|
||||
unset($image);
|
||||
$type = strtolower($device['os']);
|
||||
unset($image);
|
||||
|
||||
$image = getImage($device['device_id']);
|
||||
if ($device['os'] == "ios") { formatCiscoHardware($device, true); }
|
||||
$device['os_text'] = $config['os'][$device['os']]['text'];
|
||||
$image = getImage($device['device_id']);
|
||||
if ($device['os'] == "ios") { formatCiscoHardware($device, true); }
|
||||
$device['os_text'] = $config['os'][$device['os']]['text'];
|
||||
|
||||
$port_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."'"),0);
|
||||
$sensor_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = '".$device['device_id']."'"),0);
|
||||
$port_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."'"),0);
|
||||
$sensor_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = '".$device['device_id']."'"),0);
|
||||
|
||||
echo(' <tr background="'.$bg_image.'" bgcolor="' . $bg . '" onmouseover="this.style.backgroundColor=\'#fdd\';" onmouseout="this.style.backgroundColor=\'' . $bg . '\';"
|
||||
onclick="location.href=\'/device/'.$device['device_id'].'/\'" style="cursor: pointer;">
|
||||
<td width="40" align="center" valign="middle">' . $image . '</td>
|
||||
<td width="300"><span style="font-weight: bold; font-size: 14px;">' . generate_device_link($device) . '</span>
|
||||
<br />' . $device['sysName'] . '</td>
|
||||
echo(' <tr background="'.$bg_image.'" bgcolor="' . $bg . '" onmouseover="this.style.backgroundColor=\'#fdd\';" onmouseout="this.style.backgroundColor=\'' . $bg . '\';"
|
||||
onclick="location.href=\'/device/'.$device['device_id'].'/\'" style="cursor: pointer;">
|
||||
<td width="40" align="center" valign="middle">' . $image . '</td>
|
||||
<td width="300"><span style="font-weight: bold; font-size: 14px;">' . generate_device_link($device) . '</span>
|
||||
<br />' . $device['sysName'] . '</td>
|
||||
<td width=55>');
|
||||
|
||||
if ($port_count) { echo(' <img src="images/icons/port.png" align=absmiddle /> '.$port_count); }
|
||||
echo('<br />');
|
||||
if ($sensor_count) { echo(' <img src="images/icons/sensors.png" align=absmiddle /> '.$sensor_count); }
|
||||
if ($port_count) { echo(' <img src="images/icons/port.png" align=absmiddle /> '.$port_count); }
|
||||
echo('<br />');
|
||||
if ($sensor_count) { echo(' <img src="images/icons/sensors.png" align=absmiddle /> '.$sensor_count); }
|
||||
|
||||
echo(' </td>
|
||||
<td width="200">' . $device['os_text'] . '<br />
|
||||
' . $device['version'] . '</td>
|
||||
<td width="200">' . $device['hardware'] . '<br />
|
||||
' . $device['features'] . '</td>
|
||||
<td>' . formatUptime($device['uptime']) . '
|
||||
<br />
|
||||
' . $device['location'] . '</td>
|
||||
<td width="10">
|
||||
</td>
|
||||
</tr>');
|
||||
echo(' </td>
|
||||
<td width="200">' . $device['os_text'] . '<br />
|
||||
' . $device['version'] . '</td>
|
||||
<td width="200">' . $device['hardware'] . '<br />
|
||||
' . $device['features'] . '</td>
|
||||
<td>' . formatUptime($device['uptime']) . '
|
||||
<br />');
|
||||
if (get_dev_attrib($device,'override_sysLocation_bool'))
|
||||
{
|
||||
echo(get_dev_attrib($device,'override_sysLocation_string'));
|
||||
}
|
||||
else
|
||||
{
|
||||
echo($device['location']);
|
||||
}
|
||||
echo('</td>
|
||||
<td width="10">
|
||||
</td>
|
||||
</tr>');
|
||||
|
||||
?>
|
||||
?>
|
||||
@@ -1,27 +1,30 @@
|
||||
<?php
|
||||
|
||||
$service_alerts = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_status = '0'"),0);
|
||||
$if_alerts = mysql_result(mysql_query("SELECT count(*) FROM `ports` WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND `ignore` = '0'"),0);
|
||||
$device_alerts = "0";
|
||||
$device_alert_sql = "WHERE 0";
|
||||
$service_alerts = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_status = '0'"),0);
|
||||
$if_alerts = mysql_result(mysql_query("SELECT count(*) FROM `ports` WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND `ignore` = '0'"),0);
|
||||
$device_alerts = "0";
|
||||
$device_alert_sql = "WHERE 0";
|
||||
|
||||
if (isset($config['enable_bgp']) && $config['enable_bgp'])
|
||||
{
|
||||
$bgp_alerts = mysql_result(mysql_query("SELECT COUNT(*) FROM bgpPeers AS B where (bgpPeerAdminStatus = 'start' OR bgpPeerAdminStatus = 'running') AND bgpPeerState != 'established'"), 0);
|
||||
}
|
||||
|
||||
$query_a = mysql_query("SELECT * FROM `devices`");
|
||||
while ($device = mysql_fetch_array($query_a)) {
|
||||
$this_alert = 0;
|
||||
if ($device['status'] == 0 && $device['ignore'] == '0') { $this_alert = "1"; } elseif ($device['ignore'] == '0') {
|
||||
if (mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_status = '0' AND device_id = '".$device['device_id']."'"),0)) { $this_alert = "1"; }
|
||||
if (mysql_result(mysql_query("SELECT count(*) FROM ports WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND device_id = '" . $device['device_id'] . "' AND `ignore` = '0'"),0)) { $this_alert = "1"; }
|
||||
}
|
||||
if ($this_alert) {
|
||||
$device_alerts++;
|
||||
$device_alert_sql .= " OR `device_id` = '" . $device['device_id'] . "'";
|
||||
}
|
||||
$query_a = mysql_query("SELECT * FROM `devices`");
|
||||
while ($device = mysql_fetch_array($query_a))
|
||||
{
|
||||
$this_alert = 0;
|
||||
if ($device['status'] == 0 && $device['ignore'] == '0') { $this_alert = "1"; } elseif ($device['ignore'] == '0')
|
||||
{
|
||||
if (mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_status = '0' AND device_id = '".$device['device_id']."'"),0)) { $this_alert = "1"; }
|
||||
if (mysql_result(mysql_query("SELECT count(*) FROM ports WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND device_id = '" . $device['device_id'] . "' AND `ignore` = '0'"),0)) { $this_alert = "1"; }
|
||||
}
|
||||
if ($this_alert)
|
||||
{
|
||||
$device_alerts++;
|
||||
$device_alert_sql .= " OR `device_id` = '" . $device['device_id'] . "'";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="menu2">
|
||||
@@ -33,9 +36,9 @@ if (isset($config['enable_bgp']) && $config['enable_bgp'])
|
||||
echo('<li><a href="map/"><img src="images/16/map.png" border="0" align="absmiddle" /> Network Map</a></li>');
|
||||
} ?>
|
||||
<li><a href="eventlog/"><img src="images/16/report.png" border="0" align="absmiddle" /> Eventlog</a></li>
|
||||
<?php if (isset($config['enable_syslog']) && $config['enable_syslog']) {
|
||||
echo('<li><a href="syslog/"><img src="images/16/page.png" border="0" align="absmiddle" /> Syslog</a></li>');
|
||||
} ?>
|
||||
<?php if (isset($config['enable_syslog']) && $config['enable_syslog']) {
|
||||
echo('<li><a href="syslog/"><img src="images/16/page.png" border="0" align="absmiddle" /> Syslog</a></li>');
|
||||
} ?>
|
||||
<!-- <li><a href="alerts/"><img src="images/16/exclamation.png" border="0" align="absmiddle" /> Alerts</a></li> -->
|
||||
<li><a href="inventory/"><img src="images/16/bricks.png" border="0" align="absmiddle" /> Inventory</a></li>
|
||||
</ul>
|
||||
@@ -59,7 +62,7 @@ foreach ($config['device_types'] as $devtype)
|
||||
|
||||
?>
|
||||
<li><hr width="140" /></li>
|
||||
<li><a href="devices/alerted/"><img src="images/16/server_error.png" border="0" align="absmiddle" /> Alerts (<?php echo($device_alerts) ?>)</a></li>
|
||||
<li><a href="devices/alerted/"><img src="images/icons/alerts.png" border="0" align="absmiddle" /> Alerts (<?php echo($device_alerts) ?>)</a></li>
|
||||
<?php
|
||||
if ($_SESSION['userlevel'] >= '10') {
|
||||
echo('
|
||||
@@ -104,11 +107,6 @@ if ($_SESSION['userlevel'] >= '10') {
|
||||
## Display Locations entry if $config['show_locations']
|
||||
if ($config['show_locations'])
|
||||
{
|
||||
if($_SESSION['userlevel'] >= '5') {
|
||||
$locations = mysql_query("SELECT DISTINCT location FROM devices GROUP BY location ORDER BY location");
|
||||
} else {
|
||||
$locations = mysql_query("SELECT DISTINCT location FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' GROUP BY location ORDER BY location");
|
||||
}
|
||||
?>
|
||||
<li><a class="menu2four" href="locations/"><img src="images/16/building.png" border="0" align="absmiddle" /> Locations</a>
|
||||
<?php
|
||||
@@ -118,12 +116,9 @@ if ($config['show_locations'])
|
||||
<table><tr><td>
|
||||
<ul>
|
||||
<?php
|
||||
while ($row = mysql_fetch_array($locations))
|
||||
foreach (getlocations() as $location)
|
||||
{
|
||||
if ($row['location'] != '')
|
||||
{
|
||||
echo(' <li><a href="?page=devices&location=' . urlencode($row['location']) . '"><img src="images/16/building.png" border="0" align="absmiddle" /> ' . $row['location'] . ' </a></li>');
|
||||
}
|
||||
echo(' <li><a href="?page=devices&location=' . urlencode($location) . '"><img src="images/16/building.png" border="0" align="absmiddle" /> ' . $location . ' </a></li>');
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
@@ -136,7 +131,6 @@ if ($config['show_locations'])
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<li><a class="menu2four" href="ports/"><img src="images/16/connect.png" border="0" align="absmiddle" /> Ports</a>
|
||||
|
||||
<table><tr><td>
|
||||
@@ -212,7 +206,7 @@ if ($deleted_ports) { echo('<li><a href="ports/deleted/"><img src="images/16/cro
|
||||
<!--[if IE 7]><!--></a><!--<![endif]-->
|
||||
<table><tr><td>
|
||||
<ul>
|
||||
<li><a href="health/processors/"><img src="images/icons/processors.png" border="0" align="absmiddle" /> Processors</a></li>
|
||||
<li><a href="health/processors/"><img src="images/icons/processors.png" border="0" align="absmiddle" /> Processors</a></li>
|
||||
<li><a href="health/memory/"><img src="images/icons/memory.png" border="0" align="absmiddle" /> Memory</a></li>
|
||||
<li><a href="health/storage/"><img src="images/icons/storage.png" border="0" align="absmiddle" /> Storage</a></li>
|
||||
<li><hr width=140 /></li>
|
||||
@@ -233,7 +227,8 @@ if ($deleted_ports) { echo('<li><a href="ports/deleted/"><img src="images/16/cro
|
||||
|
||||
<?php
|
||||
|
||||
if ($_SESSION['userlevel'] >= '5' && (isset($config['enable_bgp']) && $config['enable_bgp'])) {
|
||||
if ($_SESSION['userlevel'] >= '5' && (isset($config['enable_bgp']) && $config['enable_bgp']))
|
||||
{
|
||||
echo('
|
||||
<li><a class="menu2four" href="bgp/"><img src="images/16/link.png" border="0" align="absmiddle" /> BGP Sessions</a>
|
||||
<table><tr><td>
|
||||
@@ -244,14 +239,15 @@ echo('
|
||||
<li><a href="bgp/external/"><img src="images/16/world_link.png" border="0" align="absmiddle" /> External BGP</a></li>
|
||||
<li><a href="bgp/internal/"><img src="images/16/brick_link.png" border="0" align="absmiddle" /> Internal BGP</a></li>');
|
||||
|
||||
if ($bgp_alerts) { echo('
|
||||
if ($bgp_alerts)
|
||||
{
|
||||
echo('
|
||||
<li><hr width="140" /></li>
|
||||
<li><a href="bgp/alerts/"><img src="images/16/link_error.png" border="0" align="absmiddle" /> Alerted (' . $bgp_alerts . ')</a></li>
|
||||
'); }
|
||||
');
|
||||
}
|
||||
|
||||
echo(' <li><hr /></li>
|
||||
|
||||
|
||||
</ul>
|
||||
</td></tr></table>
|
||||
</li>
|
||||
@@ -280,7 +276,7 @@ echo(' <li><hr /></li>
|
||||
if (auth_usermanagement())
|
||||
{
|
||||
echo('
|
||||
<li><a href="adduser/"><img src="images/16/user_add.png" border="0" align="absmiddle" /> Add User</a></li>
|
||||
<li><a href="adduser/"><img src="images/16/user_add.png" border="0" align="absmiddle" /> Add User</a></li>
|
||||
<li><a href="deluser/"><img src="images/16/user_delete.png" border="0" align="absmiddle" /> Remove User</a></li>
|
||||
<li><a href="?page=edituser"><img src="images/16/user_edit.png" border="0" align="absmiddle" /> Edit User</a></li>
|
||||
<li><hr width="140" /></li>');
|
||||
|
||||
Reference in New Issue
Block a user