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 class PlatalModule
extends PLModule
27 // Preferences thingies
28 'prefs' => $this->make_hook('prefs', AUTH_COOKIE
),
29 'prefs/rss' => $this->make_hook('prefs_rss', AUTH_COOKIE
),
31 => $this->make_hook('webredir', AUTH_MDP
),
32 'skin' => $this->make_hook('skin', AUTH_COOKIE
),
34 // password related thingies
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
),
38 'recovery' => $this->make_hook('recovery', AUTH_PUBLIC
),
40 // happenings related thingies
41 'rss' => $this->make_hook('rss', AUTH_PUBLIC
),
45 function __set_rss_state($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'));
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');
63 function handler_prefs(&$page)
67 $page->changeTpl('preferences.tpl');
68 $page->assign('xorg_title','Polytechnique.org - Mes préférences');
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'
76 Session
::getInt('uid'));
77 $_SESSION['mail_fmt'] = $fmt;
78 redirect($globals->baseurl
.'/preferences');
81 if (Env
::has('rss')) {
82 $this->__set_rss_state(Env
::getBool('rss'));
85 $page->assign('prefs', $globals->hook
->prefs());
90 function handler_webredir(&$page)
94 $page->changeTpl('webredirect.tpl');
96 $page->assign('xorg_title','Polytechnique.org - Redirection de page WEB');
98 $log =& Session
::getMixed('log');
99 $url = Env
::get('url');
101 if (Env
::get('submit') == 'Valider' and Env
::has('url')) {
102 $globals->xdb
->execute('UPDATE auth_user_quick
103 SET redirecturl = {?} WHERE user_id = {?}',
104 $url, Session
::getInt('uid'));
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
110 WHERE user_id = {?}",
111 Session
::getInt('uid'));
112 $log->log("carva_del", $url);
114 $page->trig('Redirection supprimée');
117 $res = $globals->xdb
->query('SELECT redirecturl
119 WHERE user_id = {?}',
120 Session
::getInt('uid'));
121 $page->assign('carva', $res->fetchOneCell());
126 function handler_prefs_rss(&$page)
130 $page->changeTpl('filrss.tpl');
132 $page->assign('goback', Env
::get('referer', 'login'));
134 if (Env
::get('act_rss') == 'Activer') {
135 $this->__set_rss_state(true
);
136 $page->trig("Ton Fil RSS est activé.");
142 function handler_password(&$page)
146 if (Post
::has('response2')) {
147 require_once 'secure_hash.inc.php';
149 $_SESSION['password'] = $password = Post
::get('response2');
151 $globals->xdb
->execute('UPDATE auth_user_md5
153 WHERE user_id={?}', $password,
154 Session
::getInt('uid'));
156 $log =& Session
::getMixed('log');
157 $log->log('passwd', '');
159 if (Cookie
::get('ORGaccess')) {
160 setcookie('ORGaccess', hash_encrypt($password), (time()+
25920000), '/', '' ,0);
163 $page->changeTpl('motdepasse.success.tpl');
167 $page->changeTpl('motdepasse.tpl');
168 $page->addJsLink('javascript/motdepasse.js');
169 $page->assign('xorg_title','Polytechnique.org - Mon mot de passe');
174 function handler_smtppass(&$page)
178 $page->changeTpl('acces_smtp.tpl');
179 $page->assign('xorg_title','Polytechnique.org - Acces SMTP/NNTP');
181 $uid = Session
::getInt('uid');
182 $pass = Env
::get('smtppass1');
183 $log = Session
::getMixed('log');
185 if (Env
::get('op') == "Valider" && strlen($pass) >= 6
186 && Env
::get('smtppass1') == Env
::get('smtppass2'))
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");
199 $res = $globals->xdb
->query("SELECT IF(smtppass != '', 'actif', '')
201 WHERE user_id = {?}", $uid);
202 $page->assign('actif', $res->fetchOneCell());
207 function handler_recovery(&$page)
211 $page->changeTpl('recovery.tpl');
213 if (!Env
::has('login') ||
!Env
::has('birth')) {
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');
220 $birth = sprintf('%s-%s-%s', substr(Env
::get('birth'),4,4), substr(Env
::get('birth'),2,2), substr(Env
::get('birth'),0,2));
222 $mailorg = strtok(Env
::get('login'), '@');
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
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();
234 if ($naissance == $birth) {
235 $page->assign('ok', true
);
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());
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
250 Si en cliquant dessus tu n'y arrives pas, copie intégralement l'adresse dans la barre de ton navigateur.
254 \"Le portail des élèves & anciens élèves de l'Ecole polytechnique\"".(Post
::get('email') ?
"
257 ".Post
::get('email') : "")."
259 Mail envoyé à ".Env
::get('login'));
262 // on cree un objet logger et on log l'evenement
263 $logger = $_SESSION['log'] = new DiogenesCoreLogger($uid);
264 $logger->log('recovery', $emails);
266 $page->trig('Pas de résultat correspondant aux champs entrés dans notre base de données.');
272 function handler_tmpPWD(&$page, $certif = null
)
276 $globals->xdb
->execute('DELETE FROM perte_pass
277 WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created');
279 $res = $globals->xdb
->query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif);
280 $ligne = $res->fetchOneAssoc();
282 $page->changeTpl('index.tpl');
283 $page->kill("Cette adresse n'existe pas ou n'existe plus sur le serveur.");
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")',
293 $globals->xdb
->query('DELETE FROM perte_pass WHERE certificat={?}', $certif);
294 $logger->log("passwd","");
295 $page->changeTpl('tmpPWD.success.tpl');
297 $page->changeTpl('motdepasse.tpl');
298 $page->addJsLink('javascript/motdepasse.js');
304 function handler_skin(&$page)
308 if (!$globals->skin
->enable
) {
312 $page->changeTpl('skins.tpl');
313 $page->assign('xorg_title','Polytechnique.org - Skins');
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'));
323 $sql = "SELECT s.*,auteur,count(*) AS nb
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));
332 function handler_rss(&$page, $user = null
, $hash = null
)
336 require_once 'rss.inc.php';
338 $uid = init_rss('rss.tpl', $user, $hash);
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);