e59506eb |
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 PlatalModule extends PLModule |
23 | { |
24 | function handlers() |
25 | { |
26 | return array( |
4da0b8d7 |
27 | // Preferences thingies |
1a5da857 |
28 | 'prefs' => $this->make_hook('prefs', AUTH_COOKIE), |
29 | 'prefs/rss' => $this->make_hook('prefs_rss', AUTH_COOKIE), |
bce2f8eb |
30 | 'prefs/webredirect' |
31 | => $this->make_hook('webredir', AUTH_MDP), |
1a5da857 |
32 | 'skin' => $this->make_hook('skin', AUTH_COOKIE), |
4da0b8d7 |
33 | |
34 | // password related thingies |
1a5da857 |
35 | 'password' => $this->make_hook('password', AUTH_MDP), |
36 | 'tmpPWD' => $this->make_hook('tmpPWD', AUTH_PUBLIC), |
37 | 'password/smtp' => $this->make_hook('smtppass', AUTH_MDP), |
8858cfc1 |
38 | 'recovery' => $this->make_hook('recovery', AUTH_PUBLIC), |
4da0b8d7 |
39 | |
40 | // happenings related thingies |
41 | 'rss' => $this->make_hook('rss', AUTH_PUBLIC), |
e59506eb |
42 | ); |
43 | } |
44 | |
7927d719 |
45 | function __set_rss_state($state) |
46 | { |
47 | global $globals; |
48 | |
49 | if ($state) { |
50 | $_SESSION['core_rss_hash'] = rand_url_id(16); |
51 | $globals->xdb->execute('UPDATE auth_user_quick |
52 | SET core_rss_hash={?} WHERE user_id={?}', |
53 | Session::get('core_rss_hash'), |
54 | Session::getInt('uid')); |
55 | } else { |
56 | $globals->xdb->execute('UPDATE auth_user_quick |
57 | SET core_rss_hash="" WHERE user_id={?}', |
58 | Session::getInt('uid')); |
59 | Session::kill('core_rss_hash'); |
60 | } |
61 | } |
62 | |
e59506eb |
63 | function handler_prefs(&$page) |
64 | { |
65 | global $globals; |
66 | |
67 | $page->changeTpl('preferences.tpl'); |
68 | $page->assign('xorg_title','Polytechnique.org - Mes préférences'); |
69 | |
70 | if (Env::has('mail_fmt')) { |
71 | $fmt = Env::get('mail_fmt'); |
72 | if ($fmt != 'texte') $fmt = 'html'; |
73 | $globals->xdb->execute("UPDATE auth_user_quick |
74 | SET core_mail_fmt = '$fmt' |
75 | WHERE user_id = {?}", |
76 | Session::getInt('uid')); |
77 | $_SESSION['mail_fmt'] = $fmt; |
20d90835 |
78 | redirect($globals->baseurl.'/preferences'); |
e59506eb |
79 | } |
80 | |
81 | if (Env::has('rss')) { |
7927d719 |
82 | $this->__set_rss_state(Env::getBool('rss')); |
e59506eb |
83 | } |
84 | |
85 | $page->assign('prefs', $globals->hook->prefs()); |
a2558f2b |
86 | |
87 | return PL_OK; |
e59506eb |
88 | } |
9bae6004 |
89 | |
bce2f8eb |
90 | function handler_webredir(&$page) |
91 | { |
92 | global $globals; |
93 | |
94 | $page->changeTpl('webredirect.tpl'); |
95 | |
96 | $page->assign('xorg_title','Polytechnique.org - Redirection de page WEB'); |
97 | |
98 | $log =& Session::getMixed('log'); |
99 | $url = Env::get('url'); |
100 | |
101 | if (Env::get('submit') == 'Valider' and Env::has('url')) { |
102 | $globals->xdb->execute('UPDATE auth_user_quick |
103 | SET redirecturl = {?} WHERE user_id = {?}', |
bf2692e3 |
104 | $url, Session::getInt('uid')); |
bce2f8eb |
105 | $log->log('carva_add', 'http://'.Env::get('url')); |
106 | $page->trig("Redirection activée vers <a href='http://$url'>$url</a>"); |
107 | } elseif (Env::get('submit') == "Supprimer") { |
108 | $globals->xdb->execute("UPDATE auth_user_quick |
109 | SET redirecturl = '' |
110 | WHERE user_id = {?}", |
bf2692e3 |
111 | Session::getInt('uid')); |
bce2f8eb |
112 | $log->log("carva_del", $url); |
113 | Post::kill('url'); |
114 | $page->trig('Redirection supprimée'); |
115 | } |
116 | |
117 | $res = $globals->xdb->query('SELECT redirecturl |
118 | FROM auth_user_quick |
119 | WHERE user_id = {?}', |
120 | Session::getInt('uid')); |
121 | $page->assign('carva', $res->fetchOneCell()); |
122 | |
123 | return PL_OK; |
124 | } |
125 | |
4da0b8d7 |
126 | function handler_prefs_rss(&$page) |
7927d719 |
127 | { |
128 | global $globals; |
129 | |
130 | $page->changeTpl('filrss.tpl'); |
131 | |
132 | $page->assign('goback', Env::get('referer', 'login')); |
133 | |
134 | if (Env::get('act_rss') == 'Activer') { |
135 | $this->__set_rss_state(true); |
136 | $page->trig("Ton Fil RSS est activé."); |
137 | } |
138 | |
139 | return PL_OK; |
140 | } |
141 | |
7c77c3ee |
142 | function handler_password(&$page) |
143 | { |
144 | global $globals; |
145 | |
146 | if (Post::has('response2')) { |
147 | require_once 'secure_hash.inc.php'; |
148 | |
149 | $_SESSION['password'] = $password = Post::get('response2'); |
150 | |
151 | $globals->xdb->execute('UPDATE auth_user_md5 |
152 | SET password={?} |
153 | WHERE user_id={?}', $password, |
154 | Session::getInt('uid')); |
155 | |
156 | $log =& Session::getMixed('log'); |
157 | $log->log('passwd', ''); |
158 | |
159 | if (Cookie::get('ORGaccess')) { |
160 | setcookie('ORGaccess', hash_encrypt($password), (time()+25920000), '/', '' ,0); |
161 | } |
162 | |
163 | $page->changeTpl('motdepasse.success.tpl'); |
164 | $page->run(); |
165 | } |
166 | |
167 | $page->changeTpl('motdepasse.tpl'); |
168 | $page->addJsLink('javascript/motdepasse.js'); |
169 | $page->assign('xorg_title','Polytechnique.org - Mon mot de passe'); |
170 | |
171 | return PL_OK; |
172 | } |
173 | |
1a5da857 |
174 | function handler_smtppass(&$page) |
175 | { |
176 | global $globals; |
177 | |
178 | $page->changeTpl('acces_smtp.tpl'); |
179 | $page->assign('xorg_title','Polytechnique.org - Acces SMTP/NNTP'); |
180 | |
181 | $uid = Session::getInt('uid'); |
182 | $pass = Env::get('smtppass1'); |
183 | $log = Session::getMixed('log'); |
184 | |
185 | if (Env::get('op') == "Valider" && strlen($pass) >= 6 |
186 | && Env::get('smtppass1') == Env::get('smtppass2')) |
187 | { |
188 | $globals->xdb->execute('UPDATE auth_user_md5 SET smtppass = {?} |
189 | WHERE user_id = {?}', $pass, $uid); |
190 | $page->trig('Mot de passe enregistré'); |
191 | $log->log("passwd_ssl"); |
192 | } elseif (Env::get('op') == "Supprimer") { |
193 | $globals->xdb->execute('UPDATE auth_user_md5 SET smtppass = "" |
194 | WHERE user_id = {?}', $uid); |
195 | $page->trig('Compte SMTP et NNTP supprimé'); |
196 | $log->log("passwd_del"); |
197 | } |
198 | |
199 | $res = $globals->xdb->query("SELECT IF(smtppass != '', 'actif', '') |
200 | FROM auth_user_md5 |
201 | WHERE user_id = {?}", $uid); |
202 | $page->assign('actif', $res->fetchOneCell()); |
203 | |
204 | return PL_OK; |
205 | } |
206 | |
8858cfc1 |
207 | function handler_recovery(&$page) |
208 | { |
209 | global $globals; |
210 | |
211 | $page->changeTpl('recovery.tpl'); |
212 | |
213 | if (!Env::has('login') || !Env::has('birth')) { |
214 | return PL_OK; |
215 | } |
216 | |
217 | if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env::get('birth'))) { |
218 | $page->trig_run('Date de naissance incorrecte ou incohérente'); |
219 | } |
220 | $birth = sprintf('%s-%s-%s', substr(Env::get('birth'),4,4), substr(Env::get('birth'),2,2), substr(Env::get('birth'),0,2)); |
221 | |
222 | $mailorg = strtok(Env::get('login'), '@'); |
223 | |
224 | // paragraphe rajouté : si la date de naissance dans la base n'existe pas, on l'update |
225 | // avec celle fournie ici en espérant que c'est la bonne |
226 | |
227 | $res = $globals->xdb->query( |
228 | "SELECT user_id, naissance |
229 | FROM auth_user_md5 AS u |
230 | INNER JOIN aliases AS a ON (u.user_id=a.id AND type!='homonyme') |
231 | WHERE a.alias={?} AND u.perms IN ('admin','user') AND u.deces=0", $mailorg); |
232 | list($uid, $naissance) = $res->fetchOneRow(); |
233 | |
234 | if ($naissance == $birth) { |
235 | $page->assign('ok', true); |
236 | |
237 | $url = rand_url_id(); |
238 | $globals->xdb->execute('INSERT INTO perte_pass (certificat,uid,created) VALUES ({?},{?},NOW())', $url, $uid); |
239 | $res = $globals->xdb->query('SELECT email FROM emails WHERE uid = {?} AND NOT FIND_IN_SET("filter", flags)', $uid); |
240 | $mails = implode(', ', $res->fetchColumn()); |
241 | |
242 | require_once "diogenes/diogenes.hermes.inc.php"; |
243 | $mymail = new HermesMailer(); |
244 | $mymail->setFrom('"Gestion des mots de passe" <support+password@polytechnique.org>'); |
245 | $mymail->addTo($mails); |
246 | $mymail->setSubject('Ton certificat d\'authentification'); |
247 | $mymail->setTxtBody("Visite la page suivante qui expire dans six heures : |
248 | {$globals->baseurl}/tmpPWD/$url |
249 | |
250 | Si en cliquant dessus tu n'y arrives pas, copie intégralement l'adresse dans la barre de ton navigateur. |
251 | |
252 | -- |
253 | Polytechnique.org |
254 | \"Le portail des élèves & anciens élèves de l'Ecole polytechnique\"".(Post::get('email') ? " |
255 | |
256 | Adresse de secours : |
257 | ".Post::get('email') : "")." |
258 | |
259 | Mail envoyé à ".Env::get('login')); |
260 | $mymail->send(); |
261 | |
262 | // on cree un objet logger et on log l'evenement |
263 | $logger = $_SESSION['log'] = new DiogenesCoreLogger($uid); |
264 | $logger->log('recovery', $emails); |
265 | } else { |
266 | $page->trig('Pas de résultat correspondant aux champs entrés dans notre base de données.'); |
267 | } |
268 | |
269 | return PL_OK; |
270 | } |
271 | |
6c49d0af |
272 | function handler_tmpPWD(&$page, $certif = null) |
273 | { |
274 | global $globals; |
275 | |
276 | $globals->xdb->execute('DELETE FROM perte_pass |
277 | WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created'); |
278 | |
279 | $res = $globals->xdb->query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif); |
280 | $ligne = $res->fetchOneAssoc(); |
281 | if (!$ligne) { |
282 | $page->changeTpl('index.tpl'); |
283 | $page->kill("Cette adresse n'existe pas ou n'existe plus sur le serveur."); |
284 | } |
285 | |
286 | $uid = $ligne["uid"]; |
287 | if (Post::has('response2')) { |
288 | $password = Post::get('response2'); |
289 | $logger = new DiogenesCoreLogger($uid); |
290 | $globals->xdb->query('UPDATE auth_user_md5 SET password={?} |
291 | WHERE user_id={?} AND perms IN("admin","user")', |
292 | $password, $uid); |
293 | $globals->xdb->query('DELETE FROM perte_pass WHERE certificat={?}', $certif); |
294 | $logger->log("passwd",""); |
295 | $page->changeTpl('tmpPWD.success.tpl'); |
296 | } else { |
297 | $page->changeTpl('motdepasse.tpl'); |
298 | $page->addJsLink('javascript/motdepasse.js'); |
299 | } |
300 | |
301 | return PL_OK; |
302 | } |
303 | |
9bae6004 |
304 | function handler_skin(&$page) |
305 | { |
306 | global $globals; |
307 | |
308 | if (!$globals->skin->enable) { |
f09cee18 |
309 | redirect('./'); |
9bae6004 |
310 | } |
f09cee18 |
311 | |
312 | $page->changeTpl('skins.tpl'); |
9bae6004 |
313 | $page->assign('xorg_title','Polytechnique.org - Skins'); |
314 | |
315 | if (Env::has('newskin')) { // formulaire soumis, traitons les données envoyées |
316 | $globals->xdb->execute('UPDATE auth_user_quick |
317 | SET skin={?} WHERE user_id={?}', |
318 | Env::getInt('newskin'), |
319 | Session::getInt('uid')); |
320 | set_skin(); |
321 | } |
322 | |
323 | $sql = "SELECT s.*,auteur,count(*) AS nb |
324 | FROM skins AS s |
325 | LEFT JOIN auth_user_quick AS a ON s.id=a.skin |
326 | WHERE skin_tpl != '' AND ext != '' |
327 | GROUP BY id ORDER BY s.date DESC"; |
328 | $page->assign_by_ref('skins', $globals->xdb->iterator($sql)); |
329 | return PL_OK; |
330 | } |
4da0b8d7 |
331 | |
332 | function handler_rss(&$page, $user = null, $hash = null) |
333 | { |
334 | global $globals; |
335 | |
336 | require_once 'rss.inc.php'; |
337 | |
338 | $uid = init_rss('rss.tpl', $user, $hash); |
339 | |
340 | $rss = $globals->xdb->iterator( |
341 | 'SELECT e.id, e.titre, e.texte, e.creation_date |
342 | FROM auth_user_md5 AS u |
343 | INNER JOIN evenements AS e ON ( (e.promo_min = 0 || e.promo_min <= u.promo) |
344 | AND (e.promo_max = 0 || e.promo_max >= u.promo) ) |
345 | WHERE u.user_id = {?} AND FIND_IN_SET(e.flags, "valide") |
346 | AND peremption >= NOW()', $uid); |
347 | $page->assign('rss', $rss); |
348 | |
349 | return PL_OK; |
350 | } |
e59506eb |
351 | } |
352 | |
353 | ?> |