| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2007 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 | 'phpinfo' => $this->make_hook('phpinfo', AUTH_MDP, 'admin'), |
| 28 | 'admin' => $this->make_hook('default', AUTH_MDP, 'admin'), |
| 29 | 'admin/ax-xorg' => $this->make_hook('ax_xorg', AUTH_MDP, 'admin'), |
| 30 | 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP, 'admin'), |
| 31 | 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP, 'admin'), |
| 32 | 'admin/homonyms' => $this->make_hook('homonyms', AUTH_MDP, 'admin'), |
| 33 | 'admin/logger' => $this->make_hook('logger', AUTH_MDP, 'admin'), |
| 34 | 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_MDP, 'admin'), |
| 35 | 'admin/postfix/blacklist' => $this->make_hook('postfix_blacklist', AUTH_MDP, 'admin'), |
| 36 | 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP, 'admin'), |
| 37 | 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP, 'admin'), |
| 38 | 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP, 'admin'), |
| 39 | 'admin/mx/broken' => $this->make_hook('mx_broken', AUTH_MDP, 'admin'), |
| 40 | 'admin/skins' => $this->make_hook('skins', AUTH_MDP, 'admin'), |
| 41 | 'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP, 'admin'), |
| 42 | 'admin/user' => $this->make_hook('user', AUTH_MDP, 'admin'), |
| 43 | 'admin/promo' => $this->make_hook('promo', AUTH_MDP, 'admin'), |
| 44 | 'admin/validate' => $this->make_hook('validate', AUTH_MDP, 'admin'), |
| 45 | 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP, 'admin'), |
| 46 | 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'), |
| 47 | 'admin/ipwatch' => $this->make_hook('ipwatch', AUTH_MDP, 'admin'), |
| 48 | 'admin/icons' => $this->make_hook('icons', AUTH_MDP, 'admin'), |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | function handler_phpinfo(&$page) |
| 53 | { |
| 54 | phpinfo(); |
| 55 | exit; |
| 56 | } |
| 57 | |
| 58 | function handler_default(&$page) |
| 59 | { |
| 60 | $page->changeTpl('admin/index.tpl'); |
| 61 | $page->assign('xorg_title','Polytechnique.org - Administration'); |
| 62 | } |
| 63 | |
| 64 | function handler_postfix_delayed(&$page) |
| 65 | { |
| 66 | $page->changeTpl('admin/postfix_delayed.tpl'); |
| 67 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Retardés'); |
| 68 | |
| 69 | if (Env::has('del')) { |
| 70 | $crc = Env::v('crc'); |
| 71 | XDB::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc); |
| 72 | $page->trig($crc." verra tous ses mails supprimés !"); |
| 73 | } elseif (Env::has('ok')) { |
| 74 | $crc = Env::v('crc'); |
| 75 | XDB::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc); |
| 76 | $page->trig($crc." a le droit de passer !"); |
| 77 | } |
| 78 | |
| 79 | $sql = XDB::iterator( |
| 80 | "SELECT crc, nb, update_time, create_time, |
| 81 | FIND_IN_SET('del', release) AS del, |
| 82 | FIND_IN_SET('ok', release) AS ok |
| 83 | FROM postfix_mailseen |
| 84 | WHERE nb >= 30 |
| 85 | ORDER BY release != ''"); |
| 86 | |
| 87 | $page->assign_by_ref('mails', $sql); |
| 88 | } |
| 89 | |
| 90 | function handler_postfix_regexpsbounces(&$page, $new = null) { |
| 91 | $page->changeTpl('admin/emails_bounces_re.tpl'); |
| 92 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Regexps Bounces'); |
| 93 | $page->assign('new', $new); |
| 94 | |
| 95 | if (Post::has('submit')) { |
| 96 | foreach (Env::v('lvl') as $id=>$val) { |
| 97 | XDB::query( |
| 98 | "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})", |
| 99 | $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id] |
| 100 | ); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | $page->assign('bre', XDB::iterator("SELECT * FROM emails_bounces_re ORDER BY pos")); |
| 105 | } |
| 106 | |
| 107 | // {{{ logger view |
| 108 | |
| 109 | /** Retrieves the available days for a given year and month. |
| 110 | * Obtain a list of days of the given month in the given year |
| 111 | * that are within the range of dates that we have log entries for. |
| 112 | * |
| 113 | * @param integer year |
| 114 | * @param integer month |
| 115 | * @return array days in that month we have log entries covering. |
| 116 | * @private |
| 117 | */ |
| 118 | function _getDays($year, $month) |
| 119 | { |
| 120 | // give a 'no filter' option |
| 121 | $months[0] = "----"; |
| 122 | |
| 123 | if ($year && $month) { |
| 124 | $day_max = Array(-1, 31, checkdate(2, 29, $year) ? 29 : 28 , 31, |
| 125 | 30, 31, 30, 31, 31, 30, 31, 30, 31); |
| 126 | $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)), |
| 127 | MONTH(MAX(start)), MONTH(MIN(start)), |
| 128 | DAYOFMONTH(MAX(start)), |
| 129 | DAYOFMONTH(MIN(start)) |
| 130 | FROM logger.sessions"); |
| 131 | list($ymax, $ymin, $mmax, $mmin, $dmax, $dmin) = $res->fetchOneRow(); |
| 132 | |
| 133 | if (($year < $ymin) || ($year == $ymin && $month < $mmin)) { |
| 134 | return array(); |
| 135 | } |
| 136 | |
| 137 | if (($year > $ymax) || ($year == $ymax && $month > $mmax)) { |
| 138 | return array(); |
| 139 | } |
| 140 | |
| 141 | $min = ($year==$ymin && $month==$mmin) ? intval($dmin) : 1; |
| 142 | $max = ($year==$ymax && $month==$mmax) ? intval($dmax) : $day_max[$month]; |
| 143 | |
| 144 | for($i = $min; $i<=$max; $i++) { |
| 145 | $days[$i] = $i; |
| 146 | } |
| 147 | } |
| 148 | return $days; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | /** Retrieves the available months for a given year. |
| 153 | * Obtains a list of month numbers that are within the timeframe that |
| 154 | * we have log entries for. |
| 155 | * |
| 156 | * @param integer year |
| 157 | * @return array List of month numbers we have log info for. |
| 158 | * @private |
| 159 | */ |
| 160 | function _getMonths($year) |
| 161 | { |
| 162 | // give a 'no filter' option |
| 163 | $months[0] = "----"; |
| 164 | |
| 165 | if ($year) { |
| 166 | $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)), |
| 167 | MONTH(MAX(start)), MONTH(MIN(start)) |
| 168 | FROM logger.sessions"); |
| 169 | list($ymax, $ymin, $mmax, $mmin) = $res->fetchOneRow(); |
| 170 | |
| 171 | if (($year < $ymin) || ($year > $ymax)) { |
| 172 | return array(); |
| 173 | } |
| 174 | |
| 175 | $min = $year == $ymin ? intval($mmin) : 1; |
| 176 | $max = $year == $ymax ? intval($mmax) : 12; |
| 177 | |
| 178 | for($i = $min; $i<=$max; $i++) { |
| 179 | $months[$i] = $i; |
| 180 | } |
| 181 | } |
| 182 | return $months; |
| 183 | } |
| 184 | |
| 185 | |
| 186 | /** Retrieves the available years. |
| 187 | * Obtains a list of years that we have log entries covering. |
| 188 | * |
| 189 | * @return array years we have log entries for. |
| 190 | * @private |
| 191 | */ |
| 192 | function _getYears() |
| 193 | { |
| 194 | // give a 'no filter' option |
| 195 | $years[0] = "----"; |
| 196 | |
| 197 | // retrieve available years |
| 198 | $res = XDB::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM logger.sessions"); |
| 199 | list($max, $min) = $res->fetchOneRow(); |
| 200 | |
| 201 | for($i = intval($min); $i<=$max; $i++) { |
| 202 | $years[$i] = $i; |
| 203 | } |
| 204 | return $years; |
| 205 | } |
| 206 | |
| 207 | |
| 208 | /** Make a where clause to get a user's sessions. |
| 209 | * Prepare the where clause request that will retrieve the sessions. |
| 210 | * |
| 211 | * @param $year INTEGER Only get log entries made during the given year. |
| 212 | * @param $month INTEGER Only get log entries made during the given month. |
| 213 | * @param $day INTEGER Only get log entries made during the given day. |
| 214 | * @param $uid INTEGER Only get log entries referring to the given user ID. |
| 215 | * |
| 216 | * @return STRING the WHERE clause of a query, including the 'WHERE' keyword |
| 217 | * @private |
| 218 | */ |
| 219 | function _makeWhere($year, $month, $day, $uid) |
| 220 | { |
| 221 | // start constructing the "where" clause |
| 222 | $where = array(); |
| 223 | |
| 224 | if ($uid) |
| 225 | array_push($where, "uid='$uid'"); |
| 226 | |
| 227 | // we were given at least a year |
| 228 | if ($year) { |
| 229 | if ($day) { |
| 230 | $dmin = mktime(0, 0, 0, $month, $day, $year); |
| 231 | $dmax = mktime(0, 0, 0, $month, $day+1, $year); |
| 232 | } elseif ($month) { |
| 233 | $dmin = mktime(0, 0, 0, $month, 1, $year); |
| 234 | $dmax = mktime(0, 0, 0, $month+1, 1, $year); |
| 235 | } else { |
| 236 | $dmin = mktime(0, 0, 0, 1, 1, $year); |
| 237 | $dmax = mktime(0, 0, 0, 1, 1, $year+1); |
| 238 | } |
| 239 | $where[] = "start >= " . date("Ymd000000", $dmin); |
| 240 | $where[] = "start < " . date("Ymd000000", $dmax); |
| 241 | } |
| 242 | |
| 243 | if (!empty($where)) { |
| 244 | return ' WHERE ' . implode($where, " AND "); |
| 245 | } else { |
| 246 | return ''; |
| 247 | } |
| 248 | // WE know it's totally reversed, so better use array_reverse than a SORT BY start DESC |
| 249 | } |
| 250 | |
| 251 | // }}} |
| 252 | |
| 253 | function handler_logger(&$page, $action = null, $arg = null) { |
| 254 | if ($action == 'session') { |
| 255 | |
| 256 | // we are viewing a session |
| 257 | $res = XDB::query("SELECT ls.*, a.alias AS username, sa.alias AS suer |
| 258 | FROM logger.sessions AS ls |
| 259 | LEFT JOIN aliases AS a ON (a.id = ls.uid AND a.type='a_vie') |
| 260 | LEFT JOIN aliases AS sa ON (sa.id = ls.suid AND sa.type='a_vie') |
| 261 | WHERE ls.id = {?}", $arg); |
| 262 | |
| 263 | $page->assign('session', $a = $res->fetchOneAssoc()); |
| 264 | |
| 265 | $res = XDB::iterator('SELECT a.text, e.data, e.stamp |
| 266 | FROM logger.events AS e |
| 267 | LEFT JOIN logger.actions AS a ON e.action=a.id |
| 268 | WHERE e.session={?}', $arg); |
| 269 | while ($myarr = $res->next()) { |
| 270 | $page->append('events', $myarr); |
| 271 | } |
| 272 | |
| 273 | } else { |
| 274 | $loguser = $action == 'user' ? $arg : Env::v('loguser'); |
| 275 | |
| 276 | $res = XDB::query('SELECT id FROM aliases WHERE alias={?}', |
| 277 | $loguser); |
| 278 | $loguid = $res->fetchOneCell(); |
| 279 | |
| 280 | if ($loguid) { |
| 281 | $year = Env::i('year'); |
| 282 | $month = Env::i('month'); |
| 283 | $day = Env::i('day'); |
| 284 | } else { |
| 285 | $year = Env::i('year', intval(date('Y'))); |
| 286 | $month = Env::i('month', intval(date('m'))); |
| 287 | $day = Env::i('day', intval(date('d'))); |
| 288 | } |
| 289 | |
| 290 | if (!$year) |
| 291 | $month = 0; |
| 292 | if (!$month) |
| 293 | $day = 0; |
| 294 | |
| 295 | // smarty assignments |
| 296 | // retrieve available years |
| 297 | $page->assign('years', $this->_getYears()); |
| 298 | $page->assign('year', $year); |
| 299 | |
| 300 | // retrieve available months for the current year |
| 301 | $page->assign('months', $this->_getMonths($year)); |
| 302 | $page->assign('month', $month); |
| 303 | |
| 304 | // retrieve available days for the current year and month |
| 305 | $page->assign('days', $this->_getDays($year, $month)); |
| 306 | $page->assign('day', $day); |
| 307 | |
| 308 | $page->assign('loguser', $loguser); |
| 309 | // smarty assignments |
| 310 | |
| 311 | if ($loguid || $year) { |
| 312 | |
| 313 | // get the requested sessions |
| 314 | $where = $this->_makeWhere($year, $month, $day, $loguid); |
| 315 | $select = "SELECT s.id, s.start, s.uid, |
| 316 | a.alias as username |
| 317 | FROM logger.sessions AS s |
| 318 | LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type='a_vie') |
| 319 | $where |
| 320 | ORDER BY start DESC"; |
| 321 | $res = XDB::iterator($select); |
| 322 | |
| 323 | $sessions = array(); |
| 324 | while ($mysess = $res->next()) { |
| 325 | $mysess['events'] = array(); |
| 326 | $sessions[$mysess['id']] = $mysess; |
| 327 | } |
| 328 | array_reverse($sessions); |
| 329 | |
| 330 | // attach events |
| 331 | $sql = "SELECT s.id, a.text |
| 332 | FROM logger.sessions AS s |
| 333 | LEFT JOIN logger.events AS e ON(e.session=s.id) |
| 334 | INNER JOIN logger.actions AS a ON(a.id=e.action) |
| 335 | $where"; |
| 336 | |
| 337 | $res = XDB::iterator($sql); |
| 338 | while ($event = $res->next()) { |
| 339 | array_push($sessions[$event['id']]['events'], $event['text']); |
| 340 | } |
| 341 | $page->assign_by_ref('sessions', $sessions); |
| 342 | } else { |
| 343 | $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur"); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | $page->changeTpl('admin/logger-view.tpl'); |
| 348 | |
| 349 | $page->assign('xorg_title','Polytechnique.org - Administration - Logs des sessions'); |
| 350 | } |
| 351 | |
| 352 | function handler_user(&$page, $login = false) |
| 353 | { |
| 354 | $page->changeTpl('admin/utilisateurs.tpl'); |
| 355 | $page->assign('xorg_title','Polytechnique.org - Administration - Edit/Su/Log'); |
| 356 | require_once("emails.inc.php"); |
| 357 | require_once("user.func.inc.php"); |
| 358 | |
| 359 | if (S::has('suid')) { |
| 360 | $page->kill("déjà en SUID !!!"); |
| 361 | } |
| 362 | |
| 363 | if (Env::has('user_id')) { |
| 364 | $login = get_user_forlife(Env::i('user_id')); |
| 365 | if (empty($login)) { |
| 366 | $login = Env::i('user_id'); |
| 367 | } |
| 368 | } elseif (Env::has('login')) { |
| 369 | $login = get_user_forlife(Env::v('login')); |
| 370 | } |
| 371 | |
| 372 | if(Env::has('logs_button') && $login) { |
| 373 | pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m')); |
| 374 | } |
| 375 | |
| 376 | if (Env::has('ax_button') && $login) { |
| 377 | pl_redirect("admin/synchro_ax/$login"); |
| 378 | } |
| 379 | |
| 380 | if(Env::has('suid_button') && $login) { |
| 381 | $_SESSION['log']->log("suid_start", "login by ".S::v('forlife')); |
| 382 | $_SESSION['suid'] = $_SESSION; |
| 383 | $r = XDB::query("SELECT id FROM aliases WHERE alias={?}", $login); |
| 384 | if($uid = $r->fetchOneCell()) { |
| 385 | start_connexion($uid,true); |
| 386 | pl_redirect(""); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | if ($login) { |
| 391 | if (is_numeric($login)) { |
| 392 | $r = XDB::query("SELECT *, a.alias AS forlife, |
| 393 | FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe, |
| 394 | (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err |
| 395 | FROM auth_user_md5 AS u |
| 396 | LEFT JOIN aliases AS a ON (a.id = u.user_id AND type= 'a_vie') |
| 397 | WHERE u.user_id = {?}", $login); |
| 398 | } else { |
| 399 | $r = XDB::query("SELECT *, a.alias AS forlife, |
| 400 | FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe, |
| 401 | (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err |
| 402 | FROM auth_user_md5 AS u |
| 403 | INNER JOIN aliases AS a ON ( a.id = u.user_id AND a.alias={?} AND type!='homonyme' )", $login); |
| 404 | } |
| 405 | $mr = $r->fetchOneAssoc(); |
| 406 | |
| 407 | if (!is_numeric($login)) { //user has a forlife |
| 408 | $redirect = new Redirect($mr['user_id']); |
| 409 | } |
| 410 | |
| 411 | // Check if there was a submission |
| 412 | foreach($_POST as $key => $val) { |
| 413 | switch ($key) { |
| 414 | case "add_fwd": |
| 415 | $email = trim(Env::v('email')); |
| 416 | if (!isvalid_email_redirection($email)) { |
| 417 | $page->trig("invalid email $email"); |
| 418 | } else { |
| 419 | $redirect->add_email($email); |
| 420 | $page->trig("Ajout de $email effectué"); |
| 421 | } |
| 422 | break; |
| 423 | |
| 424 | case "del_fwd": |
| 425 | if (!empty($val)) { |
| 426 | $redirect->delete_email($val); |
| 427 | } |
| 428 | break; |
| 429 | |
| 430 | case "del_alias": |
| 431 | if (!empty($val)) { |
| 432 | XDB::execute("DELETE FROM aliases |
| 433 | WHERE id={?} AND alias={?} |
| 434 | AND type!='a_vie' AND type!='homonyme'", $mr['user_id'], $val); |
| 435 | XDB::execute("UPDATE emails |
| 436 | SET rewrite = '' |
| 437 | WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')", |
| 438 | $mr['user_id'], $val); |
| 439 | fix_bestalias($mr['user_id']); |
| 440 | $page->trig($val." a été supprimé"); |
| 441 | } |
| 442 | break; |
| 443 | case "activate_fwd": |
| 444 | if (!empty($val)) { |
| 445 | $redirect->modify_one_email($val, true); |
| 446 | } |
| 447 | break; |
| 448 | case "deactivate_fwd": |
| 449 | if (!empty($val)) { |
| 450 | $redirect->modify_one_email($val, false); |
| 451 | } |
| 452 | break; |
| 453 | case "disable_fwd": |
| 454 | $redirect->disable(); |
| 455 | break; |
| 456 | case "enable_fwd": |
| 457 | $redirect->enable(); |
| 458 | break; |
| 459 | case "clean_fwd": |
| 460 | if (!empty($val)) { |
| 461 | $redirect->cleanErrors($val); |
| 462 | } |
| 463 | break; |
| 464 | case "add_alias": |
| 465 | XDB::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')", |
| 466 | $mr['user_id'], Env::v('email')); |
| 467 | break; |
| 468 | |
| 469 | case "best": |
| 470 | // 'bestalias' is the first bit of the set : 1 |
| 471 | // 255 is the max for flags (8 sets max) |
| 472 | XDB::execute("UPDATE aliases SET flags= flags & (255 - 1) WHERE id={?}", $mr['user_id']); |
| 473 | XDB::execute("UPDATE aliases |
| 474 | SET flags= flags | 1 |
| 475 | WHERE id={?} AND alias={?}", $mr['user_id'], $val); |
| 476 | break; |
| 477 | |
| 478 | |
| 479 | // Editer un profil |
| 480 | case "u_edit": |
| 481 | require_once('secure_hash.inc.php'); |
| 482 | $pass_encrypted = Env::v('newpass_clair') != "********" ? hash_encrypt(Env::v('newpass_clair')) : Env::v('passw'); |
| 483 | $naiss = Env::v('naissanceN'); |
| 484 | $deces = Env::v('decesN'); |
| 485 | $perms = Env::v('permsN'); |
| 486 | $prenm = Env::v('prenomN'); |
| 487 | $nom = Env::v('nomN'); |
| 488 | $promo = Env::i('promoN'); |
| 489 | $sexe = Env::v('sexeN'); |
| 490 | $comm = trim(Env::v('commentN')); |
| 491 | $watch = Env::v('watchN'); |
| 492 | $flags = ''; |
| 493 | if ($sexe) { |
| 494 | $flags = 'femme'; |
| 495 | } |
| 496 | if ($watch) { |
| 497 | if ($flags) { |
| 498 | $flags .= ','; |
| 499 | } |
| 500 | $flags .= 'watch'; |
| 501 | } |
| 502 | |
| 503 | if ($watch && !$comm) { |
| 504 | $page->trig("Il est nécessaire de mettre un commentaire pour surveiller un compte"); |
| 505 | break; |
| 506 | } |
| 507 | |
| 508 | $query = "UPDATE auth_user_md5 SET |
| 509 | naissance = '$naiss', |
| 510 | deces = '$deces', |
| 511 | password = '$pass_encrypted', |
| 512 | perms = '$perms', |
| 513 | prenom = '".addslashes($prenm)."', |
| 514 | nom = '".addslashes($nom)."', |
| 515 | flags = '$flags', |
| 516 | promo = $promo, |
| 517 | comment = '".addslashes($comm)."' |
| 518 | WHERE user_id = '{$mr['user_id']}'"; |
| 519 | if (XDB::execute($query)) { |
| 520 | user_reindex($mr['user_id']); |
| 521 | |
| 522 | $mailer = new PlMailer("admin/mail_intervention.tpl"); |
| 523 | $mailer->assign("user", S::v('forlife')); |
| 524 | $mailer->assign("query", $query); |
| 525 | $mailer->send(); |
| 526 | |
| 527 | $page->trig("updaté correctement."); |
| 528 | } |
| 529 | if (Env::v('nomusageN') != $mr['nom_usage']) { |
| 530 | require_once "xorg.misc.inc.php"; |
| 531 | set_new_usage($mr['user_id'], Env::v('nomusageN'), make_username(Env::v('prenomN'), Env::v('nomusageN'))); |
| 532 | } |
| 533 | if (Env::v('decesN') != $mr['deces']) { |
| 534 | user_clear_all_subs($mr['user_id'], false); |
| 535 | } |
| 536 | $r = XDB::query("SELECT *, a.alias AS forlife, |
| 537 | FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe |
| 538 | FROM auth_user_md5 AS u |
| 539 | LEFT JOIN aliases AS a ON (a.id = u.user_id AND type= 'a_vie') |
| 540 | WHERE u.user_id = {?}", $mr['user_id']); |
| 541 | $mr = $r->fetchOneAssoc(); |
| 542 | break; |
| 543 | |
| 544 | // DELETE FROM auth_user_md5 |
| 545 | case "u_kill": |
| 546 | user_clear_all_subs($mr['user_id']); |
| 547 | $page->trig("'{$mr['user_id']}' a été désinscrit !"); |
| 548 | $mailer = new PlMailer("admin/mail_intervention.tpl"); |
| 549 | $mailer->assign("user", S::v('forlife')); |
| 550 | $mailer->assign("query", "\nUtilisateur $login désinscrit"); |
| 551 | $mailer->send(); |
| 552 | break; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | $res = XDB::query("SELECT start, host |
| 557 | FROM logger.sessions |
| 558 | WHERE uid={?} AND suid=0 |
| 559 | ORDER BY start DESC |
| 560 | LIMIT 1", $mr['user_id']); |
| 561 | list($lastlogin,$host) = $res->fetchOneRow(); |
| 562 | $page->assign('lastlogin', $lastlogin); |
| 563 | $page->assign('host', $host); |
| 564 | |
| 565 | $res = XDB::iterator("SELECT alias |
| 566 | FROM virtual |
| 567 | INNER JOIN virtual_redirect USING(vid) |
| 568 | WHERE type = 'user' AND redirect LIKE '" . $login . "@%'"); |
| 569 | $page->assign('virtuals', $res); |
| 570 | |
| 571 | $page->assign('aliases', XDB::iterator( |
| 572 | "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire |
| 573 | FROM aliases |
| 574 | WHERE id = {?} AND type!='homonyme' |
| 575 | ORDER BY type!= 'a_vie'", $mr["user_id"])); |
| 576 | if ($mr['perms'] != 'pending') { |
| 577 | $page->assign('emails',$redirect->emails); |
| 578 | } |
| 579 | |
| 580 | $page->assign('mr',$mr); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | function getMatricule($line, $key) |
| 585 | { |
| 586 | $mat = $line['matricule']; |
| 587 | $year = intval(substr($mat, 0, 3)); |
| 588 | $rang = intval(substr($mat, 3, 3)); |
| 589 | if ($year > 200) { $year /= 10; }; |
| 590 | if ($year < 96) { |
| 591 | return null; |
| 592 | } else { |
| 593 | return sprintf('%04u%04u', 1900+$year, $rang); |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | function handler_promo(&$page, $action = null, $promo = null) |
| 598 | { |
| 599 | if (Env::has('promo')) { |
| 600 | if(Env::i('promo') > 1900 && Env::i('promo') < 2050) { |
| 601 | $action = Env::v('valid_promo') == 'Ajouter des membres' ? 'add' : 'ax'; |
| 602 | pl_redirect('admin/promo/' . $action . '/' . Env::i('promo')); |
| 603 | } else { |
| 604 | $page->trig('Promo non valide'); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | $page->changeTpl('admin/promo.tpl'); |
| 609 | if ($promo > 1900 && $promo < 2050 && ($action == 'add' || $action == 'ax')) { |
| 610 | $page->assign('promo', $promo); |
| 611 | } else { |
| 612 | return; |
| 613 | } |
| 614 | |
| 615 | $importer = new CSVImporter('auth_user_md5', 'matricule'); |
| 616 | $importer->registerFunction('matricule', 'matricle Ecole vers X.org', array($this, 'getMatricule')); |
| 617 | switch ($action) { |
| 618 | case 'add': |
| 619 | $fields = array('nom', 'nom_ini', 'prenom', |
| 620 | 'prenom_ini', 'promo', 'promo_sortie', 'flags', |
| 621 | 'matricule', 'matricule_ax', 'perms'); |
| 622 | $importer->forceValue('promo', $promo); |
| 623 | $importer->forceValue('promo_sortie', $promo + 3); |
| 624 | break; |
| 625 | case 'ax': |
| 626 | $fields = array('matricule', 'matricule_ax'); |
| 627 | break; |
| 628 | } |
| 629 | $importer->apply($page, "admin/promo/$action/$promo", $fields); |
| 630 | } |
| 631 | |
| 632 | function handler_homonyms(&$page, $op = 'list', $target = null) { |
| 633 | $page->changeTpl('admin/homonymes.tpl'); |
| 634 | $page->assign('xorg_title','Polytechnique.org - Administration - Homonymes'); |
| 635 | require_once("homonymes.inc.php"); |
| 636 | |
| 637 | if ($target) { |
| 638 | if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) { |
| 639 | $target=0; |
| 640 | } else { |
| 641 | $page->assign('nom',$nom); |
| 642 | $page->assign('prenom',$prenom); |
| 643 | $page->assign('forlife',$forlife); |
| 644 | $page->assign('loginbis',$loginbis); |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | $page->assign('op',$op); |
| 649 | $page->assign('target',$target); |
| 650 | |
| 651 | // on a un $target valide, on prepare les mails |
| 652 | if ($target) { |
| 653 | |
| 654 | // on examine l'op a effectuer |
| 655 | switch ($op) { |
| 656 | case 'mail': |
| 657 | send_warning_homonyme($prenom, $nom, $forlife, $loginbis); |
| 658 | switch_bestalias($target, $loginbis); |
| 659 | $op = 'list'; |
| 660 | break; |
| 661 | case 'correct': |
| 662 | switch_bestalias($target, $loginbis); |
| 663 | XDB::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis); |
| 664 | XDB::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target); |
| 665 | send_robot_homonyme($prenom, $nom, $forlife, $loginbis); |
| 666 | $op = 'list'; |
| 667 | break; |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | if ($op == 'list') { |
| 672 | $res = XDB::iterator( |
| 673 | "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife, |
| 674 | promo,prenom,nom, |
| 675 | IF(h.homonyme_id=s.id, a.expire, NULL) AS expire, |
| 676 | IF(h.homonyme_id=s.id, a.type, NULL) AS type |
| 677 | FROM aliases AS a |
| 678 | LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id) |
| 679 | INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie') |
| 680 | INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id) |
| 681 | WHERE a.type='homonyme' OR a.expire!='' |
| 682 | ORDER BY a.alias,promo"); |
| 683 | $hnymes = Array(); |
| 684 | while ($tab = $res->next()) { |
| 685 | $hnymes[$tab['homonyme']][] = $tab; |
| 686 | } |
| 687 | $page->assign_by_ref('hnymes',$hnymes); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | function handler_ax_xorg(&$page) { |
| 692 | $page->changeTpl('admin/ax-xorg.tpl'); |
| 693 | $page->assign('xorg_title','Polytechnique.org - Administration - AX/X.org'); |
| 694 | |
| 695 | // liste des différences |
| 696 | $res = XDB::query( |
| 697 | '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 |
| 698 | FROM auth_user_md5 AS u |
| 699 | INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax |
| 700 | WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom) |
| 701 | AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro)) |
| 702 | OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1) |
| 703 | ORDER BY u.promo,u.nom,u.prenom'); |
| 704 | $page->assign('diffs', $res->fetchAllAssoc()); |
| 705 | |
| 706 | // gens à l'ax mais pas chez nous |
| 707 | $res = XDB::query( |
| 708 | 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom |
| 709 | FROM identification_ax as ia |
| 710 | LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax |
| 711 | WHERE u.nom IS NULL'); |
| 712 | $page->assign('mank', $res->fetchAllAssoc()); |
| 713 | |
| 714 | // gens chez nous et pas à l'ax |
| 715 | $res = XDB::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL'); |
| 716 | $page->assign('plus', $res->fetchAllAssoc()); |
| 717 | } |
| 718 | |
| 719 | function handler_deaths(&$page, $promo = 0, $validate = false) { |
| 720 | $page->changeTpl('admin/deces_promo.tpl'); |
| 721 | $page->assign('xorg_title','Polytechnique.org - Administration - Deces'); |
| 722 | |
| 723 | if (!$promo) |
| 724 | $promo = Env::i('promo'); |
| 725 | if (Env::has('sub10')) $promo -= 10; |
| 726 | if (Env::has('sub01')) $promo -= 1; |
| 727 | if (Env::has('add01')) $promo += 1; |
| 728 | if (Env::has('add10')) $promo += 10; |
| 729 | |
| 730 | $page->assign('promo',$promo); |
| 731 | |
| 732 | if ($validate) { |
| 733 | $new_deces = array(); |
| 734 | $res = XDB::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo); |
| 735 | while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) { |
| 736 | $val = Env::v($mat); |
| 737 | if($val == $deces || empty($val)) continue; |
| 738 | XDB::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat); |
| 739 | $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val"); |
| 740 | if($deces=='0000-00-00' or empty($deces)) { |
| 741 | require_once('notifs.inc.php'); |
| 742 | register_watch_op($uid, WATCH_DEATH, $val); |
| 743 | require_once('user.func.inc.php'); |
| 744 | user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email |
| 745 | } |
| 746 | } |
| 747 | $page->assign('new_deces',$new_deces); |
| 748 | } |
| 749 | |
| 750 | $res = XDB::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo); |
| 751 | $page->assign('decedes', $res); |
| 752 | } |
| 753 | |
| 754 | function handler_synchro_ax(&$page, $user = null, $action = null) { |
| 755 | $page->changeTpl('admin/synchro_ax.tpl'); |
| 756 | $page->assign('xorg_title','Polytechnique.org - Administration - Synchro AX'); |
| 757 | |
| 758 | require_once('synchro_ax.inc.php'); |
| 759 | |
| 760 | if (is_ax_key_missing()) { |
| 761 | $page->assign('no_private_key', true); |
| 762 | $page->run(); |
| 763 | } |
| 764 | |
| 765 | require_once('user.func.inc.php'); |
| 766 | |
| 767 | if ($user) |
| 768 | $login = get_user_forlife($user); |
| 769 | |
| 770 | if (Env::has('user')) { |
| 771 | $login = get_user_forlife(Env::v('user')); |
| 772 | if ($login === false) { |
| 773 | return; |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | if (Env::has('mat')) { |
| 778 | $res = XDB::query( |
| 779 | "SELECT alias |
| 780 | FROM aliases AS a |
| 781 | INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie') |
| 782 | WHERE matricule={?}", Env::i('mat')); |
| 783 | $login = $res->fetchOneCell(); |
| 784 | } |
| 785 | |
| 786 | if ($login) { |
| 787 | if ($action == 'import') { |
| 788 | ax_synchronize($login, S::v('uid')); |
| 789 | } |
| 790 | // get details from user, but looking only info that can be seen by ax |
| 791 | $user = get_user_details($login, S::v('uid'), 'ax'); |
| 792 | $userax= get_user_ax($user['matricule_ax']); |
| 793 | require_once 'profil.func.inc.php'; |
| 794 | $diff = diff_user_details($userax, $user, 'ax'); |
| 795 | |
| 796 | $page->assign('x', $user); |
| 797 | $page->assign('diff', $diff); |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | function handler_validate(&$page, $action = 'list', $id = null) |
| 802 | { |
| 803 | $page->changeTpl('admin/valider.tpl'); |
| 804 | $page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande'); |
| 805 | $page->addCssLink('nl.css'); |
| 806 | $page->addJsLink('ajax.js'); |
| 807 | require_once("validations.inc.php"); |
| 808 | |
| 809 | |
| 810 | if ($action == 'edit' and !is_null($id)) { |
| 811 | $page->assign('preview_id', $id); |
| 812 | } |
| 813 | |
| 814 | if(Env::has('uid') && Env::has('type') && Env::has('stamp')) { |
| 815 | $req = Validate::get_typed_request(Env::v('uid'), Env::v('type'), Env::v('stamp')); |
| 816 | if($req) { $req->handle_formu(); } |
| 817 | } |
| 818 | |
| 819 | $r = XDB::iterator('SHOW COLUMNS FROM requests_answers'); |
| 820 | while (($a = $r->next()) && $a['Field'] != 'category'); |
| 821 | $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1)))); |
| 822 | |
| 823 | $hidden = array(); |
| 824 | if (Post::has('hide')) { |
| 825 | $hide = array(); |
| 826 | foreach ($categories as $cat) |
| 827 | if (!Post::v($cat)) { |
| 828 | $hidden[$cat] = 1; |
| 829 | $hide[] = $cat; |
| 830 | } |
| 831 | setcookie('hide_requests', join(',',$hide), time()+(count($hide)?25920000:(-3600)), '/', '', 0); |
| 832 | } elseif (Env::has('hide_requests')) { |
| 833 | foreach (explode(',',Env::v('hide_requests')) as $hide_type) |
| 834 | $hidden[$hide_type] = true; |
| 835 | } |
| 836 | $page->assign('hide_requests', $hidden); |
| 837 | |
| 838 | $page->assign('vit', new ValidateIterator()); |
| 839 | } |
| 840 | |
| 841 | function handler_validate_answers(&$page, $action = 'list', $id = null) { |
| 842 | $page->assign('xorg_title','Polytechnique.org - Administration - Réponses automatiques de validation'); |
| 843 | $page->assign('title', 'Gestion des réponses automatiques'); |
| 844 | $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id'); |
| 845 | $table_editor->describe('category','catégorie',true); |
| 846 | $table_editor->describe('title','titre',true); |
| 847 | $table_editor->describe('answer','texte',false); |
| 848 | $table_editor->apply($page, $action, $id); |
| 849 | } |
| 850 | function handler_skins(&$page, $action = 'list', $id = null) { |
| 851 | $page->assign('xorg_title','Polytechnique.org - Administration - Skins'); |
| 852 | $page->assign('title', 'Gestion des skins'); |
| 853 | $table_editor = new PLTableEditor('admin/skins','skins','id'); |
| 854 | $table_editor->describe('name','nom',true); |
| 855 | $table_editor->describe('skin_tpl','nom du template',true); |
| 856 | $table_editor->describe('auteur','auteur',false); |
| 857 | $table_editor->describe('comment','commentaire',true); |
| 858 | $table_editor->describe('date','date',false); |
| 859 | $table_editor->describe('ext','extension du screenshot',false); |
| 860 | $table_editor->apply($page, $action, $id); |
| 861 | } |
| 862 | function handler_postfix_blacklist(&$page, $action = 'list', $id = null) { |
| 863 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Blacklist'); |
| 864 | $page->assign('title', 'Blacklist de postfix'); |
| 865 | $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true); |
| 866 | $table_editor->describe('reject_text','Texte de rejet',true); |
| 867 | $table_editor->describe('email','email',true); |
| 868 | $table_editor->apply($page, $action, $id); |
| 869 | } |
| 870 | function handler_postfix_whitelist(&$page, $action = 'list', $id = null) { |
| 871 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Whitelist'); |
| 872 | $page->assign('title', 'Whitelist de postfix'); |
| 873 | $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true); |
| 874 | $table_editor->describe('email','email',true); |
| 875 | $table_editor->apply($page, $action, $id); |
| 876 | } |
| 877 | function handler_mx_broken(&$page, $action = 'list', $id = null) { |
| 878 | $page->assign('xorg_title', 'Polytechnique.org - Administration - MX Défaillants'); |
| 879 | $page->assign('title', 'MX Défaillant'); |
| 880 | $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true); |
| 881 | $table_editor->describe('host', 'Masque', true); |
| 882 | $table_editor->describe('state', 'Niveau', true); |
| 883 | $table_editor->describe('text', 'Description du problème', false); |
| 884 | $table_editor->apply($page, $action, $id); |
| 885 | } |
| 886 | function handler_logger_actions(&$page, $action = 'list', $id = null) { |
| 887 | $page->assign('xorg_title','Polytechnique.org - Administration - Actions'); |
| 888 | $page->assign('title', 'Gestion des actions de logger'); |
| 889 | $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id'); |
| 890 | $table_editor->describe('text','intitulé',true); |
| 891 | $table_editor->describe('description','description',true); |
| 892 | $table_editor->apply($page, $action, $id); |
| 893 | } |
| 894 | function handler_downtime(&$page, $action = 'list', $id = null) { |
| 895 | $page->assign('xorg_title','Polytechnique.org - Administration - Coupures'); |
| 896 | $page->assign('title', 'Gestion des coupures'); |
| 897 | $table_editor = new PLTableEditor('admin/downtime','coupures','id'); |
| 898 | $table_editor->describe('debut','date',true); |
| 899 | $table_editor->describe('duree','durée',false); |
| 900 | $table_editor->describe('resume','résumé',true); |
| 901 | $table_editor->describe('services','services affectés',true); |
| 902 | $table_editor->describe('description','description',false); |
| 903 | $table_editor->apply($page, $action, $id); |
| 904 | } |
| 905 | |
| 906 | function handler_wiki(&$page, $action='list', $wikipage='', $wikipage2='') |
| 907 | { |
| 908 | require_once 'wiki.inc.php'; |
| 909 | |
| 910 | if (S::v('core_rss_hash')) { |
| 911 | $page->setRssLink('Changement Récents', |
| 912 | '/Site/AllRecentChanges?action=rss&user=' . S::v('forlife') . '&hash=' . S::v('core_rss_hash')); |
| 913 | } |
| 914 | // update wiki perms |
| 915 | if ($action == 'update') { |
| 916 | $perms_read = Post::v('read'); |
| 917 | $perms_edot = Post::v('edit'); |
| 918 | if ($perms_read || $perms_edit) { |
| 919 | foreach ($_POST as $wiki_page => $val) if ($val == 'on') { |
| 920 | $wiki_page = str_replace('_', '/', $wiki_page); |
| 921 | if (!$perms_read || !$perms_edit) |
| 922 | list($perms0, $perms1) = wiki_get_perms($wiki_page); |
| 923 | if ($perms_read) |
| 924 | $perms0 = $perms_read; |
| 925 | if ($perms_edit) |
| 926 | $perms1 = $perms_edit; |
| 927 | wiki_set_perms($wiki_page, $perms0, $perms1); |
| 928 | } |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | if ($action == 'delete' && $wikipage != '') { |
| 933 | if (wiki_delete_page($wikipage)) { |
| 934 | $page->trig("La page ".$wikipage." a été supprimée."); |
| 935 | } else { |
| 936 | $page->trig("Impossible de supprimer la page ".$wikipage."."); |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | if ($action == 'rename' && $wikipage != '' && $wikipage2 != '' && $wikipage != $wikipage2) { |
| 941 | if ($changedLinks = wiki_rename_page($wikipage, $wikipage2)) { |
| 942 | $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.'; |
| 943 | if (is_numeric($changedLinks)) { |
| 944 | $s .= $changedLinks.' lien'.(($changedLinks>1)?'s ont été modifiés.':' a été modifié.'); |
| 945 | } |
| 946 | $page->trig($s); |
| 947 | } else { |
| 948 | $page->trig("Impossible de déplacer la page ".$wikipage); |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | $perms = wiki_perms_options(); |
| 953 | |
| 954 | // list wiki pages and their perms |
| 955 | $wiki_pages = array(); |
| 956 | $dir = wiki_work_dir(); |
| 957 | if (is_dir($dir)) { |
| 958 | if ($dh = opendir($dir)) { |
| 959 | while (($file = readdir($dh)) !== false) if (substr($file,0,1) >= 'A' && substr($file,0,1) <= 'Z') { |
| 960 | list($read,$edit) = wiki_get_perms($file); |
| 961 | $wiki_pages[$file] = array('read' => $perms[$read], 'edit' => $perms[$edit]); |
| 962 | if (is_file($dir . '/cache_' . wiki_filename($file) . '.tpl')) { |
| 963 | $wiki_pages[$file]['cached'] = true; |
| 964 | } |
| 965 | } |
| 966 | closedir($dh); |
| 967 | } |
| 968 | } |
| 969 | ksort($wiki_pages); |
| 970 | $wiki_tree = array(); |
| 971 | foreach ($wiki_pages as $file => $desc) { |
| 972 | list($cat, $name) = explode('.', $file); |
| 973 | if (!isset($wiki_tree[$cat])) { |
| 974 | $wiki_tree[$cat] = array(); |
| 975 | } |
| 976 | $wiki_tree[$cat][$name] = $desc; |
| 977 | } |
| 978 | |
| 979 | $page->changeTpl('admin/wiki.tpl'); |
| 980 | $page->addJsLink('jquery.js'); |
| 981 | $page->assign('wiki_pages', $wiki_tree); |
| 982 | $page->assign('perms_opts', $perms); |
| 983 | } |
| 984 | |
| 985 | function handler_ipwatch(&$page, $action = 'list', $ip = null) |
| 986 | { |
| 987 | $page->changeTpl('admin/ipwatcher.tpl'); |
| 988 | |
| 989 | $states = array('safe' => 'Ne pas surveiller', |
| 990 | 'unsafe' => 'Surveiller les inscriptions', |
| 991 | 'dangerous' => 'Surveiller tous les accès', |
| 992 | 'ban' => 'Bannir cette adresse'); |
| 993 | $page->assign('states', $states); |
| 994 | |
| 995 | switch (Post::v('action')) { |
| 996 | case 'create': |
| 997 | if (trim(Post::v('ipN')) != '') { |
| 998 | Xdb::execute('INSERT IGNORE INTO ip_watch (ip, state, detection, last, uid, description) |
| 999 | VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})', |
| 1000 | trim(Post::v('ipN')), Post::v('stateN'), S::i('uid'), Post::v('descriptionN')); |
| 1001 | }; |
| 1002 | break; |
| 1003 | |
| 1004 | case 'edit': |
| 1005 | Xdb::execute('UPDATE ip_watch |
| 1006 | SET state = {?}, last = NOW(), uid = {?}, description = {?} |
| 1007 | WHERE ip = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), Post::v('ipN')); |
| 1008 | break; |
| 1009 | |
| 1010 | default: |
| 1011 | if ($action == 'delete' && !is_null($ip)) { |
| 1012 | Xdb::execute('DELETE FROM emails_watch WHERE ip = {?}', $ip); |
| 1013 | } |
| 1014 | } |
| 1015 | if ($action != 'create' && $action != 'edit') { |
| 1016 | $action = 'list'; |
| 1017 | } |
| 1018 | $page->assign('action', $action); |
| 1019 | |
| 1020 | if ($action == 'list') { |
| 1021 | $sql = "SELECT w.ip, IF(w.ip = s.ip, s.host, s.forward_host), w.detection, w.state, a.alias AS forlife |
| 1022 | FROM ip_watch AS w |
| 1023 | LEFT JOIN logger.sessions AS s ON (s.ip = w.ip OR s.forward_ip = w.ip) |
| 1024 | LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type = 'a_vie') |
| 1025 | GROUP BY w.ip, a.alias |
| 1026 | ORDER BY w.state, w.ip, a.alias"; |
| 1027 | $it = Xdb::iterRow($sql); |
| 1028 | |
| 1029 | $table = array(); |
| 1030 | $props = array(); |
| 1031 | while (list($ip, $host, $date, $state, $forlife) = $it->next()) { |
| 1032 | if (count($props) == 0 || $props['ip'] != $ip) { |
| 1033 | if (count($props) > 0) { |
| 1034 | $table[] = $props; |
| 1035 | } |
| 1036 | $props = array('ip' => $ip, |
| 1037 | 'host' => $host, |
| 1038 | 'detection' => $date, |
| 1039 | 'state' => $state, |
| 1040 | 'users' => array($forlife)); |
| 1041 | } else { |
| 1042 | $props['users'][] = $forlife; |
| 1043 | } |
| 1044 | } |
| 1045 | if (count($props) > 0) { |
| 1046 | $table[] = $props; |
| 1047 | } |
| 1048 | $page->assign('table', $table); |
| 1049 | } elseif ($action == 'edit') { |
| 1050 | $sql = "SELECT w.detection, w.state, w.last, w.description, |
| 1051 | a1.alias AS edit, a2.alias AS forlife, s.host |
| 1052 | FROM ip_watch AS w |
| 1053 | LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie') |
| 1054 | LEFT JOIN logger.sessions AS s ON (w.ip = s.ip) |
| 1055 | LEFT JOIN aliases AS a2 ON (a2.id = s.uid AND a2.type = 'a_vie') |
| 1056 | WHERE w.ip = {?} |
| 1057 | GROUP BY a2.alias |
| 1058 | ORDER BY a2.alias"; |
| 1059 | $it = Xdb::iterRow($sql, $ip); |
| 1060 | |
| 1061 | $props = array(); |
| 1062 | while (list($detection, $state, $last, $description, $edit, $forlife, $host) = $it->next()) { |
| 1063 | if (count($props) == 0) { |
| 1064 | $props = array('ip' => $ip, |
| 1065 | 'host' => $host, |
| 1066 | 'detection' => $detection, |
| 1067 | 'state' => $state, |
| 1068 | 'last' => $last, |
| 1069 | 'description' => $description, |
| 1070 | 'edit' => $edit, |
| 1071 | 'users' => array($forlife)); |
| 1072 | } else { |
| 1073 | $props['users'][] = $forlife; |
| 1074 | } |
| 1075 | } |
| 1076 | $page->assign('ip', $props); |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | function handler_icons(&$page) |
| 1081 | { |
| 1082 | $page->changeTpl('admin/icons.tpl'); |
| 1083 | $dh = opendir('../htdocs/images/icons'); |
| 1084 | if (!$dh) { |
| 1085 | $page->trig('Dossier des icones introuvables.'); |
| 1086 | } |
| 1087 | $icons = array(); |
| 1088 | while (($file = readdir($dh)) !== false) { |
| 1089 | if (strlen($file) > 4 && substr($file,-4) == '.gif') { |
| 1090 | array_push($icons, substr($file, 0, -4)); |
| 1091 | } |
| 1092 | } |
| 1093 | sort($icons); |
| 1094 | $page->assign('icons', $icons); |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 1099 | ?> |