/** * Gets all the LDAP configurations. * * @return array Array of objects containing LDAP config information. * * @since 2.0 */ public function getItems() { $store = $this->getStoreId(); // Try to load the data from internal storage. if (isset($this->cache[$store])) { return $this->cache[$store]; } $config = SHFactory::getConfig(); // Config managed default domain $default = $config->get('ldap.defaultconfig'); // Config managed LDAP host source $source = (int) $config->get('ldap.config', SHLdapHelper::CONFIG_SQL); if ($source === SHLdapHelper::CONFIG_SQL) { parent::getItems(); foreach ($this->cache[$store] as $row) { /* * We need to mark the LDAP hosts that is default. */ $row->default = $row->name == $default ? true : false; /* * Count the ID number of users in each LDAP host. */ $row->users = $this->getCountDomain($row->id, $row->name); /* * Decode the paramters to get the host and port */ $decode = json_decode($row->params); $row->host = $decode->host; $row->port = $decode->port; } } else { try { // Get all the Ldap config IDs and Names $ids = SHLdapHelper::getConfigIDs(); $this->cache[$store] = array(); foreach ($ids as $id => $name) { // Get this specific Ldap configuration based on name $config = SHLdapHelper::getConfig($name); $result = new stdClass(); $result->id = $id; $result->name = $name; $result->host = $config->get('host'); $result->port = $config->get('port'); $result->users = $this->getCountDomain($result->id, $result->name); // Lets add this config to our results pool $this->cache[$store][] = $result; } } catch (Exception $e) { // We need to look for a string instead of an array on error return $e->getMessage(); } } return $this->cache[$store]; }
/** * Method to get the Ldap domains field options. * * @return array The field option objects. * * @since 2.0 */ protected function getOptions() { // Initialize variables. $options = array(); // Get the Ldap Domains $configs = SHLdapHelper::getConfigIDs(); // Present the Ldap domains in the list foreach ($configs as $id => $config) { $options[] = JHtml::_('select.option', $config, $config, 'value', 'text'); } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
/** * Gets all the LDAP configs and attempts to bind with each. * This is presented on the dashboard. * * @return array Array of objects containing LDAP config information. * * @since 2.0 */ public function getBinds() { try { $results = array(); // Get all the Ldap config IDs and Names $ids = SHLdapHelper::getConfigIDs(); foreach ($ids as $name) { // Get this specific Ldap configuration based on name $config = SHLdapHelper::getConfig($name); $result = new stdClass(); $result->name = $name; $result->host = $config->get('host'); $result->port = $config->get('port'); $result->connect = false; $ldap = new SHLdap($config); // Need to process the ldap formatting for the host configuration ready for a fsockopen $processed = str_replace(array('ldap://', 'ldaps://'), '', $config->get('host')); if ($pos = strpos($processed, chr(32))) { $processed = substr($processed, 0, $pos); } // Check if we can open a socket to the LDAP server:port to check the connection if (@fsockopen($processed, $config->get('port'))) { $result->connect = true; } // Attempt to connect and bind and record the result if ($ldap->connect()) { if ($ldap->proxyBind()) { $result->bind = true; } } // Lets add this config to our results pool $results[] = $result; } return $results; } catch (Exception $e) { // We need to look for a string instead of an array on error return $e->getMessage(); } }
/** * Returns all available domains for this adapter type. * * @return array An array of domain names. * * @since 2.1 */ public static function getDomains() { return SHLdapHelper::getConfigIDs(); }