-
Notifications
You must be signed in to change notification settings - Fork 248
/
index.php
276 lines (238 loc) · 8.52 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<?php
/*
* CATS
* Index (Delegation Module)
*
* CATS Version: 0.9.7.4
*
* Copyright (C) 2005 - 2007 Cognizo Technologies, Inc.
*
*
* The contents of this file are subject to the CATS Public License
* Version 1.1a (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.catsone.com/. Software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is "CATS Standard Edition".
*
* The Initial Developer of the Original Code is Cognizo Technologies, Inc.
* Portions created by the Initial Developer are Copyright (C) 2005 - 2007
* (or from the year in which this file was created to the year 2007) by
* Cognizo Technologies, Inc. All Rights Reserved.
*
*
* A properly formatted query string will look like this:
*
* /index.php?m=candidates&a=edit&candidateID=55
*
*
* $Id: index.php 3807 2007-12-05 01:47:41Z will $
*/
/* Do we need to run the installer? */
include_once('./config.php');
if (!file_exists('INSTALL_BLOCK') && !isset($_POST['performMaintenence']))
{
include(LEGACY_ROOT . '/modules/install/notinstalled.php');
die();
}
// FIXME: Config file setting.
@ini_set('memory_limit', '64M');
/* Hack to make CATS work with E_STRICT. */
if (function_exists('date_default_timezone_set'))
{
@date_default_timezone_set(date_default_timezone_get());
}
include_once(LEGACY_ROOT . '/constants.php');
include_once(LEGACY_ROOT . '/lib/CommonErrors.php');
include_once(LEGACY_ROOT . '/lib/CATSUtility.php');
include_once(LEGACY_ROOT . '/lib/DatabaseConnection.php');
include_once(LEGACY_ROOT . '/lib/Template.php');
include_once(LEGACY_ROOT . '/lib/Users.php');
include_once(LEGACY_ROOT . '/lib/MRU.php');
include_once(LEGACY_ROOT . '/lib/Hooks.php');
include_once(LEGACY_ROOT . '/lib/Session.php'); /* Depends: MRU, Users, DatabaseConnection. */
include_once(LEGACY_ROOT . '/lib/UserInterface.php'); /* Depends: Template, Session. */
include_once(LEGACY_ROOT . '/lib/ModuleUtility.php'); /* Depends: UserInterface */
include_once(LEGACY_ROOT . '/lib/TemplateUtility.php'); /* Depends: ModuleUtility, Hooks */
/* Give the session a unique name to avoid conflicts and start the session. */
@session_name(CATS_SESSION_NAME);
session_start();
/* Try to prevent caching. */
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// This function assures to strip the values from
// request arrays even if as values are arrays not only values
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
/* Make sure we aren't getting screwed over by magic quotes. */
if (get_magic_quotes_runtime())
{
if (function_exists('set_magic_quotes_runtime')) {
set_magic_quotes_runtime(0);
}
}
if (get_magic_quotes_gpc())
{
include_once(LEGACY_ROOT . '/lib/ArrayUtility.php');
$_GET = array_map('stripslashes_deep', $_GET);
$_POST = array_map('stripslashes_deep', $_POST);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
$_GET = ArrayUtility::arrayMapKeys('stripslashes_deep', $_GET);
$_POST = ArrayUtility::arrayMapKeys('stripslashes_deep', $_POST);
$_REQUEST = ArrayUtility::arrayMapKeys('stripslashes_deep', $_REQUEST);
}
/* Objects can't be stored in the session if session.auto_start is enabled. */
if (ini_get('session.auto_start') !== '0' &&
ini_get('session.auto_start') !== 'Off')
{
die('CATS Error: session.auto_start must be set to 0 in php.ini.');
}
/* Proper extensions loaded?! */
if (!function_exists('mysqli_connect') || !function_exists('session_start'))
{
die('OpenCATS Error: Either PHP Sessions extension or MySQLi extension is not loaded.');
}
/* Make sure we have a Session object stored in the user's session. */
if (!isset($_SESSION['CATS']) || empty($_SESSION['CATS']))
{
$_SESSION['CATS'] = new CATSSession();
}
/* Start timer for measuring server response time. Displayed in footer. */
$_SESSION['CATS']->startTimer();
/* Check to see if the server went through a SVN update while the session
* was active.
*/
$_SESSION['CATS']->checkForcedUpdate();
/* Check to see if the user level suddenly changed. If the user was changed to disabled,
* also log the user out.
*/
// FIXME: This is slow!
if ($_SESSION['CATS']->isLoggedIn())
{
$users = new Users($_SESSION['CATS']->getSiteID());
$forceLogoutData = $users->getForceLogoutData($_SESSION['CATS']->getUserID());
if (!empty($forceLogoutData) && ($forceLogoutData['forceLogout'] == 1 ||
$_SESSION['CATS']->getRealAccessLevel() != $forceLogoutData['accessLevel']))
{
$_SESSION['CATS']->setRealAccessLevel($forceLogoutData['accessLevel']);
if ($forceLogoutData['accessLevel'] == ACCESS_LEVEL_DISABLED ||
$forceLogoutData['forceLogout'] == 1)
{
/* Log the user out. */
$unixName = $_SESSION['CATS']->getUnixName();
$_SESSION['CATS']->logout();
unset($_SESSION['CATS']);
unset($_SESSION['modules']);
$URI = 'm=login';
if (!empty($unixName) && $unixName != 'demo')
{
$URI .= '&s=' . $unixName;
}
CATSUtility::transferRelativeURI($URI);
die();
}
}
}
/* Check to see if we are supposed to display the career page. */
if (((isset($careerPage) && $careerPage) ||
(isset($_GET['showCareerPortal']) && $_GET['showCareerPortal'] == '1')))
{
ModuleUtility::loadModule('careers');
}
/* Check to see if we are supposed to display an rss page. */
else if (isset($rssPage) && $rssPage)
{
ModuleUtility::loadModule('rss');
}
else if (isset($xmlPage) && $xmlPage)
{
ModuleUtility::loadModule('xml');
}
/* Check to see if the user was forcibly logged out (logged in from another browser). */
else if ($_SESSION['CATS']->isLoggedIn() &&
(!isset($_GET['m']) || ModuleUtility::moduleRequiresAuthentication($_GET['m'])) &&
$_SESSION['CATS']->checkForceLogout())
{
// FIXME: Unset session / etc.?
ModuleUtility::loadModule('login');
}
/* If user specified a module, load it; otherwise, load the home module. */
else if (!isset($_GET['m']) || empty($_GET['m']))
{
if ($_SESSION['CATS']->isLoggedIn())
{
$_SESSION['CATS']->logPageView();
if (!eval(Hooks::get('INDEX_LOAD_HOME'))) return;
ModuleUtility::loadModule('home');
}
else
{
ModuleUtility::loadModule('login');
}
}
else
{
if ($_GET['m'] == 'logout')
{
/* There isn't really a logout module. It's just a few lines. */
$unixName = $_SESSION['CATS']->getUnixName();
$_SESSION['CATS']->logout();
unset($_SESSION['CATS']);
unset($_SESSION['modules']);
$URI = 'm=login';
/* Local demo account doesn't relogin. */
if (!empty($unixName) && $unixName != 'demo')
{
$URI .= '&s=' . $unixName;
}
if (isset($_GET['message']))
{
$URI .= '&message=' . urlencode($_GET['message']);
}
if (isset($_GET['messageSuccess']))
{
$URI .= '&messageSuccess=' . urlencode($_GET['messageSuccess']);
}
/* catsone.com demo domain doesn't relogin. */
if (strpos(CATSUtility::getIndexName(), '://demo.catsone.com') !== false)
{
CATSUtility::transferURL('http://www.catsone.com');
}
else
{
CATSUtility::transferRelativeURI($URI);
}
}
else if (!ModuleUtility::moduleRequiresAuthentication($_GET['m']))
{
/* No authentication required; load the module. */
ModuleUtility::loadModule($_GET['m']);
}
else if (!$_SESSION['CATS']->isLoggedIn())
{
/* User isn't logged in and authentication is required; send the user
* to the login page.
*/
ModuleUtility::loadModule('login');
}
else
{
/* Everything's good; load the requested module. */
$_SESSION['CATS']->logPageView();
ModuleUtility::loadModule($_GET['m']);
}
}
?>