mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-22 09:59:06 +01:00
Compare commits
6 commits
6cfde7f084
...
000222ae89
Author | SHA1 | Date | |
---|---|---|---|
|
000222ae89 | ||
|
b5b540de65 | ||
|
4c7f6847fd | ||
|
9f2cbeca6f | ||
|
0e8009420c | ||
|
9224c54304 |
11 changed files with 447 additions and 229 deletions
|
@ -6,6 +6,8 @@ Cette section décrit le tableau de configuration de la journalisation de l'appl
|
||||||
$GLOBALS['LSlog'] = array(
|
$GLOBALS['LSlog'] = array(
|
||||||
'enable' => [booléen],
|
'enable' => [booléen],
|
||||||
'level' => '[niveau]',
|
'level' => '[niveau]',
|
||||||
|
'log_errors_context' => [booléen],
|
||||||
|
'log_errors_context_with_args' => [booléen],
|
||||||
'handlers' => array(
|
'handlers' => array(
|
||||||
'[handler 1]',
|
'[handler 1]',
|
||||||
array (
|
array (
|
||||||
|
@ -53,6 +55,17 @@ $GLOBALS['LSlog'] = array(
|
||||||
- `ERROR`
|
- `ERROR`
|
||||||
- `FATAL`
|
- `FATAL`
|
||||||
|
|
||||||
|
- `log_errors_context`
|
||||||
|
|
||||||
|
Booléen permatant de définir si le contexte _(=backtrace)_ doit être inclus lors de la
|
||||||
|
journalisation d'une erreurs.
|
||||||
|
|
||||||
|
- `log_errors_context_with_args`
|
||||||
|
|
||||||
|
Booléen permatant de définir si les arguments des méthodes/fonctions appelées doivent être
|
||||||
|
inclus lors de la journalisation du contexte des erreurs.
|
||||||
|
__Note :__ ce paramètre n'as aucun effet si le paramètre `log_errors_context` n'est pas activé.
|
||||||
|
|
||||||
- `handlers`
|
- `handlers`
|
||||||
|
|
||||||
Tableau permettant de configurer les *handlers* de la journalisation. Chaque *handler* gère les
|
Tableau permettant de configurer les *handlers* de la journalisation. Chaque *handler* gère les
|
||||||
|
|
|
@ -204,60 +204,77 @@ define('LS_CSS_DIR', 'css');
|
||||||
define('LSdebug',false);
|
define('LSdebug',false);
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
$GLOBALS['LSlog']['handlers'] = array (
|
$GLOBALS['LSlog'] = array (
|
||||||
array (
|
// Enable/disable logs
|
||||||
'handler' => 'file',
|
'enable' => true,
|
||||||
'path' => 'tmp/LS.log',
|
|
||||||
//'level' => 'DEBUG',
|
// Global logs level (TRACE, DEBUG, INFO, WARNING, ERROR, FATAL)
|
||||||
//'enabled' => false, // Uncomment to disable this handler
|
'level' => 'INFO',
|
||||||
// Filter on specific loggers
|
|
||||||
//'loggers' => array('LSurl', 'LSlang'),
|
// Log errors's context (=backtrace)
|
||||||
'excluded_loggers' => array('generate_lang_file', 'generate_ldapsaisie_pot'),
|
'log_errors_context' => true,
|
||||||
// Default formats
|
|
||||||
//'format' => '%{requesturi} - %{remoteaddr} - %{ldapservername} - %{authuser} - %{level} - %{message}',
|
// Log errors's context with arguments of called method/functions
|
||||||
//'cli_format' => '%{clibinpath} - %{level} - %{message}',
|
'log_errors_context_with_args' => false,
|
||||||
//'datetime_prefix' => true, // Prefix message with datetime ?
|
|
||||||
//'datetime_format' => 'Y/m/d H:i:s', // Datetime prefix format (see php date() function)
|
/**
|
||||||
|
* Logs handlers are components that logged message emitted by the application.
|
||||||
|
* Each handlers handle emitted message as its own way (storing it in file/database, send it via
|
||||||
|
* email or to an external backend, ...).
|
||||||
|
*/
|
||||||
|
'handlers' => array (
|
||||||
|
array(
|
||||||
|
'handler' => 'file',
|
||||||
|
'path' => 'tmp/LS.log',
|
||||||
|
//'level' => 'DEBUG',
|
||||||
|
//'enabled' => false, // Uncomment to disable this handler
|
||||||
|
// Filter on specific loggers
|
||||||
|
//'loggers' => array('LSurl', 'LSlang'),
|
||||||
|
'excluded_loggers' => array('generate_lang_file', 'generate_ldapsaisie_pot'),
|
||||||
|
// Default formats
|
||||||
|
//'format' => '%{requesturi} - %{remoteaddr} - %{ldapservername} - %{authuser} - %{level} - %{message}',
|
||||||
|
//'cli_format' => '%{clibinpath} - %{level} - %{message}',
|
||||||
|
//'datetime_prefix' => true, // Prefix message with datetime ?
|
||||||
|
//'datetime_format' => 'Y/m/d H:i:s', // Datetime prefix format (see php date() function)
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'handler' => 'email', // Email handler (each logged message generated an email)
|
||||||
|
'level' => 'FATAL',
|
||||||
|
'recipient' => 'root@localhost', // Email recipient
|
||||||
|
),
|
||||||
|
/*
|
||||||
|
array (
|
||||||
|
'handler' => 'syslog', // Syslog handler
|
||||||
|
//'priority' => 'WARNING', // Force priority : EMERG, ALERT, CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG
|
||||||
|
),
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
array (
|
||||||
|
'handler' => 'system', // System logging (using PHP error_log)
|
||||||
|
'level' => 'ERROR',
|
||||||
|
),
|
||||||
|
*/
|
||||||
),
|
),
|
||||||
array (
|
|
||||||
'handler' => 'email', // Email handler (each logged message generated an email)
|
|
||||||
'level' => 'FATAL',
|
|
||||||
'recipient' => 'root@localhost', // Email recipient
|
|
||||||
),
|
|
||||||
/*
|
|
||||||
array (
|
|
||||||
'handler' => 'syslog', // Syslog handler
|
|
||||||
//'priority' => 'WARNING', // Force priority : EMERG, ALERT, CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG
|
|
||||||
),
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
array (
|
|
||||||
'handler' => 'system', // System logging (using PHP error_log)
|
|
||||||
'level' => 'ERROR',
|
|
||||||
),
|
|
||||||
*/
|
|
||||||
);
|
|
||||||
$GLOBALS['LSlog']['loggers'] = array (
|
|
||||||
/**
|
/**
|
||||||
* Loggers permit to define different log parameters for specific components
|
* Loggers permit to define different log parameters for specific components
|
||||||
* of LdapSaisie (a class, an addon, ...). You could :
|
* of LdapSaisie (a class, an addon, ...). You could :
|
||||||
* - Enabled/disabled logs for this component with 'enabled' parameter
|
* - Enabled/disabled logs for this component with 'enabled' parameter
|
||||||
* - Set a specific log level for this component with 'enabled' parameter
|
* - Set a specific log level for this component with 'enabled' parameter
|
||||||
**/
|
**/
|
||||||
/*
|
"loggers" => array(
|
||||||
'LSurl' => array (
|
/*
|
||||||
'level' => 'DEBUG',
|
'LSurl' => array (
|
||||||
|
'level' => 'DEBUG',
|
||||||
|
),
|
||||||
|
'LSldap' => array (
|
||||||
|
'level' => 'DEBUG',
|
||||||
|
),
|
||||||
|
'LSlang' => array (
|
||||||
|
'enabled' => false,
|
||||||
|
),
|
||||||
|
*/
|
||||||
),
|
),
|
||||||
'LSldap' => array (
|
|
||||||
'level' => 'DEBUG',
|
|
||||||
),
|
|
||||||
'LSlang' => array (
|
|
||||||
'enabled' => false,
|
|
||||||
),
|
|
||||||
*/
|
|
||||||
);
|
);
|
||||||
$GLOBALS['LSlog']['level'] = 'INFO'; // TRACE, DEBUG, INFO, WARNING, ERROR, FATAL
|
|
||||||
$GLOBALS['LSlog']['enable'] = true;
|
|
||||||
|
|
||||||
define('NB_LSOBJECT_LIST',30);
|
define('NB_LSOBJECT_LIST',30);
|
||||||
define('NB_LSOBJECT_LIST_SELECT',20);
|
define('NB_LSOBJECT_LIST_SELECT',20);
|
||||||
|
|
|
@ -45,11 +45,17 @@ class LSattr_html_select_object extends LSattr_html{
|
||||||
*
|
*
|
||||||
* @return LSformElement|false L'element du formulaire ajouté, ou false
|
* @return LSformElement|false L'element du formulaire ajouté, ou false
|
||||||
*/
|
*/
|
||||||
public function addToForm (&$form,$idForm,$data=NULL) {
|
public function addToForm (&$form, $idForm, $data=NULL) {
|
||||||
$this -> config['attrObject'] = $this;
|
$this -> config['attrObject'] = $this;
|
||||||
$element=$form -> addElement($this -> LSformElement_type, $this -> name, $this -> getLabel(), $this -> config, $this);
|
$element = $form -> addElement(
|
||||||
|
$this -> LSformElement_type,
|
||||||
|
$this -> name,
|
||||||
|
$this -> getLabel(),
|
||||||
|
$this -> config,
|
||||||
|
$this
|
||||||
|
);
|
||||||
if(!$element) {
|
if(!$element) {
|
||||||
LSerror :: addErrorCode('LSform_06',$this -> name);
|
LSerror :: addErrorCode('LSform_06', $this -> name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($data) {
|
if ($data) {
|
||||||
|
@ -71,8 +77,8 @@ class LSattr_html_select_object extends LSattr_html{
|
||||||
*
|
*
|
||||||
* @return array La valeur formatée de l'attribut (array('DNs' => 'displayName'))
|
* @return array La valeur formatée de l'attribut (array('DNs' => 'displayName'))
|
||||||
**/
|
**/
|
||||||
public function refreshForm($data,$fromDNs=false) {
|
public function refreshForm($data, $fromDNs=false) {
|
||||||
return $this -> getFormValues($data,$fromDNs);
|
return $this -> getFormValues($data, $fromDNs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -174,8 +180,8 @@ class LSattr_html_select_object extends LSattr_html{
|
||||||
*
|
*
|
||||||
* @param mixed $values array|null Array of the input values ()
|
* @param mixed $values array|null Array of the input values ()
|
||||||
* @param boolean $fromDNs boolean If true, considered provided values as DNs (default: false)
|
* @param boolean $fromDNs boolean If true, considered provided values as DNs (default: false)
|
||||||
* @param boolean $retrieveAttrValues boolean If true, attribute values will be returned instead
|
* @param boolean $retrieveAttrValues boolean If true, final attribute values will be returned
|
||||||
* of selected objects info (default: false)
|
* instead of selected objects info (default: false)
|
||||||
*
|
*
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*
|
*
|
||||||
|
@ -193,139 +199,172 @@ class LSattr_html_select_object extends LSattr_html{
|
||||||
self :: log_warning('getFormValues(): $values is not array');
|
self :: log_warning('getFormValues(): $values is not array');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!LSsession :: loadLSclass("LSsearch"))
|
||||||
|
return false;
|
||||||
|
|
||||||
// Retrieve/check selectable objects config
|
// Retrieve/check selectable objects config
|
||||||
$objs = array();
|
$objs = [];
|
||||||
$confs = $this -> getSelectableObjectsConfig($objs);
|
$confs = $this -> getSelectableObjectsConfig($objs);
|
||||||
if (!is_array($confs) || empty($confs)) {
|
if (!is_array($confs) || empty($confs)) {
|
||||||
self :: log_warning('getFormValues(): invalid selectable objects config');
|
self :: log_warning('getFormValues(): invalid selectable objects config');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$selected_objects = array();
|
$selected_objects = [];
|
||||||
$unrecognizedValues = array();
|
$found_values = [];
|
||||||
$found_values = array();
|
$unrecognizedValues = [];
|
||||||
foreach ($confs as $conf) {
|
foreach ($confs as $conf) {
|
||||||
|
$common_search_params = [
|
||||||
|
"filter" => $conf['filter'],
|
||||||
|
"attributes" => (
|
||||||
|
$retrieveAttrValues && !in_array($conf['value_attribute'], ["dn", "%{dn}"])?
|
||||||
|
[$conf['value_attribute']]:
|
||||||
|
[$objs[$conf['object_type']]->rdn_attr]
|
||||||
|
),
|
||||||
|
"displayFormat" => (
|
||||||
|
$conf['display_name_format']?
|
||||||
|
$conf['display_name_format']:
|
||||||
|
$objs[$conf['object_type']] -> getDisplayNameFormat()
|
||||||
|
),
|
||||||
|
];
|
||||||
foreach($values as $value) {
|
foreach($values as $value) {
|
||||||
// If we already mark its value as unrecognized, pass
|
// Ignore empty value and value already marked as unrecognized
|
||||||
if (in_array($value, $unrecognizedValues))
|
if (empty($value) || in_array($value, $unrecognizedValues))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Ignore empty value
|
// Compute search params based on value attribute type (DN or attribute valued) and $fromDNs
|
||||||
if (empty($value))
|
if($fromDNs || in_array($conf['value_attribute'], ['dn', '%{dn}'])) {
|
||||||
continue;
|
if (!checkDn($value)) {
|
||||||
|
self :: log_warning(
|
||||||
// Determine value attribute: DN/attribute valued (or force form DNs)
|
"getFormValues(): value '$value' is not a valid DN, pass"
|
||||||
if(($conf['value_attribute']=='dn') || ($conf['value_attribute']=='%{dn}') || $fromDNs) {
|
);
|
||||||
// Construct resulting list from DN values
|
|
||||||
if ($conf['onlyAccessible']) {
|
|
||||||
if (!LSsession :: canAccess($conf['object_type'], $value)) {
|
|
||||||
self :: log_debug("getFormValues(): ".$conf['object_type']."($value): not accessible, pass");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load object data (with custom filter if defined)
|
|
||||||
if(!$objs[$conf['object_type']] -> loadData($value, $conf['filter'])) {
|
|
||||||
self :: log_debug("getFormValues(): ".$conf['object_type']."($value): not found, pass");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
self :: log_debug("getFormValues(): ".$conf['object_type']."($value): found");
|
if ($conf['onlyAccessible'] && !LSsession :: canAccess($conf['object_type'], $value)) {
|
||||||
|
self :: log_debug(
|
||||||
// Check if it's the first this value match with an object
|
"getFormValues(): object {$conf['object_type']} '$value' is not accessible, pass"
|
||||||
if (isset($found_values[$value])) {
|
);
|
||||||
// DN match with multiple object type
|
continue;
|
||||||
LSerror :: addErrorCode('LSattr_html_select_object_03',array('val' => $value, 'attribute' => $this -> name));
|
|
||||||
$unrecognizedValues[] = $value;
|
|
||||||
unset($selected_objects[$found_values[$value]]);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
$found_values[$value] = $value;
|
$search_params = array_merge(
|
||||||
|
$common_search_params,
|
||||||
|
["basedn" => $value, "scope" => "base"]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$filter = Net_LDAP2_Filter::create($conf['value_attribute'], 'equals', $value);
|
||||||
|
$search_params = array_merge(
|
||||||
|
$common_search_params,
|
||||||
|
[
|
||||||
|
"filter" => (
|
||||||
|
$common_search_params["filter"]?
|
||||||
|
LSldap::combineFilters('and', [$common_search_params["filter"], $filter]):
|
||||||
|
$filter
|
||||||
|
),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ($retrieveAttrValues) {
|
// Search object
|
||||||
// Retrieve attribute value case: $selected_objects[dn] = attribute value
|
$LSsearch = new LSsearch(
|
||||||
if(($conf['value_attribute']=='dn') || ($conf['value_attribute']=='%{dn}')) {
|
$conf['object_type'],
|
||||||
$selected_objects[$value] = $value;
|
'LSattr_html_select_object::getFormValues',
|
||||||
}
|
$search_params,
|
||||||
else {
|
true
|
||||||
$val = $objs[$conf['object_type']] -> getValue($conf['value_attribute']);
|
);
|
||||||
if (!empty($val)) {
|
|
||||||
$selected_objects[$value] = $val[0];
|
if(!$LSsearch -> run(false)) {
|
||||||
}
|
self :: log_warning(
|
||||||
else {
|
"getFormValues(): error during search of object(s) {$conf['object_type']} ".
|
||||||
LSerror :: addErrorCode(
|
"for value '$value', pass"
|
||||||
'LSattr_html_select_object_06',
|
);
|
||||||
array(
|
continue;
|
||||||
'name' => $objs[$conf['object_type']] -> getDisplayName($conf['display_name_format']),
|
}
|
||||||
'attr' => $this -> name
|
|
||||||
)
|
$entries = $LSsearch -> listEntries();
|
||||||
);
|
if (!is_array($entries) || empty($entries)) {
|
||||||
}
|
self :: log_debug(
|
||||||
}
|
"getFormValues(): value '$value' not found as {$conf['object_type']}, pass"
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($entries) > 1) {
|
||||||
|
self :: log_warning(
|
||||||
|
"getFormValues(): ".count($entries)." objects {$conf['object_type']} found ".
|
||||||
|
"for value '$value', pass: ".implode(" / ", array_keys($entries))
|
||||||
|
);
|
||||||
|
if (array_key_exists($value, $selected_objects))
|
||||||
|
unset($selected_objects[$value]);
|
||||||
|
$unrecognizedValues[] = $value;
|
||||||
|
$found_values[$value] = (
|
||||||
|
array_key_exists($value, $found_values)?
|
||||||
|
array_merge($found_values[$value], array_keys($entries)):
|
||||||
|
array_keys($entries)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$entry = $entries[key($entries)];
|
||||||
|
self :: log_debug(
|
||||||
|
"getFormValues(): value '$value' found as {$conf['object_type']}: {$entry->dn}"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check if it's the first this value match with an object
|
||||||
|
if (array_key_exists($value, $found_values)) {
|
||||||
|
// DN match with multiple object type
|
||||||
|
LSerror :: addErrorCode(
|
||||||
|
'LSattr_html_select_object_03',
|
||||||
|
['val' => $value, 'attribute' => $this -> name]
|
||||||
|
);
|
||||||
|
unset($selected_objects[$value]);
|
||||||
|
$unrecognizedValues[] = $value;
|
||||||
|
$found_values[$value][] = $entry->dn;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$found_values[$value] = [$entry->dn];
|
||||||
|
|
||||||
|
if ($retrieveAttrValues) {
|
||||||
|
// Retrieve attribute value case: $selected_objects[dn] = attribute value
|
||||||
|
if(($conf['value_attribute']=='dn') || ($conf['value_attribute']=='%{dn}')) {
|
||||||
|
$selected_objects[$entry->dn] = $entry->dn;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// General case: $selected_objects[dn] = array(name + object_type)
|
$val = ensureIsArray($entry -> get($conf['value_attribute']));
|
||||||
$selected_objects[$value] = array(
|
if (!empty($val)) {
|
||||||
'name' => $objs[$conf['object_type']] -> getDisplayName($conf['display_name_format']),
|
$selected_objects[$entry->dn] = $val[0];
|
||||||
'object_type' => $conf['object_type'],
|
}
|
||||||
);
|
else {
|
||||||
self :: log_debug("getFormValues(): ".$conf['object_type']."($value): ".varDump($selected_objects[$value]));
|
LSerror :: addErrorCode(
|
||||||
|
'LSattr_html_select_object_06',
|
||||||
|
array(
|
||||||
|
'name' => $entry -> displayName,
|
||||||
|
'attr' => $this -> name
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Construct resulting list from attributes values
|
// General case: $selected_objects[dn] = array(name + object_type)
|
||||||
$filter = Net_LDAP2_Filter::create($conf['value_attribute'], 'equals', $value);
|
$selected_objects[$entry->dn] = array(
|
||||||
if (isset($conf['filter']))
|
'name' => $entry -> displayName,
|
||||||
$filter = LSldap::combineFilters('and', array($filter, $conf['filter']));
|
'object_type' => $conf['object_type'],
|
||||||
$sparams = array();
|
);
|
||||||
$sparams['onlyAccessible'] = $conf['onlyAccessible'];
|
self :: log_debug(
|
||||||
$listobj = $objs[$conf['object_type']] -> listObjectsName(
|
"getFormValues(): object {$conf['object_type']} info for value '$value': ".
|
||||||
$filter,
|
varDump($selected_objects[$entry->dn])
|
||||||
NULL,
|
|
||||||
$sparams,
|
|
||||||
$conf['display_name_format']
|
|
||||||
);
|
);
|
||||||
if (count($listobj)==1) {
|
|
||||||
if (isset($found_values[$value])) {
|
|
||||||
// Value match with multiple object type
|
|
||||||
LSerror :: addErrorCode('LSattr_html_select_object_03',array('val' => $value, 'attribute' => $this -> name));
|
|
||||||
$unrecognizedValues[] = $value;
|
|
||||||
unset($selected_objects[$found_values[$value]]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$dn = key($listobj);
|
|
||||||
$selected_objects[$dn] = array(
|
|
||||||
'name' => $listobj[$dn],
|
|
||||||
'object_type' => $conf['object_type'],
|
|
||||||
);
|
|
||||||
$found_values[$value] = $dn;
|
|
||||||
}
|
|
||||||
else if(count($listobj) > 1) {
|
|
||||||
LSerror :: addErrorCode('LSattr_html_select_object_03',array('val' => $value, 'attribute' => $this -> name));
|
|
||||||
if (!in_array($value, $unrecognizedValues))
|
|
||||||
$unrecognizedValues[] = $value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if all values have been found (or already considered as unrecognized)
|
|
||||||
foreach ($values as $value) {
|
|
||||||
if (!isset($found_values[$value]) && !in_array($value, $unrecognizedValues)) {
|
|
||||||
self :: log_debug("getFormValues(): value '$value' not recognized");
|
|
||||||
$unrecognizedValues[] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve attribute values case: return forged array values (list of attribute values)
|
// Retrieve attribute values case: return forged array values (list of attribute values)
|
||||||
if ($retrieveAttrValues)
|
if ($retrieveAttrValues)
|
||||||
return array_values($selected_objects);
|
return array_values($selected_objects);
|
||||||
|
|
||||||
// General case
|
// General case
|
||||||
self :: log_debug("getFormValues(): unrecognizedValues=".varDump($unrecognizedValues));
|
$this -> unrecognizedValues = array_diff($values, array_keys($found_values));
|
||||||
$this -> unrecognizedValues = $unrecognizedValues;
|
self :: log_debug("getFormValues(): unrecognizedValues=".varDump($this -> unrecognizedValues));
|
||||||
|
|
||||||
self :: log_debug("getFormValues(): final values=".varDump($selected_objects));
|
self :: log_debug("getFormValues(): final values=".varDump($selected_objects));
|
||||||
return $selected_objects;
|
return $selected_objects;
|
||||||
}
|
}
|
||||||
|
@ -347,7 +386,7 @@ class LSattr_html_select_object extends LSattr_html{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return array of atttribute values form array of form values
|
* Return array of attribute values form array of form values
|
||||||
*
|
*
|
||||||
* @param mixed $values Array of form values
|
* @param mixed $values Array of form values
|
||||||
*
|
*
|
||||||
|
|
|
@ -140,7 +140,8 @@ class LSformElement_select_object extends LSformElement {
|
||||||
$this -> attr_html -> getLSselectId(),
|
$this -> attr_html -> getLSselectId(),
|
||||||
$select_conf,
|
$select_conf,
|
||||||
boolval($this -> getParam('multiple', 0, 'int')),
|
boolval($this -> getParam('multiple', 0, 'int')),
|
||||||
$this -> values
|
$this -> values,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
|
|
@ -462,8 +462,17 @@ class LSldap extends LSlog_staticLoggerClass {
|
||||||
*
|
*
|
||||||
* @return boolean True if entry exists, false otherwise
|
* @return boolean True if entry exists, false otherwise
|
||||||
*/
|
*/
|
||||||
public static function exists($dn) {
|
public static function exists($dn, $filter=null) {
|
||||||
return is_a(self :: getLdapEntry($dn), 'Net_LDAP2_Entry');
|
$entry = self :: search(
|
||||||
|
$filter?$filter:"(objectClass=*)",
|
||||||
|
$dn,
|
||||||
|
[
|
||||||
|
"scope" => "base",
|
||||||
|
"attronly" => true,
|
||||||
|
"attributes" => ["objectClass"],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
return boolval($entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -149,6 +149,23 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the specified object exists
|
||||||
|
* @param string $dn Object's DN
|
||||||
|
* @param string|Net_LDAP2_Filter|null $filter Extra LDAP that object must match (optional, default: null)
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function exists($dn, $filter=null) {
|
||||||
|
return LSldap::exists(
|
||||||
|
$dn,
|
||||||
|
(
|
||||||
|
$filter?
|
||||||
|
LSldap::combineFilters("and", [static :: _getObjectFilter(), $filter]):
|
||||||
|
static :: _getObjectFilter()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load object data from LDAP
|
* Load object data from LDAP
|
||||||
*
|
*
|
||||||
|
@ -901,40 +918,43 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne le filtre correpondants aux objetcClass de l'objet courant
|
* Return LDAP filter string of the current object type
|
||||||
*
|
*
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*
|
*
|
||||||
* @return Net_LDAP2_Filter le filtre ldap correspondant au type de l'objet
|
* @return Net_LDAP2_Filter LDAP filter as a Net_LDAP2_Filter object, or false in case of error
|
||||||
*/
|
*/
|
||||||
public function getObjectFilter() {
|
public function getObjectFilter() {
|
||||||
return self :: _getObjectFilter($this -> type_name);
|
return self :: _getObjectFilter($this -> type_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne le filtre correpondants aux objetcClass de l'objet
|
* Return object type LDAP filter string
|
||||||
|
*
|
||||||
|
* @param string|null $type Object type (optional, default: called class)
|
||||||
*
|
*
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*
|
*
|
||||||
* @return Net_LDAP2_Filter|false le filtre ldap correspondant au type de l'objet, ou false
|
* @return Net_LDAP2_Filter|false LDAP filter as a Net_LDAP2_Filter object, or false in case of error
|
||||||
*/
|
*/
|
||||||
public static function _getObjectFilter($type) {
|
public static function _getObjectFilter($type=null) {
|
||||||
$oc=LSconfig::get("LSobjects.$type.objectclass");
|
$type = $type?$type:get_called_class();
|
||||||
if(!is_array($oc)) return false;
|
$oc = LSconfig::get("LSobjects.$type.objectclass");
|
||||||
$filters=array();
|
if(!is_array($oc) || !$oc) return false;
|
||||||
|
$filters = [];
|
||||||
foreach ($oc as $class) {
|
foreach ($oc as $class) {
|
||||||
$filters[]=Net_LDAP2_Filter::create('objectClass','equals',$class);
|
$filters[] = Net_LDAP2_Filter::create('objectClass', 'equals', $class);
|
||||||
}
|
}
|
||||||
|
|
||||||
$filter=LSconfig::get("LSobjects.$type.filter");
|
$filter = LSconfig::get("LSobjects.$type.filter");
|
||||||
if ($filter) {
|
if ($filter) {
|
||||||
$filters[]=Net_LDAP2_Filter::parse($filter);
|
$filters[] = Net_LDAP2_Filter::parse($filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
$filter = LSldap::combineFilters('and',$filters);
|
$filter = LSldap::combineFilters('and', $filters);
|
||||||
if ($filter)
|
if ($filter)
|
||||||
return $filter;
|
return $filter;
|
||||||
LSerror :: addErrorCode('LSldapObject_30',$type);
|
LSerror :: addErrorCode('LSldapObject_30', $type);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1004,37 +1024,40 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
||||||
*
|
*
|
||||||
* @param Net_LDAP2_Filter|string|null $filter LDAP search filter
|
* @param Net_LDAP2_Filter|string|null $filter LDAP search filter
|
||||||
* @param string|null $sbasedn Base DN of the search
|
* @param string|null $sbasedn Base DN of the search
|
||||||
* @param array $sparams Search parameters (as expected by Net_LDAP2::search())
|
* @param array|null $sparams Search parameters (as expected by Net_LDAP2::search())
|
||||||
* @param string|false $displayFormat LSformat of objects's display name
|
* @param string|false $displayFormat LSformat of objects's display name
|
||||||
* @param bool $cache Enable/disable cache (default: true)
|
* @param bool $cache Enable/disable cache (default: true)
|
||||||
*
|
*
|
||||||
* @return array|false Tableau dn => name correspondant au resultat de la recherche, ou false
|
* @return array|false Tableau dn => name correspondant au resultat de la recherche, ou false
|
||||||
*/
|
*/
|
||||||
public function listObjectsName($filter=NULL,$sbasedn=NULL,$sparams=array(),$displayFormat=false,$cache=true) {
|
public function listObjectsName($filter=NULL, $sbasedn=NULL, $sparams=null, $displayFormat=false, $cache=true) {
|
||||||
if (!LSsession :: loadLSclass('LSsearch')) {
|
if (!LSsession :: loadLSclass('LSsearch')) {
|
||||||
LSerror::addErrorCode('LSsession_05','LSsearch');
|
LSerror::addErrorCode('LSsession_05', 'LSsearch');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$displayFormat) {
|
$params = [
|
||||||
$displayFormat = $this -> getDisplayNameFormat();
|
'displayFormat' => $displayFormat?$displayFormat:$this -> getDisplayNameFormat(),
|
||||||
}
|
|
||||||
|
|
||||||
$params = array(
|
|
||||||
'displayFormat' => $displayFormat,
|
|
||||||
'basedn' => $sbasedn,
|
'basedn' => $sbasedn,
|
||||||
'filter' => $filter
|
'filter' => $filter
|
||||||
|
];
|
||||||
|
|
||||||
|
$LSsearch = new LSsearch(
|
||||||
|
$this -> type_name,
|
||||||
|
'LSldapObject::listObjectsName',
|
||||||
|
(
|
||||||
|
is_array($sparams)?
|
||||||
|
$params = array_merge($sparams, $params):
|
||||||
|
$sparams
|
||||||
|
),
|
||||||
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
if (is_array($sparams)) {
|
return (
|
||||||
$params=array_merge($sparams,$params);
|
$LSsearch -> run($cache)?
|
||||||
}
|
$LSsearch -> listObjectsName():
|
||||||
|
false
|
||||||
$LSsearch = new LSsearch($this -> type_name,'LSldapObject::listObjectsName',$params,true);
|
);
|
||||||
|
|
||||||
$LSsearch -> run($cache);
|
|
||||||
|
|
||||||
return $LSsearch -> listObjectsName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,18 @@ class LSlog {
|
||||||
*/
|
*/
|
||||||
private static $enabled = false;
|
private static $enabled = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log errors context
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private static $log_errors_context = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log errors context with arguments
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private static $log_errors_context_with_args = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configured handlers
|
* Configured handlers
|
||||||
* @see self::start()
|
* @see self::start()
|
||||||
|
@ -91,6 +103,8 @@ class LSlog {
|
||||||
public static function start() {
|
public static function start() {
|
||||||
// Load configuration
|
// Load configuration
|
||||||
self :: $enabled = self :: getConfig('enable', false, 'bool');
|
self :: $enabled = self :: getConfig('enable', false, 'bool');
|
||||||
|
self :: $log_errors_context = self :: getConfig('log_errors_context', false, 'bool');
|
||||||
|
self :: $log_errors_context_with_args = self :: getConfig('log_errors_context_with_args', false, 'bool');
|
||||||
self :: setLevel();
|
self :: setLevel();
|
||||||
|
|
||||||
// Load default handlers class
|
// Load default handlers class
|
||||||
|
@ -252,6 +266,13 @@ class LSlog {
|
||||||
$message = varDump($message);
|
$message = varDump($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Append context to message (if enabled)
|
||||||
|
if (self :: $log_errors_context && self :: checkLevel($level, "ERROR"))
|
||||||
|
$message .= "\n".self :: get_debug_backtrace_context(
|
||||||
|
self :: $log_errors_context_with_args,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
foreach (self :: $handlers as $handler) {
|
foreach (self :: $handlers as $handler) {
|
||||||
// Check handler level
|
// Check handler level
|
||||||
if (!$handler -> checkLevel($level))
|
if (!$handler -> checkLevel($level))
|
||||||
|
@ -310,25 +331,34 @@ class LSlog {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate current context backtrace
|
* Generate current context backtrace
|
||||||
*
|
* @param bool $with_args Add args (optional, default: false)
|
||||||
|
* @param int|null $ignore_last_frames Ignore last frames (optional, default: 1)
|
||||||
* @return string Current context backtrace
|
* @return string Current context backtrace
|
||||||
**/
|
**/
|
||||||
public static function get_debug_backtrace_context() {
|
public static function get_debug_backtrace_context($with_args=false, $ignore_last_frames=null) {
|
||||||
$traces = debug_backtrace();
|
$traces = debug_backtrace();
|
||||||
if (!is_array($traces) || count($traces) < 2)
|
if (!is_array($traces) || count($traces) < 2)
|
||||||
return "unknown context";
|
return "unknown context";
|
||||||
|
|
||||||
$msg = array();
|
$msg = array();
|
||||||
$j=0;
|
$j=0;
|
||||||
for ($i=count($traces)-1; $i >= 1; $i--) {
|
for ($i=count($traces)-1; $i >= (is_int($ignore_last_frames)?$ignore_last_frames:1); $i--) {
|
||||||
$j += 1;
|
$j += 1;
|
||||||
$trace = array("#$j");
|
$trace = array("#$j");
|
||||||
if (isset($traces[$i]['file']))
|
if (isset($traces[$i]['file']))
|
||||||
$trace[] = $traces[$i]['file'].(isset($traces[$i]['line'])?":".$traces[$i]['line']:"");
|
$trace[] = $traces[$i]['file'].(isset($traces[$i]['line'])?":".$traces[$i]['line']:"");
|
||||||
|
$args = (
|
||||||
|
$with_args && isset($traces[$i]["args"])?
|
||||||
|
format_callable_args($traces[$i]["args"]):
|
||||||
|
""
|
||||||
|
);
|
||||||
if (isset($traces[$i]['class']) && isset($traces[$i]['function']))
|
if (isset($traces[$i]['class']) && isset($traces[$i]['function']))
|
||||||
$trace[] = $traces[$i]['class'] . " " . $traces[$i]['type'] . " " . $traces[$i]['function']. "()";
|
$trace[] = sprintf(
|
||||||
|
"%s %s %s(%s)",
|
||||||
|
$traces[$i]['class'], $traces[$i]['type'], $traces[$i]['function'], $args
|
||||||
|
);
|
||||||
elseif (isset($traces[$i]['function']))
|
elseif (isset($traces[$i]['function']))
|
||||||
$trace[] = $traces[$i]['function']. "()";
|
$trace[] = sprintf("%s(%s)", $traces[$i]['function'], $args);
|
||||||
$msg[] = implode(" - ", $trace);
|
$msg[] = implode(" - ", $trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,9 +51,10 @@ class LSselect extends LSlog_staticLoggerClass {
|
||||||
* @param boolean $multiple True if this selection permit to select more than one object, False otherwise (optional,
|
* @param boolean $multiple True if this selection permit to select more than one object, False otherwise (optional,
|
||||||
* default: false)
|
* default: false)
|
||||||
* @param array|null $current_selected_objects Array of current selected objects (optional, see setSelectedObjects for format specification)
|
* @param array|null $current_selected_objects Array of current selected objects (optional, see setSelectedObjects for format specification)
|
||||||
|
* @param bool $check_objects Check selected objects (optional, default: true)
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init($id, $LSobjects, $multiple=false, $current_selected_objects=null) {
|
public static function init($id, $LSobjects, $multiple=false, $current_selected_objects=null, $check_objects=true) {
|
||||||
if ( !isset($_SESSION['LSselect']) || !is_array($_SESSION['LSselect']))
|
if ( !isset($_SESSION['LSselect']) || !is_array($_SESSION['LSselect']))
|
||||||
$_SESSION['LSselect'] = array();
|
$_SESSION['LSselect'] = array();
|
||||||
$_SESSION['LSselect'][$id] = array (
|
$_SESSION['LSselect'][$id] = array (
|
||||||
|
@ -62,8 +63,11 @@ class LSselect extends LSlog_staticLoggerClass {
|
||||||
'selected_objects' => array(),
|
'selected_objects' => array(),
|
||||||
);
|
);
|
||||||
if (is_array($current_selected_objects))
|
if (is_array($current_selected_objects))
|
||||||
self :: setSelectedObjects($id, $current_selected_objects);
|
self :: setSelectedObjects($id, $current_selected_objects, $check_objects);
|
||||||
self :: log_debug("Initialized with id=$id: multiple=".($multiple?'yes':'no')." ".count($_SESSION['LSselect'][$id]['selected_objects'])." selected object(s).");
|
self :: log_debug(
|
||||||
|
"Initialized with id=$id: multiple=".($multiple?'yes':'no')." ".
|
||||||
|
count($_SESSION['LSselect'][$id]['selected_objects'])." selected object(s)."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -216,6 +220,7 @@ class LSselect extends LSlog_staticLoggerClass {
|
||||||
* @param array $selected_objects Array of selectable object info with objects's DN
|
* @param array $selected_objects Array of selectable object info with objects's DN
|
||||||
* as key and array of object's info as value. Objects's
|
* as key and array of object's info as value. Objects's
|
||||||
* info currently contains only the object type (key=object_type).
|
* info currently contains only the object type (key=object_type).
|
||||||
|
* @param bool $check_objects Check selected objects (optional, default: true)
|
||||||
*
|
*
|
||||||
* @return array|false Array of selectable object info with objects's DN as key
|
* @return array|false Array of selectable object info with objects's DN as key
|
||||||
* and array of object's info as value. Objects's info returned
|
* and array of object's info as value. Objects's info returned
|
||||||
|
@ -224,24 +229,37 @@ class LSselect extends LSlog_staticLoggerClass {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function setSelectedObjects($id, $selected_objects) {
|
public static function setSelectedObjects($id, $selected_objects, $check_objects=true) {
|
||||||
if (!self :: exists($id))
|
if (!self :: exists($id))
|
||||||
return;
|
return;
|
||||||
if (!is_array($selected_objects))
|
if (!is_array($selected_objects))
|
||||||
return;
|
return;
|
||||||
$_SESSION['LSselect'][$id]['selected_objects'] = array();
|
$previously_selected = $_SESSION['LSselect'][$id]['selected_objects'];
|
||||||
|
$_SESSION['LSselect'][$id]['selected_objects'] = [];
|
||||||
foreach($selected_objects as $dn => $info) {
|
foreach($selected_objects as $dn => $info) {
|
||||||
if (!is_array($info) || !isset($info['object_type'])) {
|
if (!is_array($info) || !isset($info['object_type'])) {
|
||||||
self :: log_warning("setSelectedObjects($id): invalid object info for dn='$dn'");
|
self :: log_warning("setSelectedObjects($id): invalid object info for dn='$dn'");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (self :: checkObjectIsSelectable($id, $info['object_type'], $dn))
|
if (
|
||||||
$_SESSION['LSselect'][$id]['selected_objects'][$dn] = $info;
|
$check_objects
|
||||||
else {
|
&& !(
|
||||||
self :: log_warning("setSelectedObjects($id): object type='".$info['object_type']."' and dn='$dn' is not selectable".varDump($_SESSION['LSselect'][$id]));
|
in_array($dn, $previously_selected)
|
||||||
|
|| self :: checkObjectIsSelectable($id, $info['object_type'], $dn)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
self :: log_warning(
|
||||||
|
"setSelectedObjects($id): object type='{$info['object_type']}' and dn='$dn' is not ".
|
||||||
|
"selectable"
|
||||||
|
);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
$_SESSION['LSselect'][$id]['selected_objects'][$dn] = $info;
|
||||||
}
|
}
|
||||||
self :: log_debug("id=$id: updated with ".count($_SESSION['LSselect'][$id]['selected_objects'])." selected object(s).");
|
self :: log_debug(
|
||||||
|
"setSelectedObjects($id): updated with ".
|
||||||
|
count($_SESSION['LSselect'][$id]['selected_objects'])." selected object(s)."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -250,29 +268,46 @@ class LSselect extends LSlog_staticLoggerClass {
|
||||||
* @param string $id The LSselect ID
|
* @param string $id The LSselect ID
|
||||||
* @param string $object_type The object type
|
* @param string $object_type The object type
|
||||||
* @param string $object_dn The object DN
|
* @param string $object_dn The object DN
|
||||||
|
* @param bool $check_exists Check if object exists in LDAP (optional, default: true)
|
||||||
*
|
*
|
||||||
* @return boolean True if object is selectable, false otherwise
|
* @return boolean True if object is selectable, false otherwise
|
||||||
*/
|
*/
|
||||||
public static function checkObjectIsSelectable($id, $object_type, $object_dn) {
|
public static function checkObjectIsSelectable($id, $object_type, $object_dn, $check_exists=true) {
|
||||||
if (!self :: exists($id)) {
|
if (!self :: exists($id)) {
|
||||||
self :: log_warning("checkObjectIsSelectable($id, $object_type, $object_dn): LSselect $id doesn't exists");
|
self :: log_warning(
|
||||||
|
"checkObjectIsSelectable($id, $object_type, $object_dn): LSselect $id doesn't exists"
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!array_key_exists($object_type, $_SESSION['LSselect'][$id]['LSobjects'])) {
|
if (!array_key_exists($object_type, $_SESSION['LSselect'][$id]['LSobjects'])) {
|
||||||
self :: log_warning("checkObjectIsSelectable($id, $object_type, $object_dn): object type $object_type not selectabled");
|
self :: log_warning(
|
||||||
|
"checkObjectIsSelectable($id, $object_type, $object_dn): object type $object_type not ".
|
||||||
|
"selectable"
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load LSobject type
|
// Load LSobject type
|
||||||
if ( !LSsession :: loadLSobject($object_type) ) {
|
if ( !LSsession :: loadLSobject($object_type) ) {
|
||||||
self :: log_warning("checkObjectIsSelectable($id, $object_type, $object_dn): fail to load object type $object_type");
|
self :: log_warning(
|
||||||
|
"checkObjectIsSelectable($id, $object_type, $object_dn): fail to load object type ".
|
||||||
|
$object_type
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instanciate object and load object data from DN
|
// Check object exists
|
||||||
$object = new $object_type();
|
if (
|
||||||
if (!$object -> loadData($object_dn, self :: getConfig($id, "LSobjects.$object_type.filter", null))) {
|
$check_exists
|
||||||
self :: log_warning("checkObjectIsSelectable($id, $object_type, $object_dn): object $object_dn not found (or does not match with selection filter)");
|
&& !$object_type :: exists(
|
||||||
|
$object_dn,
|
||||||
|
self :: getConfig($id, "LSobjects.$object_type.filter", null, "string")
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
self :: log_warning(
|
||||||
|
"checkObjectIsSelectable($id, $object_type, $object_dn): object $object_dn not found ".
|
||||||
|
"(or does not match with selection filter)"
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -192,13 +192,24 @@ class LSurl extends LSlog_staticLoggerClass {
|
||||||
$public_root_url = LSconfig :: get('public_root_url', '/', 'string');
|
$public_root_url = LSconfig :: get('public_root_url', '/', 'string');
|
||||||
|
|
||||||
if ($absolute && $public_root_url[0] == '/') {
|
if ($absolute && $public_root_url[0] == '/') {
|
||||||
self :: log_debug("LSurl :: public_root_url(absolute=true): configured public root URL is relative ($public_root_url) => try to detect it from current request infos.");
|
self :: log_debug(
|
||||||
$public_root_url = 'http'.(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'?'s':'').'://'.$_SERVER['HTTP_HOST'].$public_root_url;
|
"LSurl :: public_root_url(absolute=true): configured public root URL is relative ".
|
||||||
self :: log_debug("LSurl :: public_root_url(absolute=true): detected public absolute root URL: $public_root_url");
|
"($public_root_url) => try to detect it from current request infos."
|
||||||
|
);
|
||||||
|
$public_root_url = sprintf(
|
||||||
|
"http%s://%s%s",
|
||||||
|
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'?'s':'',
|
||||||
|
$_SERVER['HTTP_HOST'],
|
||||||
|
$public_root_url
|
||||||
|
);
|
||||||
|
self :: log_debug(
|
||||||
|
"LSurl :: public_root_url(absolute=true): detected public absolute root URL: ".
|
||||||
|
$public_root_url
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($relative_url) {
|
if ($relative_url) {
|
||||||
if ($public_root_url[0] == '/') $public_root_url .= "/";
|
if ($public_root_url[-1] != '/') $public_root_url .= "/";
|
||||||
return $public_root_url.$relative_url;
|
return $public_root_url.$relative_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -329,6 +329,15 @@ function LSdebugDefined() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check specified value is a valid DN
|
||||||
|
* @param mixed $dn
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function checkDn($dn) {
|
||||||
|
return is_string($dn) && boolval(@ldap_explode_dn($dn, 0));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérifie la compatibilite des DN
|
* Vérifie la compatibilite des DN
|
||||||
*
|
*
|
||||||
|
@ -737,20 +746,45 @@ function dumpFile($file_path, $mime_type=null, $max_age=3600, $force_download=fa
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format a callable object for logging
|
* Format a callable object for logging
|
||||||
* @param callable $callable The callable object
|
* @param string|array|\ReflectionMethod|\ReflectionFunction $callable The callable object
|
||||||
|
* @param null|array<int,mixed> $args Optional argument(s)
|
||||||
* @return string The callable object string representation
|
* @return string The callable object string representation
|
||||||
*/
|
*/
|
||||||
function format_callable($callable) {
|
function format_callable($callable, $args=null) {
|
||||||
|
$formatted_args = format_callable_args($args);
|
||||||
if (is_string($callable))
|
if (is_string($callable))
|
||||||
return $callable."()";
|
return $callable."($formatted_args)";
|
||||||
if (is_array($callable) && count($callable)==2)
|
if (is_array($callable))
|
||||||
if (is_string($callable[0]))
|
if (is_string($callable[0]))
|
||||||
return $callable[0]."::".$callable[1]."()";
|
return $callable[0]."::".$callable[1]."($formatted_args)";
|
||||||
elseif (is_object($callable[0]))
|
elseif (is_object($callable[0]))
|
||||||
return get_class($callable[0])."->".$callable[1]."()";
|
return get_class($callable[0])."->".$callable[1]."($formatted_args)";
|
||||||
else
|
else
|
||||||
return "Unkown->".$callable[1]."()";
|
return "Unknown->".$callable[1]."($formatted_args)";
|
||||||
return varDump($callable);
|
if ($callable instanceof \ReflectionFunction)
|
||||||
|
return sprintf("%s(%s)", $callable->name, $formatted_args);
|
||||||
|
if ($callable instanceof \ReflectionMethod)
|
||||||
|
return sprintf(
|
||||||
|
"%s::%s(%s)",
|
||||||
|
$callable->class,
|
||||||
|
$callable->name,
|
||||||
|
$formatted_args
|
||||||
|
);
|
||||||
|
return sprintf("%s(%s)", varDump($callable), $formatted_args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format callable arguments for logging
|
||||||
|
* @param array<mixed> $args Arguments
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function format_callable_args($args) {
|
||||||
|
if (!is_array($args) || empty($args))
|
||||||
|
return "";
|
||||||
|
$formatted_args = [];
|
||||||
|
foreach($args as $arg)
|
||||||
|
$formatted_args[] = str_replace("\n", '\n', var_export($arg, true));
|
||||||
|
return implode(", ", $formatted_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_empty($val) {
|
function is_empty($val) {
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
{if $dn}
|
{if $dn}
|
||||||
<a href='object/{$info.object_type|escape:"url"}/{$dn|escape:'url'}' class='LSformElement_select_object'>{$info.name|escape:"htmlall"}</a>
|
<a class='LSformElement_select_object'
|
||||||
{if !$freeze}<input type='hidden' class='LSformElement_select_object' name='{$attr_name|escape:"htmlall"}[]' value='{$dn|escape:"htmlall"}' data-object-type='{$info.object_type|escape:'quotes'}'/>{/if}
|
href='object/{$info.object_type|escape:"url"}/{$dn|escape:'url'}'>
|
||||||
|
{$info.name|escape:"htmlall"}
|
||||||
|
</a>
|
||||||
|
{if !$freeze}
|
||||||
|
<input class='LSformElement_select_object' name='{$attr_name|escape:"htmlall"}[]' type='hidden'
|
||||||
|
value='{$dn|escape:"htmlall"}' data-object-type='{$info.object_type|escape:'quotes'}'/>
|
||||||
|
{/if}
|
||||||
{else}
|
{else}
|
||||||
{$noValueTxt|escape:"htmlall"}
|
{$noValueTxt|escape:"htmlall"}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
Loading…
Reference in a new issue