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 $page->assign('ChangeLog', $clog);
89 function __set_rss_state($state)
92 $_SESSION['core_rss_hash'] = rand_url_id(16);
93 XDB
::execute('UPDATE auth_user_quick
94 SET core_rss_hash={?} WHERE user_id={?}',
95 S
::v('core_rss_hash'), S
::v('uid'));
97 XDB
::execute('UPDATE auth_user_quick
98 SET core_rss_hash="" WHERE user_id={?}',
100 S
::kill('core_rss_hash');
104 function handler_prefs(&$page)
106 $page->changeTpl('preferences.tpl');
107 $page->assign('xorg_title','Polytechnique.org - Mes préférences');
109 if (Post
::has('mail_fmt')) {
110 $fmt = Post
::v('mail_fmt');
111 if ($fmt != 'texte') $fmt = 'html';
112 XDB
::execute("UPDATE auth_user_quick
113 SET core_mail_fmt = '$fmt'
114 WHERE user_id = {?}",
116 $_SESSION['mail_fmt'] = $fmt;
119 if (Post
::has('rss')) {
120 $this->__set_rss_state(Post
::b('rss'));
124 function handler_webredir(&$page)
126 $page->changeTpl('webredirect.tpl');
128 $page->assign('xorg_title','Polytechnique.org - Redirection de page WEB');
131 $url = Env
::v('url');
133 if (Env
::v('submit') == 'Valider' and Env
::has('url')) {
134 XDB
::execute('UPDATE auth_user_quick
135 SET redirecturl = {?} WHERE user_id = {?}',
137 $log->log('carva_add', 'http://'.Env
::v('url'));
138 $page->trig("Redirection activée vers <a href='http://$url'>$url</a>");
139 } elseif (Env
::v('submit') == "Supprimer") {
140 XDB
::execute("UPDATE auth_user_quick
142 WHERE user_id = {?}",
144 $log->log("carva_del", $url);
146 $page->trig('Redirection supprimée');
149 $res = XDB
::query('SELECT redirecturl
151 WHERE user_id = {?}',
153 $page->assign('carva', $res->fetchOneCell());
156 function handler_prefs_rss(&$page)
158 $page->changeTpl('filrss.tpl');
160 $page->assign('goback', Env
::v('referer', 'login'));
162 if (Env
::v('act_rss') == 'Activer') {
163 $this->__set_rss_state(true
);
164 $page->trig("Ton Fil RSS est activé.");
168 function handler_password(&$page)
170 if (Post
::has('response2')) {
171 require_once 'secure_hash.inc.php';
173 $_SESSION['password'] = $password = Post
::v('response2');
175 XDB
::execute('UPDATE auth_user_md5
177 WHERE user_id={?}', $password,
181 $log->log('passwd', '');
183 if (Cookie
::v('ORGaccess')) {
184 setcookie('ORGaccess', hash_encrypt($password), (time()+
25920000), '/', '' ,0);
187 $page->changeTpl('motdepasse.success.tpl');
191 $page->changeTpl('motdepasse.tpl');
192 $page->addJsLink('javascript/motdepasse.js');
193 $page->assign('xorg_title','Polytechnique.org - Mon mot de passe');
196 function handler_smtppass(&$page)
198 $page->changeTpl('acces_smtp.tpl');
199 $page->assign('xorg_title','Polytechnique.org - Acces SMTP/NNTP');
202 $pass = Env
::v('smtppass1');
205 if (Env
::v('op') == "Valider" && strlen($pass) >= 6
206 && Env
::v('smtppass1') == Env
::v('smtppass2'))
208 XDB
::execute('UPDATE auth_user_md5 SET smtppass = {?}
209 WHERE user_id = {?}', $pass, $uid);
210 $page->trig('Mot de passe enregistré');
211 $log->log("passwd_ssl");
212 } elseif (Env
::v('op') == "Supprimer") {
213 XDB
::execute('UPDATE auth_user_md5 SET smtppass = ""
214 WHERE user_id = {?}', $uid);
215 $page->trig('Compte SMTP et NNTP supprimé');
216 $log->log("passwd_del");
219 $res = XDB
::query("SELECT IF(smtppass != '', 'actif', '')
221 WHERE user_id = {?}", $uid);
222 $page->assign('actif', $res->fetchOneCell());
225 function handler_recovery(&$page)
229 $page->changeTpl('recovery.tpl');
231 if (!Env
::has('login') ||
!Env
::has('birth')) {
235 if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env
::v('birth'))) {
236 $page->trig('Date de naissance incorrecte ou incohérente');
240 $birth = sprintf('%s-%s-%s',
241 substr(Env
::v('birth'), 4, 4),
242 substr(Env
::v('birth'), 2, 2),
243 substr(Env
::v('birth'), 0, 2));
245 $mailorg = strtok(Env
::v('login'), '@');
247 // paragraphe rajouté : si la date de naissance dans la base n'existe pas, on l'update
248 // avec celle fournie ici en espérant que c'est la bonne
251 "SELECT user_id, naissance
252 FROM auth_user_md5 AS u
253 INNER JOIN aliases AS a ON (u.user_id=a.id AND type!='homonyme')
254 WHERE a.alias={?} AND u.perms IN ('admin','user') AND u.deces=0", $mailorg);
255 list($uid, $naissance) = $res->fetchOneRow();
257 if ($naissance == $birth) {
258 $page->assign('ok', true
);
260 $url = rand_url_id();
261 XDB
::execute('INSERT INTO perte_pass (certificat,uid,created) VALUES ({?},{?},NOW())', $url, $uid);
262 $res = XDB
::query('SELECT email FROM emails WHERE uid = {?} AND NOT FIND_IN_SET("filter", flags)', $uid);
263 $mails = implode(', ', $res->fetchColumn());
265 require_once "diogenes/diogenes.hermes.inc.php";
266 $mymail = new HermesMailer();
267 $mymail->setFrom('"Gestion des mots de passe" <support+password@polytechnique.org>');
268 $mymail->addTo($mails);
269 $mymail->setSubject('Ton certificat d\'authentification');
270 $mymail->setTxtBody("Visite la page suivante qui expire dans six heures :
271 {$globals->baseurl}/tmpPWD/$url
273 Si en cliquant dessus tu n'y arrives pas, copie intégralement l'adresse dans la barre de ton navigateur.
277 \"Le portail des élèves & anciens élèves de l'Ecole polytechnique\"".(Post
::v('email') ?
"
280 ".Post
::v('email') : "")."
282 Mail envoyé à ".Env
::v('login'));
285 // on cree un objet logger et on log l'evenement
286 $logger = $_SESSION['log'] = new DiogenesCoreLogger($uid);
287 $logger->log('recovery', $emails);
289 $page->trig('Pas de résultat correspondant aux champs entrés dans notre base de données.');
293 function handler_tmpPWD(&$page, $certif = null
)
295 XDB
::execute('DELETE FROM perte_pass
296 WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created');
298 $res = XDB
::query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif);
299 $ligne = $res->fetchOneAssoc();
301 $page->changeTpl('index.tpl');
302 $page->kill("Cette adresse n'existe pas ou n'existe plus sur le serveur.");
305 $uid = $ligne["uid"];
306 if (Post
::has('response2')) {
307 $password = Post
::v('response2');
308 $logger = new DiogenesCoreLogger($uid);
309 XDB
::query('UPDATE auth_user_md5 SET password={?}
310 WHERE user_id={?} AND perms IN("admin","user")',
312 XDB
::query('DELETE FROM perte_pass WHERE certificat={?}', $certif);
313 $logger->log("passwd","");
314 $page->changeTpl('tmpPWD.success.tpl');
316 $page->changeTpl('motdepasse.tpl');
317 $page->addJsLink('javascript/motdepasse.js');
321 function handler_skin(&$page)
325 $page->changeTpl('skins.tpl');
326 $page->assign('xorg_title','Polytechnique.org - Skins');
328 if (Env
::has('newskin')) { // formulaire soumis, traitons les données envoyées
329 XDB
::execute('UPDATE auth_user_quick
330 SET skin={?} WHERE user_id={?}',
331 Env
::i('newskin'), S
::v('uid'));
336 $res = XDB
::query('SELECT id FROM skins WHERE skin_tpl={?}', S
::v('skin'));
337 $page->assign('skin_id', $res->fetchOneCell());
339 $sql = "SELECT s.*,auteur,count(*) AS nb
341 LEFT JOIN auth_user_quick AS a ON s.id=a.skin
342 WHERE skin_tpl != '' AND ext != ''
343 GROUP BY id ORDER BY s.date DESC";
344 $page->assign_by_ref('skins', XDB
::iterator($sql));
347 function handler_exit(&$page, $level = null
)
349 if (S
::has('suid')) {
350 if (S
::has('suid')) {
351 $a4l = S
::v('forlife');
352 $suid = S
::v('suid');
354 $log->log("suid_stop", S
::v('forlife') . " by " . $suid['forlife']);
357 pl_redirect('admin/utilisateurs.php', 'login='.$a4l);
359 pl_redirect('events');
363 if ($level == 'forget' ||
$level == 'forgetall') {
364 setcookie('ORGaccess', '', time() - 3600, '/', '', 0);
365 Cookie
::kill('ORGaccess');
366 if (isset($_SESSION['log']))
367 $_SESSION['log']->log("cookie_off");
370 if ($level == 'forgetuid' ||
$level == 'forgetall') {
371 setcookie('ORGuid', '', time() - 3600, '/', '', 0);
372 Cookie
::kill('ORGuid');
373 setcookie('ORGdomain', '', time() - 3600, '/', '', 0);
374 Cookie
::kill('ORGdomain');
377 if (isset($_SESSION['log'])) {
378 $ref = isset($_SERVER['HTTP_REFERER']) ?
$_SERVER['HTTP_REFERER'] : '';
379 $_SESSION['log']->log('deconnexion',$ref);
382 XorgSession
::destroy();
384 if (Get
::has('redirect')) {
385 http_redirect(rawurldecode(Get
::v('redirect')));
387 $page->changeTpl('exit.tpl');
391 function handler_rss(&$page, $user = null
, $hash = null
)
393 require_once 'rss.inc.php';
395 $uid = init_rss('rss.tpl', $user, $hash);
397 $rss = XDB
::iterator(
398 'SELECT e.id, e.titre, e.texte, e.creation_date
399 FROM auth_user_md5 AS u
400 INNER JOIN evenements AS e ON ( (e.promo_min = 0 || e.promo_min <= u.promo)
401 AND (e.promo_max = 0 || e.promo_max >= u.promo) )
402 WHERE u.user_id = {?} AND FIND_IN_SET(e.flags, "valide")
403 AND peremption >= NOW()', $uid);
404 $page->assign('rss', $rss);