2 /***************************************************************************
3 * Copyright (C) 2003-2007 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class AuthModule
extends PLModule
27 'login' => $this->make_hook('login', AUTH_COOKIE
),
28 'groupex/donne-chall.php'
29 => $this->make_hook('chall', AUTH_PUBLIC
),
30 'groupex/export-econfiance.php'
31 => $this->make_hook('econf', AUTH_PUBLIC
),
33 'webservices/manageurs.php'
34 => $this->make_hook('manageurs', AUTH_PUBLIC
),
36 'auth-redirect.php' => $this->make_hook('redirect', AUTH_COOKIE
),
37 'auth-groupex.php' => $this->make_hook('groupex', AUTH_COOKIE
),
38 'admin/auth-groupes-x' => $this->make_hook('admin_authgroupesx', AUTH_MDP
, 'admin'),
42 function handler_login(&$page)
44 $allkeys = func_get_args();
46 $url = join('/',$allkeys);
47 pl_redirect($url ?
$url : 'events');
50 function handler_chall(&$page)
52 $_SESSION["chall"] = uniqid(rand(), 1);
53 echo $_SESSION["chall"] . "\n" . session_id();
57 function handler_econf(&$page)
61 $cle = $globals->core
->econfiance
;
63 if (S
::v('chall') && $_GET['PASS'] == md5(S
::v('chall').$cle)) {
65 $res = XDB
::query("SELECT password FROM auth_user_md5 WHERE user_id=10154");
66 $pass = $res->fetchOneCell();
68 $list = new MMList(10154, $pass, "x-econfiance.polytechnique.org");
69 $members = $list->get_members('membres');
70 if (is_array($members)) {
72 foreach($members[1] as $member) {
73 if (preg_match('/^([^.]*.[^.]*.(\d\d\d\d))@polytechnique.org$/',
74 $member[1], $matches))
76 $membres[] = "a.alias='{$matches[1]}'";
81 $where = join(' OR ',$membres);
84 "SELECT u.prenom,u.nom,a.alias
85 FROM auth_user_md5 AS u
86 INNER JOIN aliases AS a ON ( u.user_id = a.id AND a.type!='homonyme' )
90 $res = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<membres>\n\n";
92 while (list ($prenom1,$nom1,$email1) = $all->next()) {
94 $res .= "\t<nom>$nom1</nom>\n";
95 $res .= "\t<prenom>$prenom1</prenom>\n";
96 $res .= "\t<email>$email1</email>\n";
97 $res .= "</membre>\n\n";
100 $res .= "</membres>\n\n";
102 header('Content-Type: text/xml; charset="ISO-8859-1"');
108 function handler_manageurs(&$page)
112 require_once 'webservices/manageurs.server.inc.php';
114 $ips = array_flip(explode(' ', $globals->manageurs
->authorized_ips
));
115 if ($ips && isset($ips[$_SERVER['REMOTE_ADDR']])) {
116 $server = xmlrpc_server_create();
118 xmlrpc_server_register_method($server, 'get_annuaire_infos', 'get_annuaire_infos');
119 xmlrpc_server_register_method($server, 'get_nouveau_infos', 'get_nouveau_infos');
121 $request = $GLOBALS['HTTP_RAW_POST_DATA'];
122 $response = xmlrpc_server_call_method($server, $request, null
);
123 header('Content-Type: text/xml');
125 xmlrpc_server_destroy($server);
131 function handler_redirect(&$page)
133 http_redirect(Env
::v('dest', '/'));
136 function handler_groupex(&$page)
138 require_once dirname(__FILE__
).'/auth/auth.inc.php';
139 $page->assign('referer', true
);
141 $gpex_pass = $_GET["pass"];
142 $gpex_url = urldecode($_GET["url"]);
143 if (strpos($gpex_url, '?') === false
) {
144 $gpex_url .= "?PHPSESSID=" . $_GET["session"];
146 $gpex_url .= "&PHPSESSID=" . $_GET["session"];
149 /* a-t-on besoin d'ajouter le http:// ? */
150 if (!preg_match("/^(http|https):\/\/.*/",$gpex_url))
151 $gpex_url = "http://$gpex_url";
152 $gpex_challenge = $_GET["challenge"];
154 // mise à jour de l'heure et de la machine de dernier login sauf quand on est en suid
155 if (!isset($_SESSION['suid'])) {
156 $logger = (isset($_SESSION['log']) && $_SESSION['log']->uid
== $uid)
157 ?
$_SESSION['log'] : new CoreLogger($uid);
159 $logger->log('connexion_auth_ext', $platal->path
);
162 /* on parcourt les entrees de groupes_auth */
163 $res = XDB
::iterRow('select privkey,name,datafields from groupesx_auth');
165 while (list($privkey,$name,$datafields) = $res->next()) {
166 if (md5($gpex_challenge.$privkey) == $gpex_pass) {
167 $returl = $gpex_url.gpex_make_params($gpex_challenge,$privkey,$datafields);
168 http_redirect($returl);
172 /* si on n'a pas trouvé, on renvoit sur x.org */
173 http_redirect('https://www.polytechnique.org/');
175 function handler_admin_authgroupesx(&$page, $action = 'list', $id = null
) {
176 $page->assign('xorg_title','Polytechnique.org - Administration - Auth groupes X');
177 $page->assign('title', 'Gestion de l\'authentification centralisée');
178 $table_editor = new PLTableEditor('admin/auth-groupes-x','groupesx_auth','id');
179 $table_editor->describe('name','nom',true
);
180 $table_editor->describe('privkey','clé privée',false
);
181 $table_editor->describe('datafields','champs renvoyés',true
);
182 $table_editor->apply($page, $action, $id);