0
AND dtr.local_data_id = ?',
array($local_data_id)), 'id', 'name');
}
function clog_validate_filename(&$file, &$filepath, &$filename, $filecheck = false) {
global $config;
$logfile = read_config_option('path_cactilog');
if ($logfile == '') {
$logfile = CACTI_PATH_LOG . '/cacti.log';
}
$errfile = read_config_option('path_stderrlog');
$errbase = basename($errfile);
$file = basename($file);
$logbase = basename($logfile);
$filepath = '';
$filename = '';
$filefull = '';
if (!empty($errfile) && strpos($file, $errbase) === 0) {
$filepath = dirname($errfile);
$filename = $errbase;
$filefull = $filepath . '/' . $file;
} elseif (!empty($logfile) && strpos($file, $logbase) === 0) {
$filepath = dirname($logfile);
$filename = $logbase;
$filefull = $filepath . '/' . $file;
}
return ($filecheck ? file_exists($filefull) : !empty($filefull));
}
function clog_purge_logfile() {
global $config;
$filename = get_nfilter_request_var('filename');
if (!clog_validate_filename($filename, $logpath, $logname)) {
raise_message('clog_invalid');
header('Location: ' . get_current_page());
exit(0);
}
$purgefile = $logpath . '/' . $filename;
$logfile = $logpath . '/'. $logname;
if (file_exists($purgefile)) {
if (is_writable($purgefile)) {
if ($logfile != $purgefile) {
unlink($purgefile);
raise_message('clog_remove');
} else {
/* fill in the current date for printing in the log */
if (defined('CACTI_DATE_TIME_FORMAT')) {
$date = date(CACTI_DATE_TIME_FORMAT);
} else {
$date = date('Y-m-d H:i:s');
}
$log_fh = fopen($logfile, 'w');
fwrite($log_fh, __('%s - WEBUI NOTE: Cacti Log Cleared from Web Management Interface.', $date) . PHP_EOL);
fclose($log_fh);
raise_message('clog_purged');
}
cacti_log('NOTE: Cacti Log file ' . $purgefile . ', Removed by user ' . get_username($_SESSION[SESS_USER_ID]), false, 'WEBUI');
} else {
raise_message('clog_permissions');
}
} else {
raise_message('clog_missing');
}
}
function clog_view_logfile() {
global $config;
$exclude_reported = false;
$clogAdmin = clog_admin();
/* ================= input validation and session storage ================= */
$filters = array(
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'tail_lines' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => read_config_option('num_rows_log'),
'pageset' => true
),
'message_type' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '-1',
'pageset' => true
),
'filename' => array(
'filter' => FILTER_CALLBACK,
'default' => read_config_option('path_cactilog'),
'pageset' => true,
'options' => array('options' => 'sanitize_search_string')
),
'refresh' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => read_config_option('log_refresh_interval')
),
'reverse' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'matches' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'rfilter' => array(
'filter' => FILTER_VALIDATE_IS_REGEX,
'default' => '',
'pageset' => true
)
);
validate_store_request_vars($filters, 'sess_clog');
/* ================= input validation ================= */
/* enable page refreshes */
kill_session_var('custom');
set_request_var('page_referrer', 'view_logfile');
load_current_session_value('page_referrer', 'page_referrer', 'view_logfile');
$logfile = basename(get_nfilter_request_var('filename'));
$logname = '';
if (!clog_validate_filename($logfile, $logpath, $logname, true)) {
$logfile = read_config_option('path_cactilog');
} else {
$logfile = $logpath . '/' . $logfile;
}
if ($clogAdmin && isset_request_var('purge_continue')) {
clog_purge_logfile();
$logfile = read_config_option('path_cactilog');
}
$page_nr = get_request_var('page');
$page = CACTI_PATH_URL . 'clog' . (!$clogAdmin ? '_user' : '') . '.php';
$page .= '?filename=' . basename($logfile) . '&page=' . $page_nr;
$refresh = array(
'seconds' => get_request_var('refresh'),
'page' => $page,
'logout' => 'false'
);
set_page_refresh($refresh);
top_header(true);
if ($clogAdmin && isset_request_var('purge')) {
form_start('clog.php');
html_start_box(__('Purge'), '50%', '', '3', 'center', '');
print "
|
" . __('Click \'Continue\' to purge the Log File.
Note: If logging is set to both Cacti and Syslog, the log information will remain in Syslog.') . "
|
|
 
|
\n";
html_end_box();
return;
}
html_start_box(__('Log Filters'), '100%', '', '3', 'center', '');
filter($clogAdmin, basename($logfile));
html_end_box();
/* read logfile into an array and display */
$total_rows = 0;
$number_of_lines = get_request_var('tail_lines') < 0 ? read_config_option('max_display_rows') : get_request_var('tail_lines');
$should_expand = read_config_option('log_expand') != LOG_EXPAND_NONE;
$logcontents = tail_file($logfile, $number_of_lines, get_request_var('message_type'), get_request_var('rfilter'), $page_nr, $total_rows, get_request_var('matches'), $should_expand);
if (get_request_var('reverse') == 1) {
$logcontents = array_reverse($logcontents);
}
if (!$clogAdmin) {
$exclude_regex = read_config_option('clog_exclude', true);
if ($exclude_regex != '') {
$ad_filter = __(' - Admin Filter active');
} else {
$ad_filter = __(' - Admin Unfiltered');
}
} else {
$ad_filter = __(' - Admin view');
$exclude_regex = '';
}
if (get_request_var('message_type') > 0 || get_request_var('rfilter') != '') {
$start_string = __('Log [Total Lines: %d %s - Filter active]', $total_rows, $ad_filter);
} else {
$start_string = __('Log [Total Lines: %d %s - Unfiltered]', $total_rows, $ad_filter);
}
$base_url = CACTI_PATH_URL . 'clog.php';
$nav = html_nav_bar($base_url, MAX_DISPLAY_PAGES, $page_nr, $number_of_lines, $total_rows, 1, __('Entries'), 'page', 'main');
print $nav;
html_start_box($start_string, '100%', '', '3', 'center', '');
$linecolor = false;
if (db_column_exists('sites', 'disabled')) {
$sql_where = 'AND IFNULL(s.disabled,"") != "on"';
} else {
$sql_where = '';
}
$hosts = db_fetch_assoc("SELECT h.id, h.description
FROM host h
LEFT JOIN sites s
ON s.id = h.site_id
WHERE IFNULL(TRIM(h.disabled), '') != 'on'
$sql_where
AND deleted = ''");
$hostDescriptions = array();
foreach ($hosts as $host) {
$hostDescriptions[$host['id']] = html_escape($host['description']);
}
foreach ($logcontents as $item) {
$new_item = html_escape($item);
if ($should_expand) {
$new_item = text_substitute($new_item, isHtml: true);
}
/* respect the exclusion filter */
if ($exclude_regex != '' && !$clogAdmin) {
if (validate_is_regex($exclude_regex)) {
if (preg_match($exclude_regex, $new_item)) {
continue;
}
} elseif (!$exclude_reported) {
cacti_log('Cacti Log Exclude Regex "' . $exclude_regex . '" is Invalid. Update your Exclude Regex to be valid!');
$exclude_reported = true;
}
}
/* get the background color */
if (strpos($new_item, 'ERROR') !== false || strpos($new_item, 'FATAL') !== false) {
$class = 'clogError';
} elseif (strpos($new_item, 'WARN') !== false) {
$class = 'clogWarning';
} elseif (strpos($new_item, ' SQL ') !== false) {
$class = 'clogSQL';
} elseif (strpos($new_item, 'DEBUG') !== false) {
$class = 'clogDebug';
} elseif (strpos($new_item, 'STATS') !== false) {
$class = 'clogStats';
} else {
if ($linecolor) {
$class = 'odd';
} else {
$class = 'even';
}
$linecolor = !$linecolor;
}
?>
|
|
1) {
$a_date = $a_parts[1];
}
$b_date = '99999999';
if (cacti_count($b_parts) > 1) {
$b_date = $b_parts[1];
}
// Invert the order, replace _'s with +'s to make them sort after .'s, prefix the date
// This makes cacti_stderr.log appear after cacti.log in date descending order with
// no date files first
return strcmp($b_date . '-' . str_replace('_','+',$b_parts[0]), $a_date . '-' . str_replace('_','+',$a_parts[0]));
}
function clog_get_logfiles() {
global $config;
$stdFileArray = $stdLogFileArray = $stdErrFileArray = array();
$configLogPath = read_config_option('path_cactilog');
$configLogBase = basename($configLogPath);
$stderrLogPath = read_config_option('path_stderrlog');
$stderrLogBase = basename($stderrLogPath);
if ($configLogPath == '') {
$logPath = CACTI_PATH_LOG . '/';
} else {
$logPath = dirname($configLogPath);
}
if (is_readable($logPath)) {
$files = @scandir($logPath);
} else {
$files = array('cacti.log');
}
// Defaults go first and second
$stdFileArray[] = basename($configLogPath);
// After Defaults, do Cacti log first (of archived)
if (cacti_sizeof($files)) {
$stdLogFileArray = array();
foreach ($files as $logFile) {
if (in_array($logFile, array('.', '..', '.htaccess', $configLogBase, $stderrLogBase), true)) {
continue;
}
$explode = explode('.', $logFile);
if (substr($explode[max(array_keys($explode))], 0, 3) != 'log') {
continue;
}
if (!clog_validate_filename($logFile, $logPath, $logName)) {
continue;
}
if (!empty($stderrlogbase) && strpos($logFile, $stderrLogBase) === 0) {
$stdErrFileArray[] = $logFile;
} else {
$stdLogFileArray[] = $logFile;
}
}
$stdErrFileArray = array_unique($stdErrFileArray);
$stdLogFileArray = array_unique($stdLogFileArray);
}
// Defaults go first and second
if (!empty($stderrLogPath)) {
$stdFileArray[] = basename($stderrLogPath);
// After Defaults, do Cacti StdErr log second (of archived)
if (dirname($stderrLogPath) != $logPath) {
$errFiles = @scandir(dirname($stderrLogPath));
$files = $errFiles;
if (cacti_sizeof($files)) {
$stdErrFileArray = array();
foreach ($files as $logFile) {
if (in_array($logFile, array('.', '..', '.htaccess', $configLogBase, $stderrLogBase), true)) {
continue;
}
$explode = explode('.', $logFile);
if (substr($explode[max(array_keys($explode))], 0, 3) != 'log') {
continue;
}
if (!clog_validate_filename($logFile, $logPath, $logName)) {
continue;
}
$stdErrFileArray[] = $logFile;
}
$stdErrFileArray = array_unique($stdErrFileArray);
}
}
}
arsort($stdLogFileArray, SORT_NATURAL);
arsort($stdErrFileArray, SORT_NATURAL);
return array_unique(array_merge($stdFileArray, $stdLogFileArray, $stdErrFileArray));
}
function filter($clogAdmin, $selectedFile) {
global $page_refresh_interval, $log_tail_lines, $config;
?>
|
|