| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2009 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/dead-but-active' => $this->make_hook('dead_but_active', AUTH_MDP, 'admin'), |
| 31 | 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP, 'admin'), |
| 32 | 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP, 'admin'), |
| 33 | 'admin/homonyms' => $this->make_hook('homonyms', AUTH_MDP, 'admin'), |
| 34 | 'admin/logger' => $this->make_hook('logger', AUTH_MDP, 'admin'), |
| 35 | 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_MDP, 'admin'), |
| 36 | 'admin/postfix/blacklist' => $this->make_hook('postfix_blacklist', AUTH_MDP, 'admin'), |
| 37 | 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP, 'admin'), |
| 38 | 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP, 'admin'), |
| 39 | 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP, 'admin'), |
| 40 | 'admin/mx/broken' => $this->make_hook('mx_broken', AUTH_MDP, 'admin'), |
| 41 | 'admin/skins' => $this->make_hook('skins', AUTH_MDP, 'admin'), |
| 42 | 'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP, 'admin'), |
| 43 | 'admin/user' => $this->make_hook('user', AUTH_MDP, 'admin'), |
| 44 | 'admin/promo' => $this->make_hook('promo', AUTH_MDP, 'admin'), |
| 45 | 'admin/validate' => $this->make_hook('validate', AUTH_MDP, 'admin'), |
| 46 | 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP, 'admin'), |
| 47 | 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'), |
| 48 | 'admin/ipwatch' => $this->make_hook('ipwatch', AUTH_MDP, 'admin'), |
| 49 | 'admin/icons' => $this->make_hook('icons', AUTH_MDP, 'admin'), |
| 50 | 'admin/accounts' => $this->make_hook('accounts', AUTH_MDP, 'admin'), |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | function handler_phpinfo(&$page) |
| 55 | { |
| 56 | phpinfo(); |
| 57 | exit; |
| 58 | } |
| 59 | |
| 60 | function handler_default(&$page) |
| 61 | { |
| 62 | $page->changeTpl('admin/index.tpl'); |
| 63 | $page->setTitle('Administration'); |
| 64 | } |
| 65 | |
| 66 | function handler_postfix_delayed(&$page) |
| 67 | { |
| 68 | $page->changeTpl('admin/postfix_delayed.tpl'); |
| 69 | $page->setTitle('Administration - Postfix : Retardés'); |
| 70 | |
| 71 | if (Env::has('del')) { |
| 72 | $crc = Env::v('crc'); |
| 73 | XDB::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc); |
| 74 | $page->trigSuccess($crc." verra tous ses emails supprimés !"); |
| 75 | } elseif (Env::has('ok')) { |
| 76 | $crc = Env::v('crc'); |
| 77 | XDB::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc); |
| 78 | $page->trigSuccess($crc." a le droit de passer !"); |
| 79 | } |
| 80 | |
| 81 | $sql = XDB::iterator( |
| 82 | "SELECT crc, nb, update_time, create_time, |
| 83 | FIND_IN_SET('del', release) AS del, |
| 84 | FIND_IN_SET('ok', release) AS ok |
| 85 | FROM postfix_mailseen |
| 86 | WHERE nb >= 30 |
| 87 | ORDER BY release != ''"); |
| 88 | |
| 89 | $page->assign_by_ref('mails', $sql); |
| 90 | } |
| 91 | |
| 92 | function handler_postfix_regexpsbounces(&$page, $new = null) { |
| 93 | $page->changeTpl('admin/emails_bounces_re.tpl'); |
| 94 | $page->setTitle('Administration - Postfix : Regexps Bounces'); |
| 95 | $page->assign('new', $new); |
| 96 | |
| 97 | if (Post::has('submit')) { |
| 98 | foreach (Env::v('lvl') as $id=>$val) { |
| 99 | XDB::query( |
| 100 | "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})", |
| 101 | $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id] |
| 102 | ); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | $page->assign('bre', XDB::iterator("SELECT * FROM emails_bounces_re ORDER BY pos")); |
| 107 | } |
| 108 | |
| 109 | // {{{ logger view |
| 110 | |
| 111 | /** Retrieves the available days for a given year and month. |
| 112 | * Obtain a list of days of the given month in the given year |
| 113 | * that are within the range of dates that we have log entries for. |
| 114 | * |
| 115 | * @param integer year |
| 116 | * @param integer month |
| 117 | * @return array days in that month we have log entries covering. |
| 118 | * @private |
| 119 | */ |
| 120 | function _getDays($year, $month) |
| 121 | { |
| 122 | // give a 'no filter' option |
| 123 | $months[0] = "----"; |
| 124 | |
| 125 | if ($year && $month) { |
| 126 | $day_max = Array(-1, 31, checkdate(2, 29, $year) ? 29 : 28 , 31, |
| 127 | 30, 31, 30, 31, 31, 30, 31, 30, 31); |
| 128 | $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)), |
| 129 | MONTH(MAX(start)), MONTH(MIN(start)), |
| 130 | DAYOFMONTH(MAX(start)), |
| 131 | DAYOFMONTH(MIN(start)) |
| 132 | FROM logger.sessions"); |
| 133 | list($ymax, $ymin, $mmax, $mmin, $dmax, $dmin) = $res->fetchOneRow(); |
| 134 | |
| 135 | if (($year < $ymin) || ($year == $ymin && $month < $mmin)) { |
| 136 | return array(); |
| 137 | } |
| 138 | |
| 139 | if (($year > $ymax) || ($year == $ymax && $month > $mmax)) { |
| 140 | return array(); |
| 141 | } |
| 142 | |
| 143 | $min = ($year==$ymin && $month==$mmin) ? intval($dmin) : 1; |
| 144 | $max = ($year==$ymax && $month==$mmax) ? intval($dmax) : $day_max[$month]; |
| 145 | |
| 146 | for($i = $min; $i<=$max; $i++) { |
| 147 | $days[$i] = $i; |
| 148 | } |
| 149 | } |
| 150 | return $days; |
| 151 | } |
| 152 | |
| 153 | |
| 154 | /** Retrieves the available months for a given year. |
| 155 | * Obtains a list of month numbers that are within the timeframe that |
| 156 | * we have log entries for. |
| 157 | * |
| 158 | * @param integer year |
| 159 | * @return array List of month numbers we have log info for. |
| 160 | * @private |
| 161 | */ |
| 162 | function _getMonths($year) |
| 163 | { |
| 164 | // give a 'no filter' option |
| 165 | $months[0] = "----"; |
| 166 | |
| 167 | if ($year) { |
| 168 | $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)), |
| 169 | MONTH(MAX(start)), MONTH(MIN(start)) |
| 170 | FROM logger.sessions"); |
| 171 | list($ymax, $ymin, $mmax, $mmin) = $res->fetchOneRow(); |
| 172 | |
| 173 | if (($year < $ymin) || ($year > $ymax)) { |
| 174 | return array(); |
| 175 | } |
| 176 | |
| 177 | $min = $year == $ymin ? intval($mmin) : 1; |
| 178 | $max = $year == $ymax ? intval($mmax) : 12; |
| 179 | |
| 180 | for($i = $min; $i<=$max; $i++) { |
| 181 | $months[$i] = $i; |
| 182 | } |
| 183 | } |
| 184 | return $months; |
| 185 | } |
| 186 | |
| 187 | |
| 188 | /** Retrieves the available years. |
| 189 | * Obtains a list of years that we have log entries covering. |
| 190 | * |
| 191 | * @return array years we have log entries for. |
| 192 | * @private |
| 193 | */ |
| 194 | function _getYears() |
| 195 | { |
| 196 | // give a 'no filter' option |
| 197 | $years[0] = "----"; |
| 198 | |
| 199 | // retrieve available years |
| 200 | $res = XDB::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM logger.sessions"); |
| 201 | list($max, $min) = $res->fetchOneRow(); |
| 202 | |
| 203 | for($i = intval($min); $i<=$max; $i++) { |
| 204 | $years[$i] = $i; |
| 205 | } |
| 206 | return $years; |
| 207 | } |
| 208 | |
| 209 | |
| 210 | /** Make a where clause to get a user's sessions. |
| 211 | * Prepare the where clause request that will retrieve the sessions. |
| 212 | * |
| 213 | * @param $year INTEGER Only get log entries made during the given year. |
| 214 | * @param $month INTEGER Only get log entries made during the given month. |
| 215 | * @param $day INTEGER Only get log entries made during the given day. |
| 216 | * @param $uid INTEGER Only get log entries referring to the given user ID. |
| 217 | * |
| 218 | * @return STRING the WHERE clause of a query, including the 'WHERE' keyword |
| 219 | * @private |
| 220 | */ |
| 221 | function _makeWhere($year, $month, $day, $uid) |
| 222 | { |
| 223 | // start constructing the "where" clause |
| 224 | $where = array(); |
| 225 | |
| 226 | if ($uid) |
| 227 | array_push($where, "uid='$uid'"); |
| 228 | |
| 229 | // we were given at least a year |
| 230 | if ($year) { |
| 231 | if ($day) { |
| 232 | $dmin = mktime(0, 0, 0, $month, $day, $year); |
| 233 | $dmax = mktime(0, 0, 0, $month, $day+1, $year); |
| 234 | } elseif ($month) { |
| 235 | $dmin = mktime(0, 0, 0, $month, 1, $year); |
| 236 | $dmax = mktime(0, 0, 0, $month+1, 1, $year); |
| 237 | } else { |
| 238 | $dmin = mktime(0, 0, 0, 1, 1, $year); |
| 239 | $dmax = mktime(0, 0, 0, 1, 1, $year+1); |
| 240 | } |
| 241 | $where[] = "start >= " . date("Ymd000000", $dmin); |
| 242 | $where[] = "start < " . date("Ymd000000", $dmax); |
| 243 | } |
| 244 | |
| 245 | if (!empty($where)) { |
| 246 | return ' WHERE ' . implode($where, " AND "); |
| 247 | } else { |
| 248 | return ''; |
| 249 | } |
| 250 | // WE know it's totally reversed, so better use array_reverse than a SORT BY start DESC |
| 251 | } |
| 252 | |
| 253 | // }}} |
| 254 | |
| 255 | function handler_logger(&$page, $action = null, $arg = null) { |
| 256 | if ($action == 'session') { |
| 257 | |
| 258 | // we are viewing a session |
| 259 | $res = XDB::query("SELECT ls.*, a.alias AS username, sa.alias AS suer |
| 260 | FROM logger.sessions AS ls |
| 261 | LEFT JOIN aliases AS a ON (a.id = ls.uid AND a.type='a_vie') |
| 262 | LEFT JOIN aliases AS sa ON (sa.id = ls.suid AND sa.type='a_vie') |
| 263 | WHERE ls.id = {?}", $arg); |
| 264 | |
| 265 | $page->assign('session', $a = $res->fetchOneAssoc()); |
| 266 | |
| 267 | $res = XDB::iterator('SELECT a.text, e.data, e.stamp |
| 268 | FROM logger.events AS e |
| 269 | LEFT JOIN logger.actions AS a ON e.action=a.id |
| 270 | WHERE e.session={?}', $arg); |
| 271 | while ($myarr = $res->next()) { |
| 272 | $page->append('events', $myarr); |
| 273 | } |
| 274 | |
| 275 | } else { |
| 276 | $loguser = $action == 'user' ? $arg : Env::v('loguser'); |
| 277 | |
| 278 | $res = XDB::query('SELECT id FROM aliases WHERE alias={?}', |
| 279 | $loguser); |
| 280 | $loguid = $res->fetchOneCell(); |
| 281 | |
| 282 | if ($loguid) { |
| 283 | $year = Env::i('year'); |
| 284 | $month = Env::i('month'); |
| 285 | $day = Env::i('day'); |
| 286 | } else { |
| 287 | $year = Env::i('year', intval(date('Y'))); |
| 288 | $month = Env::i('month', intval(date('m'))); |
| 289 | $day = Env::i('day', intval(date('d'))); |
| 290 | } |
| 291 | |
| 292 | if (!$year) |
| 293 | $month = 0; |
| 294 | if (!$month) |
| 295 | $day = 0; |
| 296 | |
| 297 | // smarty assignments |
| 298 | // retrieve available years |
| 299 | $page->assign('years', $this->_getYears()); |
| 300 | $page->assign('year', $year); |
| 301 | |
| 302 | // retrieve available months for the current year |
| 303 | $page->assign('months', $this->_getMonths($year)); |
| 304 | $page->assign('month', $month); |
| 305 | |
| 306 | // retrieve available days for the current year and month |
| 307 | $page->assign('days', $this->_getDays($year, $month)); |
| 308 | $page->assign('day', $day); |
| 309 | |
| 310 | $page->assign('loguser', $loguser); |
| 311 | // smarty assignments |
| 312 | |
| 313 | if ($loguid || $year) { |
| 314 | |
| 315 | // get the requested sessions |
| 316 | $where = $this->_makeWhere($year, $month, $day, $loguid); |
| 317 | $select = "SELECT s.id, s.start, s.uid, |
| 318 | a.alias as username |
| 319 | FROM logger.sessions AS s |
| 320 | LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type='a_vie') |
| 321 | $where |
| 322 | ORDER BY start DESC"; |
| 323 | $res = XDB::iterator($select); |
| 324 | |
| 325 | $sessions = array(); |
| 326 | while ($mysess = $res->next()) { |
| 327 | $mysess['events'] = array(); |
| 328 | $sessions[$mysess['id']] = $mysess; |
| 329 | } |
| 330 | array_reverse($sessions); |
| 331 | |
| 332 | // attach events |
| 333 | $sql = "SELECT s.id, a.text |
| 334 | FROM logger.sessions AS s |
| 335 | LEFT JOIN logger.events AS e ON(e.session=s.id) |
| 336 | INNER JOIN logger.actions AS a ON(a.id=e.action) |
| 337 | $where"; |
| 338 | |
| 339 | $res = XDB::iterator($sql); |
| 340 | while ($event = $res->next()) { |
| 341 | array_push($sessions[$event['id']]['events'], $event['text']); |
| 342 | } |
| 343 | $page->assign_by_ref('sessions', $sessions); |
| 344 | } else { |
| 345 | $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur"); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | $page->changeTpl('admin/logger-view.tpl'); |
| 350 | |
| 351 | $page->setTitle('Administration - Logs des sessions'); |
| 352 | } |
| 353 | |
| 354 | function handler_user(&$page, $login = false) |
| 355 | { |
| 356 | global $globals; |
| 357 | $page->changeTpl('admin/utilisateurs.tpl'); |
| 358 | $page->setTitle('Administration - Edit/Su/Log'); |
| 359 | require_once("emails.inc.php"); |
| 360 | |
| 361 | if (S::has('suid')) { |
| 362 | $page->kill("Déjà en SUID !!!"); |
| 363 | } |
| 364 | |
| 365 | // Loads the user identity using the environment. |
| 366 | if ($login) { |
| 367 | $user = User::get($login); |
| 368 | } else if (Env::has('user_id')) { |
| 369 | $user = User::get(Env::i('user_id')); |
| 370 | } else if (Env::has('login')) { |
| 371 | $user = User::get(Env::v('login')); |
| 372 | } |
| 373 | |
| 374 | if ($user) { |
| 375 | $login = $user->login(); |
| 376 | $registered = ($user->forlifeEmail() != null); |
| 377 | } else { |
| 378 | return; |
| 379 | } |
| 380 | |
| 381 | // Handles specific requests (AX sync, su, ...). |
| 382 | if(Env::has('logs_button') && $registered) { |
| 383 | pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m')); |
| 384 | } |
| 385 | |
| 386 | if (Env::has('ax_button') && $registered) { |
| 387 | pl_redirect("admin/synchro_ax/" . $user->login()); |
| 388 | } |
| 389 | |
| 390 | if(Env::has('suid_button') && $registered) { |
| 391 | S::logger()->log("suid_start", "login on " . $user->login()); |
| 392 | if (!Platal::session()->startSUID($user->id())) { |
| 393 | $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->id()); |
| 394 | } else { |
| 395 | pl_redirect(""); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | // Fetches user data. |
| 400 | $userinfo_query = "SELECT *, FIND_IN_SET('watch', flags) AS watch, FIND_IN_SET('femme', flags) AS sexe, |
| 401 | (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err |
| 402 | FROM auth_user_md5 |
| 403 | WHERE user_id = {?}"; |
| 404 | $mr = XDB::query($userinfo_query, $user->id())->fetchOneAssoc(); |
| 405 | $redirect = ($registered ? new Redirect($user) : null); |
| 406 | |
| 407 | // Processes admin requests, if any. |
| 408 | foreach($_POST as $key => $val) { |
| 409 | S::assert_xsrf_token(); |
| 410 | |
| 411 | switch ($key) { |
| 412 | // Email redirection actions. |
| 413 | case "add_fwd": |
| 414 | $email = trim(Env::v('email')); |
| 415 | if (!isvalid_email_redirection($email)) { |
| 416 | $page->trigError("Email non valide: $email"); |
| 417 | } else { |
| 418 | $redirect->add_email($email); |
| 419 | $page->trigSuccess("Ajout de $email effectué"); |
| 420 | } |
| 421 | break; |
| 422 | |
| 423 | case "del_fwd": |
| 424 | if (!empty($val)) { |
| 425 | $redirect->delete_email($val); |
| 426 | } |
| 427 | break; |
| 428 | |
| 429 | case "activate_fwd": |
| 430 | if (!empty($val)) { |
| 431 | $redirect->modify_one_email($val, true); |
| 432 | } |
| 433 | break; |
| 434 | case "deactivate_fwd": |
| 435 | if (!empty($val)) { |
| 436 | $redirect->modify_one_email($val, false); |
| 437 | } |
| 438 | break; |
| 439 | case "disable_fwd": |
| 440 | $redirect->disable(); |
| 441 | break; |
| 442 | case "enable_fwd": |
| 443 | $redirect->enable(); |
| 444 | break; |
| 445 | case "clean_fwd": |
| 446 | if (!empty($val)) { |
| 447 | $redirect->clean_errors($val); |
| 448 | } |
| 449 | break; |
| 450 | |
| 451 | // Alias actions. |
| 452 | case "add_alias": |
| 453 | global $globals; |
| 454 | |
| 455 | // Splits new alias in user and fqdn. |
| 456 | $alias = trim(Env::v('email')); |
| 457 | if (strpos($alias, '@') !== false) { |
| 458 | list($alias, $domain) = explode('@', $alias); |
| 459 | } else { |
| 460 | $domain = $globals->mail->domain; |
| 461 | } |
| 462 | |
| 463 | // Checks for alias' user validity. |
| 464 | if (!preg_match('/[-a-z0-9\.]+/s', $alias)) { |
| 465 | $page->trigError("'$alias' n'est pas un alias valide"); |
| 466 | } |
| 467 | |
| 468 | // Eventually adds the alias to the right domain. |
| 469 | if ($domain == $globals->mail->alias_dom || $domain == $globals->mail->alias_dom2) { |
| 470 | $req = new AliasReq($user, $alias, 'Admin request', false); |
| 471 | if ($req->commit()) { |
| 472 | $page->trigSuccess("Nouvel alias '$alias@$domain' attribué"); |
| 473 | } else { |
| 474 | $page->trigError("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué"); |
| 475 | } |
| 476 | } elseif ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) { |
| 477 | $res = XDB::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')", |
| 478 | $user->id(), $alias); |
| 479 | if ($res) { |
| 480 | $page->trigSuccess("Nouvel alias '$alias' ajouté"); |
| 481 | } else { |
| 482 | $page->trigError("Impossible d'ajouter l'alias '$alias', il est probablement déjà attribué"); |
| 483 | } |
| 484 | } else { |
| 485 | $page->trigError("Le domaine '$domain' n'est pas valide"); |
| 486 | } |
| 487 | break; |
| 488 | |
| 489 | case "del_alias": |
| 490 | if (!empty($val)) { |
| 491 | XDB::execute("DELETE FROM aliases |
| 492 | WHERE id = {?} AND alias = {?} AND |
| 493 | type NOT IN ('a_vie', 'homonyme')", |
| 494 | $user->id(), $val); |
| 495 | XDB::execute("UPDATE emails |
| 496 | SET rewrite = '' |
| 497 | WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')", |
| 498 | $user->id(), $val); |
| 499 | fix_bestalias($user); |
| 500 | $page->trigSuccess("L'alias '$val' a été supprimé"); |
| 501 | } |
| 502 | break; |
| 503 | |
| 504 | case "best": |
| 505 | XDB::execute("UPDATE aliases |
| 506 | SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ',')) |
| 507 | WHERE id = {?}", $user->id()); |
| 508 | XDB::execute("UPDATE aliases |
| 509 | SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias') |
| 510 | WHERE id = {?} AND alias = {?}", $user->id(), $val); |
| 511 | |
| 512 | // As having a non-null bestalias value is critical in |
| 513 | // plat/al's code, we do an a posteriori check on the |
| 514 | // validity of the bestalias. |
| 515 | fix_bestalias($user); |
| 516 | break; |
| 517 | |
| 518 | // Profile edition. |
| 519 | case "u_edit": |
| 520 | // Loads new values from environment. |
| 521 | require_once('secure_hash.inc.php'); |
| 522 | $pass_encrypted = Env::v('newpass_clair') != "********" ? hash_encrypt(Env::v('newpass_clair')) : Env::v('passw'); |
| 523 | $naiss = Env::v('naissanceN'); |
| 524 | $deces = Env::v('decesN'); |
| 525 | $perms = Env::v('permsN'); |
| 526 | $prenom = Env::v('prenomN'); |
| 527 | $nom = Env::v('nomN'); |
| 528 | $nomusage = Env::v('nomusageN'); |
| 529 | $promo = Env::i('promoN'); |
| 530 | $sexe = Env::v('sexeN'); |
| 531 | $comm = trim(Env::v('commentN')); |
| 532 | $watch = Env::v('watchN'); |
| 533 | |
| 534 | $flags = ($sexe ? 'femme' : ''); |
| 535 | if ($watch) { |
| 536 | $flags .= ($flags ? ',watch' : 'watch'); |
| 537 | } |
| 538 | if ($watch && !$comm) { |
| 539 | $page->trigError("Il est nécessaire de mettre un commentaire pour surveiller un compte"); |
| 540 | break; |
| 541 | } |
| 542 | |
| 543 | // Fetches fields to watch for changes. |
| 544 | $watch_query = "SELECT naissance, deces, password, perms, nom_usage, |
| 545 | prenom, nom, flags, promo, comment |
| 546 | FROM auth_user_md5 |
| 547 | WHERE user_id = {?}"; |
| 548 | $old_fields = XDB::query($watch_query, $user->id())->fetchOneAssoc(); |
| 549 | |
| 550 | // If user was newly banned, we need to ensure her php session |
| 551 | // is killed. This hack is ugly (and largely overkill); it should |
| 552 | // however suits our needs. |
| 553 | if ($perms == 'disabled' && $old_fields['perms'] != 'disabled') { |
| 554 | kill_sessions(); |
| 555 | |
| 556 | // Also serve a reminder to the admin: disabling an account |
| 557 | // does not deactivate email forwarding. |
| 558 | $page->trigWarning("N'oubliez pas, le cas échéant, de désactiver les redirections et le compte GoogleApps de l'utilisateur."); |
| 559 | } |
| 560 | |
| 561 | // Updates the user profile with the new values. |
| 562 | $res = XDB::execute("UPDATE auth_user_md5 |
| 563 | SET naissance = {?}, deces = {?}, password = {?}, |
| 564 | perms = {?}, prenom = {?}, nom = {?}, nom_usage = {?}, |
| 565 | flags = {?}, promo = {?}, comment = {?} |
| 566 | WHERE user_id = {?}", |
| 567 | $naiss, $deces, $pass_encrypted, |
| 568 | $perms, $prenom, $nom, $nomusage, |
| 569 | $flags, $promo, $comm, $user->id()); |
| 570 | if ($res) { |
| 571 | require_once("user.func.inc.php"); |
| 572 | user_reindex($user->id()); |
| 573 | $new_fields = XDB::query($watch_query, $user->id())->fetchOneAssoc(); |
| 574 | |
| 575 | // Redacts the password in the notification, to avoid transmitting |
| 576 | // sensitive information by email. |
| 577 | $new_fields['password'] = ($old_fields['password'] != $new_fields['password'] ? 'new' : 'old'); |
| 578 | $old_fields['password'] = 'old'; |
| 579 | |
| 580 | // Notifies the admins of the profile update. |
| 581 | $mailer = new PlMailer("admin/useredit.mail.tpl"); |
| 582 | $mailer->assign("admin", S::user()->login()); |
| 583 | $mailer->assign("user", $user->login()); |
| 584 | $mailer->assign('old', $old_fields); |
| 585 | $mailer->assign('new', $new_fields); |
| 586 | $mailer->send(); |
| 587 | |
| 588 | $globals->updateNbIns(); |
| 589 | $page->trigSuccess("Update was successful."); |
| 590 | } else { |
| 591 | $page->trigError("Update failed, please double check your values."); |
| 592 | } |
| 593 | |
| 594 | // Checks for changes, and updates other tables of plat/al. |
| 595 | if (Env::v('nomusageN') != $mr['nom_usage']) { |
| 596 | set_new_usage($user->id(), Env::v('nomusageN'), make_username(Env::v('prenomN'), Env::v('nomusageN'))); |
| 597 | } |
| 598 | if (Env::v('decesN') != $mr['deces']) { |
| 599 | require_once 'notifs.inc.php'; |
| 600 | register_watch_op($user->id(), WATCH_DEATH, $mr['deces']); |
| 601 | user_clear_all_subs($user->id(), false); |
| 602 | } |
| 603 | |
| 604 | // Eventually updates the Google Apps account. |
| 605 | if ($globals->mailstorage->googleapps_domain) { |
| 606 | // If the user did choose to use synchronized passwords, |
| 607 | // and the password was changed, updates the Google Apps |
| 608 | // password as well. |
| 609 | if (Env::v('newpass_clair') != "********") { |
| 610 | require_once 'googleapps.inc.php'; |
| 611 | $account = new GoogleAppsAccount($user); |
| 612 | if ($account->active() && $account->sync_password) { |
| 613 | $account->set_password($pass_encrypted); |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | |
| 619 | // Reloads the user profile, to ensure the latest version will |
| 620 | // be served to the administrator. |
| 621 | $mr = XDB::query($userinfo_query, $user->id())->fetchOneAssoc(); |
| 622 | |
| 623 | break; |
| 624 | |
| 625 | // User re-registration. |
| 626 | case "u_kill": |
| 627 | require_once('user.func.inc.php'); |
| 628 | user_clear_all_subs($user->id()); |
| 629 | $globals->updateNbIns(); |
| 630 | $page->trigSuccess("'" . $user->id() . "' a été désinscrit !"); |
| 631 | |
| 632 | $mailer = new PlMailer("admin/useredit.mail.tpl"); |
| 633 | $mailer->assign("admin", S::user()->login()); |
| 634 | $mailer->assign("user", $user->login()); |
| 635 | $mailer->assign("deletion", true); |
| 636 | $mailer->send(); |
| 637 | break; |
| 638 | |
| 639 | // Forum ban update. |
| 640 | case "b_edit": |
| 641 | XDB::execute("DELETE FROM forums.innd WHERE uid = {?}", $user->id()); |
| 642 | if (Env::v('write_perm') != "" || Env::v('read_perm') != "" || Env::v('commentaire') != "" ) { |
| 643 | XDB::execute("INSERT INTO forums.innd |
| 644 | SET ipmin = '0', ipmax = '4294967295', |
| 645 | write_perm = {?}, read_perm = {?}, |
| 646 | comment = {?}, priority = '200', uid = {?}", |
| 647 | Env::v('write_perm'), Env::v('read_perm'), Env::v('comment'), $user->id()); |
| 648 | } |
| 649 | break; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | // Displays last login and last host information. |
| 654 | $res = XDB::query("SELECT start, host |
| 655 | FROM logger.sessions |
| 656 | WHERE uid = {?} AND suid = 0 |
| 657 | ORDER BY start DESC |
| 658 | LIMIT 1", $user->id()); |
| 659 | list($lastlogin,$host) = $res->fetchOneRow(); |
| 660 | $page->assign('lastlogin', $lastlogin); |
| 661 | $page->assign('host', $host); |
| 662 | |
| 663 | // Display active aliases. |
| 664 | $page->assign('virtuals', XDB::iterator( |
| 665 | "SELECT alias |
| 666 | FROM virtual |
| 667 | INNER JOIN virtual_redirect USING (vid) |
| 668 | WHERE type = 'user' AND (redirect = {?} OR redirect = {?})", |
| 669 | $user->forlifeEmail(), |
| 670 | // TODO: remove this über-ugly hack. The issue is that you need |
| 671 | // to remove all @m4x.org addresses in virtual_redirect first. |
| 672 | $user->login() . '@' . $globals->mail->domain2)); |
| 673 | |
| 674 | $page->assign('aliases', XDB::iterator( |
| 675 | "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire |
| 676 | FROM aliases |
| 677 | WHERE id = {?} AND type != 'homonyme' |
| 678 | ORDER BY type != 'a_vie'", $user->id())); |
| 679 | |
| 680 | // Displays email redirection and the general profile. |
| 681 | if ($registered && $redirect) { |
| 682 | $page->assign('emails', $redirect->emails); |
| 683 | } |
| 684 | |
| 685 | $page->assign('mr', $mr); |
| 686 | $page->assign('user', $user); |
| 687 | |
| 688 | // Displays forum bans. |
| 689 | $res = XDB::query("SELECT write_perm, read_perm, comment |
| 690 | FROM forums.innd |
| 691 | WHERE uid = {?}", $user->id()); |
| 692 | $bans = $res->fetchOneAssoc(); |
| 693 | $page->assign('bans', $bans); |
| 694 | } |
| 695 | |
| 696 | function getHruid($line, $partial_result, $key) |
| 697 | { |
| 698 | if (!isset($partial_result['nom']) || |
| 699 | !isset($partial_result['prenom']) || |
| 700 | !isset($partial_result['promo'])) { |
| 701 | return null; |
| 702 | } |
| 703 | return make_forlife($partial_result['prenom'], $partial_result['nom'], $partial_result['promo']); |
| 704 | } |
| 705 | |
| 706 | function getMatricule($line, $key) |
| 707 | { |
| 708 | $mat = $line['matricule']; |
| 709 | $year = intval(substr($mat, 0, 3)); |
| 710 | $rang = intval(substr($mat, 3, 3)); |
| 711 | if ($year > 200) { $year /= 10; }; |
| 712 | if ($year < 96) { |
| 713 | return null; |
| 714 | } else { |
| 715 | return sprintf('%04u%04u', 1900+$year, $rang); |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | function handler_promo(&$page, $action = null, $promo = null) |
| 720 | { |
| 721 | if (Env::has('promo')) { |
| 722 | if(Env::i('promo') > 1900 && Env::i('promo') < 2050) { |
| 723 | $action = Env::v('valid_promo') == 'Ajouter des membres' ? 'add' : 'ax'; |
| 724 | pl_redirect('admin/promo/' . $action . '/' . Env::i('promo')); |
| 725 | } else { |
| 726 | $page->trigError('Promo non valide'); |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | $page->changeTpl('admin/promo.tpl'); |
| 731 | if ($promo > 1900 && $promo < 2050 && ($action == 'add' || $action == 'ax')) { |
| 732 | $page->assign('promo', $promo); |
| 733 | } else { |
| 734 | return; |
| 735 | } |
| 736 | |
| 737 | $importer = new CSVImporter('auth_user_md5', 'matricule'); |
| 738 | $importer->registerFunction('matricule', 'matricule Ecole vers X.org', array($this, 'getMatricule')); |
| 739 | switch ($action) { |
| 740 | case 'add': |
| 741 | $fields = array('hruid', 'nom', 'nom_ini', 'prenom', 'naissance_ini', |
| 742 | 'prenom_ini', 'promo', 'promo_sortie', 'flags', |
| 743 | 'matricule', 'matricule_ax', 'perms'); |
| 744 | $importer->forceValue('promo', $promo); |
| 745 | $importer->forceValue('promo_sortie', $promo + 3); |
| 746 | // The hruid generation callback is set last, so that it is called once 'promo' |
| 747 | // has already been computed for that line. |
| 748 | $importer->forceValue('hruid', array($this, 'getHruid')); |
| 749 | break; |
| 750 | case 'ax': |
| 751 | $fields = array('matricule', 'matricule_ax'); |
| 752 | break; |
| 753 | } |
| 754 | $importer->apply($page, "admin/promo/$action/$promo", $fields); |
| 755 | } |
| 756 | |
| 757 | function handler_homonyms(&$page, $op = 'list', $target = null) |
| 758 | { |
| 759 | $page->changeTpl('admin/homonymes.tpl'); |
| 760 | $page->setTitle('Administration - Homonymes'); |
| 761 | require_once("homonymes.inc.php"); |
| 762 | |
| 763 | if ($target) { |
| 764 | if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) { |
| 765 | $target=0; |
| 766 | } else { |
| 767 | $page->assign('nom',$nom); |
| 768 | $page->assign('prenom',$prenom); |
| 769 | $page->assign('forlife',$forlife); |
| 770 | $page->assign('loginbis',$loginbis); |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | $page->assign('op', $op); |
| 775 | $page->assign('target', $target); |
| 776 | |
| 777 | // on a un $target valide, on prepare les mails |
| 778 | if ($target) { |
| 779 | // on examine l'op a effectuer |
| 780 | switch ($op) { |
| 781 | case 'mail': |
| 782 | S::assert_xsrf_token(); |
| 783 | |
| 784 | send_warning_homonyme($prenom, $nom, $forlife, $loginbis); |
| 785 | switch_bestalias($target, $loginbis); |
| 786 | $op = 'list'; |
| 787 | $page->trigSuccess('Email envoyé à ' . $forlife . '.'); |
| 788 | break; |
| 789 | |
| 790 | case 'correct': |
| 791 | S::assert_xsrf_token(); |
| 792 | |
| 793 | switch_bestalias($target, $loginbis); |
| 794 | XDB::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis); |
| 795 | XDB::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target); |
| 796 | send_robot_homonyme($prenom, $nom, $forlife, $loginbis); |
| 797 | $op = 'list'; |
| 798 | $page->trigSuccess('Email envoyé à ' . $forlife . ', alias supprimé.'); |
| 799 | break; |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | if ($op == 'list') { |
| 804 | $res = XDB::iterator( |
| 805 | "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife, |
| 806 | promo,prenom,nom, |
| 807 | IF(h.homonyme_id=s.id, a.expire, NULL) AS expire, |
| 808 | IF(h.homonyme_id=s.id, a.type, NULL) AS type |
| 809 | FROM aliases AS a |
| 810 | LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id) |
| 811 | INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie') |
| 812 | INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id) |
| 813 | WHERE a.type='homonyme' OR a.expire!='' |
| 814 | ORDER BY a.alias,promo"); |
| 815 | $hnymes = Array(); |
| 816 | while ($tab = $res->next()) { |
| 817 | $hnymes[$tab['homonyme']][] = $tab; |
| 818 | } |
| 819 | $page->assign_by_ref('hnymes',$hnymes); |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | function handler_ax_xorg(&$page) { |
| 824 | $page->changeTpl('admin/ax-xorg.tpl'); |
| 825 | $page->setTitle('Administration - AX/X.org'); |
| 826 | |
| 827 | // liste des différences |
| 828 | $res = XDB::query( |
| 829 | '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 |
| 830 | FROM auth_user_md5 AS u |
| 831 | INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax |
| 832 | WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom) |
| 833 | AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro)) |
| 834 | OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1) |
| 835 | ORDER BY u.promo,u.nom,u.prenom'); |
| 836 | $page->assign('diffs', $res->fetchAllAssoc()); |
| 837 | |
| 838 | // gens à l'ax mais pas chez nous |
| 839 | $res = XDB::query( |
| 840 | 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom |
| 841 | FROM identification_ax as ia |
| 842 | LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax |
| 843 | WHERE u.nom IS NULL'); |
| 844 | $page->assign('mank', $res->fetchAllAssoc()); |
| 845 | |
| 846 | // gens chez nous et pas à l'ax |
| 847 | $res = XDB::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL'); |
| 848 | $page->assign('plus', $res->fetchAllAssoc()); |
| 849 | } |
| 850 | |
| 851 | function handler_deaths(&$page, $promo = 0, $validate = false) { |
| 852 | $page->changeTpl('admin/deces_promo.tpl'); |
| 853 | $page->setTitle('Administration - Deces'); |
| 854 | |
| 855 | if (!$promo) |
| 856 | $promo = Env::i('promo'); |
| 857 | if (Env::has('sub10')) $promo -= 10; |
| 858 | if (Env::has('sub01')) $promo -= 1; |
| 859 | if (Env::has('add01')) $promo += 1; |
| 860 | if (Env::has('add10')) $promo += 10; |
| 861 | |
| 862 | $page->assign('promo',$promo); |
| 863 | |
| 864 | if ($validate) { |
| 865 | S::assert_xsrf_token(); |
| 866 | |
| 867 | $res = XDB::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo); |
| 868 | while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) { |
| 869 | $val = Env::v($mat); |
| 870 | if($val == $deces || empty($val)) { |
| 871 | continue; |
| 872 | } |
| 873 | |
| 874 | XDB::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat); |
| 875 | $page->trigSuccess('Ajout du décès de ' . $prenom . " " . $nom . ' le ' . $val . '.'); |
| 876 | if($deces == '0000-00-00' || empty($deces)) { |
| 877 | require_once('notifs.inc.php'); |
| 878 | register_watch_op($uid, WATCH_DEATH, $val); |
| 879 | require_once('user.func.inc.php'); |
| 880 | user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | $res = XDB::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo); |
| 886 | $page->assign('decedes', $res); |
| 887 | } |
| 888 | |
| 889 | function handler_dead_but_active(&$page) { |
| 890 | $page->changeTpl('admin/dead_but_active.tpl'); |
| 891 | $page->setTitle('Administration - Décédés'); |
| 892 | |
| 893 | $res = XDB::iterator( |
| 894 | "SELECT u.promo, u.nom, u.prenom, u.deces, u.matricule_ax, u.hruid, DATE(MAX(s.start)) AS last |
| 895 | FROM auth_user_md5 AS u |
| 896 | LEFT JOIN logger.sessions AS s ON (s.uid = u.user_id AND suid = 0) |
| 897 | WHERE perms IN ('admin', 'user') AND deces <> 0 |
| 898 | GROUP BY u.user_id |
| 899 | ORDER BY u.promo, u.nom"); |
| 900 | $page->assign('dead', $res); |
| 901 | } |
| 902 | |
| 903 | function handler_synchro_ax(&$page, $login = null, $action = null) { |
| 904 | $page->changeTpl('admin/synchro_ax.tpl'); |
| 905 | $page->setTitle('Administration - Synchro AX'); |
| 906 | |
| 907 | // Checks for synchronization requirements. |
| 908 | require_once('synchro_ax.inc.php'); |
| 909 | if (is_ax_key_missing()) { |
| 910 | $page->assign('no_private_key', true); |
| 911 | $page->run(); |
| 912 | } |
| 913 | |
| 914 | // Determines user identity using environment. |
| 915 | if ($login) { |
| 916 | $user = User::get($login); |
| 917 | } else if (Env::has('user')) { |
| 918 | $user = User::get(Env::v('user')); |
| 919 | } else if (Env::has('mat')) { |
| 920 | $res = XDB::query("SELECT user_id FROM auth_user_md5 WHERE matricule = {?}", Env::i('mat')); |
| 921 | $user = User::get($res->fetchOneCell()); |
| 922 | } else { |
| 923 | return; |
| 924 | } |
| 925 | |
| 926 | // Finally synchronizes the AX and plat/al information. |
| 927 | if ($action == 'import') { |
| 928 | ax_synchronize($user->login(), S::v('uid')); |
| 929 | } |
| 930 | |
| 931 | require_once 'profil.func.inc.php'; |
| 932 | $userxorg = get_user_details($user->login(), S::v('uid'), 'ax'); |
| 933 | $userax = get_user_ax($userxorg['matricule_ax']); |
| 934 | $diff = diff_user_details($userax, $userxorg, 'ax'); |
| 935 | |
| 936 | $page->assign('x', $userxorg); |
| 937 | $page->assign('diff', $diff); |
| 938 | } |
| 939 | |
| 940 | function handler_validate(&$page, $action = 'list', $id = null) |
| 941 | { |
| 942 | $page->changeTpl('admin/valider.tpl'); |
| 943 | $page->setTitle('Administration - Valider une demande'); |
| 944 | $page->addCssLink('nl.css'); |
| 945 | $page->addJsLink('ajax.js'); |
| 946 | require_once("validations.inc.php"); |
| 947 | |
| 948 | |
| 949 | if ($action == 'edit' and !is_null($id)) { |
| 950 | $page->assign('preview_id', $id); |
| 951 | } |
| 952 | |
| 953 | if(Env::has('uid') && Env::has('type') && Env::has('stamp')) { |
| 954 | S::assert_xsrf_token(); |
| 955 | |
| 956 | $req = Validate::get_typed_request(Env::v('uid'), Env::v('type'), Env::v('stamp')); |
| 957 | if ($req) { |
| 958 | $req->handle_formu(); |
| 959 | } else { |
| 960 | $page->trigWarning('La validation a déjà été effectuée.'); |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | $r = XDB::iterator('SHOW COLUMNS FROM requests_answers'); |
| 965 | while (($a = $r->next()) && $a['Field'] != 'category'); |
| 966 | $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1)))); |
| 967 | |
| 968 | $hidden = array(); |
| 969 | $res = XDB::query('SELECT hidden_requests FROM requests_hidden WHERE user_id = {?}', S::v('uid')); |
| 970 | $hide_requests = $res->fetchOneCell(); |
| 971 | if (Post::has('hide')) { |
| 972 | $hide = array(); |
| 973 | foreach ($categories as $cat) |
| 974 | if (!Post::v($cat)) { |
| 975 | $hidden[$cat] = 1; |
| 976 | $hide[] = $cat; |
| 977 | } |
| 978 | $hide_requests = join(',', $hide); |
| 979 | XDB::query('REPLACE INTO requests_hidden (user_id, hidden_requests) VALUES({?}, {?})', |
| 980 | S::v('uid'), $hide_requests); |
| 981 | } elseif ($hide_requests) { |
| 982 | foreach (explode(',', $hide_requests) as $hide_type) |
| 983 | $hidden[$hide_type] = true; |
| 984 | } |
| 985 | $page->assign('hide_requests', $hidden); |
| 986 | |
| 987 | // Update the count of item to validate here... useful in development configuration |
| 988 | // where several copies of the site use the same DB, but not the same "dynamic configuration" |
| 989 | global $globals; |
| 990 | $globals->updateNbValid(); |
| 991 | $page->assign('vit', new ValidateIterator()); |
| 992 | } |
| 993 | |
| 994 | function handler_validate_answers(&$page, $action = 'list', $id = null) { |
| 995 | $page->setTitle('Administration - Réponses automatiques de validation'); |
| 996 | $page->assign('title', 'Gestion des réponses automatiques'); |
| 997 | $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id'); |
| 998 | $table_editor->describe('category','catégorie',true); |
| 999 | $table_editor->describe('title','titre',true); |
| 1000 | $table_editor->describe('answer','texte',false); |
| 1001 | $table_editor->apply($page, $action, $id); |
| 1002 | } |
| 1003 | function handler_skins(&$page, $action = 'list', $id = null) { |
| 1004 | $page->setTitle('Administration - Skins'); |
| 1005 | $page->assign('title', 'Gestion des skins'); |
| 1006 | $table_editor = new PLTableEditor('admin/skins','skins','id'); |
| 1007 | $table_editor->describe('name','nom',true); |
| 1008 | $table_editor->describe('skin_tpl','nom du template',true); |
| 1009 | $table_editor->describe('auteur','auteur',false); |
| 1010 | $table_editor->describe('comment','commentaire',true); |
| 1011 | $table_editor->describe('date','date',false); |
| 1012 | $table_editor->describe('ext','extension du screenshot',false); |
| 1013 | $table_editor->apply($page, $action, $id); |
| 1014 | } |
| 1015 | |
| 1016 | function handler_postfix_blacklist(&$page, $action = 'list', $id = null) { |
| 1017 | $page->setTitle('Administration - Postfix : Blacklist'); |
| 1018 | $page->assign('title', 'Blacklist de postfix'); |
| 1019 | $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true); |
| 1020 | $table_editor->describe('reject_text','Texte de rejet',true); |
| 1021 | $table_editor->describe('email','email',true); |
| 1022 | $table_editor->apply($page, $action, $id); |
| 1023 | } |
| 1024 | function handler_postfix_whitelist(&$page, $action = 'list', $id = null) { |
| 1025 | $page->setTitle('Administration - Postfix : Whitelist'); |
| 1026 | $page->assign('title', 'Whitelist de postfix'); |
| 1027 | $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true); |
| 1028 | $table_editor->describe('email','email',true); |
| 1029 | $table_editor->apply($page, $action, $id); |
| 1030 | } |
| 1031 | function handler_mx_broken(&$page, $action = 'list', $id = null) { |
| 1032 | $page->setTitle('Administration - MX Défaillants'); |
| 1033 | $page->assign('title', 'MX Défaillant'); |
| 1034 | $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true); |
| 1035 | $table_editor->describe('host', 'Masque', true); |
| 1036 | $table_editor->describe('state', 'Niveau', true); |
| 1037 | $table_editor->describe('text', 'Description du problème', false); |
| 1038 | $table_editor->apply($page, $action, $id); |
| 1039 | } |
| 1040 | function handler_logger_actions(&$page, $action = 'list', $id = null) { |
| 1041 | $page->setTitle('Administration - Actions'); |
| 1042 | $page->assign('title', 'Gestion des actions de logger'); |
| 1043 | $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id'); |
| 1044 | $table_editor->describe('text','intitulé',true); |
| 1045 | $table_editor->describe('description','description',true); |
| 1046 | $table_editor->apply($page, $action, $id); |
| 1047 | } |
| 1048 | function handler_downtime(&$page, $action = 'list', $id = null) { |
| 1049 | $page->setTitle('Administration - Coupures'); |
| 1050 | $page->assign('title', 'Gestion des coupures'); |
| 1051 | $table_editor = new PLTableEditor('admin/downtime','coupures','id'); |
| 1052 | $table_editor->describe('debut','date',true); |
| 1053 | $table_editor->describe('duree','durée',false); |
| 1054 | $table_editor->describe('resume','résumé',true); |
| 1055 | $table_editor->describe('services','services affectés',true); |
| 1056 | $table_editor->describe('description','description',false); |
| 1057 | $table_editor->apply($page, $action, $id); |
| 1058 | } |
| 1059 | |
| 1060 | function handler_wiki(&$page, $action = 'list', $wikipage = null, $wikipage2 = null) |
| 1061 | { |
| 1062 | if (S::v('core_rss_hash')) { |
| 1063 | $page->setRssLink('Changement Récents', |
| 1064 | '/Site/AllRecentChanges?action=rss&user=' . S::v('hruid') . '&hash=' . S::v('core_rss_hash')); |
| 1065 | } |
| 1066 | |
| 1067 | // update wiki perms |
| 1068 | if ($action == 'update') { |
| 1069 | S::assert_xsrf_token(); |
| 1070 | |
| 1071 | $perms_read = Post::v('read'); |
| 1072 | $perms_edit = Post::v('edit'); |
| 1073 | if ($perms_read || $perms_edit) { |
| 1074 | foreach ($_POST as $wiki_page => $val) { |
| 1075 | if ($val == 'on') { |
| 1076 | $wp = new PlWikiPage(str_replace(array('_', '/'), '.', $wiki_page)); |
| 1077 | if ($wp->setPerms($perms_read ? $perms_read : $wp->readPerms(), |
| 1078 | $perms_edit ? $perms_edit : $wp->writePerms())) { |
| 1079 | $page->trigSuccess("Permission de la page $wiki_page mises à jour"); |
| 1080 | } else { |
| 1081 | $page->trigError("Impossible de mettre les permissions de la page $wiki_page à jour"); |
| 1082 | } |
| 1083 | } |
| 1084 | } |
| 1085 | } |
| 1086 | } else if ($action != 'list' && !empty($wikipage)) { |
| 1087 | $wp = new PlWikiPage($wikipage); |
| 1088 | S::assert_xsrf_token(); |
| 1089 | |
| 1090 | if ($action == 'delete') { |
| 1091 | if ($wp->delete()) { |
| 1092 | $page->trigSuccess("La page ".$wikipage." a été supprimée."); |
| 1093 | } else { |
| 1094 | $page->trigError("Impossible de supprimer la page ".$wikipage."."); |
| 1095 | } |
| 1096 | } else if ($action == 'rename' && !empty($wikipage2) && $wikipage != $wikipage2) { |
| 1097 | if ($changedLinks = $wp->rename($wikipage2)) { |
| 1098 | $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.'; |
| 1099 | if (is_numeric($changedLinks)) { |
| 1100 | $s .= $changedLinks.' lien'.(($changedLinks>1)?'s ont été modifiés.':' a été modifié.'); |
| 1101 | } |
| 1102 | $page->trigSuccess($s); |
| 1103 | } else { |
| 1104 | $page->trigError("Impossible de déplacer la page ".$wikipage); |
| 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | $perms = PlWikiPage::permOptions(); |
| 1110 | |
| 1111 | // list wiki pages and their perms |
| 1112 | $wiki_pages = PlWikiPage::listPages(); |
| 1113 | ksort($wiki_pages); |
| 1114 | $wiki_tree = array(); |
| 1115 | foreach ($wiki_pages as $file => $desc) { |
| 1116 | list($cat, $name) = explode('.', $file); |
| 1117 | if (!isset($wiki_tree[$cat])) { |
| 1118 | $wiki_tree[$cat] = array(); |
| 1119 | } |
| 1120 | $wiki_tree[$cat][$name] = $desc; |
| 1121 | } |
| 1122 | |
| 1123 | $page->changeTpl('admin/wiki.tpl'); |
| 1124 | $page->addJsLink('jquery.js'); |
| 1125 | $page->assign('wiki_pages', $wiki_tree); |
| 1126 | $page->assign('perms_opts', $perms); |
| 1127 | } |
| 1128 | |
| 1129 | function handler_ipwatch(&$page, $action = 'list', $ip = null) |
| 1130 | { |
| 1131 | $page->changeTpl('admin/ipwatcher.tpl'); |
| 1132 | |
| 1133 | $states = array('safe' => 'Ne pas surveiller', |
| 1134 | 'unsafe' => 'Surveiller les inscriptions', |
| 1135 | 'dangerous' => 'Surveiller tous les accès', |
| 1136 | 'ban' => 'Bannir cette adresse'); |
| 1137 | $page->assign('states', $states); |
| 1138 | |
| 1139 | switch (Post::v('action')) { |
| 1140 | case 'create': |
| 1141 | if (trim(Post::v('ipN')) != '') { |
| 1142 | S::assert_xsrf_token(); |
| 1143 | Xdb::execute('INSERT IGNORE INTO ip_watch (ip, mask, state, detection, last, uid, description) |
| 1144 | VALUES ({?}, {?}, {?}, CURDATE(), NOW(), {?}, {?})', |
| 1145 | ip_to_uint(trim(Post::v('ipN'))), ip_to_uint(trim(Post::v('maskN'))), |
| 1146 | Post::v('stateN'), S::i('uid'), Post::v('descriptionN')); |
| 1147 | }; |
| 1148 | break; |
| 1149 | |
| 1150 | case 'edit': |
| 1151 | S::assert_xsrf_token(); |
| 1152 | Xdb::execute('UPDATE ip_watch |
| 1153 | SET state = {?}, last = NOW(), uid = {?}, description = {?}, mask = {?} |
| 1154 | WHERE ip = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), |
| 1155 | ip_to_uint(Post::v('maskN')), ip_to_uint(Post::v('ipN'))); |
| 1156 | break; |
| 1157 | |
| 1158 | default: |
| 1159 | if ($action == 'delete' && !is_null($ip)) { |
| 1160 | S::assert_xsrf_token(); |
| 1161 | Xdb::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip)); |
| 1162 | } |
| 1163 | } |
| 1164 | if ($action != 'create' && $action != 'edit') { |
| 1165 | $action = 'list'; |
| 1166 | } |
| 1167 | $page->assign('action', $action); |
| 1168 | |
| 1169 | if ($action == 'list') { |
| 1170 | $sql = "SELECT w.ip, IF(s.ip IS NULL, |
| 1171 | IF(w.ip = s2.ip, s2.host, s2.forward_host), |
| 1172 | IF(w.ip = s.ip, s.host, s.forward_host)), |
| 1173 | w.mask, w.detection, w.state, u.hruid |
| 1174 | FROM ip_watch AS w |
| 1175 | LEFT JOIN logger.sessions AS s ON (s.ip = w.ip) |
| 1176 | LEFT JOIN logger.sessions AS s2 ON (s2.forward_ip = w.ip) |
| 1177 | LEFT JOIN auth_user_md5 AS u ON (u.user_id = s.uid) |
| 1178 | GROUP BY w.ip, u.hruid |
| 1179 | ORDER BY w.state, w.ip, u.hruid"; |
| 1180 | $it = Xdb::iterRow($sql); |
| 1181 | |
| 1182 | $table = array(); |
| 1183 | $props = array(); |
| 1184 | while (list($ip, $host, $mask, $date, $state, $hruid) = $it->next()) { |
| 1185 | $ip = uint_to_ip($ip); |
| 1186 | $mask = uint_to_ip($mask); |
| 1187 | if (count($props) == 0 || $props['ip'] != $ip) { |
| 1188 | if (count($props) > 0) { |
| 1189 | $table[] = $props; |
| 1190 | } |
| 1191 | $props = array('ip' => $ip, |
| 1192 | 'mask' => $mask, |
| 1193 | 'host' => $host, |
| 1194 | 'detection' => $date, |
| 1195 | 'state' => $state, |
| 1196 | 'users' => array($hruid)); |
| 1197 | } else { |
| 1198 | $props['users'][] = $hruid; |
| 1199 | } |
| 1200 | } |
| 1201 | if (count($props) > 0) { |
| 1202 | $table[] = $props; |
| 1203 | } |
| 1204 | $page->assign('table', $table); |
| 1205 | } elseif ($action == 'edit') { |
| 1206 | $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask, |
| 1207 | u1.hruid AS edit, u2.hruid AS hruid, s.host |
| 1208 | FROM ip_watch AS w |
| 1209 | LEFT JOIN auth_user_md5 AS u1 ON (u1.user_id = w.uid) |
| 1210 | LEFT JOIN logger.sessions AS s ON (w.ip = s.ip) |
| 1211 | LEFT JOIN auth_user_md5 AS u2 ON (u2.user_id = s.uid) |
| 1212 | WHERE w.ip = {?} |
| 1213 | GROUP BY u2.hruid |
| 1214 | ORDER BY u2.hruid"; |
| 1215 | $it = Xdb::iterRow($sql, ip_to_uint($ip)); |
| 1216 | |
| 1217 | $props = array(); |
| 1218 | while (list($detection, $state, $last, $description, $mask, $edit, $hruid, $host) = $it->next()) { |
| 1219 | if (count($props) == 0) { |
| 1220 | $props = array('ip' => $ip, |
| 1221 | 'mask' => uint_to_ip($mask), |
| 1222 | 'host' => $host, |
| 1223 | 'detection' => $detection, |
| 1224 | 'state' => $state, |
| 1225 | 'last' => $last, |
| 1226 | 'description' => $description, |
| 1227 | 'edit' => $edit, |
| 1228 | 'users' => array($hruid)); |
| 1229 | } else { |
| 1230 | $props['users'][] = $hruid; |
| 1231 | } |
| 1232 | } |
| 1233 | $page->assign('ip', $props); |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | function handler_icons(&$page) |
| 1238 | { |
| 1239 | $page->changeTpl('admin/icons.tpl'); |
| 1240 | $dh = opendir('../htdocs/images/icons'); |
| 1241 | if (!$dh) { |
| 1242 | $page->trigError('Dossier des icones introuvables.'); |
| 1243 | } |
| 1244 | $icons = array(); |
| 1245 | while (($file = readdir($dh)) !== false) { |
| 1246 | if (strlen($file) > 4 && substr($file,-4) == '.gif') { |
| 1247 | array_push($icons, substr($file, 0, -4)); |
| 1248 | } |
| 1249 | } |
| 1250 | sort($icons); |
| 1251 | $page->assign('icons', $icons); |
| 1252 | } |
| 1253 | |
| 1254 | function handler_accounts(&$page) |
| 1255 | { |
| 1256 | $page->changeTpl('admin/accounts.tpl'); |
| 1257 | $page->assign('disabled', XDB::iterator('SELECT u.nom, u.prenom, u.promo, u.comment, u.hruid |
| 1258 | FROM auth_user_md5 AS u |
| 1259 | WHERE perms = \'disabled\' |
| 1260 | ORDER BY nom, prenom')); |
| 1261 | $page->assign('admins', XDB::iterator('SELECT u.nom, u.prenom, u.promo, u.hruid |
| 1262 | FROM auth_user_md5 AS u |
| 1263 | WHERE perms = \'admin\' |
| 1264 | ORDER BY nom, prenom')); |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 1269 | ?> |