Skip to content
Snippets Groups Projects
Verified Commit 1d621add authored by Damien's avatar Damien
Browse files

FEAT #8055 Ldap offline

parent ae5bd9da
No related branches found
No related tags found
No related merge requests found
...@@ -152,26 +152,38 @@ if (!empty($_SESSION['error'])) { ...@@ -152,26 +152,38 @@ if (!empty($_SESSION['error'])) {
} }
} }
if ($prefix_login != '') { if (!empty($prefix_login)) {
$login_admin = $prefix_login.'\\'.$login_admin; $login_admin = $prefix_login.'\\'.$login_admin;
} }
if ($suffix_login != '') { if (!empty($suffix_login)) {
$login_admin = $login_admin.$suffix_login; $login_admin = $login_admin.$suffix_login;
} }
//Try to create a new ldap instance //Try to create a new ldap instance
if (strtolower($type_ldap) == 'openldap') { try {
try { if (strtolower($type_ldap) == 'openldap') {
$ad = new LDAP($domain, $login_admin, $pass, $ssl, $hostname); $ad = new LDAP($domain, $login_admin, $pass, $ssl, $hostname);
} catch (Exception $conFailure) { } else {
echo functions::xssafe($conFailure->getMessage());
exit;
}
} else {
try {
$ad = new LDAP($domain, $login_admin, $pass, $ssl); $ad = new LDAP($domain, $login_admin, $pass, $ssl);
} catch (Exception $conFailure) { }
} catch (Exception $conFailure) {
if (!empty($standardConnect)) {
$res = $sec->login($login, $password);
$_SESSION['user'] = $res['user'];
if (empty($res['error'])) {
\SrcCore\models\SecurityModel::setCookieAuth(['userId' => $login]);
\SrcCore\models\AuthenticationModel::resetFailedAuthentication(['userId' => $login]);
$user = \User\models\UserModel::getByUserId(['userId' => $login, 'select' => ['id']]);
\User\models\UserModel::updatePassword(['id' => $user['id'], 'password' => $password]);
$core->load_menu($_SESSION['modules']);
} else {
$_SESSION['error'] = $res['error'];
}
header('location: '.$_SESSION['config']['businessappurl'].$res['url']);
exit();
} else {
echo functions::xssafe($conFailure->getMessage()); echo functions::xssafe($conFailure->getMessage());
exit; exit;
} }
...@@ -242,7 +254,7 @@ if (!empty($_SESSION['error'])) { ...@@ -242,7 +254,7 @@ if (!empty($_SESSION['error'])) {
$_SESSION['error'] = ''; $_SESSION['error'] = '';
$res = $sec->login($login, $password); $res = $sec->login($login, $password);
$_SESSION['user'] = $res['user']; $_SESSION['user'] = $res['user'];
if ($res['error'] == '') { if (empty($res['error'])) {
\SrcCore\models\SecurityModel::setCookieAuth(['userId' => $login]); \SrcCore\models\SecurityModel::setCookieAuth(['userId' => $login]);
\SrcCore\models\AuthenticationModel::resetFailedAuthentication(['userId' => $login]); \SrcCore\models\AuthenticationModel::resetFailedAuthentication(['userId' => $login]);
$core->load_menu($_SESSION['modules']); $core->load_menu($_SESSION['modules']);
...@@ -250,43 +262,10 @@ if (!empty($_SESSION['error'])) { ...@@ -250,43 +262,10 @@ if (!empty($_SESSION['error'])) {
$_SESSION['error'] = $res['error']; $_SESSION['error'] = $res['error'];
} }
$pathToIPFilter = '';
if (file_exists($_SESSION['config']['corepath'].'custom'.DIRECTORY_SEPARATOR.$_SESSION['custom_override_id'].DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id'].DIRECTORY_SEPARATOR.'xml'.DIRECTORY_SEPARATOR.'ip_filter.xml')) {
$pathToIPFilter = $_SESSION['config']['corepath'].'custom'.DIRECTORY_SEPARATOR.$_SESSION['custom_override_id'].DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id'].DIRECTORY_SEPARATOR.'xml'.DIRECTORY_SEPARATOR.'ip_filter.xml';
} elseif (file_exists('apps'.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id'].DIRECTORY_SEPARATOR.'xml'.DIRECTORY_SEPARATOR.'ip_filter.xml')) {
$pathToIPFilter = 'apps'.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id'].DIRECTORY_SEPARATOR.'xml'.DIRECTORY_SEPARATOR.'ip_filter.xml';
} else {
$ipArray = array();
$ipArray['enabled'] = 'false';
$ipArray['duration'] = '0';
}
$ipArray = array();
$ipArray = $func->object2array(simplexml_load_file($pathToIPFilter));
//print_r($ipArray);
if ($ipArray['enabled'] == 'true') {
$isAllowed = false;
if ($ipArray['IP'] != '') {
$isAllowed = preg_match($ipArray['IP'], $_SERVER['REMOTE_ADDR']);
}
if (empty($_SESSION['error'])) {
$_SESSION['error'] = $res['error'];
}
if (!$isAllowed && $res['error'] == '') {
if ($ipArray['duration'] == 0) {
$_SESSION['error'] = _IP_NOT_ALLOWED_NO_RA_CODE;
} else {
$_SESSION['error'] = _IP_NOT_ALLOWED;
}
$res['url'] = 'index.php?display=true&page=login';
}
}
if ($_SESSION['user']['UserId'] == 'superadmin') { if ($_SESSION['user']['UserId'] == 'superadmin') {
$res['url'] .= '?administration=true'; $res['url'] .= '?administration=true';
} }
header( header('location: '.$_SESSION['config']['businessappurl'].$res['url']);
'location: '.$_SESSION['config']['businessappurl'].$res['url']
);
exit(); exit();
} }
} }
......
<?xml version="1.0" encoding="utf-8"?>
<ROOT>
<enabled>false</enabled>
<IP>(192.168.1.10)</IP>
<duration>0</duration>
</ROOT>
...@@ -266,11 +266,11 @@ class security extends Database ...@@ -266,11 +266,11 @@ class security extends Database
} else { } else {
$error = \SrcCore\controllers\AuthenticationController::handleFailedAuthentication(['userId' => $s_login]); $error = \SrcCore\controllers\AuthenticationController::handleFailedAuthentication(['userId' => $s_login]);
return array( return [
'user' => $array, 'user' => $array,
'error' => $error, 'error' => $error,
'url' => 'index.php?display=true&page=login', 'url' => 'index.php?display=true&page=login'
); ];
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment