2010-10-29 13:19:51 +00:00
|
|
|
<?php
|
2010-12-06 20:00:18 +00:00
|
|
|
/**
|
|
|
|
* Do authentication of users and session management
|
|
|
|
*
|
|
|
|
* @category DMS
|
2013-02-14 11:10:53 +00:00
|
|
|
* @package SeedDMS
|
2010-12-06 20:00:18 +00:00
|
|
|
* @license GPL 2
|
|
|
|
* @version @version@
|
|
|
|
* @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2002-2005 Markus Westphal,
|
|
|
|
* 2006-2008 Malcolm Cowe, 2010 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
2010-10-29 13:19:51 +00:00
|
|
|
|
2016-01-29 15:48:21 +00:00
|
|
|
require_once("inc.ClassSession.php");
|
2021-04-18 17:40:13 +00:00
|
|
|
require_once("inc.ClassAccessOperation.php");
|
2016-01-29 15:48:21 +00:00
|
|
|
|
2014-03-21 07:07:18 +00:00
|
|
|
$refer = $_SERVER["REQUEST_URI"];
|
2010-10-29 13:19:51 +00:00
|
|
|
if (!strncmp("/op", $refer, 3)) {
|
|
|
|
$refer="";
|
2014-03-21 07:07:18 +00:00
|
|
|
} else {
|
|
|
|
$refer = urlencode($refer);
|
2010-10-29 13:19:51 +00:00
|
|
|
}
|
2011-01-11 08:03:38 +00:00
|
|
|
if (!isset($_COOKIE["mydms_session"])) {
|
2016-01-29 15:48:21 +00:00
|
|
|
if($settings->_enableGuestLogin && $settings->_enableGuestAutoLogin) {
|
|
|
|
$session = new SeedDMS_Session($db);
|
|
|
|
if(!$dms_session = $session->create(array('userid'=>$settings->_guestID, 'theme'=>$settings->_theme, 'lang'=>$settings->_language))) {
|
|
|
|
header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
$resArr = $session->load($dms_session);
|
2016-02-02 09:02:13 +00:00
|
|
|
} elseif($settings->_autoLoginUser) {
|
2015-07-14 19:23:54 +00:00
|
|
|
if(!($user = $dms->getUser($settings->_autoLoginUser))/* || !$user->isGuest()*/) {
|
|
|
|
header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
$theme = $user->getTheme();
|
2020-11-16 15:55:56 +00:00
|
|
|
if (strlen($theme)==0 || !empty($settings->_overrideTheme)) {
|
2015-07-14 19:23:54 +00:00
|
|
|
$theme = $settings->_theme;
|
2020-11-16 15:55:56 +00:00
|
|
|
// $user->setTheme($theme);
|
2015-07-14 19:23:54 +00:00
|
|
|
}
|
|
|
|
$lang = $user->getLanguage();
|
|
|
|
if (strlen($lang)==0) {
|
|
|
|
$lang = $settings->_language;
|
|
|
|
$user->setLanguage($lang);
|
|
|
|
}
|
|
|
|
$session = new SeedDMS_Session($db);
|
2016-02-02 09:02:13 +00:00
|
|
|
if(!$dms_session = $session->create(array('userid'=>$user->getID(), 'theme'=>$theme, 'lang'=>$lang))) {
|
2015-07-14 19:23:54 +00:00
|
|
|
header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer);
|
|
|
|
exit;
|
|
|
|
}
|
2016-02-02 09:02:13 +00:00
|
|
|
$resArr = $session->load($dms_session);
|
2015-07-14 19:23:54 +00:00
|
|
|
} else {
|
|
|
|
header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Load session */
|
|
|
|
$dms_session = $_COOKIE["mydms_session"];
|
|
|
|
$session = new SeedDMS_Session($db);
|
|
|
|
if(!$resArr = $session->load($dms_session)) {
|
2020-05-26 12:51:58 +00:00
|
|
|
setcookie("mydms_session", $dms_session, time()-3600, $settings->_httpRoot); //delete cookie
|
2015-07-14 19:23:54 +00:00
|
|
|
header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer);
|
|
|
|
exit;
|
|
|
|
}
|
2016-02-02 09:02:13 +00:00
|
|
|
}
|
2014-05-22 04:37:56 +00:00
|
|
|
|
2016-02-02 09:02:13 +00:00
|
|
|
/* Update last access time */
|
2017-03-23 16:25:54 +00:00
|
|
|
if((int)$resArr['lastAccess']+60 < time())
|
|
|
|
$session->updateAccess($dms_session);
|
2015-07-14 19:34:51 +00:00
|
|
|
|
2016-02-02 09:02:13 +00:00
|
|
|
/* Load user data */
|
|
|
|
$user = $dms->getUser($resArr["userID"]);
|
|
|
|
if (!is_object($user)) {
|
2020-05-26 12:51:58 +00:00
|
|
|
setcookie("mydms_session", $dms_session, time()-3600, $settings->_httpRoot); //delete cookie
|
2016-02-02 09:02:13 +00:00
|
|
|
header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($user->isAdmin()) {
|
|
|
|
if($resArr["su"]) {
|
|
|
|
$user = $dms->getUser($resArr["su"]);
|
|
|
|
} else {
|
2016-11-17 15:00:08 +00:00
|
|
|
// $session->resetSu();
|
2013-04-19 06:44:51 +00:00
|
|
|
}
|
2010-10-29 13:19:51 +00:00
|
|
|
}
|
2016-02-02 09:02:13 +00:00
|
|
|
$theme = $resArr["theme"];
|
|
|
|
$lang = $resArr["language"];
|
2010-10-29 13:19:51 +00:00
|
|
|
|
2010-11-15 12:01:21 +00:00
|
|
|
$dms->setUser($user);
|
2020-12-18 09:08:30 +00:00
|
|
|
if($settings->_useHomeAsRootFolder && !$user->isAdmin() && $user->getHomeFolder()) {
|
|
|
|
$dms->checkWithinRootDir = true;
|
|
|
|
$dms->setRootFolderID($user->getHomeFolder());
|
|
|
|
}
|
2016-03-09 17:25:17 +00:00
|
|
|
|
2016-05-03 05:03:31 +00:00
|
|
|
/* Include additional language file for view
|
|
|
|
* This file must set $LANG[xx][]
|
2013-01-24 08:02:58 +00:00
|
|
|
*/
|
2015-07-14 19:23:54 +00:00
|
|
|
if(file_exists($settings->_rootDir . "view/".$theme."/languages/" . $lang . "/lang.inc")) {
|
|
|
|
include $settings->_rootDir . "view/".$theme."/languages/" . $lang . "/lang.inc";
|
2012-12-13 21:33:15 +00:00
|
|
|
}
|
2010-10-29 13:19:51 +00:00
|
|
|
|
2012-08-28 06:36:33 +00:00
|
|
|
/* Check if password needs to be changed because it expired. If it needs
|
|
|
|
* to be changed redirect to out/out.ForcePasswordChange.php. Do this
|
|
|
|
* check only if password expiration is turned on, we are not on the
|
2023-03-29 18:57:48 +00:00
|
|
|
* page to change the password or the page that changes the password, the
|
|
|
|
* current user is not admin, and no user substitution has occured. */
|
2012-08-28 06:36:33 +00:00
|
|
|
|
2023-03-29 18:57:48 +00:00
|
|
|
if (!$user->isAdmin() && !$resArr['su']) {
|
|
|
|
if($settings->_passwordExpiration > 0) {
|
2018-11-08 15:38:32 +00:00
|
|
|
if(basename($_SERVER['SCRIPT_NAME']) != 'out.ForcePasswordChange.php' && basename($_SERVER['SCRIPT_NAME']) != 'op.EditUserData.php' && basename($_SERVER['SCRIPT_NAME']) != 'op.Logout.php') {
|
2012-08-28 06:36:33 +00:00
|
|
|
$pwdexp = $user->getPwdExpiration();
|
2023-03-29 18:57:48 +00:00
|
|
|
if($pwdexp && substr($pwdexp, 0, 10) != '0000-00-00') {
|
2012-08-28 06:36:33 +00:00
|
|
|
$pwdexpts = strtotime($pwdexp); // + $pwdexp*86400;
|
|
|
|
if($pwdexpts > 0 && $pwdexpts < time()) {
|
|
|
|
header("Location: ../out/out.ForcePasswordChange.php");
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-06 10:32:45 +00:00
|
|
|
|
|
|
|
/* Update cookie lifetime */
|
|
|
|
if($settings->_cookieLifetime) {
|
|
|
|
$lifetime = time() + intval($settings->_cookieLifetime);
|
2021-07-07 07:46:29 +00:00
|
|
|
setcookie("mydms_session", $dms_session, $lifetime, $settings->_httpRoot, null, false, true);
|
2014-03-06 10:32:45 +00:00
|
|
|
}
|