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, $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
|
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
|
}
|
107
|
exec("find /var/crash -type l -exec rm {} +");
|
108
|
exec("/usr/bin/gzip /var/crash/*");
|
109
|
$files_to_upload = glob("/var/crash/*");
|
110
|
echo "<br/>";
|
111
|
echo gettext("Uploading...");
|
112
|
ob_flush();
|
113
|
flush();
|
114
|
if(is_array($files_to_upload)) {
|
115
|
$resp = upload_crash_report($files_to_upload);
|
116
|
array_map('unlink', glob("/var/crash/*"));
|
117
|
// Erase the contents of the PHP error log
|
118
|
fclose(fopen("/tmp/PHP_errors.log", 'w'));
|
119
|
echo "<br/>";
|
120
|
print_r($resp);
|
121
|
echo "<p><a href=\"/\">" . gettext("Continue") . "</a>" . gettext(" and delete crash report files from local disk.") . "</p>";
|
122
|
} else {
|
123
|
echo "Could not find any crash files.";
|
124
|
}
|
125
|
} else if(gettext($_POST['Submit']) == "No") {
|
126
|
array_map('unlink', glob("/var/crash/*"));
|
127
|
// Erase the contents of the PHP error log
|
128
|
fclose(fopen("/tmp/PHP_errors.log", 'w'));
|
129
|
header("Location: /");
|
130
|
exit;
|
131
|
} else {
|
132
|
$crash_files = glob("/var/crash/*");
|
133
|
$crash_reports = $crash_report_header;
|
134
|
if (count($php_errors) > 0) {
|
135
|
$crash_reports .= "\nPHP Errors:\n";
|
136
|
$crash_reports .= implode("\n", $php_errors) . "\n\n";
|
137
|
}
|
138
|
if(is_array($crash_files)) {
|
139
|
foreach($crash_files as $cf) {
|
140
|
if(filesize($cf) < FILE_SIZE) {
|
141
|
$crash_reports .= "\nFilename: {$cf}\n";
|
142
|
$crash_reports .= file_get_contents($cf);
|
143
|
}
|
144
|
}
|
145
|
} else {
|
146
|
echo "Could not locate any crash data.";
|
147
|
}
|
148
|
output_crash_reporter_html($crash_reports);
|
149
|
}
|
150
|
?>
|
151
|
|
152
|
<?php include("fend.inc"); ?>
|
153
|
|
154
|
</body>
|
155
|
</html>
|