Skip to content

Commit 8a0b0fc

Browse files
committed
Added lock&key for phars
1 parent bdb3dc4 commit 8a0b0fc

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ gc_last
55
!favicon.ico
66
/pg_/
77
/github*/
8+
*.zip

functions.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,12 @@ function unphar_toZip($tmpName, &$result, $name = ""){
461461
$rel = substr($file, strlen($tmpDir) + 1);
462462
$zip->addFile($file, str_replace("\\", "/", $rel));
463463
}
464-
$zip->setArchiveComment(json_encode($phar->getMetadata(), JSON_PRETTY_PRINT));
464+
$metadata = $phar->getMetadata();
465+
if(isset($metadata["me.mcpe.pmt"])){
466+
$result["pmt"] = $metadata["me.mcpe.pmt"];
467+
$metadata["me.mcpe.pmt"] = "<pmt.mcpe.me metadata hidden>";
468+
}
469+
$zip->setArchiveComment(json_encode($phar->getMetadata(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
465470
$zip->close();
466471
}
467472
catch(Exception $e){

unpharResult.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
<?php
22
include "functions.php";
33
?><html>
4-
<head><title>Phar extraction result</title></head>
5-
<body><font face="Comic Sans MS">
4+
<head>
5+
<title>Phar extraction result</title>
6+
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
7+
<script>
8+
$(document).ready(function(){
9+
var dl = $("#dlButton");
10+
if(typeof pmt.agree.lock !== typeof undefined){
11+
var agreeKey = "yes";
12+
if(typeof pmt.agree.key !== typeof undefined){
13+
agreeKey = pmt.agree.key;
14+
}else{
15+
agreeLock += "\nType \"yes\" if you agree with the above terms to continue";
16+
}
17+
if(prompt(pmt.agree.lock).toLowerCase() != agreeKey.toLowerCase()){
18+
alert("You must agree with the terms to download the zip!");
19+
window.location.replace("/unphar.php");
20+
return;
21+
}
22+
}
23+
dl.css("display", "block");
24+
});
25+
</script>
26+
</head>
27+
<body><font face="Helvetica">
628
<?php
729
if(!isset($_FILES["file"])){
830
http_response_code(400);
@@ -42,20 +64,23 @@
4264
goto end;
4365
}
4466
unphar_toZip($file["tmp_name"], $result, substr($file["name"], 0, -5));
67+
$pmt = [];
4568
/** @var string|null $tmpDir */
4669
/** @var string|null $zipPath */
4770
/** @var string|null $zipRelativePath */
4871
/** @var string|null $basename */
4972
/** @var bool $error */
5073
extract($result);
74+
if(!is_array($pmt)) $pmt = [];
5175
if($error){
5276
goto end;
5377
}
5478
usage_inc("unphar", $timestamp);
79+
echo "<script>var pmt = " + json_encode($pmt) + ";</script>";
5580
echo <<<EOS
5681
<h1>Success</h1>
5782
<p>Phar has been successfully converted to zip.<br>
58-
Download the ZIP file <a href="$zipRelativePath">here</a>, or download with an alternative name:</p>
83+
Download the ZIP file <a id="dlButton" href="$zipRelativePath">here</a>, or download with an alternative name:</p>
5984
<p><i><font color="#2f4f4f">The altname download is currently not available.</font></i></p>
6085
<!--<iframe width="500" src="/data/dlPhar.php?path=$basename"></iframe>-->
6186
<p>The download link is available for <i>at least</i> <b>2 hours</b>.</p>

0 commit comments

Comments
 (0)