function cw_log_count_messages($labels = false, $start = false, $end = false) { global $var_dirs; static $regexp = '!^\\[\\d{2}-.{3}-\\d{4} \\d{2}:\\d{2}:\\d{2}\\] !S'; $logs = cw_log_list_files($labels, $start, $end); if (!is_array($logs) || empty($logs)) { return false; } $return = array(); foreach ($logs as $label => $list) { if (!is_array($list) || empty($list)) { continue; } foreach ($list as $timestamp => $file) { # count records in single log file $fp = @fopen($var_dirs['log'] . '/' . $file, 'r'); if ($fp === false) { continue; } $count = 0; while (($line = fgets($fp, 8192)) !== false) { if (preg_match($regexp, $line)) { $count++; } } fclose($fp); $return[$label][$timestamp] = $count; } } return $return; }
if (empty($posted_data['logs'])) { $posted_data['logs'] = false; } if ($StartMonth) { $posted_data['start_date'] = mktime(0, 0, 0, $StartMonth, $StartDay, $StartYear); $posted_data['end_date'] = mktime(23, 59, 59, $EndMonth, $EndDay, $EndYear); } $logs_search_data = $posted_data; if ($action == "clean") { list($start_date, $end_date) = logs_convert_date($posted_data); $labels = array(); if (!empty($posted_data['logs']) && is_array($posted_data['logs'])) { $labels = array_keys($posted_data['logs']); } $error_files = array(); $_tmp = cw_log_list_files($labels, $start_date, $end_date); if (is_array($_tmp)) { foreach ($_tmp as $l => $d) { foreach ($d as $ts => $file) { $file = $var_dirs['log'] . '/' . $file; if (ini_get('error_log') !== $file && @unlink($file) === false) { $error_files[] = $file; } } } } if (!empty($error_files)) { $top_message['type'] = 'E'; $top_message['content'] = cw_get_langvar_by_name('err_files_delete_perms', array('files' => implode("\n", $error_files)), $current_language, true); } else { $top_message['type'] = 'I';
<?php $logs = cw_log_list_files(); $is_found = false; if (!empty($logs)) { foreach ($logs as $arr) { if (in_array($file, $arr)) { $is_found = true; break; } } } $filename = $var_dirs['log'] . DIRECTORY_SEPARATOR . $file; $fp = fopen($filename, "rb"); if (!$is_found || empty($file) || !$fp) { cw_header_location("index.php?target=error_message&error=access_denied&id=62"); } header('Content-Type: text/plain; name="' . preg_replace("/\\.php\$/", ".txt", $file) . '"'); header('Content-Length: ' . (filesize($filename) - strlen(LOG_PHP_SIGNATURE))); fseek($fp, strlen(LOG_PHP_SIGNATURE), SEEK_SET); fpassthru($fp); fclose($fp);