diff --git a/html/includes/graphs/graph.inc.php b/html/includes/graphs/graph.inc.php index b889dfd36..94e4e739f 100644 --- a/html/includes/graphs/graph.inc.php +++ b/html/includes/graphs/graph.inc.php @@ -19,12 +19,13 @@ else ini_set('error_reporting', 0); } -include("../includes/defaults.inc.php"); -include("../config.php"); -include("../includes/common.php"); -include("../includes/rewrites.php"); -include("includes/functions.inc.php"); -include("includes/authenticate.inc.php"); +include_once("../includes/defaults.inc.php"); +include_once("../config.php"); +include_once("../includes/common.php"); +include_once("../includes/dbFacile.php"); +include_once("../includes/rewrites.php"); +include_once("includes/functions.inc.php"); +include_once("includes/authenticate.inc.php"); $from = mres($_GET['from']); $to = mres($_GET['to']); @@ -145,4 +146,4 @@ if (!$auth) } } -?> \ No newline at end of file +?> diff --git a/includes/billing.php b/includes/billing.php index 00626fcfc..c54c2cce7 100644 --- a/includes/billing.php +++ b/includes/billing.php @@ -19,9 +19,8 @@ function getDates($dayofmonth) $date_from = $year . $month . $dayofmonth; $date_to = $newyear . $newmonth . $dayofmonth; - $dt_q = mysql_query("SELECT DATE_SUB(DATE_ADD('$date_from', INTERVAL 1 MONTH), INTERVAL 1 DAY);"); - $date_to = mysql_result($dt_q,0); - $date_to = str_replace("-","",$date_to); + $date_to = dbFetchCell("SELECT DATE_SUB(DATE_ADD('".mres($date_from)."', INTERVAL 1 MONTH), INTERVAL 1 DAY)"); + $date_to = str_replace("-","",$date_to); } else { @@ -36,17 +35,14 @@ function getDates($dayofmonth) $date_from = $newyear . $newmonth . $dayofmonth; $date_to = $year . $month . $dayofmonth; - $dt_q = mysql_query("SELECT DATE_SUB(DATE_ADD('$date_to', INTERVAL 1 MONTH, INTERVAL 1 DAY);"); - $date_from = mysql_result($dt_q,0); + $date_from = dbFetchCell("SELECT DATE_SUB(DATE_ADD('".mres($date_to)."', INTERVAL 1 MONTH, INTERVAL 1 DAY)"); $date_from = str_replace("-","",$date_from); } - $lq_from = mysql_query("SELECT DATE_SUB('$date_from', INTERVAL 1 MONTH);"); - $last_from = mysql_result($lq_from,0); + $last_from = dbFetchCell("SELECT DATE_SUB('".mres($date_from)."', INTERVAL 1 MONTH)"); $last_from = str_replace("-","",$last_from); - $lq_to = mysql_query("SELECT DATE_SUB('$date_to', INTERVAL 1 MONTH);"); - $last_to = mysql_result($lq_to,0); + $last_to = dbFetchCell("SELECT DATE_SUB('".mres($date_to)."', INTERVAL 1 MONTH)"); $last_to = str_replace("-","",$last_to); $return['0'] = $date_from . "000000"; @@ -63,7 +59,7 @@ function getValue($host, $port, $id, $inout) global $config; $oid = "IF-MIB::ifHC" . $inout . "Octets." . $id; - $device = mysql_fetch_assoc(mysql_query("SELECT * from `devices` WHERE `hostname` = '" . $host . "' LIMIT 1")); + $device = dbFetchRow("SELECT * from `devices` WHERE `hostname` = '".mres($host)."' LIMIT 1"); $value = snmp_get($device, $oid, "-O qv"); if (!is_numeric($value)) @@ -77,15 +73,13 @@ function getValue($host, $port, $id, $inout) function getLastPortCounter($port_id,$inout) { - $query = mysql_query("SELECT count(counter) from port_" . $inout . "_measurements WHERE port_id=" . $port_id); - $rows = mysql_result($query, 0); + $rows = dbFetchCell("SELECT count(counter) from `port_" . mres($inout) . "_measurements` WHERE `port_id`='" . mres($port_id)."'"); if ($rows > 0) { - $query = mysql_query("SELECT counter,delta FROM port_" . $inout . "_measurements WHERE port_id=$port_id ORDER BY timestamp DESC"); - $row = mysql_fetch_row($query); - $return[counter] = $row[0]; - $return[delta] = $row[1]; + $row = dbFetchRow("SELECT counter,delta FROM `port_".mres($inout)."_measurements` WHERE `port_id`='".mres($port_id)."' ORDER BY timestamp DESC"); + $return[counter] = $row['counter']; + $return[delta] = $row['delta']; $return[state] = "ok"; } else { $return[state] = "failed"; @@ -96,17 +90,15 @@ function getLastPortCounter($port_id,$inout) function getLastMeasurement($bill_id) { - $query = mysql_query("SELECT count(delta) from bill_data WHERE bill_id=" . $bill_id); - $rows = mysql_result($query, 0); + $rows = dbFetchCell("SELECT count(delta) from bill_data WHERE bill_id='".mres($bill_id)."'"); if ($rows > 0) { - $query = mysql_query("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id=$bill_id ORDER BY timestamp DESC"); - $row = mysql_fetch_row($query); - $return[delta] = $row[1]; - $return[delta] = $row[2]; - $return[delta] = $row[3]; - $return[timestamp] = $row[0]; + $row = dbFetchRow("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id='".mres($bill_id)."' ORDER BY timestamp DESC"); + $return[delta] = $row['delta']; + $return[delta_in] = $row['delta_in']; + $return[delta_out] = $row['delta_out']; + $return[timestamp] = $row['timestamp']; $return[state] = "ok"; } else { $return[state] = "failed"; @@ -117,32 +109,31 @@ function getLastMeasurement($bill_id) function get95thin($bill_id,$datefrom,$dateto) { - $mq_text = "SELECT count(delta) FROM bill_data WHERE bill_id = $bill_id"; - $mq_text .= " AND timestamp > $datefrom AND timestamp <= $dateto"; - $m_query = mysql_query($mq_text); - $measurements = mysql_result($m_query,0); + $mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = '".mres($bill_id)."'"; + $mq_sql .= " AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'"; + $measurements = dbFetchCell($mq_sql); $measurement_95th = round($measurements /100 * 95) - 1; - $q_95_text = "SELECT (in_delta / period / 1000 * 8) AS rate FROM bill_data WHERE bill_id = $bill_id"; - $q_95_text .= " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY in_delta ASC"; - $q_95th = mysql_query($q_95_text); - $m_95th = mysql_result($q_95th,$measurement_95th); + $q_95_sql = "SELECT (in_delta / period / 1000 * 8) AS rate FROM bill_data WHERE bill_id = '".mres($bill_id)."'"; + $q_95_sql .= " AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."' ORDER BY in_delta ASC"; + $a_95th = dbFetchColumn($q_95_sql); + $m_95th = $a_95th[$measurement_95th]; return(round($m_95th, 2)); } function get95thout($bill_id,$datefrom,$dateto) { - $mq_text = "SELECT count(delta) FROM bill_data WHERE bill_id = $bill_id"; - $mq_text .= " AND timestamp > $datefrom AND timestamp <= $dateto"; - $m_query = mysql_query($mq_text); - $measurements = mysql_result($m_query,0); + $mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = '".mres($bill_id)."'"; + $mq_sql .= " AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'"; + $measurements = dbFetchCell($mq_sql); $measurement_95th = round($measurements /100 * 95) - 1; - $q_95_text = "SELECT (out_delta / period / 1000 * 8) AS rate FROM bill_data WHERE bill_id = $bill_id"; - $q_95_text .= " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY out_delta ASC"; - $q_95th = mysql_query($q_95_text); - $m_95th = mysql_result($q_95th,$measurement_95th); + $q_95_sql = "SELECT (out_delta / period / 1000 * 8) AS rate FROM bill_data WHERE bill_id = '".mres($bill_id)."'"; + $q_95_sql .= " AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."' ORDER BY out_delta ASC"; + + $a_95th = dbFetchColumn($q_95_sql); + $m_95th = $a_95th[$measurement_95th]; return(round($m_95th, 2)); } @@ -150,19 +141,19 @@ function get95thout($bill_id,$datefrom,$dateto) function getRates($bill_id,$datefrom,$dateto) { $mq_text = "SELECT count(delta) FROM bill_data "; - $mq_text = $mq_text . " WHERE bill_id = $bill_id"; - $mq_text = $mq_text . " AND timestamp > $datefrom AND timestamp <= $dateto"; - $m_query = mysql_query($mq_text); - $measurements = mysql_result($m_query,0); + $mq_text .= " WHERE bill_id = '".mres($bill_id)."'"; + $mq_text .= " AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'"; + $measurements = dbFetchCell($mq_sql); $measurement_95th = round($measurements /100 * 95) - 1; - $q_95_text = "SELECT delta FROM bill_data WHERE bill_id = $bill_id"; - $q_95_text = $q_95_text . " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY delta ASC"; - $q_95th = mysql_query($q_95_text); - $m_95th = mysql_result($q_95th,$measurement_95th); + $q_95_sql = "SELECT delta FROM bill_data WHERE bill_id = '".mres($bill_id)."'"; + $q_95_sql .= " AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."' ORDER BY delta ASC"; + + $a_95th = dbFetchColumn($q_95_sql); + $m_95th = $a_95th[$measurement_95th]; + + $mtot = getTotal($bill_id,$datefrom,$dateto); - $mt_q = mysql_query("SELECT SUM(delta) FROM bill_data WHERE bill_id = '$bill_id' AND timestamp > '$datefrom' AND timestamp <= '$dateto'"); - $mtot = mysql_result($mt_q,0); $data['rate_95th_in'] = get95thIn($bill_id,$datefrom,$dateto); $data['rate_95th_out'] = get95thOut($bill_id,$datefrom,$dateto); @@ -183,10 +174,9 @@ function getRates($bill_id,$datefrom,$dateto) function getTotal($bill_id,$datefrom,$dateto) { - $mt_q = mysql_query("SELECT sum(delta) FROM bill_data WHERE bill_id = $bill_id AND timestamp > $datefrom AND timestamp <= $dateto"); - $mtot = mysql_result($mt_q,0); + $mtot = dbFetchCell("SELECT SUM(delta) FROM bill_data WHERE bill_id = '".mres($bill_id)."' AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'"); return($mtot); } -?> \ No newline at end of file +?> diff --git a/includes/functions.php b/includes/functions.php index 14d83f633..48277932d 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -138,7 +138,7 @@ function renamehost($id, $new, $source = 'console') { global $config; - $host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0); + $host = dbFetchCell("SELECT hostname FROM devices WHERE device_id = '$id'"); 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'); @@ -166,7 +166,7 @@ function delete_device($id) { global $config; - $host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0); + $host = dbFetchCell("SELECT hostname FROM devices WHERE device_id = '$id'"); mysql_query("DELETE FROM `devices` WHERE `device_id` = '$id'"); $int_query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '$id'"); while ($int_data = mysql_fetch_assoc($int_query)) @@ -209,7 +209,7 @@ function addHost($host, $community, $snmpver, $port = 161, $transport = 'udp') { if (isPingable($host)) { - if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0') + if (dbFetchCell("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'") == '0') { # FIXME internalize -- but we don't have $device yet! # FIXME this needs to be addhost.php's content instead, kindof, also use this function there then. diff --git a/includes/syslog.php b/includes/syslog.php index 0277e3092..0ffbee767 100755 --- a/includes/syslog.php +++ b/includes/syslog.php @@ -17,7 +17,7 @@ function process_syslog ($entry, $update) $delete = 1; } - $device_id_host = @mysql_result(mysql_query("SELECT device_id FROM devices WHERE `hostname` = '".$entry['host']."' OR `sysName` = '".$entry['host']."'"),0); + $device_id_host = @dbFetchCell("SELECT device_id FROM devices WHERE `hostname` = '".mres($entry['host'])."' OR `sysName` = '".mres($entry['host'])."'"); if ($device_id_host) { @@ -25,8 +25,8 @@ function process_syslog ($entry, $update) } else { - $device_id_ip = @mysql_result(mysql_query("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE - A.ipv4_address = '" . $entry['host']."' AND I.interface_id = A.interface_id"),0); + $device_id_ip = @dbFetchCell("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE + A.ipv4_address = '" . $entry['host']."' AND I.interface_id = A.interface_id"); if ($device_id_ip) { $entry['device_id'] = $device_id_ip; @@ -35,7 +35,7 @@ function process_syslog ($entry, $update) if ($entry['device_id'] && !$delete) { - $os = mysql_result(mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '".$entry['device_id']."'"),0); + $os = dbFetchCell("SELECT `os` FROM `devices` WHERE `device_id` = '".mres($entry['device_id'])."'"); if ($os == 'catos') { $matches = array(); @@ -97,4 +97,4 @@ function process_syslog ($entry, $update) return $entry; } -?> \ No newline at end of file +?>