This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
forked from pmt-mcpe-me/pmt.mcpe.me-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphar-result.php
executable file
·163 lines (158 loc) · 4.63 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
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
<?php
define('PACKAGE', 'phar');
?>
<?php
include "functions.php";
$jsonExpected = $_SERVER["HTTP_ACCEPT"] === "application/json";
if(!$jsonExpected):
?>
<html>
<head>
<title>Phar creation result</title>
</head>
<body>
<font face="Comic Sans MS">
<?php endif; ?>
<?php
use inspections\BadPracticeInspection;
use inspections\ClasspathInspection;
use inspections\SyntaxErrorInspection;
if(!isset($_FILES["file"])){
http_response_code(400);
$out = "Page must be accessed by POST with upload file entry 'file'";
echo $jsonExpected ? json_encode(["error" => $out]) : $out;
return;
}
$file = $_FILES["file"];
if($file["error"] !== 0){
echo "<h1>Failure</h1>";
echo "Invalid upload: ";
switch($err = $file["error"]){
case UPLOAD_ERR_INI_SIZE:
$errMsg = "file is too large UPLOAD_ERR_INI_SIZE($err)";
break;
case UPLOAD_ERR_FORM_SIZE:
$errMsg = "file is too large UPLOAD_ERR_FORM_SIZE($err)";
break;
case UPLOAD_ERR_PARTIAL:
$errMsg = "file is only partially uploaded UPLOAD_ERR_PARTIAL($err)";
break;
case UPLOAD_ERR_NO_FILE:
$errMsg = "no file is uploaded UPLOAD_ERR_NO_FILE($err)";
break;
case UPLOAD_ERR_NO_TMP_DIR:
$errMsg = "Missing a temporary folder UPLOAD_ERR_NO_TMP_DIR($err)";
break;
case UPLOAD_ERR_CANT_WRITE:
$errMsg = "Failed to write file to disk UPLOAD_ERR_CANT_WRITE($err)";
break;
case UPLOAD_ERR_EXTENSION:
$errMsg = "A PHP extension stopped the file upload UPLOAD_ERR_EXTENSION($err)";
break;
}
if(!$jsonExpected){
goto the_end;
}else{
echo json_encode(["error" => $errMsg]);
die;
}
}
$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){
if(!$jsonExpected){
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;
}else{
json_encode(["error" => $MAKEPHAR_ERROR_MESSAGES[$result["error"]]]);
}
}
$url = $result["pharpath"];
$basename = urlencode(substr($url, 12));
$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)";
/** @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);
}
if($jsonExpected){
$jsonData = [
"phar" => "https://mcpeme.mcpe.fun" . $url,
"expiry" => time() + 7200,
"inspections" => []
];
foreach($inspections as $inspection){
$jsonData["inspections"][$result->getName()] = $inspection->run()->jsonResult();
}
echo json_encode($jsonData);
die;
}
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;
echo "<p>In the past $itv, $cnt phars have been created.</p>";
echo "<hr>";
echo "<h2>Inspections</h2>";
echo "<ul>";
foreach($inspections as $inspection){
$inspection->run()->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>