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 '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)
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 $page->assign('ChangeLog', $clog);
89 function __set_rss_state($state)
94 $_SESSION['core_rss_hash'] = rand_url_id(16);
95 $globals->xdb
->execute('UPDATE auth_user_quick
96 SET core_rss_hash={?} WHERE user_id={?}',
97 Session
::get('core_rss_hash'),
98 Session
::getInt('uid'));
100 $globals->xdb
->execute('UPDATE auth_user_quick
101 SET core_rss_hash="" WHERE user_id={?}',
102 Session
::getInt('uid'));
103 Session
::kill('core_rss_hash');
107 function handler_prefs(&$page)
111 $page->changeTpl('preferences.tpl');
112 $page->assign('xorg_title','Polytechnique.org - Mes préférences');
114 if (Env
::has('mail_fmt')) {
115 $fmt = Env
::get('mail_fmt');
116 if ($fmt != 'texte') $fmt = 'html';
117 $globals->xdb
->execute("UPDATE auth_user_quick
118 SET core_mail_fmt = '$fmt'
119 WHERE user_id = {?}",
120 Session
::getInt('uid'));
121 $_SESSION['mail_fmt'] = $fmt;
122 redirect($globals->baseurl
.'/preferences');
125 if (Env
::has('rss')) {
126 $this->__set_rss_state(Env
::getBool('rss'));
129 $page->assign('prefs', $globals->hook
->prefs());
132 function handler_webredir(&$page)
136 $page->changeTpl('webredirect.tpl');
138 $page->assign('xorg_title','Polytechnique.org - Redirection de page WEB');
140 $log =& Session
::getMixed('log');
141 $url = Env
::get('url');
143 if (Env
::get('submit') == 'Valider' and Env
::has('url')) {
144 $globals->xdb
->execute('UPDATE auth_user_quick
145 SET redirecturl = {?} WHERE user_id = {?}',
146 $url, Session
::getInt('uid'));
147 $log->log('carva_add', 'http://'.Env
::get('url'));
148 $page->trig("Redirection activée vers <a href='http://$url'>$url</a>");
149 } elseif (Env
::get('submit') == "Supprimer") {
150 $globals->xdb
->execute("UPDATE auth_user_quick
152 WHERE user_id = {?}",
153 Session
::getInt('uid'));
154 $log->log("carva_del", $url);
156 $page->trig('Redirection supprimée');
159 $res = $globals->xdb
->query('SELECT redirecturl
161 WHERE user_id = {?}',
162 Session
::getInt('uid'));
163 $page->assign('carva', $res->fetchOneCell());
166 function handler_prefs_rss(&$page)
170 $page->changeTpl('filrss.tpl');
172 $page->assign('goback', Env
::get('referer', 'login'));
174 if (Env
::get('act_rss') == 'Activer') {
175 $this->__set_rss_state(true
);
176 $page->trig("Ton Fil RSS est activé.");
180 function handler_password(&$page)
184 if (Post
::has('response2')) {
185 require_once 'secure_hash.inc.php';
187 $_SESSION['password'] = $password = Post
::get('response2');
189 $globals->xdb
->execute('UPDATE auth_user_md5
191 WHERE user_id={?}', $password,
192 Session
::getInt('uid'));
194 $log =& Session
::getMixed('log');
195 $log->log('passwd', '');
197 if (Cookie
::get('ORGaccess')) {
198 setcookie('ORGaccess', hash_encrypt($password), (time()+
25920000), '/', '' ,0);
201 $page->changeTpl('motdepasse.success.tpl');
205 $page->changeTpl('motdepasse.tpl');
206 $page->addJsLink('javascript/motdepasse.js');
207 $page->assign('xorg_title','Polytechnique.org - Mon mot de passe');
210 function handler_smtppass(&$page)
214 $page->changeTpl('acces_smtp.tpl');
215 $page->assign('xorg_title','Polytechnique.org - Acces SMTP/NNTP');
217 $uid = Session
::getInt('uid');
218 $pass = Env
::get('smtppass1');
219 $log = Session
::getMixed('log');
221 if (Env
::get('op') == "Valider" && strlen($pass) >= 6
222 && Env
::get('smtppass1') == Env
::get('smtppass2'))
224 $globals->xdb
->execute('UPDATE auth_user_md5 SET smtppass = {?}
225 WHERE user_id = {?}', $pass, $uid);
226 $page->trig('Mot de passe enregistré');
227 $log->log("passwd_ssl");
228 } elseif (Env
::get('op') == "Supprimer") {
229 $globals->xdb
->execute('UPDATE auth_user_md5 SET smtppass = ""
230 WHERE user_id = {?}', $uid);
231 $page->trig('Compte SMTP et NNTP supprimé');
232 $log->log("passwd_del");
235 $res = $globals->xdb
->query("SELECT IF(smtppass != '', 'actif', '')
237 WHERE user_id = {?}", $uid);
238 $page->assign('actif', $res->fetchOneCell());
241 function handler_recovery(&$page)
245 $page->changeTpl('recovery.tpl');
247 if (!Env
::has('login') ||
!Env
::has('birth')) {
251 if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env
::get('birth'))) {
252 $page->trig_run('Date de naissance incorrecte ou incohérente');
254 $birth = sprintf('%s-%s-%s', substr(Env
::get('birth'),4,4), substr(Env
::get('birth'),2,2), substr(Env
::get('birth'),0,2));
256 $mailorg = strtok(Env
::get('login'), '@');
258 // paragraphe rajouté : si la date de naissance dans la base n'existe pas, on l'update
259 // avec celle fournie ici en espérant que c'est la bonne
261 $res = $globals->xdb
->query(
262 "SELECT user_id, naissance
263 FROM auth_user_md5 AS u
264 INNER JOIN aliases AS a ON (u.user_id=a.id AND type!='homonyme')
265 WHERE a.alias={?} AND u.perms IN ('admin','user') AND u.deces=0", $mailorg);
266 list($uid, $naissance) = $res->fetchOneRow();
268 if ($naissance == $birth) {
269 $page->assign('ok', true
);
271 $url = rand_url_id();
272 $globals->xdb
->execute('INSERT INTO perte_pass (certificat,uid,created) VALUES ({?},{?},NOW())', $url, $uid);
273 $res = $globals->xdb
->query('SELECT email FROM emails WHERE uid = {?} AND NOT FIND_IN_SET("filter", flags)', $uid);
274 $mails = implode(', ', $res->fetchColumn());
276 require_once "diogenes/diogenes.hermes.inc.php";
277 $mymail = new HermesMailer();
278 $mymail->setFrom('"Gestion des mots de passe" <support+password@polytechnique.org>');
279 $mymail->addTo($mails);
280 $mymail->setSubject('Ton certificat d\'authentification');
281 $mymail->setTxtBody("Visite la page suivante qui expire dans six heures :
282 {$globals->baseurl}/tmpPWD/$url
284 Si en cliquant dessus tu n'y arrives pas, copie intégralement l'adresse dans la barre de ton navigateur.
288 \"Le portail des élèves & anciens élèves de l'Ecole polytechnique\"".(Post
::get('email') ?
"
291 ".Post
::get('email') : "")."
293 Mail envoyé à ".Env
::get('login'));
296 // on cree un objet logger et on log l'evenement
297 $logger = $_SESSION['log'] = new DiogenesCoreLogger($uid);
298 $logger->log('recovery', $emails);
300 $page->trig('Pas de résultat correspondant aux champs entrés dans notre base de données.');
304 function handler_tmpPWD(&$page, $certif = null
)
308 $globals->xdb
->execute('DELETE FROM perte_pass
309 WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created');
311 $res = $globals->xdb
->query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif);
312 $ligne = $res->fetchOneAssoc();
314 $page->changeTpl('index.tpl');
315 $page->kill("Cette adresse n'existe pas ou n'existe plus sur le serveur.");
318 $uid = $ligne["uid"];
319 if (Post
::has('response2')) {
320 $password = Post
::get('response2');
321 $logger = new DiogenesCoreLogger($uid);
322 $globals->xdb
->query('UPDATE auth_user_md5 SET password={?}
323 WHERE user_id={?} AND perms IN("admin","user")',
325 $globals->xdb
->query('DELETE FROM perte_pass WHERE certificat={?}', $certif);
326 $logger->log("passwd","");
327 $page->changeTpl('tmpPWD.success.tpl');
329 $page->changeTpl('motdepasse.tpl');
330 $page->addJsLink('javascript/motdepasse.js');
334 function handler_skin(&$page)
338 if (!$globals->skin
->enable
) {
342 $page->changeTpl('skins.tpl');
343 $page->assign('xorg_title','Polytechnique.org - Skins');
345 if (Env
::has('newskin')) { // formulaire soumis, traitons les données envoyées
346 $globals->xdb
->execute('UPDATE auth_user_quick
347 SET skin={?} WHERE user_id={?}',
348 Env
::getInt('newskin'),
349 Session
::getInt('uid'));
353 $sql = "SELECT s.*,auteur,count(*) AS nb
355 LEFT JOIN auth_user_quick AS a ON s.id=a.skin
356 WHERE skin_tpl != '' AND ext != ''
357 GROUP BY id ORDER BY s.date DESC";
358 $page->assign_by_ref('skins', $globals->xdb
->iterator($sql));
361 function handler_exit(&$page, $level = null
)
363 if (Session
::has('suid')) {
364 if (Session
::has('suid')) {
365 $a4l = Session
::get('forlife');
366 $suid = Session
::getMixed('suid');
367 $log = Session
::getMixed('log');
368 $log->log("suid_stop", Session
::get('forlife') . " by " . $suid['forlife']);
370 Session
::kill('suid');
371 redirect($globals->baseurl
.'/admin/utilisateurs.php?login='.$a4l);
377 if ($level == 'forget' ||
$level == 'forgetall') {
378 setcookie('ORGaccess', '', time() - 3600, '/', '', 0);
379 Cookie
::kill('ORGaccess');
380 if (isset($_SESSION['log']))
381 $_SESSION['log']->log("cookie_off");
384 if ($level == 'forgetuid' ||
$level == 'forgetall') {
385 setcookie('ORGuid', '', time() - 3600, '/', '', 0);
386 Cookie
::kill('ORGuid');
387 setcookie('ORGdomain', '', time() - 3600, '/', '', 0);
388 Cookie
::kill('ORGdomain');
391 if (isset($_SESSION['log'])) {
392 $ref = isset($_SERVER['HTTP_REFERER']) ?
$_SERVER['HTTP_REFERER'] : '';
393 $_SESSION['log']->log('deconnexion',$ref);
396 XorgSession
::destroy();
398 if (Get
::has('redirect')) {
399 redirect(rawurldecode(Get
::get('redirect')));
401 $page->changeTpl('exit.tpl');
405 function handler_rss(&$page, $user = null
, $hash = null
)
409 require_once 'rss.inc.php';
411 $uid = init_rss('rss.tpl', $user, $hash);
413 $rss = $globals->xdb
->iterator(
414 'SELECT e.id, e.titre, e.texte, e.creation_date
415 FROM auth_user_md5 AS u
416 INNER JOIN evenements AS e ON ( (e.promo_min = 0 || e.promo_min <= u.promo)
417 AND (e.promo_max = 0 || e.promo_max >= u.promo) )
418 WHERE u.user_id = {?} AND FIND_IN_SET(e.flags, "valide")
419 AND peremption >= NOW()', $uid);
420 $page->assign('rss', $rss);