You are here

function ldap_servers_test_form in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 7.2 ldap_servers/ldap_servers.test_form.inc \ldap_servers_test_form()
  2. 7 ldap_servers/ldap_servers.test_form.inc \ldap_servers_test_form()

Implements the LDAP server test page.

Parameters

$form_state: A form state array.

$op: An operatin - add or edit.

$sid: A LDAP server ID.

Return value

The form structure.

1 string reference to 'ldap_servers_test_form'
ldap_servers_menu in ldap_servers/ldap_servers.module

File

ldap_servers/ldap_servers.test_form.inc, line 23

Code

function ldap_servers_test_form($form, &$form_state, $op = NULL, $sid = NULL) {
  $ldap_server = ldap_servers_get_servers($sid, 'all', TRUE);
  drupal_set_title(t('Test LDAP Server Configuration: !server', array(
    '!server' => $ldap_server->name,
  )));
  $form['#prefix'] = t('This form tests an LDAP configuration to see if
    it can bind and basic user and group functions.  It also shows token examples
    and a sample user.  The only data this function will modify is the test LDAP group, which will be deleted and added');
  $variables = array(
    'ldap_server' => $ldap_server,
    'actions' => FALSE,
    'type' => 'detail',
  );
  $form['server_variables'] = array(
    '#markup' => theme('ldap_servers_server', $variables),
  );
  $form['sid'] = array(
    '#type' => 'hidden',
    '#default_value' => $sid,
  );
  $form['binding']['bindpw'] = array(
    '#type' => 'password',
    '#title' => t('Password for non-anonymous search'),
    '#size' => 20,
    '#maxlength' => 255,
    '#description' => t('Leave empty to test with currently stored password.'),
  );
  $form['testing_drupal_username'] = array(
    '#type' => 'textfield',
    '#title' => t('Testing Drupal Username'),
    '#default_value' => $ldap_server->testingDrupalUsername,
    '#size' => 30,
    '#maxlength' => 255,
    '#description' => t('This is optional and used for testing this server\'s configuration against an actual username.  The user need not exist in Drupal and testing will not affect the user\'s LDAP or Drupal Account.'),
  );
  $form['testingDrupalUserDn'] = array(
    '#type' => 'textfield',
    '#title' => t('Testing Drupal DN'),
    '#default_value' => $ldap_server->testingDrupalUserDn,
    '#size' => 120,
    '#maxlength' => 255,
    '#description' => t('This is optional and used for testing this server\'s configuration against an actual username.  The user need not exist in Drupal and testing will not affect the user\'s LDAP or Drupal Account.'),
  );
  $form['grp_test_grp_dn'] = array(
    '#type' => 'textfield',
    '#title' => t('Testing Group DN'),
    '#default_value' => $ldap_server->groupTestGroupDn,
    '#size' => 120,
    '#maxlength' => 255,
    '#description' => t('This is optional and used for testing this server\'s group configuration.'),
  );
  $form['grp_test_grp_dn_writeable'] = array(
    '#type' => 'textfield',
    '#title' => t('Testing Group DN that is writeable. Warning!  In test, this group will be deleted, created, have members added to it!'),
    '#default_value' => $ldap_server->groupTestGroupDnWriteable,
    '#size' => 120,
    '#maxlength' => 255,
    '#description' => t('This is optional and used for testing this server\'s group configuration.'),
  );
  if ($ldap_server->bind_method == LDAP_SERVERS_BIND_METHOD_ANON_USER) {
    $form['testing_drupal_userpw'] = array(
      '#type' => 'password',
      '#title' => t('Testing Drupal User Password'),
      '#size' => 30,
      '#maxlength' => 255,
      '#description' => t('This is optional and used for testing this server\'s configuration against the username above.'),
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Test',
    '#weight' => 100,
  );
  if (!empty($form_state['ldap_server_test_data'])) {
    $test_data = $form_state['ldap_server_test_data'];
    if (isset($test_data['username']) && isset($test_data['ldap_user'])) {
      $form['#prefix'] = theme('ldap_server_ldap_entry_table', array(
        'entry' => $test_data['ldap_user']['attr'],
        'username' => $test_data['username'],
        'dn' => $test_data['ldap_user']['dn'],
      ));
    }
    $titles = array(
      'basic' => 'Test Results',
      'group1' => 'Group Create, Delete, Add Member, Remove Member Tests',
      'group2' => 'User Group Membership Functions Test',
      'tokens' => 'User Token Samples',
      'groupfromDN' => 'Groups Derived From User DN',
    );
    foreach ($test_data['results_tables'] as $table_name => $table_data) {
      $form['#prefix'] .= '<h2>' . $titles[$table_name] . '</h2>' . theme('table', array(
        'header' => array(
          'Test',
          'Result',
        ),
        'rows' => $table_data,
      ));
    }
    if (function_exists('dpm') && !empty($test_data['username'])) {
      $user_name = $test_data['username'];
      if ($user = user_load_by_name($user_name)) {
        dpm("Corresponding Drupal user object for: {$user_name}");
        dpm($user);
        if (function_exists('entity_load_single')) {
          $user_entity = entity_load_single('user', $user->uid);
          dpm("Drupal user entity for: {$user_name}");
          dpm($user_entity);
        }
        dpm("Test Group LDAP Entry");
        dpm($test_data['group_entry'][0]);
      }
    }
  }
  return $form;
}