Project

General

Profile

Download (5.25 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 ed2d1343 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 7d5b007c Sjon Hortensius
	$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, "Mozilla/4.0 (compatible;)");
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 421f72a7 Scott Ullrich
$pgtitle = array(gettext("Diagnostics"),gettext("Crash reporter"));
69 45d72d82 Scott Ullrich
include('head.inc');
70
71 ffb9c06d Scott Ullrich
$crash_report_header = "Crash report begins.  Anonymous machine information:\n\n";
72
$crash_report_header .= php_uname("m") . "\n";
73
$crash_report_header .= php_uname("r") . "\n";
74
$crash_report_header .= php_uname("v") . "\n";
75 4261af1d Scott Ullrich
$crash_report_header .= "\nCrash report details:\n";
76 ffb9c06d Scott Ullrich
77 dc43ff1e jim-p
exec("/usr/bin/grep -vi warning /tmp/PHP_errors.log", $php_errors);
78 45d72d82 Scott Ullrich
?>
79
<?php
80 49c8f964 Scott Ullrich
	if (gettext($_POST['Submit']) == "Yes") {
81 45d72d82 Scott Ullrich
		echo gettext("Processing...");
82 eb233919 Ermal
		if (!is_dir("/var/crash"))
83 d31ca336 Renato Botelho
			mkdir("/var/crash", 0750, true);
84 eb233919 Ermal
		@file_put_contents("/var/crash/crashreport_header.txt", $crash_report_header);
85 88dadca1 Scott Ullrich
		if(file_exists("/tmp/PHP_errors.log"))
86 38cb3c39 Phil Davis
			copy("/tmp/PHP_errors.log", "/var/crash/PHP_errors.log");
87 dc43ff1e jim-p
		exec("/usr/bin/gzip /var/crash/*");
88 45d72d82 Scott Ullrich
		$files_to_upload = glob("/var/crash/*");
89 26509223 Colin Fleming
		echo "<br/>";
90 45d72d82 Scott Ullrich
		echo gettext("Uploading...");
91 58b4b246 Scott Ullrich
		ob_flush();
92
		flush();
93 45d72d82 Scott Ullrich
		if(is_array($files_to_upload)) {
94 4f09471c Scott Ullrich
			$resp = upload_crash_report($files_to_upload);
95 d31ca336 Renato Botelho
			array_map('unlink', glob("/var/crash/*"));
96 dc43ff1e jim-p
			// Erase the contents of the PHP error log
97
			fclose(fopen("/tmp/PHP_errors.log", 'w'));
98 26509223 Colin Fleming
			echo "<br/>";
99 166c7354 Scott Ullrich
			print_r($resp);
100 26509223 Colin Fleming
			echo "<p><a href=\"/\">" . gettext("Continue") . "</a>" . gettext(" and delete crash report files from local disk.") . "</p>";
101 45d72d82 Scott Ullrich
		} else {
102
			echo "Could not find any crash files.";
103
		}
104 49c8f964 Scott Ullrich
	} else if(gettext($_POST['Submit']) == "No") {
105 d7d6e57a Renato Botelho
		array_map('unlink', glob("/var/crash/*"));
106 34d0f40c jim-p
		// Erase the contents of the PHP error log
107
		fclose(fopen("/tmp/PHP_errors.log", 'w'));
108 6f3d2063 Renato Botelho
		header("Location: /");
109 45d72d82 Scott Ullrich
		exit;
110
	} else {
111
		$crash_files = glob("/var/crash/*");
112 dabcf28c Scott Ullrich
		$crash_reports = $crash_report_header;
113 dc43ff1e jim-p
		if (count($php_errors) > 0) {
114
			$crash_reports .= "\nPHP Errors:\n";
115
			$crash_reports .= implode("\n", $php_errors) . "\n\n";
116
		}
117 e0a7f441 Scott Ullrich
		if(is_array($crash_files))	{
118
			foreach($crash_files as $cf) {
119 2988636c Scott Ullrich
				if(filesize($cf) < FILE_SIZE) {
120 85c3229a Scott Ullrich
					$crash_reports .= "\nFilename: {$cf}\n";
121
					$crash_reports .= file_get_contents($cf);
122
				}
123 e0a7f441 Scott Ullrich
			}
124 7d5b007c Sjon Hortensius
		} else {
125 45d72d82 Scott Ullrich
			echo "Could not locate any crash data.";
126 e0a7f441 Scott Ullrich
		}
127 7d5b007c Sjon Hortensius
?>
128
	<div class="jumbotron">
129
	<div class="panel panel-default">
130
		<div class="panel-heading"><h3><?=gettext("Unfortunately we have detected a programming bug.")?></h3></div>
131
		<div class="panel-body">
132
		<p>
133
			<?=gettext("Would you like to submit the programming debug logs to the pfSense developers for inspection?")?>
134
			<i><?=gettext("Please double check the contents to ensure you are comfortable sending this information before clicking Yes.")?></i>
135
		</p>
136
		<textarea readonly="readonly" style="width: 100%; height: 350px;">
137
			<?=$crash_reports?>
138
		</textarea>
139
		<form action="crash_reporter.php" method="post">
140
			<button class="btn btn-primary" name="Submit" type="submit" value="Yes"><?=gettext("Yes")?> - <?=gettext("Submit this to the developers for inspection")?></button>
141
			<button class="btn btn-default" name="Submit" type="submit" value="No"><?=gettext("No")?> - <?=gettext("Just delete the crash report and take me back to the Dashboard")?></button>
142
		</form>
143
	</div>
144
	</div>
145
<?php
146 45d72d82 Scott Ullrich
	}
147
?>
148
149 31f03b6c Sjon Hortensius
<?php include("foot.inc")?>