[SPIP] ~2.1.12 -->2.1.25
[velocampus/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-2014 *
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')) return;
14
15 include_spip('auth/ldap');
16
17 // http://doc.spip.org/@install_etape_ldap4_dist
18 function install_etape_ldap4_dist()
19 {
20 $adresse_ldap = _request('adresse_ldap');
21 $login_ldap = _request('login_ldap');
22 $pass_ldap = _request('pass_ldap');
23 $port_ldap = _request('port_ldap');
24 $base_ldap = _request('base_ldap');
25 $base_ldap_text = _request('base_ldap_text');
26 if (!$base_ldap) $base_ldap = $base_ldap_text;
27
28 echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"');
29
30 $ldap_link = ldap_connect($adresse_ldap, $port_ldap);
31 @ldap_bind($ldap_link, $login_ldap, $pass_ldap);
32
33 // Essayer de verifier le chemin fourni
34 $r = @ldap_compare($ldap_link, $base_ldap, "objectClass", "");
35 $fail = (ldap_errno($ldap_link) == 32);
36
37 if ($fail) {
38 echo info_etape(_T('info_chemin_acces_annuaire')),
39 info_progression_etape(3,'etape_ldap','install/', true),
40 "<p class='resultat'><b>"._T('avis_operation_echec')."</b></p><p>"._T('avis_chemin_invalide_1'),
41 " (<tt>".htmlspecialchars($base_ldap)."</tt>) "._T('avis_chemin_invalide_2')."</p>";
42 }
43 else {
44 info_etape(_T('info_reglage_ldap'));
45 echo info_progression_etape(4,'etape_ldap','install/');
46
47 $statuts = liste_statuts_ldap();
48 $statut_ldap = defined('_INSTALL_STATUT_LDAP')
49 ? _INSTALL_STATUT_LDAP
50 : $GLOBALS['liste_des_statuts']['info_redacteurs'];
51
52
53 $res = install_propager(array('adresse_ldap','port_ldap','login_ldap','pass_ldap','protocole_ldap','tls_ldap'))
54 . "<input type='hidden' name='etape' value='ldap5' />"
55 . "<input type='hidden' name='base_ldap' value='" . htmlentities($base_ldap) . "' />"
56 . fieldset(_T('info_statut_utilisateurs_1'),
57 array(
58 'statut_ldap' => array(
59 'label' => _T('info_statut_utilisateurs_2').'<br />',
60 'valeur' => $statut_ldap,
61 'alternatives' => $statuts
62 )
63 )
64 )
65 . install_ldap_correspondances()
66 . bouton_suivant();
67
68 echo generer_form_ecrire('install', $res);
69 }
70
71 echo install_fin_html();
72 }
73
74 // http://doc.spip.org/@liste_statuts_ldap
75 function liste_statuts_ldap() {
76 $recom = array("info_administrateurs" => ("<b>" ._T('info_administrateur_1')."</b> "._T('info_administrateur_2')."<br />"),
77 "info_redacteurs" => ("<b>"._T('info_redacteur_1')."</b> "._T('info_redacteur_2')."<br />"),
78 "info_visiteurs" => ("<b>"._T('info_visiteur_1')."</b> "._T('info_visiteur_2')."<br />"));
79
80 $res = array();
81 foreach($GLOBALS['liste_des_statuts'] as $k => $v) {
82 if (isset($recom[$k])) $res[$v] = $recom[$k];
83 }
84 return $res;
85 }
86
87 function install_ldap_correspondances()
88 {
89 $champs = array();
90 foreach (is_array($GLOBALS['ldap_attributes']) ? $GLOBALS['ldap_attributes'] : array() as $champ => $v ) {
91 $nom = 'ldap_' . $champ;
92 $val = is_array($v) ? join(',', $v) : strval($v);
93 $champs[$nom]= array(
94 'label' => _T('ldap_correspondance', array('champ' => "<tt>$champ</tt>")).'<br />',
95 'valeur' => $val
96 );
97 }
98
99 return !$champs ? '' : fieldset(_T('ldap_correspondance_1'), $champs, '', _T('ldap_correspondance_2') . '<br /><br />');
100 }
101 ?>