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:
Tom Laermans
2011-03-31 17:19:54 +00:00
parent 28e03f65ea
commit b7720135e9
12 changed files with 382 additions and 319 deletions

View File

@@ -124,7 +124,7 @@ function permissions_cache($user_id)
function bill_permitted($bill_id) function bill_permitted($bill_id)
{ {
global $_SESSION, $permissions; global $permissions;
if ($_SESSION['userlevel'] >= "5") { if ($_SESSION['userlevel'] >= "5") {
$allowed = TRUE; $allowed = TRUE;
@@ -139,7 +139,7 @@ function bill_permitted($bill_id)
function port_permitted($interface_id, $device_id = NULL) 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); } 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) function application_permitted($app_id, $device_id = NULL)
{ {
global $_SESSION, $permissions; global $permissions;
if (is_numeric($app_id)) if (is_numeric($app_id))
{ {
if (!$device_id) { $device_id = device_by_id_cache ($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) function device_permitted($device_id)
{ {
global $_SESSION, $permissions; global $permissions;
if ($_SESSION['userlevel'] >= "5") if ($_SESSION['userlevel'] >= "5")
{ {
@@ -355,4 +355,42 @@ function devclass($device)
return $class; 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;
}
?> ?>

View File

@@ -1,43 +1,52 @@
<?php <?php
if ($bg == $list_colour_b) { $bg = $list_colour_a; } else { $bg = $list_colour_b; } 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['status'] == '0') { $class = "list-device-down"; $bg_image = "images/warning-background.png"; } else { $class = "list-device"; unset ($bg_image); }
if ($device['ignore'] == '1') { if ($device['ignore'] == '1')
$class = "list-device-ignored"; {
if ($device['status'] == '1') { $class = "list-device-ignored-up"; } $class = "list-device-ignored";
} if ($device['status'] == '1') { $class = "list-device-ignored-up"; }
}
$type = strtolower($device['os']); $type = strtolower($device['os']);
unset($image); unset($image);
$image = getImage($device['device_id']); $image = getImage($device['device_id']);
if ($device['os'] == "ios") { formatCiscoHardware($device, true); } if ($device['os'] == "ios") { formatCiscoHardware($device, true); }
$device['os_text'] = $config['os'][$device['os']]['text']; $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); $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); $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 . '\';" 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;"> onclick="location.href=\'/device/'.$device['device_id'].'/\'" style="cursor: pointer;">
<td width="40" align="center" valign="middle">' . $image . '</td> <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> <td width="300"><span style="font-weight: bold; font-size: 14px;">' . generate_device_link($device) . '</span>
<br />' . $device['sysName'] . '</td> <br />' . $device['sysName'] . '</td>
<td width=55>'); <td width=55>');
if ($port_count) { echo(' <img src="images/icons/port.png" align=absmiddle /> '.$port_count); } if ($port_count) { echo(' <img src="images/icons/port.png" align=absmiddle /> '.$port_count); }
echo('<br />'); echo('<br />');
if ($sensor_count) { echo(' <img src="images/icons/sensors.png" align=absmiddle /> '.$sensor_count); } if ($sensor_count) { echo(' <img src="images/icons/sensors.png" align=absmiddle /> '.$sensor_count); }
echo(' </td> echo(' </td>
<td width="200">' . $device['os_text'] . '<br /> <td width="200">' . $device['os_text'] . '<br />
' . $device['version'] . '</td> ' . $device['version'] . '</td>
<td width="200">' . $device['hardware'] . '<br /> <td width="200">' . $device['hardware'] . '<br />
' . $device['features'] . '</td> ' . $device['features'] . '</td>
<td>' . formatUptime($device['uptime']) . ' <td>' . formatUptime($device['uptime']) . '
<br /> <br />');
' . $device['location'] . '</td> if (get_dev_attrib($device,'override_sysLocation_bool'))
<td width="10"> {
</td> echo(get_dev_attrib($device,'override_sysLocation_string'));
</tr>'); }
else
{
echo($device['location']);
}
echo('</td>
<td width="10">
</td>
</tr>');
?> ?>

View File

@@ -1,27 +1,30 @@
<?php <?php
$service_alerts = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_status = '0'"),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); $if_alerts = mysql_result(mysql_query("SELECT count(*) FROM `ports` WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND `ignore` = '0'"),0);
$device_alerts = "0"; $device_alerts = "0";
$device_alert_sql = "WHERE 0"; $device_alert_sql = "WHERE 0";
if (isset($config['enable_bgp']) && $config['enable_bgp']) 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); $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`"); $query_a = mysql_query("SELECT * FROM `devices`");
while ($device = mysql_fetch_array($query_a)) { while ($device = mysql_fetch_array($query_a))
$this_alert = 0; {
if ($device['status'] == 0 && $device['ignore'] == '0') { $this_alert = "1"; } elseif ($device['ignore'] == '0') { $this_alert = 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 ($device['status'] == 0 && $device['ignore'] == '0') { $this_alert = "1"; } elseif ($device['ignore'] == '0')
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 (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 ($this_alert) { 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"; }
$device_alerts++;
$device_alert_sql .= " OR `device_id` = '" . $device['device_id'] . "'";
}
} }
if ($this_alert)
{
$device_alerts++;
$device_alert_sql .= " OR `device_id` = '" . $device['device_id'] . "'";
}
}
?> ?>
<div class="menu2"> <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>'); 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> <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']) { <?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>'); 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="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> <li><a href="inventory/"><img src="images/16/bricks.png" border="0" align="absmiddle" /> Inventory</a></li>
</ul> </ul>
@@ -59,7 +62,7 @@ foreach ($config['device_types'] as $devtype)
?> ?>
<li><hr width="140" /></li> <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 <?php
if ($_SESSION['userlevel'] >= '10') { if ($_SESSION['userlevel'] >= '10') {
echo(' echo('
@@ -104,11 +107,6 @@ if ($_SESSION['userlevel'] >= '10') {
## Display Locations entry if $config['show_locations'] ## Display Locations entry if $config['show_locations']
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> <li><a class="menu2four" href="locations/"><img src="images/16/building.png" border="0" align="absmiddle" /> Locations</a>
<?php <?php
@@ -118,12 +116,9 @@ if ($config['show_locations'])
<table><tr><td> <table><tr><td>
<ul> <ul>
<?php <?php
while ($row = mysql_fetch_array($locations)) foreach (getlocations() as $location)
{ {
if ($row['location'] != '') echo(' <li><a href="?page=devices&amp;location=' . urlencode($location) . '"><img src="images/16/building.png" border="0" align="absmiddle" /> ' . $location . ' </a></li>');
{
echo(' <li><a href="?page=devices&amp;location=' . urlencode($row['location']) . '"><img src="images/16/building.png" border="0" align="absmiddle" /> ' . $row['location'] . ' </a></li>');
}
} }
?> ?>
</ul> </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> <li><a class="menu2four" href="ports/"><img src="images/16/connect.png" border="0" align="absmiddle" /> Ports</a>
<table><tr><td> <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]--> <!--[if IE 7]><!--></a><!--<![endif]-->
<table><tr><td> <table><tr><td>
<ul> <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/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><a href="health/storage/"><img src="images/icons/storage.png" border="0" align="absmiddle" /> Storage</a></li>
<li><hr width=140 /></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 <?php
if ($_SESSION['userlevel'] >= '5' && (isset($config['enable_bgp']) && $config['enable_bgp'])) { if ($_SESSION['userlevel'] >= '5' && (isset($config['enable_bgp']) && $config['enable_bgp']))
{
echo(' echo('
<li><a class="menu2four" href="bgp/"><img src="images/16/link.png" border="0" align="absmiddle" /> BGP Sessions</a> <li><a class="menu2four" href="bgp/"><img src="images/16/link.png" border="0" align="absmiddle" /> BGP Sessions</a>
<table><tr><td> <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/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>'); <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><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> <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> echo(' <li><hr /></li>
</ul> </ul>
</td></tr></table> </td></tr></table>
</li> </li>
@@ -280,7 +276,7 @@ echo(' <li><hr /></li>
if (auth_usermanagement()) if (auth_usermanagement())
{ {
echo(' 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="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><a href="?page=edituser"><img src="images/16/user_edit.png" border="0" align="absmiddle" /> Edit User</a></li>
<li><hr width="140" /></li>'); <li><hr width="140" /></li>');

View File

@@ -21,180 +21,176 @@ if (device_permitted($_GET['id']) || $check_device == $_GET['id'])
$select[$section] = "selected"; $select[$section] = "selected";
$device_query = mysql_query("SELECT * FROM `devices` WHERE `device_id` = '" . $_GET['id'] . "'"); $device = device_by_id_cache($_GET['id']);
# FIXME device_by_id_cache ? if ($config['os'][$device['os']]['group']) { $device['os_group'] = $config['os'][$device['os']]['group']; }
while ($device = mysql_fetch_array($device_query))
echo('<table cellpadding="15" cellspacing="0" class="devicetable" width="100%">');
include("includes/device-header.inc.php");
echo('</table>');
echo('<div class="mainpane">');
echo(' <ul id="maintab" class="shadetabs">');
if (device_permitted($device['device_id']))
{ {
if ($config['os'][$device['os']]['group']) { $device['os_group'] = $config['os'][$device['os']]['group']; } if ($config['show_overview_tab'])
echo('<table cellpadding="15" cellspacing="0" class="devicetable" width="100%">');
include("includes/device-header.inc.php");
echo('</table>');
echo('<div class="mainpane">');
echo(' <ul id="maintab" class="shadetabs">');
if (device_permitted($device['device_id']))
{ {
if ($config['show_overview_tab']) echo('
{
echo('
<li class="' . $select['overview'] . '"> <li class="' . $select['overview'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/overview/"> <a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/overview/">
<img src="images/16/server_lightning.png" align="absmiddle" border="0"> Overview <img src="images/16/server_lightning.png" align="absmiddle" border="0"> Overview
</a> </a>
</li>'); </li>');
} }
echo('<li class="' . $select['graphs'] . '"> echo('<li class="' . $select['graphs'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/graphs/"> <a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/graphs/">
<img src="images/16/server_chart.png" align="absmiddle" border="0"> Graphs <img src="images/16/server_chart.png" align="absmiddle" border="0"> Graphs
</a> </a>
</li>'); </li>');
$health = mysql_result(mysql_query("select count(*) from storage WHERE device_id = '" . $device['device_id'] . "'"), 0) + $health = mysql_result(mysql_query("select count(*) from storage WHERE device_id = '" . $device['device_id'] . "'"), 0) +
mysql_result(mysql_query("select count(sensor_id) from sensors WHERE device_id = '" . $device['device_id'] . "'"), 0) + mysql_result(mysql_query("select count(sensor_id) from sensors WHERE device_id = '" . $device['device_id'] . "'"), 0) +
mysql_result(mysql_query("select count(*) from cempMemPool WHERE device_id = '" . $device['device_id'] . "'"), 0) + mysql_result(mysql_query("select count(*) from cempMemPool WHERE device_id = '" . $device['device_id'] . "'"), 0) +
mysql_result(mysql_query("select count(*) from cpmCPU WHERE device_id = '" . $device['device_id'] . "'"), 0) + mysql_result(mysql_query("select count(*) from cpmCPU WHERE device_id = '" . $device['device_id'] . "'"), 0) +
mysql_result(mysql_query("select count(*) from processors WHERE device_id = '" . $device['device_id'] . "'"), 0) + mysql_result(mysql_query("select count(*) from processors WHERE device_id = '" . $device['device_id'] . "'"), 0) +
mysql_result(mysql_query("select count(current_id) from current WHERE device_id = '" . $device['device_id'] . "'"), 0) + mysql_result(mysql_query("select count(current_id) from current WHERE device_id = '" . $device['device_id'] . "'"), 0) +
mysql_result(mysql_query("select count(freq_id) from frequencies WHERE device_id = '" . $device['device_id'] . "'"), 0) + mysql_result(mysql_query("select count(freq_id) from frequencies WHERE device_id = '" . $device['device_id'] . "'"), 0) +
mysql_result(mysql_query("select count(volt_id) from voltage WHERE device_id = '" . $device['device_id'] . "'"), 0) + mysql_result(mysql_query("select count(volt_id) from voltage WHERE device_id = '" . $device['device_id'] . "'"), 0) +
mysql_result(mysql_query("select count(fan_id) from fanspeed WHERE device_id = '" . $device['device_id'] . "'"), 0); mysql_result(mysql_query("select count(fan_id) from fanspeed WHERE device_id = '" . $device['device_id'] . "'"), 0);
if ($health) if ($health)
{ {
echo('<li class="' . $select['health'] . '"> echo('<li class="' . $select['health'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/health/"> <a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/health/">
<img src="images/icons/sensors.png" align="absmiddle" border="0" /> Health <img src="images/icons/sensors.png" align="absmiddle" border="0" /> Health
</a> </a>
</li>'); </li>');
} }
if (@mysql_result(mysql_query("select count(app_id) from applications WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') if (@mysql_result(mysql_query("select count(app_id) from applications WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0')
{ {
echo('<li class="' . $select['apps'] . '"> echo('<li class="' . $select['apps'] . '">
<a href="' . $config['base_url'] . '/device/' . $device['device_id'] . '/apps/"> <a href="' . $config['base_url'] . '/device/' . $device['device_id'] . '/apps/">
<img src="images/icons/apps.png" align="absmiddle" border="0" /> Apps <img src="images/icons/apps.png" align="absmiddle" border="0" /> Apps
</a> </a>
</li>'); </li>');
} }
if (is_dir($config['collectd_dir'] . "/" . $device['hostname'] ."/")) if (is_dir($config['collectd_dir'] . "/" . $device['hostname'] ."/"))
{ {
echo('<li class="' . $select['collectd'] . '"> echo('<li class="' . $select['collectd'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/collectd/"> <a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/collectd/">
<img src="images/16/chart_line.png" align="absmiddle" border="0" /> CollectD <img src="images/16/chart_line.png" align="absmiddle" border="0" /> CollectD
</a> </a>
</li>'); </li>');
} }
if (@mysql_result(mysql_query("select count(interface_id) from ports WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') if (@mysql_result(mysql_query("select count(interface_id) from ports WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0')
{ {
echo('<li class="' . $select['ports'] . '"> echo('<li class="' . $select['ports'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/ports/' .$config['ports_page_default']. '"> <a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/ports/' .$config['ports_page_default']. '">
<img src="images/16/connect.png" align="absmiddle" border="0" /> Ports <img src="images/16/connect.png" align="absmiddle" border="0" /> Ports
</a> </a>
</li>'); </li>');
} }
if (@mysql_result(mysql_query("select count(vlan_id) from vlans WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') if (@mysql_result(mysql_query("select count(vlan_id) from vlans WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0')
{ {
echo('<li class="' . $select['vlans'] . '"> echo('<li class="' . $select['vlans'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/vlans/"> <a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/vlans/">
<img src="images/16/vlans.png" align="absmiddle" border="0" /> VLANs <img src="images/16/vlans.png" align="absmiddle" border="0" /> VLANs
</a> </a>
</li>'); </li>');
} }
if (@mysql_result(mysql_query("SELECT COUNT(id) FROM vmware_vminfo WHERE device_id = '" . $device["device_id"] . "'"), 0) > '0') if (@mysql_result(mysql_query("SELECT COUNT(id) FROM vmware_vminfo WHERE device_id = '" . $device["device_id"] . "'"), 0) > '0')
{ {
echo('<li class="' . $select['vm'] . '"> echo('<li class="' . $select['vm'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/vm/"> <a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/vm/">
<img src="images/16/server_cog.png" align="absmiddle" border="0" /> Virtual Machines <img src="images/16/server_cog.png" align="absmiddle" border="0" /> Virtual Machines
</a> </a>
</li>'); </li>');
} }
if (@mysql_result(mysql_query("select count(*) from vrfs WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') if (@mysql_result(mysql_query("select count(*) from vrfs WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0')
{ {
echo('<li class="' . $select['vrfs'] . '"> echo('<li class="' . $select['vrfs'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/vrfs/"> <a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/vrfs/">
<img src="images/16/layers.png" align="absmiddle" border="0" /> VRFs <img src="images/16/layers.png" align="absmiddle" border="0" /> VRFs
</a> </a>
</li>'); </li>');
} }
if ($config['enable_bgp'] && $device['bgpLocalAs']) if ($config['enable_bgp'] && $device['bgpLocalAs'])
{ {
echo('<li class="' . $select['bgp'] . '"> echo('<li class="' . $select['bgp'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/bgp/"> <a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/bgp/">
<img src="images/16/link.png" align="absmiddle" border="0" /> BGP <img src="images/16/link.png" align="absmiddle" border="0" /> BGP
</a> </a>
</li>'); </li>');
} }
if ($_SESSION['userlevel'] >= "5" && mysql_result(mysql_query("SELECT count(*) FROM links AS L, ports AS I WHERE I.device_id = '".$device['device_id']."' AND I.interface_id = L.local_interface_id"),0)) if ($_SESSION['userlevel'] >= "5" && mysql_result(mysql_query("SELECT count(*) FROM links AS L, ports AS I WHERE I.device_id = '".$device['device_id']."' AND I.interface_id = L.local_interface_id"),0))
{ {
echo('<li class="' . $select['map'] . '"> echo('<li class="' . $select['map'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/map/"> <a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/map/">
<img src="images/16/chart_organisation.png" align="absmiddle" border="0" /> Map <img src="images/16/chart_organisation.png" align="absmiddle" border="0" /> Map
</a> </a>
</li>'); </li>');
} }
if ($config['enable_inventory'] && @mysql_result(mysql_query("SELECT * FROM `entPhysical` WHERE device_id = '".$device['device_id']."'"), 0) > '0') if ($config['enable_inventory'] && @mysql_result(mysql_query("SELECT * FROM `entPhysical` WHERE device_id = '".$device['device_id']."'"), 0) > '0')
{ {
echo('<li class="' . $select['entphysical'] . '"> echo('<li class="' . $select['entphysical'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/entphysical/"> <a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/entphysical/">
<img src="images/16/bricks.png" align="absmiddle" border="0" /> Inventory <img src="images/16/bricks.png" align="absmiddle" border="0" /> Inventory
</a> </a>
</li>'); </li>');
} }
elseif (device_permitted($device['device_id']) && $config['enable_inventory'] && @mysql_result(mysql_query("SELECT * FROM `hrDevice` WHERE device_id = '".$device['device_id']."'"), 0) > '0') elseif (device_permitted($device['device_id']) && $config['enable_inventory'] && @mysql_result(mysql_query("SELECT * FROM `hrDevice` WHERE device_id = '".$device['device_id']."'"), 0) > '0')
{ {
echo('<li class="' . $select['hrdevice'] . '"> echo('<li class="' . $select['hrdevice'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/hrdevice/"> <a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/hrdevice/">
<img src="images/16/bricks.png" align="absmiddle" border="0" /> Inventory <img src="images/16/bricks.png" align="absmiddle" border="0" /> Inventory
</a> </a>
</li>'); </li>');
} }
if (mysql_result(mysql_query("select count(service_id) from services WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') if (mysql_result(mysql_query("select count(service_id) from services WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0')
{ {
echo('<li class="' . $select['srv'] . '"> echo('<li class="' . $select['srv'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/srv/"> <a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/srv/">
<img src="images/icons/services.png" align="absmiddle" border="0" /> Services <img src="images/icons/services.png" align="absmiddle" border="0" /> Services
</a> </a>
</li>'); </li>');
} }
if (@mysql_result(mysql_query("select count(toner_id) from toner WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') if (@mysql_result(mysql_query("select count(toner_id) from toner WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0')
{ {
echo('<li class="' . $select['toner'] . '"> echo('<li class="' . $select['toner'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/toner/"> <a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/toner/">
<img src="images/icons/toner.png" align="absmiddle" border="0" /> Toner <img src="images/icons/toner.png" align="absmiddle" border="0" /> Toner
</a> </a>
</li>'); </li>');
} }
if (device_permitted($device['device_id'])) if (device_permitted($device['device_id']))
{ {
echo('<li class="' . $select['events'] . '"> echo('<li class="' . $select['events'] . '">
<a href="'.$config['base_url']. "/device/" . $device['device_id'] . '/events/"> <a href="'.$config['base_url']. "/device/" . $device['device_id'] . '/events/">
<img src="images/16/report_magnify.png" align="absmiddle" border="0" /> Events <img src="images/16/report_magnify.png" align="absmiddle" border="0" /> Events
</a> </a>
</li>'); </li>');
} }
if ($config['enable_syslog']) if ($config['enable_syslog'])
{ {
echo('<li class="' . $select['syslog'] . '"> echo('<li class="' . $select['syslog'] . '">
<a href="'.$config['base_url']."/device/" . $device['device_id'] . '/syslog/"> <a href="'.$config['base_url']."/device/" . $device['device_id'] . '/syslog/">
<img src="images/16/printer.png" align="absmiddle" border="0" /> Syslog <img src="images/16/printer.png" align="absmiddle" border="0" /> Syslog
</a> </a>
</li>'); </li>');
}
} }
if ($_SESSION['userlevel'] >= "7") if ($_SESSION['userlevel'] >= "7")

View File

@@ -15,6 +15,10 @@ if ($_POST['editing'])
$update_message = "Device alert settings updated."; $update_message = "Device alert settings updated.";
$updated = 1; $updated = 1;
} }
else
{
include("includes/error-no-perm.inc.php");
}
} }
if ($updated && $update_message) if ($updated && $update_message)

View File

@@ -4,11 +4,25 @@ if ($_POST['editing'])
{ {
if ($_SESSION['userlevel'] > "7") if ($_SESSION['userlevel'] > "7")
{ {
$updated = 0;
$descr = mres($_POST['descr']); $descr = mres($_POST['descr']);
$ignore = mres($_POST['ignore']); $ignore = mres($_POST['ignore']);
$type = mres($_POST['type']); $type = mres($_POST['type']);
$disabled = mres($_POST['disabled']); $disabled = mres($_POST['disabled']);
$override_sysLocation_bool = mres($_POST['override_sysLocation']);
if (isset($_POST['sysLocation'])) { $override_sysLocation_string = mres($_POST['sysLocation']); }
if (get_dev_attrib($device,'override_sysLocation_bool') != $override_sysLocation_bool
|| get_dev_attrib($device,'override_sysLocation_string') != $override_sysLocation_string)
{
$updated = 1;
}
if ($override_sysLocation_bool) { set_dev_attrib($device, 'override_sysLocation_bool', '1'); } else { del_dev_attrib($device, 'override_sysLocation_bool'); }
if (isset($override_sysLocation_string)) { set_dev_attrib($device, 'override_sysLocation_string', $override_sysLocation_string); };
#FIXME needs more sanity checking! and better feedback #FIXME needs more sanity checking! and better feedback
$sql = "UPDATE `devices` SET `purpose` = '" . $descr . "', `type` = '$type'"; $sql = "UPDATE `devices` SET `purpose` = '" . $descr . "', `type` = '$type'";
$sql .= ", `ignore` = '$ignore', `disabled` = '$disabled'"; $sql .= ", `ignore` = '$ignore', `disabled` = '$disabled'";
@@ -26,14 +40,19 @@ if ($_POST['editing'])
$updated = -1; $updated = -1;
} else { } else {
$update_message = "Device record update error."; $update_message = "Device record update error.";
$updated = 0;
} }
} }
else
{
include("includes/error-no-perm.inc.php");
}
} }
$device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '".$device['device_id']."'"));
$descr = $device['purpose']; $descr = $device['purpose'];
$override_sysLocation_bool = get_dev_attrib($device,'override_sysLocation_bool');
$override_sysLocation_string = get_dev_attrib($device,'override_sysLocation_string');
if ($updated && $update_message) if ($updated && $update_message)
{ {
print_message($update_message); print_message($update_message);
@@ -41,29 +60,31 @@ if ($updated && $update_message)
print_error($update_message); print_error($update_message);
} }
echo("<table cellpadding=0 cellspacing=0><tr><td> ?>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<h5>
<a href="?page=delhost&id="<?php echo($device['device_id']) ?>">
<img src="images/16/server_delete.png" align="absmiddle">
Delete
</a>
</h5>
<h5> <form id="edit" name="edit" method="post" action="">
<a href='?page=delhost&id=".$device['device_id']."'> <input type=hidden name="editing" value="yes">
<img src='images/16/server_delete.png' align='absmiddle'> <table width="500" border="0">
Delete
</a>
</h5>
<form id='edit' name='edit' method='post' action=''>
<input type=hidden name='editing' value='yes'>
<table width='400' border='0'>
<tr> <tr>
<td><div align='right'>Description</div></td> <td colspan="2" align="right">Description:</td>
<td colspan='3'><input name='descr' size='32' value='" . $device['purpose'] . "'></input></td> <td colspan="3"><input name="descr" size="32" value="<?php echo($device['purpose']); ?>"></input></td>
</tr> </tr>
<tr> <tr>
<td align='right'> <td colspan="2" align="right">
Type Type:
</td> </td>
<td> <td>
<select name='type'>"); <select name="type">
<?php
$unknown = 1; $unknown = 1;
foreach ($device_types as $type) foreach ($device_types as $type)
{ {
@@ -79,22 +100,21 @@ foreach ($device_types as $type)
{ {
echo(' <option value="other">Other</option>'); echo(' <option value="other">Other</option>');
} }
echo(" ?>
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr>
<td><div align='right'>Disable</div></td> <td width="40"><div style="padding-right: 5px; text-align: right"><input onclick="edit.sysLocation.disabled=!edit.override_sysLocation.checked" type="checkbox" name="override_sysLocation"<?php if ($override_sysLocation_bool) { echo(' checked="1"'); } ?> /></div></td>
<td><input name='disabled' type='checkbox' id='disabled' value='1'"); <td width="150" align="right">Override sysLocation:</td>
if ($device['disabled']) { echo("checked=checked"); } <td><input name="sysLocation" size="32"<?php if (!$override_sysLocation_bool) { echo(' disabled="1"'); } ?> value="<?php echo($override_sysLocation_string); ?>" /></td>
echo("/></td> </tr>
<td><div align='right'>Ignore</div></td> <tr>
<td><input name='ignore' type='checkbox' id='disable' value='1'"); <td colspan="2"><div align="right">Disable</div></td>
if ($device['ignore']) { echo("checked=checked"); } <td><input name="disabled" type="checkbox" id="disabled" value="1" <?php if ($device["disabled"]) { echo("checked=checked"); } ?> /></td>
echo("/></td> <td><div align="right">Ignore</div></td>
</tr>"); <td><input name="ignore" type="checkbox" id="disable" value="1" <?php if ($device['ignore']) { echo("checked=checked"); } ?> /></td>
</tr>
echo('
</table> </table>
<input type="submit" name="Submit" value="Save" /> <input type="submit" name="Submit" value="Save" />
<label><br /> <label><br />
@@ -102,6 +122,4 @@ echo('
</form> </form>
</td> </td>
<td width="50"></td><td></td></tr></table>'); <td width="50"></td><td></td></tr></table>
?>

View File

@@ -15,6 +15,10 @@ if ($_POST['editing'])
$update_message = "Device IPMI data updated."; $update_message = "Device IPMI data updated.";
$updated = 1; $updated = 1;
} }
else
{
include("includes/error-no-perm.inc.php");
}
} }
if ($updated && $update_message) if ($updated && $update_message)

View File

@@ -5,10 +5,14 @@ if ($_POST['os']) { $where = " AND os = '".mres($_POST['os'])."'"; }
if ($_POST['version']) { $where .= " AND version = '".mres($_POST['version'])."'"; } if ($_POST['version']) { $where .= " AND version = '".mres($_POST['version'])."'"; }
if ($_POST['hardware']) { $where .= " AND hardware = '".mres($_POST['hardware'])."'"; } if ($_POST['hardware']) { $where .= " AND hardware = '".mres($_POST['hardware'])."'"; }
if ($_POST['features']) { $where .= " AND features = '".mres($_POST['features'])."'"; } if ($_POST['features']) { $where .= " AND features = '".mres($_POST['features'])."'"; }
if ($_POST['location']) { $where .= " AND location = '".mres($_POST['location'])."'"; }
if ($_GET['location'] && !isset($_POST['location'])) { $where .= " AND location = '".mres($_GET['location'])."'"; } # FIXME override
if ($_GET['type']) { $where = "AND type = '" .mres($_GET[type]). "'"; } if (isset($_REQUEST['location']))
if ($_GET['location'] == "Unset") { $where .= " AND location = ''"; } {
if ($_GET['location'] == "Unset") { $location_filter = ''; }
if ($_GET['location'] && !isset($_POST['location'])) { $location_filter = $_GET['location']; }
if ($_POST['location']) { $location_filter = $_POST['location']; }
}
print_optionbar_start(62); print_optionbar_start(62);
?> ?>
@@ -23,32 +27,32 @@ print_optionbar_start(62);
<select name='os' id='os'> <select name='os' id='os'>
<option value=''>All OSes</option> <option value=''>All OSes</option>
<?php <?php
$query = mysql_query("SELECT `os` FROM `devices` WHERE 1 $where GROUP BY `os` ORDER BY `os`"); $query = mysql_query("SELECT `os` FROM `devices` AS D WHERE 1 GROUP BY `os` ORDER BY `os`");
while ($data = mysql_fetch_array($query)) while ($data = mysql_fetch_array($query))
{ {
if ($data['os']) if ($data['os'])
{ {
echo("<option value='".$data['os']."'"); echo("<option value='".$data['os']."'");
if ($data['os'] == $_POST['os']) { echo(" selected"); } if ($data['os'] == $_POST['os']) { echo(" selected"); }
echo(">".$config['os'][$data['os']]['text']."</option>"); echo(">".$config['os'][$data['os']]['text']."</option>");
} }
} }
?> ?>
</select> </select>
<br /> <br />
<select name='version' id='version'> <select name='version' id='version'>
<option value=''>All Versions</option> <option value=''>All Versions</option>
<?php <?php
$query = mysql_query("SELECT `version` FROM `devices` WHERE 1 $where GROUP BY `version` ORDER BY `version`"); $query = mysql_query("SELECT `version` FROM `devices` AS D WHERE 1 GROUP BY `version` ORDER BY `version`");
while ($data = mysql_fetch_array($query)) while ($data = mysql_fetch_array($query))
{ {
if ($data['version']) if ($data['version'])
{ {
echo("<option value='".$data['version']."'"); echo("<option value='".$data['version']."'");
if ($data['version'] == $_POST['version']) { echo(" selected"); } if ($data['version'] == $_POST['version']) { echo(" selected"); }
echo(">".$data['version']."</option>"); echo(">".$data['version']."</option>");
} }
} }
?> ?>
</select> </select>
</td> </td>
@@ -56,32 +60,32 @@ print_optionbar_start(62);
<select name="hardware" id="hardware"> <select name="hardware" id="hardware">
<option value="">All Platforms</option> <option value="">All Platforms</option>
<?php <?php
$query = mysql_query("SELECT `hardware` FROM `devices` WHERE 1 $where GROUP BY `hardware` ORDER BY `hardware`"); $query = mysql_query("SELECT `hardware` FROM `devices` AS D WHERE 1 GROUP BY `hardware` ORDER BY `hardware`");
while ($data = mysql_fetch_array($query)) while ($data = mysql_fetch_array($query))
{ {
if ($data['hardware']) if ($data['hardware'])
{ {
echo('<option value="'.$data['hardware'].'"'); echo('<option value="'.$data['hardware'].'"');
if ($data['hardware'] == $_POST['hardware']) { echo(" selected"); } if ($data['hardware'] == $_POST['hardware']) { echo(" selected"); }
echo(">".$data['hardware']."</option>"); echo(">".$data['hardware']."</option>");
} }
} }
?> ?>
</select> </select>
<br /> <br />
<select name="features" id="features"> <select name="features" id="features">
<option value="">All Featuresets</option> <option value="">All Featuresets</option>
<?php <?php
$query = mysql_query("SELECT `features` FROM `devices` WHERE 1 $where GROUP BY `features` ORDER BY `features`"); $query = mysql_query("SELECT `features` FROM `devices` AS D WHERE 1 GROUP BY `features` ORDER BY `features`");
while ($data = mysql_fetch_array($query)) while ($data = mysql_fetch_array($query))
{ {
if ($data['features']) if ($data['features'])
{ {
echo('<option value="'.$data['features'].'"'); echo('<option value="'.$data['features'].'"');
if ($data['features'] == $_POST['features']) { echo(" selected"); } if ($data['features'] == $_POST['features']) { echo(" selected"); }
echo(">".$data['features']."</option>"); echo(">".$data['features']."</option>");
} }
} }
?> ?>
</select> </select>
</td> </td>
@@ -89,23 +93,15 @@ print_optionbar_start(62);
<select name="location" id="location"> <select name="location" id="location">
<option value="">All Locations</option> <option value="">All Locations</option>
<?php <?php
foreach (getlocations() as $location)
if($_SESSION['userlevel'] >= '5') {
{ if ($location)
$query = mysql_query("SELECT location FROM devices WHERE 1 $where GROUP BY location ORDER BY location"); {
} else { echo('<option value="'.$location.'"');
$query = mysql_query("SELECT location FROM devices AS D, devices_perms AS P WHERE 1 $where AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' GROUP BY location ORDER BY location"); if ($location == $_POST['location']) { echo(" selected"); }
} echo(">".$location."</option>");
}
while ($data = mysql_fetch_array($query)) }
{
if ($data['location'])
{
echo('<option value="'.$data['location'].'"');
if ($data['location'] == $_POST['location']) { echo(" selected"); }
echo(">".$data['location']."</option>");
}
}
?> ?>
</select> </select>
<input class="submit" type="submit" class="submit" value="Search"> <input class="submit" type="submit" class="submit" value="Search">
@@ -128,11 +124,15 @@ echo('<table cellpadding="7" cellspacing="0" class="devicetable sortable" width=
<tr class="tablehead"><th></th><th>Device</th><th></th><th>Operating System</th><th>Platform</th><th>Uptime</th></tr>'); <tr class="tablehead"><th></th><th>Device</th><th></th><th>Operating System</th><th>Platform</th><th>Uptime</th></tr>');
$device_query = mysql_query($sql); $device_query = mysql_query($sql);
while ($device = mysql_fetch_array($device_query)) while ($device = mysql_fetch_assoc($device_query))
{ {
if (device_permitted($device['device_id'])) if (device_permitted($device['device_id']))
{ {
include("includes/hostbox.inc.php"); if (!$location_filter || ((get_dev_attrib($device,'override_sysLocation_bool') && get_dev_attrib($device,'override_sysLocation_string') == $location_filter)
|| $device['location'] == $location_filter))
{
include("includes/hostbox.inc.php");
}
} }
} }

View File

@@ -1,39 +1,31 @@
<?php <?php
echo('<table cellpadding="7" cellspacing="0" class="devicetable" width="100%">'); echo('<table cellpadding="7" cellspacing="0" class="devicetable" width="100%">');
if ($_SESSION['userlevel'] >= '5') foreach (getlocations() as $location)
{
$sql = "SELECT `location` FROM `devices` GROUP BY `location` ORDER BY `location`";
} else {
$sql = "SELECT `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`";
}
$device_query = mysql_query($sql);
while ($device = mysql_fetch_array($device_query))
{ {
if (!isset($bg) || $bg == "#ffffff") { $bg = "#eeeeee"; } else { $bg="#ffffff"; } if (!isset($bg) || $bg == "#ffffff") { $bg = "#eeeeee"; } else { $bg="#ffffff"; }
if ($_SESSION['userlevel'] == '10') if ($_SESSION['userlevel'] == '10')
{ {
$num = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "'"),0); $num = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $location . "'"),0);
$net = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "' AND type = 'network'"),0); $net = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $location . "' AND type = 'network'"),0);
$srv = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "' AND type = 'server'"),0); $srv = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $location . "' AND type = 'server'"),0);
$fwl = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "' AND type = 'firewall'"),0); $fwl = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $location . "' AND type = 'firewall'"),0);
$hostalerts = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "' AND status = '0'"),0); $hostalerts = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $location . "' AND status = '0'"),0);
} else { } else {
$num = mysql_result(mysql_query("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $device['location'] . "'"),0); $num = mysql_result(mysql_query("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $location . "'"),0);
$net = mysql_result(mysql_query("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $device['location'] . "' AND D.type = 'network'"),0); $net = mysql_result(mysql_query("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $location . "' AND D.type = 'network'"),0);
$srv = mysql_result(mysql_query("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $device['location'] . "' AND type = 'server'"),0); $srv = mysql_result(mysql_query("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $location . "' AND type = 'server'"),0);
$fwl = mysql_result(mysql_query("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $device['location'] . "' AND type = 'firewall'"),0); $fwl = mysql_result(mysql_query("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $location . "' AND type = 'firewall'"),0);
$hostalerts = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices AS D, devices_perms AS P WHERE location = '" . $device['location'] . "' AND status = '0'"),0); $hostalerts = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices AS D, devices_perms AS P WHERE location = '" . $location . "' AND status = '0'"),0);
} }
if ($hostalerts) { $alert = '<img src="images/16/flag_red.png" alt="alert" />'; } else { $alert = ""; } if ($hostalerts) { $alert = '<img src="images/16/flag_red.png" alt="alert" />'; } else { $alert = ""; }
if ($device['location'] != "") if ($location != "")
{ {
echo(' <tr bgcolor="' . $bg . '"> echo(' <tr bgcolor="' . $bg . '">
<td class="interface" width="300"><a class="list-bold" href="?page=devices&amp;location=' . urlencode($device['location']) . '">' . $device['location'] . '</a></td> <td class="interface" width="300"><a class="list-bold" href="?page=devices&amp;location=' . urlencode($location) . '">' . $location . '</a></td>
<td width="100">' . $alert . '</td> <td width="100">' . $alert . '</td>
<td width="100">' . $num . ' devices</td> <td width="100">' . $num . ' devices</td>
<td width="100">' . $net . ' network</td> <td width="100">' . $net . ' network</td>

View File

@@ -78,6 +78,11 @@ function device_by_id_cache($device_id)
$device = $device_cache[$device_id]; $device = $device_cache[$device_id];
} else { } else {
$device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '".$device_id."'")); $device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '".$device_id."'"));
if (get_dev_attrib($device,'override_sysLocation_bool'))
{
$device['real_location'] = $device['location'];
$device['location'] = get_dev_attrib($device,'override_sysLocation_string');
}
$device_cache[$device_id] = $device; $device_cache[$device_id] = $device;
} }
@@ -192,5 +197,40 @@ function zeropad($num, $length = 2)
return $num; return $num;
} }
function set_dev_attrib($device, $attrib_type, $attrib_value)
{
$count_sql = "SELECT COUNT(*) FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'";
if (mysql_result(mysql_query($count_sql),0))
{
$update_sql = "UPDATE devices_attribs SET attrib_value = '$attrib_value' WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'";
mysql_query($update_sql);
}
else
{
$insert_sql = "INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES ('" . mres($device['device_id'])."', '$attrib_type', '$attrib_value')";
mysql_query($insert_sql);
}
return mysql_affected_rows();
}
function get_dev_attrib($device, $attrib_type)
{
$sql = "SELECT attrib_value FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'";
if ($row = mysql_fetch_assoc(mysql_query($sql)))
{
return $row['attrib_value'];
}
else
{
return NULL;
}
}
function del_dev_attrib($device, $attrib_type)
{
$sql = "DELETE FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'";
return mysql_query($sql);
}
?> ?>

View File

@@ -42,42 +42,6 @@ function logfile($string)
fclose($fd); fclose($fd);
} }
function set_dev_attrib($device, $attrib_type, $attrib_value)
{
$count_sql = "SELECT COUNT(*) FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'";
if (mysql_result(mysql_query($count_sql),0))
{
$update_sql = "UPDATE devices_attribs SET attrib_value = '$attrib_value' WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'";
mysql_query($update_sql);
}
else
{
$insert_sql = "INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES ('" . mres($device['device_id'])."', '$attrib_type', '$attrib_value')";
mysql_query($insert_sql);
}
return mysql_affected_rows();
}
function get_dev_attrib($device, $attrib_type)
{
$sql = "SELECT attrib_value FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'";
if ($row = mysql_fetch_assoc(mysql_query($sql)))
{
return $row['attrib_value'];
}
else
{
return NULL;
}
}
function del_dev_attrib($device, $attrib_type)
{
$sql = "DELETE FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'";
return mysql_query($sql);
}
function shorthost($hostname, $len=16) function shorthost($hostname, $len=16)
{ {
$parts = explode(".", $hostname); $parts = explode(".", $hostname);
@@ -218,8 +182,7 @@ function renamehost($id, $new, $source = 'console')
{ {
global $config; global $config;
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0); # FIXME getdevicebyid? $host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0);
rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new"); rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new");
mysql_query("UPDATE devices SET hostname = '$new' WHERE device_id = '$id'"); mysql_query("UPDATE devices SET hostname = '$new' WHERE device_id = '$id'");
log_event("Hostname changed -> $new ($source)", $id, 'system'); log_event("Hostname changed -> $new ($source)", $id, 'system');

View File

@@ -272,8 +272,11 @@ while ($device = mysql_fetch_assoc($device_query))
if ($sysLocation && $device['location'] != $sysLocation) if ($sysLocation && $device['location'] != $sysLocation)
{ {
$poll_update .= $poll_separator . "`location` = '$sysLocation'"; if (!get_dev_attrib($device,'override_sysLocation_bool'))
$poll_separator = ", "; {
$poll_update .= $poll_separator . "`location` = '$sysLocation'";
$poll_separator = ", ";
}
log_event("Location -> $sysLocation", $device['device_id'], 'system'); log_event("Location -> $sysLocation", $device['device_id'], 'system');
} }