Adding forbidden
This commit is contained in:
parent
88e4514654
commit
83061751f3
6 changed files with 43 additions and 6 deletions
5
404.html
5
404.html
|
@ -1,5 +0,0 @@
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>404 NOT FOUND</title>
|
|
||||||
</head>
|
|
||||||
<body>Error. File not found !</body>
|
|
14
config.yml
Normal file
14
config.yml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# Welcome to Online config !
|
||||||
|
|
||||||
|
#This define the port that your website that will run.
|
||||||
|
#****NOTE THAT YOU WILL NEED TO RE-PORTFOREWARD WITH THE NEW PORT****
|
||||||
|
port: 8080
|
||||||
|
|
||||||
|
# Here you can choose the pages !
|
||||||
|
index: index.html
|
||||||
|
404: 404.html
|
||||||
|
403: 403.html
|
||||||
|
|
||||||
|
# Here you can config pages that user will not be able to see !
|
||||||
|
denied-pages:
|
||||||
|
- /config..yml/
|
5
resources/403.html
Normal file
5
resources/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>
|
14
resources/config.yml
Normal file
14
resources/config.yml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# Welcome to Online config !
|
||||||
|
|
||||||
|
#This define the port that your website that will run.
|
||||||
|
#****NOTE THAT YOU WILL NEED TO RE-PORTFOREWARD WITH THE NEW PORT****
|
||||||
|
port: 8080
|
||||||
|
|
||||||
|
# Here you can choose the pages !
|
||||||
|
index: index.html
|
||||||
|
404: 404.html
|
||||||
|
403: 403.html
|
||||||
|
|
||||||
|
# Here you can config pages that user will not be able to see !
|
||||||
|
denied-pages:
|
||||||
|
- /config..yml
|
|
@ -24,10 +24,13 @@ if(!file_exists($this->getDataFolder() . "index.html")) {
|
||||||
if(!file_exists($this->getDataFolder() . "404.html")) {
|
if(!file_exists($this->getDataFolder() . "404.html")) {
|
||||||
file_put_contents($this->getDataFolder() . "404.html", $this->getResource("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"));
|
||||||
|
}
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
$address = '0.0.0.0';
|
$address = '0.0.0.0';
|
||||||
$port = 8080;
|
$port = $this->getConfig()->get("port");
|
||||||
|
|
||||||
$sock = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
|
$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');
|
$result = socket_bind($sock, $address, $port) or die('Could not bind to address');
|
||||||
|
|
|
@ -10,6 +10,7 @@ use pocketmine\plugin\Plugin;
|
||||||
use pocketmine\level\Level;
|
use pocketmine\level\Level;
|
||||||
use pocketmine\block\Block;
|
use pocketmine\block\Block;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
use pocketmine\utils\Config;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\utils\TextFormat as C;
|
use pocketmine\utils\TextFormat as C;
|
||||||
use pocketmine\IPlayer;
|
use pocketmine\IPlayer;
|
||||||
|
@ -22,6 +23,7 @@ use pocketmine\math\Vector3;
|
||||||
$this->sock = $sock;
|
$this->sock = $sock;
|
||||||
$this->datapath = $datapath;
|
$this->datapath = $datapath;
|
||||||
$this->isRunning = true;
|
$this->isRunning = true;
|
||||||
|
$this->cfg = new Config($datapath . "config.yml", Config::YAML);
|
||||||
}
|
}
|
||||||
public function onRun() {
|
public function onRun() {
|
||||||
$sock = $this->sock;
|
$sock = $this->sock;
|
||||||
|
@ -44,11 +46,15 @@ use pocketmine\math\Vector3;
|
||||||
"Date: Fri, 31 Dec 1999 23:59:59 GMT \r\n" .
|
"Date: Fri, 31 Dec 1999 23:59:59 GMT \r\n" .
|
||||||
"Content-Type: text/html \r\n\r\n";
|
"Content-Type: text/html \r\n\r\n";
|
||||||
$file = ltrim($file, '/');
|
$file = ltrim($file, '/');
|
||||||
|
echo $fetchArray[1];
|
||||||
if(file_exists($this->datapath . $file)) {
|
if(file_exists($this->datapath . $file)) {
|
||||||
$Content = file_get_contents($this->datapath . $file);
|
$Content = file_get_contents($this->datapath . $file);
|
||||||
} else {
|
} else {
|
||||||
$Content = file_get_contents($this->datapath . "404.html");
|
$Content = file_get_contents($this->datapath . "404.html");
|
||||||
}
|
}
|
||||||
|
if(in_array($file, $this->cfg->get("denied-pages"))) {
|
||||||
|
$Content = file_get_contents($this->datapath . "403.html");
|
||||||
|
}
|
||||||
$output = $Header . $Content;
|
$output = $Header . $Content;
|
||||||
socket_write($client,$output,strlen($output));
|
socket_write($client,$output,strlen($output));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue