You are here

function ldap_help_get_ldap_servers in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_help/ldap_help.status.inc \ldap_help_get_ldap_servers()
  2. 7 ldap_help/ldap_help.status.inc \ldap_help_get_ldap_servers()
1 call to ldap_help_get_ldap_servers()
ldap_help_status in ldap_help/ldap_help.status.inc

File

ldap_help/ldap_help.status.inc, line 278
Status file for ldaphelp module.

Code

function ldap_help_get_ldap_servers() {
  if (!module_exists('ldap_servers')) {
    return FALSE;
  }
  ldap_servers_module_load_include('inc', 'ldap_servers', 'ldap_servers.settings');
  ldap_servers_module_load_include('inc', 'ldap_servers', 'ldap_servers.admin');
  $conf_form = ldap_servers_settings();
  $selected = @$conf_form['encryption']['ldap_servers_encryption']['#default_value'];
  $status[] = [
    'title' => 'encryption',
    'value' => @$conf_form['encryption']['ldap_servers_encryption']['#options'][$selected],
  ];
  $servers_objects = ldap_servers_get_servers(NULL, 'all');
  $servers = [];
  $field_to_properties = LdapServer::field_to_properties_map();

  // Format: ['sid', 'name', 'status', 'ldap_type', 'port', 'tls', 'user_attr', 'mail_attr', 'user_dn_expression', 'ldap_to_drupal_user'].
  $props = array_values($field_to_properties);
  foreach ($servers_objects as $sid => $server_object) {
    $server_admin = new LdapServerAdmin($sid);
    $form = $server_admin
      ->drupalForm('update');
    foreach ($props as $property) {
      $value = print_r($server_object->{$property}, TRUE);
      if ($property == 'bind_method') {
        $value = $form['bind_method']['bind_method']['#options'][$value];
      }
      $servers[$sid][] = [
        'title' => $property,
        'value' => $value,
      ];
    }
    $ldaps = strpos(drupal_strtolower($server_object->address), 'ldaps') !== FALSE ? 'y' : 'n';
    $servers[$sid][] = [
      'title' => 'ldaps in address',
      'value' => $ldaps,
    ];
    $binddn = trim($server_object->binddn) ? 'yes' : 'no';
    $servers[$sid][] = [
      'title' => 'binddn present',
      'value' => $binddn,
    ];
    $basedn = count($server_object->basedn);
    $servers[$sid][] = [
      'title' => 'basedn count',
      'value' => $basedn,
    ];
  }
  return [
    $status,
    $servers,
  ];
}