Browse Source

1.4 starting...

Just have to add an handler.
master
Ad5001 3 years ago
parent
commit
335007df2b
9 changed files with 87 additions and 26 deletions
  1. 5
    0
      403.html
  2. 5
    0
      404.html
  3. 2
    5
      config.yml
  4. 8
    0
      index.html
  5. 1
    1
      plugin.yml
  6. 3
    2
      resources/config.yml
  7. 16
    0
      resources/handler.php
  8. 16
    0
      router.php
  9. 31
    18
      src/Ad5001/Online/Main.php

+ 5
- 0
403.html View 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
- 0
404.html View File

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

+ 2
- 5
config.yml View File

@@ -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
- 0
index.html View 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
- 1
plugin.yml View File

@@ -1,7 +1,7 @@
---
name: Online
author: Ad5001
version: 1.1
version: 1.4
api: [2.0.0]
main: Ad5001\Online\Main
commands: []

+ 3
- 2
resources/config.yml View File

@@ -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
- 0
resources/handler.php View 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
- 0
router.php View 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;
}

+ 31
- 18
src/Ad5001/Online/Main.php View File

@@ -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;
use pocketmine\Player;


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->socket = new isOnlineTask($this, $sock, $this->getDataFolder());
$this->getServer()->getScheduler()->scheduleRepeatingTask($this->socket, $this->getConfig()->get("TimePerConnection"));
$this->sock = $sock;
$this->getServer()->getScheduler()->scheduleAsyncTask(new execTask($this->getServer()->getFilePath()));
// UPnP::PortForward($port); \\\\ Beta for Windows
}
public function onCommand(CommandSender $issuer, Command $cmd, $label, array $params){
switch($cmd->getName()){
}
return false;
}

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;
}
}
}

Loading…
Cancel
Save