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