Итак, к сути:
Есть исходник скрипта .php с одного сайта, делает он следующее.
При заходе на страницу сайта пользователь может загрузить свой файл расширения .phar (написанный в php), выбрать нужные опции для обработки файла, после чего жмется кнопка Inject и пользователь переадресовывается на страницу загрузки своего файла, но уже обработанного данным скриптом.
Суть вопроса: как бы подредактировать данный скрипт, чтобы получить обработанный им .phar файл (выбранный пользователем по желанию), с последующим сохранением где-нибудь на диске или локальном веб-сервере в нужном для себя месте? Не могу найти путь для отправки готового файла.
Буду крайне признателен за любую посильную помощь!
Сам код:
Спойлер (Отобразить)
PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- <?PHP
- const debugOn = false;
- echo "Error: $msg at $file#$line";
- http_response_code(500);
- exit;
- });
- $newApi = "2.0.0";
- $newApi = $_REQUEST["api"];
- }
- $path = $_FILES["phar"]["tmp_name"];
- $extended = $path . ".phar";
- $phar = new Phar($extended);
- $phar->startBuffering();
- echo "plugin.yml missing";
- exit;
- }
- $yaml = yaml_parse($contents);
- $yaml["api"] = [$yaml["api"]];
- }
- echo "API version $newApi is already declared.";
- exit;
- }
- $yaml["api"][] = "2.0.0";
- $contents = yaml_emit($yaml);
- $phar->addFromString("plugin.yml", $contents);
- if(debugOn){
- }
- $replaceUse = ($_REQUEST["nbt-use"] ?? "off") === "on";
- $replaceFQN = ($_REQUEST["nbt-fqn"] ?? "off") === "on";
- $replaceNew = ($_REQUEST["nbt-new"] ?? "off") === "on";
- $replaceInstanceOf = ($_REQUEST["nbt-instanceof"] ?? "off") === "on";
- if($replaceUse or $replaceFQN or $replaceNew or $replaceInstanceOf){
- $refactorTable = [
- "ByteArray" => "ByteArrayTag",
- "Byte" => "ByteTag",
- "Compound" => "CompoundTag",
- "Double" => "DoubleTag",
- "End" => "EndTag",
- "Float" => "FloatTag",
- "IntArray" => "IntArrayTag",
- "Int" => "IntTag",
- "Enum" => "ListTag",
- "Long" => "LongTag",
- "Short" => "ShortTag",
- "String" => "StringTag",
- ];
- foreach(new \RecursiveIteratorIterator($phar) as $localName => $file){
- $fn = $file->getFileName();
- if($replaceUse){
- $ns = "pocketmine\\nbt\\tag\\";
- $c = preg_replace_callback("/use[ \t\n\r]+$quotedNs($names)[ \t\n\r]*;/i", function ($match) use ($ns, $refactorTable){
- return "use $ns" . $refactorTable[$match[1]] . ";";
- }, $c);
- }
- if($replaceFQN){
- foreach($refactorTable as $from => $to){
- $from = "\\pocketmine\\nbt\\tag\\$from";
- $to = "\\pocketmine\\nbt\\tag\\$to";
- }
- }
- if($replaceNew){
- $ns = "pocketmine\\nbt\\tag\\";
- $c = preg_replace_callback("/new[ \t\n\r]+($names)[ \t\n\r]*([\(\);,])/i", function ($match) use ($ns, $refactorTable){
- return "new " . $refactorTable[$match[1]] . $match[2];
- }, $c);
- }
- if($replaceInstanceOf){
- $ns = "pocketmine\\nbt\\tag\\";
- $c = preg_replace_callback("/instanceof[ \t\n\r]+$quotedNs($names)/i", function ($match) use ($ns, $refactorTable){
- return "instanceof " . $refactorTable[$match[1]];
- }, $c);
- }
- if(debugOn){
- echo $localName, " ($fn):\n", $c, "\n\n";
- }
- if($c !== $o){
- $phar->addFromString($localName, $c);
- }
- }
- }
- }
- $phar->stopBuffering();
- if(debugOn){
- die;
- }
- exit;
- }
- ?>
- <html>
- <head>
- <title>Plugin API version bumper</title>
- </head>
- <body>
- <h1>API 2.0.0 injection</h1>
- <p>Before using this tool, please carefully read the following caution:</p>
- <ul>
- <li>This tool only <em>forces</em> the plugin to say that it supports API 2.0.0 (PHP 7 update), and optionally,
- blindly replaces some specific backwards-incompatible changes in the phar. It will not fix the actual
- incompatibility issues.
- </li>
- <li>If errors happen after using phars downloaded from this page, unintsall it immediately.</li>
- <li>Click <span
- onclick='alert("Thanks for carefully reading the caution!"); document.getElementById("upload").disabled = false;'>these three words</span>
- if you have read the above.
- </li>
- </ul>
- <hr>
- <form action="updated.phar" method="post" enctype="multipart/form-data">
- <p><input type="file" name="phar"></p>
- <ul>
- <li>
- <input type="checkbox" name="diffapi" onclick='document.getElementById("apiInput").disabled = false;'> No, I
- don't want API <code>2.0.0</code>.
- I want something else: <input id="apiInput" type="text" name="api" value="2.0.0" disabled>
- </li>
- <li>
- Replace the following usage of NBT tags:
- <ul>
- <li><input type="checkbox" name="nbt-use" checked> <code>use pocketmine\nbt\tag\****Tag</code></li>
- <li><input type="checkbox" name="nbt-fqn" checked> fully-qualified
- <code>\pocketmine\nbt\tag\****Tag</code></li>
- <li><input type="checkbox" name="nbt-new" checked> <code>new ****Tag</code></li>
- <li><input type="checkbox" name="nbt-instanceof" checked> <code>instanceof ****Tag</code></li>
- </ul>
- </li>
- </ul>
- <p><input type="submit" id="upload" value="Inject" disabled></p>
- </form>
- </body>
- </html>