2 /***************************************************************************
3 * Copyright (C) 2003-2009 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 'groupex/donne-chall.php' => $this->make_hook('chall', AUTH_PUBLIC
),
28 'groupex/export-econfiance.php' => $this->make_hook('econf', AUTH_PUBLIC
, 'user', NO_HTTPS
),
30 'webservices/manageurs.php' => $this->make_hook('manageurs', AUTH_PUBLIC
, 'user', NO_HTTPS
),
32 'auth-redirect.php' => $this->make_hook('redirect', AUTH_COOKIE
),
33 'auth-groupex.php' => $this->make_hook('groupex_old', AUTH_COOKIE
),
34 'auth-groupex' => $this->make_hook('groupex', AUTH_COOKIE
),
35 'admin/auth-groupes-x' => $this->make_hook('admin_authgroupesx', AUTH_MDP
, 'admin'),
39 function handler_chall(&$page)
41 $_SESSION["chall"] = uniqid(rand(), 1);
42 echo $_SESSION["chall"] . "\n" . session_id();
46 function handler_econf(&$page)
50 $cle = $globals->core
->econfiance
;
52 if (S
::v('chall') && $_GET['PASS'] == md5(S
::v('chall').$cle)) {
54 $res = XDB
::query("SELECT password FROM auth_user_md5 WHERE user_id=10154");
55 $pass = $res->fetchOneCell();
57 $list = new MMList(10154, $pass, "x-econfiance.polytechnique.org");
58 $members = $list->get_members('membres');
59 if (is_array($members)) {
61 foreach($members[1] as $member) {
62 if (preg_match('/^([^.]*.[^.]*.(\d\d\d\d))@polytechnique.org$/',
63 $member[1], $matches))
65 $membres[] = "a.alias='{$matches[1]}'";
70 $where = join(' OR ',$membres);
73 "SELECT u.prenom,u.nom,a.alias
74 FROM auth_user_md5 AS u
75 INNER JOIN aliases AS a ON ( u.user_id = a.id AND a.type!='homonyme' )
79 $res = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<membres>\n\n";
81 while (list ($prenom1,$nom1,$email1) = $all->next()) {
83 $res .= "\t<nom>$nom1</nom>\n";
84 $res .= "\t<prenom>$prenom1</prenom>\n";
85 $res .= "\t<email>$email1</email>\n";
86 $res .= "</membre>\n\n";
89 $res .= "</membres>\n\n";
91 header('Content-Type: text/xml; charset="UTF-8"');
97 function handler_manageurs(&$page)
101 require_once 'webservices/manageurs.server.inc.php';
103 $ips = array_flip(explode(' ', $globals->manageurs
->authorized_ips
));
104 if ($ips && isset($ips[$_SERVER['REMOTE_ADDR']])) {
105 $server = xmlrpc_server_create();
107 xmlrpc_server_register_method($server, 'get_annuaire_infos', 'get_annuaire_infos');
108 xmlrpc_server_register_method($server, 'get_nouveau_infos', 'get_nouveau_infos');
110 $request = @$GLOBALS['HTTP_RAW_POST_DATA'];
111 $response = xmlrpc_server_call_method($server, $request, null
);
112 header('Content-Type: text/xml');
114 xmlrpc_server_destroy($server);
120 function handler_redirect(&$page)
122 http_redirect(Env
::v('dest', '/'));
125 function handler_groupex_old(&$page)
127 return $this->handler_groupex($page, 'iso-8859-1');
130 function handler_groupex(&$page, $charset = 'utf8')
132 $this->load('auth.inc.php');
133 $page->assign('referer', true
);
135 $gpex_pass = $_GET["pass"];
136 $gpex_url = urldecode($_GET["url"]);
137 if (strpos($gpex_url, '?') === false
) {
138 $gpex_url .= "?PHPSESSID=" . $_GET["session"];
140 $gpex_url .= "&PHPSESSID=" . $_GET["session"];
143 // Normalize the return URL.
144 if (!preg_match("/^(http|https):\/\/.*/",$gpex_url)) {
145 $gpex_url = "http://$gpex_url";
147 $gpex_challenge = $_GET["challenge"];
149 // Update the last login information (unless the user is in SUID).
151 if (!isset($_SESSION['suid'])) {
153 S
::logger($uid)->log('connexion_auth_ext', $platal->path
);
156 // Iterate over the auth token to find which one did sign the request.
157 $res = XDB
::iterRow('SELECT privkey, name, datafields, returnurls FROM groupesx_auth');
158 while (list($privkey,$name,$datafields,$returnurls) = $res->next()) {
159 if (md5($gpex_challenge.$privkey) == $gpex_pass) {
160 $returnurls = trim($returnurls);
161 // We check that the return url matches a per-key regexp to prevent
162 // replay attacks (more exactly to force replay attacks to redirect
163 // the user to the real GroupeX website, which defeats the attack).
164 if (empty($returnurls) || @preg_match
($returnurls, $gpex_url)) {
165 $returl = $gpex_url . gpex_make_params($gpex_challenge, $privkey, $datafields, $charset);
166 http_redirect($returl);
167 } else if (S
::admin()) {
168 $page->kill("La requête d'authentification a échouée (url de retour invalide).");
173 // Otherwise (if no valid request was found, or if the return URL is not
174 // acceptable), the user is redirected back to our homepage.
178 function handler_admin_authgroupesx(&$page, $action = 'list', $id = null
)
180 $page->setTitle('Administration - Auth groupes X');
181 $page->assign('title', 'Gestion de l\'authentification centralisée');
182 $table_editor = new PLTableEditor('admin/auth-groupes-x','groupesx_auth','id');
183 $table_editor->describe('name','nom',true
);
184 $table_editor->describe('privkey','clé privée',false
);
185 $table_editor->describe('datafields','champs renvoyés',true
);
186 $table_editor->describe('returnurls','urls de retour',true
);
187 $table_editor->apply($page, $action, $id);
191 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: