Unify and improve crash report checking. Fixes #8915

This commit is contained in:
jim-p 2018-10-04 11:03:02 -04:00
parent 245bfa559b
commit 6e150fc0d0
3 changed files with 47 additions and 57 deletions

View File

@ -55,27 +55,6 @@ function download_crashdata_file($name) {
exit;
}
/* Remove files we do not want to see in the report */
function cleanup_file_list($files) {
if (!is_array($files)) {
return $files;
}
$exclude_patterns = array(
'.*.last',
'bounds',
'minfree'
);
foreach ($files as $idx => $fb) {
if (preg_match('/' . implode('|', $exclude_patterns) . '/', basename($fb)) == 1) {
unset($files[$idx]);
}
}
return $files;
}
if (!empty($_POST['Download'])) {
if ($_POST['Download'] == "PHP") {
/* Send PHP log */
@ -97,8 +76,6 @@ $crash_report_header .= php_uname("r") . "\n";
$crash_report_header .= php_uname("v") . "\n";
$crash_report_header .= "\nCrash report details:\n";
exec("/bin/cat /tmp/PHP_errors.log", $php_errors);
if ($_POST['Submit'] == "No") {
array_map('unlink', glob("/var/crash/*"));
// Erase the contents of the PHP error log
@ -106,14 +83,16 @@ if ($_POST['Submit'] == "No") {
header("Location: /");
exit;
} else {
$crash_files = cleanup_file_list(glob("/var/crash/*"));
$crash_reports = $crash_report_header;
if (count($php_errors) > 0) {
if (system_has_php_errors()) {
$php_errors = file_get_contents("/tmp/PHP_errors.log");
$crash_reports .= "\nPHP Errors:\n";
$crash_reports .= implode("\n", $php_errors) . "\n\n";
$crash_reports .= $php_errors . "\n\n";
} else {
$crash_reports .= "\nNo PHP errors found.\n";
}
$crash_files = cleanup_crash_file_list(glob("/var/crash/*"));
if (count($crash_files) > 0) {
foreach ($crash_files as $cf) {
if (filesize($cf) < FILE_SIZE) {
@ -145,10 +124,10 @@ if ($_POST['Submit'] == "No") {
</button>
<br/><br/>
<?php if ((count($crash_files) > 0) || (count($php_errors) > 0)): ?>
<?php if ((count($crash_files) > 0) || system_has_php_errors()): ?>
Click a button below to download an individual debugging data file:
<br/><br/>
<?php if (count($php_errors) > 0): ?>
<?php if (system_has_php_errors()): ?>
<button class="btn btn-info" name="Download" type="submit" value="PHP">
<i class="fa fa-download"></i>
<?=gettext("Download PHP Error Log")?>

View File

@ -1298,6 +1298,39 @@ if (isset($config['system']['timezone']) &&
$timezone = "Etc/UTC";
}
/* Remove files we do not want to see in a crash report */
function cleanup_crash_file_list() {
$files = glob("/var/crash/*");
if (!is_array($files) || empty($files)) {
return array();
}
$exclude_patterns = array(
'.*.last',
'bounds',
'minfree'
);
foreach ($files as $idx => $fb) {
if (preg_match('/' . implode('|', $exclude_patterns) . '/', basename($fb)) == 1) {
unset($files[$idx]);
}
}
return $files;
}
function system_has_crash_data() {
/* Test if there are any crash data files present */
return count(cleanup_crash_file_list()) > 0;
}
function system_has_php_errors() {
/* Check if the PHP error log is empty. Cast to int in case the file
* does not exist and filesize() returns false. */
return (int) @filesize("/tmp/PHP_errors.log") > 0;
}
date_default_timezone_set($timezone);
?>

View File

@ -57,36 +57,14 @@ if (isset($_REQUEST['closenotice'])) {
sleep(1);
}
if ($g['disablecrashreporter'] != true) {
// Check to see if we have a crash report
$x = 0;
if (file_exists("/tmp/PHP_errors.log")) {
$total = `/bin/cat /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
if ($total > 0) {
$x++;
}
}
$crash = glob("/var/crash/*");
$skip_files = array(".", "..", "minfree", "");
if (is_array($crash)) {
foreach ($crash as $c) {
if (!in_array(basename($c), $skip_files)) {
$x++;
}
}
if ($x > 0) {
$savemsg = sprintf(gettext("%s has detected a crash report or programming bug."), $g['product_name']) . " ";
if (isAllowedPage("/crash_reporter.php")) {
$savemsg .= sprintf(gettext('Click %1$shere%2$s for more information.'), '<a href="crash_reporter.php">', '</a>');
} else {
$savemsg .= sprintf(gettext("Contact a firewall administrator for more information."));
}
$class = "warning";
}
if (($g['disablecrashreporter'] != true) && (system_has_crash_data() || system_has_php_errors())) {
$savemsg = sprintf(gettext("%s has detected a crash report or programming bug."), $g['product_name']) . " ";
if (isAllowedPage("/crash_reporter.php")) {
$savemsg .= sprintf(gettext('Click %1$shere%2$s for more information.'), '<a href="crash_reporter.php">', '</a>');
} else {
$savemsg .= sprintf(gettext("Contact a firewall administrator for more information."));
}
$class = "warning";
}
## Include each widget php include file.