Project

General

Profile

Download (5.49 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
function output_crash_reporter_html($crash_reports) {
69
	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
	echo "</form>";
77
}
78

    
79
$pgtitle = array(gettext("Diagnostics"),gettext("Crash reporter"));
80
include('head.inc');
81

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

    
88
exec("/usr/bin/grep -vi warning /tmp/PHP_errors.log", $php_errors);
89

    
90
?>
91

    
92
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
93

    
94
<?php include("fbegin.inc"); ?>
95

    
96
	<form action="crash_reporter.php" method="post">
97

    
98
<?php
99
	if (gettext($_POST['Submit']) == "Yes") {
100
		echo gettext("Processing...");
101
		if (!is_dir("/var/crash"))
102
			mkdir("/var/crash", 0750, true);
103
		@file_put_contents("/var/crash/crashreport_header.txt", $crash_report_header);
104
		if(file_exists("/tmp/PHP_errors.log"))
105
			copy("/tmp/PHP_errors.log", "/var/crash/PHP_errors.log");
106
		exec("/usr/bin/gzip /var/crash/*");
107
		$files_to_upload = glob("/var/crash/*");
108
		echo "<br/>";
109
		echo gettext("Uploading...");
110
		ob_flush();
111
		flush();
112
		if(is_array($files_to_upload)) {
113
			$resp = upload_crash_report($files_to_upload);
114
			array_map('unlink', glob("/var/crash/*"));
115
			// Erase the contents of the PHP error log
116
			fclose(fopen("/tmp/PHP_errors.log", 'w'));
117
			echo "<br/>";
118
			print_r($resp);
119
			echo "<p><a href=\"/\">" . gettext("Continue") . "</a>" . gettext(" and delete crash report files from local disk.") . "</p>";
120
		} else {
121
			echo "Could not find any crash files.";
122
		}
123
	} else if(gettext($_POST['Submit']) == "No") {
124
		array_map('unlink', glob("/var/crash/*"));
125
		// Erase the contents of the PHP error log
126
		fclose(fopen("/tmp/PHP_errors.log", 'w'));
127
		header("Location: /");
128
		exit;
129
	} else {
130
		$crash_files = glob("/var/crash/*");
131
		$crash_reports = $crash_report_header;
132
		if (count($php_errors) > 0) {
133
			$crash_reports .= "\nPHP Errors:\n";
134
			$crash_reports .= implode("\n", $php_errors) . "\n\n";
135
		}
136
		if(is_array($crash_files))	{
137
			foreach($crash_files as $cf) {
138
				if(filesize($cf) < FILE_SIZE) {
139
					$crash_reports .= "\nFilename: {$cf}\n";
140
					$crash_reports .= file_get_contents($cf);
141
				}
142
			}
143
		} else { 
144
			echo "Could not locate any crash data.";
145
		}
146
		output_crash_reporter_html($crash_reports);
147
	}
148
?>
149

    
150
<?php include("fend.inc"); ?>
151

    
152
</body>
153
</html>
(4-4/256)