From 2682ff9e6d232b204cbdb769805668880caf30d2 Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Thu, 10 Jun 2010 20:13:41 +0000 Subject: [PATCH] refactored device types, added power type for APC and MGE stuff + some warning fixes git-svn-id: http://www.observium.org/svn/observer/trunk@1137 61d68cd4-352d-0410-923a-c4978735b2b8 --- discovery.php | 68 ++++++++++++++------------------- html/includes/functions.inc.php | 4 +- html/pages/device/edit.inc.php | 38 ++++++++++-------- 3 files changed, 53 insertions(+), 57 deletions(-) diff --git a/discovery.php b/discovery.php index 777c0cd91..6a2aa1768 100755 --- a/discovery.php +++ b/discovery.php @@ -116,46 +116,36 @@ while ($device = mysql_fetch_array($device_query)) include("includes/discovery/toner.inc.php"); include("includes/discovery/ups.inc.php"); - if($device['os'] == "screenos") { - if ($device['type'] == "unknown") { $device['type'] = 'firewall'; } - } - - if($device['os'] == "junos") { - if ($device['type'] == "unknown") { $device['type'] = 'network'; } # FIXME: could also be a Netscreen... - } - - if($device['os'] == "linux") { - if (($device['type'] == "unknown") && preg_match("/-server$/", $device['version'])) { $device['type'] = 'server'; } - } - - if($device['os'] == "ios" || $device['os'] == "iosxe" || $device['os'] == "catos" || $device['os'] == "asa" || $device['os'] == "pix") { - if ($device['type'] == "unknown") { $device['type'] = 'network'; }; - } - - if ($device['os'] == "procurve" || $device['os'] == "powerconnect") + if ($device['type'] == "unknown") { - if ($device['type'] == "unknown") { $device['type'] = 'network'; }; - } - - if ($device['os'] == "asa" || $device['os'] == "pix") - { - if ($device['type'] == "unknown") { $device['type'] = 'firewall'; } - } - - if ($device['os'] == "dell-laser") - { - if ($device['type'] == "unknown") { $device['type'] = 'printer'; } - } - - if($device['os'] == "ironware") - { - if ($device['type'] == "unknown") { $device['type'] = 'network'; } - } - - if($device['os'] == "allied") - { - if ($device['type'] == "unknown") { $device['type'] = 'network'; } - } + switch ($device['os']) + { + case "procurve": + case "powerconnect": + case "ironware": + case "allied": + case "junos": # Could also be a Netscreen? + case "ios": + case "iosxe": + case "catos": + $device['type'] = 'network'; + break; + case "asa": + case "pix": + case "screenos": + $device['type'] = 'firewall'; + break; + case "dell-laser": + $device['type'] = 'printer'; + break; + case "linux": + if (preg_match("/-server$/", $device['version']) { $device['type'] = 'server'; } + break; + case "apc": + case "mgeups": + $device['type'] = 'power'; + break; + } $update_query = "UPDATE `devices` SET "; $update_query .= " `last_discovered` = NOW(), `type` = '" . $device['type'] . "'"; diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index fc0fef26b..b94853516 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -52,11 +52,11 @@ function permissions_cache($user_id) { $permissions = array(); $query = mysql_query("SELECT * FROM devices_perms WHERE user_id = '".$user_id."'"); while($device = mysql_fetch_assoc($query)) { - $permissions['device'][$device[device_id]] = 1; + $permissions['device'][$device['device_id']] = 1; } $query = mysql_query("SELECT * FROM ports_perms WHERE user_id = '".$user_id."'"); while($port = mysql_fetch_assoc($query)) { - $permissions['port'][$port[interface_id]] = 1; + $permissions['port'][$port['interface_id']] = 1; } return $permissions; } diff --git a/html/pages/device/edit.inc.php b/html/pages/device/edit.inc.php index 306cf580a..0af229efd 100644 --- a/html/pages/device/edit.inc.php +++ b/html/pages/device/edit.inc.php @@ -19,12 +19,7 @@ if($updated && $update_message) { print_error($update_message); } -if($device['type'] == 'server') { $server_select = "selected"; } -if($device['type'] == 'network') { $network_select = "selected"; } -if($device['type'] == 'firewall') { $firewall_select = "selected"; } -if($device['type'] == 'workstation') { $workstation_select = "selected"; } -if($device['type'] == 'printer') { $printer_select = "selected"; } -if($device['type'] == 'other' || $device['type'] == 'unknown') { $other_select = "selected"; } +$device_types = array('server','network','firewall','workstation','printer','power'); echo(" -
@@ -58,13 +53,24 @@ echo(" @@ -79,15 +85,15 @@ echo("/> echo("/>"); -echo(" +echo('
Type - "); + +$unknown = 1; +foreach ($device_types as $type) +{ + echo ' '; +} + if ($unknown) + { + echo ' '; + } +echo("
- +
"); +'); }