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