function ldap_servers_requirements in Lightweight Directory Access Protocol (LDAP) 7.2
Same name and namespace in other branches
- 8.4 ldap_servers/ldap_servers.install \ldap_servers_requirements()
- 8.2 ldap_servers/ldap_servers.install \ldap_servers_requirements()
- 8.3 ldap_servers/ldap_servers.install \ldap_servers_requirements()
- 7 ldap_servers/ldap_servers.install \ldap_servers_requirements()
Implements hook_requirements().
File
- ldap_servers/
ldap_servers.install, line 28 - Install, update and uninstall functions for the LDAP API module.
Code
function ldap_servers_requirements($phase) {
$requirements = [];
$t = get_t();
if ($phase == 'install') {
$requirements['ldap_extension_loaded']['title'] = t('LDAP Extension Loaded');
if (extension_loaded('ldap')) {
$requirements['ldap_extension_loaded']['severity'] = REQUIREMENT_OK;
}
else {
$requirements['ldap_extension_loaded']['severity'] = REQUIREMENT_ERROR;
$requirements['ldap_extension_loaded']['description'] = t('No LDAP PHP Extension is loaded for PHP, so LDAP will not work properly.');
}
}
if ($phase == 'runtime' && !extension_loaded('ldap')) {
$requirements['ldap_extension_loaded']['title'] = t('LDAP Extension Loaded');
$requirements['ldap_extension_loaded']['severity'] = REQUIREMENT_ERROR;
$requirements['ldap_extension_loaded']['description'] = t('No LDAP PHP Extension is loaded for PHP, so LDAP will not work properly.');
}
if ($phase != "install" && db_table_exists('ldapauth')) {
$requirements['ldap_servers']['title'] = t('LDAP Integration LDAP Auth to LDAP Servers Upgrade Concern');
$requirements['ldap_servers']['severity'] = REQUIREMENT_WARNING;
$requirements['ldap_servers']['value'] = NULL;
$requirements['ldap_servers']['description'] = t('Upgrade from Drupal 6 LDAP Auth to Drupal 7
LDAP Servers is not automatic. LDAP Servers will need to be configured by hand.
See http://drupal.org/node/1023016. This message will go away when the ldapauth database table is removed.');
}
// Check that ldapauth not installed.
// Check enabled LDAP servers are configured and Drupal can connect to them.
if ($phase == 'runtime') {
$requirements['ldap_servers_enabled'] = [
'title' => $t('LDAP Server status'),
'value' => $t('Disabled'),
'severity' => REQUIREMENT_WARNING,
];
$servers = ldap_servers_get_servers(NULL, 'enabled');
if (!empty($servers)) {
unset($requirements['ldap_servers_enabled']);
foreach ($servers as $server) {
$server_req_key = 'ldap_servers_sid_' . $server->sid;
$server_tokens = [
'@host' => $server->address,
'@sid' => $server->sid,
];
$requirements[$server_req_key] = [
'title' => $t('LDAP Server status: @sid (@host)', $server_tokens),
'value' => $t('Connection: Failed, check logs for details.', $server_tokens),
'severity' => REQUIREMENT_ERROR,
];
try {
$connect_result = $server
->connect();
if ($connect_result == LDAP_SUCCESS) {
if ($server->bind_method == LDAP_SERVERS_BIND_METHOD_USER) {
// Check bind anonymously if set to bind via user credentials.
// The user has already logged in and so their is no dn or password
// to check since LDAP doesn't store passwords.
$bind_result = $server
->bind(NULL, NULL, TRUE);
}
else {
$bind_result = $server
->bind();
}
if ($bind_result == LDAP_SUCCESS) {
$requirements[$server_req_key]['value'] = $t('Connection: Success, Bind: Success', $server_tokens);
$requirements[$server_req_key]['severity'] = REQUIREMENT_OK;
}
}
$server
->disconnect();
} catch (Exception $e) {
}
}
}
}
return $requirements;
}