-
Notifications
You must be signed in to change notification settings - Fork 3
/
phar-result.php
169 lines (164 loc) · 4.95 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
164
165
166
167
168
169
<?php
include("lang/setlang.php");
define('PACKAGE', 'phar');
// gettext setting
bindtextdomain(PACKAGE, 'lang'); // or $your_path/lang, ex: /var/www/test/lang
textdomain(PACKAGE);
?>
<?php
include "functions.php";
$jsonExpected = $_SERVER["HTTP_ACCEPT"] === "application/json";
if(!$jsonExpected):
?>
<html>
<head>
<title><?php echo _('Phar作成結果'); ?></title>
<link rel="stylesheet" href="/css/main.css" />
</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 = "ファイルがポストされたうえで開かれる必要があります";
echo $jsonExpected ? json_encode(["error" => $out]) : $out;
return;
}
$file = $_FILES["file"];
if($file["error"] !== 0){
echo _("<h1>Failure</h1>");
echo _("不正なアップロード: ");
switch($err = $file["error"]){
case UPLOAD_ERR_INI_SIZE:
$errMsg = "ファイルが大きすぎます UPLOAD_ERR_INI_SIZE($err)";
break;
case UPLOAD_ERR_FORM_SIZE:
$errMsg = "ファイルが大きすぎます UPLOAD_ERR_FORM_SIZE($err)";
break;
case UPLOAD_ERR_PARTIAL:
$errMsg = "ファイルが一部しかありません UPLOAD_ERR_PARTIAL($err)";
break;
case UPLOAD_ERR_NO_FILE:
$errMsg = "ファイルがアップロードされていません UPLOAD_ERR_NO_FILE($err)";
break;
case UPLOAD_ERR_NO_TMP_DIR:
$errMsg = "tempフォルダ不調です UPLOAD_ERR_NO_TMP_DIR($err)";
break;
case UPLOAD_ERR_CANT_WRITE:
$errMsg = "書き込みエラー UPLOAD_ERR_CANT_WRITE($err)";
break;
case UPLOAD_ERR_EXTENSION:
$errMsg = "PHPエクステンションが停止しました 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" => "http://pmt.haniokasai.com" . $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の作成に成功しました</h1>
EOP;
readfile("ad.txt");
echo <<<EOP
<p><a href="/data/phars/$basename">pharをここからダウンロードします</a></p>
<p>少なくとも、2時間はファイルがダウンロードできます。</p>
EOP;
echo _("<p> $itv 秒前に, $cnt 個pharが作られています</p>");
echo "<hr>";
echo _("<h2>検査</h2>");
echo "<ul>";
foreach($inspections as $inspection){
$inspection->run()->htmlEcho();
}
echo "</ul>";
echo _("<p>検査の終了</p>");
?>
<p><?php echo _(' <a href="http://www.pocketmine.net/pluginReview.php"
target="_blank">公式 PocketMineプラグイン評価ツール</a> でパーミッションや実装の悪さを確認できます'); ?></p>
<?php readfile("ad.txt");?>
<?php the_end: ?>
</body>
</html>