1.6 IS WORKING? WANNA TRY IT OUT?

This commit is contained in:
Ad5001 2016-12-27 15:19:49 +01:00
parent a5835e3b4b
commit 520f4f8115
5 changed files with 269 additions and 82 deletions

View file

@ -13,10 +13,11 @@ index: index.html
denied-pages: []
# Your domains (one per time). To redirect a domain here, put one per line then go to your registar CPanel and add a CName record that redirects to it !
Domains: []
Domains: ["localhost"]
#Parked domains: Domains that redirects to one of your domains. Same setup as shown above.
Parked domains: []
Parked domains:
127.0.0.1: localhost
# Here you can choose if the server automaticly disable itself on server stop.

View file

@ -1,8 +0,0 @@
<html>
<head>
<title>Welcome to your new website !</title>
</head>
<body>
<h3>Welcome to your new website ! You can edit it in your new folder !</h3>
</body>
</html>

View file

@ -2,9 +2,10 @@
name: Online
author: Ad5001
version: 1.6
api: [2.0.0]
api: [2.0.0, 3.0.0, 3.0.0-ALPHA1, 3.0.0-ALPHA2, 3.0.0-ALPHA3,]
description: "You're own website, on PocketMine.'"
main: Ad5001\Online\Main
load: STARTUP
commands: []
permissions: []
...

View file

@ -5,7 +5,26 @@ Copyright (C) Ad5001 2016 All rights reserved.
Do not attemped to modify this file if you're not sure on how it works.
This file process 404, 403 requests, custom index and some other stuff.
*/
$cfg = yaml_parse(file_get_contents(__DIR__ . "/config.yml"));
// Definitions
$cfg = yaml_parse(file_get_contents(__DIR__ . "/../config.yml"));
$args = json_decode(file_get_contents(__DIR__ . "/args"), true);
$_POCKETMINE = $args["POCKETMINE"];
$_PLUGINS = $args["PLUGINS"];
$_PLAYERS = $args["PLAYERS"];
$_LEVELS = $args["LEVELS"];
// Calling handlers.
foreach($args["HANDLERS"] as $handler) {
// echo $handler;
if((include $handler) == false) {
return true;
}
}
// Domains parsing
$host = $_SERVER["HTTP_HOST"];
if(isset($cfg["Parked domains"][$host])) {
$host = $cfg["Parked domains"][$host];
@ -16,21 +35,27 @@ if(in_array($host, $cfg["Domains"])) {
unallowedDomain();
return true;
}
// Removing GET from the request
$uri = $_SERVER["REQUEST_URI"];
if(strpos($uri, "?") !== false) {
$uri = explode("?", $uri)[0];
}
if(!file_exists(__DIR__ . "/" . $uri)) {
echo file_get_contents(__DIR__ . "/" . $host . "/" . $cfg[404]);
} elseif(in_array($uri, yaml_parse(file_get_contents(__DIR__ . "/config.yml"))["denied-pages"])) {
echo file_get_contents(__DIR__ . "/" . $host . "/" . $cfg[403]);
} elseif(is_dir(__DIR__ . "/" .$uri)) {
if(file_exists(__DIR__ . "/" . $uri . "index.html")) {
include(__DIR__ . "/" . $uri . "index.html");
} elseif(file_exists(__DIR__ . "/" . $uri . "index.php")) {
include(__DIR__ . "/" . $uri . "index.php");
} elseif(file_exists(__DIR__ . "/" . $uri . $cfg["index"])) {
include(__DIR__ . "/" . $uri . $cfg["index"]);
// Getting the file & output it if possible.
if(!file_exists(__DIR__ . "/../" . $uri)) {
echo file_get_contents(__DIR__ . "/../" . $host . "/" . $cfg[404]);
} elseif(in_array($uri, $cfg["denied-pages"])) {
echo file_get_contents(__DIR__ . "/../" . $host . "/" . $cfg[403]);
} elseif(is_dir(__DIR__ . "/../" .$uri)) {
if(file_exists(__DIR__ . "/../" . $uri . "index.html")) {
include(__DIR__ . "/../" . $uri . "index.html");
} elseif(file_exists(__DIR__ . "/../" . $uri . "index.php")) {
include(__DIR__ . "/../" . $uri . "index.php");
} elseif(file_exists(__DIR__ . "/../" . $uri . $cfg["index"])) {
include(__DIR__ . "/../" . $uri . $cfg["index"]);
}
} else {
include(__DIR__ . "/" . $uri);
@ -42,28 +67,29 @@ function unallowedDomain() {
echo <<<A
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed:300" rel="stylesheet">
<style>
body {
padding: 60px;
}
div.container {
padding: 40px;
border: 3px solid white;
border: 3px solid lightgray;
border-radius: 8px;
background-color: gray;
background: linear-gradient(45deg, gray, grey);
height: 70%;
}
h1, h2, h3, p {
font-family: Arial;
font-family: 'Roboto Condensed', sans-serif;
}
</style>
<link rel="icon" src="http://ad5001.ga/Online/icon.ico" href="http://ad5001.ga/Online/icon.ico" />
<link rel="icon" src="http://serveur.cf/Online/icon.ico" href="http://serveur.cf/Online/icon.ico" />
</head>
<body>
<div class="container">
<h1><img src="http://ad5001.ga/Online/icon.png" style="width: 30px; height: 30px;"></img>Unallowed domain</h1><hr>
<h1><img src="http://serveur.cf/Online/icon.png" style="width: 30px; height: 30px;"></img>Unallowed domain</h1><hr>
<p>This IP does not have any domain on this machine. Please refer to your server administartor if you think it's an error.</p>
<h2 style="float: right;"><a href="http://projects.ad5001.ga/Online">Online 1.5 - Eclipse edition</a></h2>
<h2 style="float: right;">Online 1.6 - Eclipse edition</a></h2>
</body>
</style>
A;

View file

@ -10,13 +10,25 @@ use pocketmine\Player;
class Main extends PluginBase{
public function onEnable(){
$this->saveDefaultConfig();
if(!stream_resolve_include_path("router.php")) {
file_put_contents($this->getDataFolder() . "router.php", $this->getResource("handler.php"));
}
foreach($this->getConfig()->get("Domains") as $d) {
protected $handlers;
protected $arguments;
public function onEnable(){
$this->saveDefaultConfig();
$this->handlers = [];
$this->arguments = [];
$this->getServer()->getScheduler()->scheduleRepeatingTask($task = new ArgFillTask($this), 20*10);
@mkdir($this->getDataFolder() . "tmp");
$task->onRun(0);
if(!file_exists($this->getDataFolder() . "tmp/router.php")) {
file_put_contents($this->getDataFolder() . "tmp/router.php", $this->getResource("handler.php"));
}
foreach($this->getConfig()->get("Domains") as $d) {
@mkdir($this->getDataFolder() . $d);
if(!file_exists($this->getDataFolder() . $d . "/index.html") and !file_exists($this->getDataFolder() . $d . "/index.php")) {
file_put_contents($this->getDataFolder() .$d. "/index.html", $this->getResource("index.html"));
@ -27,26 +39,21 @@ foreach($this->getConfig()->get("Domains") as $d) {
if(!file_exists($this->getDataFolder() . $d . "/403.html")) {
file_put_contents($this->getDataFolder() .$d . "/403.html", $this->getResource("403.html"));
}
}
}
register_shutdown_function("Ad5001\\Online\\Main::shutdown");
set_time_limit(0);
set_time_limit(0);
$this->port = $this->getConfig()->get("port");
$this->port = $this->getConfig()->get("port");
if(!UPnP::PortForward($this->port)) {// Beta for Windows
if(!UPnP::PortForward($this->port)) {// Beta for Windows
$this->getLogger()->info("Not able to port forward!");
}
}
$this->getServer()->getScheduler()->scheduleAsyncTask(new execTask($this->getServer()->getFilePath()));
}
$this->getServer()->getScheduler()->scheduleAsyncTask(new execTask($this->getServer()->getFilePath()));
}
public static function shutdown() {
echo "Shutdowned !";
}
public function onDisable() {
public function onDisable() {
if($this->getConfig()->get("KillOnShutdown") !== "false") {
$this->getLogger()->info("Shutdowning.....");
switch(true) {
@ -60,9 +67,61 @@ public function onDisable() {
break;
}
}
}
/*
Adds a PHP handler
@param $path string
@return bool
*/
public function addHandler(string $path) : bool {
if(file_exists($path)) {
$this->handlers[$path] = $path;
return true;
}
return false;
}
/*
Return an array with all handlers
@return array
*/
public function getHandlers() : array {
return $this->handlers;
}
/*
Sets a plugin argument
@param $plugin \pocketmine\plugin\Plugin
@param $id string
@param $value mixed
@return bool
*/
public function setArgument(\pocketmine\plugin\Plugin $plugin, string $id, $value) : bool {
if(!isset($this->arguments[$plugin->getName()])) $this->arguments[$plugin->getName()] = [];
$this->arguments[$plugin->getName()][$id] = $value;
return true;
}
/*
Gets a plugin arguments
@param $plugin \pocketmine\plugin\Plugin
@return array
*/
public function getArguments(\pocketmine\plugin\Plugin $plugin) : array {
return isset($this->arguments[$plugin->getName()]) ? $this->arguments[$plugin->getName()] : [];
}
}
}
/**
* Setting rguments for the pocketine infos
@ -74,8 +133,9 @@ class ArgFillTask extends \pocketmine\scheduler\PluginTask {
@param $main Main
*/
public function __construct(Main $main) {
parent::__construct($main);
$this->main = $main;
$this->server = $server;
$this->server = $main->getServer();
}
/*
@ -83,14 +143,121 @@ class ArgFillTask extends \pocketmine\scheduler\PluginTask {
@param $tick mixed
*/
public function onRun($tick) {
$args = [];
$server = $this->server;
$pmargs = [];
$pluginsargs = [];
$players = [];
$levels = [];
// Filling the arguments
// 1. Pocketmine
$pmargs["software_name"] = $server->getName();
$pmargs["software_codename"] = $server->getCodename();
$pmargs["software_version"] = $server->getPocketmineVersion();
$pmargs["mcpe_version"] = $server->getVersion();
$pmargs["API"] = $server->getApiVersion();
$pmargs["software_datapath"] = $server->getDataPath();
$pmargs["software_pluginpath"] = $server->getPluginPath();
$pmargs["max_players"] = $server->getMaxPlayers();
$pmargs["port"] = $server->getPort();
$pmargs["view_distance"] = $server->getViewDistance();
$pmargs["ip"] = $server->getIp();
$pmargs["server_unique_id"] = $server->getServerUniqueId();
$pmargs["auto_save"] = $server->getAutoSave();
$pmargs["default_gamemode"] = $server->getGamemode();
$pmargs["force_gamemode"] = $server->getForceGamemode();
$pmargs["difficulty"] = $server->getDifficulty();
$pmargs["spawn_radius"] = $server->getSpawnRadius();
$pmargs["allow_flight"] = $server->getAllowFlight();
$pmargs["ultra_hardcore"] = $server->isHardcore();
$pmargs["motd"] = $server->getMotd();
$pmargs["tps"] = $server->getTicksPerSecond();
$pmargs["lang_name"] = $server->getLanguage()->getName();
$pmargs["lang_code"] = $server->getLanguage()->getLang();
// 2. Plugins
foreach($server->getPluginManager()->getPlugins() as $plugin) {
$pl = [];
$pl["name"] = $plugin->getName();
$pl["is_enabled"] = $plugin->isEnabled();
$pl["data_folder"] = $plugin->getDataFolder();
$pl["apis"] = $plugin->getDescription()->getCompatibleApis();
$pl["authors"] = $plugin->getDescription()->getAuthors();
$pl["prefix"] = $plugin->getDescription()->getPrefix();
$pl["commands"] = $plugin->getDescription()->getCommands();
$pl["dependencies"] = $plugin->getDescription()->getDepend();
$pl["description"] = $plugin->getDescription()->getDescription();
$pl["load_before"] = $plugin->getDescription()->getLoadBefore();
$pl["main"] = $plugin->getDescription()->getMain();
$pl["order"] = $plugin->getDescription()->getOrder();
$pl["soft_depend"] = $plugin->getDescription()->getSoftDepend();
$pl["version"] = $plugin->getDescription()->getVersion();
$pl["website"] = $plugin->getDescription()->getWebsite();
foreach($this->main->getArguments($plugin) as $name => $arg) {
if(!isset($pl[$name])) {
$pl[$name] = $arg;
}
}
$pluginsargs[$plugin->getName()] = $pl;
}
// 3. Players
foreach ($server->getOnlinePlayers() as $player) {
$pl = [];
$pl["client_secret"] = $player->getClientSecret();
$pl["banned"] = $player->isBanned(); // I don't know if tis could be to false but we never know xD
$pl["whitelisted"] = $player->isWhitelisted();
$pl["client_secret"] = $player->getClientSecret();
$pl["first_played"] = $player->getFirstPlayed();
$pl["last_played"] = $player->getLastPlayed();
$pl["played_before"] = $player->hasPlayedBefore();
$pl["allow_flight"] = $player->getAllowFlight();
$pl["flying"] = $player->isFlying();
$pl["auto_jump"] = $player->hasAutoJump();
$pl["op"] = $player->isOp();
$pl["connected"] = $player->isConnected();
$pl["display_name"] = $player->getDisplayName();
$pl["ip"] = $player->getAddress();
$pl["port"] = $player->getPort();
$pl["is_sleeping"] = $player->isSleeping();
$pl["ticks_in_air"] = $player->getInAirTicks();
$pl["gamemode"] = $player->getGamemode();
$pl["name"] = $player->getName();
$pl["loader_id"] = $player->getLoaderId();
$players[$player->getName()] = $pl;
}
// 4.Levels
foreach ($server->getLevels() as $level) {
$lvl = [];
$lvl["tick_rate"] = $level->getTickRate();
$lvl["id"] = $level->getId();
$lvl["auto_save"] = $level->getAutoSave();
$lvl["tick_rate"] = $level->getTickRate();
$lvl["players"] = [];
foreach ($level->getPlayers() as $pl) {
$lvl["players"][$pl->getName()] = $players[$pl->getName()];
}
$lvl["time"] = $level->getTime();
$lvl["name"] = $level->getName();
$lvl["folder_name"] = $level->getFolderName();
$lvl["seed"] = $level->getSeed();
$levels[$lvl["name"]] = $lvl;
}
file_put_contents($this->main->getDataFolder() . "tmp/args", json_encode(["POCKETMINE" => $pmargs, "PLUGINS" => $pluginsargs, "PLAYERS" => $players, "LEVELS" => $levels, "HANDLERS" => $this->main->getHandlers()]));
}
}
class execTask extends \pocketmine\scheduler\AsyncTask {
public function __construct(string $path) {
@ -103,13 +270,13 @@ class execTask extends \pocketmine\scheduler\AsyncTask {
switch(true) {
case stristr(PHP_OS, "WIN"):
// echo '"%CD%\\bin\\php\\php.exe -t %CD%\\plugins\\Online -n -d include_path=\'%CD%\\plugins\\Online\\\' -S ' . $address . ":" . $port . ' -f %CD%\\plugins\\Online\\router.php"';
shell_exec('start /MIN cmd /c "%CD%\\bin\\php\\php.exe -t %CD%\\plugins\\Online -n -d include_path=\'%CD%\\plugins\\Online\\\' -d extension=\'%CD%\\bin\\php\\ext\\php_yaml.dll\' -S ' . $address . ":" . $port . ' router.php"');
shell_exec('start /MIN cmd /c "%CD%\\bin\\php\\php.exe -t %CD%\\plugins\\Online -n -d include_path=\'%CD%\\plugins\\Online\\\' -d extension=\'%CD%\\bin\\php\\ext\\php_yaml.dll\' -S ' . $address . ":" . $port . ' tmp/router.php"');
break;
case stristr(PHP_OS, "DAR"):
shell_exec('open -a Terminal "' . $this->path . "bin\\php\\php.exe -t " . $this->path . "plugins\\Online -n -d include_path=\'" . $this->path . "plugins\\Online\\\' -d extension=\'" . $this->path . "bin\\php\\ext\\php_yaml.dll\' -S " . $address . ":" . $port . ' router.php"');
shell_exec('open -a Terminal php -t ' . $this->path . "plugins\\Online -n -d include_path=\'" . $this->path . "plugins\\Online\\\' -d extension=\'" . $this->path . "bin\\php\\ext\\php_yaml.dll\' -S " . $address . ":" . $port . ' tmp/router.php"');
break;
case stristr(PHP_OS, "LINUX"):
shell_exec('gnome-terminal -e "' . $this->path . "bin\\php\\php.exe -t " . $this->path . "plugins\\Online -n -d include_path=\'" . $this->path . "plugins\\Online\\\' -d extension=\'" . $this->path . "bin\\php\\ext\\php_yaml.dll\' -S " . $address . ":" . $port . ' router.php"');
shell_exec('gnome-terminal -e php -t ' . $this->path . "plugins\\Online -n -d include_path=\'" . $this->path . "plugins\\Online\\\' -d extension=\'" . $this->path . "bin\\php\\ext\\php_yaml.dll\' -S " . $address . ":" . $port . ' tmp/router.php"');
break;
}
}