Commit 9aadffbc authored by Franco Fichtner's avatar Franco Fichtner

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.
parent d84c544d
<?php <?php
/* /*
Copyright (C) 2015 Franco Fichtner <franco@opnsense.org>
Copyright (C) 2014 Deciso B.V. Copyright (C) 2014 Deciso B.V.
Copyright (C) 2011 Scott Ullrich Copyright (C) 2011 Scott Ullrich
All rights reserved. All rights reserved.
...@@ -58,27 +59,17 @@ function upload_crash_report($files) ...@@ -58,27 +59,17 @@ function upload_crash_report($files)
return $response; return $response;
} }
function output_crash_reporter_html($crash_reports) {
echo "<p><strong>" . gettext("Unfortunately we have detected a programming bug.") . "</strong></p>";
echo "<p>" . gettext("Would you like to submit the programming debug logs to the OPNsense developers for inspection?") . "</p>";
echo "<p><i>" . gettext("Please double check the contents to ensure you are comfortable sending this information before clicking Yes.") . "</i></p>";
echo "<p>" . gettext("Contents of crash reports") . ":<br />";
echo "<textarea readonly=\"readonly\" style=\"max-width: none;\" rows=\"24\" cols=\"80\" name=\"crashreports\">{$crash_reports}</textarea></p>";
echo "<p><input disabled=\"disabled\" name=\"Submit\" type=\"submit\" class=\"btn btn-primary\" value=\"" . gettext("Yes") . "\" />" . gettext(" - Submit this to the developers for inspection") . "</p>";
echo "<p><input name=\"Submit\" type=\"submit\" class=\"btn btn-primary\" value=\"" . gettext("No") . "\" />" . gettext(" - Just delete the crash report and take me back to the Dashboard") . "</p>";
echo "</form>";
}
$pgtitle = array(gettext("Diagnostics"),gettext("Crash Reporter")); $pgtitle = array(gettext("Diagnostics"),gettext("Crash Reporter"));
include('head.inc'); include('head.inc');
$crash_report_header = "Crash report begins. Anonymous machine information:\n\n"; $crash_report_header = sprintf(
$crash_report_header .= php_uname("m") . "\n"; "System Information:\n%s\n%s %s (%s)\n%s\n",
$crash_report_header .= php_uname("r") . "\n"; php_uname('v'),
$crash_report_header .= php_uname("v") . "\n"; $g['product_name'],
$crash_report_header .= "\nCrash report details:\n"; trim(file_get_contents('/usr/local/opnsense/version/opnsense')),
php_uname('m'),
$php_errors = @file_get_contents('/tmp/PHP_errors.log'); exec('/usr/local/bin/openssl version')
);
?> ?>
...@@ -96,56 +87,58 @@ $php_errors = @file_get_contents('/tmp/PHP_errors.log'); ...@@ -96,56 +87,58 @@ $php_errors = @file_get_contents('/tmp/PHP_errors.log');
<?php <?php
if (gettext($_POST['Submit']) == "Yes") { if ($_POST['Submit'] == 'yes') {
echo gettext("Processing..."); echo '<p>' . gettext('Processing...');
if (!is_dir("/var/crash")) ob_flush();
mkdir("/var/crash", 0750, true); flush();
@file_put_contents("/var/crash/crashreport_header.txt", $crash_report_header); if (!is_dir('/var/crash')) {
if(file_exists("/tmp/PHP_errors.log")) mkdir('/var/crash', 0750, true);
copy("/tmp/PHP_errors.log", "/var/crash/PHP_errors.log"); }
exec("/usr/bin/gzip /var/crash/*"); file_put_contents('/var/crash/crashreport_header.txt', $crash_report_header);
$files_to_upload = glob("/var/crash/*"); @rename('/tmp/PHP_errors.log', '/var/crash/PHP_errors.log');
echo "<br/>"; exec('/usr/bin/gzip /var/crash/*');
echo gettext("Uploading..."); $files_to_upload = glob('/var/crash/*');
echo '<br/>' . gettext('Uploading...');
ob_flush(); ob_flush();
flush(); flush();
if(is_array($files_to_upload)) {
$resp = upload_crash_report($files_to_upload); $resp = upload_crash_report($files_to_upload);
array_map('unlink', glob("/var/crash/*")); echo '<br/>' . print_r($resp) . '</p>';
// Erase the contents of the PHP error log array_map('unlink', $files_to_upload);
fclose(fopen("/tmp/PHP_errors.log", 'w')); } elseif ($_POST['Submit'] == 'no') {
echo "<br/>"; array_map('unlink', glob('/var/crash/*'));
print_r($resp); @unlink('/tmp/PHP_errors.log');
echo "<p><a href=\"/\">" . gettext("Continue") . "</a>" . gettext(" and delete crash report files from local disk.") . "</p>"; }
if (get_crash_report(true) == '') {
echo '<p><strong>';
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 { } else {
echo "Could not find any crash files."; echo gettext('Luckily we have not detected a programming bug.');
} }
} else if(gettext($_POST['Submit']) == "No") { echo '</strong></p>';
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 '<p><strong>' . gettext('Luckily we have not detected a programming bug.') . '</strong></p>';
} else { } else {
$crash_files = glob("/var/crash/*"); $crash_files = glob("/var/crash/*");
$crash_reports = $crash_report_header; $crash_reports = $crash_report_header;
$php_errors = @file_get_contents('/tmp/PHP_errors.log');
if (!empty($php_errors)) { if (!empty($php_errors)) {
$crash_reports .= "\nPHP Errors:\n"; $crash_reports .= "\nPHP Errors:\n";
$crash_reports .= $php_errors; $crash_reports .= $php_errors;
} }
if(is_array($crash_files)) { foreach ($crash_files as $cf) {
foreach($crash_files as $cf) { if (filesize($cf) < FILE_SIZE) {
if(filesize($cf) < FILE_SIZE) {
$crash_reports .= "\nFilename: {$cf}\n"; $crash_reports .= "\nFilename: {$cf}\n";
$crash_reports .= file_get_contents($cf); $crash_reports .= file_get_contents($cf);
} }
} }
} else { echo "<p><strong>" . gettext("Unfortunately we have detected at least one programming bug.") . "</strong></p>";
echo "Could not locate any crash data."; echo "<p><br/>" . sprintf(gettext("Would you like to submit this crash report to the %s developers?"), $g['product_name']) . "</p>";
} echo "<p><button disabled=\"disabled\" name=\"Submit\" type=\"submit\" class=\"btn btn-primary\" value=\"yes\">" . gettext('Yes') . "</button> ";
output_crash_reporter_html($crash_reports); echo "<button name=\"Submit\" type=\"submit\" class=\"btn btn-primary\" value=\"no\">" . gettext('No') . "</button></p>";
echo "<p><br/><i>" . gettext("Please-double check the contents to ensure you are comfortable submitting the following information:") . "</i></p>";
echo "<textarea readonly=\"readonly\" style=\"max-width: none;\" rows=\"24\" cols=\"80\" name=\"crashreports\">{$crash_reports}</textarea></p>";
} }
?> ?>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment