diff --git a/src/www/crash_reporter.php b/src/www/crash_reporter.php index 11e503d05..2548fff63 100644 --- a/src/www/crash_reporter.php +++ b/src/www/crash_reporter.php @@ -85,12 +85,16 @@ $user_agent = $g['product_name'] . '/' . $pkgver[0]; $crash_reports = array(); $has_crashed = false; -if (isset($_POST['Submit'])) { - if ($_POST['Submit'] == 'yes') { +$pconfig = array(); +$pconfig['Email'] = isset($config['system']['contact_email']) ? $config['system']['contact_email'] : ''; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $pconfig = $_POST; + if ($pconfig['Submit'] == 'yes') { if (!is_dir('/var/crash')) { mkdir('/var/crash', 0750, true); } - $email = trim($_POST['Email']); + $email = trim($pconfig['Email']); if (!empty($email)) { $crash_report_header .= "Email {$email}\n"; if (!isset($config['system']['contact_email']) || @@ -102,30 +106,42 @@ if (isset($_POST['Submit'])) { unset($config['system']['contact_email']); write_config('Removed crash reporter contact email.'); } - $desc = trim($_POST['Desc']); + $desc = trim($pconfig['Desc']); if (!empty($desc)) { $crash_report_header .= "Description\n\n{$desc}"; } - file_put_contents('/var/crash/crashreport_header.txt', $crash_report_header); - if (file_exists('/tmp/PHP_errors.log')) { - // limit PHP_errors to send to 1MB - exec('/usr/bin/tail -c 1048576 /tmp/PHP_errors.log > /var/crash/PHP_errors.log'); - @unlink('/tmp/PHP_errors.log'); + $skip_files = array('.', '..', 'minfree', 'bounds', ''); + $crashes = glob('/var/crash/*'); + foreach ($crashes as $crash) { + if (!in_array(basename($crash), $skip_files)) { + $count++; + } } - @copy('/var/run/dmesg.boot', '/var/crash/dmesg.boot'); - exec('/usr/bin/gzip /var/crash/*'); - $files_to_upload = glob('/var/crash/*'); - upload_crash_report($files_to_upload, $user_agent); - foreach ($files_to_upload as $file_to_upload) { - @unlink($file_to_upload); + if ($count || (!empty($desc) && !empty($email))) { + file_put_contents('/var/crash/crashreport_header.txt', $crash_report_header); + if (file_exists('/tmp/PHP_errors.log')) { + // limit PHP_errors to send to 1MB + exec('/usr/bin/tail -c 1048576 /tmp/PHP_errors.log > /var/crash/PHP_errors.log'); + @unlink('/tmp/PHP_errors.log'); + } + @copy('/var/run/dmesg.boot', '/var/crash/dmesg.boot'); + exec('/usr/bin/gzip /var/crash/*'); + $files_to_upload = glob('/var/crash/*'); + upload_crash_report($files_to_upload, $user_agent); + foreach ($files_to_upload as $file_to_upload) { + @unlink($file_to_upload); + } + } else { + /* still crashing ;) */ + $has_crashed = true; } - } elseif ($_POST['Submit'] == 'no') { + } elseif ($pconfig['Submit'] == 'no') { $files_to_upload = glob('/var/crash/*'); foreach ($files_to_upload as $file_to_upload) { @unlink($file_to_upload); } @unlink('/tmp/PHP_errors.log'); - } elseif ($_POST['Submit'] == 'new') { + } elseif ($pconfig['Submit'] == 'new') { /* force a crash report generation */ $has_crashed = true; } @@ -134,8 +150,6 @@ if (isset($_POST['Submit'])) { $has_crashed = get_crash_report(true) != ''; } -$email = isset($config['system']['contact_email']) ? $config['system']['contact_email'] : ''; - if ($has_crashed) { $crash_files = glob("/var/crash/*"); $crash_reports['System Information'] = trim($crash_report_header); @@ -171,15 +185,26 @@ if ($has_crashed) { } $message = gettext('Luckily we have not detected a programming bug.'); -if (isset($_POST['Submit'])) { - if ($_POST['Submit'] == 'yes') { - $message = gettext('Thank you for submitting this crash report.'); - } elseif ($_POST['Submit'] == 'no') { +if ($has_crashed) { + $message = gettext('Unfortunately we have detected at least one programming bug.'); +} + +if (isset($pconfig['Submit'])) { + if ($pconfig['Submit'] == 'yes') { + if (!$has_crashed) { + $message = gettext('Thank you for submitting this crash report.'); + } else { + $message = gettext('This crash report has no relevant crash information. If you want to submit a problem please fill out your email and decription below.'); + } + } elseif ($pconfig['Submit'] == 'no') { $message = gettext('Please consider submitting a crash report if the error persists.'); } } -?> +// escape form output before processing +legacy_html_escape_form_data($pconfig); + +?>
@@ -195,12 +220,12 @@ if (isset($_POST['Submit'])) { if ($has_crashed):?>=gettext("Unfortunately we have detected at least one programming bug.");?>
+= $message ?>
=gettext("Would you like to submit this crash report to the developers?");?>
=gettext('You can help us further by adding your contact information and a problem description. ' . 'Please note that providing your contact information greatly improves the chances of bugs being fixed.');?>
- - + +=gettext("Please double-check the following contents to ensure you are comfortable submitting the following information.");?>
$content):?> @@ -212,6 +237,7 @@ if (isset($_POST['Submit'])) { endforeach; else:?> +=$message;?>