2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 function bugize($list)
24 $list = split(',', $list);
27 foreach ($list as $bug) {
28 $clean = str_replace('#', '', $bug);
29 $ans[] = "<a href='http://trackers.polytechnique.org/task/$clean'>$bug</a>";
32 return join(',', $ans);
36 class PlatalModule
extends PLModule
41 'index' => $this->make_hook('index', AUTH_PUBLIC
),
42 'cacert.pem' => $this->make_hook('cacert', AUTH_PUBLIC
),
43 'changelog' => $this->make_hook('changelog', AUTH_PUBLIC
),
45 // Preferences thingies
46 'prefs' => $this->make_hook('prefs', AUTH_COOKIE
),
47 'prefs/rss' => $this->make_hook('prefs_rss', AUTH_COOKIE
),
49 => $this->make_hook('webredir', AUTH_MDP
),
50 'prefs/skin' => $this->make_hook('skin', AUTH_COOKIE
),
52 // password related thingies
53 'password' => $this->make_hook('password', AUTH_MDP
),
54 'tmpPWD' => $this->make_hook('tmpPWD', AUTH_PUBLIC
),
55 'password/smtp' => $this->make_hook('smtppass', AUTH_MDP
),
56 'recovery' => $this->make_hook('recovery', AUTH_PUBLIC
),
57 'exit' => $this->make_hook('exit', AUTH_PUBLIC
),
59 // happenings related thingies
60 'rss' => $this->make_hook('rss', AUTH_PUBLIC
),
64 function handler_index(&$page)
67 pl_redirect('events');
71 function handler_cacert(&$page)
73 $data = file_get_contents('/etc/ssl/xorgCA/cacert.pem');
74 header('Content-Type: application/x-x509-ca-cert');
75 header('Content-Length: '.strlen($data));
80 function handler_changelog(&$page)
82 $page->changeTpl('changeLog.tpl');
84 $clog = htmlentities(file_get_contents(dirname(__FILE__
).'/../ChangeLog'));
85 $clog = preg_replace('!(#[0-9]+(,[0-9]+)*)!e', 'bugize("\1")', $clog);
86 $clog = preg_replace('!vim:.*$!', '', $clog);
87 $page->assign('ChangeLog', $clog);
90 function __set_rss_state($state)
93 $_SESSION['core_rss_hash'] = rand_url_id(16);
94 XDB
::execute('UPDATE auth_user_quick
95 SET core_rss_hash={?} WHERE user_id={?}',
96 S
::v('core_rss_hash'), S
::v('uid'));
98 XDB
::execute('UPDATE auth_user_quick
99 SET core_rss_hash="" WHERE user_id={?}',
101 S
::kill('core_rss_hash');
105 function handler_prefs(&$page)
107 $page->changeTpl('preferences.tpl');
108 $page->assign('xorg_title','Polytechnique.org - Mes préférences');
110 if (Post
::has('mail_fmt')) {
111 $fmt = Post
::v('mail_fmt');
112 if ($fmt != 'texte') $fmt = 'html';
113 XDB
::execute("UPDATE auth_user_quick
114 SET core_mail_fmt = '$fmt'
115 WHERE user_id = {?}",
117 $_SESSION['mail_fmt'] = $fmt;
120 if (Post
::has('rss')) {
121 $this->__set_rss_state(Post
::b('rss'));
125 function handler_webredir(&$page)
127 $page->changeTpl('webredirect.tpl');
129 $page->assign('xorg_title','Polytechnique.org - Redirection de page WEB');
132 $url = Env
::v('url');
134 if (Env
::v('submit') == 'Valider' and Env
::has('url')) {
135 XDB
::execute('UPDATE auth_user_quick
136 SET redirecturl = {?} WHERE user_id = {?}',
138 $log->log('carva_add', 'http://'.Env
::v('url'));
139 $page->trig("Redirection activée vers <a href='http://$url'>$url</a>");
140 } elseif (Env
::v('submit') == "Supprimer") {
141 XDB
::execute("UPDATE auth_user_quick
143 WHERE user_id = {?}",
145 $log->log("carva_del", $url);
147 $page->trig('Redirection supprimée');
150 $res = XDB
::query('SELECT redirecturl
152 WHERE user_id = {?}',
154 $page->assign('carva', $res->fetchOneCell());
157 function handler_prefs_rss(&$page)
159 $page->changeTpl('filrss.tpl');
161 $page->assign('goback', Env
::v('referer', 'login'));
163 if (Env
::v('act_rss') == 'Activer') {
164 $this->__set_rss_state(true
);
165 $page->trig("Ton Fil RSS est activé.");
169 function handler_password(&$page)
171 if (Post
::has('response2')) {
172 require_once 'secure_hash.inc.php';
174 $_SESSION['password'] = $password = Post
::v('response2');
176 XDB
::execute('UPDATE auth_user_md5
178 WHERE user_id={?}', $password,
182 $log->log('passwd', '');
184 if (Cookie
::v('ORGaccess')) {
185 setcookie('ORGaccess', hash_encrypt($password), (time()+
25920000), '/', '' ,0);
188 $page->changeTpl('motdepasse.success.tpl');
192 $page->changeTpl('motdepasse.tpl');
193 $page->addJsLink('javascript/motdepasse.js');
194 $page->assign('xorg_title','Polytechnique.org - Mon mot de passe');
197 function handler_smtppass(&$page)
199 $page->changeTpl('acces_smtp.tpl');
200 $page->assign('xorg_title','Polytechnique.org - Acces SMTP/NNTP');
203 $pass = Env
::v('smtppass1');
206 if (Env
::v('op') == "Valider" && strlen($pass) >= 6
207 && Env
::v('smtppass1') == Env
::v('smtppass2'))
209 XDB
::execute('UPDATE auth_user_md5 SET smtppass = {?}
210 WHERE user_id = {?}', $pass, $uid);
211 $page->trig('Mot de passe enregistré');
212 $log->log("passwd_ssl");
213 } elseif (Env
::v('op') == "Supprimer") {
214 XDB
::execute('UPDATE auth_user_md5 SET smtppass = ""
215 WHERE user_id = {?}', $uid);
216 $page->trig('Compte SMTP et NNTP supprimé');
217 $log->log("passwd_del");
220 $res = XDB
::query("SELECT IF(smtppass != '', 'actif', '')
222 WHERE user_id = {?}", $uid);
223 $page->assign('actif', $res->fetchOneCell());
226 function handler_recovery(&$page)
230 $page->changeTpl('recovery.tpl');
232 if (!Env
::has('login') ||
!Env
::has('birth')) {
236 if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env
::v('birth'))) {
237 $page->trig('Date de naissance incorrecte ou incohérente');
241 $birth = sprintf('%s-%s-%s',
242 substr(Env
::v('birth'), 4, 4),
243 substr(Env
::v('birth'), 2, 2),
244 substr(Env
::v('birth'), 0, 2));
246 $mailorg = strtok(Env
::v('login'), '@');
248 // paragraphe rajouté : si la date de naissance dans la base n'existe pas, on l'update
249 // avec celle fournie ici en espérant que c'est la bonne
252 "SELECT user_id, naissance
253 FROM auth_user_md5 AS u
254 INNER JOIN aliases AS a ON (u.user_id=a.id AND type!='homonyme')
255 WHERE a.alias={?} AND u.perms IN ('admin','user') AND u.deces=0", $mailorg);
256 list($uid, $naissance) = $res->fetchOneRow();
258 if ($naissance == $birth) {
259 $page->assign('ok', true
);
261 $url = rand_url_id();
262 XDB
::execute('INSERT INTO perte_pass (certificat,uid,created) VALUES ({?},{?},NOW())', $url, $uid);
263 $res = XDB
::query('SELECT email FROM emails WHERE uid = {?} AND NOT FIND_IN_SET("filter", flags)', $uid);
264 $mails = implode(', ', $res->fetchColumn());
266 require_once "diogenes/diogenes.hermes.inc.php";
267 $mymail = new HermesMailer();
268 $mymail->setFrom('"Gestion des mots de passe" <support+password@polytechnique.org>');
269 $mymail->addTo($mails);
270 $mymail->setSubject('Ton certificat d\'authentification');
271 $mymail->setTxtBody("Visite la page suivante qui expire dans six heures :
272 {$globals->baseurl}/tmpPWD/$url
274 Si en cliquant dessus tu n'y arrives pas, copie intégralement l'adresse dans la barre de ton navigateur.
278 \"Le portail des élèves & anciens élèves de l'Ecole polytechnique\"".(Post
::v('email') ?
"
281 ".Post
::v('email') : "")."
283 Mail envoyé à ".Env
::v('login'));
286 // on cree un objet logger et on log l'evenement
287 $logger = $_SESSION['log'] = new DiogenesCoreLogger($uid);
288 $logger->log('recovery', $emails);
290 $page->trig('Pas de résultat correspondant aux champs entrés dans notre base de données.');
294 function handler_tmpPWD(&$page, $certif = null
)
296 XDB
::execute('DELETE FROM perte_pass
297 WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created');
299 $res = XDB
::query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif);
300 $ligne = $res->fetchOneAssoc();
302 $page->changeTpl('index.tpl');
303 $page->kill("Cette adresse n'existe pas ou n'existe plus sur le serveur.");
306 $uid = $ligne["uid"];
307 if (Post
::has('response2')) {
308 $password = Post
::v('response2');
309 $logger = new DiogenesCoreLogger($uid);
310 XDB
::query('UPDATE auth_user_md5 SET password={?}
311 WHERE user_id={?} AND perms IN("admin","user")',
313 XDB
::query('DELETE FROM perte_pass WHERE certificat={?}', $certif);
314 $logger->log("passwd","");
315 $page->changeTpl('tmpPWD.success.tpl');
317 $page->changeTpl('motdepasse.tpl');
318 $page->addJsLink('javascript/motdepasse.js');
322 function handler_skin(&$page)
326 $page->changeTpl('skins.tpl');
327 $page->assign('xorg_title','Polytechnique.org - Skins');
329 if (Env
::has('newskin')) { // formulaire soumis, traitons les données envoyées
330 XDB
::execute('UPDATE auth_user_quick
331 SET skin={?} WHERE user_id={?}',
332 Env
::i('newskin'), S
::v('uid'));
337 $res = XDB
::query('SELECT id FROM skins WHERE skin_tpl={?}', S
::v('skin'));
338 $page->assign('skin_id', $res->fetchOneCell());
340 $sql = "SELECT s.*,auteur,count(*) AS nb
342 LEFT JOIN auth_user_quick AS a ON s.id=a.skin
343 WHERE skin_tpl != '' AND ext != ''
344 GROUP BY id ORDER BY s.date DESC";
345 $page->assign_by_ref('skins', XDB
::iterator($sql));
348 function handler_exit(&$page, $level = null
)
350 if (S
::has('suid')) {
351 if (S
::has('suid')) {
352 $a4l = S
::v('forlife');
353 $suid = S
::v('suid');
355 $log->log("suid_stop", S
::v('forlife') . " by " . $suid['forlife']);
358 pl_redirect('admin/utilisateurs.php', 'login='.$a4l);
360 pl_redirect('events');
364 if ($level == 'forget' ||
$level == 'forgetall') {
365 setcookie('ORGaccess', '', time() - 3600, '/', '', 0);
366 Cookie
::kill('ORGaccess');
367 if (isset($_SESSION['log']))
368 $_SESSION['log']->log("cookie_off");
371 if ($level == 'forgetuid' ||
$level == 'forgetall') {
372 setcookie('ORGuid', '', time() - 3600, '/', '', 0);
373 Cookie
::kill('ORGuid');
374 setcookie('ORGdomain', '', time() - 3600, '/', '', 0);
375 Cookie
::kill('ORGdomain');
378 if (isset($_SESSION['log'])) {
379 $ref = isset($_SERVER['HTTP_REFERER']) ?
$_SERVER['HTTP_REFERER'] : '';
380 $_SESSION['log']->log('deconnexion',$ref);
383 XorgSession
::destroy();
385 if (Get
::has('redirect')) {
386 http_redirect(rawurldecode(Get
::v('redirect')));
388 $page->changeTpl('exit.tpl');
392 function handler_rss(&$page, $user = null
, $hash = null
)
394 require_once 'rss.inc.php';
396 $uid = init_rss('rss.tpl', $user, $hash);
398 $rss = XDB
::iterator(
399 'SELECT e.id, e.titre, e.texte, e.creation_date
400 FROM auth_user_md5 AS u
401 INNER JOIN evenements AS e ON ( (e.promo_min = 0 || e.promo_min <= u.promo)
402 AND (e.promo_max = 0 || e.promo_max >= u.promo) )
403 WHERE u.user_id = {?} AND FIND_IN_SET(e.flags, "valide")
404 AND peremption >= NOW()', $uid);
405 $page->assign('rss', $rss);