5d292fd8 |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2006 Polytechnique.org * |
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( |
87221416 |
27 | 'groupex/done-chall.php' |
28 | => $this->make_hook('chall', AUTH_PUBLIC), |
29 | 'groupex/export-econfiance.php' |
30 | => $this->make_hook('econf', AUTH_PUBLIC), |
d5749a28 |
31 | |
87221416 |
32 | 'webservices/manageurs.php' |
33 | => $this->make_hook('manageurs', AUTH_PUBLIC), |
34 | |
35 | 'auth-redirect.php' => $this->make_hook('redirect', AUTH_COOKIE), |
36 | 'auth-groupex.php' => $this->make_hook('groupex', AUTH_COOKIE), |
5d292fd8 |
37 | ); |
38 | } |
39 | |
c9178c75 |
40 | function handler_chall(&$page) |
d5749a28 |
41 | { |
42 | $_SESSION["chall"] = uniqid(rand(), 1); |
43 | echo $_SESSION["chall"] . "\n" . session_id(); |
44 | exit; |
45 | } |
46 | |
c9178c75 |
47 | function handler_econf(&$page) |
d5749a28 |
48 | { |
49 | global $globals; |
50 | |
51 | require_once 'platal/xmlrpc-client.inc.php'; |
52 | require_once 'lists.inc.php'; |
53 | |
54 | $cle = $globals->core->econfiance; |
55 | |
56 | if (Session::get('chall') && $_GET['PASS'] == md5(Session::get('chall').$cle)) { |
57 | |
58 | $res = $globals->xdb->query("SELECT password FROM auth_user_md5 WHERE user_id=10154"); |
59 | $pass = $res->fetchOneCell(); |
60 | |
61 | $client =& lists_xmlrpc(10154, $pass, "x-econfiance.polytechnique.org"); |
62 | $members = $client->get_members('membres'); |
63 | if (is_array($members)) { |
64 | $membres = Array(); |
65 | foreach($members[1] as $member) { |
66 | if (preg_match('/^([^.]*.[^.]*.(\d\d\d\d))@polytechnique.org$/', |
67 | $member[1], $matches)) |
68 | { |
69 | $membres[] = "a.alias='{$matches[1]}'"; |
70 | } |
71 | } |
72 | } |
73 | |
74 | $where = join(' OR ',$membres); |
75 | |
76 | $all = $globals->xdb->iterRow( |
77 | "SELECT u.prenom,u.nom,a.alias |
78 | FROM auth_user_md5 AS u |
79 | INNER JOIN aliases AS a ON ( u.user_id = a.id AND a.type!='homonyme' ) |
80 | WHERE $where |
81 | ORDER BY nom"); |
82 | |
83 | $res = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<membres>\n\n"; |
84 | |
85 | while (list ($prenom1,$nom1,$email1) = $all->next()) { |
86 | $res .= "<membre>\n"; |
87 | $res .= "\t<nom>$nom1</nom>\n"; |
88 | $res .= "\t<prenom>$prenom1</prenom>\n"; |
89 | $res .= "\t<email>$email1</email>\n"; |
90 | $res .= "</membre>\n\n"; |
91 | } |
92 | |
93 | $res .= "</membres>\n\n"; |
94 | |
95 | echo $res; |
96 | } |
97 | exit; |
98 | } |
99 | |
c9178c75 |
100 | function handler_manageurs(&$page) |
87221416 |
101 | { |
102 | global $globals; |
103 | |
104 | require_once 'webservices/manageurs.server.inc.php'; |
105 | |
106 | $ips = array_flip(explode(' ',$globals->manageurs->authorized_ips)); |
107 | if ($ips && isset($ips[$_SERVER['REMOTE_ADDR']])) { |
108 | $server = xmlrpc_server_create(); |
109 | |
110 | xmlrpc_server_register_method($server, 'get_annuaire_infos', 'get_annuaire_infos'); |
111 | xmlrpc_server_register_method($server, 'get_nouveau_infos', 'get_nouveau_infos'); |
112 | |
113 | $request = $GLOBALS['HTTP_RAW_POST_DATA']; |
114 | $response = xmlrpc_server_call_method($server, $request, null); |
115 | header('Content-Type: text/xml'); |
116 | print $response; |
117 | xmlrpc_server_destroy($server); |
118 | } |
119 | } |
120 | |
5d292fd8 |
121 | function handler_redirect(&$page) |
122 | { |
123 | redirect(Env::get('dest', '/')); |
124 | } |
125 | |
126 | function handler_groupex(&$page) |
127 | { |
128 | global $globals; |
129 | |
352fb101 |
130 | require_once dirname(__FILE__).'/auth/auth.inc.php'; |
5d292fd8 |
131 | |
132 | $gpex_pass = $_GET["pass"]; |
133 | $gpex_url = urldecode($_GET["url"]); |
134 | if (strpos($gpex_url, '?') === false) { |
135 | $gpex_url .= "?PHPSESSID=" . $_GET["session"]; |
136 | } else { |
137 | $gpex_url .= "&PHPSESSID=" . $_GET["session"]; |
138 | } |
139 | |
140 | /* a-t-on besoin d'ajouter le http:// ? */ |
141 | if (!preg_match("/^(http|https):\/\/.*/",$gpex_url)) |
142 | $gpex_url = "http://$gpex_url"; |
143 | $gpex_challenge = $_GET["challenge"]; |
144 | |
145 | // mise à jour de l'heure et de la machine de dernier login sauf quand on est en suid |
146 | if (!isset($_SESSION['suid'])) { |
147 | $logger = (isset($_SESSION['log']) && $_SESSION['log']->uid == $uid) |
148 | ? $_SESSION['log'] |
149 | : new DiogenesCoreLogger($uid); |
150 | $logger->log('connexion_auth_ext', $_SERVER['PHP_SELF']); |
151 | } |
152 | |
153 | /* on parcourt les entrees de groupes_auth */ |
154 | $res = $globals->xdb->iterRow('select privkey,name,datafields from groupesx_auth'); |
155 | |
156 | while (list($privkey,$name,$datafields) = $res->next()) { |
157 | if (md5($gpex_challenge.$privkey) == $gpex_pass) { |
158 | $returl = $gpex_url.gpex_make_params($gpex_challenge,$privkey,$datafields); |
159 | redirect($returl); |
160 | } |
161 | } |
162 | |
163 | /* si on n'a pas trouvé, on renvoit sur x.org */ |
164 | redirect('https://www.polytechnique.org/'); |
165 | } |
166 | } |
167 | |
168 | ?> |