diff --git a/database.php b/database.php
index a3d1d3a..ee2de1a 100644
--- a/database.php
+++ b/database.php
@@ -72,6 +72,17 @@ function syslog_db_fetch_cell($sql, $col_name = '', $log = TRUE) {
return db_fetch_cell($sql, $col_name, $log, $syslog_cnn);
}
+/* syslog_db_fetch_assoc_prepared - run a 'select' sql query and return all rows found
+ @arg $sql - the sql query to run
+ @arg $params - the parameters to bind to the query
+ @arg $log - whether or not to log the query to the cacti log
+ @returns - the complete result set as an associative array */
+function syslog_db_fetch_assoc_prepared(string $sql, array $params = [], bool $log = true) {
+ global $syslog_cnn;
+
+ return db_fetch_assoc_prepared($sql, $params, $log, $syslog_cnn);
+}
+
/* syslog_db_fetch_cell_prepared - run a 'select' sql query and return the first column of the
first row found
@param $sql - the sql query to execute
@@ -128,4 +139,3 @@ function syslog_sql_save($array_items, $table_name, $key_cols = 'id', $autoinc =
global $syslog_cnn;
return sql_save($array_items, $table_name, $key_cols, $autoinc, $syslog_cnn);
}
-
diff --git a/functions.php b/functions.php
index 5c6c7c0..a0368f5 100644
--- a/functions.php
+++ b/functions.php
@@ -226,6 +226,12 @@ function syslog_remove_items($table, $uniqueID) {
if (sizeof($rows)) {
foreach($rows as $remove) {
+ /* SQL expressions are legacy, untrusted input and cannot be safely bound
+ * as prepared-statement values. Ignore them rather than executing raw SQL. */
+ if ($remove['type'] === 'sql') {
+ cacti_log('Syslog SQL removal rules are disabled for safety.', false, 'SYSTEM');
+ continue;
+ }
$sql = '';
$sql1 = '';
if ($remove['type'] == 'facility') {
@@ -624,7 +630,7 @@ function syslog_debug($message) {
}
}
-function syslog_log_alert($alert_id, $alert_name, $severity, $msg, $count = 1, $html) {
+function syslog_log_alert($alert_id, $alert_name, $severity, $msg, $count = 1, $html = '') {
global $config, $severities;
include(dirname(__FILE__) . '/config.php');
@@ -800,4 +806,3 @@ function syslog_manage_items($from_table, $to_table) {
return array('removed' => $removed, 'xferred' => $xferred);
}
-
diff --git a/setup.php b/setup.php
index e70d620..92d578b 100644
--- a/setup.php
+++ b/setup.php
@@ -928,7 +928,6 @@ function syslog_config_arrays () {
'messagee' => __('Ends with', 'syslog'),
'host' => __('Hostname is', 'syslog'),
'facility' => __('Facility is', 'syslog'),
- 'sql' => __('SQL Expression', 'syslog')
);
$syslog_freqs = array(
@@ -1093,4 +1092,3 @@ function syslog_utilities_list() {
' . (get_request_var('host') != '-2' ? $r['host']:'-') . '';
+ echo '
' . (get_request_var('host') !== '-2' ? html_escape($r['host']):'-') . ' | ';
echo '' . (get_request_var('facility') != '-2' ? ucfirst($r['facility']):'-') . ' | ';
echo '' . (get_request_var('priority') != '-2' ? ucfirst($r['priority']):'-') . ' | ';
- echo '' . (get_request_var('program') != '-2' ? ucfirst($r['program']):'-') . ' | ';
+ echo '' . (get_request_var('program') !== '-2' ? html_escape(ucfirst($r['program'])):'-') . ' | ';
//echo '' . $r['insert_time'] . ' | ';
echo '' . $time . ' | ';
echo '' . number_format_i18n($r['records'], -1) . ' | ';
@@ -1667,4 +1667,3 @@ function get_ajax_programs($include_any = true, $sql_where = '') {
print json_encode($return);
}
-
diff --git a/syslog_alerts.php b/syslog_alerts.php
index aef6775..3669f7f 100644
--- a/syslog_alerts.php
+++ b/syslog_alerts.php
@@ -117,14 +117,14 @@ function form_actions() {
form_start('syslog_alerts.php');
- html_start_box($syslog_actions{get_request_var('drp_action')}, '60%', '', '3', 'center', '');
+ html_start_box($syslog_actions[get_request_var('drp_action')], '60%', '', '3', 'center', '');
/* setup some variables */
- $alert_array = array(); $alert_list = '';
+ $alert_array = []; $alert_list = '';
/* loop through each of the clusters selected on the previous page and get more info about them */
- while (list($var,$val) = each($_POST)) {
- if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
+ foreach (array_keys($_POST) as $var) {
+ if (preg_match('/^chk_([0-9]+)$/', $var, $matches) === 1) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
@@ -720,4 +720,3 @@ function syslog_alerts() {
form_end();
}
-
diff --git a/syslog_process.php b/syslog_process.php
index 681632b..5078f17 100644
--- a/syslog_process.php
+++ b/syslog_process.php
@@ -272,43 +272,53 @@
$smsalert = '';
$th_sql = '';
- if ($alert['type'] == 'facility') {
+ $params = [];
+ if ($alert['type'] === 'facility') {
$sql = 'SELECT * FROM `' . $syslogdb_default . '`.`syslog_incoming`
- WHERE ' . $syslog_incoming_config['facilityField'] . "='" . $alert['message'] . "'
- AND status=" . $uniqueID;
- } else if ($alert['type'] == 'messageb') {
+ WHERE ' . $syslog_incoming_config['facilityField'] . '=?
+ AND status=?';
+ $params[] = $alert['message'];
+ $params[] = $uniqueID;
+ } elseif ($alert['type'] === 'messageb') {
$sql = 'SELECT * FROM `' . $syslogdb_default . '`.`syslog_incoming`
- WHERE ' . $syslog_incoming_config['textField'] . "
- LIKE '" . $alert['message'] . "%'
- AND status=" . $uniqueID;
- } else if ($alert['type'] == 'messagec') {
+ WHERE ' . $syslog_incoming_config['textField'] . '
+ LIKE ?
+ AND status=?';
+ $params[] = $alert['message'] . '%';
+ $params[] = $uniqueID;
+ } elseif ($alert['type'] === 'messagec') {
$sql = 'SELECT * FROM `' . $syslogdb_default . '`.`syslog_incoming`
- WHERE ' . $syslog_incoming_config['textField'] . "
- LIKE '%" . $alert['message'] . "%'
- AND status=" . $uniqueID;
- } else if ($alert['type'] == 'messagee') {
+ WHERE ' . $syslog_incoming_config['textField'] . '
+ LIKE ?
+ AND status=?';
+ $params[] = '%' . $alert['message'] . '%';
+ $params[] = $uniqueID;
+ } elseif ($alert['type'] === 'messagee') {
$sql = 'SELECT * FROM `' . $syslogdb_default . '`.`syslog_incoming`
- WHERE ' . $syslog_incoming_config['textField'] . "
- LIKE '%" . $alert['message'] . "'
- AND status=" . $uniqueID;
- } else if ($alert['type'] == 'host') {
+ WHERE ' . $syslog_incoming_config['textField'] . '
+ LIKE ?
+ AND status=?';
+ $params[] = '%' . $alert['message'];
+ $params[] = $uniqueID;
+ } elseif ($alert['type'] === 'host') {
$sql = 'SELECT * FROM `' . $syslogdb_default . '`.`syslog_incoming`
- WHERE ' . $syslog_incoming_config['hostField'] . "='" . $alert['message'] . "'
- AND status=" . $uniqueID;
- } else if ($alert['type'] == 'sql') {
- $sql = 'SELECT * FROM `' . $syslogdb_default . '`.`syslog_incoming`
- WHERE (' . $alert['message'] . ')
- AND status=' . $uniqueID;
+ WHERE ' . $syslog_incoming_config['hostField'] . '=?
+ AND status=?';
+ $params[] = $alert['message'];
+ $params[] = $uniqueID;
+ } elseif ($alert['type'] === 'sql') {
+ cacti_log('Syslog SQL alert rules are disabled for safety.', false, 'SYSTEM');
+ continue;
}
- if ($sql != '') {
- if ($alert['method'] == '1') {
+ if ($sql !== '') {
+ if ($alert['method'] === '1') {
$th_sql = str_replace('*', 'count(*)', $sql);
- $count = syslog_db_fetch_cell($th_sql);
+ $count = syslog_db_fetch_cell_prepared($th_sql, $params);
}
- if (($alert['method'] == '1' && $count >= $alert['num']) || ($alert['method'] == '0')) {
- $at = syslog_db_fetch_assoc($sql);
+ if (($alert['method'] === '1' && $count >= $alert['num']) || $alert['method'] === '0') {
+ $at = syslog_db_fetch_assoc_prepared($sql, $params);
/* get a date for the repeat alert */
if ($alert['repeat_alert']) {
diff --git a/syslog_removal.php b/syslog_removal.php
index e5f59db..c8df107 100644
--- a/syslog_removal.php
+++ b/syslog_removal.php
@@ -126,14 +126,14 @@ function form_actions() {
form_start('syslog_removal.php');
- html_start_box($syslog_actions{get_request_var('drp_action')}, '60%', '', '3', 'center', '');
+ html_start_box($syslog_actions[get_request_var('drp_action')], '60%', '', '3', 'center', '');
/* setup some variables */
- $removal_array = array(); $removal_list = '';
+ $removal_array = []; $removal_list = '';
/* loop through each of the clusters selected on the previous page and get more info about them */
- while (list($var,$val) = each($_POST)) {
- if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
+ foreach (array_keys($_POST) as $var) {
+ if (preg_match('/^chk_([0-9]+)$/', $var, $matches) === 1) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
@@ -644,4 +644,3 @@ function syslog_removal() {
form_end();
}
-
diff --git a/syslog_reports.php b/syslog_reports.php
index cb49174..71ec6da 100644
--- a/syslog_reports.php
+++ b/syslog_reports.php
@@ -114,14 +114,14 @@ function form_actions() {
form_start('syslog_reports.php');
- html_start_box($syslog_actions{get_request_var('drp_action')}, '60%', '', '3', 'center', '');
+ html_start_box($syslog_actions[get_request_var('drp_action')], '60%', '', '3', 'center', '');
/* setup some variables */
- $report_array = array(); $report_list = '';
+ $report_array = []; $report_list = '';
/* loop through each of the clusters selected on the previous page and get more info about them */
- while (list($var,$val) = each($_POST)) {
- if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
+ foreach (array_keys($_POST) as $var) {
+ if (preg_match('/^chk_([0-9]+)$/', $var, $matches) === 1) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
@@ -633,4 +633,3 @@ function syslog_report() {
form_end();
}
-