fe02deda2d9afcce385fd6b0d6e5b0822c0a3f48
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
),
30 'skin' => $this->make_hook('skin', AUTH_COOKIE
),
32 // password related thingies
33 'password' => $this->make_hook('password', AUTH_MDP
),
34 'tmpPWD' => $this->make_hook('tmpPWD', AUTH_PUBLIC
),
35 'password/smtp' => $this->make_hook('smtppass', AUTH_MDP
),
36 'recovery' => $this->make_hook('recovery', AUTH_PUBLIC
),
38 // happenings related thingies
39 'rss' => $this->make_hook('rss', AUTH_PUBLIC
),
43 function __set_rss_state($state)
48 $_SESSION['core_rss_hash'] = rand_url_id(16);
49 $globals->xdb
->execute('UPDATE auth_user_quick
50 SET core_rss_hash={?} WHERE user_id={?}',
51 Session
::get('core_rss_hash'),
52 Session
::getInt('uid'));
54 $globals->xdb
->execute('UPDATE auth_user_quick
55 SET core_rss_hash="" WHERE user_id={?}',
56 Session
::getInt('uid'));
57 Session
::kill('core_rss_hash');
61 function handler_prefs(&$page)
65 $page->changeTpl('preferences.tpl');
66 $page->assign('xorg_title','Polytechnique.org - Mes préférences');
68 if (Env
::has('mail_fmt')) {
69 $fmt = Env
::get('mail_fmt');
70 if ($fmt != 'texte') $fmt = 'html';
71 $globals->xdb
->execute("UPDATE auth_user_quick
72 SET core_mail_fmt = '$fmt'
74 Session
::getInt('uid'));
75 $_SESSION['mail_fmt'] = $fmt;
76 redirect('preferences');
79 if (Env
::has('rss')) {
80 $this->__set_rss_state(Env
::getBool('rss'));
83 $page->assign('prefs', $globals->hook
->prefs());
88 function handler_prefs_rss(&$page)
92 $page->changeTpl('filrss.tpl');
94 $page->assign('goback', Env
::get('referer', 'login'));
96 if (Env
::get('act_rss') == 'Activer') {
97 $this->__set_rss_state(true
);
98 $page->trig("Ton Fil RSS est activé.");
104 function handler_password(&$page)
108 if (Post
::has('response2')) {
109 require_once 'secure_hash.inc.php';
111 $_SESSION['password'] = $password = Post
::get('response2');
113 $globals->xdb
->execute('UPDATE auth_user_md5
115 WHERE user_id={?}', $password,
116 Session
::getInt('uid'));
118 $log =& Session
::getMixed('log');
119 $log->log('passwd', '');
121 if (Cookie
::get('ORGaccess')) {
122 setcookie('ORGaccess', hash_encrypt($password), (time()+
25920000), '/', '' ,0);
125 $page->changeTpl('motdepasse.success.tpl');
129 $page->changeTpl('motdepasse.tpl');
130 $page->addJsLink('javascript/motdepasse.js');
131 $page->assign('xorg_title','Polytechnique.org - Mon mot de passe');
136 function handler_smtppass(&$page)
140 $page->changeTpl('acces_smtp.tpl');
141 $page->assign('xorg_title','Polytechnique.org - Acces SMTP/NNTP');
143 $uid = Session
::getInt('uid');
144 $pass = Env
::get('smtppass1');
145 $log = Session
::getMixed('log');
147 if (Env
::get('op') == "Valider" && strlen($pass) >= 6
148 && Env
::get('smtppass1') == Env
::get('smtppass2'))
150 $globals->xdb
->execute('UPDATE auth_user_md5 SET smtppass = {?}
151 WHERE user_id = {?}', $pass, $uid);
152 $page->trig('Mot de passe enregistré');
153 $log->log("passwd_ssl");
154 } elseif (Env
::get('op') == "Supprimer") {
155 $globals->xdb
->execute('UPDATE auth_user_md5 SET smtppass = ""
156 WHERE user_id = {?}', $uid);
157 $page->trig('Compte SMTP et NNTP supprimé');
158 $log->log("passwd_del");
161 $res = $globals->xdb
->query("SELECT IF(smtppass != '', 'actif', '')
163 WHERE user_id = {?}", $uid);
164 $page->assign('actif', $res->fetchOneCell());
169 function handler_recovery(&$page)
173 $page->changeTpl('recovery.tpl');
175 if (!Env
::has('login') ||
!Env
::has('birth')) {
179 if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env
::get('birth'))) {
180 $page->trig_run('Date de naissance incorrecte ou incohérente');
182 $birth = sprintf('%s-%s-%s', substr(Env
::get('birth'),4,4), substr(Env
::get('birth'),2,2), substr(Env
::get('birth'),0,2));
184 $mailorg = strtok(Env
::get('login'), '@');
186 // paragraphe rajouté : si la date de naissance dans la base n'existe pas, on l'update
187 // avec celle fournie ici en espérant que c'est la bonne
189 $res = $globals->xdb
->query(
190 "SELECT user_id, naissance
191 FROM auth_user_md5 AS u
192 INNER JOIN aliases AS a ON (u.user_id=a.id AND type!='homonyme')
193 WHERE a.alias={?} AND u.perms IN ('admin','user') AND u.deces=0", $mailorg);
194 list($uid, $naissance) = $res->fetchOneRow();
196 if ($naissance == $birth) {
197 $page->assign('ok', true
);
199 $url = rand_url_id();
200 $globals->xdb
->execute('INSERT INTO perte_pass (certificat,uid,created) VALUES ({?},{?},NOW())', $url, $uid);
201 $res = $globals->xdb
->query('SELECT email FROM emails WHERE uid = {?} AND NOT FIND_IN_SET("filter", flags)', $uid);
202 $mails = implode(', ', $res->fetchColumn());
204 require_once "diogenes/diogenes.hermes.inc.php";
205 $mymail = new HermesMailer();
206 $mymail->setFrom('"Gestion des mots de passe" <support+password@polytechnique.org>');
207 $mymail->addTo($mails);
208 $mymail->setSubject('Ton certificat d\'authentification');
209 $mymail->setTxtBody("Visite la page suivante qui expire dans six heures :
210 {$globals->baseurl}/tmpPWD/$url
212 Si en cliquant dessus tu n'y arrives pas, copie intégralement l'adresse dans la barre de ton navigateur.
216 \"Le portail des élèves & anciens élèves de l'Ecole polytechnique\"".(Post
::get('email') ?
"
219 ".Post
::get('email') : "")."
221 Mail envoyé à ".Env
::get('login'));
224 // on cree un objet logger et on log l'evenement
225 $logger = $_SESSION['log'] = new DiogenesCoreLogger($uid);
226 $logger->log('recovery', $emails);
228 $page->trig('Pas de résultat correspondant aux champs entrés dans notre base de données.');
234 function handler_tmpPWD(&$page, $certif = null
)
238 $globals->xdb
->execute('DELETE FROM perte_pass
239 WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created');
241 $res = $globals->xdb
->query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif);
242 $ligne = $res->fetchOneAssoc();
244 $page->changeTpl('index.tpl');
245 $page->kill("Cette adresse n'existe pas ou n'existe plus sur le serveur.");
248 $uid = $ligne["uid"];
249 if (Post
::has('response2')) {
250 $password = Post
::get('response2');
251 $logger = new DiogenesCoreLogger($uid);
252 $globals->xdb
->query('UPDATE auth_user_md5 SET password={?}
253 WHERE user_id={?} AND perms IN("admin","user")',
255 $globals->xdb
->query('DELETE FROM perte_pass WHERE certificat={?}', $certif);
256 $logger->log("passwd","");
257 $page->changeTpl('tmpPWD.success.tpl');
259 $page->changeTpl('motdepasse.tpl');
260 $page->addJsLink('javascript/motdepasse.js');
266 function handler_skin(&$page)
270 if (!$globals->skin
->enable
) {
274 $page->changeTpl('skins.tpl');
275 $page->assign('xorg_title','Polytechnique.org - Skins');
277 if (Env
::has('newskin')) { // formulaire soumis, traitons les données envoyées
278 $globals->xdb
->execute('UPDATE auth_user_quick
279 SET skin={?} WHERE user_id={?}',
280 Env
::getInt('newskin'),
281 Session
::getInt('uid'));
285 $sql = "SELECT s.*,auteur,count(*) AS nb
287 LEFT JOIN auth_user_quick AS a ON s.id=a.skin
288 WHERE skin_tpl != '' AND ext != ''
289 GROUP BY id ORDER BY s.date DESC";
290 $page->assign_by_ref('skins', $globals->xdb
->iterator($sql));
294 function handler_rss(&$page, $user = null
, $hash = null
)
298 require_once 'rss.inc.php';
300 $uid = init_rss('rss.tpl', $user, $hash);
302 $rss = $globals->xdb
->iterator(
303 'SELECT e.id, e.titre, e.texte, e.creation_date
304 FROM auth_user_md5 AS u
305 INNER JOIN evenements AS e ON ( (e.promo_min = 0 || e.promo_min <= u.promo)
306 AND (e.promo_max = 0 || e.promo_max >= u.promo) )
307 WHERE u.user_id = {?} AND FIND_IN_SET(e.flags, "valide")
308 AND peremption >= NOW()', $uid);
309 $page->assign('rss', $rss);