From 4d0aa7ef1ed4ed9234e4b9f7bf8e1e6d4f950083 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Mon, 30 May 2016 19:06:31 +0200 Subject: [PATCH] Moving forward ! Fixing some issues in the config + processing PHP --- config.yml | 5 +- hey.php | 2 + im.php | 3 + index.html | 235 +++++++++++++++++++++++++++++ src/Ad5001/Online/Main.php | 5 +- src/Ad5001/Online/OnlineTask.php | 40 +++-- src/Ad5001/Online/isOnlineTask.php | 31 ++++ 7 files changed, 304 insertions(+), 17 deletions(-) create mode 100644 hey.php create mode 100644 im.php create mode 100644 index.html create mode 100644 src/Ad5001/Online/isOnlineTask.php diff --git a/config.yml b/config.yml index f542ada..6c78ef3 100644 --- a/config.yml +++ b/config.yml @@ -11,4 +11,7 @@ index: index.html # Here you can config pages that user will not be able to see ! denied-pages: - - /config..yml/ \ No newline at end of file + - config.yml + + # Here you can configure the refresh in tick (20 tick = 1s) +TimePerConnection: 20 \ No newline at end of file diff --git a/hey.php b/hey.php new file mode 100644 index 0000000..1d4f555 --- /dev/null +++ b/hey.php @@ -0,0 +1,2 @@ + +<?php echo "hey"; ?> \ No newline at end of file diff --git a/im.php b/im.php new file mode 100644 index 0000000..05bb92b --- /dev/null +++ b/im.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..419b596 --- /dev/null +++ b/index.html @@ -0,0 +1,235 @@ + + + + + + BoxOfDevs + + + + + + + + + + + + + + + + + +
+
+
+

Consectetur adipisicing elit

+

Lorem ipsum dolor sit amet, delectus consequatur, similique quia!

+
+
+
+
+ +

Lorem ipsum dolor

+

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Enim quam consectetur quibusdam magni minus aut modi aliquid.

+
+
+
+
+ +

Consectetur adipisicing

+

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium ullam consequatur repellat debitis maxime.

+
+
+
+
+ +

Adipisicing elit totam

+

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque eaque eveniet, nesciunt molestias. Ipsam, voluptate vero.

+
+
+
+
+
+ + +
+
+
+

Lorem ipsum dolor sit

+

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Distinctio, autem.

+
+
+
+
+ +

Lorem ipsum

+

Lorem ipsum dolor

+
+
+ +

Voluptatem dolores

+

Ullam nihil repudi

+
+
+ +

Doloremque quo

+

Harum corrupti quia

+
+
+ +

Voluptatem dicta

+

Et natus sapiente

+
+
+
+
+

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam dolore illum, temporibus veritatis eligendi, aliquam, dolor enim itaque veniam aut eaque sequi qui quia vitae pariatur repudiandae ab dignissimos ex!

+ +
+
+
+ + +
+
+
+

Consectetur adipisicing elit

+

Lorem ipsum dolor sit amet. Delectus consequatur, similique quia!

+
+
+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
    +
  • +
+
+
+
+
+
+ + + + + + diff --git a/src/Ad5001/Online/Main.php b/src/Ad5001/Online/Main.php index b09aa8e..d1c2348 100644 --- a/src/Ad5001/Online/Main.php +++ b/src/Ad5001/Online/Main.php @@ -13,7 +13,6 @@ use pocketmine\Server; class Main extends PluginBase{ public function onDisable() { $this->socket->close(); - socket_shutdown($this->sock, 2); } public function onEnable(){ // $this->getServer()->getPluginManager()->registerEvents($this, $this); @@ -35,8 +34,8 @@ $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->socket = new OnlineTask($this, $sock, $this->getDataFolder()); -$this->getServer()->getScheduler()->scheduleAsyncTask($this->socket); +$this->socket = new isOnlineTask($this, $sock, $this->getDataFolder()); +$this->getServer()->getScheduler()->scheduleRepeatingTask($this->socket, $this->getConfig()->get("TimePerConnection")); $this->sock = $sock; } public function onCommand(CommandSender $issuer, Command $cmd, $label, array $params){ diff --git a/src/Ad5001/Online/OnlineTask.php b/src/Ad5001/Online/OnlineTask.php index fb39ca6..cc30a9a 100644 --- a/src/Ad5001/Online/OnlineTask.php +++ b/src/Ad5001/Online/OnlineTask.php @@ -25,17 +25,18 @@ use pocketmine\math\Vector3; $this->isRunning = true; $this->cfg = new Config($datapath . "config.yml", Config::YAML); } + public function close() { + $this->isRunning = false; + } public function onRun() { $sock = $this->sock; - socket_listen($sock); - while ($this->isRunning) { $client = socket_accept($sock); $input = socket_read($client, 1024); $incoming = explode("\r\n", $input); $fetchArray = explode(" ", $incoming[0]); if($fetchArray[1] == "/"){ - $file = "index.html"; - $fetchArray[1] = "index.html"; + $file = $this->cfg->get("index"); + $fetchArray[1] = $this->cfg->get("index"); } else { $filearray = []; $filearray = explode("/", $fetchArray[1]); @@ -46,20 +47,33 @@ use pocketmine\math\Vector3; "Date: Fri, 31 Dec 1999 23:59:59 GMT \r\n" . "Content-Type: text/html \r\n\r\n"; $file = ltrim($file, '/'); - echo $fetchArray[1]; if(file_exists($this->datapath . $file)) { - $Content = file_get_contents($this->datapath . $file); + if(pathinfo($this->datapath . $file)['extension'] === "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 { - $Content = file_get_contents($this->datapath . "404.html"); + $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")); } - if(in_array($file, $this->cfg->get("denied-pages"))) { - $Content = file_get_contents($this->datapath . "403.html"); + 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)); - } - } - public function close() { - $this->isRunning = false; } } \ No newline at end of file diff --git a/src/Ad5001/Online/isOnlineTask.php b/src/Ad5001/Online/isOnlineTask.php new file mode 100644 index 0000000..e7e1acd --- /dev/null +++ b/src/Ad5001/Online/isOnlineTask.php @@ -0,0 +1,31 @@ +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)); + } + } + } \ No newline at end of file