be16f6da4b3e26004162de42f0281045ac3be5e8
[lhc/web/www.git] / www / ecrire / install / etape_ldap4.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2017 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 if (!defined('_ECRIRE_INC_VERSION')) {
14 return;
15 }
16
17 include_spip('auth/ldap');
18
19 // http://code.spip.net/@install_etape_ldap4_dist
20 function install_etape_ldap4_dist() {
21 $adresse_ldap = _request('adresse_ldap');
22 $login_ldap = _request('login_ldap');
23 $pass_ldap = _request('pass_ldap');
24 $port_ldap = _request('port_ldap');
25 $base_ldap = _request('base_ldap');
26 $base_ldap_text = _request('base_ldap_text');
27 if (!$base_ldap) {
28 $base_ldap = $base_ldap_text;
29 }
30
31 echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"');
32
33 $ldap_link = ldap_connect($adresse_ldap, $port_ldap);
34 @ldap_bind($ldap_link, $login_ldap, $pass_ldap);
35
36 // Essayer de verifier le chemin fourni
37 $r = @ldap_compare($ldap_link, $base_ldap, 'objectClass', '');
38 $fail = (ldap_errno($ldap_link) == 32);
39
40 if ($fail) {
41 echo info_etape(_T('info_chemin_acces_annuaire')),
42 info_progression_etape(3, 'etape_ldap', 'install/', true),
43 "<div class='error'><p><b>" . _T('avis_operation_echec') . '</b></p><p>' . _T('avis_chemin_invalide_1'),
44 ' (<tt>' . spip_htmlspecialchars($base_ldap) . '</tt>) ' . _T('avis_chemin_invalide_2') . '</p></div>';
45 } else {
46 info_etape(_T('info_reglage_ldap'));
47 echo info_progression_etape(4, 'etape_ldap', 'install/');
48
49 $statuts = liste_statuts_ldap();
50 $statut_ldap = defined('_INSTALL_STATUT_LDAP')
51 ? _INSTALL_STATUT_LDAP
52 : $GLOBALS['liste_des_statuts']['info_redacteurs'];
53
54
55 $res = install_propager(array('adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap'))
56 . "<input type='hidden' name='etape' value='ldap5' />"
57 . "<input type='hidden' name='base_ldap' value='" . spip_htmlentities($base_ldap) . "' />"
58 . fieldset(
59 _T('info_statut_utilisateurs_1'),
60 array(
61 'statut_ldap' => array(
62 'label' => _T('info_statut_utilisateurs_2') . '<br />',
63 'valeur' => $statut_ldap,
64 'alternatives' => $statuts
65 )
66 )
67 )
68 . install_ldap_correspondances()
69 . bouton_suivant();
70
71 echo generer_form_ecrire('install', $res);
72 }
73
74 echo install_fin_html();
75 }
76
77 // http://code.spip.net/@liste_statuts_ldap
78 function liste_statuts_ldap() {
79 $recom = array(
80 'info_administrateurs' => ('<b>' . _T('info_administrateur_1') . '</b> ' . _T('info_administrateur_2') . '<br />'),
81 'info_redacteurs' => ('<b>' . _T('info_redacteur_1') . '</b> ' . _T('info_redacteur_2') . '<br />'),
82 'info_visiteurs' => ('<b>' . _T('info_visiteur_1') . '</b> ' . _T('info_visiteur_2') . '<br />')
83 );
84
85 $res = array();
86 foreach ($GLOBALS['liste_des_statuts'] as $k => $v) {
87 if (isset($recom[$k])) {
88 $res[$v] = $recom[$k];
89 }
90 }
91
92 return $res;
93 }
94
95 function install_ldap_correspondances() {
96 $champs = array();
97 foreach (is_array($GLOBALS['ldap_attributes']) ? $GLOBALS['ldap_attributes'] : array() as $champ => $v) {
98 $nom = 'ldap_' . $champ;
99 $val = is_array($v) ? join(',', $v) : strval($v);
100 $champs[$nom] = array(
101 'label' => _T('ldap_correspondance', array('champ' => "<tt>$champ</tt>")) . '<br />',
102 'valeur' => $val
103 );
104 }
105
106 return !$champs ?
107 '' : fieldset(_T('ldap_correspondance_1'), $champs, '', _T('ldap_correspondance_2') . '<br /><br />');
108 }