Skip to content

Instantly share code, notes, and snippets.

@PEMapModder
Last active January 25, 2016 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PEMapModder/60d2e90ac744eeea774e to your computer and use it in GitHub Desktop.
Save PEMapModder/60d2e90ac744eeea774e to your computer and use it in GitHub Desktop.
pmt.mcpe.me "pmt" property

In the future, if users are converting phars into zips via pmt.mcpe.me, developers can require the users to agree with their terms before downloading the extraction.

The terms are composed of two parts, namely "lock" and "key". When a user clicked the Convert button of the webpage submitting a phar that requires agreeing with terms, he will get a prompt that shows the content of the "lock". To continue and download the zip, he has to enter the "key" into the prompt.

There are currently three simple ways to add lock-and-key into your phar:

plugin.yml

If your plugin is compiled with pmt.mcpe.me, you can add this into your plugin.yml:

me.mcpe.pmt:
  agree:
    lock: "Do not redistribute this phar! Type 'ok' to continue."
    key: ok

If you omit key, Type "yes" if you agree with the above terms to continue will be automatically appended to the lock and the key will be yes.

terms.php

Run the terms.php in this gist with php, with the following parameters:

  • --phar
    • A relative or absolute path to your phar file
  • --lock (optional)
    • Path to a file whose contents are the lock to use, or php://stdin for STDIN. If not provided, the user will be prompted to enter that during the script run.
  • --key (optional)
    • The key itself. If not provided, Type "yes" if you agree with the above terms to continue will be automatically appended to the lock and the key will be yes.

php -r

Run a simple PHP script that updates the metadata of your phar:

php -r '$phar = new Phar("my.phar");
$phar->startBuffering();
$metadata = $phar->getMetadata();
$metadata["me.mcpe.pmt"] = [
  "agree" => [
    "lock" => "The lock here",
    " key" => "The key here"
  ]
];
$phar->setMetadata($metadata);
$phar->stopBuffering();'

You can also omit key, and same rules as above if you do so.

Support

If you need help, please contact @PEMapModder_Flw on Twitter. If you found out a bug, please create an issue at https://github.com/PEMapModder/web-server-source

#!/usr/bin/env php
<?php
echo "\r[*] Starting pmt.mcpe.me lock-and-key injector for phar files...", PHP_EOL;
if(!defined("STDIN")){
define("STDIN", fopen("php://stdin", "rt"));
}
if(((string) ini_get("phar.readonly")) != "0"){
echo "[!] Fatal: Please run this script with -dphar.readonly=0", PHP_EOL;
die(2);
}
$opts = getopt("", ["phar:", "lock::", "key::"];
if(!isset($opts["phar"])){
echo "[!] Fatal: Please provide the --phar argument", PHP_EOL;
die(2);
}
if(!is_file($pharFile = $opts["phar"])){
echo "[!] Fatal: $pharFile is not a file.", PHP_EOL;
die(2);
}
try{
echo "[*] Checking phar file...", PHP_EOL;
$phar = new Phar($pharFile);
}catch(\PharException $e){
echo "[!] Fatal phar error: ", $e->getMessage(), PHP_EOL;
die(2);
}
if(isset($opts["lock"])){
$lock = @file_get_contents($lock = $opts["lock"]);
if($lock === false){
echo "[!] Fatal: cannot read from $lock", PHP_EOL;
die(2);
}
}else{
echo "[?] Please enter the lock (It can only contain one line. If you want to use multiple lines, type \\n at line breaks): ";
$lock = str_replace("\\n", "\n", trim(fgets(STDIN)));
}
$phar->startBuffering();
$agree = ["lock" => $lock];
if(isset($opts["key"])){
$agree["key"] = $opts["key"];
}
$md = $phar->getMetadata();
$md["me.mcpe.pmt"]["agree"] = $agree;
$phar->setMetadata($md);
$phar->stopBuffering();
echo "[*] Injected lock and key.", PHP_EOL;
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment