| 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 AdminModule extends PLModule |
| 23 | { |
| 24 | function handlers() |
| 25 | { |
| 26 | return array( |
| 27 | 'admin' => $this->make_hook('default', AUTH_MDP, 'admin'), |
| 28 | 'admin/ax-xorg' => $this->make_hook('ax_xorg', AUTH_MDP, 'admin'), |
| 29 | 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP, 'admin'), |
| 30 | 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP, 'admin'), |
| 31 | 'admin/homonyms' => $this->make_hook('homonyms', AUTH_MDP, 'admin'), |
| 32 | 'admin/logger' => $this->make_hook('logger', AUTH_MDP, 'admin'), |
| 33 | 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_MDP, 'admin'), |
| 34 | 'admin/postfix/blacklist' => $this->make_hook('postfix_blacklist', AUTH_MDP, 'admin'), |
| 35 | 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP, 'admin'), |
| 36 | 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP, 'admin'), |
| 37 | 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP, 'admin'), |
| 38 | 'admin/skins' => $this->make_hook('skins', AUTH_MDP, 'admin'), |
| 39 | 'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP, 'admin'), |
| 40 | 'admin/user' => $this->make_hook('user', AUTH_MDP, 'admin'), |
| 41 | 'admin/validate' => $this->make_hook('validate', AUTH_MDP, 'admin'), |
| 42 | 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP, 'admin'), |
| 43 | 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'), |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | function handler_default(&$page) |
| 48 | { |
| 49 | $page->changeTpl('admin/index.tpl'); |
| 50 | $page->assign('xorg_title','Polytechnique.org - Administration'); |
| 51 | } |
| 52 | |
| 53 | function handler_postfix_delayed(&$page) |
| 54 | { |
| 55 | $page->changeTpl('admin/postfix_delayed.tpl'); |
| 56 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Retardés'); |
| 57 | |
| 58 | if (Env::has('del')) { |
| 59 | $crc = Env::v('crc'); |
| 60 | XDB::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc); |
| 61 | $page->trig($crc." verra tous ses mails supprimés !"); |
| 62 | } elseif (Env::has('ok')) { |
| 63 | $crc = Env::v('crc'); |
| 64 | XDB::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc); |
| 65 | $page->trig($crc." a le droit de passer !"); |
| 66 | } |
| 67 | |
| 68 | $sql = XDB::iterator( |
| 69 | "SELECT crc, nb, update_time, create_time, |
| 70 | FIND_IN_SET('del', release) AS del, |
| 71 | FIND_IN_SET('ok', release) AS ok |
| 72 | FROM postfix_mailseen |
| 73 | WHERE nb >= 30 |
| 74 | ORDER BY release != ''"); |
| 75 | |
| 76 | $page->assign_by_ref('mails', $sql); |
| 77 | } |
| 78 | |
| 79 | function handler_postfix_regexpsbounces(&$page, $new = null) { |
| 80 | $page->changeTpl('admin/emails_bounces_re.tpl'); |
| 81 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Regexps Bounces'); |
| 82 | $page->assign('new', $new); |
| 83 | |
| 84 | if (Post::has('submit')) { |
| 85 | foreach (Env::v('lvl') as $id=>$val) { |
| 86 | XDB::query( |
| 87 | "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})", |
| 88 | $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id] |
| 89 | ); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | $page->assign('bre', XDB::iterator("SELECT * FROM emails_bounces_re ORDER BY pos")); |
| 94 | } |
| 95 | |
| 96 | function handler_logger(&$page) { |
| 97 | require_once dirname(__FILE__).'/../classes/LoggerView.php'; |
| 98 | |
| 99 | if (!Env::has('logauth')) { |
| 100 | $_REQUEST['logauth'] = 'native'; |
| 101 | } |
| 102 | |
| 103 | $logview = new LoggerView; |
| 104 | $logview->run($page); |
| 105 | |
| 106 | $page->assign('xorg_title','Polytechnique.org - Administration - Logs des sessions'); |
| 107 | } |
| 108 | |
| 109 | function handler_user(&$page, $login = false) { |
| 110 | $page->changeTpl('admin/utilisateurs.tpl'); |
| 111 | $page->assign('xorg_title','Polytechnique.org - Administration - Edit/Su/Log'); |
| 112 | require_once("emails.inc.php"); |
| 113 | require_once("user.func.inc.php"); |
| 114 | |
| 115 | if (S::has('suid')) { |
| 116 | $page->kill("déjà en SUID !!!"); |
| 117 | } |
| 118 | |
| 119 | if (Env::has('user_id')) { |
| 120 | $login = get_user_login(Env::i('user_id')); |
| 121 | } elseif (Env::has('login')) { |
| 122 | $login = get_user_login(Env::v('login')); |
| 123 | } |
| 124 | |
| 125 | if(Env::has('logs_button') && $login) { |
| 126 | pl_redirect("admin/logger?login=$login&year=".date('Y')."&month=".date('m')); |
| 127 | } |
| 128 | |
| 129 | if (Env::has('ax_button') && $login) { |
| 130 | pl_redirect("admin/synchro_ax/$login"); |
| 131 | } |
| 132 | |
| 133 | if(Env::has('suid_button') && $login) { |
| 134 | $_SESSION['log']->log("suid_start", "login by ".S::v('forlife')); |
| 135 | $_SESSION['suid'] = $_SESSION; |
| 136 | $r = XDB::query("SELECT id FROM aliases WHERE alias={?}", $login); |
| 137 | if($uid = $r->fetchOneCell()) { |
| 138 | start_connexion($uid,true); |
| 139 | pl_redirect(""); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | if ($login) { |
| 144 | $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe |
| 145 | FROM auth_user_md5 AS u |
| 146 | INNER JOIN aliases AS a ON ( a.id = u.user_id AND a.alias={?} AND type!='homonyme' )", $login); |
| 147 | $mr = $r->fetchOneAssoc(); |
| 148 | |
| 149 | $redirect = new Redirect($mr['user_id']); |
| 150 | |
| 151 | // Check if there was a submission |
| 152 | foreach($_POST as $key => $val) { |
| 153 | switch ($key) { |
| 154 | case "add_fwd": |
| 155 | $email = trim(Env::v('email')); |
| 156 | if (!isvalid_email_redirection($email)) { |
| 157 | $page->trig("invalid email $email"); |
| 158 | } else { |
| 159 | $redirect->add_email($email); |
| 160 | $page->trig("Ajout de $email effectué"); |
| 161 | } |
| 162 | break; |
| 163 | |
| 164 | case "del_fwd": |
| 165 | if (!empty($val)) { |
| 166 | $redirect->delete_email($val); |
| 167 | } |
| 168 | break; |
| 169 | |
| 170 | case "del_alias": |
| 171 | if (!empty($val)) { |
| 172 | XDB::execute("DELETE FROM aliases WHERE id={?} AND alias={?} |
| 173 | AND type!='a_vie' AND type!='homonyme'", $mr['user_id'], $val); |
| 174 | fix_bestalias($mr['user_id']); |
| 175 | $page->trig($val." a été supprimé"); |
| 176 | } |
| 177 | break; |
| 178 | case "activate_fwd": |
| 179 | if (!empty($val)) { |
| 180 | $redirect->modify_one_email($val, true); |
| 181 | } |
| 182 | break; |
| 183 | case "deactivate_fwd": |
| 184 | if (!empty($val)) { |
| 185 | $redirect->modify_one_email($val, false); |
| 186 | } |
| 187 | break; |
| 188 | case "add_alias": |
| 189 | XDB::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')", |
| 190 | $mr['user_id'], Env::v('email')); |
| 191 | break; |
| 192 | |
| 193 | case "best": |
| 194 | // 'bestalias' is the first bit of the set : 1 |
| 195 | // 255 is the max for flags (8 sets max) |
| 196 | XDB::execute("UPDATE aliases SET flags= flags & (255 - 1) WHERE id={?}", $mr['user_id']); |
| 197 | XDB::execute("UPDATE aliases |
| 198 | SET flags= flags | 1 |
| 199 | WHERE id={?} AND alias={?}", $mr['user_id'], $val); |
| 200 | break; |
| 201 | |
| 202 | |
| 203 | // Editer un profil |
| 204 | case "u_edit": |
| 205 | require_once('secure_hash.inc.php'); |
| 206 | $pass_encrypted = Env::v('newpass_clair') != "********" ? hash_encrypt(Env::v('newpass_clair')) : Env::v('passw'); |
| 207 | $naiss = Env::v('naissanceN'); |
| 208 | $deces = Env::v('decesN'); |
| 209 | $perms = Env::v('permsN'); |
| 210 | $prenm = Env::v('prenomN'); |
| 211 | $nom = Env::v('nomN'); |
| 212 | $promo = Env::i('promoN'); |
| 213 | $sexe = Env::v('sexeN'); |
| 214 | $comm = Env::v('commentN'); |
| 215 | |
| 216 | $query = "UPDATE auth_user_md5 SET |
| 217 | naissance = '$naiss', |
| 218 | deces = '$deces', |
| 219 | password = '$pass_encrypted', |
| 220 | perms = '$perms', |
| 221 | prenom = '".addslashes($prenm)."', |
| 222 | nom = '".addslashes($nom)."', |
| 223 | flags = '$sexe', |
| 224 | promo = $promo, |
| 225 | comment = '".addslashes($comm)."' |
| 226 | WHERE user_id = '{$mr['user_id']}'"; |
| 227 | if (XDB::execute($query)) { |
| 228 | user_reindex($mr['user_id']); |
| 229 | |
| 230 | require_once("diogenes/diogenes.hermes.inc.php"); |
| 231 | $mailer = new HermesMailer(); |
| 232 | $mailer->setFrom("webmaster@polytechnique.org"); |
| 233 | $mailer->addTo("web@polytechnique.org"); |
| 234 | $mailer->setSubject("INTERVENTION de ".S::v('forlife')); |
| 235 | $mailer->setTxtBody(preg_replace("/[ \t]+/", ' ', $query)); |
| 236 | $mailer->send(); |
| 237 | |
| 238 | $page->trig("updaté correctement."); |
| 239 | } |
| 240 | if (Env::v('nomusageN') != $mr['nom_usage']) { |
| 241 | require_once('nomusage.inc.php'); |
| 242 | set_new_usage($mr['user_id'], Env::v('nomusageN'), make_username(Env::v('prenomN'), Env::v('nomusageN'))); |
| 243 | } |
| 244 | $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe |
| 245 | FROM auth_user_md5 AS u |
| 246 | INNER JOIN aliases AS a ON (u.user_id=a.id) |
| 247 | WHERE user_id = {?}", $mr['user_id']); |
| 248 | $mr = $r->fetchOneAssoc(); |
| 249 | break; |
| 250 | |
| 251 | // DELETE FROM auth_user_md5 |
| 252 | case "u_kill": |
| 253 | user_clear_all_subs($mr['user_id']); |
| 254 | $page->trig("'{$mr['user_id']}' a été désinscrit !"); |
| 255 | require_once("diogenes/diogenes.hermes.inc.php"); |
| 256 | $mailer = new HermesMailer(); |
| 257 | $mailer->setFrom("webmaster@polytechnique.org"); |
| 258 | $mailer->addTo("web@polytechnique.org"); |
| 259 | $mailer->setSubject("INTERVENTION de ".S::v('forlife')); |
| 260 | $mailer->setTxtBody("\nUtilisateur $login effacé"); |
| 261 | $mailer->send(); |
| 262 | break; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | $res = XDB::query("SELECT UNIX_TIMESTAMP(start), host |
| 267 | FROM logger.sessions |
| 268 | WHERE uid={?} AND suid=0 |
| 269 | ORDER BY start DESC |
| 270 | LIMIT 1", $mr['user_id']); |
| 271 | list($lastlogin,$host) = $res->fetchOneRow(); |
| 272 | $page->assign('lastlogin', $lastlogin); |
| 273 | $page->assign('host', $host); |
| 274 | |
| 275 | $page->assign('aliases', XDB::iterator( |
| 276 | "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire |
| 277 | FROM aliases |
| 278 | WHERE id = {?} AND type!='homonyme' |
| 279 | ORDER BY type!= 'a_vie'", $mr["user_id"])); |
| 280 | $page->assign('xorgmails', $xorgmails); |
| 281 | $page->assign('email_panne', $email_panne); |
| 282 | $page->assign('emails',$redirect->emails); |
| 283 | |
| 284 | $page->assign('mr',$mr); |
| 285 | } |
| 286 | } |
| 287 | function handler_homonyms(&$page, $op = 'list', $target = null) { |
| 288 | $page->changeTpl('admin/homonymes.tpl'); |
| 289 | $page->assign('xorg_title','Polytechnique.org - Administration - Homonymes'); |
| 290 | require_once("homonymes.inc.php"); |
| 291 | |
| 292 | if ($target) { |
| 293 | if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) { |
| 294 | $target=0; |
| 295 | } else { |
| 296 | $page->assign('nom',$nom); |
| 297 | $page->assign('prenom',$prenom); |
| 298 | $page->assign('forlife',$forlife); |
| 299 | $page->assign('loginbis',$loginbis); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | $page->assign('op',$op); |
| 304 | $page->assign('target',$target); |
| 305 | |
| 306 | // on a un $target valide, on prepare les mails |
| 307 | if ($target) { |
| 308 | |
| 309 | // on examine l'op a effectuer |
| 310 | switch ($op) { |
| 311 | case 'mail': |
| 312 | send_warning_homonyme($prenom, $nom, $forlife, $loginbis); |
| 313 | switch_bestalias($target, $loginbis); |
| 314 | $op = 'list'; |
| 315 | break; |
| 316 | case 'correct': |
| 317 | switch_bestalias($target, $loginbis); |
| 318 | XDB::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis); |
| 319 | XDB::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target); |
| 320 | send_robot_homonyme($prenom, $nom, $forlife, $loginbis); |
| 321 | $op = 'list'; |
| 322 | break; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | if ($op == 'list') { |
| 327 | $res = XDB::iterator( |
| 328 | "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife, |
| 329 | promo,prenom,nom, |
| 330 | IF(h.homonyme_id=s.id, a.expire, NULL) AS expire, |
| 331 | IF(h.homonyme_id=s.id, a.type, NULL) AS type |
| 332 | FROM aliases AS a |
| 333 | LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id) |
| 334 | INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie') |
| 335 | INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id) |
| 336 | WHERE a.type='homonyme' OR a.expire!='' |
| 337 | ORDER BY a.alias,promo"); |
| 338 | $hnymes = Array(); |
| 339 | while ($tab = $res->next()) { |
| 340 | $hnymes[$tab['homonyme']][] = $tab; |
| 341 | } |
| 342 | $page->assign_by_ref('hnymes',$hnymes); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | function handler_ax_xorg(&$page) { |
| 347 | $page->changeTpl('admin/ax-xorg.tpl'); |
| 348 | $page->assign('xorg_title','Polytechnique.org - Administration - AX/X.org'); |
| 349 | |
| 350 | // liste des différences |
| 351 | $res = XDB::query( |
| 352 | 'SELECT u.promo,u.nom AS nom,u.prenom AS prenom,ia.nom AS nomax,ia.prenom AS prenomax,u.matricule AS mat,ia.matricule_ax AS matax |
| 353 | FROM auth_user_md5 AS u |
| 354 | INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax |
| 355 | WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom) |
| 356 | AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro)) |
| 357 | OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1) |
| 358 | ORDER BY u.promo,u.nom,u.prenom'); |
| 359 | $page->assign('diffs', $res->fetchAllAssoc()); |
| 360 | |
| 361 | // gens à l'ax mais pas chez nous |
| 362 | $res = XDB::query( |
| 363 | 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom |
| 364 | FROM identification_ax as ia |
| 365 | LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax |
| 366 | WHERE u.nom IS NULL'); |
| 367 | $page->assign('mank', $res->fetchAllAssoc()); |
| 368 | |
| 369 | // gens chez nous et pas à l'ax |
| 370 | $res = XDB::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL'); |
| 371 | $page->assign('plus', $res->fetchAllAssoc()); |
| 372 | } |
| 373 | |
| 374 | function handler_deaths(&$page, $promo = 0, $validate = false) { |
| 375 | $page->changeTpl('admin/deces_promo.tpl'); |
| 376 | $page->assign('xorg_title','Polytechnique.org - Administration - Deces'); |
| 377 | |
| 378 | if (!$promo) |
| 379 | $promo = Env::i('promo'); |
| 380 | if (Env::has('sub10')) $promo -= 10; |
| 381 | if (Env::has('sub01')) $promo -= 1; |
| 382 | if (Env::has('add01')) $promo += 1; |
| 383 | if (Env::has('add10')) $promo += 10; |
| 384 | |
| 385 | $page->assign('promo',$promo); |
| 386 | |
| 387 | if ($validate) { |
| 388 | $new_deces = array(); |
| 389 | $res = XDB::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo); |
| 390 | while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) { |
| 391 | $val = Env::v($mat); |
| 392 | if($val == $deces || empty($val)) continue; |
| 393 | XDB::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat); |
| 394 | $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val"); |
| 395 | if($deces=='0000-00-00' or empty($deces)) { |
| 396 | require_once('notifs.inc.php'); |
| 397 | register_watch_op($uid, WATCH_DEATH, $val); |
| 398 | require_once('user.func.inc.php'); |
| 399 | user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email |
| 400 | } |
| 401 | } |
| 402 | $page->assign('new_deces',$new_deces); |
| 403 | } |
| 404 | |
| 405 | $res = XDB::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo); |
| 406 | $page->assign('decedes', $res); |
| 407 | } |
| 408 | |
| 409 | function handler_synchro_ax(&$page, $user = null, $action = null) { |
| 410 | $page->changeTpl('admin/synchro_ax.tpl'); |
| 411 | $page->assign('xorg_title','Polytechnique.org - Administration - Synchro AX'); |
| 412 | |
| 413 | require_once('synchro_ax.inc.php'); |
| 414 | |
| 415 | if (is_ax_key_missing()) { |
| 416 | $page->assign('no_private_key', true); |
| 417 | $page->run(); |
| 418 | } |
| 419 | |
| 420 | require_once('user.func.inc.php'); |
| 421 | |
| 422 | if ($user) |
| 423 | $login = get_user_forlife($user); |
| 424 | |
| 425 | if (Env::has('user')) { |
| 426 | $login = get_user_forlife(Env::v('user')); |
| 427 | if ($login === false) { |
| 428 | return; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | if (Env::has('mat')) { |
| 433 | $res = XDB::query( |
| 434 | "SELECT alias |
| 435 | FROM aliases AS a |
| 436 | INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie') |
| 437 | WHERE matricule={?}", Env::i('mat')); |
| 438 | $login = $res->fetchOneCell(); |
| 439 | } |
| 440 | |
| 441 | if ($login) { |
| 442 | if ($action == 'import') { |
| 443 | ax_synchronize($login, S::v('uid')); |
| 444 | } |
| 445 | // get details from user, but looking only info that can be seen by ax |
| 446 | $user = get_user_details($login, S::v('uid'), 'ax'); |
| 447 | $userax= get_user_ax($user['matricule_ax']); |
| 448 | require_once 'profil.func.inc.php'; |
| 449 | $diff = diff_user_details($userax, $user, 'ax'); |
| 450 | |
| 451 | $page->assign('x', $user); |
| 452 | $page->assign('diff', $diff); |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | function handler_validate(&$page) { |
| 457 | $page->changeTpl('admin/valider.tpl'); |
| 458 | $page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande'); |
| 459 | require_once("validations.inc.php"); |
| 460 | |
| 461 | if(Env::has('uid') && Env::has('type') && Env::has('stamp')) { |
| 462 | $req = Validate::get_request(Env::v('uid'), Env::v('type'), Env::v('stamp')); |
| 463 | if($req) { $req->handle_formu(); } |
| 464 | } |
| 465 | |
| 466 | $r = XDB::iterator('SHOW COLUMNS FROM requests_answers'); |
| 467 | while (($a = $r->next()) && $a['Field'] != 'category'); |
| 468 | $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1)))); |
| 469 | |
| 470 | $hidden = array(); |
| 471 | if (Post::has('hide')) { |
| 472 | $hide = array(); |
| 473 | foreach ($categories as $cat) |
| 474 | if (!Post::v($cat)) { |
| 475 | $hidden[$cat] = 1; |
| 476 | $hide[] = $cat; |
| 477 | } |
| 478 | setcookie('hide_requests', join(',',$hide), time()+(count($hide)?25920000:(-3600)), '/', '', 0); |
| 479 | } elseif (Env::has('hide_requests')) { |
| 480 | foreach (explode(',',Env::v('hide_requests')) as $hide_type) |
| 481 | $hidden[$hide_type] = true; |
| 482 | } |
| 483 | $page->assign('hide_requests', $hidden); |
| 484 | |
| 485 | $page->assign('vit', new ValidateIterator()); |
| 486 | } |
| 487 | function handler_validate_answers(&$page, $action = 'list', $id = null) { |
| 488 | require_once('../classes/PLTableEditor.php'); |
| 489 | $page->assign('xorg_title','Polytechnique.org - Administration - Réponses automatiques de validation'); |
| 490 | $page->assign('title', 'Gestion des réponses automatiques'); |
| 491 | $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id'); |
| 492 | $table_editor->describe('category','catégorie',true); |
| 493 | $table_editor->describe('title','titre',true); |
| 494 | $table_editor->describe('answer','texte',false); |
| 495 | $table_editor->apply($page, $action, $id); |
| 496 | } |
| 497 | function handler_skins(&$page, $action = 'list', $id = null) { |
| 498 | require_once('../classes/PLTableEditor.php'); |
| 499 | $page->assign('xorg_title','Polytechnique.org - Administration - Skins'); |
| 500 | $page->assign('title', 'Gestion des skins'); |
| 501 | $table_editor = new PLTableEditor('admin/skins','skins','id'); |
| 502 | $table_editor->describe('name','nom',true); |
| 503 | $table_editor->describe('skin_tpl','nom du template',true); |
| 504 | $table_editor->describe('auteur','auteur',false); |
| 505 | $table_editor->describe('comment','commentaire',true); |
| 506 | $table_editor->describe('date','date',false); |
| 507 | $table_editor->describe('ext','extension du screenshot',false); |
| 508 | $table_editor->apply($page, $action, $id); |
| 509 | } |
| 510 | function handler_postfix_blacklist(&$page, $action = 'list', $id = null) { |
| 511 | require_once('../classes/PLTableEditor.php'); |
| 512 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Blacklist'); |
| 513 | $page->assign('title', 'Blacklist de postfix'); |
| 514 | $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true); |
| 515 | $table_editor->describe('reject_text','Texte de rejet',true); |
| 516 | $table_editor->describe('email','email',true); |
| 517 | $table_editor->apply($page, $action, $id); |
| 518 | } |
| 519 | function handler_postfix_whitelist(&$page, $action = 'list', $id = null) { |
| 520 | require_once('../classes/PLTableEditor.php'); |
| 521 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Whitelist'); |
| 522 | $page->assign('title', 'Whitelist de postfix'); |
| 523 | $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true); |
| 524 | $table_editor->describe('email','email',true); |
| 525 | $table_editor->apply($page, $action, $id); |
| 526 | } |
| 527 | function handler_logger_actions(&$page, $action = 'list', $id = null) { |
| 528 | require_once('../classes/PLTableEditor.php'); |
| 529 | $page->assign('xorg_title','Polytechnique.org - Administration - Actions'); |
| 530 | $page->assign('title', 'Gestion des actions de logger'); |
| 531 | $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id'); |
| 532 | $table_editor->describe('text','intitulé',true); |
| 533 | $table_editor->describe('description','description',true); |
| 534 | $table_editor->apply($page, $action, $id); |
| 535 | } |
| 536 | function handler_downtime(&$page, $action = 'list', $id = null) { |
| 537 | require_once('../classes/PLTableEditor.php'); |
| 538 | $page->assign('xorg_title','Polytechnique.org - Administration - Coupures'); |
| 539 | $page->assign('title', 'Gestion des coupures'); |
| 540 | $table_editor = new PLTableEditor('admin/downtime','coupures','id'); |
| 541 | $table_editor->describe('debut','date',true); |
| 542 | $table_editor->describe('duree','durée',false); |
| 543 | $table_editor->describe('resume','résumé',true); |
| 544 | $table_editor->describe('services','services affectés',true); |
| 545 | $table_editor->describe('description','description',false); |
| 546 | $table_editor->apply($page, $action, $id); |
| 547 | } |
| 548 | function handler_wiki(&$page, $action='list') { |
| 549 | require_once 'wiki.inc.php'; |
| 550 | |
| 551 | // update wiki perms |
| 552 | if ($action == 'update') { |
| 553 | $perms_read = Post::v('read'); |
| 554 | $perms_edot = Post::v('edit'); |
| 555 | if ($perms_read || $perms_edit) { |
| 556 | foreach ($_POST as $wiki_page => $val) if ($val == 'on') { |
| 557 | $wiki_page = str_replace('_', '/', $wiki_page); |
| 558 | if (!$perms_read || !$perms_edit) |
| 559 | list($perms0, $perms1) = wiki_get_perms($wiki_page); |
| 560 | if ($perms_read) |
| 561 | $perms0 = $perms_read; |
| 562 | if ($perms_edit) |
| 563 | $perms1 = $perms_edit; |
| 564 | wiki_set_perms($wiki_page, $perms0, $perms1); |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | $perms = wiki_perms_options(); |
| 570 | |
| 571 | // list wiki pages and their perms |
| 572 | $wiki_pages = array(); |
| 573 | $dir = wiki_work_dir(); |
| 574 | if (is_dir($dir)) { |
| 575 | if ($dh = opendir($dir)) { |
| 576 | while (($file = readdir($dh)) !== false) if (substr($file,0,1) >= 'A' && substr($file,0,1) <= 'Z') { |
| 577 | list($read,$edit) = wiki_get_perms($file); |
| 578 | $wiki_pages[$file] = array('read' => $perms[$read], 'edit' => $perms[$edit]); |
| 579 | } |
| 580 | closedir($dh); |
| 581 | } |
| 582 | } |
| 583 | ksort($wiki_pages); |
| 584 | |
| 585 | $page->changeTpl('admin/wiki.tpl'); |
| 586 | $page->assign('wiki_pages', $wiki_pages); |
| 587 | $page->assign('perms_opts', $perms); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | ?> |