LSsession : improving logging

This commit is contained in:
Benjamin Renard 2019-10-25 19:25:25 +02:00
parent 1f4c21256f
commit 08f3be6e20

View file

@ -246,30 +246,30 @@ class LSsession {
$error = 0; $error = 0;
self :: loadLSclass('LSldapObject'); self :: loadLSclass('LSldapObject');
if (!self :: loadLSclass($object,'LSobjects')) { if (!self :: loadLSclass($object,'LSobjects')) {
LSdebug("LSsession :: loadLSobject($object) : Fail to load LSldapObject class"); LSlog :: error("LSsession :: loadLSobject($object) : Fail to load LSldapObject class");
$error = 1; $error = 1;
} }
if (!self :: includeFile( LS_OBJECTS_DIR . 'config.LSobjects.'.$object.'.php' )) { if (!self :: includeFile( LS_OBJECTS_DIR . 'config.LSobjects.'.$object.'.php' )) {
LSdebug("LSsession :: loadLSobject($object) : Fail to include 'config.LSobjects.$object.php' file"); LSlog :: error("LSsession :: loadLSobject($object) : Fail to include 'config.LSobjects.$object.php' file");
$error = 1; $error = 1;
} }
else { else {
if (!LSconfig :: set("LSobjects.$object",$GLOBALS['LSobjects'][$object])) { if (!LSconfig :: set("LSobjects.$object",$GLOBALS['LSobjects'][$object])) {
LSdebug("LSsession :: loadLSobject($object) : Fail to LSconfig :: set('LSobjects.$object', \$GLOBALS['LSobjects'][$object])"); LSlog :: error("LSsession :: loadLSobject($object) : Fail to LSconfig :: set('LSobjects.$object', \$GLOBALS['LSobjects'][$object])");
$error = 1; $error = 1;
} }
else if (isset($GLOBALS['LSobjects'][$object]['LSaddons'])){ else if (isset($GLOBALS['LSobjects'][$object]['LSaddons'])){
if (is_array($GLOBALS['LSobjects'][$object]['LSaddons'])) { if (is_array($GLOBALS['LSobjects'][$object]['LSaddons'])) {
foreach ($GLOBALS['LSobjects'][$object]['LSaddons'] as $addon) { foreach ($GLOBALS['LSobjects'][$object]['LSaddons'] as $addon) {
if (!self :: loadLSaddon($addon)) { if (!self :: loadLSaddon($addon)) {
LSdebug("LSsession :: loadLSobject($object) : Fail to load LSaddon '$addon'"); LSlog :: error("LSsession :: loadLSobject($object) : Fail to load LSaddon '$addon'");
$error = 1; $error = 1;
} }
} }
} }
else { else {
if (!self :: loadLSaddon($GLOBALS['LSobjects'][$object]['LSaddons'])) { if (!self :: loadLSaddon($GLOBALS['LSobjects'][$object]['LSaddons'])) {
LSdebug("LSsession :: loadLSobject($object) : Fail to load LSaddon '".$GLOBALS['LSobjects'][$object]['LSaddons']."'"); LSlog :: error("LSsession :: loadLSobject($object) : Fail to load LSaddon '".$GLOBALS['LSobjects'][$object]['LSaddons']."'");
$error = 1; $error = 1;
} }
} }
@ -384,6 +384,7 @@ class LSsession {
if (self :: localeExist($lang,$encoding)) { if (self :: localeExist($lang,$encoding)) {
LSlog :: debug("LSsession :: setLocale() : Use local '$lang.$encoding'");
if ($encoding) { if ($encoding) {
$lang.='.'.$encoding; $lang.='.'.$encoding;
} }
@ -394,14 +395,16 @@ class LSsession {
self :: includeFile(LS_I18N_DIR.'/'.$lang.'/lang.php'); self :: includeFile(LS_I18N_DIR.'/'.$lang.'/lang.php');
foreach (listFiles(LS_LOCAL_DIR.'/'.LS_I18N_DIR.'/'.$lang, '/^lang.+\.php$/') as $file) { foreach (listFiles(LS_LOCAL_DIR.'/'.LS_I18N_DIR.'/'.$lang, '/^lang.+\.php$/') as $file) {
include(LS_LOCAL_DIR.'/'.LS_I18N_DIR."/$lang/$file"); $path = LS_LOCAL_DIR.'/'.LS_I18N_DIR."/$lang/$file";
LSlog :: debug("LSession :: setLocale() : Local '$lang.$encoding' : load translation file '$path'");
include($path);
} }
} }
else { else {
if ($encoding && $lang) { if ($encoding && $lang) {
$lang.='.'.$encoding; $lang.='.'.$encoding;
} }
LSdebug('La locale "'.$lang.'" n\'existe pas, utilisation de la locale par défaut.'); LSlog :: error("The local '$lang' does not exists , use default one.");
} }
} }
@ -513,7 +516,7 @@ class LSsession {
} }
if(isset($_SESSION['LSsession']['dn']) && !isset($_GET['LSsession_recoverPassword'])) { if(isset($_SESSION['LSsession']['dn']) && !isset($_GET['LSsession_recoverPassword'])) {
LSdebug('LSsession : Session existente'); LSlog :: debug('LSsession : existing session');
// --------------------- Session existante --------------------- // // --------------------- Session existante --------------------- //
self :: $topDn = $_SESSION['LSsession']['topDn']; self :: $topDn = $_SESSION['LSsession']['topDn'];
self :: $dn = $_SESSION['LSsession']['dn']; self :: $dn = $_SESSION['LSsession']['dn'];
@ -525,7 +528,7 @@ class LSsession {
if ( self :: cacheLSprofiles() && !isset($_REQUEST['LSsession_refresh']) ) { if ( self :: cacheLSprofiles() && !isset($_REQUEST['LSsession_refresh']) ) {
self :: setLdapServer(self :: $ldapServerId); self :: setLdapServer(self :: $ldapServerId);
if (!LSauth :: start()) { if (!LSauth :: start()) {
LSdebug("LSsession : can't start LSauth -> stop"); LSlog :: error("LSsession :: startLSsession() : can't start LSauth -> stop");
return; return;
} }
self :: $LSprofiles = $_SESSION['LSsession']['LSprofiles']; self :: $LSprofiles = $_SESSION['LSsession']['LSprofiles'];
@ -537,7 +540,7 @@ class LSsession {
else { else {
self :: setLdapServer(self :: $ldapServerId); self :: setLdapServer(self :: $ldapServerId);
if (!LSauth :: start()) { if (!LSauth :: start()) {
LSdebug("LSsession : can't start LSauth -> stop"); LSlog :: error("LSsession :: startLSsession() : can't start LSauth -> stop");
return; return;
} }
if (!self :: LSldapConnect()) if (!self :: LSldapConnect())
@ -622,7 +625,7 @@ class LSsession {
$_SESSION['LSsession_topDn']=self :: $topDn; $_SESSION['LSsession_topDn']=self :: $topDn;
if (!LSauth :: start()) { if (!LSauth :: start()) {
LSdebug("LSsession : can't start LSauth -> stop"); LSlog :: error("LSsession :: startLSsession() : can't start LSauth -> stop");
return; return;
} }
@ -718,25 +721,26 @@ class LSsession {
$nbresult=count($result); $nbresult=count($result);
if ($nbresult==0) { if ($nbresult==0) {
LSdebug('hash/username incorrect'); LSlog :: debug('LSsession :: recoverPasswd() : incorrect hash/username');
LSerror :: addErrorCode('LSsession_06'); LSerror :: addErrorCode('LSsession_06');
} }
elseif ($nbresult>1) { elseif ($nbresult>1) {
LSlog :: debug("LSsession :: recoverPasswd() : duplicated user found with hash/username '$username'");
LSerror :: addErrorCode('LSsession_07'); LSerror :: addErrorCode('LSsession_07');
} }
else { else {
$rdn = $result[0] -> getValue('rdn'); $rdn = $result[0] -> getValue('rdn');
$username = $rdn[0]; $username = $rdn[0];
LSdebug('Recover : Id trouvé : '.$username); LSlog :: debug("LSsession :: recoverPasswd() : user found, username = '$username'");
if (self :: $ldapServer['recoverPassword']) { if (self :: $ldapServer['recoverPassword']) {
if (self :: loadLSaddon('mail')) { if (self :: loadLSaddon('mail')) {
LSdebug('Récupération active'); LSlog :: debug("LSsession :: recoverPasswd() : start recovering password");
$user=$result[0]; $user=$result[0];
$emailAddress = $user -> getValue(self :: $ldapServer['recoverPassword']['mailAttr']); $emailAddress = $user -> getValue(self :: $ldapServer['recoverPassword']['mailAttr']);
$emailAddress = $emailAddress[0]; $emailAddress = $emailAddress[0];
if (checkEmail($emailAddress)) { if (checkEmail($emailAddress)) {
LSdebug('Email : '.$emailAddress); LSlog :: debug("LSsession :: recoverPasswd() : Email = '$emailAddress'");
self :: $dn = $user -> getDn(); self :: $dn = $user -> getDn();
// 1ère étape : envoie du recoveryHash // 1ère étape : envoie du recoveryHash
@ -813,7 +817,7 @@ class LSsession {
} }
if (!sendMail($mail,$subject,$msg,$sendParams)) { if (!sendMail($mail,$subject,$msg,$sendParams)) {
LSdebug("Problème durant l'envoie du mail"); LSlog :: debug("LSsession :: recoverPasswdSendMail($mail, $step) : error sending email.");
LSerror :: addErrorCode('LSsession_20',4); LSerror :: addErrorCode('LSsession_20',4);
return; return;
} }
@ -849,13 +853,13 @@ class LSsession {
} }
else { else {
// Erreur durant la mise à jour de l'objet // Erreur durant la mise à jour de l'objet
LSdebug("Erreur durant la mise à jour de l'objet"); LSlog :: error("LSsession :: recoverPasswdFirstStep($user) : error updating user.");
LSerror :: addErrorCode('LSsession_20',6); LSerror :: addErrorCode('LSsession_20',6);
} }
} }
else { else {
// Erreur durant la validation du formulaire de modification de perte de password // Erreur durant la validation du formulaire de modification de perte de password
LSdebug("Erreur durant la validation du formulaire de modification de perte de password"); LSlog :: error("LSsession :: recoverPasswdFirstStep($user) : error validating form.");
LSerror :: addErrorCode('LSsession_20',5); LSerror :: addErrorCode('LSsession_20',5);
} }
return; return;
@ -875,7 +879,7 @@ class LSsession {
$attr -> config['html_options']['chars'], $attr -> config['html_options']['chars'],
$attr -> config['html_options']['lenght'] $attr -> config['html_options']['lenght']
); );
LSdebug('Nvx mpd : '.$mdp); LSlog :: debug("LSsession :: recoverPasswdSecondStep($user) : new password = '$mdp'.");
$lostPasswdForm = $user -> getForm('lostPassword'); $lostPasswdForm = $user -> getForm('lostPassword');
$lostPasswdForm -> setPostData( $lostPasswdForm -> setPostData(
array( array(
@ -890,19 +894,19 @@ class LSsession {
} }
else { else {
// Erreur durant la mise à jour de l'objet // Erreur durant la mise à jour de l'objet
LSdebug("Erreur durant la mise à jour de l'objet"); LSlog :: error("LSsession :: recoverPasswdSecondStep($user) : error updating user.");
LSerror :: addErrorCode('LSsession_20',3); LSerror :: addErrorCode('LSsession_20',3);
} }
} }
else { else {
// Erreur durant la validation du formulaire de modification de perte de password // Erreur durant la validation du formulaire de modification de perte de password
LSdebug("Erreur durant la validation du formulaire de modification de perte de password"); LSlog :: error("LSsession :: recoverPasswdSecondStep($user) : error validating form.");
LSerror :: addErrorCode('LSsession_20',2); LSerror :: addErrorCode('LSsession_20',2);
} }
} }
else { else {
// l'attribut password n'existe pas // l'attribut password n'existe pas
LSdebug("L'attribut password n'existe pas"); LSlog :: error("LSsession :: recoverPasswdSecondStep($user) : password attribute '$attr' does not exists.");
LSerror :: addErrorCode('LSsession_20',1); LSerror :: addErrorCode('LSsession_20',1);
} }
return; return;
@ -1565,17 +1569,17 @@ class LSsession {
if (! isset($filter_def['filter']) && if (! isset($filter_def['filter']) &&
(! isset($filter_def['attr']) || (! isset($filter_def['attr']) ||
! isset($filter_def['attr_value']))) { ! isset($filter_def['attr_value']))) {
LSdebug("Filtre de profil LSobject invalide " . var_export($filter_def, true)); LSlog :: debug("LSsession :: reduceLdapSet() : LSobject LSprofil filter invalid : " . varDump($filter_def));
return array(); return array();
} }
LSdebug('LSsession :: reducing set of'); LSlog :: debug('LSsession :: reduceLdapSet() : reducing set of');
foreach ($set as $object) { foreach ($set as $object) {
LSdebug('LSsession :: -> ' . $object -> getDn()); LSdebug('LSsession :: -> ' . $object -> getDn());
} }
$LSobject = isset($filter_def['LSObject']) ? $filter_def['LSobject'] : $LSobject; $LSobject = isset($filter_def['LSObject']) ? $filter_def['LSobject'] : $LSobject;
LSdebug('LSobject :: ' . $LSobject); LSlog :: debug('LSsession :: reduceLdapSet() : LSobject = ' . $LSobject);
$filters = array(); $filters = array();
foreach ($set as $object) { foreach ($set as $object) {
if (isset($filter_def['filter'])) { if (isset($filter_def['filter'])) {
@ -1599,9 +1603,9 @@ class LSsession {
$LSsearch -> run(false); $LSsearch -> run(false);
$set = $LSsearch -> listObjects(); $set = $LSsearch -> listObjects();
LSdebug('LSsession :: reduced set to'); LSlog :: debug('LSsession :: reduceLdapSet() : reduced set to');
foreach ($set as $object) { foreach ($set as $object) {
LSdebug('LSsession :: -> ' . $object -> getDn()); LSlog :: debug('LSsession :: reduceLdapSet() : -> ' . $object -> getDn());
} }
return $set; return $set;
} }
@ -1615,7 +1619,7 @@ class LSsession {
*/ */
private static function loadLSprofilesLSobjects($profile, $LSobject, $listInfos) { private static function loadLSprofilesLSobjects($profile, $LSobject, $listInfos) {
if (! self :: loadLSclass('LSsearch')) { if (! self :: loadLSclass('LSsearch')) {
LSdebug('Impossible de charger la classe LSsearch'); LSlog :: error('Fail to load class LSsearch');
return; return;
} }
# we are gonna grow a set of objects progressively, we start from the user # we are gonna grow a set of objects progressively, we start from the user
@ -1670,12 +1674,12 @@ class LSsession {
elseif ($topDn == 'LSobjects') { elseif ($topDn == 'LSobjects') {
if (is_array($rightsInfos)) { if (is_array($rightsInfos)) {
foreach ($rightsInfos as $LSobject => $listInfos) { foreach ($rightsInfos as $LSobject => $listInfos) {
LSdebug('loading LSprofile ' . $profile . ' for LSobject ' . $LSobject . ' with params ' . var_export($listInfos, true)); LSlog :: debug('LSsession :: loadLSprofiles() : loading LSprofile ' . $profile . ' for LSobject ' . $LSobject . ' with params ' . var_export($listInfos, true));
self :: loadLSprofilesLSobjects($profile, $LSobject, $listInfos); self :: loadLSprofilesLSobjects($profile, $LSobject, $listInfos);
} }
} }
else { else {
LSdebug('LSobjects => [] doit etre un tableau'); LSlog :: warning('LSsession :: loadLSprofiles() : LSobjects => [] must be an array');
} }
} }
else { else {
@ -1695,11 +1699,11 @@ class LSsession {
} }
} }
else { else {
LSdebug('Impossible de chargé le dn : '.$dn); LSlog :: warning("LSsession :: loadLSprofiles() : fail to load DN '$dn'.");
} }
} }
else { else {
LSdebug('Impossible de créer l\'objet de type : '.$conf['LSobject']); LSlog :: warning("LSsession :: loadLSprofiles() : fail to instanciate LSobject type '".$conf['LSobject']."'.");
} }
} }
} }
@ -1719,7 +1723,7 @@ class LSsession {
} // fin foreach($profileInfos) } // fin foreach($profileInfos)
} // fin is_array($profileInfos) } // fin is_array($profileInfos)
} // fin foreach LSprofiles } // fin foreach LSprofiles
LSdebug("LSprofiles : ".print_r(self :: $LSprofiles,1)); LSlog :: debug("LSsession :: loadLSprofiles() : LSprofiles = ".print_r(self :: $LSprofiles,1));
return true; return true;
} }
else { else {