/** * Locate, parse and display the latest error logged in the main error_log file. * * @return array A list of pseudo-variables and values that will replace them in the HTML template. */ function sucuriscan_infosys_errorlogs() { $template_variables = array('ErrorLog.Path' => '', 'ErrorLog.Exists' => 'No', 'ErrorLog.NoItemsVisibility' => 'hidden', 'ErrorLog.DisabledVisibility' => 'hidden', 'ErrorLog.InvalidFormatVisibility' => 'hidden', 'ErrorLog.LogsLimit' => '0', 'ErrorLog.FileSize' => '0B', 'ErrorLog.List' => ''); $error_log_path = false; $log_filename = SucuriScan::ini_get('error_log'); $errorlogs_limit = SucuriScanOption::get_option(':errorlogs_limit'); $template_variables['ErrorLog.LogsLimit'] = $errorlogs_limit; $errorlogs_counter = 0; if ($log_filename) { $error_log_path = @realpath(ABSPATH . '/' . $log_filename); } if (SucuriScanOption::is_disabled(':parse_errorlogs')) { $template_variables['ErrorLog.DisabledVisibility'] = 'visible'; } if ($error_log_path) { $template_variables['ErrorLog.Path'] = $error_log_path; $template_variables['ErrorLog.Exists'] = 'Yes'; $template_variables['ErrorLog.FileSize'] = SucuriScan::human_filesize(filesize($error_log_path)); $last_lines = SucuriScanFileInfo::tail_file($error_log_path, $errorlogs_limit); $error_logs = SucuriScanFSScanner::parse_error_logs($last_lines); $error_logs = array_reverse($error_logs); $errorlogs_counter = 0; foreach ($error_logs as $error_log) { $css_class = $errorlogs_counter % 2 == 0 ? '' : 'alternate'; $template_variables['ErrorLog.List'] .= SucuriScanTemplate::get_snippet('infosys-errorlogs', array('ErrorLog.CssClass' => $css_class, 'ErrorLog.DateTime' => SucuriScan::datetime($error_log->timestamp), 'ErrorLog.ErrorType' => SucuriScan::escape($error_log->error_type), 'ErrorLog.ErrorCode' => SucuriScan::escape($error_log->error_code), 'ErrorLog.ErrorAbbr' => strtoupper(substr($error_log->error_code, 0, 1)), 'ErrorLog.ErrorMessage' => SucuriScan::escape($error_log->error_message), 'ErrorLog.FilePath' => SucuriScan::escape($error_log->file_path), 'ErrorLog.LineNumber' => SucuriScan::escape($error_log->line_number))); $errorlogs_counter += 1; } if ($errorlogs_counter <= 0) { $template_variables['ErrorLog.InvalidFormatVisibility'] = 'visible'; } } else { $template_variables['ErrorLog.NoItemsVisibility'] = 'visible'; } return SucuriScanTemplate::get_section('infosys-errorlogs', $template_variables); }
function sucuriscan_infosys_errorlogs_ajax() { if (SucuriScanRequest::post('form_action') == 'get_error_logs') { $response = ''; // Scan the project and get the ignored paths. if (SucuriScanOption::is_enabled(':parse_errorlogs')) { $fname = SucuriScan::ini_get('error_log'); $fpath = $fname ? @realpath(ABSPATH . '/' . $fname) : false; if ($fpath !== false && is_file($fpath) && file_exists($fpath) && is_readable($fpath)) { $limit = SucuriScanOption::get_option(':errorlogs_limit'); $flines = SucuriScanFileInfo::tail_file($fpath, $limit); $error_logs = SucuriScanFSScanner::parse_error_logs($flines); $error_logs = array_reverse($error_logs); $counter = 0; foreach ($error_logs as $log) { $css_class = $counter % 2 === 0 ? '' : 'alternate'; $response .= SucuriScanTemplate::getSnippet('infosys-errorlogs', array('ErrorLog.CssClass' => $css_class, 'ErrorLog.DateTime' => SucuriScan::datetime($log->timestamp), 'ErrorLog.ErrorType' => $log->error_type, 'ErrorLog.ErrorCode' => $log->error_code, 'ErrorLog.ErrorAbbr' => strtoupper(substr($log->error_code, 0, 1)), 'ErrorLog.ErrorMessage' => $log->error_message, 'ErrorLog.FilePath' => $log->file_path, 'ErrorLog.LineNumber' => $log->line_number)); $counter++; } } } if (empty($response)) { $response = '<tr><td colspan="5">List is empty.</td></tr>'; } print $response; exit(0); } }