- ');
+
+ if (device_permitted($device['device_id']))
{
- if ($config['os'][$device['os']]['group']) { $device['os_group'] = $config['os'][$device['os']]['group']; }
-
- echo('
-
Overview
');
- }
+ }
- echo(' - + echo('
-
Graphs
');
- $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(*) 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 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(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(fan_id) from fanspeed 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(*) 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 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(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(fan_id) from fanspeed WHERE device_id = '" . $device['device_id'] . "'"), 0);
- if ($health)
- {
- echo(' - + if ($health) + { + echo('
-
Health
');
- }
+ }
- if (@mysql_result(mysql_query("select count(app_id) from applications WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0')
- {
- echo(' - + if (@mysql_result(mysql_query("select count(app_id) from applications WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') + { + echo('
-
Apps
');
- }
+ }
- if (is_dir($config['collectd_dir'] . "/" . $device['hostname'] ."/"))
- {
- echo(' - + if (is_dir($config['collectd_dir'] . "/" . $device['hostname'] ."/")) + { + echo('
-
CollectD
');
- }
+ }
- if (@mysql_result(mysql_query("select count(interface_id) from ports WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0')
- {
- echo(' - + if (@mysql_result(mysql_query("select count(interface_id) from ports WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') + { + echo('
-
Ports
');
- }
+ }
- if (@mysql_result(mysql_query("select count(vlan_id) from vlans WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0')
- {
- echo(' - + if (@mysql_result(mysql_query("select count(vlan_id) from vlans WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') + { + echo('
-
VLANs
');
- }
+ }
- if (@mysql_result(mysql_query("SELECT COUNT(id) FROM vmware_vminfo WHERE device_id = '" . $device["device_id"] . "'"), 0) > '0')
- {
- echo(' - + if (@mysql_result(mysql_query("SELECT COUNT(id) FROM vmware_vminfo WHERE device_id = '" . $device["device_id"] . "'"), 0) > '0') + { + echo('
-
Virtual Machines
');
- }
+ }
- if (@mysql_result(mysql_query("select count(*) from vrfs WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0')
- {
- echo(' - + if (@mysql_result(mysql_query("select count(*) from vrfs WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') + { + echo('
-
VRFs
');
- }
+ }
- if ($config['enable_bgp'] && $device['bgpLocalAs'])
- {
- echo(' - + if ($config['enable_bgp'] && $device['bgpLocalAs']) + { + echo('
-
BGP
');
- }
+ }
- 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(' - + 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('
-
Map
');
- }
+ }
- if ($config['enable_inventory'] && @mysql_result(mysql_query("SELECT * FROM `entPhysical` WHERE device_id = '".$device['device_id']."'"), 0) > '0')
- {
- echo(' - + if ($config['enable_inventory'] && @mysql_result(mysql_query("SELECT * FROM `entPhysical` WHERE device_id = '".$device['device_id']."'"), 0) > '0') + { + echo('
-
Inventory
');
- }
- 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(' - + } + 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('
-
Inventory
');
- }
+ }
- if (mysql_result(mysql_query("select count(service_id) from services WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0')
- {
- echo(' - + if (mysql_result(mysql_query("select count(service_id) from services WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') + { + echo('
-
Services
');
- }
+ }
- if (@mysql_result(mysql_query("select count(toner_id) from toner WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0')
- {
- echo(' - + if (@mysql_result(mysql_query("select count(toner_id) from toner WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') + { + echo('
-
Toner
');
- }
+ }
- if (device_permitted($device['device_id']))
- {
- echo(' - + if (device_permitted($device['device_id'])) + { + echo('
-
Events
');
- }
+ }
- if ($config['enable_syslog'])
- {
- echo(' - + if ($config['enable_syslog']) + { + echo('
-
Syslog
');
- }
}
if ($_SESSION['userlevel'] >= "7")
diff --git a/html/pages/device/edit/alerts.inc.php b/html/pages/device/edit/alerts.inc.php
index ace242ba6..e339beeb1 100644
--- a/html/pages/device/edit/alerts.inc.php
+++ b/html/pages/device/edit/alerts.inc.php
@@ -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)
diff --git a/html/pages/device/edit/device.inc.php b/html/pages/device/edit/device.inc.php
index 9cf455ccd..93616b2af 100644
--- a/html/pages/device/edit/device.inc.php
+++ b/html/pages/device/edit/device.inc.php
@@ -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("
- ');
-
- if (device_permitted($device['device_id']))
+ if ($config['show_overview_tab'])
{
- if ($config['show_overview_tab'])
- {
- echo('
+ echo('
+?>
+
|
@@ -56,32 +60,32 @@ print_optionbar_start(62);
| Device | Operating System | Platform | Uptime | '); $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'])) { - 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"); + } } } diff --git a/html/pages/locations.inc.php b/html/pages/locations.inc.php index e53af687f..4816de54d 100644 --- a/html/pages/locations.inc.php +++ b/html/pages/locations.inc.php @@ -1,39 +1,31 @@ '); -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 = '|
|---|---|---|---|---|
| ' . $device['location'] . ' | +' . $location . ' | ' . $alert . ' | ' . $num . ' devices | ' . $net . ' network | diff --git a/includes/common.php b/includes/common.php index 84fdf579a..76f52b0be 100644 --- a/includes/common.php +++ b/includes/common.php @@ -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); +} ?> \ No newline at end of file diff --git a/includes/functions.php b/includes/functions.php index 9b2b7dc92..e3d4d8cd3 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -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'); diff --git a/poller.php b/poller.php index c64c23c42..6bedc2825 100755 --- a/poller.php +++ b/poller.php @@ -272,8 +272,11 @@ while ($device = mysql_fetch_assoc($device_query)) if ($sysLocation && $device['location'] != $sysLocation) { - $poll_update .= $poll_separator . "`location` = '$sysLocation'"; - $poll_separator = ", "; + if (!get_dev_attrib($device,'override_sysLocation_bool')) + { + $poll_update .= $poll_separator . "`location` = '$sysLocation'"; + $poll_separator = ", "; + } log_event("Location -> $sysLocation", $device['device_id'], 'system'); }
Network Map
Eventlog
Syslog
Alerts ()
Locations
External BGP
Internal BGP
Alerted (' . $bgp_alerts . ')
Add User
Remove User
Edit User
+ Delete
+
'; } else { $alert = ""; }
- if ($device['location'] != "")
+ if ($location != "")
{
echo('