crash_reporter.php 5.06 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
4
	Copyright (C) 2015 Franco Fichtner <franco@opnsense.org>
5
	Copyright (C) 2014 Deciso B.V.
Ad Schellevis's avatar
Ad Schellevis committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
	Copyright (C) 2011 Scott Ullrich
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:

	1. Redistributions of source code must retain the above copyright notice,
	   this list of conditions and the following disclaimer.

	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.

	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
*/

31 32 33
require_once("guiconfig.inc");
require_once("functions.inc");
require_once("captiveportal.inc");
Ad Schellevis's avatar
Ad Schellevis committed
34 35 36

define("FILE_SIZE", 450000);

37 38
function upload_crash_report($files)
{
Ad Schellevis's avatar
Ad Schellevis committed
39
	global $g;
40

Ad Schellevis's avatar
Ad Schellevis committed
41 42
	$post = array();
	$counter = 0;
43

Ad Schellevis's avatar
Ad Schellevis committed
44 45 46 47
	foreach($files as $file) {
		$post["file{$counter}"] = "@{$file}";
		$counter++;
	}
48 49 50 51 52 53 54 55 56 57 58

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_VERBOSE, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible;)');
	curl_setopt($ch, CURLOPT_URL, 'https://crash.opnsense.org/');
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
	$response = curl_exec($ch);

Ad Schellevis's avatar
Ad Schellevis committed
59 60 61
	return $response;
}

62
$pgtitle = array(gettext("Diagnostics"),gettext("Crash Reporter"));
Ad Schellevis's avatar
Ad Schellevis committed
63 64
include('head.inc');

65 66 67 68 69 70 71 72
$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')
);
Ad Schellevis's avatar
Ad Schellevis committed
73 74 75

?>

76
<body>
Ad Schellevis's avatar
Ad Schellevis committed
77 78
<?php include("fbegin.inc"); ?>

79
<section class="page-content-main">
80
	<div class="container-fluid">
81
		<div class="row">
82

83
			<section class="col-xs-12">
84
                <div class="content-box">
85 86 87
					 <form action="crash_reporter.php" method="post">
						 <div class="col-xs-12">

Ad Schellevis's avatar
Ad Schellevis committed
88 89

<?php
90 91
	if ($_POST['Submit'] == 'yes') {
		echo '<p>' . gettext('Processing...');
Ad Schellevis's avatar
Ad Schellevis committed
92 93
		ob_flush();
		flush();
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
		if (!is_dir('/var/crash')) {
			mkdir('/var/crash', 0750, true);
		}
		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 '<br/>' . gettext('Uploading...');
		ob_flush();
		flush();
		$resp = upload_crash_report($files_to_upload);
		echo '<br/>' . print_r($resp) . '</p>';
		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 '<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.');
Ad Schellevis's avatar
Ad Schellevis committed
118
		} else {
119
			echo gettext('Luckily we have not detected a programming bug.');
Ad Schellevis's avatar
Ad Schellevis committed
120
		}
121
		echo '</strong></p>';
Ad Schellevis's avatar
Ad Schellevis committed
122 123 124
	} else {
		$crash_files = glob("/var/crash/*");
		$crash_reports = $crash_report_header;
125
		$php_errors = @file_get_contents('/tmp/PHP_errors.log');
126
		if (!empty($php_errors)) {
Ad Schellevis's avatar
Ad Schellevis committed
127
			$crash_reports .= "\nPHP Errors:\n";
128
			$crash_reports .= $php_errors;
Ad Schellevis's avatar
Ad Schellevis committed
129
		}
130 131 132 133
		foreach ($crash_files as $cf) {
			if (filesize($cf) < FILE_SIZE) {
				$crash_reports .= "\nFilename: {$cf}\n";
				$crash_reports .= file_get_contents($cf);
Ad Schellevis's avatar
Ad Schellevis committed
134 135
			}
		}
136 137 138 139 140 141
		echo "<p><strong>" . gettext("Unfortunately we have detected at least one programming bug.") . "</strong></p>";
		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> ";
		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>";
Ad Schellevis's avatar
Ad Schellevis committed
142 143
	}
?>
144 145 146 147 148 149 150
						 </div>
					</form>
                </div>
			</section>
		</div>
	</div>
</section>
151 152

<?php include("foot.inc"); ?>