main.php 10.98 KiB
<?php
/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
  Copyright (C) 2003-2010  Cajus Pollmeier
  Copyright (C) 2011-2018  FusionDirectory
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
/* Basic setup, remove eventually registered sessions */
require_once ("../include/php_setup.inc");
require_once ("functions.inc");
require_once ("variables.inc");
/* Set headers */
header('Content-type: text/html; charset=UTF-8');
header('X-XSS-Protection: 1; mode=block');
header('X-Content-Type-Options: nosniff');
header('X-Frame-Options: deny');
/* Set the text domain as 'fusiondirectory' */
$domain = 'fusiondirectory';
bindtextdomain($domain, LOCALE_DIR);
textdomain($domain);
/* Remember everything we did after the last click */
session::start();
reset_errors();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, '_POST');
@DEBUG (DEBUG_SESSION, __LINE__, __FUNCTION__, __FILE__, $_SESSION, '_SESSION');
/* Logged in? Simple security check */
if (!session::global_is_set('connected')) {
  logging::log('security', 'login', '', array(), 'main.php called without session - logging out');
  header ('Location: index.php?message=nosession');
  exit;
CSRFProtection::check();
$ui     = session::global_get('ui');
$config = session::global_get('config');
/* If SSL is forced, just forward to the SSL enabled site */
if (($config->get_cfg_value('forcessl') == 'TRUE') && ($ssl != '')) {
  header ("Location: $ssl");
  exit;
timezone::setDefaultTimezoneFromConfig();
/* Check for invalid sessions */
if (session::global_get('_LAST_PAGE_REQUEST') != '') {
  /* check FusionDirectory.conf for defined session lifetime */
  $max_life = $config->get_cfg_value('sessionLifetime', 60 * 60 * 2);
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
if ($max_life > 0) { /* get time difference between last page reload */ $request_time = (time() - session::global_get('_LAST_PAGE_REQUEST')); /* If page wasn't reloaded for more than max_life seconds * kill session */ if ($request_time > $max_life) { session::destroy(); logging::log('security', 'login', '', array(), 'main.php called with expired session - logging out'); header ('Location: index.php?signout=1&message=expired'); exit; } } } session::global_set('_LAST_PAGE_REQUEST', time()); @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config"); /* Set template compile directory */ $smarty->compile_dir = $config->get_cfg_value("templateCompileDirectory", SPOOL_DIR); Language::init(); /* Prepare plugin list */ pluglist::load(); /* Check Plugin variable */ if (session::global_is_set('plugin_dir')) { $old_plugin_dir = session::global_get('plugin_dir'); } else { $old_plugin_dir = ""; } $plist->gen_menu(); /* check if we are using account expiration */ $smarty->assign("hideMenus", FALSE); if ($config->get_cfg_value("handleExpiredAccounts") == "TRUE") { $expired = $ui->expired_status(); if (($expired == POSIX_WARN_ABOUT_EXPIRATION) && !session::is_set('POSIX_WARN_ABOUT_EXPIRATION__DONE')) { @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $expired, 'This user account ('.$ui->uid.') is about to expire'); // The users password is about to xpire soon, display a warning message. logging::log('security', 'fusiondirectory', '', array(), 'password for user "'.$ui->uid.'" is about to expire'); msg_dialog::display(_('Password change'), _('Your password is about to expire, please change your password!'), INFO_DIALOG); session::set('POSIX_WARN_ABOUT_EXPIRATION__DONE', TRUE); } elseif ($expired == POSIX_FORCE_PASSWORD_CHANGE) { @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $expired, "This user account expired"); // The password is expired, we are now going to enforce a new one from the user. // Hide the FusionDirectory menus to avoid leaving the enforced password change dialog. $smarty->assign("hideMenus", TRUE); $plug = (isset($_GET['plug'])) ? $_GET['plug'] : NULL; // Search for the 'user' class and set its id as active plug. foreach ($plist->dirlist as $key => $value) { if ($value == 'user') { if (!isset($_GET['plug']) || ($_GET['plug'] != $key)) { $_GET['plug'] = $key; msg_dialog::display(_('Warning'), _('Your password has expired, please set a new one.'), WARNING_DIALOG); } break; } } } }
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
if (isset($_GET['plug']) && $plist->plugin_access_allowed($_GET['plug'])) { $plug = validate($_GET['plug']); $plugin_dir = $plist->get_path($plug); session::global_set('plugin_dir', $plugin_dir); if ($plugin_dir == '') { logging::log('security', 'fusiondirectory', '', array(), "main.php called with invalid plug parameter \"$plug\""); header ('Location: index.php?signout=1&message=invalidparameter&plug='.$plug); exit; } } else { /* set to welcome page as default plugin */ session::global_set('plugin_dir', 'welcome'); $plugin_dir = "$BASE_DIR/plugins/generic/welcome"; } /* Handle plugin locks. - Remove the plugin from session if we switched to another. (cleanup) - Remove all created locks if "reset" was posted. - Remove all created locks if we switched to another plugin. */ $cleanup = FALSE; $remove_lock = FALSE; /* Check if we have changed the selected plugin */ if ($old_plugin_dir != $plugin_dir && $old_plugin_dir != "") { if (is_file("$old_plugin_dir/main.inc")) { $cleanup = $remove_lock = TRUE; require ("$old_plugin_dir/main.inc"); $cleanup = $remove_lock = FALSE; } } elseif ((isset($_GET['reset']) && $_GET['reset'] == 1) || isset($_POST['delete_lock'])) { /* Reset was posted, remove all created locks for the current plugin */ $remove_lock = TRUE; } /* Check for sizelimits */ $ui->getSizeLimitHandler()->update(); /* Check for memory */ if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )) { msg_dialog::display(_("Configuration error"), _("Running out of memory!"), WARNING_DIALOG); } /* Load department list when plugin has changed. That is some kind of compromise between speed and beeing up to date */ if (isset($_GET['reset'])) { set_object_info(); } /* show web frontend */ $smarty->assign ("date", date("l, dS F Y H:i:s O")); $lang = session::global_get('lang'); $smarty->assign ('lang', preg_replace('/_.*$/', '', $lang)); $smarty->assign ('rtl', Language::isRTL($lang)); $smarty->assign ('must', '<span class="must">*</span>'); if (isset($plug)) { $plug = "?plug=$plug"; } else { $plug = ""; } if ($ui->ignore_acl_for_current_user()) { $smarty->assign ('username', '<div style="color:#FF0000;">'._('User ACL checks disabled').'</div>&nbsp;'.$ui->uid); } else { $smarty->assign ('username', $ui->uid); } $smarty->assign ("menu", $plist->menu); $smarty->assign ("plug", "$plug");