Improve routing
parent
26311c8ffb
commit
0ff99a3678
42
index.php
42
index.php
|
@ -18,10 +18,13 @@ $RUNTIME['OPENSIM'] = new OpenSim();
|
||||||
|
|
||||||
include_once("config.php");
|
include_once("config.php");
|
||||||
|
|
||||||
|
function isValidEndpoint(string $pageName, string $dirPrefix) {
|
||||||
|
return preg_match("[a-zA-Z0-9\.]{1,100}", $pageName) && file_exists("./".$dirPrefix."/".$pageName.".php");
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: add API keys and/or rate limiting
|
//TODO: add API keys and/or rate limiting
|
||||||
if(isset($_REQUEST['api']))
|
if(isset($_REQUEST['api'])) {
|
||||||
{
|
if(isValidEndpoint($_REQUEST['api'], 'api')) {
|
||||||
if(preg_match("[a-zA-Z0-9\.]{1,100}", $_REQUEST['api']) && file_exists("./api/".$_REQUEST['api'].".php")) {
|
|
||||||
include "./api/".$_REQUEST['api'].".php";
|
include "./api/".$_REQUEST['api'].".php";
|
||||||
} else {
|
} else {
|
||||||
die("ERROR; ENDPOINT NOT EXIST");
|
die("ERROR; ENDPOINT NOT EXIST");
|
||||||
|
@ -30,12 +33,9 @@ if(isset($_REQUEST['api']))
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($handle = opendir('./plugins/'))
|
if ($handle = opendir('./plugins/')) {
|
||||||
{
|
while (false !== ($entry = readdir($handle))) {
|
||||||
while (false !== ($entry = readdir($handle)))
|
if ($entry != "." && $entry != "..") {
|
||||||
{
|
|
||||||
if ($entry != "." && $entry != "..")
|
|
||||||
{
|
|
||||||
include_once "./plugins/".$entry;
|
include_once "./plugins/".$entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,22 +43,15 @@ if ($handle = opendir('./plugins/'))
|
||||||
closedir($handle);
|
closedir($handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($_REQUEST['logout']))
|
if(isset($_REQUEST['logout']) && $_REQUEST['logout'] == '1') {
|
||||||
if($_REQUEST['logout'] == '1')
|
|
||||||
$_SESSION = array();
|
$_SESSION = array();
|
||||||
|
|
||||||
if(isset($_SESSION['LOGIN']))
|
|
||||||
if($_SESSION['LOGIN'] == 'true')
|
|
||||||
{
|
|
||||||
if(!isset($_REQUEST['page']))
|
|
||||||
$_REQUEST['page'] = 'dashboard';
|
|
||||||
|
|
||||||
if(file_exists("./pages/".$_REQUEST['page'].".php")){
|
|
||||||
if($_REQUEST['page'] == str_replace("/"," ",$_REQUEST['page']) and $_REQUEST['page'] == str_replace("\\"," ",$_REQUEST['page']) and $_REQUEST['page'] == str_replace(".."," ",$_REQUEST['page'])){
|
|
||||||
include "./pages/".$_REQUEST['page'].".php";
|
|
||||||
}else{
|
|
||||||
include "./pages/error.php";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isset($_SESSION['LOGIN']) && $_SESSION['LOGIN'] == 'true') {
|
||||||
|
if(!isset($_REQUEST['page'])) {
|
||||||
|
include './pages/dashboard.php';
|
||||||
|
} else if(isValidEndpoint($_REQUEST['page'], 'pages')) {
|
||||||
|
include "./pages/".$_REQUEST['page'].".php";
|
||||||
} else {
|
} else {
|
||||||
include "./pages/error.php";
|
include "./pages/error.php";
|
||||||
}
|
}
|
||||||
|
@ -66,8 +59,7 @@ if(isset($_SESSION['LOGIN']))
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(@$_REQUEST['page'] == "register")
|
if(isset($_REQUEST['page']) && $_REQUEST['page'] == "register") {
|
||||||
{
|
|
||||||
include "./pages/register.php";
|
include "./pages/register.php";
|
||||||
} else {
|
} else {
|
||||||
include "./pages/login.php";
|
include "./pages/login.php";
|
||||||
|
|
Loading…
Reference in New Issue