Project

General

Profile

Download (5.25 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	crash_reporter.php
5
	part of pfSense
6
	Copyright (C) 2011 Scott Ullrich
7
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8
	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
##|*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
##|-PRIV
41

    
42
require("guiconfig.inc");
43
require("functions.inc");
44
require("captiveportal.inc");
45

    
46
define("FILE_SIZE", 450000);
47

    
48
function upload_crash_report($files) {
49
	global $g;
50
	$post = array();
51
	$counter = 0;
52
	foreach($files as $file) {
53
		$post["file{$counter}"] = "@{$file}";
54
		$counter++;
55
	}
56
	$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
	return $response;
66
}
67

    
68
$pgtitle = array(gettext("Diagnostics"),gettext("Crash reporter"));
69
include('head.inc');
70

    
71
$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
$crash_report_header .= "\nCrash report details:\n";
76

    
77
exec("/usr/bin/grep -vi warning /tmp/PHP_errors.log", $php_errors);
78
?>
79
<?php
80
	if (gettext($_POST['Submit']) == "Yes") {
81
		echo gettext("Processing...");
82
		if (!is_dir("/var/crash"))
83
			mkdir("/var/crash", 0750, true);
84
		@file_put_contents("/var/crash/crashreport_header.txt", $crash_report_header);
85
		if(file_exists("/tmp/PHP_errors.log"))
86
			copy("/tmp/PHP_errors.log", "/var/crash/PHP_errors.log");
87
		exec("/usr/bin/gzip /var/crash/*");
88
		$files_to_upload = glob("/var/crash/*");
89
		echo "<br/>";
90
		echo gettext("Uploading...");
91
		ob_flush();
92
		flush();
93
		if(is_array($files_to_upload)) {
94
			$resp = upload_crash_report($files_to_upload);
95
			array_map('unlink', glob("/var/crash/*"));
96
			// Erase the contents of the PHP error log
97
			fclose(fopen("/tmp/PHP_errors.log", 'w'));
98
			echo "<br/>";
99
			print_r($resp);
100
			echo "<p><a href=\"/\">" . gettext("Continue") . "</a>" . gettext(" and delete crash report files from local disk.") . "</p>";
101
		} else {
102
			echo "Could not find any crash files.";
103
		}
104
	} else if(gettext($_POST['Submit']) == "No") {
105
		array_map('unlink', glob("/var/crash/*"));
106
		// Erase the contents of the PHP error log
107
		fclose(fopen("/tmp/PHP_errors.log", 'w'));
108
		header("Location: /");
109
		exit;
110
	} else {
111
		$crash_files = glob("/var/crash/*");
112
		$crash_reports = $crash_report_header;
113
		if (count($php_errors) > 0) {
114
			$crash_reports .= "\nPHP Errors:\n";
115
			$crash_reports .= implode("\n", $php_errors) . "\n\n";
116
		}
117
		if(is_array($crash_files))	{
118
			foreach($crash_files as $cf) {
119
				if(filesize($cf) < FILE_SIZE) {
120
					$crash_reports .= "\nFilename: {$cf}\n";
121
					$crash_reports .= file_get_contents($cf);
122
				}
123
			}
124
		} else {
125
			echo "Could not locate any crash data.";
126
		}
127
?>
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
	}
147
?>
148

    
149
<?php include("foot.inc")?>
(4-4/252)