2010-12-02 23:34:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
2019-04-15 14:02:16 -04:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2022-11-16 16:20:43 +00:00
|
|
|
use Illuminate\Support\Facades\Crypt;
|
2019-04-15 14:02:16 -04:00
|
|
|
use ProcessMaker\BusinessModel\User;
|
2017-08-14 16:13:46 -04:00
|
|
|
use ProcessMaker\Core\System;
|
2017-08-01 12:16:06 -04:00
|
|
|
use ProcessMaker\Plugins\PluginRegistry;
|
|
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
try {
|
2025-05-06 19:51:37 -04:00
|
|
|
// Initialize variables for username and password
|
2015-11-27 15:38:27 -04:00
|
|
|
$usr = '';
|
|
|
|
|
$pwd = '';
|
|
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Determine the login URL based on the HTTP referer
|
2025-04-18 07:31:14 +00:00
|
|
|
if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], 'home/login') !== false) {
|
2015-11-27 15:38:27 -04:00
|
|
|
$urlLogin = '../home/login';
|
|
|
|
|
} else {
|
|
|
|
|
$urlLogin = (substr(SYS_SKIN, 0, 2) !== 'ux')? 'login' : '../main/login';
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Set cookie options for session management
|
2021-11-26 15:58:35 +00:00
|
|
|
$cookieOptions = Bootstrap::buildCookieOptions(['expires' => time() + (24 * 60 * 60)]);
|
2025-05-06 19:51:37 -04:00
|
|
|
|
|
|
|
|
// Check if single sign-on is not enabled
|
2012-07-04 19:01:31 -04:00
|
|
|
if (!$RBAC->singleSignOn) {
|
2025-05-06 19:51:37 -04:00
|
|
|
// Set a cookie to indicate single sign-on status
|
2021-11-26 15:58:35 +00:00
|
|
|
setcookie('singleSignOn', '0', $cookieOptions);
|
2025-05-06 19:51:37 -04:00
|
|
|
|
|
|
|
|
// Check if the form data is set
|
2012-07-04 19:01:31 -04:00
|
|
|
if (!isset($_POST['form']) ) {
|
|
|
|
|
G::SendTemporalMessage ('ID_USER_HAVENT_RIGHTS_SYSTEM', 'error');
|
|
|
|
|
G::header('Location: login');
|
|
|
|
|
die();
|
|
|
|
|
}
|
2011-08-24 19:30:03 -04:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Retrieve the form data
|
2012-07-04 19:01:31 -04:00
|
|
|
$frm = $_POST['form'];
|
2011-08-24 19:34:44 -04:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Check if the user is changing their password
|
2019-04-15 14:02:16 -04:00
|
|
|
$changePassword = false;
|
|
|
|
|
if (isset($_POST['form']['__USR_PASSWORD_CHANGE__'])) {
|
|
|
|
|
$value = Cache::pull($_POST['form']['__USR_PASSWORD_CHANGE__']);
|
|
|
|
|
$changePassword = !empty($value);
|
|
|
|
|
if ($changePassword === true) {
|
|
|
|
|
$_POST['form']['USER_ENV'] = $value['userEnvironment'];
|
|
|
|
|
$_POST['form']['BROWSER_TIME_ZONE_OFFSET'] = $value['browserTimeZoneOffset'];
|
|
|
|
|
$frm['USR_USERNAME'] = $value['usrUsername'];
|
|
|
|
|
$frm['USR_PASSWORD'] = $value['usrPassword'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Process the username and password from the form data
|
2012-07-04 19:01:31 -04:00
|
|
|
if (isset($frm['USR_USERNAME'])) {
|
2025-05-06 19:51:37 -04:00
|
|
|
$usr = mb_strtolower(trim($frm['USR_USERNAME']), 'UTF-8'); // Convert to lowercase
|
|
|
|
|
$pwd = rtrim($frm['USR_PASSWORD']); // Remove trailing spaces
|
2012-07-04 19:01:31 -04:00
|
|
|
}
|
2025-03-28 13:16:06 +00:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Clear any previous LDAP error messages
|
|
|
|
|
Cache::put('ldapMessageError', '', 120); // Set cache for 120 seconds.
|
|
|
|
|
$uid = $RBAC->VerifyLogin($usr, $pwd); // Verify user credentials
|
|
|
|
|
$ldapMessageError = Cache::pull('ldapMessageError'); // Retrieve LDAP error message if any
|
2012-07-04 19:01:31 -04:00
|
|
|
$RBAC->cleanSessionFiles(72); //cleaning session files older than 72 hours
|
|
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Handle different cases based on the user ID returned
|
2012-07-04 19:01:31 -04:00
|
|
|
switch ($uid) {
|
2025-05-06 19:51:37 -04:00
|
|
|
case -1: // The user does doesn't exist
|
2013-03-04 11:32:49 -04:00
|
|
|
$errLabel = 'WRONG_LOGIN_CREDENTIALS';
|
2012-07-04 19:01:31 -04:00
|
|
|
break;
|
2025-05-06 19:51:37 -04:00
|
|
|
case -2: // Incorrect password
|
2013-03-04 11:32:49 -04:00
|
|
|
$errLabel = 'WRONG_LOGIN_CREDENTIALS';
|
2012-07-04 19:01:31 -04:00
|
|
|
if (isset($_SESSION['__AUTH_ERROR__'])) {
|
|
|
|
|
G::SendMessageText($_SESSION['__AUTH_ERROR__'], "warning");
|
|
|
|
|
unset($_SESSION['__AUTH_ERROR__']);
|
2014-07-03 10:32:25 -04:00
|
|
|
}
|
2012-07-04 19:01:31 -04:00
|
|
|
break;
|
2025-05-06 19:51:37 -04:00
|
|
|
case -3: // User is inactive
|
2012-07-04 19:01:31 -04:00
|
|
|
require_once 'classes/model/Users.php';
|
2012-09-13 14:54:38 -04:00
|
|
|
$user = new Users();
|
2012-07-04 19:01:31 -04:00
|
|
|
$aUser = $user->loadByUsernameInArray($usr);
|
2012-02-24 19:32:24 -04:00
|
|
|
|
2012-07-04 19:01:31 -04:00
|
|
|
switch ($aUser['USR_STATUS']) {
|
|
|
|
|
case 'VACATION':
|
2012-09-13 14:54:38 -04:00
|
|
|
$uid = $aUser['USR_UID'];
|
|
|
|
|
$RBAC->changeUserStatus($uid, 1);
|
|
|
|
|
$aUser['USR_STATUS'] = 'ACTIVE';
|
|
|
|
|
$user->update($aUser);
|
2012-07-04 19:01:31 -04:00
|
|
|
break;
|
|
|
|
|
case 'INACTIVE':
|
|
|
|
|
$errLabel = 'ID_USER_INACTIVE';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
//The Due date is finished
|
2025-05-06 19:51:37 -04:00
|
|
|
case -4: // User's due date is expired
|
2012-07-04 19:01:31 -04:00
|
|
|
$errLabel = 'ID_USER_INACTIVE_BY_DATE';
|
|
|
|
|
break;
|
2025-05-06 19:51:37 -04:00
|
|
|
case -5: // Invalid authentication source
|
2012-07-04 19:01:31 -04:00
|
|
|
$errLabel = 'ID_AUTHENTICATION_SOURCE_INVALID';
|
|
|
|
|
break;
|
2025-05-06 19:51:37 -04:00
|
|
|
case -6: // Inactive role
|
2013-12-09 14:58:41 -04:00
|
|
|
$errLabel = 'ID_ROLE_INACTIVE';
|
|
|
|
|
break;
|
2025-05-06 19:51:37 -04:00
|
|
|
case -7: // Specific authentication error
|
2014-12-03 13:42:09 -04:00
|
|
|
$errLabel = 'ID_LECA';
|
|
|
|
|
break;
|
2011-08-24 19:30:03 -04:00
|
|
|
}
|
2012-02-24 19:32:24 -04:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Default to wrong credentials if no user ID is set
|
2012-07-04 19:01:31 -04:00
|
|
|
if ( !isset($uid) ) {
|
|
|
|
|
$uid = -1;
|
2013-03-04 11:32:49 -04:00
|
|
|
$errLabel = 'WRONG_LOGIN_CREDENTIALS';
|
2011-08-24 19:30:03 -04:00
|
|
|
}
|
2012-02-24 19:32:24 -04:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Store previous usernames for tracking failed logins
|
2014-09-23 17:16:31 -04:00
|
|
|
$_SESSION["USERNAME_PREVIOUS1"] = (isset($_SESSION["USERNAME_PREVIOUS2"]))? $_SESSION["USERNAME_PREVIOUS2"] : "";
|
2014-09-19 10:45:24 -04:00
|
|
|
$_SESSION["USERNAME_PREVIOUS2"] = $usr;
|
2022-11-16 16:09:50 -04:00
|
|
|
$_SESSION["FAILED_LOGINS"] = is_numeric(Cache::get("FAILED_LOGINS{$usr}")) ? Cache::get("FAILED_LOGINS{$usr}") : 0;
|
2014-09-19 10:45:24 -04:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Handled failed login attempts
|
2012-07-04 19:01:31 -04:00
|
|
|
if (!isset($uid) || $uid < 0) {
|
2014-09-19 10:45:24 -04:00
|
|
|
if ($_SESSION["USERNAME_PREVIOUS1"] != "" && $_SESSION["USERNAME_PREVIOUS2"] != "" && $_SESSION["USERNAME_PREVIOUS1"] != $_SESSION["USERNAME_PREVIOUS2"]) {
|
|
|
|
|
$_SESSION["FAILED_LOGINS"] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-11 12:07:24 -04:00
|
|
|
if (isset($_SESSION['FAILED_LOGINS']) && ($uid == -1 || $uid == -2)) {
|
2012-07-04 19:01:31 -04:00
|
|
|
$_SESSION['FAILED_LOGINS']++;
|
|
|
|
|
}
|
|
|
|
|
if (!defined('PPP_FAILED_LOGINS')) {
|
|
|
|
|
define('PPP_FAILED_LOGINS', 0);
|
|
|
|
|
}
|
|
|
|
|
if (PPP_FAILED_LOGINS > 0) {
|
|
|
|
|
if ($_SESSION['FAILED_LOGINS'] >= PPP_FAILED_LOGINS) {
|
2025-05-06 19:51:37 -04:00
|
|
|
// Disable user account after too many failed login attempts
|
2012-07-04 19:01:31 -04:00
|
|
|
$oConnection = Propel::getConnection('rbac');
|
2014-09-17 10:57:33 -04:00
|
|
|
$oStatement = $oConnection->prepareStatement("SELECT USR_UID FROM RBAC_USERS WHERE USR_USERNAME = '" . $usr . "'");
|
2012-07-04 19:01:31 -04:00
|
|
|
$oDataset = $oStatement->executeQuery();
|
|
|
|
|
if ($oDataset->next()) {
|
|
|
|
|
$sUserUID = $oDataset->getString('USR_UID');
|
2025-05-06 19:51:37 -04:00
|
|
|
// Update user status to inactive
|
2012-07-04 19:01:31 -04:00
|
|
|
$oConnection = Propel::getConnection('rbac');
|
2014-09-17 10:57:33 -04:00
|
|
|
$oStatement = $oConnection->prepareStatement("UPDATE RBAC_USERS SET USR_STATUS = 0 WHERE USR_UID = '" . $sUserUID . "'");
|
2012-07-04 19:01:31 -04:00
|
|
|
$oStatement->executeQuery();
|
|
|
|
|
$oConnection = Propel::getConnection('workflow');
|
|
|
|
|
$oStatement = $oConnection->prepareStatement("UPDATE USERS SET USR_STATUS = 'INACTIVE' WHERE USR_UID = '" . $sUserUID . "'");
|
|
|
|
|
$oStatement->executeQuery();
|
|
|
|
|
unset($_SESSION['FAILED_LOGINS']);
|
2022-11-16 16:09:50 -04:00
|
|
|
Cache::forget("FAILED_LOGINS{$usr}");
|
2014-07-11 12:07:24 -04:00
|
|
|
$errLabel = G::LoadTranslation('ID_ACCOUNT') . ' "' . $usr . '" ' . G::LoadTranslation('ID_ACCOUNT_DISABLED_CONTACT_ADMIN');
|
2012-07-04 19:01:31 -04:00
|
|
|
}
|
2025-05-06 19:51:37 -04:00
|
|
|
// Log failed authentication attempts
|
2017-10-10 12:33:25 -04:00
|
|
|
$message = "| Many failed authentication attempts for USER: " . $usr . " | IP: " . G::getIpAddress() . " | WS: " . config("system.workspace");
|
2014-10-03 11:09:45 -04:00
|
|
|
$message .= " | BROWSER: " . $_SERVER['HTTP_USER_AGENT'];
|
2014-07-11 12:07:24 -04:00
|
|
|
|
|
|
|
|
G::log($message, PATH_DATA, 'loginFailed.log');
|
2012-07-04 19:01:31 -04:00
|
|
|
}
|
|
|
|
|
}
|
2011-08-24 19:30:03 -04:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Redirect to login page with error message
|
2012-07-04 19:01:31 -04:00
|
|
|
if (strpos($_SERVER['HTTP_REFERER'], 'home/login') !== false) {
|
2015-11-27 15:38:27 -04:00
|
|
|
$d = serialize(['u' => $usr, 'p' => $pwd, 'm' => G::LoadTranslation($errLabel)]);
|
2022-11-16 16:20:43 +00:00
|
|
|
$urlLogin = $urlLogin . '?d=' . Crypt::encryptString($d);
|
2012-07-04 19:01:31 -04:00
|
|
|
} else {
|
2020-10-07 22:59:04 -04:00
|
|
|
if (empty($ldapMessageError)) {
|
|
|
|
|
G::SendTemporalMessage($errLabel, "warning");
|
|
|
|
|
} else {
|
|
|
|
|
G::SendTemporalMessage($ldapMessageError, "warning", "string");
|
|
|
|
|
}
|
2012-07-04 19:01:31 -04:00
|
|
|
}
|
|
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Append URL if provided
|
2016-08-17 17:04:14 -04:00
|
|
|
$u = (array_key_exists('form', $_POST) && array_key_exists('URL', $_POST['form']))? 'u=' . urlencode(htmlspecialchars_decode($_POST['form']['URL'])) : '';
|
2016-07-28 18:27:20 -04:00
|
|
|
|
|
|
|
|
if ($u != '') {
|
|
|
|
|
$urlLogin = $urlLogin . ((preg_match('/^.+\?.+$/', $urlLogin))? '&' : '?') . $u;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 15:38:27 -04:00
|
|
|
G::header('Location: ' . $urlLogin);
|
|
|
|
|
exit(0);
|
2012-03-29 16:42:09 -04:00
|
|
|
}
|
2012-02-24 19:32:24 -04:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Initialize user session if uid is valid
|
2012-07-04 19:01:31 -04:00
|
|
|
if (!isset( $_SESSION['WORKSPACE'] ) ) {
|
2017-10-10 12:33:25 -04:00
|
|
|
$_SESSION['WORKSPACE'] = config("system.workspace");
|
2012-07-04 19:01:31 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-07-04 19:01:31 -04:00
|
|
|
//Execute the SSO Script from plugin
|
2017-08-01 12:16:06 -04:00
|
|
|
$oPluginRegistry = PluginRegistry::loadSingleton();
|
2014-09-25 16:55:16 -04:00
|
|
|
$lSession="";
|
|
|
|
|
$loginInfo = new loginInfo ($usr, $pwd, $lSession );
|
2012-07-04 19:01:31 -04:00
|
|
|
if ($oPluginRegistry->existsTrigger ( PM_LOGIN )) {
|
|
|
|
|
$oPluginRegistry->executeTriggers ( PM_LOGIN , $loginInfo );
|
|
|
|
|
}
|
2017-10-13 07:57:22 -04:00
|
|
|
initUserSession($uid, $usr);
|
2012-07-04 19:01:31 -04:00
|
|
|
} else {
|
2025-05-06 19:51:37 -04:00
|
|
|
// Handle single sign-on case
|
2021-11-26 15:58:35 +00:00
|
|
|
setcookie('singleSignOn', '1', $cookieOptions);
|
2012-07-04 19:01:31 -04:00
|
|
|
$uid = $RBAC->userObj->fields['USR_UID'];
|
|
|
|
|
$usr = $RBAC->userObj->fields['USR_USERNAME'];
|
2017-10-13 07:57:22 -04:00
|
|
|
initUserSession($uid, $usr);
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
//Set default Language for the user
|
2015-12-09 17:33:31 -04:00
|
|
|
if (isset($frm['USER_LANG'])) {
|
|
|
|
|
if ($frm['USER_LANG'] != '') {
|
|
|
|
|
$lang = $frm['USER_LANG'];
|
|
|
|
|
if($frm['USER_LANG'] == "default"){
|
2025-05-06 19:51:37 -04:00
|
|
|
//Check the user's default language
|
2015-12-09 17:33:31 -04:00
|
|
|
require_once 'classes/model/Users.php';
|
|
|
|
|
$user = new Users();
|
|
|
|
|
$rsUser = $user->userLanguaje($_SESSION['USER_LOGGED']);
|
|
|
|
|
$rsUser->next();
|
|
|
|
|
$rowUser = $rsUser->getRow();
|
|
|
|
|
if( isset($rowUser["USR_DEFAULT_LANG"]) && $rowUser["USR_DEFAULT_LANG"]!=''){
|
|
|
|
|
$lang = $rowUser["USR_DEFAULT_LANG"];
|
|
|
|
|
} else {
|
2025-05-06 19:51:37 -04:00
|
|
|
//Check the system's default language
|
2015-12-09 17:33:31 -04:00
|
|
|
$oConf = new Configurations();
|
|
|
|
|
$oConf->loadConfig($obj, 'ENVIRONMENT_SETTINGS', '');
|
|
|
|
|
if (isset($oConf->aConfig["login_defaultLanguage"]) && $oConf->aConfig["login_defaultLanguage"] != "") {
|
|
|
|
|
$lang = $oConf->aConfig["login_defaultLanguage"];
|
|
|
|
|
}else{
|
|
|
|
|
if(SYS_LANG != ''){
|
|
|
|
|
$lang = SYS_LANG;
|
|
|
|
|
}else{
|
2025-05-06 19:51:37 -04:00
|
|
|
$lang = 'en'; // Default to English
|
2015-12-09 17:33:31 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$lang = $frm['USER_LANG'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2025-05-06 19:51:37 -04:00
|
|
|
// Set language to system default if not specified
|
2015-12-09 17:33:31 -04:00
|
|
|
if (defined("SYS_LANG") && SYS_LANG != "") {
|
|
|
|
|
$lang = SYS_LANG;
|
|
|
|
|
} else {
|
2025-05-06 19:51:37 -04:00
|
|
|
$lang = 'en'; // Default to English
|
2015-12-09 17:33:31 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Set User Time Zone
|
2015-11-26 20:11:58 -04:00
|
|
|
$user = UsersPeer::retrieveByPK($_SESSION['USER_LOGGED']);
|
|
|
|
|
|
|
|
|
|
if (!is_null($user)) {
|
|
|
|
|
$userTimeZone = $user->getUsrTimeZone();
|
|
|
|
|
if (trim($userTimeZone) == '') {
|
2017-10-10 12:33:25 -04:00
|
|
|
$arraySystemConfiguration = System::getSystemConfiguration('', '', config("system.workspace"));
|
2015-11-26 20:11:58 -04:00
|
|
|
|
|
|
|
|
$userTimeZone = $arraySystemConfiguration['time_zone'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$_SESSION['USR_TIME_ZONE'] = $userTimeZone;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Check and set browser time zone
|
2025-04-18 07:31:14 +00:00
|
|
|
if (isset($_SESSION['__SYSTEM_UTC_TIME_ZONE__']) && $_SESSION['__SYSTEM_UTC_TIME_ZONE__']) {
|
|
|
|
|
$dateTime = new \ProcessMaker\Util\DateTime();
|
2015-11-27 15:38:27 -04:00
|
|
|
|
2025-04-18 07:31:14 +00:00
|
|
|
$timeZoneOffset = $dateTime->getTimeZoneOffsetByTimeZoneId($_SESSION['USR_TIME_ZONE']);
|
2015-11-27 15:38:27 -04:00
|
|
|
|
2025-04-18 07:31:14 +00:00
|
|
|
if ($timeZoneOffset === false || $timeZoneOffset != (int)($_POST['form']['BROWSER_TIME_ZONE_OFFSET'])) {
|
|
|
|
|
$_SESSION['__TIME_ZONE_FAILED__'] = true;
|
|
|
|
|
$_SESSION['BROWSER_TIME_ZONE'] = $dateTime->getTimeZoneIdByTimeZoneOffset((int)$_POST['form']['BROWSER_TIME_ZONE_OFFSET'], false);
|
|
|
|
|
} else {
|
|
|
|
|
$_SESSION['__TIME_ZONE_FAILED__'] = False;
|
2015-11-27 15:38:27 -04:00
|
|
|
}
|
2025-04-18 07:31:14 +00:00
|
|
|
}
|
2015-11-27 15:38:27 -04:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Load user data and permissions
|
2012-07-04 19:01:31 -04:00
|
|
|
$aUser = $RBAC->userObj->load($_SESSION['USER_LOGGED']);
|
|
|
|
|
$RBAC->loadUserRolePermission($RBAC->sSystem, $_SESSION['USER_LOGGED']);
|
2025-05-06 19:51:37 -04:00
|
|
|
$_SESSION['USR_FULLNAME'] = $aUser['USR_FIRSTNAME'] . ' ' . $aUser['USR_LASTNAME']; // Store user's full name in session
|
2011-08-24 19:30:03 -04:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Clear failed login attempts
|
2012-07-04 19:01:31 -04:00
|
|
|
unset($_SESSION['FAILED_LOGINS']);
|
2022-11-16 16:09:50 -04:00
|
|
|
Cache::forget("FAILED_LOGINS{$usr}");
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-07-04 19:01:31 -04:00
|
|
|
// Assign the uid of user to userloggedobj
|
|
|
|
|
$RBAC->loadUserRolePermission($RBAC->sSystem, $uid);
|
2017-10-05 12:20:25 -04:00
|
|
|
$res = $RBAC->userCanAccess('PM_LOGIN/strict');
|
2012-07-04 19:01:31 -04:00
|
|
|
if ($res != 1 ) {
|
|
|
|
|
if ($res == -2) {
|
|
|
|
|
G::SendTemporalMessage ('ID_USER_HAVENT_RIGHTS_SYSTEM', "error");
|
|
|
|
|
} else {
|
|
|
|
|
G::SendTemporalMessage ('ID_USER_HAVENT_RIGHTS_PAGE', "error");
|
|
|
|
|
}
|
|
|
|
|
G::header ("location: login.html");
|
|
|
|
|
die;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-07-04 19:01:31 -04:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Log login attempt in table Login
|
2012-07-04 19:01:31 -04:00
|
|
|
require_once 'classes/model/LoginLog.php';
|
|
|
|
|
$weblog=new LoginLog();
|
|
|
|
|
$aLog['LOG_UID'] = G::generateUniqueID();
|
|
|
|
|
$aLog['LOG_STATUS'] = 'ACTIVE';
|
2014-03-27 10:09:35 -04:00
|
|
|
$aLog['LOG_IP'] = G::getIpAddress();
|
2012-07-04 19:01:31 -04:00
|
|
|
$aLog['LOG_SID'] = session_id();
|
|
|
|
|
$aLog['LOG_INIT_DATE'] = date('Y-m-d H:i:s');
|
2018-10-19 17:01:49 -04:00
|
|
|
$aLog['LOG_CLIENT_HOSTNAME']= System::getServerHost();
|
2012-07-04 19:01:31 -04:00
|
|
|
$aLog['USR_UID'] = $_SESSION['USER_LOGGED'];
|
|
|
|
|
$weblog->create($aLog);
|
2025-05-06 19:51:37 -04:00
|
|
|
// end log
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Save server info for command line environment
|
|
|
|
|
// defining and saving server info, this file has the values of the global array $_SERVER
|
|
|
|
|
// this file is useful for command line environment (no Browser), I mean for triggers, crons and other executed over command line
|
2012-07-04 19:01:31 -04:00
|
|
|
$_CSERVER = $_SERVER;
|
|
|
|
|
unset($_CSERVER['REQUEST_TIME']);
|
|
|
|
|
unset($_CSERVER['REMOTE_PORT']);
|
2025-07-02 12:07:52 -04:00
|
|
|
|
|
|
|
|
$host = '';
|
|
|
|
|
$port = 80;
|
2025-07-02 09:29:27 -04:00
|
|
|
if (!empty($_SERVER['HTTP_HOST'])) {
|
|
|
|
|
$hostParts = explode(':', $_SERVER['HTTP_HOST']);
|
|
|
|
|
|
|
|
|
|
$host = $hostParts[0];
|
|
|
|
|
|
|
|
|
|
if (isset($hostParts[1]) && is_numeric($hostParts[1])) {
|
|
|
|
|
$port = (int)$hostParts[1];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$host = $_SERVER['SERVER_NAME'] ?? 'localhost';
|
|
|
|
|
$port = $_SERVER['SERVER_PORT'] ?? 80;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$_CSERVER['SERVER_PORT'] = (string)$port;
|
|
|
|
|
$_CSERVER['SERVER_NAME'] = (string)$host;
|
|
|
|
|
|
2012-07-04 19:01:31 -04:00
|
|
|
$cput = serialize($_CSERVER);
|
2015-05-10 17:16:34 -04:00
|
|
|
if (!is_file(PATH_DATA_SITE . '.server_info')) {
|
|
|
|
|
file_put_contents(PATH_DATA_SITE . '.server_info', $cput);
|
2012-07-04 19:01:31 -04:00
|
|
|
} else {
|
2015-05-10 17:16:34 -04:00
|
|
|
$c = file_get_contents(PATH_DATA_SITE . '.server_info');
|
2015-03-25 16:22:18 -04:00
|
|
|
if (G::encryptOld($c) != G::encryptOld($cput)) {
|
2015-05-10 17:16:34 -04:00
|
|
|
file_put_contents(PATH_DATA_SITE . '.server_info', $cput);
|
2012-07-04 19:01:31 -04:00
|
|
|
}
|
2012-04-05 12:52:33 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Check password using policy - Start
|
2012-07-04 19:01:31 -04:00
|
|
|
require_once 'classes/model/UsersProperties.php';
|
2018-10-26 16:14:37 -04:00
|
|
|
$userProperty = new UsersProperties();
|
2011-10-11 18:33:06 -04:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Determine the user's default location after login
|
2012-07-04 19:01:31 -04:00
|
|
|
if (isset($_REQUEST['form']['URL']) && $_REQUEST['form']['URL'] != '') {
|
2013-01-08 13:21:40 -04:00
|
|
|
if (isset($_SERVER['HTTP_REFERER'])) {
|
|
|
|
|
if (strpos($_SERVER['HTTP_REFERER'], 'processes/processes_Map?PRO_UID=') !== false) {
|
|
|
|
|
$sLocation = $_SERVER['HTTP_REFERER'];
|
|
|
|
|
} else {
|
2013-11-15 15:29:07 -04:00
|
|
|
$sLocation = G::sanitizeInput($_REQUEST['form']['URL']);
|
2013-01-08 13:21:40 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2013-11-15 15:29:07 -04:00
|
|
|
$sLocation = G::sanitizeInput($_REQUEST['form']['URL']);
|
2013-01-08 13:21:40 -04:00
|
|
|
}
|
2012-07-04 19:01:31 -04:00
|
|
|
} else {
|
|
|
|
|
if (isset($_REQUEST['u']) && $_REQUEST['u'] != '') {
|
2013-11-15 15:29:07 -04:00
|
|
|
$sLocation = G::sanitizeInput($_REQUEST['u']);
|
2012-07-04 19:01:31 -04:00
|
|
|
} else {
|
2018-10-26 16:14:37 -04:00
|
|
|
$sLocation = $userProperty->redirectTo($_SESSION['USER_LOGGED'], $lang);
|
2012-07-04 19:01:31 -04:00
|
|
|
}
|
2011-10-10 12:14:38 -04:00
|
|
|
}
|
2012-07-04 19:01:31 -04:00
|
|
|
|
|
|
|
|
if ($RBAC->singleSignOn) {
|
2019-07-05 16:00:43 -04:00
|
|
|
// Update the User's last login date
|
|
|
|
|
updateUserLastLogin($aLog);
|
2012-07-04 19:01:31 -04:00
|
|
|
G::header('Location: ' . $sLocation);
|
|
|
|
|
die();
|
2011-10-10 12:14:38 -04:00
|
|
|
}
|
2012-04-05 12:52:33 -04:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Load or create user property info
|
2018-10-26 16:14:37 -04:00
|
|
|
$userPropertyInfo = $userProperty->loadOrCreateIfNotExists($_SESSION['USER_LOGGED'], array('USR_PASSWORD_HISTORY' => serialize(array(G::encryptOld($pwd)))));
|
2025-05-06 19:51:37 -04:00
|
|
|
|
|
|
|
|
// Handle password change
|
2019-04-15 14:02:16 -04:00
|
|
|
if ($changePassword === true) {
|
|
|
|
|
$user = new User();
|
|
|
|
|
$currentUser = $user->changePassword($_SESSION['USER_LOGGED'], $_POST['form']['USR_PASSWORD']);
|
2019-07-05 16:00:43 -04:00
|
|
|
// Update the User's last login date
|
|
|
|
|
updateUserLastLogin($aLog);
|
2019-04-15 14:02:16 -04:00
|
|
|
G::header('Location: ' . $currentUser["__REDIRECT_PATH__"]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-05-06 19:51:37 -04:00
|
|
|
|
|
|
|
|
// Validate the password against security policies
|
2018-10-26 16:14:37 -04:00
|
|
|
$errorInPassword = $userProperty->validatePassword(
|
|
|
|
|
$_POST['form']['USR_PASSWORD'],
|
|
|
|
|
$userPropertyInfo['USR_LAST_UPDATE_DATE'],
|
|
|
|
|
$userPropertyInfo['USR_LOGGED_NEXT_TIME']
|
|
|
|
|
);
|
2025-05-06 19:51:37 -04:00
|
|
|
|
|
|
|
|
// Exclude certain policies for non-MySQL authentication types.
|
2020-10-01 20:13:13 -04:00
|
|
|
if (!empty($aUser['USR_AUTH_TYPE'])) {
|
|
|
|
|
$authType = $aUser['USR_AUTH_TYPE'];
|
2023-01-16 11:37:38 -04:00
|
|
|
if (strtolower($authType) != "mysql" && $authType != "") {
|
2020-10-01 20:13:13 -04:00
|
|
|
$policiesToExclude = [
|
|
|
|
|
'ID_PPP_MINIMUM_LENGTH',
|
|
|
|
|
'ID_PPP_MAXIMUM_LENGTH',
|
|
|
|
|
'ID_PPP_NUMERICAL_CHARACTER_REQUIRED',
|
|
|
|
|
'ID_PPP_UPPERCASE_CHARACTER_REQUIRED',
|
|
|
|
|
'ID_PPP_SPECIAL_CHARACTER_REQUIRED'
|
|
|
|
|
];
|
|
|
|
|
$errorInPassword = array_diff($errorInPassword, $policiesToExclude);
|
|
|
|
|
$errorInPassword = array_values($errorInPassword);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-06 19:51:37 -04:00
|
|
|
|
|
|
|
|
//Get the enabled password policies
|
2018-12-11 07:48:44 -04:00
|
|
|
$policiesInPassword = $userProperty->validatePassword('', date('Y-m-d'), $userPropertyInfo['USR_LOGGED_NEXT_TIME'], true);
|
2025-05-06 19:51:37 -04:00
|
|
|
|
2018-10-26 16:14:37 -04:00
|
|
|
//Enable change password from GAP
|
2018-10-11 12:19:57 -04:00
|
|
|
if (!isset($enableChangePasswordAfterNextLogin)) {
|
|
|
|
|
$enableChangePasswordAfterNextLogin = true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Check if the password change is required after the next login
|
2018-10-26 16:14:37 -04:00
|
|
|
if ($enableChangePasswordAfterNextLogin && !empty($errorInPassword)) {
|
2012-07-04 19:01:31 -04:00
|
|
|
if (!defined('NO_DISPLAY_USERNAME')) {
|
|
|
|
|
define('NO_DISPLAY_USERNAME', 1);
|
|
|
|
|
}
|
2025-05-06 19:51:37 -04:00
|
|
|
|
|
|
|
|
// Prepare the message for the login page
|
2018-12-11 07:48:44 -04:00
|
|
|
$messPassword = $policySection = $userProperty->getMessageValidatePassword($policiesInPassword, false);
|
2018-10-26 16:14:37 -04:00
|
|
|
$changePassword = '<span style="font-weight:normal;">';
|
|
|
|
|
if (array_search('ID_PPP_CHANGE_PASSWORD_AFTER_NEXT_LOGIN', $errorInPassword)) {
|
|
|
|
|
$changePassword .= G::LoadTranslation('ID_PPP_CHANGE_PASSWORD_AFTER_NEXT_LOGIN') . '<br/><br/>';
|
2012-07-04 19:01:31 -04:00
|
|
|
}
|
2018-10-26 16:14:37 -04:00
|
|
|
|
2018-12-11 07:48:44 -04:00
|
|
|
$messPassword['DESCRIPTION'] = $changePassword . $policySection['DESCRIPTION'] . '</span>';
|
2012-07-04 19:01:31 -04:00
|
|
|
$G_PUBLISH = new Publisher;
|
2015-09-25 19:55:26 -04:00
|
|
|
$version = explode('.', trim(file_get_contents(PATH_GULLIVER . 'VERSION')));
|
|
|
|
|
$version = isset($version[0]) ? intval($version[0]) : 0;
|
2019-04-15 14:02:16 -04:00
|
|
|
|
2015-09-25 19:55:26 -04:00
|
|
|
if ($version >= 3) {
|
2019-04-15 14:02:16 -04:00
|
|
|
$values = [
|
|
|
|
|
"usrUsername" => $usr,
|
|
|
|
|
"usrPassword" => $pwd,
|
|
|
|
|
"userEnvironment" => config("system.workspace"),
|
|
|
|
|
"browserTimeZoneOffset" => $_POST['form']['BROWSER_TIME_ZONE_OFFSET']
|
|
|
|
|
];
|
|
|
|
|
$messPassword['__USR_PASSWORD_CHANGE__'] = G::generateUniqueID();
|
2025-05-06 19:51:37 -04:00
|
|
|
Cache::put($messPassword['__USR_PASSWORD_CHANGE__'], $values, 120); // Set cache for 120 seconds.
|
2019-04-15 14:02:16 -04:00
|
|
|
$G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/changePasswordpm3', '', $messPassword, 'sysLoginVerify');
|
|
|
|
|
G::RenderPage('publish');
|
|
|
|
|
session_destroy();
|
2018-10-26 16:14:37 -04:00
|
|
|
} else {
|
|
|
|
|
$G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/changePassword', '', $messPassword, 'changePassword');
|
2019-04-15 14:02:16 -04:00
|
|
|
G::RenderPage('publish');
|
2015-05-07 17:13:45 -04:00
|
|
|
}
|
2012-07-04 19:01:31 -04:00
|
|
|
die;
|
2012-04-05 12:52:33 -04:00
|
|
|
}
|
|
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Check if session blocking is enabled
|
2017-10-10 12:33:25 -04:00
|
|
|
$configS = System::getSystemConfiguration('', '', config("system.workspace"));
|
2016-03-15 11:54:22 -04:00
|
|
|
$activeSession = isset($configS['session_block']) ? !(int)$configS['session_block']:true;
|
2016-03-08 18:37:38 -04:00
|
|
|
if ($activeSession){
|
2021-11-26 15:58:35 +00:00
|
|
|
setcookie('PM-TabPrimary', 101010010, $cookieOptions);
|
2016-03-08 18:37:38 -04:00
|
|
|
}
|
|
|
|
|
|
2019-07-05 16:00:43 -04:00
|
|
|
// Update the User's last login date
|
|
|
|
|
updateUserLastLogin($aLog);
|
|
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Execute post-login triggers
|
2017-08-01 12:16:06 -04:00
|
|
|
$oPluginRegistry = PluginRegistry::loadSingleton();
|
2014-07-23 12:12:50 -04:00
|
|
|
if ($oPluginRegistry->existsTrigger ( PM_AFTER_LOGIN )) {
|
|
|
|
|
$oPluginRegistry->executeTriggers ( PM_AFTER_LOGIN , $_SESSION['USER_LOGGED'] );
|
2014-07-23 09:20:31 -04:00
|
|
|
}
|
2014-07-23 12:12:50 -04:00
|
|
|
|
2025-05-06 19:51:37 -04:00
|
|
|
// Redirect to the user's location after successful login
|
2017-06-19 16:21:40 -04:00
|
|
|
G::header('Location: ' . $sLocation);
|
2012-07-04 19:01:31 -04:00
|
|
|
die;
|
2025-05-06 19:51:37 -04:00
|
|
|
|
2012-07-04 19:01:31 -04:00
|
|
|
} catch ( Exception $e ) {
|
2025-05-06 19:51:37 -04:00
|
|
|
// Handle exceptions and display error messages
|
2012-07-04 19:01:31 -04:00
|
|
|
$aMessage['MESSAGE'] = $e->getMessage();
|
|
|
|
|
$G_PUBLISH = new Publisher;
|
|
|
|
|
$G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
|
|
|
|
|
G::RenderPage( 'publish' );
|
|
|
|
|
die;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|