5d292fd8 |
1 | <?php |
2 | /*************************************************************************** |
5ddeb07c |
3 | * Copyright (C) 2003-2007 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 | |
22 | class AuthModule extends PLModule |
23 | { |
24 | function handlers() |
25 | { |
26 | return array( |
6c85148b |
27 | 'login' => $this->make_hook('login', AUTH_COOKIE), |
4c745880 |
28 | 'groupex/donne-chall.php' |
87221416 |
29 | => $this->make_hook('chall', AUTH_PUBLIC), |
30 | 'groupex/export-econfiance.php' |
31 | => $this->make_hook('econf', AUTH_PUBLIC), |
d5749a28 |
32 | |
87221416 |
33 | 'webservices/manageurs.php' |
34 | => $this->make_hook('manageurs', AUTH_PUBLIC), |
35 | |
36 | 'auth-redirect.php' => $this->make_hook('redirect', AUTH_COOKIE), |
37 | 'auth-groupex.php' => $this->make_hook('groupex', AUTH_COOKIE), |
92423144 |
38 | 'admin/auth-groupes-x' => $this->make_hook('admin_authgroupesx', AUTH_MDP, 'admin'), |
5d292fd8 |
39 | ); |
40 | } |
41 | |
6c85148b |
42 | function handler_login(&$page) |
43 | { |
44 | $allkeys = func_get_args(); |
45 | unset($allkeys[0]); |
46 | $url = join('/',$allkeys); |
47 | pl_redirect($url ? $url : 'events'); |
48 | } |
49 | |
c9178c75 |
50 | function handler_chall(&$page) |
d5749a28 |
51 | { |
52 | $_SESSION["chall"] = uniqid(rand(), 1); |
53 | echo $_SESSION["chall"] . "\n" . session_id(); |
54 | exit; |
55 | } |
56 | |
c9178c75 |
57 | function handler_econf(&$page) |
d5749a28 |
58 | { |
59 | global $globals; |
60 | |
d5749a28 |
61 | $cle = $globals->core->econfiance; |
62 | |
cab08090 |
63 | if (S::v('chall') && $_GET['PASS'] == md5(S::v('chall').$cle)) { |
d5749a28 |
64 | |
08cce2ff |
65 | $res = XDB::query("SELECT password FROM auth_user_md5 WHERE user_id=10154"); |
d5749a28 |
66 | $pass = $res->fetchOneCell(); |
67 | |
9bb8bf21 |
68 | $list = new MMList(10154, $pass, "x-econfiance.polytechnique.org"); |
69 | $members = $list->get_members('membres'); |
d5749a28 |
70 | if (is_array($members)) { |
71 | $membres = Array(); |
72 | foreach($members[1] as $member) { |
73 | if (preg_match('/^([^.]*.[^.]*.(\d\d\d\d))@polytechnique.org$/', |
74 | $member[1], $matches)) |
75 | { |
76 | $membres[] = "a.alias='{$matches[1]}'"; |
77 | } |
78 | } |
79 | } |
80 | |
81 | $where = join(' OR ',$membres); |
82 | |
08cce2ff |
83 | $all = XDB::iterRow( |
d5749a28 |
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' ) |
87 | WHERE $where |
88 | ORDER BY nom"); |
89 | |
90 | $res = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<membres>\n\n"; |
91 | |
92 | while (list ($prenom1,$nom1,$email1) = $all->next()) { |
93 | $res .= "<membre>\n"; |
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"; |
98 | } |
99 | |
100 | $res .= "</membres>\n\n"; |
101 | |
4e9a4346 |
102 | header('Content-Type: text/xml; charset="ISO-8859-1"'); |
d5749a28 |
103 | echo $res; |
104 | } |
105 | exit; |
106 | } |
107 | |
c9178c75 |
108 | function handler_manageurs(&$page) |
87221416 |
109 | { |
110 | global $globals; |
111 | |
112 | require_once 'webservices/manageurs.server.inc.php'; |
113 | |
34c8c3b5 |
114 | $ips = array_flip(explode(' ', $globals->manageurs->authorized_ips)); |
87221416 |
115 | if ($ips && isset($ips[$_SERVER['REMOTE_ADDR']])) { |
116 | $server = xmlrpc_server_create(); |
117 | |
118 | xmlrpc_server_register_method($server, 'get_annuaire_infos', 'get_annuaire_infos'); |
119 | xmlrpc_server_register_method($server, 'get_nouveau_infos', 'get_nouveau_infos'); |
120 | |
121 | $request = $GLOBALS['HTTP_RAW_POST_DATA']; |
122 | $response = xmlrpc_server_call_method($server, $request, null); |
123 | header('Content-Type: text/xml'); |
124 | print $response; |
125 | xmlrpc_server_destroy($server); |
126 | } |
34c8c3b5 |
127 | |
128 | exit; |
87221416 |
129 | } |
130 | |
5d292fd8 |
131 | function handler_redirect(&$page) |
132 | { |
5e2307dc |
133 | http_redirect(Env::v('dest', '/')); |
5d292fd8 |
134 | } |
135 | |
136 | function handler_groupex(&$page) |
137 | { |
352fb101 |
138 | require_once dirname(__FILE__).'/auth/auth.inc.php'; |
6c85148b |
139 | $page->assign('referer', true); |
5d292fd8 |
140 | |
141 | $gpex_pass = $_GET["pass"]; |
142 | $gpex_url = urldecode($_GET["url"]); |
143 | if (strpos($gpex_url, '?') === false) { |
144 | $gpex_url .= "?PHPSESSID=" . $_GET["session"]; |
145 | } else { |
146 | $gpex_url .= "&PHPSESSID=" . $_GET["session"]; |
147 | } |
148 | |
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"]; |
153 | |
089a5801 |
154 | // mise à jour de l'heure et de la machine de dernier login sauf quand on est en suid |
5d292fd8 |
155 | if (!isset($_SESSION['suid'])) { |
156 | $logger = (isset($_SESSION['log']) && $_SESSION['log']->uid == $uid) |
07e8e0ab |
157 | ? $_SESSION['log'] : new CoreLogger($uid); |
158 | global $platal; |
159 | $logger->log('connexion_auth_ext', $platal->path); |
5d292fd8 |
160 | } |
161 | |
162 | /* on parcourt les entrees de groupes_auth */ |
08cce2ff |
163 | $res = XDB::iterRow('select privkey,name,datafields from groupesx_auth'); |
5d292fd8 |
164 | |
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); |
8b00e0e0 |
168 | http_redirect($returl); |
5d292fd8 |
169 | } |
170 | } |
171 | |
089a5801 |
172 | /* si on n'a pas trouvé, on renvoit sur x.org */ |
8b00e0e0 |
173 | http_redirect('https://www.polytechnique.org/'); |
5d292fd8 |
174 | } |
92423144 |
175 | function handler_admin_authgroupesx(&$page, $action = 'list', $id = null) { |
92423144 |
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); |
183 | } |
5d292fd8 |
184 | } |
185 | |
186 | ?> |