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
),
58 'deconnexion.php' => $this->make_hook('exit', AUTH_PUBLIC
),
60 // happenings related thingies
61 'rss' => $this->make_hook('rss', AUTH_PUBLIC
),
65 function handler_index(&$page)
68 pl_redirect('events');
72 function handler_cacert(&$page)
74 $data = file_get_contents("/etc/ssl/xorgCA/cacert.pem","r");
76 header("Set-Cookie:");
77 header("Cache-Control:");
79 header("Content-Type: application/x-x509-ca-cert");
80 header("Content-Length: ".strlen($data));
85 function handler_changelog(&$page)
87 $page->changeTpl('changeLog.tpl');
89 $clog = htmlentities(file_get_contents(dirname(__FILE__
).'/../ChangeLog'));
90 $clog = preg_replace('!(#[0-9]+(,[0-9]+)*)!e', 'bugize("\1")', $clog);
91 $clog = preg_replace('!vim:.*$!', '', $clog);
92 $page->assign('ChangeLog', $clog);
95 function __set_rss_state($state)
98 $_SESSION['core_rss_hash'] = rand_url_id(16);
99 XDB
::execute('UPDATE auth_user_quick
100 SET core_rss_hash={?} WHERE user_id={?}',
101 S
::v('core_rss_hash'), S
::v('uid'));
103 XDB
::execute('UPDATE auth_user_quick
104 SET core_rss_hash="" WHERE user_id={?}',
106 S
::kill('core_rss_hash');
110 function handler_prefs(&$page)
112 $page->changeTpl('preferences.tpl');
113 $page->assign('xorg_title','Polytechnique.org - Mes préférences');
115 if (Post
::has('mail_fmt')) {
116 $fmt = Post
::v('mail_fmt');
117 if ($fmt != 'texte') $fmt = 'html';
118 XDB
::execute("UPDATE auth_user_quick
119 SET core_mail_fmt = '$fmt'
120 WHERE user_id = {?}",
122 $_SESSION['mail_fmt'] = $fmt;
125 if (Post
::has('rss')) {
126 $this->__set_rss_state(Post
::b('rss'));
130 function handler_webredir(&$page)
132 $page->changeTpl('webredirect.tpl');
134 $page->assign('xorg_title','Polytechnique.org - Redirection de page WEB');
137 $url = Env
::v('url');
139 if (Env
::v('submit') == 'Valider' and Env
::has('url')) {
140 XDB
::execute('UPDATE auth_user_quick
141 SET redirecturl = {?} WHERE user_id = {?}',
143 $log->log('carva_add', 'http://'.Env
::v('url'));
144 $page->trig("Redirection activée vers <a href='http://$url'>$url</a>");
145 } elseif (Env
::v('submit') == "Supprimer") {
146 XDB
::execute("UPDATE auth_user_quick
148 WHERE user_id = {?}",
150 $log->log("carva_del", $url);
152 $page->trig('Redirection supprimée');
155 $res = XDB
::query('SELECT redirecturl
157 WHERE user_id = {?}',
159 $page->assign('carva', $res->fetchOneCell());
162 function handler_prefs_rss(&$page)
164 $page->changeTpl('filrss.tpl');
166 $page->assign('goback', Env
::v('referer', 'login'));
168 if (Env
::v('act_rss') == 'Activer') {
169 $this->__set_rss_state(true
);
170 $page->trig("Ton Fil RSS est activé.");
174 function handler_password(&$page)
176 if (Post
::has('response2')) {
177 require_once 'secure_hash.inc.php';
179 $_SESSION['password'] = $password = Post
::v('response2');
181 XDB
::execute('UPDATE auth_user_md5
183 WHERE user_id={?}', $password,
187 $log->log('passwd', '');
189 if (Cookie
::v('ORGaccess')) {
190 setcookie('ORGaccess', hash_encrypt($password), (time()+
25920000), '/', '' ,0);
193 $page->changeTpl('motdepasse.success.tpl');
194 $page->assign('now', strftime("%Y%m%d%H%M%S"));
198 $page->changeTpl('motdepasse.tpl');
199 $page->addJsLink('motdepasse.js');
200 $page->assign('xorg_title','Polytechnique.org - Mon mot de passe');
203 function handler_smtppass(&$page)
205 $page->changeTpl('acces_smtp.tpl');
206 $page->assign('xorg_title','Polytechnique.org - Acces SMTP/NNTP');
209 $pass = Env
::v('smtppass1');
212 if (Env
::v('op') == "Valider" && strlen($pass) >= 6
213 && Env
::v('smtppass1') == Env
::v('smtppass2'))
215 XDB
::execute('UPDATE auth_user_md5 SET smtppass = {?}
216 WHERE user_id = {?}', $pass, $uid);
217 $page->trig('Mot de passe enregistré');
218 $log->log("passwd_ssl");
219 } elseif (Env
::v('op') == "Supprimer") {
220 XDB
::execute('UPDATE auth_user_md5 SET smtppass = ""
221 WHERE user_id = {?}', $uid);
222 $page->trig('Compte SMTP et NNTP supprimé');
223 $log->log("passwd_del");
226 $res = XDB
::query("SELECT IF(smtppass != '', 'actif', '')
228 WHERE user_id = {?}", $uid);
229 $page->assign('actif', $res->fetchOneCell());
232 function handler_recovery(&$page)
236 $page->changeTpl('recovery.tpl');
238 if (!Env
::has('login') ||
!Env
::has('birth')) {
242 if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env
::v('birth'))) {
243 $page->trig('Date de naissance incorrecte ou incohérente');
247 $birth = sprintf('%s-%s-%s',
248 substr(Env
::v('birth'), 4, 4),
249 substr(Env
::v('birth'), 2, 2),
250 substr(Env
::v('birth'), 0, 2));
252 $mailorg = strtok(Env
::v('login'), '@');
254 // paragraphe rajouté : si la date de naissance dans la base n'existe pas, on l'update
255 // avec celle fournie ici en espérant que c'est la bonne
258 "SELECT user_id, naissance
259 FROM auth_user_md5 AS u
260 INNER JOIN aliases AS a ON (u.user_id=a.id AND type != 'homonyme')
261 WHERE a.alias={?} AND u.perms IN ('admin','user') AND u.deces=0", $mailorg);
262 list($uid, $naissance) = $res->fetchOneRow();
264 if ($naissance == $birth) {
265 $page->assign('ok', true
);
267 $url = rand_url_id();
268 XDB
::execute('INSERT INTO perte_pass (certificat,uid,created) VALUES ({?},{?},NOW())', $url, $uid);
269 $res = XDB
::query('SELECT email FROM emails WHERE uid = {?} AND NOT FIND_IN_SET("filter", flags)', $uid);
270 $mails = implode(', ', $res->fetchColumn());
272 require_once "diogenes/diogenes.hermes.inc.php";
273 $mymail = new HermesMailer();
274 $mymail->setFrom('"Gestion des mots de passe" <support+password@polytechnique.org>');
275 $mymail->addTo($mails);
276 $mymail->setSubject('Ton certificat d\'authentification');
277 $mymail->setTxtBody("Visite la page suivante qui expire dans six heures :
278 {$globals->baseurl}/tmpPWD/$url
280 Si en cliquant dessus tu n'y arrives pas, copie intégralement l'adresse dans la barre de ton navigateur.
284 \"Le portail des élèves & anciens élèves de l'Ecole polytechnique\"".(Post
::v('email') ?
"
287 ".Post
::v('email') : "")."
289 Mail envoyé à ".Env
::v('login'));
292 // on cree un objet logger et on log l'evenement
293 $logger = $_SESSION['log'] = new CoreLogger($uid);
294 $logger->log('recovery', $emails);
296 $page->trig('Les informations que tu as rentrées ne permettent pas de récupérer ton mot de passe.<br />'.
297 'Si tu as un homonyme, utilise prenom.nom.promo comme login');
301 function handler_tmpPWD(&$page, $certif = null
)
303 XDB
::execute('DELETE FROM perte_pass
304 WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created');
306 $res = XDB
::query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif);
307 $ligne = $res->fetchOneAssoc();
309 $page->changeTpl('index.tpl');
310 $page->kill("Cette adresse n'existe pas ou n'existe plus sur le serveur.");
313 $uid = $ligne["uid"];
314 if (Post
::has('response2')) {
315 $password = Post
::v('response2');
316 $logger = new CoreLogger($uid);
317 XDB
::query('UPDATE auth_user_md5 SET password={?}
318 WHERE user_id={?} AND perms IN("admin","user")',
320 XDB
::query('DELETE FROM perte_pass WHERE certificat={?}', $certif);
321 $logger->log("passwd","");
322 $page->changeTpl('tmpPWD.success.tpl');
323 $page->assign('now', strftime("%Y%m%d%H%M%S"));
325 $page->changeTpl('motdepasse.tpl');
326 $page->addJsLink('motdepasse.js');
330 function handler_skin(&$page)
334 $page->changeTpl('skins.tpl');
335 $page->assign('xorg_title','Polytechnique.org - Skins');
337 if (Env
::has('newskin')) { // formulaire soumis, traitons les données envoyées
338 XDB
::execute('UPDATE auth_user_quick
339 SET skin={?} WHERE user_id={?}',
340 Env
::i('newskin'), S
::v('uid'));
345 $res = XDB
::query('SELECT id FROM skins WHERE skin_tpl={?}', S
::v('skin'));
346 $page->assign('skin_id', $res->fetchOneCell());
348 $sql = "SELECT s.*,auteur,count(*) AS nb
350 LEFT JOIN auth_user_quick AS a ON s.id=a.skin
351 WHERE skin_tpl != '' AND ext != ''
352 GROUP BY id ORDER BY s.date DESC";
353 $page->assign_by_ref('skins', XDB
::iterator($sql));
356 function handler_exit(&$page, $level = null
)
358 if (S
::has('suid')) {
359 if (S
::has('suid')) {
360 $a4l = S
::v('forlife');
361 $suid = S
::v('suid');
363 $log->log("suid_stop", S
::v('forlife') . " by " . $suid['forlife']);
366 pl_redirect('admin/utilisateurs.php', 'login='.$a4l);
368 pl_redirect('events');
372 if ($level == 'forget' ||
$level == 'forgetall') {
373 setcookie('ORGaccess', '', time() - 3600, '/', '', 0);
374 Cookie
::kill('ORGaccess');
375 if (isset($_SESSION['log']))
376 $_SESSION['log']->log("cookie_off");
379 if ($level == 'forgetuid' ||
$level == 'forgetall') {
380 setcookie('ORGuid', '', time() - 3600, '/', '', 0);
381 Cookie
::kill('ORGuid');
382 setcookie('ORGdomain', '', time() - 3600, '/', '', 0);
383 Cookie
::kill('ORGdomain');
386 if (isset($_SESSION['log'])) {
387 $ref = isset($_SERVER['HTTP_REFERER']) ?
$_SERVER['HTTP_REFERER'] : '';
388 $_SESSION['log']->log('deconnexion',$ref);
391 XorgSession
::destroy();
393 if (Get
::has('redirect')) {
394 http_redirect(rawurldecode(Get
::v('redirect')));
396 $page->changeTpl('exit.tpl');
400 function handler_rss(&$page, $user = null
, $hash = null
)
402 require_once 'rss.inc.php';
404 $uid = init_rss('rss.tpl', $user, $hash);
406 $rss = XDB
::iterator(
407 'SELECT e.id, e.titre, e.texte, e.creation_date,
408 IF(u2.nom_usage = "", u2.nom, u2.nom_usage) AS nom, u2.prenom, u2.promo
409 FROM auth_user_md5 AS u
410 INNER JOIN evenements AS e ON ( (e.promo_min = 0 || e.promo_min <= u.promo)
411 AND (e.promo_max = 0 || e.promo_max >= u.promo) )
412 INNER JOIN auth_user_md5 AS u2 ON (u2.user_id = e.user_id)
413 WHERE u.user_id = {?} AND FIND_IN_SET(e.flags, "valide")
414 AND peremption >= NOW()', $uid);
415 $page->assign('rss', $rss);