forked from pmt-mcpe-me/pmt.mcpe.me-source
/
phar-result.php
executable file
·128 lines (126 loc) · 3.74 KB
/
phar-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
<?php
include "functions.php";
?>
<html><head>
<title>Phar creation result</title>
</head><body><font face="Comic Sans MS">
<?php
use inspections\BadPracticeInspection;
use inspections\ClasspathInspection;
use inspections\SyntaxErrorInspection;
if(!isset($_FILES["file"])){
http_response_code(400);
echo "Page must be accessed by POST with upload file entry 'file'";
return;
}
$file = $_FILES["file"];
if($file["error"] !== 0){
echo "<h1>Failure</h1>";
echo "Invalid upload: ";
switch($err = $file["error"]){
case UPLOAD_ERR_INI_SIZE:
echo "file is too large UPLOAD_ERR_INI_SIZE($err)";
break;
case UPLOAD_ERR_FORM_SIZE:
echo "file is too large UPLOAD_ERR_FORM_SIZE($err)";
break;
case UPLOAD_ERR_PARTIAL:
echo "file is only partially uploaded UPLOAD_ERR_PARTIAL($err)";
break;
case UPLOAD_ERR_NO_FILE:
echo "no file is uploaded UPLOAD_ERR_NO_FILE($err)";
break;
case UPLOAD_ERR_NO_TMP_DIR:
echo "Missing a temporary folder UPLOAD_ERR_NO_TMP_DIR($err)";
break;
case UPLOAD_ERR_CANT_WRITE:
echo "Failed to write file to disk UPLOAD_ERR_CANT_WRITE($err)";
break;
case UPLOAD_ERR_EXTENSION:
echo "A PHP extension stopped the file upload UPLOAD_ERR_EXTENSION($err)";
break;
}
goto the_end;
}
$args = new TuneArgs;
$tno = "tune_top_namespace_optimization";
$obs = "tune_obfuscation";
$args->topNamespaceBackslash = isset($_POST[$tno]) ? ($_POST[$tno] === "on") : false;
$args->obfuscate = isset($_POST[$tno]) ? ($_POST[$tno] === "on") : false;
$result = phar_buildFromZip($file["tmp_name"], substr($file["name"], 0, -4), $args);
if($result["error"] !== MAKEPHAR_ERROR_NO){
echo "<h1>Failed to create phar</h1>";
echo "<p>Error: ";
echo $MAKEPHAR_ERROR_MESSAGES[$result["error"]];
echo "<br>";
echo "<code>" . $result["error_name"] . "(" . $result["erorr_id"] . ")</code>: ";
echo $result["error_msg"];
echo "</p>";
goto the_end;
}
$url = $result["pharpath"];
$basename = urlencode(substr($url, 12));
echo <<<EOP
<h1>Phar has been successfully created.</h1>
<p><a href="$url">Download the phar here</a>, or download with an alternative name:</p>
<iframe width="500" src="/data/dlPhar.php?path=$basename"></iframe>
<p>The download link is available for at least two hours.</p>
EOP;
$cnt = usage_inc("pharbuild", $time);
$diff = time() - $time;
$itv = "";
if($diff >= 3600 * 24){
$itv .= ((int) ($diff / (3600 * 24))) . " day(s), ";
$diff %= 3600 * 24;
while($diff < 0){
$diff += 3600 * 24;
}
}
if($diff >= 3600){
$itv .= ((int) ($diff / 3600)) . " hour(s), ";
$diff %= 3600;
while($diff < 0){
$diff += 3600;
}
}
if($diff >= 60){
$itv .= ((int) ($diff / 60)) . " minute(s), ";
$diff %= 60;
while($diff < 0){
$diff += 60;
}
}
$itv .= "$diff second(s)";
echo "<p>In the past $itv, $cnt phars have been created.</p>";
echo "<hr>";
echo "<h2>Inspections</h2>";
echo "<ul>";
/** @var inspections\Inspection[] $inspections */
$inspections = [];
$dir = $result["extractpath"];
foreach(["inspection_classpath", "inspection_bad_practice", "inspection_lint"] as $field){
if(!isset($_POST[$field])){
$_POST[$field] = "off";
}
}
if($_POST["inspection_classpath"] === "on"){
$inspections[] = new ClasspathInspection($dir);
}
if($_POST["inspection_bad_practice"] === "on"){
$inspections[] = new BadPracticeInspection($dir);
}
if($_POST["inspection_lint"] === "on"){
$inspections[] = new SyntaxErrorInspection($dir);
}
foreach($inspections as $inspection){
$result = $inspection->run();
$result->htmlEcho();
}
echo "</ul>";
echo "<p>End of inspections</p>";
?>
<p>You are also recommended to check the phar file at <a href="http://www.pocketmine.net/pluginReview.php"
target="_blank">the official PocketMine plugin reviewing tool</a> to check your bad practices and
the permissions that your plugin uses.</p>
<?php the_end: ?>
</font></body></html>