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

crash reporter: improve the output and behaviour

* Refactor crash report link into a function so it could be called
  from any page if desired.

* Do not show a crash report when there is none.
parent 023fa9c1
...@@ -126,6 +126,8 @@ $php_errors = @file_get_contents('/tmp/PHP_errors.log'); ...@@ -126,6 +126,8 @@ $php_errors = @file_get_contents('/tmp/PHP_errors.log');
fclose(fopen("/tmp/PHP_errors.log", 'w')); fclose(fopen("/tmp/PHP_errors.log", 'w'));
header("Location: /"); header("Location: /");
exit; 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;
......
...@@ -1102,3 +1102,33 @@ if (!$timezone) { ...@@ -1102,3 +1102,33 @@ if (!$timezone) {
} }
date_default_timezone_set($timezone); date_default_timezone_set($timezone);
function get_crash_report($pedantic = false)
{
global $g;
$savemsg = "{$g['product_name']} has detected a crash report or programming bug. Click <a href='crash_reporter.php'>here</a> for more information.";
$skip_files = array('.', '..', 'minfree', '');
$count = 0;
if (file_exists('/tmp/PHP_errors.log')) {
/* only notify about crash report when there's an error */
$total = `/usr/bin/grep -v 'PHP Warning:' /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
if ($total > 0 || $pedantic) {
$count++;
}
}
$crashes = glob('/var/crash/*');
foreach ($crashes as $crash) {
if (!in_array(basename($crash), $skip_files)) {
$count++;
}
}
if (!$count) {
$savemsg = '';
}
return $savemsg;
}
...@@ -50,34 +50,6 @@ if ($_REQUEST['act'] == 'alias_info_popup' && !preg_match("/\D/",$_REQUEST['alia ...@@ -50,34 +50,6 @@ if ($_REQUEST['act'] == 'alias_info_popup' && !preg_match("/\D/",$_REQUEST['alia
exit; exit;
} }
/* CRASH REPORT BEGIN */
$x = 0;
if (file_exists('/tmp/PHP_errors.log')) {
/* don't notify about crash report when there's only errors */
$total = `/usr/bin/grep -v 'PHP Warning:' /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
if($total > 0) {
$x++;
}
}
$crash = glob('/var/crash/*');
if (is_array($crash)) {
$skip_files = array('.', '..', 'minfree', '');
foreach($crash as $c) {
if (!in_array(basename($c), $skip_files)) {
$x++;
}
}
}
if($x > 0) {
$savemsg = "{$g['product_name']} has detected a crash report or programming bug. Click <a href='crash_reporter.php'>here</a> for more information.";
}
/* CRASH REPORT END */
##build list of widgets ##build list of widgets
$directory = "/usr/local/www/widgets/widgets/"; $directory = "/usr/local/www/widgets/widgets/";
$dirhandle = opendir($directory); $dirhandle = opendir($directory);
...@@ -443,15 +415,11 @@ echo $jscriptstr; ...@@ -443,15 +415,11 @@ echo $jscriptstr;
<div class="row"> <div class="row">
<?php <?php
if ($savemsg) $crash_report = get_crash_report();
print_info_box($savemsg); if ($crash_report != '') {
print_info_box($crash_report);
}
?>
<?php
$totalwidgets = count($widgetfiles); $totalwidgets = count($widgetfiles);
$halftotal = $totalwidgets / 2 - 2; $halftotal = $totalwidgets / 2 - 2;
$widgetcounter = 0; $widgetcounter = 0;
......
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