/** * Get all replicate name servers for a master one * * @param $master_id : master ldap server ID * * @return string containing names of the replicate servers **/ function getAllReplicatesNamesForAMaster($master_id) { $replicates = getAllReplicateForAMaster($master_id); $str = ""; foreach ($replicates as $replicate) { $str .= ($str != '' ? ',' : '') . " " . $replicate["host"] . ":" . $replicate["port"]; } return $str; }
/** * Try to connect to a ldap server * * @param $ldap_method : ldap_method array to use * @param $login User Login * @param $password User Password * * @return link to the LDAP server : false if connection failed **/ static function tryToConnectToServer($ldap_method, $login, $password) { $ds = self::connectToServer($ldap_method['host'], $ldap_method['port'], $ldap_method['rootdn'], decrypt($ldap_method['rootdn_passwd'], GLPIKEY), $ldap_method['use_tls'], $ldap_method['deref_option']); // Test with login and password of the user if exists if (!$ds && !empty($login)) { $ds = self::connectToServer($ldap_method['host'], $ldap_method['port'], $login, $password, $ldap_method['use_tls'], $ldap_method['deref_option']); } //If connection is not successfull on this directory, try replicates (if replicates exists) if (!$ds && $ldap_method['id'] > 0) { foreach (getAllReplicateForAMaster($ldap_method['id']) as $replicate) { $ds = self::connectToServer($replicate["host"], $replicate["port"], $ldap_method['rootdn'], decrypt($ldap_method['rootdn_passwd'], GLPIKEY), $ldap_method['use_tls'], $ldap_method['deref_option']); // Test with login and password of the user if (!$ds && !empty($login)) { $ds = self::connectToServer($replicate["host"], $replicate["port"], $login, $password, $ldap_method['use_tls'], $ldap_method['deref_option']); } if ($ds) { return $ds; } } } return $ds; }