118 lines
3.0 KiB
PHP
Executable File
118 lines
3.0 KiB
PHP
Executable File
<?php
|
|
|
|
/* [0] On definit la racine __ROOT__ si c'est pas deja fait
|
|
=========================================================*/
|
|
if( !defined('__ROOT__') ) define('__ROOT__', dirname(__FILE__) );
|
|
if( !defined('__CONFIG__') ) define('__CONFIG__', __ROOT__.'/config' );
|
|
if( !defined('__BUILD__') ) define('__BUILD__', __ROOT__.'/build' );
|
|
if( !defined('__PUBLIC__') ) define('__PUBLIC__', __ROOT__.'/public_html' );
|
|
|
|
|
|
|
|
/* [1] On définit __SERVER_HOST__ et __SERVER_ROOT__ si c'est pas déja fait
|
|
=========================================================*/
|
|
if( !defined('__SERVER_HOST__') || !defined('__SERVER_ROOT__') ){
|
|
/* (1) On charge le fichier de configuration */
|
|
$json = json_decode( file_get_contents(__ROOT__.'/config/server.json'), true );
|
|
|
|
// Si pas d'erreur, on définit
|
|
if( !is_null($json) ){
|
|
|
|
/* (2) Gestion de la config si server local ou remote */
|
|
if( !isset($_SERVER['SERVER_NAME']) || !checkdnsrr($_SERVER['SERVER_NAME'], 'NS') )
|
|
$config = $json['local'];
|
|
else
|
|
$config = $json['remote'];
|
|
|
|
/* (3) Création des constantes */
|
|
define('__SERVER_HOST__', $config['host']);
|
|
define('__SERVER_ROOT__', $config['root']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ACTIVE LE DEBUGGAGE (WARNING + EXCEPTION)
|
|
*
|
|
*/
|
|
function debug(){
|
|
ini_set('display_errors',1);
|
|
ini_set('display_startup_errors',1);
|
|
error_reporting(-1);
|
|
}
|
|
|
|
|
|
/*************************/
|
|
/* SECURE SHA1 ALGORITHM */
|
|
/*************************/
|
|
function secure_hash($data, $salt='">\[..|{@#))', $depth=1){
|
|
/* (1) On hash @depth fois
|
|
---------------------------------------------------------*/
|
|
$hash = $data;
|
|
$c = 0;
|
|
|
|
for( $h = 0 ; $h < $depth ; $h++ ){
|
|
$hash = hash('sha512', $salt.hash('sha512', $hash.'_)Q@#((%*_$%(@#') );
|
|
$c++;
|
|
}
|
|
|
|
|
|
/* (2) On renvoie le résultat
|
|
---------------------------------------------------------*/
|
|
return $hash;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* AUTOLOADER
|
|
*
|
|
* @className<String> Nom de la classe appelee
|
|
*
|
|
*/
|
|
function autoloader($className){
|
|
/* [1] Basic processing
|
|
=========================================================*/
|
|
/* (1) Explode classname by namespaces */
|
|
$path = explode('\\', $className);
|
|
|
|
/* (2) Check if at least a filename */
|
|
if( count($path) < 1 )
|
|
throw new \Exception('Missing classname for autoloader.');
|
|
|
|
/* (3) Detect if build class or lib class */
|
|
$type = $path[0] === 'lib' ? 'lib' : 'build';
|
|
|
|
|
|
/* [2] Manage type and check file
|
|
=========================================================*/
|
|
/* (1) Build path according to type */
|
|
if( $type === 'lib' )
|
|
$file = __ROOT__.'/'.implode('/', $path).'.php';
|
|
else
|
|
$file = __BUILD__.'/'.implode('/', $path).'.php';
|
|
|
|
|
|
/* (2) Check file */
|
|
if( file_exists($file) )
|
|
require_once $file;
|
|
|
|
}
|
|
|
|
// On definit l'autoloader comme autoloader (obvious)
|
|
require_once __ROOT__.'/lib/vendor/autoload.php';
|
|
spl_autoload_register('autoloader', false, true);
|
|
|
|
|
|
|
|
|
|
/* On demarre la session securisee PHP
|
|
=========================================================*/
|
|
session_start();
|
|
// \manager\sessionManager::session_start();
|
|
|
|
?>
|