You are here

public function LdapUserConfAdmin::drupalForm in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 7.2 ldap_user/LdapUserConfAdmin.class.php \LdapUserConfAdmin::drupalForm()

generate admin form for ldapUserConf object

Return value

array $form as drupal form api form array

File

ldap_user/LdapUserConfAdmin.class.php, line 85

Class

LdapUserConfAdmin

Code

public function drupalForm() {
  if (count($this->drupalAcctProvisionServerOptions) == 0) {
    $message = ldap_servers_no_enabled_servers_msg('configure LDAP User');
    $form['intro'] = array(
      '#type' => 'item',
      '#markup' => t('<h1>LDAP User Settings</h1>') . $message,
    );
    return $form;
  }
  $form['#storage'] = array();
  $form['#theme'] = 'ldap_user_conf_form';
  $form['intro'] = array(
    '#type' => 'item',
    '#markup' => t('<h1>LDAP User Settings</h1>'),
  );
  $form['manual_drupal_account_editing'] = array(
    '#type' => 'fieldset',
    '#title' => t('Manual Drupal Account Creation and Updates'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['manual_drupal_account_editing']['manualAccountConflict'] = array(
    '#type' => 'radios',
    '#options' => $this->manualAccountConflictOptions,
    '#title' => t('How to resolve LDAP conflicts with manually  created Drupal accounts.'),
    '#description' => t('This applies only to accounts created manually through admin/people/create
        for which an LDAP entry can be found on the LDAP server selected in "LDAP Servers Providing Provisioning Data"'),
    '#default_value' => $this->manualAccountConflict,
  );
  $form['basic_to_drupal'] = array(
    '#type' => 'fieldset',
    '#title' => t('Basic Provisioning to Drupal Account Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $default_value = $this->drupalAcctProvisionServer ? $this->drupalAcctProvisionServer : 'none';
  $form['basic_to_drupal']['drupalAcctProvisionServer'] = array(
    '#type' => 'radios',
    '#title' => t('LDAP Servers Providing Provisioning Data'),
    '#required' => 1,
    '#default_value' => $default_value,
    '#options' => $this->drupalAcctProvisionServerOptions,
    '#description' => $this->drupalAcctProvisionServerDescription,
    '#states' => array(
      'enabled' => array(
        // action to take.
        ':input[name=drupalAcctProvisionTriggers]' => array(
          'value' => LDAP_USER_DRUPAL_USER_PROV_ON_AUTHENTICATE,
        ),
      ),
    ),
  );
  $form['basic_to_drupal']['drupalAcctProvisionTriggers'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Drupal Account Provisioning Events'),
    '#required' => FALSE,
    '#default_value' => $this->drupalAcctProvisionTriggers,
    '#options' => $this->drupalAccountProvisionEventsOptions,
    '#description' => $this->drupalAccountProvisionEventsDescription,
  );
  $form['basic_to_drupal']['userConflictResolve'] = array(
    '#type' => 'radios',
    '#title' => t('Existing Drupal User Account Conflict'),
    '#required' => 1,
    '#default_value' => $this->userConflictResolve,
    '#options' => $this->userConflictOptions,
    '#description' => t($this->userConflictResolveDescription),
  );
  $form['basic_to_drupal']['acctCreation'] = array(
    '#type' => 'radios',
    '#title' => t('Application of Drupal Account settings to LDAP Authenticated Users'),
    '#required' => 1,
    '#default_value' => $this->acctCreation,
    '#options' => $this->acctCreationOptions,
    '#description' => t($this->acctCreationDescription),
  );
  $account_options = array();
  $account_options['ldap_user_orphan_do_not_check'] = t('Do not check for orphaned Drupal accounts.');
  $account_options['ldap_user_orphan_email'] = t('Perform no action, but email list of orphaned accounts. (All the other options will send email summaries also.)');
  foreach (user_cancel_methods() as $option_name => $option) {
    $account_options[$option_name] = $option['#title'];
  }

  //@todo these 2 options are removed until this feature is better tested in

  // actual production environments; it has potentially disastrous effects
  unset($account_options['user_cancel_reassign']);
  unset($account_options['user_cancel_delete']);
  $form['basic_to_drupal']['orphanedDrupalAcctBehavior'] = array(
    '#type' => 'radios',
    '#title' => t('Action to perform on Drupal account that no longer have a
        corresponding LDAP entry'),
    '#required' => 0,
    '#default_value' => $this->orphanedDrupalAcctBehavior,
    '#options' => $account_options,
    '#description' => t($this->orphanedDrupalAcctBehaviorDescription),
  );
  $form['basic_to_drupal']['orphanedCheckQty'] = array(
    '#type' => 'textfield',
    '#size' => 10,
    '#title' => t('Number of users to check each cron run.'),
    '#description' => t(''),
    '#default_value' => $this->orphanedCheckQty,
    '#required' => FALSE,
  );
  $form['basic_to_ldap'] = array(
    '#type' => 'fieldset',
    '#title' => t('Basic Provisioning to LDAP Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => !$this->ldapEntryProvisionServer,
  );
  $default_value = $this->ldapEntryProvisionServer ? $this->ldapEntryProvisionServer : 'none';
  $form['basic_to_ldap']['ldapEntryProvisionServer'] = array(
    '#type' => 'radios',
    '#title' => t('LDAP Servers to Provision LDAP Entries on'),
    '#required' => 1,
    '#default_value' => $default_value,
    '#options' => $this->ldapEntryProvisionServerOptions,
    '#description' => $this->ldapEntryProvisionServerDescription,
  );
  $form['basic_to_ldap']['ldapEntryProvisionTriggers'] = array(
    '#type' => 'checkboxes',
    '#title' => t('LDAP Entry Provisioning Events'),
    '#required' => FALSE,
    '#default_value' => $this->ldapEntryProvisionTriggers,
    '#options' => $this->ldapEntryProvisionTriggersOptions,
    '#description' => $this->ldapEntryProvisionTriggersDescription,
  );

  /**
      $form['ws'] = array(
        '#type' => 'fieldset',
        '#title' => t('[Untested and Unfinished Code] REST Webservice for Provisioning and Synching.'),
        '#collapsible' => TRUE,
        '#collapsed' => !$this->wsEnabled,
        '#description' => t('Once configured, this webservice can be used to trigger creation, synching, deletion, etc of an LDAP associated Drupal account.'),
      );

      $form['ws']['wsEnabled'] = array(
        '#type' => 'checkbox',
        '#title' => t('Enable REST Webservice'),
        '#required' => FALSE,
        '#default_value' => $this->wsEnabled,
      );

      $form['ws']['wsUserIps'] = array(
        '#type' => 'textarea',
        '#title' => t('Allowed IP Addresses to request webservice.'),
        '#required' => FALSE,
        '#default_value' => join("\n", $this->wsUserIps),
        '#description' => t('One Per Line. The current server address is LOCAL_ADDR and the client ip requesting this page is REMOTE_ADDR .', $_SERVER),
        '#cols' => 20,
        '#rows' => 2,
        '#states' => array(
          'visible' => array(   // action to take.
            ':input[name="wsEnabled"]' => array('checked' => TRUE),
          ),
        ),
      );

      if (!$this->wsKey) {
        $urls = t('URLs are not available until a key is create a key and urls will be generated');
      }
      else {
        $urls = theme('item_list',
          array(
            'items' => ldap_user_ws_urls_item_list(),
            'title' => 'REST urls',
            'type' => 'ul',
          ));
      }

      $form['ws']['wsKey'] = array(
        '#type' => 'textfield',
        '#title' => t('Key for webservice'),
        '#required' => FALSE,
        '#default_value' => $this->wsKey,
        '#description' => t('Any random string of characters.') . $urls,
        '#states' => array(
          'visible' => array(   // action to take.
            ':input[name="wsEnabled"]' => array('checked' => TRUE),
          ),
        ),
      );
  */
  $form['server_mapping_preamble'] = array(
    '#type' => 'markup',
    '#markup' => t('
The relationship between a Drupal user and an LDAP entry is defined within the LDAP server configurations.


The mappings below are for user fields, properties, and profile2 data that are not automatically mapped elsewhere.
Mappings such as username or email address that are configured elsewhere are shown at the top for clarity.
When more than one ldap server is enabled for provisioning data (or simply more than one configuration for the same ldap server),
mappings need to be setup for each server.  If no tables are listed below, you have not enabled any provisioning servers at
the top of this form.
'),
  );
  foreach (array(
    LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
    LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY,
  ) as $direction) {
    $sid = $this->provisionSidFromDirection[$direction];
    $ldap_server = $sid ? ldap_servers_get_servers($sid, NULL, TRUE) : FALSE;
    $ldap_server_selected = (bool) $ldap_server;
    if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {
      $parent_fieldset = 'basic_to_drupal';
      $description = t('Provisioning from LDAP to Drupal Mappings:');
    }
    elseif ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
      $parent_fieldset = 'basic_to_ldap';
      $description = t('Provisioning from Drupal to LDAP Mappings:');
    }
    $form[$parent_fieldset]['mappings__' . $direction] = array(
      '#type' => 'fieldset',
      '#title' => $description,
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#description' => '',
      'table__' . $direction => array(
        '#type' => 'markup',
        '#markup' => '[replace_with_table__' . $direction . ']',
      ),
    );
    $password_notes = '<h3>' . t('Password Tokens') . '</h3><ul>' . '<li>' . t('Pwd: Random -- Uses a random Drupal generated password') . '</li>' . '<li>' . t('Pwd: User or Random -- Uses password supplied on user forms.
  If none available uses random password.') . '</li></ul>' . '<h3>' . t('Password Concerns') . '</h3>' . '<ul>' . '<li>' . t('Provisioning passwords to LDAP means passwords must meet the LDAP\'s
password requirements.  Password Policy module can be used to add requirements.') . '</li>' . '<li>' . t('Some LDAPs require a user to reset their password if it has been changed
by someone other that user.  Consider this when provisioning LDAP passwords.') . '</li>' . '</ul></p>';
    $source_drupal_token_notes = <<<EOT
<p>Examples in form: Source Drupal User token => Target LDAP Token (notes)</p>
<ul>
<li>Source Drupal User token => Target LDAP Token</li>
<li>cn=[property.name],ou=test,dc=ad,dc=mycollege,dc=edu => [dn] (example of token and constants)</li>
<li>top => [objectclass:0] (example of constants mapped to multivalued attribute)</li>
<li>person => [objectclass:1] (example of constants mapped to multivalued attribute)</li>
<li>organizationalPerson => [objectclass:2] (example of constants mapped to multivalued attribute)</li>
<li>user => [objectclass:3] (example of constants mapped to multivalued attribute)</li>
<li>Drupal Provisioned LDAP Account => [description] (example of constant)</li>
<li>[field.field_lname] => [sn]</li>

</ul>
EOT;
    if ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {

      // add some password notes
      $form[$parent_fieldset]['password_notes'] = array(
        '#type' => 'fieldset',
        '#title' => t('Password Notes'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        'directions' => array(
          '#type' => 'markup',
          '#markup' => $password_notes,
        ),
      );
      $form[$parent_fieldset]['source_drupal_token_notes'] = array(
        '#type' => 'fieldset',
        '#title' => t('Source Drupal User Tokens and Corresponding Target LDAP Tokens'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        'directions' => array(
          '#type' => 'markup',
          '#markup' => $source_drupal_token_notes,
        ),
      );
    }
    $this
      ->addServerMappingFields($form, $direction);
  }
  foreach (array(
    'orphanedCheckQty',
    'orphanedDrupalAcctBehavior',
    'acctCreation',
    'userConflictResolve',
    'drupalAcctProvisionTriggers',
    'mappings__' . LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
  ) as $input_name) {
    $form['basic_to_drupal'][$input_name]['#states']['invisible'] = array(
      ':input[name=drupalAcctProvisionServer]' => array(
        'value' => 'none',
      ),
    );
  }
  foreach (array(
    'ldapEntryProvisionTriggers',
    'password_notes',
    'source_drupal_token_notes',
    'mappings__' . LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY,
  ) as $input_name) {
    $form['basic_to_ldap'][$input_name]['#states']['invisible'] = array(
      ':input[name=ldapEntryProvisionServer]' => array(
        'value' => 'none',
      ),
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Save',
  );
  return $form;
}