132
156
error_reporting(E_ALL);
134
158
# Start our session.
161
# See if we have a session, we can then get our theme out
162
$app['theme'] = 'default';
163
if (isset($_SESSION[APPCONFIG]))
164
if (is_dir(realpath(sprintf('images/%s',$_SESSION[APPCONFIG]->getValue('appearance','theme'))))
165
&& is_file(realpath(sprintf('css/%s/%s',$_SESSION[APPCONFIG]->getValue('appearance','theme'),$_SESSION[APPCONFIG]->getValue('appearance','stylesheet')))))
167
$app['theme'] = $_SESSION[APPCONFIG]->getValue('appearance','theme');
169
define('CSSDIR',sprintf('css/%s',$app['theme']));
170
define('IMGDIR',sprintf('images/%s',$app['theme']));
137
172
# Initialise the hooks
138
require_once LIBDIR.'hooks.php';
173
if (file_exists(LIBDIR.'hooks.php'))
174
require_once LIBDIR.'hooks.php';
140
176
# If we get here, and $_SESSION[APPCONFIG] is not set, then redirect the user to the index.
141
if (! isset($_SESSION[APPCONFIG])) {
142
header(sprintf('Location: index.php?URI=%s',base64_encode($_SERVER['QUERY_STRING'])));
177
if (isset($_SERVER['SERVER_SOFTWARE']) && ! isset($_SESSION[APPCONFIG])) {
178
if ($_SERVER['QUERY_STRING'])
179
header(sprintf('Location: index.php?URI=%s',base64_encode($_SERVER['QUERY_STRING'])));
181
header('Location: index.php');
156
196
if (ini_get('safe_mode') && ! get_request('cmd','GET'))
157
197
system_message(array(
158
198
'title'=>_('PHP Safe Mode'),
159
'body'=>_('You have PHP Safe Mode enabled. PLA may work unexpectedly in Safe Mode.'),
199
'body'=>_('You have PHP Safe Mode enabled. This application may work unexpectedly in Safe Mode.'),
160
200
'type'=>'info'));
162
202
# Set our timezone, if it is specified in config.php
163
if ($_SESSION[APPCONFIG]->GetValue('appearance','timezone'))
164
date_default_timezone_set($_SESSION[APPCONFIG]->GetValue('appearance','timezone'));
203
if ($_SESSION[APPCONFIG]->getValue('appearance','timezone'))
204
date_default_timezone_set($_SESSION[APPCONFIG]->getValue('appearance','timezone'));
166
206
# If we are here, $_SESSION is set - so enabled DEBUGing if it has been configured.
167
if (($_SESSION[APPCONFIG]->GetValue('debug','syslog') || $_SESSION[APPCONFIG]->GetValue('debug','file'))
168
&& $_SESSION[APPCONFIG]->GetValue('debug','level'))
207
if (($_SESSION[APPCONFIG]->getValue('debug','syslog') || $_SESSION[APPCONFIG]->getValue('debug','file'))
208
&& $_SESSION[APPCONFIG]->getValue('debug','level'))
169
209
define('DEBUG_ENABLED',1);
171
211
define('DEBUG_ENABLED',0);
173
213
if (DEBUG_ENABLED)
174
debug_log('Application (%s) initialised and starting with (%s).',1,__FILE__,__LINE__,__METHOD__,
175
pla_version(),$_REQUEST);
214
debug_log('Application (%s) initialised and starting with (%s).',1,0,__FILE__,__LINE__,__METHOD__,
215
app_version(),$_REQUEST);
177
217
# Set our PHP timelimit.
178
if ($_SESSION[APPCONFIG]->GetValue('session','timelimit'))
179
@set_time_limit($_SESSION[APPCONFIG]->GetValue('session','timelimit'));
218
if ($_SESSION[APPCONFIG]->getValue('session','timelimit') && ! ini_get('safe_mode'))
219
set_time_limit($_SESSION[APPCONFIG]->getValue('session','timelimit'));
181
221
# If debug mode is set, increase the time_limit, since we probably need it.
182
if (DEBUG_ENABLED && $_SESSION[APPCONFIG]->GetValue('session','timelimit'))
183
@set_time_limit($_SESSION[APPCONFIG]->GetValue('session','timelimit') * 5);
222
if (DEBUG_ENABLED && $_SESSION[APPCONFIG]->getValue('session','timelimit') && ! ini_get('safe_mode'))
223
set_time_limit($_SESSION[APPCONFIG]->getValue('session','timelimit') * 5);
186
226
* Language configuration. Auto or specified?
187
227
* Shall we attempt to auto-determine the language?
189
$language = $_SESSION[APPCONFIG]->GetValue('appearance','language');
191
if ($language == 'auto') {
229
# If we are in safe mode, and LANG is not in the allowed vars, display an error.
230
if (ini_get('safe_mode') && ! in_array('LANG',explode(',',ini_get('safe_mode_allowed_env_vars'))))
231
error('You are running in SAFE_MODE, but LANG is not in the safe_mode_allowed_env_vars. Please add LANG to safe_mode_allowed_env_vars','error',true,false);
233
$app['language'] = $_SESSION[APPCONFIG]->getValue('appearance','language');
235
if ($app['language'] == 'auto') {
193
237
# Make sure their browser correctly reports language. If not, skip this.
194
238
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
196
240
# Get the languages which are spetcified in the HTTP header
197
$HTTP_LANGS = preg_split ('/[;,]+/',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
198
foreach ($HTTP_LANGS as $key => $value) {
241
$app['lang_http'] = preg_split ('/[;,]+/',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
242
foreach ($app['lang_http'] as $key => $value) {
199
243
if (substr($value,0,2) == 'q=') {
200
unset($HTTP_LANGS[$key]);
244
unset($app['lang_http'][$key]);
204
248
$value = preg_split('/[-]+/',$value);
205
249
if (sizeof($value) == 2)
206
$HTTP_LANGS[$key] = strtolower($value[0]).'_'.strtoupper($value[1]);
250
$app['lang_http'][$key] = strtolower($value[0]).'_'.strtoupper($value[1]);
208
$HTTP_LANGS[$key] = auto_lang(strtolower($value[0]));
252
$app['lang_http'][$key] = auto_lang(strtolower($value[0]));
211
$HTTP_LANGS = array_unique($HTTP_LANGS);
213
foreach ($HTTP_LANGS as $HTTP_LANG) {
214
$language_dir = LANGDIR.$HTTP_LANG;
216
if ((substr($HTTP_LANG,0,2) == 'en') ||
217
(file_exists($language_dir) && is_readable($language_dir))) {
255
$app['lang_http'] = array_unique($app['lang_http']);
257
foreach ($app['lang_http'] as $lang) {
258
$app['language_dir'] = LANGDIR.$lang;
260
if ((substr($lang,0,2) == 'en') ||
261
(file_exists($app['language_dir']) && is_readable($app['language_dir']))) {
220
@putenv('LANG='.$HTTP_LANG); # e.g. LANG=de_DE
221
$HTTP_LANG .= '.UTF-8';
222
setlocale(LC_ALL,$HTTP_LANG); # set LC_ALL to de_DE
264
putenv('LANG='.$lang); # e.g. LANG=de_DE
266
setlocale(LC_ALL,$lang); # set LC_ALL to de_DE
223
267
bindtextdomain('messages',LANGDIR);
224
268
bind_textdomain_codeset('messages','UTF-8');
225
269
textdomain('messages');
230
#todo: Generate an error if language doesnt exist.
274
#todo Generate an error if language doesnt exist.
234
278
# Grab the language file configured in config.php
235
#todo: Generate an error if language doesnt exist.
236
if ($language != null) {
237
if (strcmp($language,'english') == 0)
279
#todo Generate an error if language doesnt exist.
280
if ($app['language'] != null) {
281
if (strcmp($app['language'],'english') == 0)
282
$app['language'] = 'en_GB';
241
@putenv('LANG='.$language); # e.g. LANG=de_DE
242
$language .= '.UTF-8';
243
setlocale(LC_ALL,$language); # set LC_ALL to de_DE
285
putenv('LANG='.$app['language']); # e.g. LANG=de_DE
286
$app['language'] .= '.UTF-8';
287
setlocale(LC_ALL,$app['language']); # set LC_ALL to de_DE
244
288
bindtextdomain('messages',LANGDIR);
245
289
bind_textdomain_codeset('messages','UTF-8');
246
290
textdomain('messages');
260
304
$slashes_stripped = true;
264
* Create our application repository variable.
266
if (isset($_REQUEST['server_id'])) {
267
$ldapserver = $_SESSION[APPCONFIG]->ldapservers->Instance($_REQUEST['server_id']);
269
if (isset($_SESSION[APPCONFIG]->ldapservers) && is_object($_SESSION[APPCONFIG]->ldapservers))
270
$ldapserver = $_SESSION[APPCONFIG]->ldapservers->Instance(null);
307
# Create our application repository variable.
308
$app['server'] = $_SESSION[APPCONFIG]->getServer(get_request('server_id','REQUEST'));
274
311
* Look/evaluate our timeout
276
if (isset($ldapserver) && is_object($ldapserver) && method_exists($ldapserver,'haveAuthInfo')) {
277
if ($ldapserver->haveAuthInfo() && isset($ldapserver->auth_type) && ! in_array($ldapserver->auth_type,array('config','http'))) {
279
* If time out value has been reached:
281
* - put $server_id in array of recently timed out servers
283
if (function_exists('session_timed_out') && session_timed_out($ldapserver)) {
285
# If $session_timeout not defined, use ( session_cache_expire() - 1 )
286
$session_timeout = $ldapserver->session_timeout ? $ldapserver->session_timeout : session_cache_expire()-1;
288
system_message(array(
289
'title'=>_('Session Timed Out'),
290
'body'=>sprintf('%s %s %s',
291
_('Your Session timed out after'),$session_timeout,
292
_('min. of inactivity. You have been automatically logged out.')),
293
'type'=>'info'),'index.php');
298
# Update $_SESSION['activity'] for timeout and automatic logout feature
299
if ($ldapserver->haveAuthInfo() && function_exists('set_lastactivity'))
300
set_lastactivity($ldapserver);
313
if (! $app['server']->isSessionValid()) {
314
system_message(array(
315
'title'=>_('Session Timed Out'),
316
'body'=>sprintf('%s %s %s',
317
_('Your Session timed out after'),$app['server']->getValue('login','timeout'),
318
_('min. of inactivity. You have been automatically logged out.')),
319
'type'=>'info'),sprintf('index.php?server_id=%s&refresh=SID_%s',$app['server']->getIndex(),$app['server']->getIndex()));
324
# If syslog is enabled, we need to include the supporting file.
325
if ($_SESSION[APPCONFIG]->getValue('debug','syslog'))
326
require LIBDIR.'syslog.php';
304
329
* At this point we have read all our additional function PHP files and our configuration.
305
330
* If we are using hooks, run the session_init hook.