| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2006 Polytechnique.org * |
| 4 | * http://opensource.polytechnique.org/ * |
| 5 | * * |
| 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. * |
| 10 | * * |
| 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. * |
| 15 | * * |
| 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 * |
| 18 | * Foundation, Inc., * |
| 19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | class PlatalModule extends PLModule |
| 23 | { |
| 24 | function handlers() |
| 25 | { |
| 26 | return array( |
| 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), |
| 31 | |
| 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 | |
| 37 | // happenings related thingies |
| 38 | 'rss' => $this->make_hook('rss', AUTH_PUBLIC), |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | function __set_rss_state($state) |
| 43 | { |
| 44 | global $globals; |
| 45 | |
| 46 | if ($state) { |
| 47 | $_SESSION['core_rss_hash'] = rand_url_id(16); |
| 48 | $globals->xdb->execute('UPDATE auth_user_quick |
| 49 | SET core_rss_hash={?} WHERE user_id={?}', |
| 50 | Session::get('core_rss_hash'), |
| 51 | Session::getInt('uid')); |
| 52 | } else { |
| 53 | $globals->xdb->execute('UPDATE auth_user_quick |
| 54 | SET core_rss_hash="" WHERE user_id={?}', |
| 55 | Session::getInt('uid')); |
| 56 | Session::kill('core_rss_hash'); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | function handler_prefs(&$page) |
| 61 | { |
| 62 | global $globals; |
| 63 | |
| 64 | $page->changeTpl('preferences.tpl'); |
| 65 | $page->assign('xorg_title','Polytechnique.org - Mes préférences'); |
| 66 | |
| 67 | if (Env::has('mail_fmt')) { |
| 68 | $fmt = Env::get('mail_fmt'); |
| 69 | if ($fmt != 'texte') $fmt = 'html'; |
| 70 | $globals->xdb->execute("UPDATE auth_user_quick |
| 71 | SET core_mail_fmt = '$fmt' |
| 72 | WHERE user_id = {?}", |
| 73 | Session::getInt('uid')); |
| 74 | $_SESSION['mail_fmt'] = $fmt; |
| 75 | redirect('preferences'); |
| 76 | } |
| 77 | |
| 78 | if (Env::has('rss')) { |
| 79 | $this->__set_rss_state(Env::getBool('rss')); |
| 80 | } |
| 81 | |
| 82 | $page->assign('prefs', $globals->hook->prefs()); |
| 83 | |
| 84 | return PL_OK; |
| 85 | } |
| 86 | |
| 87 | function handler_prefs_rss(&$page) |
| 88 | { |
| 89 | global $globals; |
| 90 | |
| 91 | $page->changeTpl('filrss.tpl'); |
| 92 | |
| 93 | $page->assign('goback', Env::get('referer', 'login')); |
| 94 | |
| 95 | if (Env::get('act_rss') == 'Activer') { |
| 96 | $this->__set_rss_state(true); |
| 97 | $page->trig("Ton Fil RSS est activé."); |
| 98 | } |
| 99 | |
| 100 | return PL_OK; |
| 101 | } |
| 102 | |
| 103 | function handler_password(&$page) |
| 104 | { |
| 105 | global $globals; |
| 106 | |
| 107 | if (Post::has('response2')) { |
| 108 | require_once 'secure_hash.inc.php'; |
| 109 | |
| 110 | $_SESSION['password'] = $password = Post::get('response2'); |
| 111 | |
| 112 | $globals->xdb->execute('UPDATE auth_user_md5 |
| 113 | SET password={?} |
| 114 | WHERE user_id={?}', $password, |
| 115 | Session::getInt('uid')); |
| 116 | |
| 117 | $log =& Session::getMixed('log'); |
| 118 | $log->log('passwd', ''); |
| 119 | |
| 120 | if (Cookie::get('ORGaccess')) { |
| 121 | setcookie('ORGaccess', hash_encrypt($password), (time()+25920000), '/', '' ,0); |
| 122 | } |
| 123 | |
| 124 | $page->changeTpl('motdepasse.success.tpl'); |
| 125 | $page->run(); |
| 126 | } |
| 127 | |
| 128 | $page->changeTpl('motdepasse.tpl'); |
| 129 | $page->addJsLink('javascript/motdepasse.js'); |
| 130 | $page->assign('xorg_title','Polytechnique.org - Mon mot de passe'); |
| 131 | |
| 132 | return PL_OK; |
| 133 | } |
| 134 | |
| 135 | function handler_smtppass(&$page) |
| 136 | { |
| 137 | global $globals; |
| 138 | |
| 139 | $page->changeTpl('acces_smtp.tpl'); |
| 140 | $page->assign('xorg_title','Polytechnique.org - Acces SMTP/NNTP'); |
| 141 | |
| 142 | $uid = Session::getInt('uid'); |
| 143 | $pass = Env::get('smtppass1'); |
| 144 | $log = Session::getMixed('log'); |
| 145 | |
| 146 | if (Env::get('op') == "Valider" && strlen($pass) >= 6 |
| 147 | && Env::get('smtppass1') == Env::get('smtppass2')) |
| 148 | { |
| 149 | $globals->xdb->execute('UPDATE auth_user_md5 SET smtppass = {?} |
| 150 | WHERE user_id = {?}', $pass, $uid); |
| 151 | $page->trig('Mot de passe enregistré'); |
| 152 | $log->log("passwd_ssl"); |
| 153 | } elseif (Env::get('op') == "Supprimer") { |
| 154 | $globals->xdb->execute('UPDATE auth_user_md5 SET smtppass = "" |
| 155 | WHERE user_id = {?}', $uid); |
| 156 | $page->trig('Compte SMTP et NNTP supprimé'); |
| 157 | $log->log("passwd_del"); |
| 158 | } |
| 159 | |
| 160 | $res = $globals->xdb->query("SELECT IF(smtppass != '', 'actif', '') |
| 161 | FROM auth_user_md5 |
| 162 | WHERE user_id = {?}", $uid); |
| 163 | $page->assign('actif', $res->fetchOneCell()); |
| 164 | |
| 165 | return PL_OK; |
| 166 | } |
| 167 | |
| 168 | function handler_tmpPWD(&$page, $certif = null) |
| 169 | { |
| 170 | global $globals; |
| 171 | |
| 172 | $globals->xdb->execute('DELETE FROM perte_pass |
| 173 | WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created'); |
| 174 | |
| 175 | $res = $globals->xdb->query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif); |
| 176 | $ligne = $res->fetchOneAssoc(); |
| 177 | if (!$ligne) { |
| 178 | $page->changeTpl('index.tpl'); |
| 179 | $page->kill("Cette adresse n'existe pas ou n'existe plus sur le serveur."); |
| 180 | } |
| 181 | |
| 182 | $uid = $ligne["uid"]; |
| 183 | if (Post::has('response2')) { |
| 184 | $password = Post::get('response2'); |
| 185 | $logger = new DiogenesCoreLogger($uid); |
| 186 | $globals->xdb->query('UPDATE auth_user_md5 SET password={?} |
| 187 | WHERE user_id={?} AND perms IN("admin","user")', |
| 188 | $password, $uid); |
| 189 | $globals->xdb->query('DELETE FROM perte_pass WHERE certificat={?}', $certif); |
| 190 | $logger->log("passwd",""); |
| 191 | $page->changeTpl('tmpPWD.success.tpl'); |
| 192 | } else { |
| 193 | $page->changeTpl('motdepasse.tpl'); |
| 194 | $page->addJsLink('javascript/motdepasse.js'); |
| 195 | } |
| 196 | |
| 197 | return PL_OK; |
| 198 | } |
| 199 | |
| 200 | function handler_skin(&$page) |
| 201 | { |
| 202 | global $globals; |
| 203 | |
| 204 | if (!$globals->skin->enable) { |
| 205 | redirect('./'); |
| 206 | } |
| 207 | |
| 208 | $page->changeTpl('skins.tpl'); |
| 209 | $page->assign('xorg_title','Polytechnique.org - Skins'); |
| 210 | |
| 211 | if (Env::has('newskin')) { // formulaire soumis, traitons les données envoyées |
| 212 | $globals->xdb->execute('UPDATE auth_user_quick |
| 213 | SET skin={?} WHERE user_id={?}', |
| 214 | Env::getInt('newskin'), |
| 215 | Session::getInt('uid')); |
| 216 | set_skin(); |
| 217 | } |
| 218 | |
| 219 | $sql = "SELECT s.*,auteur,count(*) AS nb |
| 220 | FROM skins AS s |
| 221 | LEFT JOIN auth_user_quick AS a ON s.id=a.skin |
| 222 | WHERE skin_tpl != '' AND ext != '' |
| 223 | GROUP BY id ORDER BY s.date DESC"; |
| 224 | $page->assign_by_ref('skins', $globals->xdb->iterator($sql)); |
| 225 | return PL_OK; |
| 226 | } |
| 227 | |
| 228 | function handler_rss(&$page, $user = null, $hash = null) |
| 229 | { |
| 230 | global $globals; |
| 231 | |
| 232 | require_once 'rss.inc.php'; |
| 233 | |
| 234 | $uid = init_rss('rss.tpl', $user, $hash); |
| 235 | |
| 236 | $rss = $globals->xdb->iterator( |
| 237 | 'SELECT e.id, e.titre, e.texte, e.creation_date |
| 238 | FROM auth_user_md5 AS u |
| 239 | INNER JOIN evenements AS e ON ( (e.promo_min = 0 || e.promo_min <= u.promo) |
| 240 | AND (e.promo_max = 0 || e.promo_max >= u.promo) ) |
| 241 | WHERE u.user_id = {?} AND FIND_IN_SET(e.flags, "valide") |
| 242 | AND peremption >= NOW()', $uid); |
| 243 | $page->assign('rss', $rss); |
| 244 | |
| 245 | return PL_OK; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | ?> |