2016-10-18 13:11:37 +00:00
|
|
|
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
2016-04-18 06:42:26 +00:00
|
|
|
|
2016-10-18 13:11:37 +00:00
|
|
|
require_once __ROOT__.'/autoloader.php';
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-10-18 13:11:37 +00:00
|
|
|
use \router\core\Router;
|
2016-12-17 23:12:23 +00:00
|
|
|
use \http\core\HttpRequest;
|
2016-10-18 13:11:37 +00:00
|
|
|
use \api\core\ModuleRequest;
|
|
|
|
use \api\core\ModuleResponse;
|
2016-04-12 15:46:34 +00:00
|
|
|
use \manager\ManagerError;
|
2016-11-05 10:56:03 +00:00
|
|
|
use \database\core\DatabaseDriver;
|
2016-10-18 13:11:37 +00:00
|
|
|
use \api\core\Checker;
|
2016-04-13 15:06:16 +00:00
|
|
|
use \manager\MenuManager;
|
2016-04-12 15:46:34 +00:00
|
|
|
|
2016-10-24 13:47:28 +00:00
|
|
|
// var_dump($_SESSION);
|
|
|
|
|
2016-04-12 15:46:34 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
/*******************************************/
|
|
|
|
/* DEBUGGER */
|
|
|
|
/*******************************************/
|
|
|
|
debug();
|
|
|
|
/*******************************************/
|
|
|
|
|
|
|
|
|
2016-06-02 16:52:12 +00:00
|
|
|
define('__REDIRECT__', 'Location: /dashboard/');
|
|
|
|
|
2016-04-13 11:36:49 +00:00
|
|
|
|
2016-11-05 10:56:03 +00:00
|
|
|
/* [2] Identity Management
|
2016-04-12 15:46:34 +00:00
|
|
|
=========================================================*/
|
2016-11-05 10:56:03 +00:00
|
|
|
/* (1) Session initialization */
|
2016-04-12 15:46:34 +00:00
|
|
|
if( !isset($_SESSION['userid']) ) $_SESSION['userid'] = null;
|
|
|
|
if( !isset($_SESSION['username']) ) $_SESSION['username'] = null;
|
2016-10-24 13:47:28 +00:00
|
|
|
if( !isset($_SESSION['permission']) ) $_SESSION['permission'] = [];
|
2016-04-12 15:46:34 +00:00
|
|
|
|
2016-04-13 11:36:49 +00:00
|
|
|
|
2016-11-05 10:56:03 +00:00
|
|
|
/* (2) Sign-In management */
|
|
|
|
$login_vars = isset($_POST['login-sub']) && isset($_POST['login']) && isset($_POST['password']);
|
2016-04-12 15:46:34 +00:00
|
|
|
|
|
|
|
// Status de login
|
|
|
|
$_SESSION['login_status'] = 'no';
|
|
|
|
|
|
|
|
// Si les parametres de connection, on essaie de connecter
|
|
|
|
if( $login_vars ){
|
2016-04-17 16:01:23 +00:00
|
|
|
|
2016-09-12 16:04:53 +00:00
|
|
|
$login = new ModuleRequest('user/login', [ 'login' => $_POST['login'], 'password' => $_POST['password'] ]);
|
2016-04-12 15:46:34 +00:00
|
|
|
$login_ans = $login->dispatch();
|
|
|
|
|
2016-10-24 13:47:28 +00:00
|
|
|
// Si aucune erreur, on dit qu'on vient de se connecter
|
2016-04-12 22:29:18 +00:00
|
|
|
if( $login_ans->error == ManagerError::Success )
|
2016-04-12 15:46:34 +00:00
|
|
|
$_SESSION['login_status'] = 'logged';
|
2016-10-24 13:47:28 +00:00
|
|
|
|
|
|
|
// Si on n'a pas les bonnes donnees
|
2016-11-05 10:56:03 +00:00
|
|
|
else
|
2016-04-12 15:46:34 +00:00
|
|
|
$_SESSION['login_status'] = 'error';
|
|
|
|
}
|
2016-04-04 12:04:36 +00:00
|
|
|
|
2016-11-05 10:56:03 +00:00
|
|
|
/* (3) Log-Out management */
|
2016-04-13 13:20:57 +00:00
|
|
|
$logout_vars = isset($_POST['logout-sub']);
|
|
|
|
|
2016-06-02 16:52:12 +00:00
|
|
|
// Si on se deconnecte
|
2016-04-13 13:20:57 +00:00
|
|
|
if( $logout_vars ){
|
2016-04-14 10:45:54 +00:00
|
|
|
$logout = new ModuleRequest('user/logout');
|
2016-04-13 13:20:57 +00:00
|
|
|
$logout_ans = $logout->dispatch();
|
|
|
|
|
|
|
|
// Si aucune erreur, on dit qu'on vient de se deconnecter
|
|
|
|
if( $logout_ans->error == ManagerError::Success )
|
|
|
|
$_SESSION['login_status'] = 'unlogged';
|
2016-10-24 13:47:28 +00:00
|
|
|
|
2016-04-13 13:20:57 +00:00
|
|
|
}
|
2016-04-13 11:36:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-17 16:01:23 +00:00
|
|
|
|
2016-11-05 10:56:03 +00:00
|
|
|
/* [3] On initialise le routeur
|
2016-04-04 09:47:17 +00:00
|
|
|
===================================================*/
|
2016-11-05 10:56:03 +00:00
|
|
|
/* (1) New Router */
|
2016-04-04 09:47:17 +00:00
|
|
|
$R = new Router( $_GET['url'] );
|
2016-04-13 11:36:49 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-11-05 10:56:03 +00:00
|
|
|
/* (2) path/to/resource/filename@0hexa0.svg -> update svg content */
|
2016-09-11 10:06:40 +00:00
|
|
|
$R->get('(.+)@([a-f0-9]{6})(\.svg)', function($matches){
|
2016-10-18 13:11:37 +00:00
|
|
|
$path = __PUBLIC__.'/'.$matches[0].$matches[2];
|
2016-09-11 10:06:40 +00:00
|
|
|
|
2016-11-05 15:13:31 +00:00
|
|
|
header('Content-Type: image/svg+xml; charset=utf-8');
|
2016-09-11 10:06:40 +00:00
|
|
|
|
|
|
|
// On crée la partie ajoutée
|
|
|
|
$stylesheet = "\n<style type='text/css'>\n";
|
|
|
|
$stylesheet .= "\t#stylisable{\n";
|
|
|
|
$stylesheet .= "\t\tfill: #".$matches[1]." !important;\n";
|
|
|
|
$stylesheet .= "\t\tfill-opacity: 1 !important;\n";
|
|
|
|
$stylesheet .= "\t}\n";
|
|
|
|
$stylesheet .= "</style></svg>";
|
|
|
|
|
|
|
|
// On récupère le fichier
|
|
|
|
$file = file_get_contents($path);
|
|
|
|
|
|
|
|
// On ajoute le style
|
|
|
|
$file = str_replace('</svg>', $stylesheet, $file);
|
|
|
|
|
|
|
|
echo $file;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-11-05 10:56:03 +00:00
|
|
|
/* [4] / -> homepage
|
2016-04-04 09:47:17 +00:00
|
|
|
===================================================*/
|
|
|
|
// Racine -> page d'accueil
|
2016-06-02 16:52:12 +00:00
|
|
|
$R->get('/?', function(){ header(__REDIRECT__); });
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-04 12:04:36 +00:00
|
|
|
|
2016-11-05 10:56:03 +00:00
|
|
|
/* [5] Manage websites pages
|
2016-04-04 12:04:36 +00:00
|
|
|
=========================================================*/
|
2016-04-13 15:06:16 +00:00
|
|
|
$temporaryMenuInflater = new MenuManager();
|
|
|
|
$views = $temporaryMenuInflater->getCategories();
|
2016-04-04 12:04:36 +00:00
|
|
|
|
2016-11-05 10:56:03 +00:00
|
|
|
// pagename/arg1/arg2 -> include view
|
2016-10-18 13:11:37 +00:00
|
|
|
$R->get('(?:'.implode('|', $views).')(?:/[\w-]+)*/?', function(){ include __PUBLIC__.'/view.php'; });
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-13 11:36:49 +00:00
|
|
|
|
2016-11-05 10:56:03 +00:00
|
|
|
/* [6] host.xxx/api/{module}/{method} -> api
|
|
|
|
=========================================================*/
|
2016-06-03 08:06:47 +00:00
|
|
|
$R->post('api(?:/(.*))?', function($url){
|
2016-12-17 23:12:23 +00:00
|
|
|
$http = new HttpRequest();
|
|
|
|
$_POST = $http->POST();
|
|
|
|
|
2016-06-03 08:06:47 +00:00
|
|
|
$request = ModuleRequest::fromPost($url, $_POST);
|
2016-06-03 08:58:01 +00:00
|
|
|
$answer = $request->dispatch();
|
|
|
|
|
|
|
|
// Si c'est une réponse
|
2016-06-04 09:06:36 +00:00
|
|
|
if( $answer instanceof ModuleResponse )
|
2016-06-03 08:58:01 +00:00
|
|
|
echo $answer->serialize();
|
2016-04-18 06:42:26 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
});
|
|
|
|
|
2016-04-13 11:36:49 +00:00
|
|
|
|
2016-11-05 10:56:03 +00:00
|
|
|
/* [7] Any other URL -> homepage
|
|
|
|
=========================================================*/
|
|
|
|
$R->get('.+', function(){ header(__REDIRECT__); });
|
2016-06-02 16:52:12 +00:00
|
|
|
$R->post('.+', function(){ header(__REDIRECT__); });
|
2016-04-18 06:42:26 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-11-05 10:56:03 +00:00
|
|
|
/* [8] Launch Router
|
2016-04-04 09:47:17 +00:00
|
|
|
===================================================*/
|
|
|
|
$R->run();
|
|
|
|
|
2016-04-18 06:42:26 +00:00
|
|
|
?>
|