Subversion Repositories Applications.papyrus

Rev

Rev 832 | Rev 1087 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
220 alex 1
<?php
2
//vim: set expandtab tabstop=4 shiftwidth=4:
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2003 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// |                                                                                                      |
9
// | This library is free software; you can redistribute it and/or                                        |
10
// | modify it under the terms of the GNU Lesser General Public                                           |
11
// | License as published by the Free Software Foundation; either                                         |
12
// | version 2.1 of the License, or (at your option) any later version.                                   |
13
// |                                                                                                      |
14
// | This library is distributed in the hope that it will be useful,                                      |
15
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
16
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
17
// | Lesser General Public License for more details.                                                      |
18
// |                                                                                                      |
19
// | You should have received a copy of the GNU Lesser General Public                                     |
20
// | License along with this library; if not, write to the Free Software                                  |
21
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
22
// |                                                                                                      |
23
// +------------------------------------------------------------------------------------------------------+
1054 jp_milcent 24
// CVS : $Id: pap_initialise_auth.inc.php,v 1.22 2006-11-20 17:29:42 jp_milcent Exp $
220 alex 25
/**
26
* Initialisation de l'authentification.
27
*
28
* Suite à la recherche des informations depuis la base de données nous initialisons
29
* l'authentification des utilisateurs si le site l'utilise.
30
* La page contient le code initialisant l'objet PEAR créé par Net_URL contenant l'url
31
* courante demandée par l'utilisateur.
32
* Nous initialisons aussi l'identification de l'utilisateur et le démarage de la session.
33
*
34
*@package Papyrus
35
//Auteur original :
36
*@author            Alexandre GRANIER <alex@tela-botanica.org>
37
//Autres auteurs :
38
*@author            Jean-Pascal MILCENT <jpm@tela-botanica.org>
39
*@copyright         Tela-Botanica 2000-2004
1054 jp_milcent 40
*@version           $Revision: 1.22 $ $Date: 2006-11-20 17:29:42 $
220 alex 41
// +------------------------------------------------------------------------------------------------------+
42
*/
207 jpm 43
 
44
// +------------------------------------------------------------------------------------------------------+
220 alex 45
// |                                            ENTÊTE du PROGRAMME                                       |
46
// +------------------------------------------------------------------------------------------------------+
47
 
48
/** <br> Inclusion de l'authentification de PEAR.*/
832 florian 49
include_once PAP_CHEMIN_API_PEAR.'Auth/Auth.php';
220 alex 50
 
51
/** Inclusion de la bibliothèque de fonctions d'identification.
52
* Contient entre autre la fonction founissant le formulaire d'identification pour Auth de Pear.
53
* Cette inclusion n'a lieu que si le site utilise l'identification.
54
*/
55
include_once GEN_CHEMIN_PAP.'bibliotheque/fonctions/pap_identification.fonct.php' ;
56
include_once GEN_CHEMIN_PAP.'bibliotheque/fonctions/pap_site.fonct.php' ;
57
 
58
// +------------------------------------------------------------------------------------------------------+
59
// |                                            CORPS du PROGRAMME                                        |
60
// +------------------------------------------------------------------------------------------------------+
61
 
62
// +------------------------------------------------------------------------------------------------------+
63
// Gestion de l'identification des utilisateurs et des sessions
64
 
65
// +------------------------------------------------------------------------------------------------------+
207 jpm 66
// Récupération des informations d'identification pour le site courant
67
 
68
// Récupération des informations sur le site
208 alex 69
$requete_auth = 'SELECT gen_site_auth.*, gs_id_site '.
207 jpm 70
                'FROM gen_site_auth, gen_site '.
220 alex 71
                'WHERE gs_ce_auth <> 0 '.
207 jpm 72
                'AND gs_ce_auth = gsa_id_auth';
73
 
74
$resultat_auth = $db->query($requete_auth);
75
(DB::isError($resultat_auth))
76
    ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_auth->getMessage(), $requete_auth))
77
    : '';
78
 
79
while ($ligne_auth = $resultat_auth->fetchRow(DB_FETCHMODE_OBJECT)) {
80
    // Ajout des valeurs communes aux différents type d'auth
81
    $GLOBALS['_PAPYRUS_']['auth'][$ligne_auth->gsa_id_auth]['gsa_nom'] = $ligne_auth->gsa_nom;
82
    $GLOBALS['_PAPYRUS_']['auth'][$ligne_auth->gsa_id_auth]['gsa_abreviation'] = $ligne_auth->gsa_abreviation;
220 alex 83
    $GLOBALS['_PAPYRUS_']['auth'][$ligne_auth->gsa_id_auth]['gsa_ce_type_auth'] = $ligne_auth->gsa_ce_type_auth;
207 jpm 84
 
443 ddelon 85
 
314 jpm 86
    if ($ligne_auth->gsa_id_auth == $GLOBALS['_GEN_commun']['info_site']->gs_ce_auth) {
87
        $GLOBALS['_GEN_commun']['info_auth'] = $ligne_auth;
207 jpm 88
    }
89
 
90
    if ($ligne_auth->gsa_ce_auth_bdd != 0) {
91
        //Identification via une base de donnée :
92
        $requete_auth_bdd = 'SELECT * '.
93
                            'FROM gen_site_auth_bdd '.
94
                            'WHERE gsab_id_auth_bdd = '.$ligne_auth->gsa_ce_auth_bdd;
95
 
96
        $resultat_auth_bdd = $db->query($requete_auth_bdd);
97
        (DB::isError($resultat_auth_bdd))
98
            ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_auth_bdd->getMessage(), $requete_auth_bdd))
99
            : '';
220 alex 100
        $tab_auth_bdd = $resultat_auth_bdd->fetchRow(DB_FETCHMODE_OBJECT) ;
314 jpm 101
        if ($ligne_auth->gsa_id_auth == $GLOBALS['_GEN_commun']['info_site']->gs_ce_auth) {
102
            $GLOBALS['_GEN_commun']['info_auth_bdd'] = $tab_auth_bdd ;
103
            // Gestion des arguments de l'authentification
104
            if (isset($GLOBALS['_GEN_commun']['info_auth_bdd']->gsab_parametres)) {
105
                $arguments = explode(' ', $GLOBALS['_GEN_commun']['info_auth_bdd']->gsab_parametres);
106
                for ($i = 0; $i < count($arguments); $i++) {
107
                    $attr = explode('=', $arguments[$i]);
108
                    if ($attr[0] != '') {
109
                        $GLOBALS['_GEN_commun']['info_auth_bdd']->$attr[0] = (isset($attr[1]) ? $attr[1] : '');
110
                    }
111
                }
112
            }
207 jpm 113
        }
443 ddelon 114
 
115
       	$GLOBALS['_PAPYRUS_']['auth'][$ligne_auth->gsa_id_auth] = array_merge((array)$GLOBALS['_PAPYRUS_']['auth'][$ligne_auth->gsa_id_auth], (array) $tab_auth_bdd);
207 jpm 116
        $resultat_auth_bdd->free();
117
    } else if ($ligne_auth->gsa_ce_auth_ldap != 0) {
118
        //Identification via LDAP :
119
        $requete_auth_ldap =    'SELECT * '.
120
                                'FROM gen_site_auth_ldap '.
121
                                'WHERE gsal_id_auth_ldap = '.$ligne_auth->gsa_ce_auth_ldap;
122
 
123
        $resultat_auth_ldap = $db->query($requete_auth_ldap);
124
        (DB::isError($resultat_auth_ldap))
125
            ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_auth_ldap->getMessage(), $requete_auth_ldap))
126
            : '';
220 alex 127
        $tab_auth_ldap = $resultat_auth_ldap->fetchRow(DB_FETCHMODE_OBJECT);
207 jpm 128
        if ($ligne_auth->gsa_id_auth == $_GEN_commun['info_site']->gs_ce_auth) {
314 jpm 129
            $GLOBALS['_GEN_commun']['info_auth_ldap'] = $tab_auth_ldap;
207 jpm 130
        }
443 ddelon 131
        $GLOBALS['_PAPYRUS_']['auth'][$ligne_auth->gsa_id_auth] = array_merge((array) $GLOBALS['_PAPYRUS_']['auth'][$ligne_auth->gsa_id_auth], (array) $tab_auth_ldap);
207 jpm 132
        $resultat_auth_ldap->free();
133
    } else {
134
        die('ERREUR Papyrus : impossible de trouver les information authentification. <br />'.
135
            'Identifiant auth : '.$ligne_auth->gs_ce_auth.'<br />'.
136
            'Ligne n° : '. __LINE__ .'<br />'.
137
            'Fichier : '. __FILE__ );
138
    }
220 alex 139
 
208 alex 140
    // On teste le type d'authentification
220 alex 141
    $tab_type_site = GEN_retournerTableauTypeSiteExterne($db);
142
    $types_site = '';
143
    foreach ($tab_type_site as $val) {
144
        $types_site .= $val['id'].', ';
145
    }
146
    $types_site = substr($types_site, 0, -2);
147
    $requete =  'SELECT gsr_id_valeur '.
148
                'FROM gen_site_relation '.
149
                'WHERE gsr_id_site_01 = '.$ligne_auth->gs_id_site.' '.
150
                'AND gsr_id_site_01 = gsr_id_site_02 '.
151
                'AND gsr_id_valeur IN ('.$types_site.')';
152
    $type_site_externe = $db->getOne($requete);
153
    (DB::isError($type_site_externe))
154
            ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $type_site_externe->getMessage(), $requete))
155
            : '';
156
    // Type du site de l'authentification
157
    if ($type_site_externe != '') {
158
        $GLOBALS['_PAPYRUS_']['auth'][$ligne_auth->gsa_id_auth]['type_site_externe'] = $type_site_externe;
159
    }
207 jpm 160
}
161
$resultat_auth->free();
112 jpm 162
 
220 alex 163
// Nour regardons à quel type d'identification nous avons à faire:
314 jpm 164
$auth_courante = $GLOBALS['_PAPYRUS_']['auth'][$GLOBALS['_GEN_commun']['info_site']->gs_ce_auth] ;
220 alex 165
if ($auth_courante['gsa_ce_type_auth'] == 1) {
166
    // Authentification via une base de données
271 jpm 167
    $GLOBALS['_PAPYRUS_']['auth']['param_bdd'] = array ('dsn' => $auth_courante['gsab_dsn'],
220 alex 168
                        'table' => $auth_courante['gsab_nom_table'],
169
                        'usernamecol' => $auth_courante['gsab_nom_champ_login'],
170
                        'passwordcol' => $auth_courante['gsab_nom_champ_mdp'],
171
                        'cryptType' => $auth_courante['gsab_cryptage_mdp'],
172
                        'db_fields' => '*');
173
    // L'authentification courrante
314 jpm 174
    $GLOBALS['_GEN_commun']['pear_auth'] = new Auth('DB', $GLOBALS['_PAPYRUS_']['auth']['param_bdd'], 'GEN_afficherInfoIdentification', 1);
220 alex 175
 
176
} else if ($auth_courante['gsa_ce_type_auth'] == 2) {
177
    // Authentification via LDAP
271 jpm 178
    $GLOBALS['_PAPYRUS_']['auth']['param_ldap'] = array (   'host' => $auth_courante['gsal_serveur'],
220 alex 179
                            'port' => $auth_courante['gsal_port'],
180
                            'basedn' => $auth_courante['gsal_base_dn'],
181
                            'userattr' => $auth_courante['gsal_uid']);
314 jpm 182
    $GLOBALS['_GEN_commun']['pear_auth'] = new Auth('LDAP', $GLOBALS['_PAPYRUS_']['auth']['param_ldap'], 'GEN_afficherInfoIdentification', 1);
220 alex 183
} else {
184
    die('ERREUR Papyrus : type identification introuvable. <br />'.
185
        'Type identification : '.$auth_courante['gsa_ce_type_auth'].'<br />'.
186
        'Ligne n° : '. __LINE__ . '<br />'.
187
        'Fichier : '. __FILE__ . '<br />');
188
}
189
 
1054 jp_milcent 190
// +------------------------------------------------------------------------------------------------------+
191
// Définition du nom de la session
192
$GLOBALS['_GEN_commun']['pear_auth']->setSessionname('gen_'.$GLOBALS['_GEN_commun']['info_auth']->gsa_abreviation);
193
// Démarage de la session
314 jpm 194
$GLOBALS['_GEN_commun']['pear_auth']->start();
220 alex 195
 
196
/* +--Fin du code ---------------------------------------------------------------------------------------+
5 jpm 197
* $Log: not supported by cvs2svn $
1054 jp_milcent 198
* Revision 1.21  2006/04/28 12:41:49  florian
199
* corrections erreurs chemin
200
*
832 florian 201
* Revision 1.20  2006/03/15 09:30:50  florian
202
* suppression des echos, qui entrainaient des problemes d'affichages
203
*
775 florian 204
* Revision 1.19  2005/09/20 17:01:22  ddelon
205
* php5 et bugs divers
206
*
443 ddelon 207
* Revision 1.18  2005/07/07 09:15:36  alexandre_tb
208
* mise en place de la co-authentification Wikini - papyrus.
209
*  - ajout d'une requete pour récupérer le mot de passe
210
*
406 alexandre_ 211
* Revision 1.17  2005/04/27 15:06:21  alex
212
* ajout de l'authentification wiki.
213
*
363 alex 214
* Revision 1.16  2005/03/25 13:08:20  jpm
215
* Déplacement de la gestion des arguments de l'authentification.
216
*
314 jpm 217
* Revision 1.15  2005/03/24 15:04:26  alex
218
* ajout d'un appel à session_set_cookie_params pour allonger la durée de la session
219
*
313 alex 220
* Revision 1.14  2005/03/15 14:20:01  jpm
221
* Gestion des arguments de l'identification courante.
222
*
307 jpm 223
* Revision 1.13  2005/02/22 18:27:24  jpm
224
* Changement de nom de variables.
225
*
271 jpm 226
* Revision 1.12  2004/12/15 15:24:45  alex
227
* suppression d'un notice
228
*
232 alex 229
* Revision 1.11  2004/12/13 18:06:52  alex
230
* authentification spip presque parfaite
231
*
227 alex 232
* Revision 1.10  2004/12/07 19:13:51  alex
233
* authentification spip
234
*
220 alex 235
* Revision 1.7  2004/12/07 10:26:27  jpm
236
* Correction for en foreach.
237
*
219 jpm 238
* Revision 1.6  2004/12/06 12:42:02  alex
239
* en cours
240
*
208 alex 241
* Revision 1.5  2004/12/06 12:12:28  jpm
242
* Début de gestion des auth multiples.
243
*
207 jpm 244
* Revision 1.4  2004/10/25 16:28:47  jpm
245
* Ajout de nouvelles balises Papyrus, ajout vérification mise à jour de Papyrus, meilleure gestion des sessions...
246
*
112 jpm 247
* Revision 1.3  2004/10/15 18:29:19  jpm
248
* Modif pour gérer l'appli installateur de Papyrus.
249
*
67 jpm 250
* Revision 1.2  2004/06/30 07:23:36  jpm
251
* Ajout d'un commentaire.
252
*
21 jpm 253
* Revision 1.1  2004/06/16 08:12:01  jpm
254
* Changement de nom de Génésia en Papyrus.
255
* Changement de l'arborescence.
256
*
5 jpm 257
* Revision 1.6  2004/05/01 11:40:21  jpm
258
* Suppression de code intégré dans le fichier de l'applette Identification.
220 alex 259
*
260
* Revision 1.5  2004/04/28 12:04:31  jpm
261
* Changement du modèle de la base de données.
262
*
263
* Revision 1.4  2004/04/22 08:29:11  jpm
264
* Transformation de $GS_GLOBAL en $_GEN_commun.
265
*
266
* Revision 1.3  2004/04/09 16:20:33  jpm
267
* Gestion de l'authentification uniquement.
268
* Gestion des tables i18n.
269
*
270
* Revision 1.2  2004/04/02 16:29:58  jpm
271
* Ajout de la gestion de la déconnexion et reconnexion.
272
*
273
* Revision 1.1  2004/04/02 08:54:58  jpm
274
* Création du fichier qui contient l'initialisation des objets Pear, hormis la base de données.
275
*
276
* +--Fin du code ----------------------------------------------------------------------------------------+
277
*/
278
?>