Skip to content

Commit 48874fa

Browse files
committed
Merge pull request #18 from pmt-mcpe-me/new
New
2 parents 39f2de1 + bd49139 commit 48874fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2804
-266
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
*.phar
22
/data/data.json
33
gc_last
4-
.idea
4+
.idea/
55
!favicon.ico
66
/pg_/
77
/github*/
8+
*.zip
9+
/pmb/
10+
/nowhere/
11+

.htaccess

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ RewriteRule ^(index.php)?$ /pocketmine.php
1111
RewriteRule ^pg/viewSrc\.php/(.*)$ /pg/viewSrc.php?path=$1
1212
RewriteRule ^pg/viewSrc/(.*)$ /pg/viewSrc.php?path=$1
1313
RewriteRule ^(pg/([^\.]+)(\.[a-z]+))/.*$ /$1
14+
RewriteRule ^pmb/dl/(.+).phar$ /pmb/dl.php?branch=$1
15+
RewriteRule ^api2/.+\.phar$ /api2/
16+
RewriteCond %{REQUEST_URI} !/robots\.txt$ [nocase]
17+
RewriteRule \.txt$ - [forbidden,last]
1418

README.md

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# web-server-source
2-
pemapmodder.zapto.org source (partial)
2+
Source code for http://pmt.mcpe.me (partial)
33

44
## Requirements
5-
* PHP 5.6 (yes, and the default PHP 5 installation on Ubuntu is PHP 5.5)
5+
* At least PHP 5.6 (default PHP 5 installation on apt is PHP 5.5, make sure to install PHP 5.6 instead), PHP 7.0+ _recommended_
66
* PHP YAML extension
77
* PHP cURL extension
88
* probably other things that I forgot
99

1010
## Installation
1111
Clone this repo at the **document root** of your website. It is because some hyperlinks explicitly indicate as `/file.php`. Assuming `/var/www/html` in this page.
1212

13-
Please allow read/write access to the parent directory of the document root of the website, i.e. `/var/www`. I do that with `chmod -R www-data:www-data /var/www`.
13+
Please allow read/write access to the parent directory of the document root of the website, i.e. `/var/www`. I do that with `chown -R www-data:www-data /var/www`.
1414

15-
A GitHub service client\_id + client\_secret is required to be set up at /var/www/cid.txt and /var/www/secret.txt
15+
A GitHub service client\_id + client\_secret is required to be set up at `/var/www/cid.txt` and `/var/www/secret.txt`. The service should redirect the clien to `/insta/accessToken.php`.
1616

1717
A GitHub API access token for any valid account (without any scopes required) is required at /var/www/token.txt
1818

@@ -28,3 +28,61 @@ for the sake of security.
2828

2929
This website generates files at /var/www/html/insta/data/ without deleting them. If you find the directory too resource-consuming, please add a cronjob yourself to clean it.
3030

31+
===
32+
33+
Here is a list of PHP extensions used by the website at pmt.mcpe.me:
34+
35+
```
36+
Array
37+
(
38+
[0] => Core
39+
[1] => date
40+
[2] => ereg
41+
[3] => libxml
42+
[4] => openssl
43+
[5] => pcre
44+
[6] => zlib
45+
[7] => bcmath
46+
[8] => bz2
47+
[9] => calendar
48+
[10] => ctype
49+
[11] => dba
50+
[12] => dom
51+
[13] => hash
52+
[14] => fileinfo
53+
[15] => filter
54+
[16] => ftp
55+
[17] => gettext
56+
[18] => SPL
57+
[19] => iconv
58+
[20] => mbstring
59+
[21] => session
60+
[22] => posix
61+
[23] => Reflection
62+
[24] => standard
63+
[25] => shmop
64+
[26] => SimpleXML
65+
[27] => soap
66+
[28] => sockets
67+
[29] => Phar
68+
[30] => exif
69+
[31] => sysvmsg
70+
[32] => sysvsem
71+
[33] => sysvshm
72+
[34] => tokenizer
73+
[35] => wddx
74+
[36] => xml
75+
[37] => xmlreader
76+
[38] => xmlwriter
77+
[39] => zip
78+
[40] => apache2handler
79+
[41] => yaml
80+
[42] => Weakref
81+
[43] => PDO
82+
[44] => curl
83+
[45] => json
84+
[46] => readline
85+
[47] => mhash
86+
[48] => Zend OPcache
87+
)
88+
```

api2/index.php

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
<?php
2+
3+
const debugOn = false;
4+
5+
set_error_handler(function ($n, $msg, $file, $line){
6+
header("Content-Type: text/plain");
7+
echo "Error: $msg at $file#$line";
8+
http_response_code(500);
9+
exit;
10+
});
11+
if(isset($_FILES["phar"])){
12+
$newApi = "2.0.0";
13+
if(isset($_REQUEST["diffapi"]) and $_REQUEST["diffapi"] === "on" and isset($_REQUEST["api"])){
14+
$newApi = $_REQUEST["api"];
15+
}
16+
$path = $_FILES["phar"]["tmp_name"];
17+
$extended = $path . ".phar";
18+
move_uploaded_File($path, $extended);
19+
$phar = new Phar($extended);
20+
$phar->startBuffering();
21+
if(!isset($phar["plugin.yml"])){
22+
header("Content-Type: text/plain");
23+
echo "plugin.yml missing";
24+
exit;
25+
}
26+
$contents = file_get_contents($phar["plugin.yml"]);
27+
$yaml = yaml_parse($contents);
28+
if(!is_array($yaml["api"])){
29+
$yaml["api"] = [$yaml["api"]];
30+
}
31+
if(in_array($newApi, $yaml["api"])){
32+
header("Content-Type: text/plain");
33+
echo "API version $newApi is already declared.";
34+
exit;
35+
}
36+
$yaml["api"][] = "2.0.0";
37+
$contents = yaml_emit($yaml);
38+
$phar->addFromString("plugin.yml", $contents);
39+
40+
if(debugOn){
41+
header("Content-Type: text/plain");
42+
}
43+
44+
$replaceUse = ($_REQUEST["nbt-use"] ?? "off") === "on";
45+
$replaceFQN = ($_REQUEST["nbt-fqn"] ?? "off") === "on";
46+
$replaceNew = ($_REQUEST["nbt-new"] ?? "off") === "on";
47+
$replaceInstanceOf = ($_REQUEST["nbt-instanceof"] ?? "off") === "on";
48+
if($replaceUse or $replaceFQN or $replaceNew or $replaceInstanceOf){
49+
$refactorTable = [
50+
"ByteArray" => "ByteArrayTag",
51+
"Byte" => "ByteTag",
52+
"Compound" => "CompoundTag",
53+
"Double" => "DoubleTag",
54+
"End" => "EndTag",
55+
"Float" => "FloatTag",
56+
"IntArray" => "IntArrayTag",
57+
"Int" => "IntTag",
58+
"Enum" => "ListTag",
59+
"Long" => "LongTag",
60+
"Short" => "ShortTag",
61+
"String" => "StringTag",
62+
];
63+
foreach(new \RecursiveIteratorIterator($phar) as $localName => $file){
64+
$fn = $file->getFileName();
65+
$localName = substr($localName, 8 + strlen($extended));
66+
if(substr($fn, -4) === ".php"){
67+
$c = $o = file_get_contents($file->getPathName());
68+
if($replaceUse){
69+
$ns = "pocketmine\\nbt\\tag\\";
70+
$quotedNs = preg_quote($ns);
71+
$names = implode("|", array_map("preg_quote", array_keys($refactorTable)));
72+
$c = preg_replace_callback("/use[ \t\n\r]+$quotedNs($names)[ \t\n\r]*;/i", function ($match) use ($ns, $refactorTable){
73+
return "use $ns" . $refactorTable[$match[1]] . ";";
74+
}, $c);
75+
}
76+
if($replaceFQN){
77+
foreach($refactorTable as $from => $to){
78+
$from = "\\pocketmine\\nbt\\tag\\$from";
79+
$to = "\\pocketmine\\nbt\\tag\\$to";
80+
$c = str_replace($from, $to, $c);
81+
}
82+
}
83+
if($replaceNew){
84+
$ns = "pocketmine\\nbt\\tag\\";
85+
$quotedNs = preg_quote($ns);
86+
$names = implode("|", array_map("preg_quote", array_keys($refactorTable)));
87+
$c = preg_replace_callback("/new[ \t\n\r]+($names)[ \t\n\r]*([\(\);,])/i", function ($match) use ($ns, $refactorTable){
88+
return "new " . $refactorTable[$match[1]] . $match[2];
89+
}, $c);
90+
}
91+
if($replaceInstanceOf){
92+
$ns = "pocketmine\\nbt\\tag\\";
93+
$quotedNs = preg_quote($ns);
94+
$names = implode("|", array_map("preg_quote", array_keys($refactorTable)));
95+
$c = preg_replace_callback("/instanceof[ \t\n\r]+$quotedNs($names)/i", function ($match) use ($ns, $refactorTable){
96+
return "instanceof " . $refactorTable[$match[1]];
97+
}, $c);
98+
}
99+
if(debugOn){
100+
echo $localName, " ($fn):\n", $c, "\n\n";
101+
}
102+
if($c !== $o){
103+
$phar->addFromString($localName, $c);
104+
}
105+
}
106+
}
107+
}
108+
109+
$phar->stopBuffering();
110+
if(debugOn){
111+
echo base64_encode(file_get_contents($extended));
112+
die;
113+
}
114+
header("Content-Type: application/octet-stream");
115+
echo file_get_contents($extended);
116+
exit;
117+
}
118+
?>
119+
<html>
120+
<head>
121+
<title>Plugin API version bumper</title>
122+
</head>
123+
<body>
124+
<h1>API 2.0.0 injection</h1>
125+
<p>Before using this tool, please carefully read the following caution:</p>
126+
<ul>
127+
<li>This tool only <em>forces</em> the plugin to say that it supports API 2.0.0 (PHP 7 update), and optionally,
128+
blindly replaces some specific backwards-incompatible changes in the phar. It will not fix the actual
129+
incompatibility issues.
130+
</li>
131+
<li>If errors happen after using phars downloaded from this page, unintsall it immediately.</li>
132+
<li>Click <span
133+
onclick='alert("Thanks for carefully reading the caution!"); document.getElementById("upload").disabled = false;'>these three words</span>
134+
if you have read the above.
135+
</li>
136+
</ul>
137+
<hr>
138+
<form action="updated.phar" method="post" enctype="multipart/form-data">
139+
<p><input type="file" name="phar"></p>
140+
<ul>
141+
<li>
142+
<input type="checkbox" name="diffapi" onclick='document.getElementById("apiInput").disabled = false;'> No, I
143+
don't want API <code>2.0.0</code>.
144+
I want something else: <input id="apiInput" type="text" name="api" value="2.0.0" disabled>
145+
</li>
146+
<li>
147+
Replace the following usage of NBT tags:
148+
<ul>
149+
<li><input type="checkbox" name="nbt-use" checked> <code>use pocketmine\nbt\tag\****Tag</code></li>
150+
<li><input type="checkbox" name="nbt-fqn" checked> fully-qualified
151+
<code>\pocketmine\nbt\tag\****Tag</code></li>
152+
<li><input type="checkbox" name="nbt-new" checked> <code>new ****Tag</code></li>
153+
<li><input type="checkbox" name="nbt-instanceof" checked> <code>instanceof ****Tag</code></li>
154+
</ul>
155+
</li>
156+
</ul>
157+
<p><input type="submit" id="upload" value="Inject" disabled></p>
158+
</form>
159+
</body>
160+
</html>
161+

0 commit comments

Comments
 (0)