Esse commit está contido em:
Ad5001 2016-08-26 17:40:14 +03:00
commit bec496715e
Nenhuma chave conhecida encontrada para esta assinatura no banco de dados
ID da chave GPG: C9622754F6196EB7
11 arquivos alterados com 181 adições e 173 exclusões

6
.gitignore externo
Ver arquivo

@ -45,3 +45,9 @@ $RECYCLE.BIN/
Network Trash Folder
Temporary Items
.apdisk
# Github files, Junk files
.github
.router.php
.config.yml

7
.vscode/tasks.json externo Normal file
Ver arquivo

@ -0,0 +1,7 @@
{
"version": "0.1.0",
"command": "start",
"isShellCommand": true,
"args": ["cmd", "/C", "C:\\Program Files\\Git\\commit-signed.cmd"],
"showOutput": "always"
}

Ver arquivo

@ -1,5 +0,0 @@
<html>
<head>
<title>403 FORBIDDEN</title>
</head>
<body>Error. You don't have the peremission to view this page or to perform this action !</body>

Ver arquivo

@ -1,5 +0,0 @@
<html>
<head>
<title>404 NOT FOUND</title>
</head>
<body>Error. File not found !</body>

Ver arquivo

@ -10,10 +10,15 @@ index: index.html
403: 403.html
# Here you can config pages that user will not be able to see !
denied-pages:
- /config.yml
- /router.php
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: []
#Parked domains: Domains that redirects to one of your domains. Same setup as shown above.
Parked domains: []
# Here you can choose if the server automaticly disable itself on server stop.
# DO NOT DISABLE THIS OPTION WHEN YOU'RE USING AN HOSTER ! OR YOU WON4T BE ABLE TO STOP IT !
# DO NOT DISABLE THIS OPTION WHEN YOU'RE USING AN HOSTER ! OR YOU WON'T BE ABLE TO STOP IT !
KillOnShutdown: true

Ver arquivo

@ -10,10 +10,18 @@ index: index.html
403: 403.html
# Here you can config pages that user will not be able to see !
denied-pages:
- /config.yml
- /router.php
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:
- localhost
#Parked domains: Domains that redirects to one of your domains. Same setup as shown above.
Parked domains:
127.0.0.1: localhost
0.0.0.0: localhost
# Here you can choose if the server automaticly disable itself on server stop.
# DO NOT DISABLE THIS OPTION WHEN YOU'RE USING AN HOSTER ! OR YOU WON4T BE ABLE TO STOP IT !
# DO NOT DISABLE THIS OPTION WHEN YOU'RE USING AN HOSTER ! OR YOU WON'T BE ABLE TO STOP IT !
KillOnShutdown: true

Ver arquivo

@ -3,14 +3,66 @@
Copyright (C) Ad5001 2016 All rights reserved.
@link http://ad5001.ga
Do not attemped to modify this file if you're not sure on how it works.
This file process 404, 403 requests and custom index.
This file process 404, 403 requests, custom index and some other stuff.
*/
if(!file_exists(__DIR__ . $_SERVER["REQUEST_URI"])) {
echo file_get_contents(__DIR__ . "/" . yaml_parse(file_get_contents(__DIR__ . "/config.yml"))[404]);
} elseif($_SERVER["REQUEST_URI"] == "/") {
echo file_get_contents(__DIR__ . "/" . yaml_parse(file_get_contents(__DIR__ . "/config.yml"))["index"]);
} elseif(in_array($_SERVER["REQUEST_URI"], yaml_parse(file_get_contents(__DIR__ . "/config.yml"))["denied-pages"])) {
echo file_get_contents(__DIR__ . "/" . yaml_parse(file_get_contents(__DIR__ . "/config.yml"))[403]);
$cfg = yaml_parse(file_get_contents(__DIR__ . "/config.yml"));
$host = $_SERVER["HTTP_HOST"];
if(isset($cfg["Parked domains"][$host])) {
$host = $cfg["Parked domains"][$host];
}
if(in_array($host, $cfg["Domains"])) {
$_SERVER["REQUEST_URI"] = $host . $_SERVER["REQUEST_URI"];
} else {
return false;
unallowedDomain();
return true;
}
$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");
}
} else {
include(__DIR__ . "/" . $uri);
}
function unallowedDomain() {
echo <<<A
<html>
<head>
<style>
body {
padding: 60px;
}
div.container {
padding: 40px;
border: 3px solid white;
border-radius: 8px;
background-color: gray;
height: 70%;
}
h1, h2, h3, p {
font-family: Arial;
}
</style>
<link rel="icon" src="http://ad5001.ga/Online/icon.ico" href="http://ad5001.ga/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>
<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>
</body>
</style>
A;
}

Ver arquivo

@ -3,14 +3,66 @@
Copyright (C) Ad5001 2016 All rights reserved.
@link http://ad5001.ga
Do not attemped to modify this file if you're not sure on how it works.
This file process 404, 403 requests and custom index.
This file process 404, 403 requests, custom index and some other stuff.
*/
if(!file_exists(__DIR__ . $_SERVER["REQUEST_URI"])) {
echo file_get_contents(__DIR__ . "/" . yaml_parse(file_get_contents(__DIR__ . "/config.yml"))[404]);
} elseif($_SERVER["REQUEST_URI"] == "/") {
echo file_get_contents(__DIR__ . "/" . yaml_parse(file_get_contents(__DIR__ . "/config.yml"))["index"]);
} elseif(in_array($_SERVER["REQUEST_URI"], yaml_parse(file_get_contents(__DIR__ . "/config.yml"))["denied-pages"])) {
echo file_get_contents(__DIR__ . "/" . yaml_parse(file_get_contents(__DIR__ . "/config.yml"))[403]);
$cfg = yaml_parse(file_get_contents(__DIR__ . "/config.yml"));
$host = $_SERVER["HTTP_HOST"];
if(isset($cfg["Parked domains"][$host])) {
$host = $cfg["Parked domains"][$host];
}
if(in_array($host, $cfg["Domains"])) {
$_SERVER["REQUEST_URI"] = $host . $_SERVER["REQUEST_URI"];
} else {
return false;
unallowedDomain();
return true;
}
$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");
}
} else {
include(__DIR__ . "/" . $uri);
}
function unallowedDomain() {
echo <<<A
<html>
<head>
<style>
body {
padding: 60px;
}
div.container {
padding: 40px;
border: 3px solid white;
border-radius: 8px;
background-color: gray;
height: 70%;
}
h1, h2, h3, p {
font-family: Arial;
}
</style>
<link rel="icon" src="http://ad5001.ga/Online/icon.ico" href="http://ad5001.ga/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>
<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>
</body>
</style>
A;
}

Ver arquivo

@ -12,34 +12,51 @@ use pocketmine\Player;
class Main extends PluginBase{
public function onEnable(){
$this->saveDefaultConfig();
if(!file_exists($this->getDataFolder() . "index.html")) {
file_put_contents($this->getDataFolder() . "index.html", $this->getResource("index.html"));
}
if(!stream_resolve_include_path("router.php")) {
file_put_contents($this->getDataFolder() . "router.php", $this->getResource("handler.php"));
}
if(!file_exists($this->getDataFolder() . "404.html")) {
file_put_contents($this->getDataFolder() . "404.html", $this->getResource("404.html"));
}
if(!file_exists($this->getDataFolder() . "403.html")) {
file_put_contents($this->getDataFolder() . "403.html", $this->getResource("403.html"));
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"));
}
if(!file_exists($this->getDataFolder() .$d. "/404.html")) {
file_put_contents($this->getDataFolder() . $d . "/404.html", $this->getResource("404.html"));
}
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);
$this->port = $this->getConfig()->get("port");
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()));
// UPnP::PortForward($port); \\\\ Beta for Windows
}
public static function shutdown() {
echo "Shutdowned !";
}
public function onDisable() {
if($this->getConfig()->get("KillOnShutdown") !== "false") {
$this->getLogger()->info("Shutdowning.....");
switch(true) {
case stristr(PHP_OS, "WIN"):
exec('FOR /F "tokens=4 delims= " %P IN (\'netstat -a -n -o ^| findstr :'. $this->port .'\') DO @ECHO TaskKill.exe /PID %P');
shell_exec('FOR /F "tokens=5" %P IN (\'netstat -a -n -o ^| findstr 0.0.0.0:'. $this->port .'\') DO TaskKill.exe /F /PID %P');
$this->getLogger()->info("Shutdowned on Windows !");
break;
case stristr(PHP_OS, "DAR") or stristr(PHP_OS, "LINUX"):
shell_exec("kill -kill `lsof -t -i tcp:$this->port`");
$this->getLogger()->info("Shutdowned on Linux or MAC !");
break;
}
}

Ver arquivo

@ -1,98 +0,0 @@
<?php
namespace Ad5001\Online;
use pocketmine\Server;
use pocketmine\scheduler\AsyncTask;
use pocketmine\scheduler\Task;
use pocketmine\scheduler\ServerScheduler;
use pocketmine\event\Listener;
use pocketmine\plugin\Plugin;
use pocketmine\level\Level;
use pocketmine\block\Block;
use pocketmine\Player;
use pocketmine\utils\Config;
use pocketmine\item\Item;
use pocketmine\utils\TextFormat as C;
use pocketmine\IPlayer;
use pocketmine\math\Vector3;
class OnlineTask extends AsyncTask{
private $plugin;
private $sock;
public function __construct(Plugin $plugin, $sock, $datapath){
$this->sock = $sock;
$this->datapath = $datapath;
$this->isRunning = true;
$this->cfg = new Config($datapath . "config.yml", Config::YAML);
}
public function close() {
$this->isRunning = false;
}
public function onRun() {
$sock = $this->sock;
$client = socket_accept($sock);
$input = socket_read($client, 1024);
$incoming = explode("\r\n", $input);
$fetchArray = explode(" ", $incoming[0]);
if($fetchArray[1] == "/"){
$file = $this->cfg->get("index");
$fetchArray[1] = $this->cfg->get("index");
} else {
$filearray = [];
$filearray = explode("/", $fetchArray[1]);
$file = $fetchArray[1];
}
$output = "";
$Header = "HTTP/1.1 200 OK \r\n" .
"Date: Fri, 31 Dec 1999 23:59:59 GMT \r\n" .
"Content-Type: text/html \r\n\r\n";
$file = ltrim($file, '/');
if(strpos($file, "?")) {
$exe = explode("?", $file);
$file = $exe[0];
$exe = explode("&", $exe[1]);
}
if(file_exists($this->datapath . $file)) {
if(pathinfo($this->datapath . $file)['extension'] === "php") {
if(isset($exe[0])) {
$GET = [];
foreach($exe as $exes) {
$ex = explode("=", $exes);
array_push($GET, "\"{$ex[0]}\" => \"{$ex[1]}\"");
}
$current = '<?php
$GET = [' . implode("," . PHP_EOL, $GET) . '];
?>' . file_get_contents($this->datapath . $file);
$current = str_ireplace('$_GET', '$GET', $current);
file_put_contents($this->datapath . "current.php", $current);
$file = "current.php";
}
ob_start();
include $this->datapath . $file ;
$Content = ob_get_contents();
ob_end_clean();
} else {
$Content = file_get_contents($this->datapath . $file);
}
$Header = "HTTP/1.1 200 OK \r\n" .
"Date: Fri, 31 Dec 1999 23:59:59 GMT \r\n" .
"Content-Type: text/html \r\n\r\n";
} else {
$Header = "HTTP/1.1 404 NOT FOUND \r\n" .
"Date: Fri, 31 Dec 1999 23:59:59 GMT \r\n" .
"Content-Type: text/html \r\n\r\n";
$Content = file_get_contents($this->datapath . $this->cfg->get("404"));
}
foreach($this->cfg->get("denied-pages") as $dp) {
if($dp === $file) {
$Header = "HTTP/1.1 403 FORBIDDEN \r\n" .
"Date: Fri, 31 Dec 1999 23:59:59 GMT \r\n" .
"Content-Type: text/html \r\n\r\n";
$Content = file_get_contents($this->datapath . $this->cfg->get("403"));
}
}
$output = $Header . $Content;
socket_write($client,$output,strlen($output));
}
}

Ver arquivo

@ -1,31 +0,0 @@
<?php
namespace Ad5001\Online;
use pocketmine\Server;
use pocketmine\scheduler\PluginTask;
use pocketmine\scheduler\Task;
use pocketmine\plugin\Plugin;
use pocketmine\scheduler\ServerScheduler;
use Ad5001\Online\OnlineTask;
class isOnlineTask extends PluginTask{
private $plugin;
private $sock;
public function __construct(Plugin $plugin, $sock, $datapath){
parent::__construct($plugin);
$this->pl = $plugin;
$this->sock = $sock;
$this->datapath = $datapath;
$this->isRunning = true;
}
public function close() {
$this->isRunning = false;
}
public function onRun($tick) {
if($this->isRunning) {
socket_listen($this->sock);
$this->pl->getServer()->getScheduler()->scheduleAsyncTask(new OnlineTask($this->pl, $this->sock, $this->datapath));
}
}
}