Projet

Général

Profil

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

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

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * status file for ldaphelp module
6
 *
7
 */
8
9
function ldap_help_status($return = 'html') {
10
11
  drupal_add_css(drupal_get_path('module', 'system') . '/system.css', 'module', 'all', FALSE);
12
  include_once(drupal_get_path('module', 'system') . '/system.admin.inc');
13
14
  // server and LDAP Module Data
15
  $heading = "Server and LDAP Module";
16
  $key = 'server';
17
  $phpinfo = ldap_help_parsePHPModules();
18
  $status['server'] = ldap_help_get_server($phpinfo, $info);
19
  $reporting_text = _ldap_help_parse_status_to_text($status['server'], $heading);
20 bc175c27 Assos Assos
  $content = "<h3>$heading</h3>" . theme('status_report', array('requirements' => $status['server'])); //  . ldap_help_phpinfo();
21 85ad3d82 Assos Assos
22
  $status['user_settings'] = ldap_help_get_user_settings();
23 bc175c27 Assos Assos
  $content .= "<h3>User Settings</h3>" . theme('status_report', array('requirements' => $status['user_settings']));
24 85ad3d82 Assos Assos
25
  if (module_exists('ldap_servers')) {
26
    list($status['ldap_servers'], $servers) = ldap_help_get_ldap_servers();
27 bc175c27 Assos Assos
    $content .= "<h3>General Settings</h3>" . theme('status_report', array('requirements' => $status['ldap_servers']));
28 85ad3d82 Assos Assos
29
    foreach ($servers as $sid => $server) {
30 bc175c27 Assos Assos
      $content .= "<h3>Server: " . $server[1]['value'] . "</h3>" . theme('status_report', array('requirements' => $server));
31 85ad3d82 Assos Assos
    }
32
  }
33
34
  if (module_exists('ldap_authentication')) {
35
    $status['ldap_authentication'] = ldap_help_get_ldap_authentication();
36 bc175c27 Assos Assos
    $content .= "<h3>LDAP Authentication Settings</h3>" . theme('status_report', array('requirements' => $status['ldap_authentication']));
37 85ad3d82 Assos Assos
  }
38
  if (module_exists('ldap_authorization')) {
39
    $status['ldap_authorizations'] = ldap_help_get_ldap_authorization();
40
    if (count($status['ldap_authorizations'])) {
41
      foreach ($status['ldap_authorizations'] as $sid => $mapping) {
42 bc175c27 Assos Assos
        $content .= "<h3>LDAP Authorization Mapping</h3>" . theme('status_report', array('requirements' => $mapping));
43 85ad3d82 Assos Assos
      }
44
    }
45
  }
46
47
  if ($return == 'array') {
48
    return $status;
49
  }
50
  else {
51
    return $content;
52
  }
53
54
}
55
function ldap_help_get_server($phpinfo, &$info) {
56
57
  $info['phpversion'] = phpversion();
58
  $info['ldaploaded'] = extension_loaded('ldap');
59
60
  $info['ldap'] = $phpinfo['ldap'];
61
62
  $text = "";
63
  foreach ($phpinfo['ldap'] as $key => $value) {
64
    if (is_scalar($value)) {
65
      $text .= "<br/>$key: " . $value;
66
    }
67
    else {
68
      $text .= "<br/>$key: " . print_r($value, TRUE);
69
    }
70
  }
71
  $info['ldap']['text'] = $text;
72
73
  $modules = system_rebuild_module_data();
74
  $ldapmodules = array('ldap_servers', 'ldap_authentication', 'ldap_authorization',
75
    'ldap_authorization_drupal_role', 'ldap_authorization_og', 'ldap_feeds',
76
    'ldap_query', 'ldap_sso', 'ldap_views');
77
78
  foreach ($ldapmodules as $ldapmodule) {
79
    $data['status'] = $modules[$ldapmodule]->status;
80
    $data['schema_version'] = $modules[$ldapmodule]->schema_version;
81
    $data['version'] = ($modules[$ldapmodule]->info['version']) ? $modules[$ldapmodule]->info['version'] : 'unknown';
82
    $data['text'] = "status: " . $data['status']
83
      . ", schema_version: " . $data['schema_version']
84
      . ", v: " . $data['version'];
85
86
    $info[$ldapmodule] = $data;
87
  }
88
89
  // set status array to be converted into html table.
90
  if (isset($phpinfo['Apache Environment'])) {
91
    $status[] = array(
92
      'title' => 'Apache',
93
      'value' => $phpinfo['Apache Environment']['SERVER_SOFTWARE']
94
    );
95
  }
96
  elseif (isset($_SERVER["SERVER_SOFTWARE"])) {
97
        $status[] = array(
98
      'title' => 'SERVER_SOFTWARE',
99
      'value' => $_SERVER["SERVER_SOFTWARE"]
100
    );
101
102
  }
103
104
105
  $status[] = array(
106
    'title' => 'PHP version',
107
    'value' => phpversion()
108
  );
109
110
111
112
113
  if (! $info['ldaploaded']) {
114
    $status[] = array( 'title' => 'PHP ldap extension not loaded',
115
    'value' => l(t('PHP LDAP extension'), 'http://us2.php.net/ldap') . ' must be loaded for LDAP Integration to work.
116
    It comes compiled with most versions of PHP.'  ,
117
    'severity' => REQUIREMENT_ERROR);
118
  }
119
  else {
120
    $status[] = array( 'title' => 'PHP ldap extension data',
121
    'value' => $info['ldap']['text']  ,
122
    'severity' => 0);
123
  }
124
125
  $status[] = array(
126
    'title' => 'mcrypt extension loaded',
127
    'value' => (extension_loaded('mcrypt')) ? "yes" : "no",
128
  );
129
130
  $status[] = array(
131
    'title' => 'open ssl extension loaded',
132
    'value' => extension_loaded('openssl') ? "yes" : "no",
133
  );
134
135
  $status[] = array('title' => 'Drupal', 'value' => VERSION , 'severity' => "0");
136
137
  foreach ( $ldapmodules as $ldapmodule) {
138 bc175c27 Assos Assos
    $status[] = array('title' => $ldapmodule, 'value' => $info[$ldapmodule]['text'], 'severity' => "0");
139 85ad3d82 Assos Assos
  }
140
  return $status;
141
}
142
143
function ldap_help_get_ldapauth(&$info) {
144
145 bc175c27 Assos Assos
  $status[] = array(
146 85ad3d82 Assos Assos
    'title' => 'Authentication mode',
147 bc175c27 Assos Assos
    value => $info['ldapauth']['login_process_text'] ,
148 85ad3d82 Assos Assos
  'severity' => "0");
149
150 bc175c27 Assos Assos
  $status[] = array(
151 85ad3d82 Assos Assos
    'title' => 'Conflict Resolve Feature',
152 bc175c27 Assos Assos
    value => $info['ldapauth']['login_conflict_text'],
153 85ad3d82 Assos Assos
  'severity' => "0");
154
155
  $info['ldapauth']['ldapauth_disable_pass_change_text'] = (LDAPAUTH_FORGET_PASSWORDS == TRUE) ? "Do not " : "Do";
156
  $info['ldapauth']['ldapauth_disable_pass_change_text'] .= 'store users\' passwords during sessions.';
157
158 bc175c27 Assos Assos
  $status[] = array('title' => 'Security Options', value => $info['ldapauth']['ldapauth_disable_pass_change_text'], 'severity' => "0");
159 85ad3d82 Assos Assos
160
  $info['ldapauth']['ldapauth_disable_pass_change_text'] = (LDAPAUTH_DISABLE_PASS_CHANGE == TRUE) ? "R" : "Do not R";
161
  $info['ldapauth']['ldapauth_disable_pass_change_text'] .= 'emove password change fields from user edit form';
162
  $info['ldapauth']['ldapauth_alter_email_field_text'] = 'ldapauth_alter_email_field: ' . LDAPAUTH_ALTER_EMAIL_FIELD ;
163
164 bc175c27 Assos Assos
  $status[] = array('title' => 'LDAP UI Options', value => $info['ldapauth']['ldapauth_disable_pass_change_text'] . "<br/>" . $info['ldapauth']['ldapauth_alter_email_field_text'], 'severity' => "0");
165 85ad3d82 Assos Assos
166
  return $status;
167
}
168
169
function _ldap_help_parse_status_to_text($status, $heading, $replacements = array()) {
170
171
  $var_del = "\r\n------------------------------------------------\r\n";
172
  $section_del = "\r\n\r\n================================================\r\n";
173
  $name_val_del = ":\r\n";
174
  $lr = "\r\n";
175
176
  $replacements = array_merge($replacements, array(
177
  '<br/>' => $lr,
178
  '<ul>' => $lr,
179
  '</ul>' => $lr,
180
  '<li>' => $lr,
181
  '</li>' => "",
182
  "<code>" => "",
183
  "</code>" => "",
184
  "<strong>" => "",
185
  "</strong>" => ""
186
  ));
187
188
189
  $content = drupal_strtoupper($heading) . $lr  ;
190
  foreach ($status as $item) {
191
  //  $item['value'] = str_replace(array('<br/>','<ul>','</ul>','<li>','</li>',"<code>","</code>"),
192
   // array("\r\n","\r\n","\r\n","\r\n","\r\n"),$item['value'] );
193
    $item['value'] = str_replace(array_keys($replacements), array_values($replacements), $item['value'] );
194
    $item['title'] = str_replace(array_keys($replacements), array_values($replacements), $item['title'] );
195 bc175c27 Assos Assos
    $content .= $item['title'] . $name_val_del . $item['value'] . $var_del;
196 85ad3d82 Assos Assos
  }
197
  return $content;
198
}
199
200
function ldap_help_phpinfo() {
201
  ob_start();
202
  phpinfo();
203
  $s = ob_get_contents();
204
  ob_end_clean();
205
  return $s;
206
}
207
/** parse php modules from phpinfo */
208
function ldap_help_parsePHPModules() {
209
  ob_start();
210
  phpinfo();
211
  $s = ob_get_contents();
212
  ob_end_clean();
213
214
  $s = strip_tags($s, '<h2><th><td>');
215
  $s = preg_replace('/<th[^>]*>([^<]+)<\/th>/', "<info>\\1</info>", $s);
216
  $s = preg_replace('/<td[^>]*>([^<]+)<\/td>/', "<info>\\1</info>", $s);
217
  $vtmp = preg_split('/(<h2>[^<]+<\/h2>)/', $s, -1, PREG_SPLIT_DELIM_CAPTURE);
218
  $vmodules = array();
219 bc175c27 Assos Assos
  for ($i = 1; $i < count($vtmp); $i++) {
220 85ad3d82 Assos Assos
    if (preg_match('/<h2>([^<]+)<\/h2>/', $vtmp[$i], $vmat)) {
221
      $vname = trim($vmat[1]);
222 bc175c27 Assos Assos
      $vtmp2 = explode("\n", $vtmp[$i + 1]);
223 85ad3d82 Assos Assos
      foreach ($vtmp2 AS $vone) {
224
        $vpat = '<info>([^<]+)<\/info>';
225
        $vpat3 = "/$vpat\s*$vpat\s*$vpat/";
226
        $vpat2 = "/$vpat\s*$vpat/";
227
        if (preg_match($vpat3, $vone, $vmat)) { // 3cols
228
          $vmodules[$vname][trim($vmat[1])] = array(trim($vmat[2]), trim($vmat[3]));
229
        }
230
        elseif (preg_match($vpat2, $vone, $vmat)) { // 2cols
231
          $vmodules[$vname][trim($vmat[1])] = trim($vmat[2]);
232
        }
233
      }
234
    }
235
  }
236
  return $vmodules;
237
}
238
239
function ldap_help_get_user_settings() {
240
241
  $user_register = variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
242
  $options = array(
243
    USER_REGISTER_ADMINISTRATORS_ONLY => t('Administrators only'),
244
    USER_REGISTER_VISITORS => t('Visitors'),
245
    USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL => t('Visitors, but administrator approval is required'),
246
  );
247
248
249
    $status[] = array(
250
      'title' => 'Who can register accounts?',
251
      'value' => $options[$user_register],
252
    );
253
254
    return $status;
255
256
}
257
258
function ldap_help_get_ldap_servers() {
259
  if (!module_exists('ldap_servers')) {
260
    return FALSE;
261
  }
262
263
  ldap_servers_module_load_include('inc', 'ldap_servers', 'ldap_servers.settings');
264
  ldap_servers_module_load_include('inc', 'ldap_servers', 'ldap_servers.admin');
265
266
  $conf_form = ldap_servers_settings();
267
268
  $selected = @$conf_form['encryption']['ldap_servers_encryption']['#default_value'];
269
  $status[] = array(
270
      'title' => 'encryption',
271
      'value' => @$conf_form['encryption']['ldap_servers_encryption']['#options'][$selected],
272
    );
273
274
  $servers_objects = ldap_servers_get_servers(NULL, 'all');
275
  $servers = array();
276
  $field_to_properties = LdapServer::field_to_properties_map();
277
  $props = array_values($field_to_properties); // array('sid', 'name', 'status', 'ldap_type', 'port', 'tls', 'user_attr', 'mail_attr', 'user_dn_expression', 'ldap_to_drupal_user');
278
  foreach ($servers_objects as $sid => $server_object) {
279
    $server_admin = new LdapServerAdmin($sid);
280
    $form = $server_admin->drupalForm('update');
281
282
    foreach ($props as $property) {
283
      $value = print_r($server_object->{$property}, TRUE);
284
285
      if ($property == 'bind_method') {
286
        $value = $form['bind_method']['bind_method']['#options'][$value];
287
      }
288
289
      $servers[$sid][] = array(
290
          'title' => $property,
291
          'value' => $value,
292
      );
293
    }
294
295 bc175c27 Assos Assos
  $ldaps = (strpos(drupal_strtolower($server_object->address), 'ldaps') !== FALSE) ? 'y' : 'n';
296 85ad3d82 Assos Assos
  $servers[$sid][] = array(
297
    'title' => 'ldaps in address',
298
    'value' => $ldaps,
299
    );
300
301
  $binddn = trim($server_object->binddn) ? 'yes' : 'no';
302
  $servers[$sid][] = array(
303
    'title' => 'binddn present',
304
    'value' => $binddn,
305
    );
306
307
  $basedn = count($server_object->basedn);
308
  $servers[$sid][] = array(
309
    'title' => 'basedn count',
310
    'value' => $basedn,
311
    );
312
313
  }
314
315
  return array($status, $servers);
316
}
317
318
function ldap_help_get_ldap_authentication() {
319
320
  ldap_servers_module_load_include('php', 'ldap_authentication', 'LdapAuthenticationConfAdmin.class');
321
  $auth_conf = new LdapAuthenticationConfAdmin();
322
  $conf_form = $auth_conf->drupalForm();
323
324
  $items['logon']['authenticationMode'] = 'string';
325
  $items['logon']['authenticationServers'] = 'checkbox';
326
  $items['restrictions']['allowOnlyIfTextInDn'] = 'string';
327
  $items['restrictions']['excludeIfTextInDn'] = 'string';
328
  $items['restrictions']['allowTestPhp'] = 'string';
329
  $items['restrictions']['excludeIfNoAuthorizations '] = 'checkbox';
330
  $items['drupal_accounts']['loginConflictResolve'] = 'radios';
331
  $items['drupal_accounts']['acctCreation'] = 'radios';
332
  $items['email']['emailOption'] = 'radios';
333
  $items['email']['emailUpdate'] = 'radios';
334
  $items['sso']['ssoRemoteUserStripDomainName'] = 'checkbox';
335
  $items['sso']['seamlessLogin'] = 'checkbox';
336
  $items['sso']['cookieExpire '] = 'select';
337
  $items['sso']['ldapImplementation'] = 'select';
338
339
  $status = ldap_help_parse_form($conf_form, $items);
340
341
  return $status;
342
}
343
344
function ldap_help_get_ldap_user() {
345
  ldap_servers_module_load_include('php', 'ldap_user', 'LdapUserConfAdmin.class');
346
  $conf = new LdapUserConfAdmin();
347
  $form = $conf->drupalForm();
348
349
  $items['drupal_accounts']['loginConflictResolve'] = 'radios';
350
  $items['drupal_accounts']['acctCreation'] = 'radios';
351
352
  $status = ldap_help_parse_form($form, $items);
353
354
  return $status;
355
}
356
357
358
359
360
function ldap_help_get_ldap_authorization() {
361
  $status = array();
362
  ldap_servers_module_load_include('php', 'ldap_authorization', 'LdapAuthorizationConsumerConfAdmin.class');
363
  ldap_servers_module_load_include('inc', 'ldap_servers', 'ldap_servers.settings');
364
  ldap_servers_module_load_include('inc', 'ldap_servers', 'ldap_servers.admin');
365
366
  $servers = ldap_servers_get_servers(NULL, 'enabled');
367
  $consumers = ldap_authorization_get_consumers();
368
369
  if (count($servers) == 0) {
370
    return array();
371
  }
372
373
  foreach ($servers as $sid => $server) {
374
    $server_options[$sid] = $server->name;
375
  }
376
377
378
  $items['status']['mapping_id'] = 'string';
379
  $items['status']['consumer_type'] = 'string';
380
  $items['status']['status'] = 'string';
381
  $items['status']['only_ldap_authenticated'] = 'string';
382
383
  // $items['filter_and_mappings']['mappings'] = 'string';
384
  $items['use_filter']['mappings'] = 'string';
385
386
  $items['misc_settings']['allow_synch_both_directions'] = 'string';
387
  $items['misc_settings']['synchronization_modes'] = 'string';
388
  $items['misc_settings']['synchronization_actions'] = 'string';
389
390
  foreach ($consumers as $consumer_type => $consumer) {
391
    $consumer_obj = ldap_authorization_get_consumer_object($consumer_type);
392
    $mapping_admin = new LdapAuthorizationConsumerConfAdmin($consumer_obj, FALSE);
393
    $authorization_form = $mapping_admin->drupalForm($server_options, 'edit');
394
    $status[$consumer_type] = ldap_help_parse_form($authorization_form, $items);
395
    $maps = $authorization_form['filter_and_mappings']['mappings']['#default_value'];
396
    $map_content = (trim($maps)) ? "mappings present" : "empty";
397
    if ($map_content == 'data present') {
398
      $map_content .= ($maps == drupal_strtolower($maps)) ? ', lower case' : ', mixed case';
399
    }
400
    $status[$consumer_type][] = array(
401
      'title' => 'mappings',
402
      'value' => $map_content,
403
    );
404
405
  }
406
  return $status;
407
408
}
409
410
411
function ldap_help_parse_form($form, $items) {
412
413
  $status = array();
414
  foreach ($form as $fieldset_name => $field) {
415
    foreach ($field as $field_name => $field_data) {
416
      if (isset($items[$fieldset_name][$field_name])) {
417
        $value = "";
418
        if (!@is_array($field_data['#default_value'])) {
419
          $default_value = @$field_data['#default_value'];
420
        }
421
        else {
422
          $default_value = join(', ', array_values($field_data['#default_value']));
423
        }
424
425
        switch ($field_data['#type']) {
426
          case 'radios':
427
            $value = $field_data['#options'][$default_value];
428
            break;
429
          case 'select':
430
          case 'checkboxes':
431
            $value = $default_value;
432
            break;
433
          case 'checkbox':
434
            $value = (boolean)($field_data['#default_value']) ? 'y' : 'n';
435
            break;
436
          case 'hidden':
437
            $value = $field_data['#value'];
438
            break;
439
          case 'textarea':
440
          case 'textfield':
441
442
            $value = $default_value;
443
            break;
444
        }
445
        if ($items[$fieldset_name][$field_name] == 'empty') {
446 bc175c27 Assos Assos
          $value = ((boolean)trim($value)) ? 'populated' : 'empty';
447 85ad3d82 Assos Assos
        }
448
        $status[] = array(
449
          'title' => $field_name,
450
          'value' => $value,
451
        );
452
453
      }
454
455
    }
456
457
  }
458
459
  return $status;
460
461
462
}