forked from PEMapModder/CrashDumpParserSource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.php
379 lines (363 loc) · 9.7 KB
/
result.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<?php
if(!isset($_POST["method"])){
header("Location: ./");
die;
}
$method = $_POST["method"];
if($method === "buffer"){
if(!isset($_POST["buffer"])){
header("Location: ./");
die;
}
$buffer = $_POST["buffer"];
}elseif($method === "file"){
if(!isset($_FILES["file"])){
header("Location: ./");
die;
}
$path = $_FILES["file"]["tmp_name"];
if(is_uploaded_file($path)){
$buffer = file_get_contents($path);
}else{
header("Location: ./");
die;
}
}elseif($method === "github"){
$buffer = "";
}else{
header("Location: ./");
die;
}
$buffer = $_POST["buffer"];
if(($start = strpos($buffer, "----------------------REPORT THE DATA BELOW THIS LINE-----------------------
===BEGIN CRASH DUMP===")) !== false){
if(($end = strpos($buffer, "===END CRASH DUMP===")) !== false){
$buffer = trim(substr($buffer, $start, $end - $start));
}
}
$base64 = str_replace(str_split("\r\n\t "), "", $buffer);
$zlib = base64_decode($base64);
$json = zlib_decode($zlib);
$data = json_decode($json, true);
if(!is_array($data)){
http_response_code(400);
header("Content-Type: text/plain");
echo "Data error!";
die;
}
function formatUrl($url){
if(preg_match('%^((http(s)?):)?//([^/]+)(/.*)?$%', $url, $matches)){
return "<a target='_blank' href='$matches[0]'>$matches[4]</a>";
}
return $url;
}
function formatArray(array $array){
if(count($array) === 0){
return "<em>None</em>";
}
return htmlspecialchars(implode(", ", $array));
}
if($_SERVER["HTTP_ACCEPT"] === "application/json" or isset($_REQUEST["api"])){
header("Content-Type: application/json");
echo json_encode($data, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING | JSON_UNESCAPED_SLASHES);
die;
}
const OPTIMIZER_ON = false; // need to disable it in <pre></pre>
ob_start();
?>
<!--suppress CssUnusedSymbol -->
<html>
<head>
<title>Crash dump viewer</title>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
$(document).ready(function(){
var i = 0;
var spoiling = function(){
var $this = $(this);
var autoName = "auto-compiled-spoiler-" + (++i);
var definedName = $this.attr("data-spoiler-name");
var html = "<div><button class='spoiler-opener auto-compiled' " +
"data-spoiler='" + autoName + "' data-spoiler-name='" + definedName + "'>";
html += "Show " + definedName;
html += "</button>";
html += "<div class='spoiler' data-spoiler='" + autoName + "' data-spoiler-name='" + definedName + "'>";
html += $this.html();
html += "</div></div>";
$this.replaceWith(html);
};
while($(".spoiling").length > 0){
$(".spoiling").each(spoiling);
}
$(".spoiler-opener").click(function(){
var $this = $(this);
var spoiler = $(".spoiler[data-spoiler=\"" + $this.attr("data-spoiler") + "\"]");
var toShow = spoiler.css("display") === "none";
spoiler.css("display", toShow ? "block" : "none");
if($this.hasClass("auto-compiled")){
$this.text((toShow ? "Hide" : "Show") + " " + $this.attr("data-spoiler-name"));
}
});
$(".spoiler").css("display", "none");
$("pre.code").each(function(){
var $this = $(this);
var showLineNumber = typeof $this.attr("data-hide-line-number") === typeof undefined;
var firstLine = 1;
var firstLineString = $this.attr("data-first-line");
if(typeof firstLineString !== typeof undefined){
firstLine = parseInt(firstLineString);
}
var lines = $this.html().split("\n");
var html = "<table class='code'>";
var hightlightLines = $this.attr("data-highlight-line");
if(typeof hightlightLines === typeof undefined){
hightlightLines = (String)(firstLine - 1);
}
hightlightLines = hightlightLines.split(",");
for(var line = 0; line < lines.length; line++){
var isHighlightLine = false;
for(var num = 0; num < hightlightLines.length; num++){
if(line + firstLine == hightlightLines[num]){
isHighlightLine = true;
}
}
html += "<tr";
if(isHighlightLine){
html += " class='highlighted'";
}
html += ">";
html += "<td align='right'>";
if(showLineNumber){
html += line + firstLine;
}
html += "</td>";
html += "<td> </td>";
html += "<td align='left'>";
html += lines[line];
html += "</td>";
html += "</tr>";
}
html += "</table>";
$(this).replaceWith(html);
});
$("div.datum").each(function(){
var $this = $(this);
$this.before("<hr>");
$this.before("<h3 class='subheading'>" + $this.attr("data-name") + "</h3>");
});
$("table.info").attr("border", "1");
});
</script>
<style>
body{
margin: 30px 50px;
font-family: "Helvetica Neue", Helvetica, Verdana, Arial, sans-serif;
}
h1{
text-align: center;
font-weight: bold;
}
.code{
background-color: #303030;
color: #FFFFFF;
font-family: monospace;
border-radius: 5px;
}
pre.code{
padding: 10px 0;
}
table.code{
padding: 10px 5px;
}
table.code tr.highlighted{
background-color: #798B47;
}
table.info th{
text-align: right;
padding: 5px;
}
table.info td{
text-align: left;
padding: 5px;
}
</style>
</head>
<body>
<h1>Crash dump</h1>
<div class="datum" data-name="Date of Crash">
<script>
var date = new Date(<?= json_encode($data["time"]) * 1000 ?>);
document.write(date.toDateString());
</script>
</div>
<div class="datum" data-name="Error">
<pre class="code" data-hide-line-number>
<?= htmlspecialchars($data["error"]["type"]) ?> - <?= htmlspecialchars($data["error"]["message"]) ?>
</pre>
<h5>Code: <?= htmlspecialchars(substr($data["error"]["file"], 1) . ".php") ?></h5>
<?php
foreach($data["code"] as $key => $v){
if($v === null){
unset($data["code"][$key]);
}
}
$errorLine = $data["error"]["line"];
?>
<div class="spoiling" data-spoiler-name="error code">
<pre class="code" data-first-line="<?= array_keys($data["code"])[0] ?>" data-highlight-line="<?= $errorLine ?>">
<?= str_replace(["\t", " "], [" ", " "], implode("\n", $data["code"])) ?>
</pre>
</div>
</div>
<?php if(isset($data["plugin"]) and isset($data["plugins"][$data["plugin"]])): ?>
<div class="datum" data-name="Crashing plugin">
<?php
$plugin = $data["plugins"][$data["plugin"]];
if($plugin["website"] !== null){
echo "<a target='_blank' href='" . $plugin["website"] . "'>";
}
?>
<?= htmlspecialchars($data["plugin"]) ?>
<?php
if($plugin["website"] !== null){
echo "</a>";
}
?>
</div>
<?php endif; ?>
<div class="datum" data-name="Backtrace">
<?php
$trace = $data["trace"];
foreach($trace as &$line){
$line = substr(strstr($line, " "), 1);
}
?>
<div class="spoiling" data-spoiler-name="backtrace">
<pre class="code" data-first-line="0">
<?= implode("\n", $trace) ?>
</pre>
</div>
</div>
<div class="datum" data-name="PocketMine Information">
<table class="info">
<?php
$generalInfo = $data["general"];
?>
<tbody>
<tr>
<th>Version</th>
<td><?= $generalInfo["version"] ?></td>
</tr>
<tr>
<th>API</th>
<td><?= $generalInfo["version"] ?></td>
</tr>
<?php if(trim($generalInfo["git"], "0") !== ""): ?>
<tr>
<th>Git commit SHA</th>
<td><?= $generalInfo["git"] ?></td>
</tr>
<?php endif; ?>
<tr>
<th>RakLib version</th>
<td><?= $generalInfo["raklib"] ?></td>
</tr>
</tbody>
</table>
</div>
<div class="datum" data-name="Plugins">
<div class="spoiling" data-spoiler-name="<?= count($data["plugins"]) ?> plugins">
<ul>
<?php foreach($data["plugins"] as $plugin): ?>
<?php
if(!$plugin["enabled"]){
continue;
}
?>
<li>
<?= htmlspecialchars($plugin["name"]) ?>
<div class="spoiling" data-spoiler-name="<?= $plugin["name"] ?> information">
<table class="info">
<tbody>
<tr>
<th>Version</th>
<td><?= htmlspecialchars($plugin["version"]) ?></td>
</tr>
<tr>
<th>Author(s)</th>
<td><?= formatArray($plugin["authors"]) ?></td>
</tr>
<tr>
<th>Supported API(s)</th>
<td><?= formatArray($plugin["api"]) ?></td>
</tr>
<?php if(count($plugin["depends"]) > 0): ?>
<tr>
<th>Dependencies</th>
<td><?= formatArray($plugin["depends"]) ?></td>
</tr>
<?php endif; ?>
<?php if(count($plugin["softDepends"]) > 0): ?>
<tr>
<th>Soft Dependencies</th>
<td><?= formatArray($plugin["softDepends"]) ?></td>
</tr>
<?php endif; ?>
<?php if($plugin["website"] !== null): $website = $plugin["website"]; ?>
<tr>
<th>Website</th>
<td><?= formatUrl($website) ?></td>
</tr>
<?php endif; ?>
<tr>
<th>Main class</th>
<td><?= htmlspecialchars($plugin["main"]) ?></td>
</tr>
</tbody>
</table>
</div>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<div class="datum" data-name="PocketMine configuration files">
<div class="spoiling" data-spoiler-name="server.properties">
<pre class="code">
<?= htmlspecialchars($data["server.properties"]) ?>
</pre>
</div>
<div class="spoiling" data-spoiler-name="pocketmine.yml">
<pre class="code">
<?= htmlspecialchars($data["pocketmine.yml"]) ?>
</pre>
</div>
</div>
<div class="datum" data-name="PHP information">
<div class="spoiling" data-spoiler-name="PHP extensions">
<table class="info">
<tbody>
<?php foreach($data["extensions"] as $extension => $version): ?>
<?php
if($version === false){
continue;
}
?>
<tr>
<th><?= htmlspecialchars($extension) ?></th>
<td><?= htmlspecialchars($version) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</body>
</html>
<?php
$html = ob_get_clean();
if(OPTIMIZER_ON){
$html = preg_replace('/[ \r\n\t]+/', " ", $html);
}
echo $html;
?>