diff --git a/contrib/openldap/core-fd-conf.schema b/contrib/openldap/core-fd-conf.schema index 774cb56f793754894cb3f8fba7d2f2874bb5c0f7..bddfd45d855ebada08eeea23077b72a3570965e5 100644 --- a/contrib/openldap/core-fd-conf.schema +++ b/contrib/openldap/core-fd-conf.schema @@ -388,6 +388,12 @@ attributetype ( 1.3.6.1.4.1.38414.8.18.9 NAME 'fdPluginsMenuBlacklist' SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15) +attributetype ( 1.3.6.1.4.1.38414.8.18.10 NAME 'fdManagementConfig' + DESC 'FusionDirectory - Configuration for management classes' + EQUALITY caseIgnoreMatch + SUBSTR caseIgnoreSubstringsMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15) + # Plugins attributetype ( 1.3.6.1.4.1.38414.8.19.1 NAME 'fdOGroupRDN' diff --git a/include/class_config.inc b/include/class_config.inc index 7acc5a3713936fbcc733b2f59cd4896771b5848e..762f86916d2e5e1ce068aae763509b9bdb4cbd69 100644 --- a/include/class_config.inc +++ b/include/class_config.inc @@ -382,6 +382,9 @@ class config /* Load in-ldap configuration */ $this->load_inldap_config(); + /* Parse management config */ + $this->loadManagementConfig(); + if (class_available('systemManagement')) { /* Load server informations */ $this->load_servers(); @@ -504,6 +507,65 @@ class config } } + /*! + * \brief Loads the management classes config to index them by class + */ + private function loadManagementConfig() + { + if (isset($this->current['MANAGEMENTCONFIG'])) { + $value = array(); + foreach ($this->current['MANAGEMENTCONFIG'] as $value) { + list($class, $config) = explode(':', $value, 2); + $value[$class] = $config; + } + $this->current['MANAGEMENTCONFIG'] = $value; + } + } + + /*! + * \brief Update the management config in the LDAP and the cache + */ + public function updateManagementConfig($managementClass, $managementConfig) + { + $managementConfig = json_encode($managementConfig, JSON_THROW_ON_ERROR); + $changes = array(); + if (isset($this->current['MANAGEMENTCONFIG'][$managementClass])) { + /* If there already was a config for this class, remove it */ + if ($this->current['MANAGEMENTCONFIG'][$managementClass] == $managementConfig) { + /* Unless it's the same one and we've got nothing to do */ + return array(); + } + $changes[] = array( + 'attrib' => 'fdManagementConfig', + 'modtype' => LDAP_MODIFY_BATCH_REMOVE, + 'values' => array($managementClass.':'.$this->current['MANAGEMENTCONFIG'][$managementClass]), + ); + } + /* Add the new one */ + $changes[] = array( + 'attrib' => 'fdManagementConfig', + 'modtype' => LDAP_MODIFY_BATCH_ADD, + 'values' => array($managementClass.':'.$managementConfig), + ); + $ldap = $this->get_ldap_link(); + $ldap->cd(CONFIGRDN.$this->current['BASE']); + if (!$ldap->modify_batch($modifs)) { + return array($ldap->get_error()); + } + } + + /*! + * \brief Returns the config for a management class, or NULL + */ + public function getManagementConfig($managementClass) + { + if (isset($this->current['MANAGEMENTCONFIG'][$managementClass])) { + return json_decode($this->current['MANAGEMENTCONFIG'][$managementClass], TRUE); + } else { + return NULL; + } + } + /*! * \brief Store the departments from ldap in $this->departments */ diff --git a/include/class_ldap.inc b/include/class_ldap.inc index 8f3dbfc1a243b6de2496f593337516ea0618b1f6..36b9c7b935680ed372f2f9a4c68c79b5fe566124 100644 --- a/include/class_ldap.inc +++ b/include/class_ldap.inc @@ -696,6 +696,29 @@ class LDAP } } + /*! + * \brief Modify a entry of the directory LDAP with fine control + * + * \param array $changes The changes + */ + function modify_batch(array $changes) + { + if (count($changes) == 0) { + return TRUE; + } + if ($this->hascon) { + if ($this->reconnect) { + $this->connect(); + } + $r = @ldap_modify_batch($this->cid, $this->basedn, $changes); + $this->error = @ldap_error($this->cid); + return $r; + } else { + $this->error = 'Could not connect to LDAP server'; + return FALSE; + } + } + /*! * \brief Add entry in the LDAP directory * diff --git a/include/management/class_ManagementConfigurationDialog.inc b/include/management/class_ManagementConfigurationDialog.inc index cfdcc22b788f864ce39afdec52deba6372405132..bffbee9655a3ad31e4a2d55f3ca603cf9ca4e122 100644 --- a/include/management/class_ManagementConfigurationDialog.inc +++ b/include/management/class_ManagementConfigurationDialog.inc @@ -83,6 +83,10 @@ class ManagementConfigurationDialog extends simplePlugin array(), TRUE // edition ), + new BooleanAttribute( + _('Persitent'), _('Should this configuration be saved in the LDAP as the default configuration for this management page'), + 'saveInLdap', FALSE + ), ) ), ); @@ -92,6 +96,8 @@ class ManagementConfigurationDialog extends simplePlugin { parent::__construct(); $this->parent = $parent; + $this->attributesAccess['saveInLdap']->setInLdap(FALSE); + /* TODO test ACL */ $this->attributesAccess['managementColumns']->setInLdap(FALSE); $this->attributesAccess['managementColumns']->setLinearRendering(FALSE); $columnInfos = $this->parent->getColumnConfiguration(); @@ -136,6 +142,7 @@ class ManagementConfigurationDialog extends simplePlugin function save () { + global $config; $columnInfos = array(); $values = $this->managementColumns; foreach ($values as $value) { @@ -149,5 +156,10 @@ class ManagementConfigurationDialog extends simplePlugin $columnInfos[] = $column; } $this->parent->setColumnConfiguration($columnInfos); + + if ($this->saveInLdap) { + $errors = $config->updateManagementConfig(get_class($this->parent), $columnInfos); + msg_dialog::displayChecks($errors); + } } } diff --git a/include/management/class_management.inc b/include/management/class_management.inc index 1b2fa95901395f8c2b8f32e60c2fac91d9b9ef43..4c503239ccff31998619eb6082f2dcfacef37cff 100644 --- a/include/management/class_management.inc +++ b/include/management/class_management.inc @@ -327,13 +327,20 @@ class management public function getColumnConfiguration() { + global $config; + + if (!isset($this->columnConfiguration)) { + // LDAP configuration + $this->columnConfiguration = $config->getManagementConfig(get_class($this)); + } + if (!isset($this->columnConfiguration)) { // Default configuration $this->columnConfiguration = static::$columns; } + // Session configuration return $this->columnConfiguration; - // TODO: LDAP configuration } public function setColumnConfiguration($columns) diff --git a/plugins/config/class_configInLdap.inc b/plugins/config/class_configInLdap.inc index 7641a86dfd631e0341d5df1d77408141df664e18..1f05a9c136d89e5268577ab08d3804ed0620dbb3 100644 --- a/plugins/config/class_configInLdap.inc +++ b/plugins/config/class_configInLdap.inc @@ -387,7 +387,9 @@ class configInLdap extends simplePlugin // no order FALSE, array() - ) + ), + // Needed here for ACLs + new HiddenAttribute ('fdManagementConfig'), ) ), 'hooks' => array(