1.4 starting...
Just have to add an handler.
This commit is contained in:
parent
1db1810c7d
commit
335007df2b
9 changed files with 88 additions and 27 deletions
5
403.html
Normal file
5
403.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
<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>
|
5
404.html
Normal file
5
404.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>404 NOT FOUND</title>
|
||||
</head>
|
||||
<body>Error. File not found !</body>
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#This define the port that your website that will run.
|
||||
#****NOTE THAT YOU WILL NEED TO RE-PORTFOREWARD WITH THE NEW PORT****
|
||||
port: 8080
|
||||
port: 80
|
||||
|
||||
# Here you can choose the pages !
|
||||
index: index.html
|
||||
|
@ -11,7 +11,4 @@ index: index.html
|
|||
|
||||
# Here you can config pages that user will not be able to see !
|
||||
denied-pages:
|
||||
- config.yml
|
||||
|
||||
# Here you can configure the refresh in tick (20 tick = 1s)
|
||||
TimePerConnection: 20
|
||||
- /config.yml
|
8
index.html
Normal file
8
index.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<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>
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
name: Online
|
||||
author: Ad5001
|
||||
version: 1.1
|
||||
version: 1.4
|
||||
api: [2.0.0]
|
||||
main: Ad5001\Online\Main
|
||||
commands: []
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#This define the port that your website that will run.
|
||||
#****NOTE THAT YOU WILL NEED TO RE-PORTFOREWARD WITH THE NEW PORT****
|
||||
port: 8080
|
||||
port: 80
|
||||
|
||||
# Here you can choose the pages !
|
||||
index: index.html
|
||||
|
@ -11,4 +11,5 @@ index: index.html
|
|||
|
||||
# Here you can config pages that user will not be able to see !
|
||||
denied-pages:
|
||||
- /config..yml
|
||||
- /config.yml
|
||||
- /router.php
|
16
resources/handler.php
Normal file
16
resources/handler.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
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]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
16
router.php
Normal file
16
router.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
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]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
|
@ -4,22 +4,20 @@ use pocketmine\command\CommandSender;
|
|||
use pocketmine\command\Command;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\plugin\PluginBase;
|
||||
use pocketmine\network\upnp\UPnP;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\Player;
|
||||
|
||||
use Ad5001\Online\OnlineTask;
|
||||
|
||||
|
||||
class Main extends PluginBase{
|
||||
public function onDisable() {
|
||||
$this->socket->close();
|
||||
}
|
||||
public function onEnable(){
|
||||
// $this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||
$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"));
|
||||
}
|
||||
|
@ -31,17 +29,32 @@ set_time_limit(0);
|
|||
$address = '0.0.0.0';
|
||||
$port = $this->getConfig()->get("port");
|
||||
|
||||
$sock = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
|
||||
$result = socket_bind($sock, $address, $port) or die('Could not bind to address');
|
||||
$this->getLogger()->info("Website open in port §a" . $port);
|
||||
$this->getServer()->getScheduler()->scheduleAsyncTask(new execTask($this->getServer()->getFilePath()));
|
||||
// UPnP::PortForward($port); \\\\ Beta for Windows
|
||||
}
|
||||
}
|
||||
|
||||
$this->socket = new isOnlineTask($this, $sock, $this->getDataFolder());
|
||||
$this->getServer()->getScheduler()->scheduleRepeatingTask($this->socket, $this->getConfig()->get("TimePerConnection"));
|
||||
$this->sock = $sock;
|
||||
class execTask extends \pocketmine\scheduler\AsyncTask {
|
||||
|
||||
public function __construct(string $path) {
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
public function onRun() {
|
||||
$address = '0.0.0.0';
|
||||
$port = yaml_parse(file_get_contents("plugins\\Online\\config.yml"))["port"];
|
||||
// shell_exec("cd plugins/Online");
|
||||
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 "Online Listener" 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"');
|
||||
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");
|
||||
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");
|
||||
break;
|
||||
}
|
||||
public function onCommand(CommandSender $issuer, Command $cmd, $label, array $params){
|
||||
switch($cmd->getName()){
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue