Projet

Général

Profil

Paste
Télécharger (2,59 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_servers / ldap_servers.settings.inc @ 91af538d

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5 32700c57 Assos Assos
 * Admin interface for general ldap api settings.
6 85ad3d82 Assos Assos
 */
7
8 32700c57 Assos Assos
/**
9
 *
10
 */
11 85ad3d82 Assos Assos
function ldap_servers_settings() {
12
  ldap_servers_module_load_include('inc', 'ldap_servers', 'ldap_servers.functions');
13
14 32700c57 Assos Assos
  if (!ldap_servers_ldap_extension_loaded()) {
15 85ad3d82 Assos Assos
    drupal_set_message(t('PHP LDAP Extension is not loaded.'), "warning");
16
  }
17
18
  $form['#title'] = "Configure LDAP Preferences";
19 b42754b9 Assos Assos
20 32700c57 Assos Assos
  $options = ldap_servers_encrypt_types();
21 85ad3d82 Assos Assos
22 32700c57 Assos Assos
  /**  when this is changed, need to decrypt and possibly encrypt pwd in newly selected format
23 85ad3d82 Assos Assos
    *   ... thus default needs to be "No Encryption" to avoid confusion.
24
    */
25
26 32700c57 Assos Assos
  $form['previous_encryption'] = ['#type' => 'hidden', '#default_value' => variable_get('ldap_servers_encryption', LDAP_SERVERS_ENC_TYPE_CLEARTEXT)];
27
  $form['encryption'] = ['#type' => 'fieldset', '#title' => t('Encryption')];
28
  $form['encryption']['ldap_servers_encryption'] = [
29 85ad3d82 Assos Assos
    '#type' => 'select',
30
    '#options' => $options,
31 32700c57 Assos Assos
    '#title' => t('Obfuscate LDAP Passwords?'),
32 85ad3d82 Assos Assos
    '#default_value' => variable_get('ldap_servers_encryption', LDAP_SERVERS_ENC_TYPE_CLEARTEXT),
33 32700c57 Assos Assos
    '#description' => t('With obfuscation enabled, passwords will be stored in encrypted form and decrypted with the site hash.'),
34
  ];
35 85ad3d82 Assos Assos
36
  // Disable the form field and explain this to the user.
37 32700c57 Assos Assos
  if (count($options) == 1) {
38 85ad3d82 Assos Assos
    $form['encryption']['ldap_servers_encryption']['#disabled'] = TRUE;
39 32700c57 Assos Assos
    $form['encryption']['ldap_servers_encryption']['#description'] = ' <strong>' . t('Obfuscation is not supported on this web server.') . '</strong>';
40 85ad3d82 Assos Assos
  }
41
42
  $form = system_settings_form($form);
43 32700c57 Assos Assos
  // Needs to be first.
44
  array_unshift($form['#submit'], 'ldap_servers_settings_submit');
45 85ad3d82 Assos Assos
  return $form;
46
}
47
48 32700c57 Assos Assos
/**
49
 *
50
 */
51 85ad3d82 Assos Assos
function ldap_servers_settings_submit($form, &$form_state) {
52
  if ($form_state['submitted']) {
53
    $new_encyption = $form_state['values']['ldap_servers_encryption'];
54
    $old_encyption = $form_state['values']['previous_encryption'];
55
56 32700c57 Assos Assos
    // Use db instead of functions to avoid classes encryption and decryption.
57 85ad3d82 Assos Assos
    if ($new_encyption != $old_encyption) {
58
      $servers = db_query("SELECT sid, bindpw FROM {ldap_servers} WHERE bindpw is not NULL AND bindpw <> ''")->fetchAllAssoc('sid');
59
      foreach ($servers as $sid => $server) {
60 5136ce55 Assos Assos
        if ($server->bindpw != '') {
61
          $decrypted_bind_pwd = ldap_servers_decrypt($server->bindpw, $old_encyption);
62
          $rencrypted = ldap_servers_encrypt($decrypted_bind_pwd, $new_encyption);
63
        }
64
        else {
65
          $rencrypted = '';
66
        }
67 32700c57 Assos Assos
        db_query("UPDATE {ldap_servers} SET bindpw = :bindpw WHERE sid = :sid", [':bindpw' => $rencrypted, ':sid' => $sid]);
68 85ad3d82 Assos Assos
      }
69
    }
70
  }
71
}