LSldap : use LSlog_logger

This commit is contained in:
Benjamin Renard 2020-05-08 15:16:24 +02:00
parent 6abf194807
commit 5674a99a7c
5 changed files with 67 additions and 65 deletions

View file

@ -78,7 +78,7 @@ class LSlang extends LSlog_staticLoggerClass {
// Check
if (self :: localeExist($lang, $encoding)) {
self :: log("DEBUG", "setLocale() : Use local '$lang.$encoding'");
self :: log_debug("setLocale() : Use local '$lang.$encoding'");
if ($encoding) {
$lang .= '.'.$encoding;
}
@ -87,26 +87,26 @@ class LSlang extends LSlog_staticLoggerClass {
// Set the locale
if (setlocale(LC_ALL, $lang) === false)
self :: log("ERROR", "An error occured setting locale to '$lang'");
self :: log_error("An error occured setting locale to '$lang'");
// Configure and set the text domain
$fullpath = bindtextdomain(LS_TEXT_DOMAIN, LS_I18N_DIR_PATH);
self :: log("DEBUG", "setLocale(): Text domain fullpath is '$fullpath'.");
self :: log("DEBUG", "setLocale(): Text domain is : ".textdomain(LS_TEXT_DOMAIN));
self :: log_debug("setLocale(): Text domain fullpath is '$fullpath'.");
self :: log_debug("setLocale(): Text domain is : ".textdomain(LS_TEXT_DOMAIN));
// Include local translation file
$lang_file = LS_I18N_DIR.'/'.$lang.'/lang.php';
if (LSsession :: includeFile($lang_file, false, false))
self :: log("DEBUG", "setLocale(): lang file '$lang_file' loaded.");
self :: log_debug("setLocale(): lang file '$lang_file' loaded.");
else
self :: log("DEBUG", "setLocale(): no lang file found ($lang_file).");
self :: log_debug("setLocale(): no lang file found ($lang_file).");
// Include other local translation file(s)
foreach(array(LS_I18N_DIR_PATH.'/'.$lang, LS_LOCAL_DIR.'/'.LS_I18N_DIR.'/'.$lang) as $lang_dir) {
if (is_dir($lang_dir)) {
foreach (listFiles($lang_dir, '/^lang.+\.php$/') as $file) {
$path = "$lang_dir/$file";
self :: log("DEBUG", "setLocale(): Local '$lang.$encoding' : load translation file '$path'");
self :: log_debug("setLocale(): Local '$lang.$encoding' : load translation file '$path'");
include($path);
}
}
@ -114,7 +114,7 @@ class LSlang extends LSlog_staticLoggerClass {
}
else {
if ($encoding && $lang) $lang .= '.'.$encoding;
self :: log("ERROR", "The local '$lang' does not exists, use default one.");
self :: log_error("The local '$lang' does not exists, use default one.");
}
}

View file

@ -20,6 +20,8 @@
******************************************************************************/
LSsession :: loadLSclass('LSlog_staticLoggerClass');
/**
* Gestion de l'accès à l'annaire Ldap
*
@ -27,7 +29,7 @@
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSldap {
class LSldap extends LSlog_staticLoggerClass {
private static $config;
private static $cnx = NULL;
@ -139,7 +141,7 @@ class LSldap {
LSerror :: addErrorCode('LSldap_02',$ret -> getMessage());
return;
}
LSdebug("LSldap::search() : return ".$ret->count()." objet(s)");
self :: log_debug("LSldap::search() : return ".$ret->count()." objet(s)");
$retInfos=array();
foreach($ret as $dn => $entry) {
if (!$entry instanceof Net_LDAP2_Entry) {
@ -291,7 +293,7 @@ class LSldap {
* @retval boolean true si l'objet a bien été mis à jour, false sinon
*/
public static function update($object_type,$dn,$change) {
LSdebug($change);
self :: log_debug($change);
$dropAttr=array();
$entry=self :: getEntry($object_type,$dn);
if (is_array($entry)) {
@ -325,19 +327,19 @@ class LSldap {
}
if (isset($changeData)) {
$entry -> replace($changeData);
LSdebug('change : <pre>'.print_r($changeData,true).'</pre>');
LSdebug('drop : <pre>'.print_r($dropAttr,true).'</pre>');
self :: log_debug('change : <pre>'.print_r($changeData,true).'</pre>');
self :: log_debug('drop : <pre>'.print_r($dropAttr,true).'</pre>');
}
else {
LSdebug('No change');
self :: log_debug('No change');
}
if ($new) {
LSdebug('LSldap :: add()');
self :: log_debug('LSldap :: add()');
$ret = self :: $cnx -> add($entry);
}
else {
LSdebug('LSldap :: update()');
self :: log_debug('LSldap :: update()');
$ret = $entry -> update();
}

View file

@ -344,9 +344,9 @@ class LSldapObject extends LSlog_staticLoggerClass {
}
}
if($this -> validateAttrsData($idForm)) {
self :: log("DEBUG", "les données sont validées");
self :: log_debug("les données sont validées");
if ($justValidate) {
self :: log("DEBUG", 'Just validate mode');
self :: log_debug('Just validate mode');
return True;
}
@ -362,7 +362,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
}
if ($this -> submitChange($idForm)) {
self :: log("DEBUG", 'Les modifications sont submitées');
self :: log_debug('Les modifications sont submitées');
// Event After Modify
$this -> fireEvent('after_modify');
@ -591,7 +591,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
if(($attr -> isUpdate())&&($attr -> isValidate())) {
if(($attr -> name == $this -> getConfig('rdn')) && (!$new)) {
$new = true;
self :: log("DEBUG", 'Rename');
self :: log_debug('Rename');
if (!$this -> fireEvent('before_rename')) {
LSerror :: addErrorCode('LSldapObject_16');
return;
@ -627,7 +627,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
$dn=$this -> getDn();
if($dn) {
$this -> dn=$dn;
self :: log("DEBUG", $submitData);
self :: log_debug($submitData);
if ($new) {
if (!$this -> fireEvent('before_create')) {
LSerror :: addErrorCode('LSldapObject_20');
@ -1143,7 +1143,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
);
}
else {
self :: log("DEBUG", 'Problème durant la mise en cache de la relation '.$relation_name);
self :: log_debug('Problème durant la mise en cache de la relation '.$relation_name);
return;
}
}
@ -1267,7 +1267,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
* @retval True en cas de cas ce succès, False sinon.
*/
private function afterCreate() {
self :: log("DEBUG", 'after');
self :: log_debug('after');
$error = 0;
// container_auto_create
@ -1279,7 +1279,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
if (isset($conf_type['container_auto_create'])&&isset($conf_type['container_dn'])) {
$dn = $conf_type['container_dn'].','.$this -> getDn();
if(!LSldap :: getNewEntry($dn,$conf_type['container_auto_create']['objectclass'],$conf_type['container_auto_create']['attrs'],true)) {
self :: log("DEBUG", "Impossible de créer l'entrée fille : ".print_r(
self :: log_debug("Impossible de créer l'entrée fille : ".print_r(
array(
'dn' => $dn,
'objectClass' => $conf_type['container_auto_create']['objectclass'],
@ -1911,7 +1911,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
$obj = new $objType();
if (!$obj->loadData($dn)) {
self :: log("FATAL", "Fail to load object $dn data from LDAP");
self :: log_fatal("Fail to load object $dn data from LDAP");
return false;
}
@ -1962,7 +1962,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
}
}
else {
self :: log("ERROR", "Fail to load related objects.");
self :: log_error("Fail to load related objects.");
}
echo "\n";
}
@ -2036,7 +2036,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
$obj = new $objType();
if (!$obj->loadData($dn)) {
self :: log("FATAL", "Fail to load object $dn data from LDAP");
self :: log_fatal("Fail to load object $dn data from LDAP");
return false;
}
@ -2054,10 +2054,10 @@ class LSldapObject extends LSlog_staticLoggerClass {
}
if ($obj -> remove()) {
self :: log("INFO", "Object ".$obj->getDn()." removed.");
self :: log_info("Object ".$obj->getDn()." removed.");
return true;
}
self :: log("ERROR", "Fail to remove object ".$obj->getDn().".");
self :: log_error("Fail to remove object ".$obj->getDn().".");
return false;
}
@ -2110,17 +2110,17 @@ class LSldapObject extends LSlog_staticLoggerClass {
$obj = new $objType();
if (!$obj->loadData($dn)) {
self :: log("FATAL", "Fail to load object $dn data from LDAP");
self :: log_fatal("Fail to load object $dn data from LDAP");
return false;
}
if (!LSsession :: loadLSclass('LSrelation')) {
self :: log("FATAL", "Fail to load LSrelation class.");
self :: log_fatal("Fail to load LSrelation class.");
return false;
}
if (!is_array($obj -> getConfig("LSrelation.$relName"))) {
self :: log("FATAL", "LSobject $objType have no relation '$relName'.");
self :: log_fatal("LSobject $objType have no relation '$relName'.");
return false;
}
@ -2134,7 +2134,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
$listDns[] = $o -> getDn();
}
}
self :: log("DEBUG", "Current related object(s) :".varDump($listDns));
self :: log_debug("Current related object(s) :".varDump($listDns));
// Keep a copy of initial related objects list
$initialListDns = $listDns;
@ -2151,7 +2151,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
foreach ($add as $dn) {
// Check if DN is already in relation
if (in_array($dn, $listDns)) {
self :: log("DEBUG", "LSobject $relatedLSobject $dn is already in relation with ".$obj -> getDn().".");
self :: log_debug("LSobject $relatedLSobject $dn is already in relation with ".$obj -> getDn().".");
continue;
}
@ -2160,7 +2160,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
$search -> run(false);
$result = $search -> listObjectsDn();
if (!is_array($result) || count($result) != 1) {
self :: log("ERROR", "No $relatedLSobject found for DN $dn");
self :: log_error("No $relatedLSobject found for DN $dn");
return false;
}
$listDns[] = $dn;
@ -2176,20 +2176,20 @@ class LSldapObject extends LSlog_staticLoggerClass {
unset($listDns[$key]);
}
if (!$found)
self :: log("DEBUG", "LSobject $relatedLSobject $dn is not in relation with ".$obj -> getDn().".");
self :: log_debug("LSobject $relatedLSobject $dn is not in relation with ".$obj -> getDn().".");
}
if ($initialListDns == $listDns) {
self :: log("INFO", 'No changes done.');
self :: log_info('No changes done.');
return True;
}
self :: log("DEBUG", "New related object(s) list: ".varDump($listDns));
self :: log_debug("New related object(s) list: ".varDump($listDns));
if ($relation -> updateRelations($listDns)) {
self :: log("INFO", 'Objects in relation updated.');
self :: log_info('Objects in relation updated.');
return True;
}
self :: log("ERROR", "Fail to update objects in relation");
self :: log_error("Fail to update objects in relation");
return False;
}
}

View file

@ -98,7 +98,7 @@ class LStemplate extends LSlog_staticLoggerClass {
self :: $_smarty -> template_dir = self :: $config['template_dir'];
if ( ! is_writable(self :: $config['compile_dir']) ) {
self :: log("FATAL", getFData(_("LStemplate : compile directory is not writable (dir : %{dir})"), self :: $config['compile_dir']));
self :: log_fatal(getFData(_("LStemplate : compile directory is not writable (dir : %{dir})"), self :: $config['compile_dir']));
}
self :: $_smarty -> compile_dir = self :: $config['compile_dir'];
@ -196,7 +196,7 @@ class LStemplate extends LSlog_staticLoggerClass {
// Checks that the file is in the actual folder location
$pos = strpos($file_path, $dir_path);
if (!is_int($pos) || $pos != 0) {
self :: log("ERROR", "LStemplate :: getFilePath($file, $root_dir, $default_dir, $with_nocache) : File '$file_path' is not in root directory '$dir_path' (".varDump($pos).").");
self :: log_error("LStemplate :: getFilePath($file, $root_dir, $default_dir, $with_nocache) : File '$file_path' is not in root directory '$dir_path' (".varDump($pos).").");
}
elseif (file_exists($file_path)) {
$path = $file_path;
@ -276,7 +276,7 @@ class LStemplate extends LSlog_staticLoggerClass {
**/
public static function getTemplatePath($template, $with_nocache=false) {
if (in_array($template, self :: $deprecated_template_files))
self :: log("FATAL",
self :: log_fatal(
getFData(
_("LStemplate : Request template '%{tpl}' is now deprecated. Please refer to upgrade documentation to adapt your templates."),
$template

View file

@ -82,14 +82,14 @@ class LSurl extends LSlog_staticLoggerClass {
);
}
elseif ($override) {
self :: log("\Udebug", "URL : override pattern '$pattern' with handler '$handler' (old handler = '".self :: $patterns[$pattern]."')");
self :: log_debug("URL : override pattern '$pattern' with handler '$handler' (old handler = '".self :: $patterns[$pattern]."')");
self :: $patterns[$pattern] = array(
'handler' => $handler,
'authenticated' => $authenticated,
);
}
else {
self :: log("DEBUG", "URL : pattern '$pattern' already defined : do not override.");
self :: log_debug("URL : pattern '$pattern' already defined : do not override.");
}
}
}
@ -105,16 +105,16 @@ class LSurl extends LSlog_staticLoggerClass {
private static function get_request($default_url=null) {
$current_url = self :: get_current_url();
if (is_null($current_url)) {
self :: log("FATAL", _("Fail to determine the requested URL."));
self :: log_fatal(_("Fail to determine the requested URL."));
exit();
}
if (!is_array(self :: $patterns)) {
self :: log("FATAL", 'No URL patterns configured !');
self :: log_fatal('No URL patterns configured !');
exit();
}
self :: log("DEBUG", "URL : current url = '$current_url'");
self :: log("DEBUG", "URL : check current url with the following URL patterns :\n - ".implode("\n - ", array_keys(self :: $patterns)));
self :: log_debug("URL : current url = '$current_url'");
self :: log_debug("URL : check current url with the following URL patterns :\n - ".implode("\n - ", array_keys(self :: $patterns)));
foreach (self :: $patterns as $pattern => $handler_infos) {
$m = self :: url_match($pattern, $current_url);
if (is_array($m)) {
@ -122,16 +122,16 @@ class LSurl extends LSlog_staticLoggerClass {
// Reset last redirect
if (isset($_SESSION['last_redirect']))
unset($_SESSION['last_redirect']);
self :: log("DEBUG", "URL : result :\n".varDump($request, 1));
self :: log_debug("URL : result :\n".varDump($request, 1));
return $request;
}
}
if (!is_null($default_url)) {
self :: log("DEBUG", "Current URL match with no pattern. Redirect to default URL ('$default_url')");
self :: log_debug("Current URL match with no pattern. Redirect to default URL ('$default_url')");
self :: redirect($default_url);
exit();
}
self :: log("DEBUG", "Current URL match with no pattern. Use error 404 handler.");
self :: log_debug("Current URL match with no pattern. Use error 404 handler.");
return new LSurlRequest(
$current_url,
array(
@ -155,7 +155,7 @@ class LSurl extends LSlog_staticLoggerClass {
if (!$current_url) return False;
}
if (preg_match($pattern, $current_url, $m)) {
self :: log("DEBUG", "URL : Match found with pattern '$pattern' :\n\t".str_replace("\n", "\n\t", print_r($m, 1)));
self :: log_debug("URL : Match found with pattern '$pattern' :\n\t".str_replace("\n", "\n\t", print_r($m, 1)));
return $m;
}
return False;
@ -169,7 +169,7 @@ class LSurl extends LSlog_staticLoggerClass {
public static function get_current_url() {
if (array_key_exists(self :: REWRITED_REQUEST_PARAM, $_REQUEST))
return $_REQUEST[self :: REWRITED_REQUEST_PARAM];
self :: log("WARNING", 'LSurl : Rewrite request param not present, try to detect current URL.');
self :: log_warning('LSurl : Rewrite request param not present, try to detect current URL.');
return self :: detect_current_url();
}
@ -187,13 +187,13 @@ class LSurl extends LSlog_staticLoggerClass {
$public_root_url = LSconfig :: get('public_root_url', '/', 'string');
if ($public_root_url[0] == '/') {
self :: log("DEBUG", "LSurl :: get_public_absolute_url($relative_url): configured public root URL is relative ($public_root_url) => try to detect it from current request infos.");
self :: log_debug("LSurl :: get_public_absolute_url($relative_url): configured public root URL is relative ($public_root_url) => try to detect it from current request infos.");
$public_root_url = 'http'.(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'?'s':'').'://'.$_SERVER['HTTP_HOST'].$public_root_url;
self :: log("DEBUG", "LSurl :: get_public_absolute_url($relative_url): detected public_root_url: $public_root_url");
self :: log_debug("LSurl :: get_public_absolute_url($relative_url): detected public_root_url: $public_root_url");
}
$url = self :: remove_trailing_slash($public_root_url)."/$relative_url";
self :: log("DEBUG", "LSurl :: get_public_absolute_url($relative_url): result = $url");
self :: log_debug("LSurl :: get_public_absolute_url($relative_url): result = $url");
return $url;
}
@ -222,11 +222,11 @@ class LSurl extends LSlog_staticLoggerClass {
// Prevent loop
if (isset($_SESSION['last_redirect']) && $_SESSION['last_redirect'] == $url)
self :: log("FATAL", _("Fail to determine the requested URL (loop detected)."));
self :: log_fatal(_("Fail to determine the requested URL (loop detected)."));
else
$_SESSION['last_redirect'] = $url;
self :: log("DEBUG", "redirect($go) => Redirect to : <$url>");
self :: log_debug("redirect($go) => Redirect to : <$url>");
header("Location: $url");
// Set & display template
@ -260,8 +260,8 @@ class LSurl extends LSlog_staticLoggerClass {
$request = self :: get_request($default_url);
if (!is_callable($request -> handler)) {
self :: log("ERROR", "URL handler function ".$request -> handler."() does not exists !");
self :: log("FATAL", "This request could not be handled.");
self :: log_error("URL handler function ".$request -> handler."() does not exists !");
self :: log_fatal("This request could not be handled.");
}
if (class_exists('LStemplate'))
@ -278,7 +278,7 @@ class LSurl extends LSlog_staticLoggerClass {
}
catch (Exception $e) {
self :: log_exception($e, "An exception occured running URL handler function ".$request -> handler."()");
self :: log("FATAL", "This request could not be processed correctly.");
self :: log_fatal("This request could not be processed correctly.");
}
}
@ -292,16 +292,16 @@ class LSurl extends LSlog_staticLoggerClass {
* @retval string|false The current request URL or false if detection fail
**/
private static function detect_current_url() {
self :: log("DEBUG", "URL : request URI = '".$_SERVER['REQUEST_URI']."'");
self :: log_debug("URL : request URI = '".$_SERVER['REQUEST_URI']."'");
$base = self :: get_rewrite_base();
self :: log("DEBUG", "URL : rewrite base = '$base'");
self :: log_debug("URL : rewrite base = '$base'");
if ($_SERVER['REQUEST_URI'] == $base)
return '';
if (substr($_SERVER['REQUEST_URI'], 0, strlen($base)) != $base) {
self :: log("ERROR", "URL : request URI (".$_SERVER['REQUEST_URI'].") does not start with rewrite base ($base)");
self :: log_error("URL : request URI (".$_SERVER['REQUEST_URI'].") does not start with rewrite base ($base)");
return False;
}