3
* This code is part of GOsa (http://www.gosa-project.org)
4
* Copyright (C) 2003-2008 GONICUS GmbH
6
* ID: $$Id: main.php 21044 2011-11-07 10:01:32Z hickert $$
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
// Will be used in the "stats" plugin later, to be able calculate the elapsed render time.
27
$overallRenderTimer = microtime(TRUE);
29
/* Basic setup, remove eventually registered sessions */
30
require_once ("../include/php_setup.inc");
31
require_once ("functions.inc");
34
header("Content-type: text/html; charset=UTF-8");
36
/* Set the text domain as 'messages' */
38
bindtextdomain($domain, LOCALE_DIR);
42
/* Remember everything we did after the last click */
44
session::set('errorsAlreadyPosted',array());
45
session::global_set('runtime_cache',array());
46
session::set('limit_exceeded',FALSE);
48
// Count number of page reloads
49
if(!session::is_set('clicks')){
50
session::set('clicks', 0);
52
$clicks = session::get('clicks');
54
session::set('clicks', $clicks);
56
pathNavigator::clear();
58
if ($_SERVER["REQUEST_METHOD"] == "POST"){
59
@DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
61
@DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, session::get_all(), "_SESSION");
63
/* Logged in? Simple security check */
64
if (!session::global_is_set('config')){
65
new log("security","login","",array(),"main.php called without session - logging out") ;
66
header ("Location: logout.php");
70
/* Check for uniqe ip address */
71
$ui= session::global_get('ui');
72
if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
73
new log("security","login","",array(),"main.php called with session which has a changed IP address.") ;
74
header ("Location: logout.php");
77
$config= session::global_get('config');
78
$config->check_and_reload();
79
$config->configRegistry->reload();
81
/* Enable compressed output */
82
if ($config->get_cfg_value("core","sendCompressedOutput") == "true"){
83
ob_start("ob_gzhandler");
86
/* Check for invalid sessions */
87
if(session::global_get('_LAST_PAGE_REQUEST') == ""){
88
session::global_set('_LAST_PAGE_REQUEST',time());
91
/* check GOsa.conf for defined session lifetime */
92
$max_life= $config->get_cfg_value("core","sessionLifetime");
94
/* get time difference between last page reload */
95
$request_time = (time()- session::global_get('_LAST_PAGE_REQUEST'));
97
/* If page wasn't reloaded for more than max_life seconds
100
if($request_time > $max_life){
102
new log("security","login","",array(),"main.php called without session - logging out") ;
103
header ("Location: logout.php");
106
session::global_set('_LAST_PAGE_REQUEST',time());
110
@DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
112
/* Set template compile directory */
113
$smarty->compile_dir= $config->get_cfg_value("core","templateCompileDirectory");
114
$smarty->error_unassigned= true;
117
$reload_navigation = false;
119
/* Set last initialised language to current, browser settings */
120
if(!session::global_is_set('Last_init_lang')){
121
$reload_navigation = true;
122
session::global_set('Last_init_lang',get_browser_language());
125
/* If last language != current force navi reload */
126
$lang= get_browser_language();
127
if(session::global_get('Last_init_lang') != $lang){
128
$reload_navigation = true;
132
session::global_set('Last_init_lang',$lang);
134
/* Preset current main base */
135
if(!session::global_is_set('CurrentMainBase')){
136
session::global_set('CurrentMainBase',get_base_from_people($ui->dn));
140
putenv("LANG=$lang");
141
setlocale(LC_ALL, $lang);
142
$GLOBALS['t_language']= $lang;
143
$GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
145
// Validate LDAP schema if not done already
146
if( $config->boolValueIsTrue('core','schemaCheck') &&
147
!$config->configRegistry->schemaCheckFinished() &&
148
!$config->configRegistry->validateSchemata($force=FALSE,$disableIncompatiblePlugins=TRUE)){
149
$config->configRegistry->displayRequirementErrors();
152
/* Check if the config is up to date */
153
$config->check_config_version();
155
/* Set the text domain as 'messages' */
156
$domain = 'messages';
157
bindtextdomain($domain, LOCALE_DIR);
159
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
161
/* Prepare plugin list */
162
if (!session::global_is_set('plist')){
163
/* Initially load all classes */
164
$class_list= get_declared_classes();
165
foreach ($class_mapping as $class => $path){
166
if (!in_array_strict($class, $class_list)){
167
if (is_readable("$BASE_DIR/$path")){
168
require_once("$BASE_DIR/$path");
170
msg_dialog::display(_("Fatal error"),
171
sprintf(_("Cannot locate file %s - please run %s to fix this"),
172
bold("$BASE_DIR/$path"), bold("update-gosa")), FATAL_ERROR_DIALOG);
178
session::global_set('plist', new pluglist($config, $ui));
180
/* Load ocMapping into userinfo */
181
$tmp= new acl($config, NULL, $ui->dn);
182
$ui->ocMapping= $tmp->ocMapping;
183
session::global_set('ui',$ui);
185
$plist= session::global_get('plist');
187
/* Check for register globals */
188
if (isset($global_check) && $config->boolValueIsTrue("core","forceGlobals")){
190
_("PHP configuration"),
191
_("Fatal error: Register globals is active. Please fix this in order to continue."),
194
new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ;
199
/* Check Plugin variable */
200
if (session::global_is_set('plugin_dir')){
201
$old_plugin_dir= session::global_get('plugin_dir');
207
$plist->gen_headlines();
209
$plist->genPathMenu();
211
/* check if we are using account expiration */
212
$smarty->assign("hideMenus", FALSE);
213
if ($config->boolValueIsTrue("core","handleExpiredAccounts")){
214
$expired= ldap_expired_account($config, $ui->dn, $ui->username);
216
if ($expired == POSIX_WARN_ABOUT_EXPIRATION && !session::is_set('POSIX_WARN_ABOUT_EXPIRATION__DONE')){
218
// The users password is about to xpire soon, display a warning message.
219
new log("security","gosa","",array(),"password for user \"$ui->username\" is about to expire") ;
220
msg_dialog::display(_("Password change"), _("Your password is about to expire, please change your password!"), INFO_DIALOG);
221
session::set('POSIX_WARN_ABOUT_EXPIRATION__DONE', TRUE);
223
} elseif ($expired == POSIX_FORCE_PASSWORD_CHANGE){
225
// The password is expired, we are now going to enforce a new one from the user.
227
// Hide the GOsa menus to avoid leaving the enforced password change dialog.
228
$smarty->assign("hideMenus", TRUE);
229
$plug = (isset($_GET['plug'])) ? $_GET['plug'] : null;
231
// Detect password plugin id:
232
$passId = array_search('password', $plist->pluginList);
233
if($passId !== FALSE){
234
$_GET['plug'] = $passId;
239
$smarty->assign("noMenuMode", count($plist->getRegisteredMenuEntries()) == 0);
240
if (isset($_GET['plug']) && $plist->plugin_access_allowed($_GET['plug'])){
241
$plug= validate($_GET['plug']);
242
$plugin_dir= $plist->get_path($plug);
243
$plugin= $plist->get_class($plug);
244
session::global_set('currentPlugin',$plugin);
245
session::global_set('plugin_dir',$plugin_dir);
246
if ($plugin_dir == ""){
247
new log("security","gosa","",array(),"main.php called with invalid plug parameter \"$plug\"") ;
248
header ("Location: logout.php");
252
session::global_set('plugin_dir',"welcome");
253
session::global_set('currentPlugin','welcome');
254
$plugin_dir= "$BASE_DIR/plugins/generic/welcome";
257
// Display the welcome page for admins (iconmenu) and an info page for those
258
// who are not allowed to adminstrate anything (user)
259
if(count($plist->getRegisteredMenuEntries()) == 0 && session::global_get('currentPlugin') == "welcome"){
260
session::global_set('plugin_dir',"infoPage");
261
session::global_set('currentPlugin','welcome');
262
$plugin_dir= "$BASE_DIR/plugins/generic/infoPage";
265
/* Handle plugin locks.
266
- Remove the plugin from session if we switched to another. (cleanup)
267
- Remove all created locks if "reset" was posted.
268
- Remove all created locks if we switched to another plugin.
273
/* Check if we have changed the selected plugin
275
if(($old_plugin_dir != $plugin_dir && $old_plugin_dir != "") ||
276
(isset($_GET['reset']) && $_GET['reset'] == 1)){
277
if (is_file("$old_plugin_dir/main.inc")){
278
$cleanup = $remove_lock = TRUE;
279
require ("$old_plugin_dir/main.inc");
280
$cleanup = $remove_lock = FALSE;
284
/* Reset was posted, remove all created locks for the current plugin
286
if((isset($_GET['reset']) && $_GET['reset'] == 1) || isset($_POST['delete_lock'])){
290
/* Check for sizelimits */
293
/* Check for memory */
294
if (function_exists("memory_get_usage")){
295
if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
296
msg_dialog::display(_("Configuration error"), _("Running out of memory!"), WARNING_DIALOG);
300
/* Redirect on back event */
301
if ($_SERVER["REQUEST_METHOD"] == "POST"){
303
/* Look for button events that match /^back[0-9]+$/,
304
extract the number and step the correct plugin. */
305
foreach ($_POST as $key => $value){
306
if (preg_match("/^back[0-9]+$/", $key)){
307
$back= substr($key, 4);
308
header ("Location: main.php?plug=$back");
314
/* Redirect on password back event */
315
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
316
header ("Location: main.php");
320
/* Check for multiple windows logout */
321
if ($_SERVER["REQUEST_METHOD"] == "POST"){
322
if (isset($_POST['reset_session'])){
323
header ("Location: logout.php");
329
/* Load department list when plugin has changed. That is some kind of
330
compromise between speed and beeing up to date */
331
if (isset($_GET['reset'])){
335
/* show web frontend */
336
$smarty->assign ("title","GOsa");
337
$smarty->assign ("logo", image(get_template_path("images/logo.png")));
338
$smarty->assign ("logoutimage", get_template_path("images/btn-logout.png"));
339
$smarty->assign ("date", date("l, dS F Y H:i:s O"));
340
$smarty->assign ("lang", preg_replace('/_.*$/', '', $lang));
341
$smarty->assign ("must", "<span class='required'>*</span>");
343
$plug= "?plug=$plug";
347
if (session::global_get('js')==FALSE){
348
$smarty->assign("javascript", "false");
349
$smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
351
$smarty->assign("javascript", "true");
352
$smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
356
$loggedin = sprintf(_("You're logged in as %s"),
357
"<span>".$ui->cn." [".$ui->username."] / ".$config->current['NAME']."</span> ");
358
if($ui->ignore_acl_for_current_user()){
359
$loggedin = "<font color='red'>"._("ACLs are disabled")."</font> ".$loggedin;
362
$smarty->assign ("loggedin", $loggedin);
363
$smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
364
$smarty->assign ("go_base", get_template_path('images/dtree.png'));
365
$smarty->assign ("go_home", get_template_path('images/gohome.png'));
366
$smarty->assign ("go_out", get_template_path('images/logout.png'));
367
$smarty->assign ("go_top", get_template_path('images/go_top.png'));
368
$smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
369
$smarty->assign ("go_left", get_template_path('images/go_left.png'));
370
$smarty->assign ("go_help", get_template_path('images/help.png'));
372
/* reload navigation if language changed*/
373
if($reload_navigation){
376
$smarty->assign ("menu", $plist->gen_menu());
377
$smarty->assign ("plug", "$plug");
380
/* React on clicks */
381
if ($_SERVER["REQUEST_METHOD"] == "POST"){
382
if (isset($_POST['delete_lock']) || isset($_POST['open_readonly'])){
384
/* Set old Post data */
385
if(session::global_is_set('LOCK_VARS_USED_GET')){
386
foreach(session::global_get('LOCK_VARS_USED_GET') as $name => $value){
387
$_GET[$name] = $value;
390
if(session::global_is_set('LOCK_VARS_USED_POST')){
391
foreach(session::global_get('LOCK_VARS_USED_POST') as $name => $value){
392
$_POST[$name] = $value;
395
if(session::global_is_set('LOCK_VARS_USED_REQUEST')){
396
foreach(session::global_get('LOCK_VARS_USED_REQUEST') as $name => $value){
397
$_REQUEST[$name] = $value;
404
if (is_file("$plugin_dir/main.inc")){
406
require ("$plugin_dir/main.inc");
410
sprintf(_("Fatal error: Cannot find any plugin definitions for plugin %s!"), bold($plug)),
416
/* Print_out last ErrorMessage repeated string. */
417
$smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
418
$smarty->assign ("pathMenu", $plist->genPathMenu());
419
$smarty->assign("contents", $display);
420
$smarty->assign("sessionLifetime", $config->get_cfg_value('core','sessionLifetime'));
422
/* If there's some post, take a look if everything is there... */
423
if (isset($_POST) && count($_POST)){
424
if (!isset($_POST['php_c_check'])){
426
_("Configuration Error"),
427
sprintf(_("Fatal error: not all POST variables have been transfered by PHP - please inform your administrator!")),
433
/* Assign erros to smarty */
434
if (session::is_set('errors')){
435
$smarty->assign("errors", session::get('errors'));
437
if ($error_collector != ""){
438
$smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>");
440
$smarty->assign("php_errors", "");
443
/* Set focus to the error button if we've an error message */
445
if (session::is_set('errors') && session::get('errors') != ""){
446
$focus= '<script language="JavaScript" type="text/javascript">';
447
$focus.= 'document.forms[0].error_accept.focus();';
448
$focus.= '</script>';
451
$focus= '<script language="JavaScript" type="text/javascript">';
452
$focus.= 'next_msg_dialog();';
453
$focus.= '</script>';
454
$smarty->assign("focus", $focus);
456
/* Set channel if needed */
457
#TODO: * move all global session calls to global_
458
# * create a new channel where needed (mostly management dialogues)
459
# * remove regulary created channels when not needed anymore
460
# * take a look at external php calls (i.e. get fax, ldif, etc.)
461
# * handle aborted sessions (by pressing anachors i.e. Main, Menu, etc.)
462
# * check lock removals, is "dn" global or not in this case?
463
# * last page request -> global or not?
464
# * check that filters are still global
466
if (isset($_POST['_channel_'])){
467
echo "DEBUG - current channel: ".$_POST['_channel_'];
468
$smarty->assign("channel", $_POST['_channel_']);
470
$smarty->assign("channel", "");
473
$display= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl')).
474
$smarty->fetch(get_template_path('framework.tpl'));
476
/* Save dialog filters and selected base in a cookie.
477
So we may be able to restore the filter an base settings on reload.
481
if(isset($_COOKIE['GOsa_Filter_Settings'])){
482
$cookie = unserialize(base64_decode($_COOKIE['GOsa_Filter_Settings']));
483
}elseif(isset($HTTP_COOKIE_VARS['GOsa_Filter_Settings'])){
484
$cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['GOsa_Filter_Settings']));
488
if($config->get_cfg_value("core","storeFilterSettings") == "true"){
489
$cookie_vars = array("MultiDialogFilters","CurrentMainBase");
490
foreach($cookie_vars as $var){
491
if(session::global_is_set($var)){
492
$cookie[$ui->dn][$var] = session::global_get($var);
495
if(isset($_GET['plug'])){
496
$cookie[$ui->dn]['plug'] = $_GET['plug'];
498
@setcookie("GOsa_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24));
504
/* Save plist and config */
505
session::global_set('plist',$plist);
506
session::global_set('config',$config);
507
session::set('errorsAlreadyPosted',array());
509
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: