Merge commit 'origin/fusionax' into account
[platal.git] / modules / auth.php
CommitLineData
5d292fd8 1<?php
2/***************************************************************************
179afa7f 3 * Copyright (C) 2003-2008 Polytechnique.org *
5d292fd8 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(
4c745880 27 'groupex/donne-chall.php'
87221416 28 => $this->make_hook('chall', AUTH_PUBLIC),
29 'groupex/export-econfiance.php'
91826112 30 => $this->make_hook('econf', AUTH_PUBLIC, 'user', NO_HTTPS),
d5749a28 31
87221416 32 'webservices/manageurs.php'
91826112 33 => $this->make_hook('manageurs', AUTH_PUBLIC, 'user', NO_HTTPS),
87221416 34
35 'auth-redirect.php' => $this->make_hook('redirect', AUTH_COOKIE),
670b0ac0 36 'auth-groupex.php' => $this->make_hook('groupex_old', AUTH_COOKIE),
37 'auth-groupex' => $this->make_hook('groupex', AUTH_COOKIE),
92423144 38 'admin/auth-groupes-x' => $this->make_hook('admin_authgroupesx', AUTH_MDP, 'admin'),
5d292fd8 39 );
40 }
41
c9178c75 42 function handler_chall(&$page)
d5749a28 43 {
44 $_SESSION["chall"] = uniqid(rand(), 1);
45 echo $_SESSION["chall"] . "\n" . session_id();
46 exit;
47 }
48
c9178c75 49 function handler_econf(&$page)
d5749a28 50 {
51 global $globals;
52
d5749a28 53 $cle = $globals->core->econfiance;
54
cab08090 55 if (S::v('chall') && $_GET['PASS'] == md5(S::v('chall').$cle)) {
7f1ff426 56 $list = new MMList(User::getWithUID(10154), "x-econfiance.polytechnique.org");
9bb8bf21 57 $members = $list->get_members('membres');
d5749a28 58 if (is_array($members)) {
59 $membres = Array();
60 foreach($members[1] as $member) {
61 if (preg_match('/^([^.]*.[^.]*.(\d\d\d\d))@polytechnique.org$/',
62 $member[1], $matches))
63 {
64 $membres[] = "a.alias='{$matches[1]}'";
65 }
66 }
67 }
68
69 $where = join(' OR ',$membres);
70
08cce2ff 71 $all = XDB::iterRow(
d5749a28 72 "SELECT u.prenom,u.nom,a.alias
73 FROM auth_user_md5 AS u
74 INNER JOIN aliases AS a ON ( u.user_id = a.id AND a.type!='homonyme' )
75 WHERE $where
76 ORDER BY nom");
77
493b6abe 78 $res = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<membres>\n\n";
d5749a28 79
80 while (list ($prenom1,$nom1,$email1) = $all->next()) {
81 $res .= "<membre>\n";
82 $res .= "\t<nom>$nom1</nom>\n";
83 $res .= "\t<prenom>$prenom1</prenom>\n";
84 $res .= "\t<email>$email1</email>\n";
85 $res .= "</membre>\n\n";
86 }
87
88 $res .= "</membres>\n\n";
89
493b6abe 90 header('Content-Type: text/xml; charset="UTF-8"');
d5749a28 91 echo $res;
92 }
93 exit;
94 }
95
c9178c75 96 function handler_manageurs(&$page)
87221416 97 {
98 global $globals;
99
100 require_once 'webservices/manageurs.server.inc.php';
101
34c8c3b5 102 $ips = array_flip(explode(' ', $globals->manageurs->authorized_ips));
87221416 103 if ($ips && isset($ips[$_SERVER['REMOTE_ADDR']])) {
104 $server = xmlrpc_server_create();
105
106 xmlrpc_server_register_method($server, 'get_annuaire_infos', 'get_annuaire_infos');
107 xmlrpc_server_register_method($server, 'get_nouveau_infos', 'get_nouveau_infos');
108
206e75c3 109 $request = @$GLOBALS['HTTP_RAW_POST_DATA'];
87221416 110 $response = xmlrpc_server_call_method($server, $request, null);
111 header('Content-Type: text/xml');
112 print $response;
113 xmlrpc_server_destroy($server);
114 }
34c8c3b5 115
116 exit;
87221416 117 }
118
5d292fd8 119 function handler_redirect(&$page)
120 {
5e2307dc 121 http_redirect(Env::v('dest', '/'));
5d292fd8 122 }
123
670b0ac0 124 function handler_groupex_old(&$page)
125 {
126 return $this->handler_groupex($page, 'iso-8859-1');
127 }
128
129 function handler_groupex(&$page, $charset = 'utf8')
5d292fd8 130 {
460d8f55 131 $this->load('auth.inc.php');
6c85148b 132 $page->assign('referer', true);
5d292fd8 133
134 $gpex_pass = $_GET["pass"];
135 $gpex_url = urldecode($_GET["url"]);
136 if (strpos($gpex_url, '?') === false) {
137 $gpex_url .= "?PHPSESSID=" . $_GET["session"];
138 } else {
139 $gpex_url .= "&PHPSESSID=" . $_GET["session"];
140 }
141
142 /* a-t-on besoin d'ajouter le http:// ? */
670b0ac0 143 if (!preg_match("/^(http|https):\/\/.*/",$gpex_url)) {
5d292fd8 144 $gpex_url = "http://$gpex_url";
670b0ac0 145 }
5d292fd8 146 $gpex_challenge = $_GET["challenge"];
147
a7de4ef7 148 // mise à jour de l'heure et de la machine de dernier login sauf quand on est en suid
0469a7fb 149 $uid = S::i('uid');
0c02607e 150 if (!S::suid()) {
07e8e0ab 151 global $platal;
0c02607e 152 S::logger($uid)->log('connexion_auth_ext', $platal->path);
5d292fd8 153 }
154
155 /* on parcourt les entrees de groupes_auth */
e10bc2ef 156 $res = XDB::iterRow('SELECT privkey, name, datafields, returnurls FROM groupesx_auth');
5d292fd8 157
e10bc2ef 158 while (list($privkey,$name,$datafields,$returnurls) = $res->next()) {
5d292fd8 159 if (md5($gpex_challenge.$privkey) == $gpex_pass) {
50579de4
FB
160 $returnurls = trim($returnurls);
161 if (empty($returnurls) || @preg_match($returnurls, $gpex_url)) {
e10bc2ef
VZ
162 $returl = $gpex_url . gpex_make_params($gpex_challenge, $privkey, $datafields, $charset);
163 http_redirect($returl);
164 }
5d292fd8 165 }
166 }
167
a7de4ef7 168 /* si on n'a pas trouvé, on renvoit sur x.org */
8b00e0e0 169 http_redirect('https://www.polytechnique.org/');
5d292fd8 170 }
670b0ac0 171
172 function handler_admin_authgroupesx(&$page, $action = 'list', $id = null)
173 {
46f272fe 174 $page->setTitle('Administration - Auth groupes X');
a7de4ef7 175 $page->assign('title', 'Gestion de l\'authentification centralisée');
92423144 176 $table_editor = new PLTableEditor('admin/auth-groupes-x','groupesx_auth','id');
177 $table_editor->describe('name','nom',true);
a7de4ef7 178 $table_editor->describe('privkey','clé privée',false);
179 $table_editor->describe('datafields','champs renvoyés',true);
e10bc2ef 180 $table_editor->describe('returnurls','urls de retour',true);
92423144 181 $table_editor->apply($page, $action, $id);
eaf30d86 182 }
5d292fd8 183}
184
a7de4ef7 185// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
5d292fd8 186?>