diff --git a/attic/ciscosensors.inc.php b/attic/ciscosensors.inc.php new file mode 100644 index 000000000..02489ec43 --- /dev/null +++ b/attic/ciscosensors.inc.php @@ -0,0 +1,39 @@ +"); } + echo("" . htmlspecialchars($type) ."\n"); + if ($_GET['opta'] == $type) { echo(""); } + $sep = ' | '; +} + +unset ($sep); + +print_optionbar_end(); + +$query = mysql_query("SELECT * FROM `entPhysical` WHERE device_id = '".$device['device_id']."' and entSensorType = '".$_GET['opta']."' ORDER BY `entPhysicalName`"); +while ($data = mysql_fetch_assoc($query)) +{ + if ($data['entSensorMeasuredEntity']) + { + $measured = mysql_fetch_assoc(mysql_query("SELECT * FROM entPhysical WHERE device_id = '".$device['device_id']."' AND entPhysicalIndex = '".$data['entSensorMeasuredEntity']."'")); + } + + echo("

".$measured['entPhysicalName']." ".$data['entPhysicalName']."

"); + $graph_type = "cisco_entity_sensor"; + $args = "&a=".$data['entPhysical_id']; + + include("includes/print-device-graph.php"); + + echo("
"); +} + +?> \ No newline at end of file diff --git a/html/pages/device/edit/apps.inc.php b/html/pages/device/edit/apps.inc.php index 551d26743..9f581046f 100644 --- a/html/pages/device/edit/apps.inc.php +++ b/html/pages/device/edit/apps.inc.php @@ -22,37 +22,33 @@ if ($handle = opendir($config['install_dir'] . "/includes/polling/applications/" if ($_POST['device']) { $updated = 0; - + $param = array($device['device_id']); foreach (array_keys($_POST) as $key) { if (substr($key,0,4) == 'app_') { - $enabled[] = "'" . substr($key,4) . "'"; + $param[] = substr($key,4); + $enabled[] = substr($key,4); + $query[] = "?"; } } - $sql = "DELETE FROM applications WHERE device_id=" . $device['device_id']; - if ($enabled) - { - $sql .= " AND app_type NOT IN (" . implode(',',$enabled) . ")"; + if(count($enabled)) { + $updated += dbDelete('applications', "`device_id` = ? AND `app_type` NOT IN (".implode(',',$query).")", array($param)); + } else { + $updated += dbDelete('applications', "`device_id` = ?", array($param)); } - mysql_query($sql); - $updated += mysql_affected_rows(); - $sql = "SELECT app_type FROM applications WHERE device_id=" . $device['device_id']; - $result = mysql_query($sql); - while ($row = mysql_fetch_assoc($result)) + foreach (dbFetchRows( "SELECT `app_type` FROM `applications` WHERE `device_id` = ?", array($device['device_id'])) as $row) { $app_in_db[] = $row['app_type']; } foreach ($enabled as $app) { - if (!in_array(trim($app,"'"),$app_in_db)) + if (!in_array($app,$app_in_db)) { - $sql = "INSERT INTO applications (device_id,app_type) VALUES (" . $device['device_id'] . ", " . $app . ")"; - mysql_query($sql); - $updated += mysql_affected_rows(); + $updated += dbInsert(array('device_id' => $device['device_id'], 'app_type' => $app), 'applications'); } } @@ -69,10 +65,10 @@ if ($_POST['device']) # Show list of apps with checkboxes echo('
'); -if (mysql_result(mysql_query("SELECT COUNT(*) from `applications` WHERE `device_id` = '".$device['device_id']."'"), 0) > '0') +$apps_enabled = dbFetchRows("SELECT * from `applications` WHERE `device_id` = ? ORDER BY app_type", array($device['device_id'])); +if (count($apps_enabled)) { - $app_query = mysql_query("select * from applications WHERE device_id = '".$device['device_id']."' ORDER BY app_type"); - while ($application = mysql_fetch_assoc($app_query)) + foreach ($apps_enabled as $application) { $app_enabled[] = $application['app_type']; } diff --git a/html/pages/device/edit/snmp.inc.php b/html/pages/device/edit/snmp.inc.php index 13a34f0f9..23daafa0b 100644 --- a/html/pages/device/edit/snmp.inc.php +++ b/html/pages/device/edit/snmp.inc.php @@ -19,7 +19,7 @@ if ($_POST['editing']) if ($rows_updated > 0) { - $update_message = mysql_affected_rows() . " Device record updated."; + $update_message = $rows_updated . " Device record updated."; $updated = 1; } elseif ($rows_updated = '-1') { $update_message = "Device record unchanged. No update necessary."; diff --git a/html/pages/device/health/sensors.inc.php b/html/pages/device/health/sensors.inc.php index 0eeee81c4..5ef6e9000 100644 --- a/html/pages/device/health/sensors.inc.php +++ b/html/pages/device/health/sensors.inc.php @@ -1,8 +1,5 @@ "); $row = 1; diff --git a/html/pages/device/overview/generic/sensor.inc.php b/html/pages/device/overview/generic/sensor.inc.php index 1eafc70b3..c6d54c6b9 100644 --- a/html/pages/device/overview/generic/sensor.inc.php +++ b/html/pages/device/overview/generic/sensor.inc.php @@ -1,15 +1,14 @@ '); echo('

' . $sensor_type . '

'); $i = '1'; echo(''); - while ($sensor = mysql_fetch_assoc($results)) + foreach ($sensors as $sensor) { if (is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } @@ -38,4 +37,4 @@ if (mysql_num_rows($results)) echo(""); } -?> \ No newline at end of file +?> diff --git a/html/pages/device/overview/mempools.inc.php b/html/pages/device/overview/mempools.inc.php index 525e1082e..9fb0b78e8 100644 --- a/html/pages/device/overview/mempools.inc.php +++ b/html/pages/device/overview/mempools.inc.php @@ -2,7 +2,9 @@ $graph_type = "mempool_usage"; -if (mysql_result(mysql_query("SELECT count(*) from mempools WHERE device_id = '" . $device['device_id'] . "'"),0)) +$mempools = dbFetchRows("SELECT * FROM `mempools` WHERE device_id = ?", array($device['device_id'])); + +if (count($mempools)) { echo("
"); echo("

"); @@ -10,9 +12,8 @@ if (mysql_result(mysql_query("SELECT count(*) from mempools WHERE device_id = '" echo(" Memory Pools

"); echo("
"); $mempool_rows = '0'; - $mempools = mysql_query("SELECT * FROM `mempools` WHERE device_id = '" . $device['device_id'] . "'"); - while ($mempool = mysql_fetch_assoc($mempools)) + foreach($mempools as $mempool) { if (is_integer($mempool_rows/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } $perc = round($mempool['mempool_perc'],0); diff --git a/html/pages/device/overview/ports.inc.php b/html/pages/device/overview/ports.inc.php index 9d7a29438..7a711f7e7 100644 --- a/html/pages/device/overview/ports.inc.php +++ b/html/pages/device/overview/ports.inc.php @@ -44,11 +44,9 @@ if ($ports['total']) echo('
'); - $sql = "SELECT * FROM ports WHERE `device_id` = '" . $device['device_id'] . "' AND deleted != '1'"; - $query = mysql_query($sql); $ifsep = ""; - while ($data = mysql_fetch_assoc($query)) + foreach (dbFetchRows("SELECT * FROM `ports` WHERE device_id = ? AND `deleted` != '1'", array($device['device_id'])) as $data) { $data = ifNameDescr($data); $data = array_merge($data, $device); @@ -61,4 +59,4 @@ if ($ports['total']) echo("
"); } -?> \ No newline at end of file +?> diff --git a/html/pages/device/overview/processors.inc.php b/html/pages/device/overview/processors.inc.php index 11da81628..f943b4f88 100644 --- a/html/pages/device/overview/processors.inc.php +++ b/html/pages/device/overview/processors.inc.php @@ -2,7 +2,9 @@ $graph_type = "processor_usage"; -if (mysql_result(mysql_query("SELECT count(*) from processors WHERE device_id = '" . $device['device_id'] . "'"),0)) +$processors = dbFetchRows("SELECT * FROM `processors` WHERE device_id = ?", array($device['device_id'])); + +if (count($processors)) { $processor_rows = 0; echo("
"); @@ -10,8 +12,8 @@ if (mysql_result(mysql_query("SELECT count(*) from processors WHERE device_id = echo(''); echo(" Processors

"); echo("
"); - $procs = mysql_query("SELECT * FROM `processors` WHERE device_id = '" . $device['device_id'] . "' ORDER BY processor_descr ASC"); - while ($proc = mysql_fetch_assoc($procs)) + + foreach($processors as $proc) { if (is_integer($processor_rows/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } diff --git a/html/pages/device/overview/storage.inc.php b/html/pages/device/overview/storage.inc.php index 827520588..a6de4ca22 100644 --- a/html/pages/device/overview/storage.inc.php +++ b/html/pages/device/overview/storage.inc.php @@ -2,7 +2,9 @@ $graph_type = "storage_usage"; -if (mysql_result(mysql_query("SELECT count(storage_id) from storage WHERE device_id = '" . $device['device_id'] . "'"),0)) +$drives = dbFetchRows("SELECT * FROM `storage` WHERE device_id = ? ORDER BY `storage_descr` ASC", array($device['device_id'])); + +if (count($drives)) { echo("
"); echo("

"); @@ -11,8 +13,7 @@ if (mysql_result(mysql_query("SELECT count(storage_id) from storage WHERE device echo("

"); $drive_rows = '0'; - $drives = mysql_query("SELECT * FROM `storage` WHERE device_id = '" . $device['device_id'] . "' ORDER BY storage_descr ASC"); - while ($drive = mysql_fetch_assoc($drives)) + foreach ($drives as $drive) { $skipdrive = 0; diff --git a/html/pages/device/routing/ospf.inc.php b/html/pages/device/routing/ospf.inc.php index a75ff381f..c60151312 100644 --- a/html/pages/device/routing/ospf.inc.php +++ b/html/pages/device/routing/ospf.inc.php @@ -1,15 +1,12 @@ '); #### Loop Instances -while ($instance = mysql_fetch_assoc($query)) +foreach (dbFetchRows("SELECT * FROM `ospf_instances` WHERE `device_id` = ?", array($device['device_id'])) as $instance) { if (!is_integer($i_i/2)) { $instance_bg = $list_colour_a; } else { $instance_bg = $list_colour_b; } diff --git a/html/pages/device/routing/overview/bgp.inc.php b/html/pages/device/routing/overview/bgp.inc.php deleted file mode 100644 index 20cc47aaf..000000000 --- a/html/pages/device/routing/overview/bgp.inc.php +++ /dev/null @@ -1,14 +0,0 @@ - -AS".$device['bgpLocalAs'].""); - -echo("
"); - -$total = mysql_result(mysql_query("SELECT count(*) FROM `bgpPeers` WHERE `device_id` = '".$device['device_id']."'"),0); -$up = mysql_result(mysql_query("SELECT count(*) FROM `bgpPeers` WHERE `device_id` = '".$device['device_id']."' AND `bgpPeerState` = 'established'"),0); -$stop = mysql_result(mysql_query("SELECT count(*) FROM `bgpPeers` WHERE `device_id` = '".$device['device_id']."' AND `bgpPeerAdminStatus` = 'stop'"),0); - -echo("Sessions: ".$total." Up: ".$up." Down: ".($total-$up) . ($stop != 0 ? " ( Shutdown: ".$stop." )" : "")); - -?> diff --git a/html/pages/device/routing/overview/cef.inc.php b/html/pages/device/routing/overview/cef.inc.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/html/pages/device/routing/overview/ospf.inc.php b/html/pages/device/routing/overview/ospf.inc.php deleted file mode 100644 index 99a12e9de..000000000 --- a/html/pages/device/routing/overview/ospf.inc.php +++ /dev/null @@ -1,44 +0,0 @@ -'); - -#### Loop Instances - -while ($instance = mysql_fetch_assoc($query)) -{ - if (!is_integer($i_i/2)) { $instance_bg = $list_colour_a; } else { $instance_bg = $list_colour_b; } - - $area_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `ospf_areas` WHERE `device_id` = '".$device['device_id']."'"),0); - $port_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."'"),0); - - $query = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE "; - $query .= "(A.ipv4_address = '".$peer['bgpPeerIdentifier']."' AND I.interface_id = A.interface_id)"; - $query .= " AND I.device_id = '".$device['device_id']."'"; - $ipv4_host = mysql_fetch_assoc(mysql_query($query)); - - if ($instance['ospfAdminStat'] == "enabled") { $enabled = 'enabled'; } else { $enabled = 'disabled'; } - if ($instance['ospfAreaBdrRtrStatus'] == "true") { $abr = 'yes'; } else { $abr = 'no'; } - if ($instance['ospfASBdrRtrStatus'] == "true") { $asbr = 'yes'; } else { $asbr = 'no'; } - - echo(''); - echo(''); - echo(' '); - echo(' '); - echo(' '); - echo(' '); - echo(' '); - echo(' '); - echo(' '); - echo(''); - - $i_i++; -} ### End loop instances - -echo('
Router IdStatusABRASBRAreasPortsNeighbours
'.$instance['ospfRouterId'] . '' . $enabled . '' . $abr . '' . $asbr . '' . $area_count . '' . $port_count . '' . ($neighbour_count+0) . '
'); - -?> diff --git a/html/pages/front/traffic.php b/html/pages/front/traffic.php index 6aa9fa382..1065f26b8 100644 --- a/html/pages/front/traffic.php +++ b/html/pages/front/traffic.php @@ -5,16 +5,16 @@ 0) { - $uptimesql = " AND A.attrib_value < '" . $config['uptime_warning'] . "'"; + $uptimesql = " AND A.attrib_value < ?"; + $param = array($config['uptime_warning']); } -$sql = mysql_query("SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' " . $uptimesql); - -while ($device = mysql_fetch_assoc($sql)){ +foreach (dbFetchRows("SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' " . $uptimesql, $param) as $device) +{ unset($already); $i = 0; while ($i <= count($nodes)) { @@ -28,8 +28,8 @@ while ($device = mysql_fetch_assoc($sql)){ } -$sql = mysql_query("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'"); -while ($device = mysql_fetch_assoc($sql)){ +foreach (dbFetchRows("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'") as $device) +{ if (device_permitted($device['device_id'])) { echo("
".generate_device_link($device, shorthost($device['hostname']))."
@@ -41,8 +41,8 @@ while ($device = mysql_fetch_assoc($sql)){ if ($config['warn']['ifdown']) { -$sql = mysql_query("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"); -while ($interface = mysql_fetch_assoc($sql)){ +foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'") as $interface) +{ if (port_permitted($interface['interface_id'])) { echo("
".generate_device_link($interface, shorthost($interface['hostname']))."
@@ -55,8 +55,8 @@ while ($interface = mysql_fetch_assoc($sql)){ } -$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"); -while ($service = mysql_fetch_assoc($sql)){ +foreach (dbFetchRows("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'") as $service) +{ if (device_permitted($service['device_id'])) { echo("
".generate_device_link($service, shorthost($service['hostname']))."
@@ -67,8 +67,8 @@ while ($service = mysql_fetch_assoc($sql)){ } } -$sql = mysql_query("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id"); -while ($peer = mysql_fetch_assoc($sql)){ +foreach (dbFetchRows("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id") as $peer) +{ if (device_permitted($peer['device_id'])) { echo("
".generate_device_link($peer, shorthost($peer['hostname']))."
@@ -81,8 +81,7 @@ while ($peer = mysql_fetch_assoc($sql)){ if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) { - $sql = mysql_query("SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < '" . $config['uptime_warning'] . "' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"); - while ($device = mysql_fetch_assoc($sql)){ + foreach (dbFetchRows("SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < ? AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'", array($config['uptime_warning'])) as $device){ if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == "uptime") { echo("
".generate_device_link($device, shorthost($device['hostname']))."
diff --git a/html/pages/routing.inc.php b/html/pages/routing.inc.php index 9d35968f6..272ed2ecb 100644 --- a/html/pages/routing.inc.php +++ b/html/pages/routing.inc.php @@ -19,7 +19,7 @@ print_optionbar_start(); echo("Routing » "); unset($sep); -foreach ($datas as $type) +foreach ($routing_count as $type => $value) { if (!$_GET['opta']) { $_GET['opta'] = $type; } diff --git a/html/pages/routing/ospf.inc.php b/html/pages/routing/ospf.inc.php index c4ded7eda..fc5b75676 100644 --- a/html/pages/routing/ospf.inc.php +++ b/html/pages/routing/ospf.inc.php @@ -1,8 +1,5 @@ '); @@ -10,7 +7,7 @@ echo('DeviceRouter IdStatusABRASBR" . $vrf['mplsVpnVrfRouteDistinguisher'] . ""); #echo("" . $vrf['mplsVpnVrfDescription'] . ""); echo(""); - $devices = mysql_query("SELECT * FROM `vrfs` AS V, `devices` AS D WHERE `mplsVpnVrfRouteDistinguisher` = '".$vrf['mplsVpnVrfRouteDistinguisher']."' AND D.device_id = V.device_id"); $x=1; - while ($device = mysql_fetch_assoc($devices)) + foreach (dbFetchRows("SELECT * FROM `vrfs` AS V, `devices` AS D WHERE `mplsVpnVrfRouteDistinguisher` = ? AND D.device_id = V.device_id", array($vrf['mplsVpnVrfRouteDistinguisher'])) as $device) { if (!is_integer($i/2)) { diff --git a/includes/dbFacile.php b/includes/dbFacile.php index 39717bc11..3b32757ac 100644 --- a/includes/dbFacile.php +++ b/includes/dbFacile.php @@ -135,6 +135,7 @@ function dbDelete($table, $where = null, $parameters = array()) { * Most other retrieval functions build off this * */ function dbFetchRows($sql, $parameters = array()) { + global $db_stats; $result = dbQuery($sql, $parameters); if(mysql_num_rows($result) > 0) { $rows = array(); @@ -144,7 +145,14 @@ function dbFetchRows($sql, $parameters = array()) { mysql_free_result($result); return $rows; } - mysql_free_result($result); + + $time_start = microtime(true); + mysql_free_result($result); + $time_end = microtime(true); + + $db_stats['fetchrows_sec'] += number_format($time_end - $time_start, 8); + $db_stats['fetchrows']++; + // no records, thus return empty array // which should evaluate to false, and will prevent foreach notices/warnings return array(); @@ -172,10 +180,20 @@ function dbFetch($sql, $parameters = array()) { * The first argument is an sprintf-ready query stringTypes * */ function dbFetchRow($sql = null, $parameters = array()) { + global $db_stats; + $time_start = microtime(true); + $result = dbQuery($sql, $parameters); + $time_start = microtime(true); + if($result) { $row = mysql_fetch_assoc($result); mysql_free_result($result); + $time_end = microtime(true); + + $db_stats['fetchrow_sec'] += number_format($time_end - $time_start, 8); + $db_stats['fetchrow']++; + return $row; } else { return null; @@ -186,10 +204,18 @@ function dbFetchRow($sql = null, $parameters = array()) { * Fetches the first call from the first row returned by the query * */ function dbFetchCell($sql, $parameters = array()) { + global $db_stats; + $time_start = microtime(true); + $row = dbFetchRow($sql, $parameters); if($row) { return array_shift($row); // shift first field off first row } + $time_end = microtime(true); + + $db_stats['fetchcell_sec'] += number_format($time_end - $time_start, 8); + $db_stats['fetchcell']++; + return null; } @@ -198,10 +224,17 @@ function dbFetchCell($sql, $parameters = array()) { * It fetches one cell from each row and places all the values in 1 array * */ function dbFetchColumn($sql, $parameters = array()) { + global $db_stats; + $time_start = microtime(true); $cells = array(); foreach(dbFetch($sql, $parameters) as $row) { $cells[] = array_shift($row); } + $time_end = microtime(true); + + $db_stats['fetchcol_sec'] += number_format($time_end - $time_start, 8); + $db_stats['fetchcol']++; + return $cells; }