Index: html/includes/graphs/port/mac_acc_total.inc.php =================================================================== --- html/includes/graphs/port/mac_acc_total.inc.php (revision 5100) +++ html/includes/graphs/port/mac_acc_total.inc.php (working copy) @@ -69,7 +69,7 @@ $name = $peer['hostname'] . " " . short_ifname($peer['ifDescr']) . " (".$mac.")"; } - if (dbFetchCell("SELECT count(*) FROM bgpPeers WHERE device_id = '".$ma['device_id']."' AND bgpPeerIdentifier = ?", array($addy['ipv4_address']))) + if (dbFetchCell("SELECT COUNT(*) FROM bgpPeers WHERE device_id = ? AND bgpPeerIdentifier = ?", array($ma['device_id'], $addy['ipv4_address']))) { $peer_info = dbFetchRow("SELECT * FROM bgpPeers WHERE device_id = ? AND bgpPeerIdentifier = ?", array($ma['device_id'], $addy['ipv4_address'])); $name .= " - AS".$peer_info['bgpPeerRemoteAs']; Index: html/pages/addhost.inc.php =================================================================== --- html/pages/addhost.inc.php (revision 5100) +++ html/pages/addhost.inc.php (working copy) @@ -152,7 +152,7 @@
@@ -169,7 +169,7 @@
Index: html/pages/device.inc.php =================================================================== --- html/pages/device.inc.php (revision 5100) +++ html/pages/device.inc.php (working copy) @@ -109,11 +109,11 @@ $navbar['options']['graphs'] = array('text' => 'Graphs', 'icon' => 'oicon-chart-up'); - $health = dbFetchCell("SELECT COUNT(*) FROM storage WHERE device_id = '" . $device['device_id'] . "'") + - dbFetchCell("SELECT COUNT(sensor_id) FROM sensors WHERE device_id = '" . $device['device_id'] . "'") + - dbFetchCell("SELECT COUNT(*) FROM cempMemPool WHERE device_id = '" . $device['device_id'] . "'") + - dbFetchCell("SELECT COUNT(*) FROM cpmCPU WHERE device_id = '" . $device['device_id'] . "'") + - dbFetchCell("SELECT COUNT(*) FROM processors WHERE device_id = '" . $device['device_id'] . "'"); + $health = dbFetchCell('SELECT COUNT(*) FROM storage WHERE device_id = ?', array($device['device_id'])) + + dbFetchCell('SELECT COUNT(sensor_id) FROM sensors WHERE device_id = ?', array($device['device_id'])) + + dbFetchCell('SELECT COUNT(*) FROM cempMemPool WHERE device_id = ?', array($device['device_id'])) + + dbFetchCell('SELECT COUNT(*) FROM cpmCPU WHERE device_id = ?', array($device['device_id'])) + + dbFetchCell('SELECT COUNT(*) FROM processors WHERE device_id = ?', array($device['device_id'])); if ($health) { @@ -121,7 +121,7 @@ } // Print applications tab if there are matching entries in `applications` table - if (dbFetchCell("SELECT COUNT(app_id) FROM applications WHERE device_id = '" . $device['device_id'] . "'") > '0') + if (dbFetchCell('SELECT COUNT(app_id) FROM applications WHERE device_id = ?', array($device['device_id'])) > '0') { $navbar['options']['apps'] = array('text' => 'Apps', 'icon' => 'oicon-application-icon-large'); } @@ -133,25 +133,25 @@ } // Print the munin tab if there are matchng entries in the munin_plugins table - if (dbFetchCell("SELECT COUNT(mplug_id) FROM munin_plugins WHERE device_id = '" . $device['device_id'] . "'") > '0') + if (dbFetchCell('SELECT COUNT(mplug_id) FROM munin_plugins WHERE device_id = ?', array($device['device_id'])) > '0') { $navbar['options']['munin'] = array('text' => 'Munin', 'icon' => 'oicon-chart-up'); } // Print the port tab if there are matching entries in the ports table - if (dbFetchCell("SELECT COUNT(port_id) FROM ports WHERE device_id = '" . $device['device_id'] . "'") > '0') + if (dbFetchCell('SELECT COUNT(port_id) FROM ports WHERE device_id = ?', array($device['device_id'])) > '0') { $navbar['options']['ports'] = array('text' => 'Ports', 'icon' => 'oicon-network-ethernet'); } // Print the SLAs tab if there are matching entries in the slas table - if (dbFetchCell("SELECT COUNT(sla_id) FROM slas WHERE device_id = '" . $device['device_id'] . "'") > '0') + if (dbFetchCell('SELECT COUNT(sla_id) FROM slas WHERE device_id = ?', array($device['device_id'])) > '0') { $navbar['options']['slas'] = array('text' => 'SLAs', 'icon' => 'oicon-chart-up'); } // Print the acceess points tab if there are matching entries in the accesspoints table - if (dbFetchCell("SELECT COUNT(accesspoint_id) FROM accesspoints WHERE device_id = '" . $device['device_id'] . "'") > '0') + if (dbFetchCell('SELECT COUNT(accesspoint_id) FROM accesspoints WHERE device_id = ?', array($device['device_id'])) > '0') { $navbar['options']['accesspoints'] = array('text' => 'Access Points', 'icon' => 'oicon-wi-fi-zone'); } @@ -196,13 +196,13 @@ } // Print vlans tab if there are matching entries in the vlans table - if (dbFetchCell("SELECT COUNT(vlan_id) FROM vlans WHERE device_id = '" . $device['device_id'] . "'") > '0') + if (dbFetchCell('SELECT COUNT(vlan_id) FROM vlans WHERE device_id = ?', array($device['device_id'])) > '0') { $navbar['options']['vlans'] = array('text' => 'VLANs', 'icon' => 'oicon-arrow-branch-bgr'); } // Pring Virtual Machines tab if there are matching entries in the vminfo table - if (dbFetchCell("SELECT COUNT(id) FROM vminfo WHERE device_id = '" . $device["device_id"] . "'") > '0') + if (dbFetchCell('SELECT COUNT(id) FROM vminfo WHERE device_id = ?', array($device['device_id'])) > '0') { $navbar['options']['vm'] = array('text' => 'VMs', 'icon' => 'oicon-network-cloud'); } @@ -279,7 +279,7 @@ # } // Print the packages tab if there are matching entries in the packages table - if (dbFetchCell("SELECT COUNT(*) FROM `packages` WHERE device_id = '".$device['device_id']."'") > '0') + if (dbFetchCell('SELECT COUNT(*) FROM `packages` WHERE `device_id` = ?', array($device['device_id'])) > '0') { $navbar['options']['packages'] = array('text' => 'Pkgs', 'icon' => 'oicon-box-zipper'); } @@ -296,13 +296,13 @@ // Print service tab if show_services enabled and there are entries in the services table ## DEPRECATED - if ($config['show_services'] && dbFetchCell("SELECT COUNT(service_id) FROM services WHERE device_id = '" . $device['device_id'] . "'") > '0') + if ($config['show_services'] && dbFetchCell('SELECT COUNT(service_id) FROM services WHERE device_id = ?', array($device['device_id'])) > '0') { $navbar['options']['services'] = array('text' => 'Services', 'icon' => 'oicon-target'); } // Print toner tab if there are entries in the toner table - if (dbFetchCell("SELECT COUNT(toner_id) FROM toner WHERE device_id = '" . $device['device_id'] . "'") > '0') + if (dbFetchCell('SELECT COUNT(toner_id) FROM toner WHERE device_id = ?', array($device['device_id'])) > '0') { $navbar['options']['printing'] = array('text' => 'Printing', 'icon' => 'oicon-printer-color'); } Index: html/pages/device/hrdevice.inc.php =================================================================== --- html/pages/device/hrdevice.inc.php (revision 5100) +++ html/pages/device/hrdevice.inc.php (working copy) @@ -21,7 +21,7 @@ if ($hrdevice['hrDeviceType'] == "hrDeviceProcessor") { - $proc_id = dbFetchCell("SELECT processor_id FROM processors WHERE device_id = '".$device['device_id']."' AND hrDeviceIndex = '".$hrdevice['hrDeviceIndex']."'"); + $proc_id = dbFetchCell('SELECT processor_id FROM processors WHERE device_id = ? AND hrDeviceIndex = ?', array($device['device_id'], $hrdevice['hrDeviceIndex'])); $proc_url = "device/device=".$device['device_id']."/tab=health/metric=processor/"; $proc_popup = "onmouseover=\"return overlib('
".$device['hostname']." - ".$hrdevice['hrDeviceDescr']; $proc_popup .= "
"; Index: html/pages/device/port.inc.php =================================================================== --- html/pages/device/port.inc.php (revision 5100) +++ html/pages/device/port.inc.php (working copy) @@ -73,12 +73,12 @@ $navbar['options']['alerts']['text'] = 'Alerts'; } -if (dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `measured_class` = 'port' AND `measured_entity` = '".$port['port_id']."' and `device_id` = '".$device['device_id']."'")) +if (dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `measured_class` = 'port' AND `measured_entity` = ? and `device_id` = ?", array($port['port_id'], $device['device_id']))) { $navbar['options']['sensors']['text'] = 'Sensors'; } $navbar['options']['realtime']['text'] = 'Real time'; // FIXME CONDITIONAL -if(dbFetchCell('SELECT COUNT(*) FROM `ip_mac` WHERE `port_id` = ?;', array($port['port_id']))) +if(dbFetchCell('SELECT COUNT(*) FROM `ip_mac` WHERE `port_id` = ?', array($port['port_id']))) { $navbar['options']['arp']['text'] = 'ARP/NDP Table'; } if (dbFetchCell("SELECT COUNT(*) FROM `vlans_fdb` WHERE `port_id` = ?", array($port['port_id']))) @@ -89,16 +89,16 @@ if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = ?", array($port['port_id']))) { $navbar['options']['adsl']['text'] = 'ADSL'; } -if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `pagpGroupIfIndex` = '".$port['ifIndex']."' and `device_id` = '".$device['device_id']."'") ) +if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE `pagpGroupIfIndex` = ? and `device_id` = ?', array($port['ifIndex'], $device['device_id']))) { $navbar['options']['pagp']['text'] = 'PAgP'; } -if (dbFetchCell("SELECT COUNT(*) FROM `ports_vlans` WHERE `port_id` = '".$port['port_id']."' and `device_id` = '".$device['device_id']."'")) +if (dbFetchCell('SELECT COUNT(*) FROM `ports_vlans` WHERE `port_id` = ? and `device_id` = ?', array($port['port_id'], $device['device_id']))) { $navbar['options']['vlans']['text'] = 'VLANs'; } -if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = '".$port['port_id']."'") > "0" ) +if (dbFetchCell('SELECT count(*) FROM mac_accounting WHERE port_id = ?', array($port['port_id'])) > '0') { $navbar['options']['macaccounting']['text'] = 'MAC Accounting'; } -if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '".$port['port_id']."'") > "0" ) +if (dbFetchCell('SELECT COUNT(*) FROM juniAtmVp WHERE port_id = ?', array($port['port_id'])) > '0') { // FIXME ATM VPs Index: html/pages/device/port/vlans.inc.php =================================================================== --- html/pages/device/port/vlans.inc.php (revision 5100) +++ html/pages/device/port/vlans.inc.php (working copy) @@ -1,6 +1,6 @@ '); Index: html/pages/routing/ospf.inc.php =================================================================== --- html/pages/routing/ospf.inc.php (revision 5100) +++ html/pages/routing/ospf.inc.php (working copy) @@ -13,10 +13,10 @@ $device = device_by_id_cache($instance['device_id']); - $area_count = dbFetchCell("SELECT COUNT(*) FROM `ospf_areas` WHERE `device_id` = '".$device['device_id']."'"); - $port_count = dbFetchCell("SELECT COUNT(*) FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."'"); - $port_count_enabled = dbFetchCell("SELECT COUNT(*) FROM `ospf_ports` WHERE `ospfIfAdminStat` = 'enabled' AND `device_id` = '".$device['device_id']."'"); - $neighbour_count = dbFetchCell("SELECT COUNT(*) FROM `ospf_nbrs` WHERE `device_id` = '".$device['device_id']."'"); + $area_count = dbFetchCell('SELECT COUNT(*) FROM `ospf_areas` WHERE `device_id` = ?', array($device['device_id'])); + $port_count = dbFetchCell('SELECT COUNT(*) FROM `ospf_ports` WHERE `device_id` = ?', array($device['device_id'])); + $port_count_enabled = dbFetchCell("SELECT COUNT(*) FROM `ospf_ports` WHERE `ospfIfAdminStat` = 'enabled' AND `device_id` = ?", array($device['device_id'])); + $neighbour_count = dbFetchCell('SELECT COUNT(*) FROM `ospf_nbrs` WHERE `device_id` = ?', array($device['device_id'])); $ip_query = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE "; $ip_query .= "(A.ipv4_address = ? AND I.port_id = A.port_id)"; Index: includes/discovery/cisco-vrf.inc.php =================================================================== --- includes/discovery/cisco-vrf.inc.php (revision 5100) +++ includes/discovery/cisco-vrf.inc.php (working copy) @@ -1,7 +1,5 @@ $descr_table[$vrf_oid], 'mplsVpnVrfRouteDistinguisher' => $vrf_rd); + dbUpdate($update_array, 'vrfs', '`device_id` = ? AND `vrf_oid` = ?', array($device['device_id'], $vrf_oid)); } else { - $insert_query = "INSERT INTO `vrfs` (`vrf_oid`,`vrf_name`,`mplsVpnVrfRouteDistinguisher`,`mplsVpnVrfDescription`,`device_id`) "; - $insert_query .= "VALUES ('$vrf_oid','$vrf_name','$vrf_rd','".$descr_table[$vrf_oid]."','".$device['device_id']."')"; - mysql_query($insert_query); + $insert_array = array('device_id' => $device['device_id'], 'vrf_oid' => $vrf_oid, 'vrf_name' => $vrf_name, 'mplsVpnVrfDescription' => $descr_table[$vrf_oid], 'mplsVpnVrfRouteDistinguisher' => $vrf_rd); + dbInsert($insert_array, 'vrfs'); } - $vrf_id = @mysql_result(mysql_query("SELECT vrf_id FROM vrfs WHERE `device_id` = '".$device['device_id']."' AND `vrf_oid`='$vrf_oid'"),0); + $vrf_id = dbFetchCell('SELECT vrf_id FROM `vrfs` WHERE `device_id` = ? AND `vrf_oid` = ?', array($device['device_id'], $vrf_oid)); $valid_vrf[$vrf_id] = 1; echo "\n [VRF $vrf_name] PORTS - "; foreach ($port_table[$vrf_oid] as $if_id) { - $interface = mysql_fetch_assoc(mysql_query("SELECT * FROM ports WHERE ifIndex = '$if_id' AND device_id = '" . $device['device_id'] . "'")); + $interface = dbFetchRow('SELECT ifDescr, port_id FROM ports WHERE ifIndex = ? AND device_id = ?', array($if_id, $device['device_id'])); echo(short_ifname($interface['ifDescr']) . " "); - mysql_query("UPDATE ports SET ifVrf = '$vrf_id' WHERE port_id = '".$interface['port_id']."'"); + dbUpdate(array('ifVrf' => $vrf_id), 'ports', '`port_id` = ?', array($interface['port_id'])); $if = $interface['port_id']; $valid_vrf_if[$vrf_id][$if] = 1; } @@ -121,9 +116,7 @@ echo "\n"; - $sql = "SELECT * FROM ports WHERE device_id = '" . $device['device_id'] . "'"; - $data = mysql_query($sql); - while ($row = mysql_fetch_assoc($data)) + foreach (dbFetchRows('SELECT * FROM ports WHERE device_id = ?', array($device['device_id'])) as $row) { $if = $row['port_id']; $vrf_id = $row['ifVrf']; @@ -132,7 +125,7 @@ if (!$valid_vrf_if[$vrf_id][$if]) { echo("-"); - $query = @mysql_query("UPDATE ports SET `ifVrf` = NULL WHERE port_id = '$if'"); + dbUpdate(array('ifVrf' => NULL), 'ports', '`port_id` = ?', array($if)); } else { @@ -141,15 +134,13 @@ } } - $sql = "SELECT * FROM vrfs WHERE device_id = '" . $device['device_id'] . "'"; - $data = mysql_query($sql); - while ($row = mysql_fetch_assoc($data)) + foreach (dbFetchRows('SELECT * FROM vrfs WHERE device_id = ?', array($device['device_id'])) as $row) { $vrf_id = $row['vrf_id']; if (!$valid_vrf[$vrf_id]) { echo("-"); - $query = @mysql_query("DELETE FROM vrfs WHERE vrf_id = '$vrf_id'"); + dbDelete('vrfs', '`vrf_id` = ?', array($vrf_id)); } else { @@ -160,8 +151,8 @@ unset($valid_vrf_if); unset($valid_vrf); - echo("\n"); + echo(PHP_EOL); } # cisco/junos/ironware } # enable_vrfs -?> +// EOF Index: includes/discovery/processors.inc.php =================================================================== --- includes/discovery/processors.inc.php (revision 5100) +++ includes/discovery/processors.inc.php (working copy) @@ -25,25 +25,21 @@ // Last-resort discovery here include("processors/ucd-snmp-mib.inc.php"); +if ($debug && count($valid['processor'])) { print_vars($valid['processor']); } + // Remove processors which weren't redetected here - -$sql = "SELECT * FROM `processors` WHERE `device_id` = '".$device['device_id']."'"; -// FIXME dbFacile -$query = mysql_query($sql); - -if ($debug) { print_vars ($valid['processor']); } - -while ($test_processor = mysql_fetch_assoc($query)) +foreach (dbFetchRows('SELECT * FROM `processors` WHERE `device_id` = ?', array($device['device_id'])) as $test_processor) { $processor_index = $test_processor['processor_index']; - $processor_type = $test_processor['processor_type']; - if ($debug) { echo($processor_index . " -> " . $processor_type . "\n"); } + $processor_type = $test_processor['processor_type']; + $processor_descr = $test_processor['processor_descr']; + print_debug($processor_index . " -> " . $processor_type); + if (!$valid['processor'][$processor_type][$processor_index]) { - echo("-"); - // FIXME dbFacile - mysql_query("DELETE FROM `processors` WHERE processor_id = '" . $test_processor['processor_id'] . "'"); - log_event("Processor removed: type ".$processor_type." index ".$processor_index." descr ". $test_processor['processor_descr'], $device, 'processor', $test_processor['processor_id']); + echo('-'); + dbDelete('processors', '`processor_id` = ?', array($test_processor['processor_id'])); + log_event("Processor removed: type ".$processor_type." index ".$processor_index." descr ". $processor_descr, $device, 'processor', $test_processor['processor_id']); } unset($processor_oid); unset($processor_type); } @@ -50,4 +46,4 @@ echo(PHP_EOL); -// EOF \ No newline at end of file +// EOF Index: includes/discovery/vmware-vminfo.inc.php =================================================================== --- includes/discovery/vmware-vminfo.inc.php (revision 5100) +++ includes/discovery/vmware-vminfo.inc.php (working copy) @@ -100,13 +100,14 @@ * Check whether the Virtual Machine is already known for this host. */ - if (mysql_result(mysql_query("SELECT COUNT(id) FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vmwVmVMID = '" . $oid . "' AND vm_type='vmware'"), 0) == 0) + if (dbFetchCell("SELECT COUNT(`id`) FROM `vminfo` WHERE `device_id` = ? AND `vmwVmVMID` = ? AND `vm_type` = 'vmware'", array($device['device_id'], $oid)) == '0') { - mysql_query("INSERT INTO vminfo (device_id, vm_type, vmwVmVMID, vmwVmDisplayName, vmwVmGuestOS, vmwVmMemSize, vmwVmCpus, vmwVmState) VALUES (" . $device["device_id"] . ",'vmware', " . $oid . ", '" . mres($vmwVmDisplayName) . "', '" . mres($vmwVmGuestOS) . "', " . $vmwVmMemSize . ", " . $vmwVmCpus . ", '" . mres($vmwVmState) . "')"); - echo("+"); - // FIXME eventlog + $vmware_insert = array('device_id' => $device['device_id'], 'vm_type' => 'vmware', 'vmwVmVMID' => $oid, 'vmwVmDisplayName' => $vmwVmDisplayName, 'vmwVmGuestOS' => $vmwVmGuestOS, 'vmwVmMemSize' => $vmwVmMemSize, 'vmwVmCpus' => $vmwVmCpus, 'vmwVmState' => $vmwVmState); + dbInsert($vmware_insert, 'vminfo'); + echo('+'); + log_event("Virtual Machine added: $vmwVmDisplayName ($vmwVmMemSize MB)", $device, 'vm', mysql_insert_id()); } else { - echo("."); + echo('.'); } // FIXME update code! @@ -122,19 +123,17 @@ * Get a list of all the known Virtual Machines for this host. */ - $db_vm_list = mysql_query("SELECT id, vmwVmVMID FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vm_type='vmware'"); - - while ($db_vm = mysql_fetch_assoc($db_vm_list)) + foreach (dbFetchRows("SELECT id, vmwVmVMID, vmwVmDisplayName FROM `vminfo` WHERE `device_id` = ? AND `vm_type` = 'vmware'", array($device['device_id'])) as $db_vm) { /* * Delete the Virtual Machines that are removed from the host. */ - if (!in_array($db_vm["vmwVmVMID"], $vmw_vmlist)) + if (!in_array($db_vm['vmwVmVMID'], $vmw_vmlist)) { - mysql_query("DELETE FROM vminfo WHERE id = '" . $db_vm["id"] . "'"); - echo("-"); - // FIXME eventlog + dbDelete('vminfo', '`id` = ?', array($db_vm['id'])); + echo('-'); + log_event("Virtual Machine removed: " . $db_vm['vmwVmDisplayName'], $device, 'vm', $db_vm['id']); } } @@ -142,7 +141,7 @@ * Finished discovering VMware information. */ - echo("\n"); + echo(PHP_EOL); } -?> \ No newline at end of file +// EOF Index: includes/polling/applications/mssql.inc.php =================================================================== --- includes/polling/applications/mssql.inc.php (revision 5100) +++ includes/polling/applications/mssql.inc.php (working copy) @@ -173,7 +173,7 @@ } else { - dbUpdate(array('app_last_polled' => time(), 'app_status' => 1, 'app_state' => $app_data), 'applications-state', "`application_id`='".$app_state['application_id']."'"); + dbUpdate(array('app_last_polled' => time(), 'app_status' => 1, 'app_state' => $app_data), 'applications-state', "`application_id` = ?", array($app_state['application_id'])); } echo("\n");