109 lines
2.9 KiB
PHP
Executable File
109 lines
2.9 KiB
PHP
Executable File
<?php define('__ROOT__', dirname(__FILE__) );
|
|
|
|
require_once __ROOT__.'/manager/autoloader.php';
|
|
|
|
use \router\Router;
|
|
|
|
use \manager\ModuleRequest;
|
|
use \manager\ModuleResponse;
|
|
use \manager\ManagerError;
|
|
use \manager\Authentification;
|
|
|
|
|
|
/*******************************************/
|
|
/* DEBUGGER */
|
|
/*******************************************/
|
|
debug();
|
|
/*******************************************/
|
|
/* DEBUGGER */
|
|
/*******************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] Gestion des authentifications et des droits
|
|
=========================================================*/
|
|
/* (1) On met à jour l'authentification et les permissions */
|
|
Authentification::check();
|
|
$auth = Authentification::auth();
|
|
|
|
|
|
/* (2) On définit la page d'accueil */
|
|
if( $auth == 2 ) define('__REDIRECT__', 'Location: /dashboard/'); // Connecté -> Accès
|
|
elseif( $auth == 1 ) define('__REDIRECT__', 'Location: /admin/'); // Pas identifié -> Identification
|
|
else define('__REDIRECT__', 'Location: /warehouse/'); // Pas localisé -> Localisation
|
|
|
|
|
|
|
|
|
|
/* [2] Gestion du routage
|
|
=========================================================*/
|
|
|
|
/* (1) On initialise le routeur
|
|
---------------------------------------------------------*/
|
|
$R = new Router( $_GET['url'] );
|
|
|
|
|
|
/* (3) On cree les regles de routage QUAND ON EST CONNECTE
|
|
---------------------------------------------------------*/
|
|
/* (2) Si on est connecté */
|
|
if( $auth == 2 ){
|
|
|
|
|
|
|
|
// nomPage/arg1/arg2 -> inclusion de la page
|
|
$R->get('(.*)', function($m){
|
|
// Liste des pages du site
|
|
$page_list = [ 'dashboard', 'profile', 'machines', 'users', 'groups', 'analytics', 'settings' ];
|
|
|
|
|
|
if( !preg_match('#^(?:'.implode('|', $page_list).')(?:/[\w-]+)*/?$#i', $m[0]) )
|
|
header(__REDIRECT__);
|
|
else
|
|
include __ROOT__.'/view/view.php';
|
|
});
|
|
|
|
|
|
/* (3) Si on est pas authentifié */
|
|
}else if( $auth == 1 ){
|
|
|
|
$R->get('(.*)', function($m){
|
|
if( !preg_match('#^admin/$#', $m[0]) ) header(__REDIRECT__);
|
|
else include __ROOT__.'/view/admin.php';
|
|
});
|
|
|
|
}else{
|
|
$R->get('(.*)', function($m){
|
|
if( !preg_match('#^warehouse/$#', $m[0]) ) header(__REDIRECT__);
|
|
else include __ROOT__.'/view/warehouse.php';
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* (4) api/module/method -> Api */
|
|
$R->post('api(?:/(.*))?', function($url){
|
|
$request = ModuleRequest::fromPost($url, $_POST);
|
|
$answer = $request->dispatch();
|
|
|
|
// Si c'est une réponse (et non un download)
|
|
if( $answer instanceof ModuleResponse )
|
|
echo $answer->serialize();
|
|
});
|
|
|
|
|
|
/* (5) N'importe -> page d'accueil */
|
|
$R->get('.+', function(){ header(__REDIRECT__); });
|
|
$R->post('.+', function(){ header(__REDIRECT__); });
|
|
|
|
|
|
|
|
/* (3) On lance le routeur
|
|
---------------------------------------------------------*/
|
|
$R->run();
|
|
|
|
?>
|