Projet

Général

Profil

Paste
Télécharger (14,5 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_help / ldap_help.status.inc @ 91af538d

1
<?php
2

    
3
/**
4
 * @file
5
 * Status file for ldaphelp module.
6
 */
7

    
8
/**
9
 *
10
 */
11
function ldap_help_status($return = 'html') {
12

    
13
  drupal_add_css(drupal_get_path('module', 'system') . '/system.css', 'module', 'all', FALSE);
14
  include_once drupal_get_path('module', 'system') . '/system.admin.inc';
15

    
16
  // Server and LDAP Module Data.
17
  $heading = "Server and LDAP Module";
18
  $key = 'server';
19
  $phpinfo = ldap_help_parsePHPModules();
20
  $status['server'] = ldap_help_get_server($phpinfo, $info);
21
  $reporting_text = _ldap_help_parse_status_to_text($status['server'], $heading);
22
  $content = "<h3>$heading</h3>" . theme('status_report', ['requirements' => $status['server']]);
23

    
24
  $status['user_settings'] = ldap_help_get_user_settings();
25
  $content .= "<h3>User Settings</h3>" . theme('status_report', ['requirements' => $status['user_settings']]);
26

    
27
  if (module_exists('ldap_servers')) {
28
    list($status['ldap_servers'], $servers) = ldap_help_get_ldap_servers();
29
    $content .= "<h3>General Settings</h3>" . theme('status_report', ['requirements' => $status['ldap_servers']]);
30

    
31
    foreach ($servers as $sid => $server) {
32
      $content .= "<h3>Server: " . $server[1]['value'] . "</h3>" . theme('status_report', ['requirements' => $server]);
33
    }
34
  }
35

    
36
  if (module_exists('ldap_authentication')) {
37
    $status['ldap_authentication'] = ldap_help_get_ldap_authentication();
38
    $content .= "<h3>LDAP Authentication Settings</h3>" . theme('status_report', ['requirements' => $status['ldap_authentication']]);
39
  }
40
  if (module_exists('ldap_authorization')) {
41
    $status['ldap_authorizations'] = ldap_help_get_ldap_authorization();
42
    if (count($status['ldap_authorizations'])) {
43
      foreach ($status['ldap_authorizations'] as $sid => $mapping) {
44
        $content .= "<h3>LDAP Authorization Mapping</h3>" . theme('status_report', ['requirements' => $mapping]);
45
      }
46
    }
47
  }
48

    
49
  if ($return == 'array') {
50
    return $status;
51
  }
52
  else {
53
    return $content;
54
  }
55

    
56
}
57

    
58
/**
59
 *
60
 */
61
function ldap_help_get_server($phpinfo, &$info) {
62

    
63
  $info['phpversion'] = phpversion();
64
  $info['ldaploaded'] = extension_loaded('ldap');
65

    
66
  $info['ldap'] = $phpinfo['ldap'];
67

    
68
  $text = "";
69
  foreach ($phpinfo['ldap'] as $key => $value) {
70
    if (is_scalar($value)) {
71
      $text .= "<br/>$key: " . $value;
72
    }
73
    else {
74
      $text .= "<br/>$key: " . print_r($value, TRUE);
75
    }
76
  }
77
  $info['ldap']['text'] = $text;
78

    
79
  $modules = system_rebuild_module_data();
80
  $ldapmodules = [
81
    'ldap_servers', 'ldap_authentication', 'ldap_authorization',
82
    'ldap_authorization_drupal_role', 'ldap_authorization_og', 'ldap_feeds',
83
    'ldap_query', 'ldap_sso', 'ldap_views',
84
  ];
85

    
86
  foreach ($ldapmodules as $ldapmodule) {
87
    $data['status'] = $modules[$ldapmodule]->status;
88
    $data['schema_version'] = $modules[$ldapmodule]->schema_version;
89
    $data['version'] = ($modules[$ldapmodule]->info['version']) ? $modules[$ldapmodule]->info['version'] : 'unknown';
90
    $data['text'] = "status: " . $data['status']
91
      . ", schema_version: " . $data['schema_version']
92
      . ", v: " . $data['version'];
93

    
94
    $info[$ldapmodule] = $data;
95
  }
96

    
97
  // Set status array to be converted into html table.
98
  if (isset($phpinfo['Apache Environment'])) {
99
    $status[] = [
100
      'title' => 'Apache',
101
      'value' => $phpinfo['Apache Environment']['SERVER_SOFTWARE'],
102
    ];
103
  }
104
  elseif (isset($_SERVER["SERVER_SOFTWARE"])) {
105
    $status[] = [
106
      'title' => 'SERVER_SOFTWARE',
107
      'value' => $_SERVER["SERVER_SOFTWARE"],
108
    ];
109

    
110
  }
111

    
112
  $status[] = [
113
    'title' => 'PHP version',
114
    'value' => phpversion(),
115
  ];
116

    
117
  if (!$info['ldaploaded']) {
118
    $status[] = [
119
      'title' => 'PHP ldap extension not loaded',
120
      'value' => l(t('PHP LDAP extension'), 'http://us2.php.net/ldap') . ' must be loaded for LDAP Integration to work.
121
    It comes compiled with most versions of PHP.'  ,
122
      'severity' => REQUIREMENT_ERROR,
123
    ];
124
  }
125
  else {
126
    $status[] = [
127
      'title' => 'PHP ldap extension data',
128
      'value' => $info['ldap']['text']  ,
129
      'severity' => 0,
130
    ];
131
  }
132

    
133
  $status[] = [
134
    'title' => 'open ssl extension loaded',
135
    'value' => extension_loaded('openssl') ? "yes" : "no",
136
  ];
137

    
138
  $status[] = ['title' => 'Drupal', 'value' => VERSION , 'severity' => "0"];
139

    
140
  foreach ($ldapmodules as $ldapmodule) {
141
    $status[] = ['title' => $ldapmodule, 'value' => $info[$ldapmodule]['text'], 'severity' => "0"];
142
  }
143
  return $status;
144
}
145

    
146
/**
147
 *
148
 */
149
function ldap_help_get_ldapauth(&$info) {
150

    
151
  $status[] = [
152
    'title' => 'Authentication mode',
153
    value => $info['ldapauth']['login_process_text'] ,
154
    'severity' => "0",
155
  ];
156

    
157
  $status[] = [
158
    'title' => 'Conflict Resolve Feature',
159
    value => $info['ldapauth']['login_conflict_text'],
160
    'severity' => "0",
161
  ];
162

    
163
  $info['ldapauth']['ldapauth_disable_pass_change_text'] = (LDAPAUTH_FORGET_PASSWORDS == TRUE) ? "Do not " : "Do";
164
  $info['ldapauth']['ldapauth_disable_pass_change_text'] .= 'store users\' passwords during sessions.';
165

    
166
  $status[] = ['title' => 'Security Options', value => $info['ldapauth']['ldapauth_disable_pass_change_text'], 'severity' => "0"];
167

    
168
  $info['ldapauth']['ldapauth_disable_pass_change_text'] = (LDAPAUTH_DISABLE_PASS_CHANGE == TRUE) ? "R" : "Do not R";
169
  $info['ldapauth']['ldapauth_disable_pass_change_text'] .= 'emove password change fields from user edit form';
170
  $info['ldapauth']['ldapauth_alter_email_field_text'] = 'ldapauth_alter_email_field: ' . LDAPAUTH_ALTER_EMAIL_FIELD;
171

    
172
  $status[] = ['title' => 'LDAP UI Options', value => $info['ldapauth']['ldapauth_disable_pass_change_text'] . "<br/>" . $info['ldapauth']['ldapauth_alter_email_field_text'], 'severity' => "0"];
173

    
174
  return $status;
175
}
176

    
177
/**
178
 *
179
 */
180
function _ldap_help_parse_status_to_text($status, $heading, $replacements = []) {
181

    
182
  $var_del = "\r\n------------------------------------------------\r\n";
183
  $section_del = "\r\n\r\n================================================\r\n";
184
  $name_val_del = ":\r\n";
185
  $lr = "\r\n";
186

    
187
  $replacements = array_merge($replacements, [
188
    '<br/>' => $lr,
189
    '<ul>' => $lr,
190
    '</ul>' => $lr,
191
    '<li>' => $lr,
192
    '</li>' => "",
193
    "<code>" => "",
194
    "</code>" => "",
195
    "<strong>" => "",
196
    "</strong>" => "",
197
  ]);
198

    
199
  $content = drupal_strtoupper($heading) . $lr;
200
  foreach ($status as $item) {
201
    $item['value'] = str_replace(array_keys($replacements), array_values($replacements), $item['value']);
202
    $item['title'] = str_replace(array_keys($replacements), array_values($replacements), $item['title']);
203
    $content .= $item['title'] . $name_val_del . $item['value'] . $var_del;
204
  }
205
  return $content;
206
}
207

    
208
/**
209
 *
210
 */
211
function ldap_help_phpinfo() {
212
  ob_start();
213
  phpinfo();
214
  $s = ob_get_contents();
215
  ob_end_clean();
216
  return $s;
217
}
218

    
219
/**
220
 * Parse php modules from phpinfo .*/
221
function ldap_help_parsePHPModules() {
222
  ob_start();
223
  phpinfo();
224
  $s = ob_get_contents();
225
  ob_end_clean();
226

    
227
  $s = strip_tags($s, '<h2><th><td>');
228
  $s = preg_replace('/<th[^>]*>([^<]+)<\/th>/', "<info>\\1</info>", $s);
229
  $s = preg_replace('/<td[^>]*>([^<]+)<\/td>/', "<info>\\1</info>", $s);
230
  $vtmp = preg_split('/(<h2>[^<]+<\/h2>)/', $s, -1, PREG_SPLIT_DELIM_CAPTURE);
231
  $vmodules = [];
232
  for ($i = 1; $i < count($vtmp); $i++) {
233
    if (preg_match('/<h2>([^<]+)<\/h2>/', $vtmp[$i], $vmat)) {
234
      $vname = trim($vmat[1]);
235
      $vtmp2 = explode("\n", $vtmp[$i + 1]);
236
      foreach ($vtmp2 as $vone) {
237
        $vpat = '<info>([^<]+)<\/info>';
238
        $vpat3 = "/$vpat\s*$vpat\s*$vpat/";
239
        $vpat2 = "/$vpat\s*$vpat/";
240
        // 3cols.
241
        if (preg_match($vpat3, $vone, $vmat)) {
242
          $vmodules[$vname][trim($vmat[1])] = [trim($vmat[2]), trim($vmat[3])];
243
        }
244
        // 2cols.
245
        elseif (preg_match($vpat2, $vone, $vmat)) {
246
          $vmodules[$vname][trim($vmat[1])] = trim($vmat[2]);
247
        }
248
      }
249
    }
250
  }
251
  return $vmodules;
252
}
253

    
254
/**
255
 *
256
 */
257
function ldap_help_get_user_settings() {
258

    
259
  $user_register = variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
260
  $options = [
261
    USER_REGISTER_ADMINISTRATORS_ONLY => t('Administrators only'),
262
    USER_REGISTER_VISITORS => t('Visitors'),
263
    USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL => t('Visitors, but administrator approval is required'),
264
  ];
265

    
266
  $status[] = [
267
    'title' => 'Who can register accounts?',
268
    'value' => $options[$user_register],
269
  ];
270

    
271
  return $status;
272

    
273
}
274

    
275
/**
276
 *
277
 */
278
function ldap_help_get_ldap_servers() {
279
  if (!module_exists('ldap_servers')) {
280
    return FALSE;
281
  }
282

    
283
  ldap_servers_module_load_include('inc', 'ldap_servers', 'ldap_servers.settings');
284
  ldap_servers_module_load_include('inc', 'ldap_servers', 'ldap_servers.admin');
285

    
286
  $conf_form = ldap_servers_settings();
287

    
288
  $selected = @$conf_form['encryption']['ldap_servers_encryption']['#default_value'];
289
  $status[] = [
290
    'title' => 'encryption',
291
    'value' => @$conf_form['encryption']['ldap_servers_encryption']['#options'][$selected],
292
  ];
293

    
294
  $servers_objects = ldap_servers_get_servers(NULL, 'all');
295
  $servers = [];
296
  $field_to_properties = LdapServer::field_to_properties_map();
297
  // Format: ['sid', 'name', 'status', 'ldap_type', 'port', 'tls', 'user_attr', 'mail_attr', 'user_dn_expression', 'ldap_to_drupal_user'].
298
  $props = array_values($field_to_properties);
299
  foreach ($servers_objects as $sid => $server_object) {
300
    $server_admin = new LdapServerAdmin($sid);
301
    $form = $server_admin->drupalForm('update');
302

    
303
    foreach ($props as $property) {
304
      $value = print_r($server_object->{$property}, TRUE);
305

    
306
      if ($property == 'bind_method') {
307
        $value = $form['bind_method']['bind_method']['#options'][$value];
308
      }
309

    
310
      $servers[$sid][] = [
311
        'title' => $property,
312
        'value' => $value,
313
      ];
314
    }
315

    
316
    $ldaps = (strpos(drupal_strtolower($server_object->address), 'ldaps') !== FALSE) ? 'y' : 'n';
317
    $servers[$sid][] = [
318
      'title' => 'ldaps in address',
319
      'value' => $ldaps,
320
    ];
321

    
322
    $binddn = trim($server_object->binddn) ? 'yes' : 'no';
323
    $servers[$sid][] = [
324
      'title' => 'binddn present',
325
      'value' => $binddn,
326
    ];
327

    
328
    $basedn = count($server_object->basedn);
329
    $servers[$sid][] = [
330
      'title' => 'basedn count',
331
      'value' => $basedn,
332
    ];
333

    
334
  }
335

    
336
  return [$status, $servers];
337
}
338

    
339
/**
340
 *
341
 */
342
function ldap_help_get_ldap_authentication() {
343

    
344
  ldap_servers_module_load_include('php', 'ldap_authentication', 'LdapAuthenticationConfAdmin.class');
345
  $auth_conf = new LdapAuthenticationConfAdmin();
346
  $conf_form = $auth_conf->drupalForm();
347

    
348
  $items['logon']['authenticationMode'] = 'string';
349
  $items['logon']['authenticationServers'] = 'checkbox';
350
  $items['restrictions']['allowOnlyIfTextInDn'] = 'string';
351
  $items['restrictions']['excludeIfTextInDn'] = 'string';
352
  $items['restrictions']['allowTestPhp'] = 'string';
353
  $items['restrictions']['excludeIfNoAuthorizations '] = 'checkbox';
354
  $items['drupal_accounts']['loginConflictResolve'] = 'radios';
355
  $items['drupal_accounts']['acctCreation'] = 'radios';
356
  $items['email']['emailOption'] = 'radios';
357
  $items['email']['emailUpdate'] = 'radios';
358
  $items['sso']['ssoRemoteUserStripDomainName'] = 'checkbox';
359
  $items['sso']['seamlessLogin'] = 'checkbox';
360
  $items['sso']['cookieExpire '] = 'select';
361
  $items['sso']['ldapImplementation'] = 'select';
362

    
363
  $status = ldap_help_parse_form($conf_form, $items);
364

    
365
  return $status;
366
}
367

    
368
/**
369
 *
370
 */
371
function ldap_help_get_ldap_user() {
372
  ldap_servers_module_load_include('php', 'ldap_user', 'LdapUserConfAdmin.class');
373
  $conf = new LdapUserConfAdmin();
374
  $form = $conf->drupalForm();
375

    
376
  $items['drupal_accounts']['loginConflictResolve'] = 'radios';
377
  $items['drupal_accounts']['acctCreation'] = 'radios';
378

    
379
  $status = ldap_help_parse_form($form, $items);
380

    
381
  return $status;
382
}
383

    
384
/**
385
 *
386
 */
387
function ldap_help_get_ldap_authorization() {
388
  $status = [];
389
  ldap_servers_module_load_include('php', 'ldap_authorization', 'LdapAuthorizationConsumerConfAdmin.class');
390
  ldap_servers_module_load_include('inc', 'ldap_servers', 'ldap_servers.settings');
391
  ldap_servers_module_load_include('inc', 'ldap_servers', 'ldap_servers.admin');
392

    
393
  $servers = ldap_servers_get_servers(NULL, 'enabled');
394
  $consumers = ldap_authorization_get_consumers();
395

    
396
  if (count($servers) == 0) {
397
    return [];
398
  }
399

    
400
  foreach ($servers as $sid => $server) {
401
    $server_options[$sid] = $server->name;
402
  }
403

    
404
  $items['status']['mapping_id'] = 'string';
405
  $items['status']['consumer_type'] = 'string';
406
  $items['status']['status'] = 'string';
407
  $items['status']['only_ldap_authenticated'] = 'string';
408

    
409
  $items['use_filter']['mappings'] = 'string';
410

    
411
  $items['misc_settings']['allow_synch_both_directions'] = 'string';
412
  $items['misc_settings']['synchronization_modes'] = 'string';
413
  $items['misc_settings']['synchronization_actions'] = 'string';
414

    
415
  foreach ($consumers as $consumer_type => $consumer) {
416
    $consumer_obj = ldap_authorization_get_consumer_object($consumer_type);
417
    $mapping_admin = new LdapAuthorizationConsumerConfAdmin($consumer_obj, FALSE);
418
    $authorization_form = $mapping_admin->drupalForm($server_options, 'edit');
419
    $status[$consumer_type] = ldap_help_parse_form($authorization_form, $items);
420
    $maps = $authorization_form['filter_and_mappings']['mappings']['#default_value'];
421
    $map_content = (trim($maps)) ? "mappings present" : "empty";
422
    if ($map_content == 'data present') {
423
      $map_content .= ($maps == drupal_strtolower($maps)) ? ', lower case' : ', mixed case';
424
    }
425
    $status[$consumer_type][] = [
426
      'title' => 'mappings',
427
      'value' => $map_content,
428
    ];
429

    
430
  }
431
  return $status;
432

    
433
}
434

    
435
/**
436
 *
437
 */
438
function ldap_help_parse_form($form, $items) {
439

    
440
  $status = [];
441
  foreach ($form as $fieldset_name => $field) {
442
    foreach ($field as $field_name => $field_data) {
443
      if (isset($items[$fieldset_name][$field_name])) {
444
        $value = "";
445
        if (!@is_array($field_data['#default_value'])) {
446
          $default_value = @$field_data['#default_value'];
447
        }
448
        else {
449
          $default_value = join(', ', array_values($field_data['#default_value']));
450
        }
451

    
452
        switch ($field_data['#type']) {
453
          case 'radios':
454
            $value = $field_data['#options'][$default_value];
455
            break;
456

    
457
          case 'select':
458
          case 'checkboxes':
459
            $value = $default_value;
460
            break;
461

    
462
          case 'checkbox':
463
            $value = (boolean) ($field_data['#default_value']) ? 'y' : 'n';
464
            break;
465

    
466
          case 'hidden':
467
            $value = $field_data['#value'];
468
            break;
469

    
470
          case 'textarea':
471
          case 'textfield':
472

    
473
            $value = $default_value;
474
            break;
475
        }
476
        if ($items[$fieldset_name][$field_name] == 'empty') {
477
          $value = ((boolean) trim($value)) ? 'populated' : 'empty';
478
        }
479
        $status[] = [
480
          'title' => $field_name,
481
          'value' => $value,
482
        ];
483

    
484
      }
485

    
486
    }
487

    
488
  }
489

    
490
  return $status;
491

    
492
}