Project

General

Profile

Download (5.3 KB) Statistics
| Branch: | Tag: | Revision:
1 45d72d82 Scott Ullrich
<?php
2
/* $Id$ */
3
/*
4
	crash_reporter.php
5
	part of pfSense
6
	Copyright (C) 2011 Scott Ullrich
7
	All rights reserved.
8
9
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11
12
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14
15
	2. Redistributions in binary form must reproduce the above copyright
16
	   notice, this list of conditions and the following disclaimer in the
17
	   documentation and/or other materials provided with the distribution.
18
19
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30
/*
31
	pfSense_MODULE:	header
32
*/
33
34
##|+PRIV
35 528d5abf Scott Ullrich
##|*IDENT=page-diagnostics-crash-reporter
36
##|*NAME=Crash reporter
37
##|*DESCR=Uploads crash reports to pfSense and or deletes crash reports.
38
##|*MATCH=crash_reporter.php*
39 45d72d82 Scott Ullrich
##|-PRIV
40
41
require("guiconfig.inc");
42
require("functions.inc");
43
require("captiveportal.inc");
44
45 8e572710 Scott Ullrich
define("FILE_SIZE", 450000);
46 2988636c Scott Ullrich
47 45d72d82 Scott Ullrich
function upload_crash_report($files) {
48 9b700cf2 Scott Ullrich
	global $g;
49 4f09471c Scott Ullrich
	$post = array();
50
	$counter = 0;
51
	foreach($files as $file) {
52 dabcf28c Scott Ullrich
		$post["file{$counter}"] = "@{$file}";
53
		$counter++;
54 4f09471c Scott Ullrich
	}
55 45d72d82 Scott Ullrich
    $ch = curl_init();
56
    curl_setopt($ch, CURLOPT_HEADER, 0);
57
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
58
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
59
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
60 4b665f74 Scott Ullrich
    curl_setopt($ch, CURLOPT_URL, $g['crashreporterurl']);
61 45d72d82 Scott Ullrich
    curl_setopt($ch, CURLOPT_POST, true);
62
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
63
    $response = curl_exec($ch);
64 528d5abf Scott Ullrich
	return $response;
65 45d72d82 Scott Ullrich
}
66
67
function output_crash_reporter_html($crash_reports) {
68 088de6b1 Scott Ullrich
	echo "<strong>" . gettext("Unfortunately we have detected a programming bug.") . "</strong></p>";
69
	echo gettext("Would you like to submit the programming debug logs to the pfSense developers for inspection?") . "</p>";
70 49c8f964 Scott Ullrich
	echo "<p>";
71 4a1ab618 Scott Ullrich
	echo "<i>" . gettext("Please double check the contents to ensure you are comfortable sending this information before clicking Yes.") . "</i><br/>";
72
	echo "<p>";
73 49c8f964 Scott Ullrich
	echo gettext("Contents of crash reports") . ":<br/>";
74 9b091133 Scott Ullrich
	echo "<textarea readonly rows='40' cols='65' name='crashreports'>{$crash_reports}</textarea>";
75 3a6cda80 Scott Ullrich
	echo "<p/>";
76 c26c01d7 Scott Ullrich
	echo "<input name=\"Submit\" type=\"submit\" class=\"formbtn\" value=\"" . gettext("Yes") .  "\">" . gettext(" - Submit this to the developers for inspection");
77 f75a4575 Scott Ullrich
	echo "<p/><input name=\"Submit\" type=\"submit\" class=\"formbtn\" value=\"" . gettext("No") .  "\">" . gettext(" - Just delete the crash report and take me back to the Dashboard");
78 528d5abf Scott Ullrich
	echo "<p/>";
79
	echo "</form>";
80 45d72d82 Scott Ullrich
}
81
82 421f72a7 Scott Ullrich
$pgtitle = array(gettext("Diagnostics"),gettext("Crash reporter"));
83 45d72d82 Scott Ullrich
include('head.inc');
84
85 ffb9c06d Scott Ullrich
$crash_report_header = "Crash report begins.  Anonymous machine information:\n\n";
86
$crash_report_header .= php_uname("m") . "\n";
87
$crash_report_header .= php_uname("r") . "\n";
88
$crash_report_header .= php_uname("v") . "\n";
89 4261af1d Scott Ullrich
$crash_report_header .= "\nCrash report details:\n";
90 ffb9c06d Scott Ullrich
91 dc43ff1e jim-p
exec("/usr/bin/grep -vi warning /tmp/PHP_errors.log", $php_errors);
92
93 45d72d82 Scott Ullrich
?>
94
95
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
96
97
<?php include("fbegin.inc"); ?>
98
99 421f72a7 Scott Ullrich
	<form action="crash_reporter.php" method="post">
100 45d72d82 Scott Ullrich
101
<?php
102 49c8f964 Scott Ullrich
	if (gettext($_POST['Submit']) == "Yes") {
103 45d72d82 Scott Ullrich
		echo gettext("Processing...");
104 ffb9c06d Scott Ullrich
		file_put_contents("/var/crash/crashreport_header.txt", $crash_report_header);
105 88dadca1 Scott Ullrich
		if(file_exists("/tmp/PHP_errors.log"))
106
			exec("cp /tmp/PHP_errors.log /var/crash/");
107 dc43ff1e jim-p
		exec("/usr/bin/gzip /var/crash/*");
108 45d72d82 Scott Ullrich
		$files_to_upload = glob("/var/crash/*");
109
		echo "<p/>";
110
		echo gettext("Uploading...");
111 58b4b246 Scott Ullrich
		ob_flush();
112
		flush();
113 45d72d82 Scott Ullrich
		if(is_array($files_to_upload)) {
114 4f09471c Scott Ullrich
			$resp = upload_crash_report($files_to_upload);
115 45d72d82 Scott Ullrich
			exec("rm /var/crash/*");
116 dc43ff1e jim-p
			// Erase the contents of the PHP error log
117
			fclose(fopen("/tmp/PHP_errors.log", 'w'));
118 166c7354 Scott Ullrich
			echo "<p/>";
119
			print_r($resp);
120 63526c2c Scott Ullrich
			echo "<p/><a href='/'>" . gettext("Continue") . "</a>" . gettext(" and delete crash report files from local disk.");
121 45d72d82 Scott Ullrich
		} else {
122
			echo "Could not find any crash files.";
123
		}
124 49c8f964 Scott Ullrich
	} else if(gettext($_POST['Submit']) == "No") {
125 45d72d82 Scott Ullrich
		exec("rm /var/crash/*");
126 34d0f40c jim-p
		// Erase the contents of the PHP error log
127
		fclose(fopen("/tmp/PHP_errors.log", 'w'));
128 45d72d82 Scott Ullrich
		Header("Location: /");
129
		exit;
130
	} else {
131
		$crash_files = glob("/var/crash/*");
132 dabcf28c Scott Ullrich
		$crash_reports = $crash_report_header;
133 dc43ff1e jim-p
		if (count($php_errors) > 0) {
134
			$crash_reports .= "\nPHP Errors:\n";
135
			$crash_reports .= implode("\n", $php_errors) . "\n\n";
136
		}
137 e0a7f441 Scott Ullrich
		if(is_array($crash_files))	{
138
			foreach($crash_files as $cf) {
139 2988636c Scott Ullrich
				if(filesize($cf) < FILE_SIZE) {
140 85c3229a Scott Ullrich
					$crash_reports .= "\nFilename: {$cf}\n";
141
					$crash_reports .= file_get_contents($cf);
142
				}
143 e0a7f441 Scott Ullrich
			}
144
		} else { 
145 45d72d82 Scott Ullrich
			echo "Could not locate any crash data.";
146 e0a7f441 Scott Ullrich
		}
147 45d72d82 Scott Ullrich
		output_crash_reporter_html($crash_reports);
148
	}
149
?>
150
151
<?php include("fend.inc"); ?>
152
153
</body>
154
</html>