diff --git a/trunk/conf/config.inc.php b/trunk/conf/config.inc.php index 729458c8..748a029e 100644 --- a/trunk/conf/config.inc.php +++ b/trunk/conf/config.inc.php @@ -172,7 +172,7 @@ define('LS_IMAGES_DIR', 'images/'.LS_THEME); define('LS_CSS_DIR', 'css/'.LS_THEME); //Debug -$GLOBALS['LSdebug']['active'] = true; +define('LSdebug',true); // Logs $GLOBALS['LSlog']['filename'] = 'tmp/LS.log'; @@ -183,16 +183,6 @@ define('NB_LSOBJECT_LIST_SELECT',11); define('MAX_SEND_FILE_SIZE',2000000); -// Définitions des dossiers d'inclusions -define('LS_CONF_DIR','conf/'); -define('LS_OBJECTS_DIR', LS_CONF_DIR . 'LSobjects/'); -define('LS_INCLUDE_DIR','includes/'); -define('LS_CLASS_DIR', LS_INCLUDE_DIR .'class/'); -define('LS_LIB_DIR', LS_INCLUDE_DIR .'libs/'); -define('LS_ADDONS_DIR', LS_INCLUDE_DIR .'addons/'); -define('LS_JS_DIR', LS_INCLUDE_DIR .'js/'); -define('LS_TMP_DIR', 'tmp/'); - // Javascript $GLOBALS['defaultJSscipts']=array( @@ -202,13 +192,4 @@ $GLOBALS['defaultJSscipts']=array( 'LSdefault.js' ); -// PHP values -ini_set( 'magic_quotes_gpc', 'off' ); -ini_set( 'magic_quotes_sybase', 'off' ); -ini_set( 'magic_quotes_runtime', 'off' ); - -// Locale -define('LS_TEXT_DOMAIN', 'ldapsaisie'); -define('LS_I18N_DIR', 'lang'); - ?> diff --git a/trunk/core.php b/trunk/core.php new file mode 100644 index 00000000..7ec52061 --- /dev/null +++ b/trunk/core.php @@ -0,0 +1,46 @@ + diff --git a/trunk/create.php b/trunk/create.php index 5575ac92..cf94bda3 100644 --- a/trunk/create.php +++ b/trunk/create.php @@ -20,7 +20,7 @@ ******************************************************************************/ -require_once 'includes/class/class.LSsession.php'; +require_once 'core.php'; if(LSsession :: startLSsession()) { diff --git a/trunk/includes/class/class.LSconfig.php b/trunk/includes/class/class.LSconfig.php new file mode 100644 index 00000000..a9fa98f3 --- /dev/null +++ b/trunk/includes/class/class.LSconfig.php @@ -0,0 +1,95 @@ + + */ +class LSconfig { + + // Configuration Data + private static $data=array(); + + /** + * Lancement de LSconfig + * + * Chargement initiale des données de configuration à partir des fichiers en + * config.*.php du dossier LS_CONF_DIR + * + * @retval boolean True si tout s'est bien passé, False sinon + **/ + public static function start() { + if (loadDir(LS_CONF_DIR, '^config\..*\.php$')) { + if (is_array($GLOBALS['LSconfig'])) { + self :: $data = $GLOBALS['LSconfig']; + self :: $data['LSaddons'] = $GLOBALS['LSaddons']; + return true; + } + } + return; + } + + /** + * Récupération d'une valeur + * + * @param[in] $var string Le nom de valeur à récupérer (Exemple : cacheSearch) + * + * @retval mixed La valeur de la variable, ou false si son nom n'est parsable + **/ + public static function get($var) { + $vars=explode('.',$var); + if(is_array($vars)) { + $data=self :: $data; + foreach ($vars as $v) { + $data=$data[$v]; + } + return $data; + } + return; + } + + /** + * Définition d'une valeur + * + * @param[in] $var string Le nom de valeur à définir + * @param[in] $val mixed La valeur de la variable + * + * @retval boolean True si tout s'est bien passé, False sinon + **/ + public static function set($var,$val) { + $vars=explode('.',$var); + if(is_array($vars)) { + $code='self :: $data'; + foreach ($vars as $v) { + $code.='["'.$v.'"]'; + } + $code.='=$val;'; + return (eval($code)===NULL); + } + return; + } + +} + + +?> diff --git a/trunk/includes/class/class.LSsession.php b/trunk/includes/class/class.LSsession.php index 5f8af9a4..0e41edfe 100644 --- a/trunk/includes/class/class.LSsession.php +++ b/trunk/includes/class/class.LSsession.php @@ -20,9 +20,6 @@ ******************************************************************************/ -define('LS_DEFAULT_CONF_DIR','conf'); -require_once 'includes/functions.php'; - /** * Gestion des sessions * @@ -95,7 +92,7 @@ class LSsession { if (!file_exists($file)) { return; } - if ($GLOBALS['LSdebug']['active']) { + if (LSdebug) { return include_once($file); } else { @@ -105,48 +102,60 @@ class LSsession { } /** - * Chargement de la configuration - * - * Chargement des fichiers de configuration et création de l'objet Smarty. + * Lancement de LSconfig * * @author Benjamin Renard * * @retval true si tout c'est bien passé, false sinon */ - private static function loadConfig() { - if (loadDir(LS_DEFAULT_CONF_DIR, '^config\..*\.php$')) { - if ( self :: includeFile($GLOBALS['LSconfig']['Smarty']) ) { - $GLOBALS['Smarty'] = new Smarty(); - $GLOBALS['Smarty'] -> template_dir = LS_TEMPLATES_DIR; - $GLOBALS['Smarty'] -> compile_dir = LS_TMP_DIR; - - if ($GLOBALS['LSdebug']['active']) { - $GLOBALS['Smarty'] -> caching = 0; - // cache files are always regenerated - $GLOBALS['Smarty'] -> force_compile = TRUE; - // recompile template if it is changed - $GLOBALS['Smarty'] -> compile_check = TRUE; - } - - $GLOBALS['Smarty'] -> assign('LS_CSS_DIR',LS_CSS_DIR); - $GLOBALS['Smarty'] -> assign('LS_IMAGES_DIR',LS_IMAGES_DIR); - - self :: addJSconfigParam('LS_IMAGES_DIR',LS_IMAGES_DIR); + private static function startLSconfig() { + if (self :: loadLSclass('LSconfig')) { + if (LSconfig :: start()) { return true; } - else { - die("ERROR : Can't load Smarty."); - return; + } + die("ERROR : Can't load configuration files."); + return; + } + + /** + * Lancement et initialisation de Smarty + * + * @author Benjamin Renard + * + * @retval true si tout c'est bien passé, false sinon + */ + private static function startLStemplate() { + if ( self :: includeFile(LSconfig :: get('Smarty')) ) { + $GLOBALS['Smarty'] = new Smarty(); + $GLOBALS['Smarty'] -> template_dir = LS_TEMPLATES_DIR; + $GLOBALS['Smarty'] -> compile_dir = LS_TMP_DIR; + + if (LSdebug) { + $GLOBALS['Smarty'] -> caching = 0; + // cache files are always regenerated + $GLOBALS['Smarty'] -> force_compile = TRUE; + // recompile template if it is changed + $GLOBALS['Smarty'] -> compile_check = TRUE; } + + $GLOBALS['Smarty'] -> assign('LS_CSS_DIR',LS_CSS_DIR); + $GLOBALS['Smarty'] -> assign('LS_IMAGES_DIR',LS_IMAGES_DIR); + + self :: addJSconfigParam('LS_IMAGES_DIR',LS_IMAGES_DIR); return true; } - else { - die("ERROR : Can't load configuration files."); - return; - } - + die("ERROR : Can't load Smarty."); + return; } + /** + * Retourne le topDn de la session + * + * @author Benjamin Renard + * + * @retval string le topDn de la session + */ public static function getTopDn() { return self :: $topDn; } @@ -194,6 +203,9 @@ class LSsession { * @retval boolean true si le chargement a réussi, false sinon. */ public static function loadLSobject($object) { + if(class_exists($object)) { + return true; + } $error = 0; self :: loadLSclass('LSldapObject'); if (!self :: loadLSclass($object,'LSobjects')) { @@ -202,6 +214,11 @@ class LSsession { if (!self :: includeFile( LS_OBJECTS_DIR . 'config.LSobjects.'.$object.'.php' )) { $error = 1; } + else { + if (!LSconfig :: set("LSobjects.$object",$GLOBALS['LSobjects'][$object])) { + $error = 1; + } + } if ($error) { LSerror :: addErrorCode('LSsession_04',$object); return; @@ -239,12 +256,13 @@ class LSsession { * @retval boolean true si le chargement a réussi, false sinon. */ public static function loadLSaddons() { - if(!is_array($GLOBALS['LSaddons']['loads'])) { + $conf=LSconfig :: get('LSaddons.loads'); + if(!is_array($conf)) { LSerror :: addErrorCode('LSsession_01',"LSaddons['loads']"); return; } - foreach ($GLOBALS['LSaddons']['loads'] as $addon) { + foreach ($conf as $addon) { self :: loadLSaddon($addon); } return true; @@ -266,7 +284,7 @@ class LSsession { $lang = self :: $ldapServer['lang']; } else { - $lang = $GLOBALS['LSconfig']['lang']; + $lang = LSconfig :: get('lang'); } if (isset($_REQUEST['encoding'])) { @@ -279,7 +297,7 @@ class LSsession { $encoding = self :: $ldapServer['encoding']; } else { - $encoding = $GLOBALS['LSconfig']['encoding']; + $encoding = LSconfig :: get('encoding'); } $_SESSION['LSlang']=$lang; @@ -360,9 +378,12 @@ class LSsession { * @retval boolean True si l'initialisation à réussi, false sinon. */ public static function initialize() { - if (!self :: loadConfig()) { + if (!self :: startLSconfig()) { return; } + + self :: startLStemplate(); + session_start(); self :: setLocale(); @@ -773,9 +794,10 @@ class LSsession { * @retval boolean True sinon false. */ public static function setLdapServer($id) { - if ( isset($GLOBALS['LSconfig']['ldap_servers'][$id]) ) { + $conf = LSconfig :: get("ldap_servers.$id"); + if ( is_array($conf) ) { self :: $ldapServerId = $id; - self :: $ldapServer=$GLOBALS['LSconfig']['ldap_servers'][$id]; + self :: $ldapServer = $conf; self :: setLocale(); return true; } @@ -791,7 +813,7 @@ class LSsession { */ public static function LSldapConnect() { if (self :: $ldapServer) { - self :: includeFile($GLOBALS['LSconfig']['NetLDAP2']); + self :: includeFile(LSconfig :: get('NetLDAP2')); if (!self :: loadLSclass('LSldap')) { return; } @@ -964,13 +986,13 @@ class LSsession { else { $GLOBALS['Smarty'] -> assign('loginform_action',$_SERVER['REQUEST_URI']); } - if (count($GLOBALS['LSconfig']['ldap_servers'])==1) { + if (count(LSconfig :: get('ldap_servers'))==1) { $GLOBALS['Smarty'] -> assign('loginform_ldapserver_style','style="display: none"'); } $GLOBALS['Smarty'] -> assign('loginform_label_ldapserver',_('LDAP server')); $ldapservers_name=array(); $ldapservers_index=array(); - foreach($GLOBALS['LSconfig']['ldap_servers'] as $id => $infos) { + foreach(LSconfig :: get('ldap_servers') as $id => $infos) { $ldapservers_index[]=$id; $ldapservers_name[]=__($infos['name']); } @@ -1002,14 +1024,14 @@ class LSsession { $GLOBALS['Smarty'] -> assign('pagetitle',_('Recovery of your credentials')); $GLOBALS['Smarty'] -> assign('recoverpasswordform_action','index.php?LSsession_recoverPassword'); - if (count($GLOBALS['LSconfig']['ldap_servers'])==1) { + if (count(LSconfig :: get('ldap_servers'))==1) { $GLOBALS['Smarty'] -> assign('recoverpasswordform_ldapserver_style','style="display: none"'); } $GLOBALS['Smarty'] -> assign('recoverpasswordform_label_ldapserver',_('LDAP server')); $ldapservers_name=array(); $ldapservers_index=array(); - foreach($GLOBALS['LSconfig']['ldap_servers'] as $id => $infos) { + foreach(LSconfig :: get('ldap_servers') as $id => $infos) { $ldapservers_index[]=$id; $ldapservers_name[]=$infos['name']; } @@ -1127,15 +1149,12 @@ class LSsession { $JSscript_txt.="\n"; } + $KAconf = LSconfig :: get('keepLSsessionActive'); if ( ( (!isset(self :: $ldapServer['keepLSsessionActive'])) && - ( - (!isset($GLOBALS['LSconfig']['keepLSsessionActive'])) - || - ($GLOBALS['LSconfig']['keepLSsessionActive']) - ) + (!($KAconf === false)) ) || (self :: $ldapServer['keepLSsessionActive']) @@ -1145,7 +1164,7 @@ class LSsession { $GLOBALS['Smarty'] -> assign('LSjsConfig',json_encode(self :: $_JSconfigParams)); - if ($GLOBALS['LSdebug']['active']) { + if (LSdebug) { $JSscript_txt.="\n"; } else { @@ -1397,7 +1416,7 @@ class LSsession { foreach($objectConf['LSobjects'] as $type) { if (self :: loadLSobject($type)) { if (self :: canAccess($type)) { - $access[$type] = $GLOBALS['LSobjects'][$type]['label']; + $access[$type] = LSconfig :: get('LSobjects.'.$type.'.label'); } } } @@ -1418,7 +1437,7 @@ class LSsession { foreach($config['LSobjects'] as $objectType) { if (self :: loadLSobject($objectType)) { if (self :: canAccess($objectType)) { - $access[$objectType] = $GLOBALS['LSobjects'][$objectType]['label']; + $access[$objectType] = LSconfig :: get('LSobjects.'.$objectType.'.label'); } } } @@ -1434,7 +1453,7 @@ class LSsession { foreach(self :: $ldapServer['LSaccess'] as $objectType) { if (self :: loadLSobject($objectType)) { if (self :: canAccess($objectType)) { - $access[$objectType] = $GLOBALS['LSobjects'][$objectType]['label']; + $access[$objectType] = LSconfig :: get('LSobjects.'.$objectType.'.label'); } } } @@ -1529,22 +1548,22 @@ class LSsession { } } else { - $objectdn=$GLOBALS['LSobjects'][$LSobject]['container_dn'].','.self :: $topDn; + $objectdn=LSconfig :: get('LSobjects.'.$LSobject.'.container_dn').','.self :: $topDn; $whoami = self :: whoami($objectdn); } // Pour un attribut particulier if ($attr) { if ($attr=='rdn') { - $attr=$GLOBALS['LSobjects'][$LSobject]['rdn']; + $attr=LSconfig :: get('LSobjects.'.$LSobject.'.rdn'); } - if (!isset($GLOBALS['LSobjects'][$LSobject]['attrs'][$attr])) { + if (!is_array(LSconfig :: get('LSobjects.'.$LSobject.'.attrs.'.$attr))) { return; } $r = 'n'; foreach($whoami as $who) { - $nr = $GLOBALS['LSobjects'][$LSobject]['attrs'][$attr]['rights'][$who]; + $nr = LSconfig :: get('LSobjects.'.$LSobject.'.attrs.'.$attr.'.rights.'.$who); if($nr == 'w') { $r = 'w'; } @@ -1570,10 +1589,11 @@ class LSsession { } // Pour un attribut quelconque - if (is_array($GLOBALS['LSobjects'][$LSobject]['attrs'])) { + $attrs_conf=LSconfig :: get('LSobjects.'.$LSobject.'.attrs'); + if (is_array($attrs_conf)) { if (($right=='r')||($right=='w')) { foreach($whoami as $who) { - foreach ($GLOBALS['LSobjects'][$LSobject]['attrs'] as $attr_name => $attr_config) { + foreach ($attrs_conf as $attr_name => $attr_config) { if ($attr_config['rights'][$who]==$right) { return true; } @@ -1582,7 +1602,7 @@ class LSsession { } else { foreach($whoami as $who) { - foreach ($GLOBALS['LSobjects'][$LSobject]['attrs'] as $attr_name => $attr_config) { + foreach ($attrs_conf as $attr_name => $attr_config) { if ( ($attr_config['rights'][$who]=='r') || ($attr_config['rights'][$who]=='w') ) { return true; } @@ -1640,14 +1660,15 @@ class LSsession { * @retval boolean True si l'utilisateur a accès, false sinon */ public static function relationCanAccess($dn,$LSobject,$relationName,$right=NULL) { - if (!isset($GLOBALS['LSobjects'][$LSobject]['LSrelation'][$relationName])) + $relConf=LSconfig :: get('LSobjects.'.$LSobject.'.LSrelation.'.$relationName); + if (!is_array($relConf)) return; $whoami = self :: whoami($dn); if (($right=='w') || ($right=='r')) { $r = 'n'; foreach($whoami as $who) { - $nr = $GLOBALS['LSobjects'][$LSobject]['LSrelation'][$relationName]['rights'][$who]; + $nr = $relConf['rights'][$who]; if($nr == 'w') { $r = 'w'; } @@ -1664,7 +1685,7 @@ class LSsession { } else { foreach($whoami as $who) { - if (($GLOBALS['LSobjects'][$LSobject]['LSrelation'][$relationName]['rights'][$who] == 'w') || ($GLOBALS['LSobjects'][$LSobject]['LSrelation'][$relationName]['rights'][$who] == 'r')) { + if (($relConf['rights'][$who] == 'w') || ($relConf['rights'][$who] == 'r')) { return true; } } @@ -1774,7 +1795,7 @@ class LSsession { * @retval boolean True si le cache des droits est activé, false sinon. */ public static function cacheLSprofiles() { - return ( ($GLOBALS['LSconfig']['cacheLSprofiles']) || (self :: $ldapServer['cacheLSprofiles']) ); + return ( (LSconfig :: get('cacheLSprofiles')) || (self :: $ldapServer['cacheLSprofiles']) ); } /** @@ -1785,7 +1806,7 @@ class LSsession { * @retval boolean True si le cache des subDn est activé, false sinon. */ public static function cacheSudDn() { - return (($GLOBALS['LSconfig']['cacheSubDn']) || (self :: $ldapServer['cacheSubDn'])); + return ( (LSconfig :: get('cacheSubDn')) || (self :: $ldapServer['cacheSubDn'])); } /** @@ -1796,7 +1817,7 @@ class LSsession { * @retval boolean True si le cache des recherches est activé, false sinon. */ public static function cacheSearch() { - return (($GLOBALS['LSconfig']['cacheSearch']) || (self :: $ldapServer['cacheSearch'])); + return ( (LSconfig :: get('cacheSearch')) || (self :: $ldapServer['cacheSearch'])); } /** diff --git a/trunk/includes/functions.php b/trunk/includes/functions.php index e0937233..71af4f28 100644 --- a/trunk/includes/functions.php +++ b/trunk/includes/functions.php @@ -188,29 +188,29 @@ function return_data($data) { return $data; } -$GLOBALS['LSdebug']['fields']=array(); +$GLOBALS['LSdebug_fields']=array(); function LSdebug($data,$dump=false) { if ($dump) { ob_start(); var_dump($data); - $GLOBALS['LSdebug']['fields'][]=ob_get_contents(); + $GLOBALS['LSdebug_fields'][]=ob_get_contents(); ob_end_clean(); } else { if (is_array($data)||is_object($data)) { - $GLOBALS['LSdebug']['fields'][]=$data; + $GLOBALS['LSdebug_fields'][]=$data; } else { - $GLOBALS['LSdebug']['fields'][]="[$data]"; + $GLOBALS['LSdebug_fields'][]="[$data]"; } } return true; } function LSdebug_print($return=false) { - if (( $GLOBALS['LSdebug']['fields'] ) && ( $GLOBALS['LSdebug']['active'] )) { + if (( $GLOBALS['LSdebug_fields'] ) && (LSdebug)) { $txt='
    '; - foreach($GLOBALS['LSdebug']['fields'] as $debug) { + foreach($GLOBALS['LSdebug_fields'] as $debug) { if (is_array($debug)||is_object($debug)) { $txt.='
  • '.print_r($debug,true).'
  • '; } @@ -228,9 +228,9 @@ function LSdebug_print($return=false) { } function LSdebugDefined() { - if (!$GLOBALS['LSdebug']['active']) + if (!LSdebug) return; - return (!empty($GLOBALS['LSdebug']['fields'])); + return (!empty($GLOBALS['LSdebug_fields'])); } /** diff --git a/trunk/index.php b/trunk/index.php index a00348f6..fa12dbba 100644 --- a/trunk/index.php +++ b/trunk/index.php @@ -20,7 +20,7 @@ ******************************************************************************/ -require_once 'includes/class/class.LSsession.php'; +require_once 'core.php'; if(LSsession :: startLSsession()) { diff --git a/trunk/index_ajax.php b/trunk/index_ajax.php index c18ea578..44c70cd6 100644 --- a/trunk/index_ajax.php +++ b/trunk/index_ajax.php @@ -1,6 +1,6 @@