Project

General

Profile

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