1
0
Fork 0

Improve routing

master
Anonymous Contributor 2023-08-23 18:16:34 +02:00
parent 26311c8ffb
commit 0ff99a3678
1 changed files with 24 additions and 32 deletions

View File

@ -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,33 +43,25 @@ 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(isset($_SESSION['LOGIN']) && $_SESSION['LOGIN'] == 'true') {
if($_SESSION['LOGIN'] == 'true') if(!isset($_REQUEST['page'])) {
{ include './pages/dashboard.php';
if(!isset($_REQUEST['page'])) } else if(isValidEndpoint($_REQUEST['page'], 'pages')) {
$_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"; include "./pages/".$_REQUEST['page'].".php";
}else{ } else {
include "./pages/error.php";
}
}else{
include "./pages/error.php"; include "./pages/error.php";
} }
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";
} }