From 9aadffbca86356b334bf9d418278cf209a016b85 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Sun, 5 Apr 2015 09:35:09 +0000 Subject: [PATCH] crash reporter: moar tweaking #80 * Update the crash report version information. * Tweak the form layout and remove HTML errors. * Show appropriate message instead instead of redirect. * Rework POST actions for style and sanity. --- src/www/crash_reporter.php | 105 +++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 56 deletions(-) diff --git a/src/www/crash_reporter.php b/src/www/crash_reporter.php index f23ecc3ee..a5b90bb91 100644 --- a/src/www/crash_reporter.php +++ b/src/www/crash_reporter.php @@ -1,6 +1,7 @@ Copyright (C) 2014 Deciso B.V. Copyright (C) 2011 Scott Ullrich All rights reserved. @@ -58,27 +59,17 @@ function upload_crash_report($files) return $response; } -function output_crash_reporter_html($crash_reports) { - echo "

" . gettext("Unfortunately we have detected a programming bug.") . "

"; - echo "

" . gettext("Would you like to submit the programming debug logs to the OPNsense developers for inspection?") . "

"; - echo "

" . gettext("Please double check the contents to ensure you are comfortable sending this information before clicking Yes.") . "

"; - echo "

" . gettext("Contents of crash reports") . ":
"; - echo "

"; - echo "

" . gettext(" - Submit this to the developers for inspection") . "

"; - echo "

" . gettext(" - Just delete the crash report and take me back to the Dashboard") . "

"; - echo ""; -} - $pgtitle = array(gettext("Diagnostics"),gettext("Crash Reporter")); include('head.inc'); -$crash_report_header = "Crash report begins. Anonymous machine information:\n\n"; -$crash_report_header .= php_uname("m") . "\n"; -$crash_report_header .= php_uname("r") . "\n"; -$crash_report_header .= php_uname("v") . "\n"; -$crash_report_header .= "\nCrash report details:\n"; - -$php_errors = @file_get_contents('/tmp/PHP_errors.log'); +$crash_report_header = sprintf( + "System Information:\n%s\n%s %s (%s)\n%s\n", + php_uname('v'), + $g['product_name'], + trim(file_get_contents('/usr/local/opnsense/version/opnsense')), + php_uname('m'), + exec('/usr/local/bin/openssl version') +); ?> @@ -96,56 +87,58 @@ $php_errors = @file_get_contents('/tmp/PHP_errors.log'); "; - echo gettext("Uploading..."); + if ($_POST['Submit'] == 'yes') { + echo '

' . gettext('Processing...'); ob_flush(); flush(); - if(is_array($files_to_upload)) { - $resp = upload_crash_report($files_to_upload); - array_map('unlink', glob("/var/crash/*")); - // Erase the contents of the PHP error log - fclose(fopen("/tmp/PHP_errors.log", 'w')); - echo "
"; - print_r($resp); - echo "

" . gettext("Continue") . "" . gettext(" and delete crash report files from local disk.") . "

"; - } else { - echo "Could not find any crash files."; + if (!is_dir('/var/crash')) { + mkdir('/var/crash', 0750, true); } - } else if(gettext($_POST['Submit']) == "No") { - array_map('unlink', glob("/var/crash/*")); - // Erase the contents of the PHP error log - fclose(fopen("/tmp/PHP_errors.log", 'w')); - header("Location: /"); - exit; - } elseif (get_crash_report(true) == '') { - echo '

' . gettext('Luckily we have not detected a programming bug.') . '

'; + file_put_contents('/var/crash/crashreport_header.txt', $crash_report_header); + @rename('/tmp/PHP_errors.log', '/var/crash/PHP_errors.log'); + exec('/usr/bin/gzip /var/crash/*'); + $files_to_upload = glob('/var/crash/*'); + echo '
' . gettext('Uploading...'); + ob_flush(); + flush(); + $resp = upload_crash_report($files_to_upload); + echo '
' . print_r($resp) . '

'; + array_map('unlink', $files_to_upload); + } elseif ($_POST['Submit'] == 'no') { + array_map('unlink', glob('/var/crash/*')); + @unlink('/tmp/PHP_errors.log'); + } + + if (get_crash_report(true) == '') { + echo '

'; + if ($_POST['Submit'] == 'yes') { + echo gettext('Thank you for submitting this crash report.'); + } elseif ($_POST['Submit'] == 'no') { + echo gettext('Please consider submitting a crash report if the error persists.'); + } else { + echo gettext('Luckily we have not detected a programming bug.'); + } + echo '

'; } else { $crash_files = glob("/var/crash/*"); $crash_reports = $crash_report_header; + $php_errors = @file_get_contents('/tmp/PHP_errors.log'); if (!empty($php_errors)) { $crash_reports .= "\nPHP Errors:\n"; $crash_reports .= $php_errors; } - if(is_array($crash_files)) { - foreach($crash_files as $cf) { - if(filesize($cf) < FILE_SIZE) { - $crash_reports .= "\nFilename: {$cf}\n"; - $crash_reports .= file_get_contents($cf); - } + foreach ($crash_files as $cf) { + if (filesize($cf) < FILE_SIZE) { + $crash_reports .= "\nFilename: {$cf}\n"; + $crash_reports .= file_get_contents($cf); } - } else { - echo "Could not locate any crash data."; } - output_crash_reporter_html($crash_reports); + echo "

" . gettext("Unfortunately we have detected at least one programming bug.") . "

"; + echo "


" . sprintf(gettext("Would you like to submit this crash report to the %s developers?"), $g['product_name']) . "

"; + echo "

"; + echo "

"; + echo "


" . gettext("Please-double check the contents to ensure you are comfortable submitting the following information:") . "

"; + echo "

"; } ?>