migrate referent + profile edition
[platal.git] / modules / auth.php
CommitLineData
5d292fd8 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22class AuthModule extends PLModule
23{
24 function handlers()
25 {
26 return array(
27 'auth-redirect.php' => $this->make_hook('redirect', AUTH_COOKIE),
28 'auth-groupex.php' => $this->make_hook('groupex', AUTH_COOKIE),
29 );
30 }
31
32 function handler_redirect(&$page)
33 {
34 redirect(Env::get('dest', '/'));
35 }
36
37 function handler_groupex(&$page)
38 {
39 global $globals;
40
41 require_once dirname(__FILE__).'/auth/methods.inc.php';
42
43 $gpex_pass = $_GET["pass"];
44 $gpex_url = urldecode($_GET["url"]);
45 if (strpos($gpex_url, '?') === false) {
46 $gpex_url .= "?PHPSESSID=" . $_GET["session"];
47 } else {
48 $gpex_url .= "&PHPSESSID=" . $_GET["session"];
49 }
50
51 /* a-t-on besoin d'ajouter le http:// ? */
52 if (!preg_match("/^(http|https):\/\/.*/",$gpex_url))
53 $gpex_url = "http://$gpex_url";
54 $gpex_challenge = $_GET["challenge"];
55
56 // mise à jour de l'heure et de la machine de dernier login sauf quand on est en suid
57 if (!isset($_SESSION['suid'])) {
58 $logger = (isset($_SESSION['log']) && $_SESSION['log']->uid == $uid)
59 ? $_SESSION['log']
60 : new DiogenesCoreLogger($uid);
61 $logger->log('connexion_auth_ext', $_SERVER['PHP_SELF']);
62 }
63
64 /* on parcourt les entrees de groupes_auth */
65 $res = $globals->xdb->iterRow('select privkey,name,datafields from groupesx_auth');
66
67 while (list($privkey,$name,$datafields) = $res->next()) {
68 if (md5($gpex_challenge.$privkey) == $gpex_pass) {
69 $returl = $gpex_url.gpex_make_params($gpex_challenge,$privkey,$datafields);
70 redirect($returl);
71 }
72 }
73
74 /* si on n'a pas trouvé, on renvoit sur x.org */
75 redirect('https://www.polytechnique.org/');
76 }
77}
78
79?>