Skip to content

Commit

Permalink
Resolving Issue #90
Browse files Browse the repository at this point in the history
Can not show correct info when choose device filter in Syslog - Alert Log page
  • Loading branch information
cigamit committed Jun 29, 2019
1 parent e3ddbb6 commit 704c4ac
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 31 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ The sylog plugin has been in development for well over a decade with increasing
## ChangeLog

--- develop ---
* issue#90: Can not show correct info when choose device filter in Syslog - Alert Log page
* issue#91: Page become blank after collecting multiple host syslog info
* issue#94: Stored XSS in syslog_removal.php

Expand Down
7 changes: 6 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ function sql_hosts_where($tab) {

$hostfilter = '';
$hostfilter_log = '';
$hosts_array = array();

if (!isempty_request_var('host') && get_nfilter_request_var('host') != 'null') {
$hostarray = explode(',', trim(get_nfilter_request_var('host')));
Expand All @@ -596,11 +597,15 @@ function sql_hosts_where($tab) {
array($host_id));

if (!empty($log_host)) {
$hostfilter_log .= ($hostfilter_log != '' ? ' AND ':'') . 'host = ' . db_qstr($log_host);
$hosts_array[] = db_qstr($log_host);
}
}
}

if (sizeof($hosts_array)) {
$hostfilter_log = ' host IN(' . implode(',', $hosts_array) . ')';
}

$hostfilter .= (strlen($hostfilter) ? ' AND ':'') . ' host_id IN(' . implode(',', $hostarray) . ')';
}
}
Expand Down
27 changes: 24 additions & 3 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -1176,13 +1176,34 @@ function syslog_utilities_action($action) {
if ($action == 'purge_syslog_hosts') {
$records = 0;

syslog_db_execute('DELETE FROM syslog_hosts WHERE host_id NOT IN (SELECT DISTINCT host_id FROM syslog UNION SELECT DISTINCT host_id FROM syslog_removed)');
syslog_db_execute('DELETE FROM syslog_hosts
WHERE host_id NOT IN (
SELECT DISTINCT host_id
FROM syslog
UNION
SELECT DISTINCT host_id
FROM syslog_removed
)');
$records += db_affected_rows($syslog_cnn);

syslog_db_execute('DELETE FROM syslog_host_facilities WHERE host_id NOT IN (SELECT DISTINCT host_id FROM syslog UNION SELECT DISTINCT host_id FROM syslog_removed)');
syslog_db_execute('DELETE FROM syslog_host_facilities
WHERE host_id NOT IN (
SELECT DISTINCT host_id
FROM syslog
UNION
SELECT DISTINCT host_id
FROM syslog_removed
)');
$records += db_affected_rows($syslog_cnn);

syslog_db_execute('DELETE FROM syslog_statistics WHERE host_id NOT IN (SELECT DISTINCT host_id FROM syslog UNION SELECT DISTINCT host_id FROM syslog_removed)');
syslog_db_execute('DELETE FROM syslog_statistics
WHERE host_id NOT IN (
SELECT DISTINCT host_id
FROM syslog
UNION
SELECT DISTINCT host_id
FROM syslog_removed
)');
$records += db_affected_rows($syslog_cnn);

raise_message('syslog_info', __('There were %s Device records removed from the Syslog database', $records, 'syslog'), MESSAGE_LEVEL_INFO);
Expand Down
59 changes: 33 additions & 26 deletions syslog.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,31 +774,40 @@ function get_syslog_messages(&$sql_where, $rows, $tab) {

$sql_where = '';

if (get_request_var('host') == 0 && $tab != 'syslog') {
// Show all hosts
} elseif (strpos(get_request_var('host'), '-1') !== false && $tab != 'syslog') {
// Show threshold type only plus matching hosts if any
$hosts = explode(',', get_request_var('host'));
if ($tab == 'alerts') {
if (get_request_var('host') == 0) {
// Show all hosts
} else {
$hosts = explode(',', get_request_var('host'));

if (cacti_sizeof($hosts) > 1) {
sql_hosts_where($tab);
$thold_pos = array_search('-1', $hosts, true);

if (strlen($hostfilter_log)) {
$sql_where .= 'WHERE ' . $hostfilter_log;
if ($thold_pos !== false) {
unset($hosts[$thold_pos]);
}
}

$ids = array_rekey(
syslog_db_fetch_assoc('SELECT id
FROM syslog_alert
WHERE method = 1'),
'id', 'id'
);
if (sizeof($hosts)) {
sql_hosts_where($tab);

if (cacti_sizeof($ids)) {
$sql_where .= ($sql_where == '' ? 'WHERE ':' AND ') . 'alert_id IN (' . implode(', ', $ids) . ')';
} else {
$sql_where .= ($sql_where == '' ? 'WHERE ':' AND ') . '0 = 1';
if (strlen($hostfilter_log)) {
$sql_where .= 'WHERE ' . $hostfilter_log;
}
}

if ($thold_pos !== false) {
$ids = array_rekey(
syslog_db_fetch_assoc('SELECT id
FROM syslog_alert
WHERE method = 1'),
'id', 'id'
);

if (cacti_sizeof($ids)) {
$sql_where .= ($sql_where == '' ? 'WHERE ':' OR ') . 'alert_id IN (' . implode(', ', $ids) . ')';
} elseif ($sql_where == '') {
$sql_where .= 'WHERE 0 = 1';
}
}
}
} elseif ($tab == 'syslog') {
if (!isempty_request_var('host')) {
Expand All @@ -808,8 +817,6 @@ function get_syslog_messages(&$sql_where, $rows, $tab) {
$sql_where .= 'WHERE ' . $hostfilter;
}
}
} elseif (!isempty_request_var('host') && $hostfilter_log != '') {
$sql_where .= 'WHERE ' . $hostfilter_log;
}

$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') .
Expand All @@ -823,18 +830,18 @@ function get_syslog_messages(&$sql_where, $rows, $tab) {

if (!isempty_request_var('filter')) {
if ($tab == 'syslog') {
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . "message LIKE " . db_qstr('%' . get_request_var('filter') . '%');
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . 'message LIKE ' . db_qstr('%' . get_request_var('filter') . '%');
} else {
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . "logmsg LIKE " . db_qstr('%' . get_request_var('filter') . '%');
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . 'logmsg LIKE ' . db_qstr('%' . get_request_var('filter') . '%');
}
}

if (get_request_var('eprogram') != '-1') {
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . "syslog.program_id = " . db_qstr(get_request_var('eprogram'));
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . 'syslog.program_id = ' . db_qstr(get_request_var('eprogram'));
}

if (get_request_var('efacility') != '-1') {
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . "syslog.facility_id = " . db_qstr(get_request_var('efacility'));
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . 'syslog.facility_id = ' . db_qstr(get_request_var('efacility'));
}

if (isset_request_var('epriority') && get_request_var('epriority') != '-1') {
Expand Down
5 changes: 4 additions & 1 deletion syslog_process.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@
/* get a uniqueID to allow moving of records to done table */
while (1) {
$uniqueID = rand(1, 127);
$count = syslog_db_fetch_cell('SELECT count(*) FROM `' . $syslogdb_default . '`.`syslog_incoming` WHERE status=' . $uniqueID);

$count = syslog_db_fetch_cell('SELECT count(*)
FROM `' . $syslogdb_default . '`.`syslog_incoming`
WHERE status=' . $uniqueID);

if ($count == 0) {
break;
Expand Down

0 comments on commit 704c4ac

Please sign in to comment.