1
|
<?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
|
##|*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
|
##|-PRIV
|
40
|
|
41
|
require("guiconfig.inc");
|
42
|
require("functions.inc");
|
43
|
require("captiveportal.inc");
|
44
|
|
45
|
define("FILE_SIZE", 450000);
|
46
|
|
47
|
function upload_crash_report($files) {
|
48
|
global $g;
|
49
|
$post = array();
|
50
|
$counter = 0;
|
51
|
foreach($files as $file) {
|
52
|
$post["file{$counter}"] = "@{$file}";
|
53
|
$counter++;
|
54
|
}
|
55
|
$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
|
curl_setopt($ch, CURLOPT_URL, $g['crashreporterurl']);
|
61
|
curl_setopt($ch, CURLOPT_POST, true);
|
62
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
63
|
$response = curl_exec($ch);
|
64
|
return $response;
|
65
|
}
|
66
|
|
67
|
function output_crash_reporter_html($crash_reports) {
|
68
|
echo "<p><strong>" . gettext("Unfortunately we have detected a programming bug.") . "</strong></p>";
|
69
|
echo "<p>" . gettext("Would you like to submit the programming debug logs to the pfSense developers for inspection?") . "</p>";
|
70
|
echo "<p><i>" . gettext("Please double check the contents to ensure you are comfortable sending this information before clicking Yes.") . "</i></p>";
|
71
|
echo "<p>" . gettext("Contents of crash reports") . ":<br />";
|
72
|
echo "<textarea readonly=\"readonly\" rows=\"40\" cols=\"65\" name=\"crashreports\">{$crash_reports}</textarea></p>";
|
73
|
echo "<p><input name=\"Submit\" type=\"submit\" class=\"formbtn\" value=\"" . gettext("Yes") . "\" />" . gettext(" - Submit this to the developers for inspection") . "</p>";
|
74
|
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>";
|
75
|
echo "</form>";
|
76
|
}
|
77
|
|
78
|
$pgtitle = array(gettext("Diagnostics"),gettext("Crash reporter"));
|
79
|
include('head.inc');
|
80
|
|
81
|
$crash_report_header = "Crash report begins. Anonymous machine information:\n\n";
|
82
|
$crash_report_header .= php_uname("m") . "\n";
|
83
|
$crash_report_header .= php_uname("r") . "\n";
|
84
|
$crash_report_header .= php_uname("v") . "\n";
|
85
|
$crash_report_header .= "\nCrash report details:\n";
|
86
|
|
87
|
exec("/usr/bin/grep -vi warning /tmp/PHP_errors.log", $php_errors);
|
88
|
|
89
|
?>
|
90
|
|
91
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
92
|
|
93
|
<?php include("fbegin.inc"); ?>
|
94
|
|
95
|
<form action="crash_reporter.php" method="post">
|
96
|
|
97
|
<?php
|
98
|
if (gettext($_POST['Submit']) == "Yes") {
|
99
|
echo gettext("Processing...");
|
100
|
if (!is_dir("/var/crash"))
|
101
|
mkdir("/var/crash", 0750, true);
|
102
|
@file_put_contents("/var/crash/crashreport_header.txt", $crash_report_header);
|
103
|
if(file_exists("/tmp/PHP_errors.log"))
|
104
|
copy("/tmp/PHP_errors.log", "/var/crash/PHP_errors.log");
|
105
|
exec("/usr/bin/gzip /var/crash/*");
|
106
|
$files_to_upload = glob("/var/crash/*");
|
107
|
echo "<br/>";
|
108
|
echo gettext("Uploading...");
|
109
|
ob_flush();
|
110
|
flush();
|
111
|
if(is_array($files_to_upload)) {
|
112
|
$resp = upload_crash_report($files_to_upload);
|
113
|
array_map('unlink', glob("/var/crash/*"));
|
114
|
// Erase the contents of the PHP error log
|
115
|
fclose(fopen("/tmp/PHP_errors.log", 'w'));
|
116
|
echo "<br/>";
|
117
|
print_r($resp);
|
118
|
echo "<p><a href=\"/\">" . gettext("Continue") . "</a>" . gettext(" and delete crash report files from local disk.") . "</p>";
|
119
|
} else {
|
120
|
echo "Could not find any crash files.";
|
121
|
}
|
122
|
} else if(gettext($_POST['Submit']) == "No") {
|
123
|
array_map('unlink', glob("/var/crash/*"));
|
124
|
// Erase the contents of the PHP error log
|
125
|
fclose(fopen("/tmp/PHP_errors.log", 'w'));
|
126
|
header("Location: /");
|
127
|
exit;
|
128
|
} else {
|
129
|
$crash_files = glob("/var/crash/*");
|
130
|
$crash_reports = $crash_report_header;
|
131
|
if (count($php_errors) > 0) {
|
132
|
$crash_reports .= "\nPHP Errors:\n";
|
133
|
$crash_reports .= implode("\n", $php_errors) . "\n\n";
|
134
|
}
|
135
|
if(is_array($crash_files)) {
|
136
|
foreach($crash_files as $cf) {
|
137
|
if(filesize($cf) < FILE_SIZE) {
|
138
|
$crash_reports .= "\nFilename: {$cf}\n";
|
139
|
$crash_reports .= file_get_contents($cf);
|
140
|
}
|
141
|
}
|
142
|
} else {
|
143
|
echo "Could not locate any crash data.";
|
144
|
}
|
145
|
output_crash_reporter_html($crash_reports);
|
146
|
}
|
147
|
?>
|
148
|
|
149
|
<?php include("fend.inc"); ?>
|
150
|
|
151
|
</body>
|
152
|
</html>
|