| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2006 Polytechnique.org * |
| 4 | * http://opensource.polytechnique.org/ * |
| 5 | * * |
| 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, write to the Free Software * |
| 18 | * Foundation, Inc., * |
| 19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | function bugize($list) |
| 23 | { |
| 24 | $list = split(',', $list); |
| 25 | $ans = array(); |
| 26 | |
| 27 | foreach ($list as $bug) { |
| 28 | $clean = str_replace('#', '', $bug); |
| 29 | $ans[] = "<a href='http://trackers.polytechnique.org/task/$clean'>$bug</a>"; |
| 30 | } |
| 31 | |
| 32 | return join(',', $ans); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | class CoreModule extends PLModule |
| 37 | { |
| 38 | function handlers() |
| 39 | { |
| 40 | return array( |
| 41 | '403' => $this->make_hook('403', AUTH_PUBLIC), |
| 42 | '404' => $this->make_hook('404', AUTH_PUBLIC), |
| 43 | 'exit' => $this->make_hook('exit', AUTH_PUBLIC), |
| 44 | 'cacert.pem' => $this->make_hook('cacert', AUTH_PUBLIC), |
| 45 | 'changelog' => $this->make_hook('changelog', AUTH_PUBLIC), |
| 46 | 'purge_cache' => $this->make_hook('purge_cache', AUTH_COOKIE, 'admin') |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | function handler_index(&$page) |
| 51 | { |
| 52 | if (logged()) { |
| 53 | redirect("login.php"); |
| 54 | } |
| 55 | |
| 56 | return PL_OK; |
| 57 | } |
| 58 | |
| 59 | function handler_cacert(&$page) |
| 60 | { |
| 61 | $data = file_get_contents('/etc/ssl/xorgCA/cacert.pem'); |
| 62 | header('Content-Type: application/x-x509-ca-cert'); |
| 63 | header('Content-Length: '.strlen($data)); |
| 64 | echo $data; |
| 65 | exit; |
| 66 | } |
| 67 | |
| 68 | function handler_changelog(&$page) |
| 69 | { |
| 70 | $page->changeTpl('changeLog.tpl'); |
| 71 | |
| 72 | $clog = htmlentities(file_get_contents(dirname(__FILE__).'/../ChangeLog')); |
| 73 | $clog = preg_replace('!(#[0-9]+(,[0-9]+)*)!e', 'bugize("\1")', $clog); |
| 74 | $page->assign('ChangeLog', $clog); |
| 75 | } |
| 76 | |
| 77 | function handler_exit(&$page, $level = null) |
| 78 | { |
| 79 | if (Session::has('suid')) { |
| 80 | if (Session::has('suid')) { |
| 81 | $a4l = Session::get('forlife'); |
| 82 | $suid = Session::getMixed('suid'); |
| 83 | $log = Session::getMixed('log'); |
| 84 | $log->log("suid_stop", Session::get('forlife') . " by " . $suid['forlife']); |
| 85 | $_SESSION = $suid; |
| 86 | Session::kill('suid'); |
| 87 | redirect($globals->baseurl.'/admin/utilisateurs.php?login='.$a4l); |
| 88 | } else { |
| 89 | redirect("login.php"); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if ($level == 'forget' || $level == 'forgetall') { |
| 94 | setcookie('ORGaccess', '', time() - 3600, '/', '', 0); |
| 95 | Cookie::kill('ORGaccess'); |
| 96 | if (isset($_SESSION['log'])) |
| 97 | $_SESSION['log']->log("cookie_off"); |
| 98 | } |
| 99 | |
| 100 | if ($level == 'forgetuid' || $level == 'forgetall') { |
| 101 | setcookie('ORGuid', '', time() - 3600, '/', '', 0); |
| 102 | Cookie::kill('ORGuid'); |
| 103 | setcookie('ORGdomain', '', time() - 3600, '/', '', 0); |
| 104 | Cookie::kill('ORGdomain'); |
| 105 | } |
| 106 | |
| 107 | if (isset($_SESSION['log'])) { |
| 108 | $ref = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; |
| 109 | $_SESSION['log']->log('deconnexion',$ref); |
| 110 | } |
| 111 | |
| 112 | XorgSession::destroy(); |
| 113 | |
| 114 | if (Get::has('redirect')) { |
| 115 | redirect(rawurldecode(Get::get('redirect'))); |
| 116 | } else { |
| 117 | $page->changeTpl('exit.tpl'); |
| 118 | } |
| 119 | return PL_OK; |
| 120 | } |
| 121 | |
| 122 | function handler_403(&$page) |
| 123 | { |
| 124 | header('HTTP/1.0 403 Forbidden'); |
| 125 | $page->changeTpl('403.tpl'); |
| 126 | return PL_OK; |
| 127 | } |
| 128 | |
| 129 | function handler_404(&$page) |
| 130 | { |
| 131 | header('HTTP/1.0 404 Not Found'); |
| 132 | $page->changeTpl('404.tpl'); |
| 133 | return PL_OK; |
| 134 | } |
| 135 | |
| 136 | function handler_purge_cache(&$page) |
| 137 | { |
| 138 | require_once 'wiki.inc.php'; |
| 139 | |
| 140 | $page->clear_compiled_tpl(); |
| 141 | wiki_clear_all_cache(); |
| 142 | |
| 143 | redirect(empty($_SERVER['HTTP_REFERER']) ? './' : $_SERVER['HTTP_REFERER']); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | ?> |