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)
{
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;
}
?>

View File

@@ -2,7 +2,8 @@
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') {
if ($device['ignore'] == '1')
{
$class = "list-device-ignored";
if ($device['status'] == '1') { $class = "list-device-ignored-up"; }
}
@@ -34,8 +35,16 @@
<td width="200">' . $device['hardware'] . '<br />
' . $device['features'] . '</td>
<td>' . formatUptime($device['uptime']) . '
<br />
' . $device['location'] . '</td>
<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>');

View File

@@ -11,13 +11,16 @@ if (isset($config['enable_bgp']) && $config['enable_bgp'])
}
$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') {
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) {
if ($this_alert)
{
$device_alerts++;
$device_alert_sql .= " OR `device_id` = '" . $device['device_id'] . "'";
}
@@ -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&amp;location=' . urlencode($row['location']) . '"><img src="images/16/building.png" border="0" align="absmiddle" /> ' . $row['location'] . ' </a></li>');
}
echo(' <li><a href="?page=devices&amp;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>
@@ -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>

View File

@@ -21,10 +21,7 @@ if (device_permitted($_GET['id']) || $check_device == $_GET['id'])
$select[$section] = "selected";
$device_query = mysql_query("SELECT * FROM `devices` WHERE `device_id` = '" . $_GET['id'] . "'");
# FIXME device_by_id_cache ?
while ($device = mysql_fetch_array($device_query))
{
$device = device_by_id_cache($_GET['id']);
if ($config['os'][$device['os']]['group']) { $device['os_group'] = $config['os'][$device['os']]['group']; }
echo('<table cellpadding="15" cellspacing="0" class="devicetable" width="100%">');
@@ -195,7 +192,6 @@ if (device_permitted($_GET['id']) || $check_device == $_GET['id'])
</a>
</li>');
}
}
if ($_SESSION['userlevel'] >= "7")
{

View File

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

View File

@@ -4,11 +4,25 @@ if ($_POST['editing'])
{
if ($_SESSION['userlevel'] > "7")
{
$updated = 0;
$descr = mres($_POST['descr']);
$ignore = mres($_POST['ignore']);
$type = mres($_POST['type']);
$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
$sql = "UPDATE `devices` SET `purpose` = '" . $descr . "', `type` = '$type'";
$sql .= ", `ignore` = '$ignore', `disabled` = '$disabled'";
@@ -26,14 +40,19 @@ if ($_POST['editing'])
$updated = -1;
} else {
$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'];
$override_sysLocation_bool = get_dev_attrib($device,'override_sysLocation_bool');
$override_sysLocation_string = get_dev_attrib($device,'override_sysLocation_string');
if ($updated && $update_message)
{
print_message($update_message);
@@ -41,29 +60,31 @@ if ($updated && $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=".$device['device_id']."'>
<img src='images/16/server_delete.png' align='absmiddle'>
<a href="?page=delhost&id="<?php echo($device['device_id']) ?>">
<img src="images/16/server_delete.png" align="absmiddle">
Delete
</a>
</h5>
<form id='edit' name='edit' method='post' action=''>
<input type=hidden name='editing' value='yes'>
<table width='400' border='0'>
<form id="edit" name="edit" method="post" action="">
<input type=hidden name="editing" value="yes">
<table width="500" border="0">
<tr>
<td><div align='right'>Description</div></td>
<td colspan='3'><input name='descr' size='32' value='" . $device['purpose'] . "'></input></td>
<td colspan="2" align="right">Description:</td>
<td colspan="3"><input name="descr" size="32" value="<?php echo($device['purpose']); ?>"></input></td>
</tr>
<tr>
<td align='right'>
Type
<td colspan="2" align="right">
Type:
</td>
<td>
<select name='type'>");
<select name="type">
<?php
$unknown = 1;
foreach ($device_types as $type)
{
@@ -79,22 +100,21 @@ foreach ($device_types as $type)
{
echo(' <option value="other">Other</option>');
}
echo("
?>
</select>
</td>
</tr>
<tr>
<td><div align='right'>Disable</div></td>
<td><input name='disabled' type='checkbox' id='disabled' value='1'");
if ($device['disabled']) { echo("checked=checked"); }
echo("/></td>
<td><div align='right'>Ignore</div></td>
<td><input name='ignore' type='checkbox' id='disable' value='1'");
if ($device['ignore']) { echo("checked=checked"); }
echo("/></td>
</tr>");
echo('
<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 width="150" align="right">Override sysLocation:</td>
<td><input name="sysLocation" size="32"<?php if (!$override_sysLocation_bool) { echo(' disabled="1"'); } ?> value="<?php echo($override_sysLocation_string); ?>" /></td>
</tr>
<tr>
<td colspan="2"><div align="right">Disable</div></td>
<td><input name="disabled" type="checkbox" id="disabled" value="1" <?php if ($device["disabled"]) { echo("checked=checked"); } ?> /></td>
<td><div align="right">Ignore</div></td>
<td><input name="ignore" type="checkbox" id="disable" value="1" <?php if ($device['ignore']) { echo("checked=checked"); } ?> /></td>
</tr>
</table>
<input type="submit" name="Submit" value="Save" />
<label><br />
@@ -102,6 +122,4 @@ echo('
</form>
</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.";
$updated = 1;
}
else
{
include("includes/error-no-perm.inc.php");
}
}
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['hardware']) { $where .= " AND hardware = '".mres($_POST['hardware'])."'"; }
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'])."'"; }
if ($_GET['type']) { $where = "AND type = '" .mres($_GET[type]). "'"; }
if ($_GET['location'] == "Unset") { $where .= " AND location = ''"; }
# FIXME override
if (isset($_REQUEST['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);
?>
@@ -23,7 +27,7 @@ print_optionbar_start(62);
<select name='os' id='os'>
<option value=''>All OSes</option>
<?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))
{
if ($data['os'])
@@ -39,7 +43,7 @@ print_optionbar_start(62);
<select name='version' id='version'>
<option value=''>All Versions</option>
<?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))
{
if ($data['version'])
@@ -56,7 +60,7 @@ print_optionbar_start(62);
<select name="hardware" id="hardware">
<option value="">All Platforms</option>
<?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))
{
if ($data['hardware'])
@@ -72,7 +76,7 @@ print_optionbar_start(62);
<select name="features" id="features">
<option value="">All Featuresets</option>
<?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))
{
if ($data['features'])
@@ -89,21 +93,13 @@ print_optionbar_start(62);
<select name="location" id="location">
<option value="">All Locations</option>
<?php
if($_SESSION['userlevel'] >= '5')
foreach (getlocations() as $location)
{
$query = mysql_query("SELECT location FROM devices WHERE 1 $where GROUP BY location ORDER BY location");
} else {
$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");
}
while ($data = mysql_fetch_array($query))
if ($location)
{
if ($data['location'])
{
echo('<option value="'.$data['location'].'"');
if ($data['location'] == $_POST['location']) { echo(" selected"); }
echo(">".$data['location']."</option>");
echo('<option value="'.$location.'"');
if ($location == $_POST['location']) { echo(" selected"); }
echo(">".$location."</option>");
}
}
?>
@@ -128,13 +124,17 @@ 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>');
$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 (!$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");
}
}
}
echo("</table>");

View File

@@ -1,39 +1,31 @@
<?php
echo('<table cellpadding="7" cellspacing="0" class="devicetable" width="100%">');
if ($_SESSION['userlevel'] >= '5')
{
$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))
foreach (getlocations() as $location)
{
if (!isset($bg) || $bg == "#ffffff") { $bg = "#eeeeee"; } else { $bg="#ffffff"; }
if ($_SESSION['userlevel'] == '10')
{
$num = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "'"),0);
$net = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "' AND type = 'network'"),0);
$srv = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "' AND type = 'server'"),0);
$fwl = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "' AND type = 'firewall'"),0);
$hostalerts = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "' AND status = '0'"),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 = '" . $location . "' AND type = 'network'"),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 = '" . $location . "' AND type = 'firewall'"),0);
$hostalerts = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $location . "' AND status = '0'"),0);
} 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);
$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);
$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);
$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);
$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);
$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 = '" . $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 = '" . $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 = '" . $location . "' AND type = 'firewall'"),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 ($device['location'] != "")
if ($location != "")
{
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">' . $num . ' devices</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];
} else {
$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;
}
@@ -192,5 +197,40 @@ function zeropad($num, $length = 2)
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);
}
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)
{
$parts = explode(".", $hostname);
@@ -218,8 +182,7 @@ function renamehost($id, $new, $source = 'console')
{
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");
mysql_query("UPDATE devices SET hostname = '$new' WHERE device_id = '$id'");
log_event("Hostname changed -> $new ($source)", $id, 'system');

View File

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