From be567490b12700998d427723dd5a347c3d07e907 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Thu, 9 Apr 2026 14:49:29 -0400 Subject: [PATCH 1/2] fix: Correcting issues with predefined timespan --- js/functions.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/js/functions.js b/js/functions.js index a96d47d..25dacc5 100644 --- a/js/functions.js +++ b/js/functions.js @@ -73,9 +73,8 @@ function applyTimespan() { */ function applyFilter() { var strURL = 'syslog.php?tab='+(window.pageTab || ''); + strURL += '&header=false'; - strURL += '&date1='+$('#date1').val(); - strURL += '&date2='+$('#date2').val(); strURL += '&host='+$('#host').val(); strURL += '&rfilter='+base64_encode($('#rfilter').val()); strURL += '&efacility='+$('#efacility').val(); @@ -86,6 +85,14 @@ function applyFilter() { strURL += '&removal='+$('#removal').val(); strURL += '&refresh='+$('#refresh').val(); strURL += '&grouping=' + ($('#grouping').length ? $('#grouping').val() : '0'); + + if ($('#predefined_timespan').val() == 0) { + strURL += '&date1='+$('#date1').val(); + strURL += '&date2='+$('#date2').val(); + } else { + strURL += '&predefined_timespan='+$('#predefined_timespan').val(); + } + loadPageNoHeader(strURL); } @@ -577,7 +584,7 @@ function initSyslogAutocomplete(formName, callback, onChange) { var formNameTimer; var formNameClickTimer; var formNameOpen = false; - + $(function() { $('#' + formName + '_input').autocomplete({ source: window.location.pathname + '?action=' + callback, @@ -614,8 +621,8 @@ function initSyslogAutocomplete(formName, callback, onChange) { }, 200); } }).on('mouseleave', function() { - formNameTimer = setTimeout(function() { - $('#' + formName + '_input').autocomplete('close'); + formNameTimer = setTimeout(function() { + $('#' + formName + '_input').autocomplete('close'); }, 800); }); @@ -630,8 +637,8 @@ function initSyslogAutocomplete(formName, callback, onChange) { $('ul[id^="ui-id"]').on('mouseenter', function() { clearTimeout(formNameTimer); }).on('mouseleave', function() { - formNameTimer = setTimeout(function() { - $('#' + formName + '_input').autocomplete('close'); + formNameTimer = setTimeout(function() { + $('#' + formName + '_input').autocomplete('close'); }, 800); }); From 12e48e68db778371abebce9dd47fdb4384a4fd50 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Thu, 9 Apr 2026 15:59:55 -0400 Subject: [PATCH 2/2] QA: Additional fixes for timespan work --- js/functions.js | 26 ++- syslog.php | 507 ++++++++++++++++++++++++------------------------ 2 files changed, 268 insertions(+), 265 deletions(-) diff --git a/js/functions.js b/js/functions.js index 25dacc5..271dcda 100644 --- a/js/functions.js +++ b/js/functions.js @@ -85,13 +85,9 @@ function applyFilter() { strURL += '&removal='+$('#removal').val(); strURL += '&refresh='+$('#refresh').val(); strURL += '&grouping=' + ($('#grouping').length ? $('#grouping').val() : '0'); - - if ($('#predefined_timespan').val() == 0) { - strURL += '&date1='+$('#date1').val(); - strURL += '&date2='+$('#date2').val(); - } else { - strURL += '&predefined_timespan='+$('#predefined_timespan').val(); - } + strURL += '&predefined_timespan='+$('#predefined_timespan').val(); + strURL += '&date1='+$('#date1').val(); + strURL += '&date2='+$('#date2').val(); loadPageNoHeader(strURL); } @@ -174,6 +170,8 @@ function initSyslogMain(config) { var pageTab = config.pageTab || ''; var hostTerm = ''; var placeHolder = config.placeHolder || ''; + var origDate1 = $('#date1').val(); + var origDate2 = $('#date2').val(); // Make pageTab global for other functions window.pageTab = pageTab; @@ -322,9 +320,13 @@ function initSyslogMain(config) { stepMinute: 1, showAnim: 'slideDown', numberOfMonths: 1, - timeFormat: 'HH:mm', + timeFormat: 'HH:mm:ss', dateFormat: 'yy-mm-dd', showButtonPanel: false + }).on('change', function() { + if ($('#date1').val() != origDate1) { + $('#predefined_timespan').val(0).selectmenu('refresh'); + } }); $('#date2').datetimepicker({ @@ -332,10 +334,14 @@ function initSyslogMain(config) { stepMinute: 1, showAnim: 'slideDown', numberOfMonths: 1, - timeFormat: 'HH:mm', + timeFormat: 'HH:mm:ss', dateFormat: 'yy-mm-dd', showButtonPanel: false - }); + }).on('change', function() { + if ($('#date2').val() != origDate2) { + $('#predefined_timespan').val(0).selectmenu('refresh'); + } + });; }); } diff --git a/syslog.php b/syslog.php index 7db1ef7..4261243 100644 --- a/syslog.php +++ b/syslog.php @@ -1,27 +1,27 @@ | + | Originally released as aloe by: sidewinder at shitworks.com | + | Modified by: Harlequin | +-------------------------------------------------------------------------+ - | http://www.cacti.net/ | + | http://www.cacti.net/ | +-------------------------------------------------------------------------+ */ @@ -76,7 +76,7 @@ if (isset_request_var('refresh')) { $refresh['seconds'] = get_request_var('refresh'); - $refresh['page'] = $config['url_path'] . 'plugins/syslog/syslog.php?header=false&tab=' . $current_tab; + $refresh['page'] = $config['url_path'] . 'plugins/syslog/syslog.php?header=false&tab=' . $current_tab; $refresh['logout'] = 'false'; set_page_refresh($refresh); @@ -150,7 +150,7 @@ function get_ajax_hosts() { } $rhosts[$host['host_id']] = array( - 'host' => $host['host'], + 'host' => $host['host'], 'host_id' => $host['id'], 'class' => $class ); @@ -183,17 +183,17 @@ function syslog_display_tabs($current_tab) { } /* draw the tabs */ - print "
"; } function syslog_view_alarm() { @@ -202,7 +202,7 @@ function syslog_view_alarm() { print ""; print ""; - print "'; //print ''; print ''; - print ''; + print ''; form_end_row(); @@ -393,7 +393,7 @@ function get_stats_records(&$sql_where, &$sql_groupby, $rows) { /* form the 'where' clause for our main sql query */ if (!isempty_request_var('rfilter')) { $sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . - "sh.host RLIKE '" . get_request_var('rfilter') . "' + "sh.host RLIKE '" . get_request_var('rfilter') . "' OR spr.program RLIKE '" . get_request_var('rfilter') . "'"; } @@ -541,7 +541,7 @@ function syslog_stats_filter() { if (cacti_sizeof($facilities)) { foreach ($facilities as $r) { - print '\n"; + print '"; } } ?> @@ -561,7 +561,7 @@ function syslog_stats_filter() { if (cacti_sizeof($priorities)) { foreach ($priorities as $r) { - print '\n"; + print '"; } } ?> @@ -591,7 +591,7 @@ function syslog_stats_filter() { '; print "'; print "'; - print "'; - print "'; + print "'; + print "'; print "'; - print "'; - print "'; - print "'; + print "'; + print "'; + print "'; print ''; html_end_box(false); } @@ -1549,10 +1546,10 @@ function syslog_log_legend() { html_start_box('', '100%', '', '3', 'center', ''); print ''; - print "'; - print "'; - print "'; - print "'; + print "'; + print "'; + print "'; + print "'; print ''; html_end_box(false); } @@ -1597,7 +1594,7 @@ function syslog_messages($tab = 'syslog') { if ($tab == 'syslog') { // Check if grouping is enabled for row count $grouping_enabled = isset_request_var('grouping') && get_request_var('grouping') == '1'; - + if ($grouping_enabled) { // When grouping, count distinct groups instead of individual rows if (get_request_var('removal') == 1) { @@ -1660,30 +1657,30 @@ function syslog_messages($tab = 'syslog') { if ($tab == 'syslog') { // Check if grouping is enabled for display $grouping_enabled = isset_request_var('grouping') && get_request_var('grouping') == '1'; - + if (api_plugin_user_realm_auth('syslog_alerts.php')) { $display_text = array( - 'nosortt' => array(__('Actions', 'syslog'), 'ASC'), - 'logtime' => array(__('Date', 'syslog'), 'ASC'), - 'host_id' => array(__('Device', 'syslog'), 'ASC'), - 'program' => array(__('Program', 'syslog'), 'ASC'), - 'message' => array(__('Message', 'syslog'), 'ASC'), + 'nosortt' => array(__('Actions', 'syslog'), 'ASC'), + 'logtime' => array(__('Date', 'syslog'), 'ASC'), + 'host_id' => array(__('Device', 'syslog'), 'ASC'), + 'program' => array(__('Program', 'syslog'), 'ASC'), + 'message' => array(__('Message', 'syslog'), 'ASC'), 'facility_id' => array(__('Facility', 'syslog'), 'ASC'), 'priority_id' => array(__('Priority', 'syslog'), 'ASC')); - + // Add count column if grouping is enabled if ($grouping_enabled) { $display_text['occurrence_count'] = array(__('Count', 'syslog'), 'DESC'); } } else { $display_text = array( - 'logtime' => array(__('Date', 'syslog'), 'ASC'), - 'host_id' => array(__('Device', 'syslog'), 'ASC'), - 'program' => array(__('Program', 'syslog'), 'ASC'), - 'message' => array(__('Message', 'syslog'), 'ASC'), + 'logtime' => array(__('Date', 'syslog'), 'ASC'), + 'host_id' => array(__('Device', 'syslog'), 'ASC'), + 'program' => array(__('Program', 'syslog'), 'ASC'), + 'message' => array(__('Message', 'syslog'), 'ASC'), 'facility_id' => array(__('Facility', 'syslog'), 'ASC'), 'priority_id' => array(__('Priority', 'syslog'), 'ASC')); - + // Add count column if grouping is enabled if ($grouping_enabled) { $display_text['occurrence_count'] = array(__('Count', 'syslog'), 'DESC'); @@ -1745,7 +1742,7 @@ function syslog_messages($tab = 'syslog') { } else { form_selectable_cell($sm['logtime'], $sm['seq'], '', 'left'); } - + form_selectable_cell(isset($hosts[$sm['host_id']]) ? $hosts[$sm['host_id']]:__('Unknown', 'syslog'), $sm['seq'], '', 'left'); form_selectable_cell($sm['program'], $sm['seq'], '', 'left'); form_selectable_cell(filter_value(title_trim($sm[$syslog_incoming_config['textField']], get_request_var_request('trimval')), get_request_var('rfilter')), $sm['seq'], '', 'left syslogMessage'); @@ -1758,11 +1755,11 @@ function syslog_messages($tab = 'syslog') { } form_end_row(); - + // If grouping is enabled and there are multiple occurrences, add hidden detail rows if ($grouping_enabled && isset($sm['occurrence_count']) && $sm['occurrence_count'] > 1 && isset($sm['seq_list'])) { $seq_array = explode(',', $sm['seq_list']); - + // Get individual messages for this group $detail_messages = syslog_db_fetch_assoc("SELECT syslog.*, syslog_programs.program FROM `" . $syslogdb_default . "`.`" . (($sm['mtype'] == 'main') ? 'syslog' : 'syslog_removed') . "` AS syslog @@ -1770,10 +1767,10 @@ function syslog_messages($tab = 'syslog') { ON syslog.program_id=syslog_programs.program_id WHERE syslog.seq IN (" . implode(',', array_map('intval', $seq_array)) . ") ORDER BY syslog.logtime DESC"); - + if (cacti_sizeof($detail_messages)) { foreach ($detail_messages as $dm) { - $severity_class = syslog_row_color($dm['priority_id'], $dm['message']); + $severity_class = syslog_row_color($dm['priority_id'], $dm['message']); print ""; if (api_plugin_user_realm_auth('syslog_alerts.php')) { $url = ''; @@ -1783,18 +1780,18 @@ function syslog_messages($tab = 'syslog') { } print ""; } - + print ""; print ""; print ""; print ""; print ""; print ""; - + if ($grouping_enabled) { print ""; } - + print ""; } } @@ -1819,12 +1816,12 @@ function syslog_messages($tab = 'syslog') { array('display' => __('Alert Name', 'syslog'), 'sort' => 'ASC', 'align' => 'left'), - 'severity' => array('display' => __('Severity', 'syslog'), 'sort' => 'ASC', 'align' => 'left'), - 'logtime' => array('display' => __('Date', 'syslog'), 'sort' => 'ASC', 'align' => 'left'), - 'logmsg' => array('display' => __('Message', 'syslog'), 'sort' => 'ASC', 'align' => 'left'), - 'count' => array('display' => __('Count', 'syslog'), 'sort' => 'ASC', 'align' => 'right'), - 'host' => array('display' => __('Device', 'syslog'), 'sort' => 'ASC', 'align' => 'right'), + 'name' => array('display' => __('Alert Name', 'syslog'), 'sort' => 'ASC', 'align' => 'left'), + 'severity' => array('display' => __('Severity', 'syslog'), 'sort' => 'ASC', 'align' => 'left'), + 'logtime' => array('display' => __('Date', 'syslog'), 'sort' => 'ASC', 'align' => 'left'), + 'logmsg' => array('display' => __('Message', 'syslog'), 'sort' => 'ASC', 'align' => 'left'), + 'count' => array('display' => __('Count', 'syslog'), 'sort' => 'ASC', 'align' => 'right'), + 'host' => array('display' => __('Device', 'syslog'), 'sort' => 'ASC', 'align' => 'right'), 'facility_id' => array('display' => __('Facility', 'syslog'), 'sort' => 'ASC', 'align' => 'right'), 'priority_id' => array('display' => __('Priority', 'syslog'), 'sort' => 'ASC', 'align' => 'right') ); @@ -1947,7 +1944,7 @@ function html_program_filter($program_id = '-1', $none_entry = '', $action = 'aj } function get_ajax_programs($include_any = true, $include_none = false, $sql_where = '') { - $return = array(); + $return = array(); $term = get_filter_request_var('term', FILTER_CALLBACK, array('options' => 'sanitize_search_string')); if ($term != '') {
" . __('Syslog Alert View', 'syslog') . "
\n"; + print "
"; $html = syslog_db_fetch_cell('SELECT html FROM `' . $syslogdb_default . '`.`syslog_logs` WHERE seq=' . get_request_var('id')); print trim($html, "' "); @@ -220,66 +220,66 @@ function syslog_statistics() { global $title, $rows, $config; global $syslogdb_default; - /* ================= input validation and session storage ================= */ - $filters = array( - 'rows' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1', - ), - 'refresh' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => read_config_option('syslog_refresh'), - ), - 'timespan' => array( - 'filter' => FILTER_VALIDATE_INT, + /* ================= input validation and session storage ================= */ + $filters = array( + 'rows' => array( + 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, - 'default' => '300', - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'rfilter' => array( - 'filter' => FILTER_VALIDATE_IS_REGEX, - 'pageset' => true, - 'default' => '' - ), - 'host' => array( - 'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST, - 'pageset' => true, - 'default' => '', - ), - 'facility' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '', - ), - 'priority' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '', - ), - 'program' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'host', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ) - ); - - validate_store_request_vars($filters, 'sess_syslogs'); - /* ================= input validation ================= */ + 'default' => '-1', + ), + 'refresh' => array( + 'filter' => FILTER_VALIDATE_INT, + 'default' => read_config_option('syslog_refresh'), + ), + 'timespan' => array( + 'filter' => FILTER_VALIDATE_INT, + 'pageset' => true, + 'default' => '300', + ), + 'page' => array( + 'filter' => FILTER_VALIDATE_INT, + 'default' => '1' + ), + 'rfilter' => array( + 'filter' => FILTER_VALIDATE_IS_REGEX, + 'pageset' => true, + 'default' => '' + ), + 'host' => array( + 'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST, + 'pageset' => true, + 'default' => '', + ), + 'facility' => array( + 'filter' => FILTER_VALIDATE_INT, + 'pageset' => true, + 'default' => '', + ), + 'priority' => array( + 'filter' => FILTER_VALIDATE_INT, + 'pageset' => true, + 'default' => '', + ), + 'program' => array( + 'filter' => FILTER_VALIDATE_INT, + 'pageset' => true, + 'default' => '', + 'options' => array('options' => 'sanitize_search_string') + ), + 'sort_column' => array( + 'filter' => FILTER_CALLBACK, + 'default' => 'host', + 'options' => array('options' => 'sanitize_search_string') + ), + 'sort_direction' => array( + 'filter' => FILTER_CALLBACK, + 'default' => 'ASC', + 'options' => array('options' => 'sanitize_search_string') + ) + ); + + validate_store_request_vars($filters, 'sess_syslogs'); + /* ================= input validation ================= */ html_start_box(__('Syslog Statistics Filter', 'syslog'), '100%', '', '3', 'center', ''); @@ -370,7 +370,7 @@ function syslog_statistics() { print '' . (get_request_var('program') != '-2' ? ucfirst($r['program']):'-') . '' . $r['insert_time'] . '' . $time . '' . number_format_i18n($r['records'], -1) . '' . number_format_i18n($r['records'], -1) . '
@@ -1166,22 +1168,17 @@ function syslog_filter($sql_where, $tab) { '> $display_text) { - print "\n"; + print ""; } ?> @@ -1531,12 +1528,12 @@ function syslog_syslog_legend() { print '
" . __('Emergency', 'syslog') . '" . __('Critical', 'syslog') . '" . __('Alert', 'syslog') . '" . __('Error', 'syslog') . '" . __('Alert', 'syslog') . '" . __('Error', 'syslog') . '" . __('Warning', 'syslog') . '" . __('Notice', 'syslog') . '" . __('Info', 'syslog') . '" . __('Debug', 'syslog') . '" . __('Notice', 'syslog') . '" . __('Info', 'syslog') . '" . __('Debug', 'syslog') . '
" . __('Critical', 'syslog') . '" . __('Warning', 'syslog') . '" . __('Notice', 'syslog') . '" . __('Informational', 'syslog') . '" . __('Critical', 'syslog') . '" . __('Warning', 'syslog') . '" . __('Notice', 'syslog') . '" . __('Informational', 'syslog') . '