|
@@ -84,32 +84,47 @@ EOF
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- public function DisplayLoginForm($bFailedLogin = false)
|
|
|
|
|
|
+ public function DisplayLoginForm($sLoginType, $bFailedLogin = false)
|
|
{
|
|
{
|
|
- $sAuthUser = utils::ReadParam('auth_user', '');
|
|
|
|
- $sAuthPwd = utils::ReadParam('suggest_pwd', '');
|
|
|
|
-
|
|
|
|
- $sVersionShort = Dict::Format('UI:iTopVersion:Short', ITOP_VERSION);
|
|
|
|
- $this->add("<div id=\"login-logo\"><a href=\"http://www.combodo.com/itop\"><img title=\"$sVersionShort\" src=\"../images/itop-logo.png\"></a></div>\n");
|
|
|
|
- $this->add("<div id=\"login\">\n");
|
|
|
|
- $this->add("<h1>".Dict::S('UI:Login:Welcome')."</h1>\n");
|
|
|
|
- if ($bFailedLogin)
|
|
|
|
- {
|
|
|
|
- $this->add("<p class=\"hilite\">".Dict::S('UI:Login:IncorrectLoginPassword')."</p>\n");
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
|
|
+ switch($sLoginType)
|
|
{
|
|
{
|
|
- $this->add("<p>".Dict::S('UI:Login:IdentifyYourself')."</p>\n");
|
|
|
|
|
|
+ case 'popup':
|
|
|
|
+ case 'url':
|
|
|
|
+ $this->add_header('WWW-Authenticate: Basic realm="'.Dict::Format('UI:iTopVersion:Short', ITOP_VERSION));
|
|
|
|
+ $this->add_header('HTTP/1.0 401 Unauthorized');
|
|
|
|
+ // Note: displayed when the user will click on Cancel
|
|
|
|
+ $this->add('<p><strong>'.Dict::S('UI:Login:Error:AccessRestricted').'</strong></p>');
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case 'remote':
|
|
|
|
+ case 'form':
|
|
|
|
+ default: // In case the settings get messed up...
|
|
|
|
+ $sAuthUser = utils::ReadParam('auth_user', '');
|
|
|
|
+ $sAuthPwd = utils::ReadParam('suggest_pwd', '');
|
|
|
|
+
|
|
|
|
+ $sVersionShort = Dict::Format('UI:iTopVersion:Short', ITOP_VERSION);
|
|
|
|
+ $this->add("<div id=\"login-logo\"><a href=\"http://www.combodo.com/itop\"><img title=\"$sVersionShort\" src=\"../images/itop-logo.png\"></a></div>\n");
|
|
|
|
+ $this->add("<div id=\"login\">\n");
|
|
|
|
+ $this->add("<h1>".Dict::S('UI:Login:Welcome')."</h1>\n");
|
|
|
|
+ if ($bFailedLogin)
|
|
|
|
+ {
|
|
|
|
+ $this->add("<p class=\"hilite\">".Dict::S('UI:Login:IncorrectLoginPassword')."</p>\n");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ $this->add("<p>".Dict::S('UI:Login:IdentifyYourself')."</p>\n");
|
|
|
|
+ }
|
|
|
|
+ $this->add("<form method=\"post\">\n");
|
|
|
|
+ $this->add("<table>\n");
|
|
|
|
+ $this->add("<tr><td><label for=\"user\">".Dict::S('UI:Login:UserNamePrompt').":</label></td><td><input id=\"user\" type=\"text\" name=\"auth_user\" value=\"$sAuthUser\" /></td></tr>\n");
|
|
|
|
+ $this->add("<tr><td><label for=\"pwd\">".Dict::S('UI:Login:PasswordPrompt').":</label></td><td><input id=\"pwd\" type=\"password\" name=\"auth_pwd\" value=\"$sAuthPwd\" /></td></tr>\n");
|
|
|
|
+ $this->add("<tr><td colspan=\"2\" class=\"center v-spacer\"> <input type=\"submit\" value=\"".Dict::S('UI:Button:Login')."\" /></td></tr>\n");
|
|
|
|
+ $this->add("</table>\n");
|
|
|
|
+ $this->add("<input type=\"hidden\" name=\"loginop\" value=\"login\" />\n");
|
|
|
|
+ $this->add("</form>\n");
|
|
|
|
+ $this->add("</div>\n");
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
- $this->add("<form method=\"post\">\n");
|
|
|
|
- $this->add("<table>\n");
|
|
|
|
- $this->add("<tr><td><label for=\"user\">".Dict::S('UI:Login:UserNamePrompt').":</label></td><td><input id=\"user\" type=\"text\" name=\"auth_user\" value=\"$sAuthUser\" /></td></tr>\n");
|
|
|
|
- $this->add("<tr><td><label for=\"pwd\">".Dict::S('UI:Login:PasswordPrompt').":</label></td><td><input id=\"pwd\" type=\"password\" name=\"auth_pwd\" value=\"$sAuthPwd\" /></td></tr>\n");
|
|
|
|
- $this->add("<tr><td colspan=\"2\" class=\"center v-spacer\"> <input type=\"submit\" value=\"".Dict::S('UI:Button:Login')."\" /></td></tr>\n");
|
|
|
|
- $this->add("</table>\n");
|
|
|
|
- $this->add("<input type=\"hidden\" name=\"loginop\" value=\"login\" />\n");
|
|
|
|
- $this->add("</form>\n");
|
|
|
|
- $this->add("</div>\n");
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public function DisplayChangePwdForm($bFailedLogin = false)
|
|
public function DisplayChangePwdForm($bFailedLogin = false)
|
|
@@ -155,8 +170,16 @@ EOF
|
|
$this->add("</div>\n");
|
|
$this->add("</div>\n");
|
|
}
|
|
}
|
|
|
|
|
|
- static protected function ResetSession()
|
|
|
|
|
|
+ static function ResetSession()
|
|
{
|
|
{
|
|
|
|
+ if (isset($_SESSION['login_mode']))
|
|
|
|
+ {
|
|
|
|
+ $sPreviousLoginMode = $_SESSION['login_mode'];
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ $sPreviousLoginMode = '';
|
|
|
|
+ }
|
|
// Unset all of the session variables.
|
|
// Unset all of the session variables.
|
|
$_SESSION = array();
|
|
$_SESSION = array();
|
|
// If it's desired to kill the session, also delete the session cookie.
|
|
// If it's desired to kill the session, also delete the session cookie.
|
|
@@ -186,7 +209,7 @@ EOF
|
|
return $bSecured;
|
|
return $bSecured;
|
|
}
|
|
}
|
|
|
|
|
|
- static function DoLogin()
|
|
|
|
|
|
+ protected static function Login()
|
|
{
|
|
{
|
|
if (self::SecureConnectionRequired() && !self::IsConnectionSecure())
|
|
if (self::SecureConnectionRequired() && !self::IsConnectionSecure())
|
|
{
|
|
{
|
|
@@ -195,52 +218,147 @@ EOF
|
|
header("Location: $sUrl");
|
|
header("Location: $sUrl");
|
|
exit;
|
|
exit;
|
|
}
|
|
}
|
|
- $bHTTPBasicAuthentication = (utils::ReadParam('auth', '', 'get') == 'http_basic');
|
|
|
|
- if ($bHTTPBasicAuthentication)
|
|
|
|
|
|
+
|
|
|
|
+ $aAllowedLoginTypes = utils::GetConfig()->GetAllowedLoginTypes();
|
|
|
|
+
|
|
|
|
+ if (isset($_SESSION['auth_user']))
|
|
|
|
+ {
|
|
|
|
+ //echo "User: ".$_SESSION['auth_user']."\n";
|
|
|
|
+ // Already authentified
|
|
|
|
+ UserRights::Login($_SESSION['auth_user']); // Login & set the user's language
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- // Basic HTTP/PHP authentication mecanism
|
|
|
|
- //
|
|
|
|
- // meme avec ca c'est pourri - return;
|
|
|
|
- if (!isset($_SERVER['PHP_AUTH_USER']))
|
|
|
|
|
|
+ $index = 0;
|
|
|
|
+ $sLoginMode = '';
|
|
|
|
+ $sAuthentication = 'internal';
|
|
|
|
+ while(($sLoginMode == '') && ($index < count($aAllowedLoginTypes)))
|
|
{
|
|
{
|
|
- header('WWW-Authenticate: Basic realm="iTop access is restricted"');
|
|
|
|
- header('HTTP/1.0 401 Unauthorized');
|
|
|
|
- // Note: accessed when the user will click on Cancel
|
|
|
|
- echo '<p><strong>'.Dict::S('UI:Login:Error:AccessRestricted').'</strong></p>';
|
|
|
|
|
|
+ $sLoginType = $aAllowedLoginTypes[$index];
|
|
|
|
+ switch($sLoginType)
|
|
|
|
+ {
|
|
|
|
+ case 'form':
|
|
|
|
+ // iTop standard mode: form based authentication
|
|
|
|
+ $sAuthUser = utils::ReadParam('auth_user', '', 'post');
|
|
|
|
+ $sAuthPwd = utils::ReadParam('auth_pwd', '', 'post');
|
|
|
|
+ if ($sAuthUser != '')
|
|
|
|
+ {
|
|
|
|
+ $sLoginMode = 'form';
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case 'popup':
|
|
|
|
+ // Standard PHP authentication method, works with Apache...
|
|
|
|
+ // Case 1) Apache running in CGI mode + rewrite rules in .htaccess
|
|
|
|
+ if (isset($_SERVER['HTTP_AUTHORIZATION']) && !empty($_SERVER['HTTP_AUTHORIZATION']))
|
|
|
|
+ {
|
|
|
|
+ list($sAuthUser, $sAuthPwd) = explode(':' , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
|
|
|
|
+ $sLoginMode = 'popup';
|
|
|
|
+ }
|
|
|
|
+ else if (isset($_SERVER['PHP_AUTH_USER']))
|
|
|
|
+ {
|
|
|
|
+ $sAuthUser = $_SERVER['PHP_AUTH_USER'];
|
|
|
|
+ $sAuthPwd = $_SERVER['PHP_AUTH_PW'];
|
|
|
|
+ $sLoginMode = 'popup';
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case 'remote':
|
|
|
|
+ // Web server supplied authentication
|
|
|
|
+ if (isset($_SERVER['REMOTE_USER']))
|
|
|
|
+ {
|
|
|
|
+ $sAuthUser = $_SERVER['REMOTE_USER'];
|
|
|
|
+ $sAuthPwd = ''; // No password in this case the web server already authentified the user...
|
|
|
|
+ $sLoginMode = 'remote';
|
|
|
|
+ $sAuthentication = 'external';
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case 'url':
|
|
|
|
+ // Credentials passed directly in the url
|
|
|
|
+ $sAuthUser = utils::ReadParam('auth_user', '', 'get');
|
|
|
|
+ if ($sAuthUser != '')
|
|
|
|
+ {
|
|
|
|
+ $sAuthPwd = utils::ReadParam('auth_pwd', '', 'post');
|
|
|
|
+ $sLoginMode = 'url';
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ $index++;
|
|
|
|
+ }
|
|
|
|
+ //echo "\nsLoginMode: $sLoginMode (user: $sAuthUser / pwd: $sAuthPwd\n)";
|
|
|
|
+ if ($sLoginMode == '')
|
|
|
|
+ {
|
|
|
|
+ // First connection
|
|
|
|
+ $sDesiredLoginMode = utils::ReadParam('login_mode');
|
|
|
|
+ if (in_array($sDesiredLoginMode, $aAllowedLoginTypes))
|
|
|
|
+ {
|
|
|
|
+ $sLoginMode = $sDesiredLoginMode;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ $sLoginMode = $aAllowedLoginTypes[0]; // First in the list...
|
|
|
|
+ }
|
|
|
|
+ $oPage = new LoginWebPage();
|
|
|
|
+ $oPage->DisplayLoginForm( $sLoginMode, false /* no previous failed attempt */);
|
|
|
|
+ $oPage->output();
|
|
exit;
|
|
exit;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- $sAuthUser = $_SERVER['PHP_AUTH_USER'];
|
|
|
|
- $sAuthPwd = $_SERVER['PHP_AUTH_PW'];
|
|
|
|
- if (!UserRights::Login($sAuthUser, $sAuthPwd))
|
|
|
|
|
|
+ if (!UserRights::CheckCredentials($sAuthUser, $sAuthPwd, $sAuthentication))
|
|
{
|
|
{
|
|
- header('WWW-Authenticate: Basic realm="Unknown user \''.$sAuthUser.'\'"');
|
|
|
|
- header('HTTP/1.0 401 Unauthorized');
|
|
|
|
- // Note: accessed when the user will click on Cancel
|
|
|
|
- // Todo: count the attempts
|
|
|
|
- echo '<p><strong>'.Dict::S('UI:Login:Error:AccessRestricted').'</strong></p>';
|
|
|
|
|
|
+ self::ResetSession();
|
|
|
|
+ $oPage = new LoginWebPage();
|
|
|
|
+ $oPage->DisplayLoginForm( $sLoginMode, true /* failed attempt */);
|
|
|
|
+ $oPage->output();
|
|
exit;
|
|
exit;
|
|
}
|
|
}
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ // User is Ok, let's save it in the session and proceed with normal login
|
|
|
|
+ UserRights::Login($sAuthUser, $sAuthentication); // Login & set the user's language
|
|
|
|
+ $_SESSION['auth_user'] = $sAuthUser;
|
|
|
|
+ $_SESSION['login_mode'] = $sLoginMode;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return;
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- // Home-made authentication mecanism
|
|
|
|
- //
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static function DoLogin()
|
|
|
|
+ {
|
|
$operation = utils::ReadParam('loginop', '');
|
|
$operation = utils::ReadParam('loginop', '');
|
|
session_start();
|
|
session_start();
|
|
|
|
|
|
if ($operation == 'logoff')
|
|
if ($operation == 'logoff')
|
|
{
|
|
{
|
|
|
|
+ if (isset($_SESSION['login_mode']))
|
|
|
|
+ {
|
|
|
|
+ $sLoginMode = $_SESSION['login_mode'];
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ $aAllowedLoginTypes = utils::GetConfig()->GetAllowedLoginTypes();
|
|
|
|
+ if (count($aAllowedLoginTypes) > 0)
|
|
|
|
+ {
|
|
|
|
+ $sLoginMode = $aAllowedLoginTypes[0];
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ $sLoginMode = 'form';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
self::ResetSession();
|
|
self::ResetSession();
|
|
- }
|
|
|
|
-
|
|
|
|
- if ($operation == 'change_pwd')
|
|
|
|
|
|
+ $oPage = new LoginWebPage();
|
|
|
|
+ $oPage->DisplayLoginForm( $sLoginMode, false /* not a failed attempt */);
|
|
|
|
+ $oPage->output();
|
|
|
|
+ exit;
|
|
|
|
+ }
|
|
|
|
+ else if ($operation == 'change_pwd')
|
|
{
|
|
{
|
|
$sAuthUser = $_SESSION['auth_user'];
|
|
$sAuthUser = $_SESSION['auth_user'];
|
|
- $sAuthPwd = $_SESSION['auth_pwd'];
|
|
|
|
- UserRights::Login($sAuthUser, $sAuthPwd); // Set the user's language
|
|
|
|
|
|
+ UserRights::Login($sAuthUser); // Set the user's language
|
|
$oPage = new LoginWebPage();
|
|
$oPage = new LoginWebPage();
|
|
$oPage->DisplayChangePwdForm();
|
|
$oPage->DisplayChangePwdForm();
|
|
$oPage->output();
|
|
$oPage->output();
|
|
@@ -249,11 +367,10 @@ EOF
|
|
if ($operation == 'do_change_pwd')
|
|
if ($operation == 'do_change_pwd')
|
|
{
|
|
{
|
|
$sAuthUser = $_SESSION['auth_user'];
|
|
$sAuthUser = $_SESSION['auth_user'];
|
|
- $sAuthPwd = $_SESSION['auth_pwd'];
|
|
|
|
- UserRights::Login($sAuthUser, $sAuthPwd); // Set the user's language
|
|
|
|
|
|
+ UserRights::Login($sAuthUser); // Set the user's language
|
|
$sOldPwd = utils::ReadPostedParam('old_pwd');
|
|
$sOldPwd = utils::ReadPostedParam('old_pwd');
|
|
$sNewPwd = utils::ReadPostedParam('new_pwd');
|
|
$sNewPwd = utils::ReadPostedParam('new_pwd');
|
|
- if (UserRights::CanChangePassword() && ((!UserRights::Login($sAuthUser, $sOldPwd)) || (!UserRights::ChangePassword($sOldPwd, $sNewPwd))))
|
|
|
|
|
|
+ if (UserRights::CanChangePassword() && ((!UserRights::CheckCredentials($sAuthUser, $sOldPwd)) || (!UserRights::ChangePassword($sOldPwd, $sNewPwd))))
|
|
{
|
|
{
|
|
$oPage = new LoginWebPage();
|
|
$oPage = new LoginWebPage();
|
|
$oPage->DisplayChangePwdForm(true); // old pwd was wrong
|
|
$oPage->DisplayChangePwdForm(true); // old pwd was wrong
|
|
@@ -268,44 +385,8 @@ EOF
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (!isset($_SESSION['auth_user']) || !isset($_SESSION['auth_pwd']))
|
|
|
|
- {
|
|
|
|
- if ($operation == 'loginurl')
|
|
|
|
- {
|
|
|
|
- $sAuthUser = utils::ReadParam('auth_user', '', 'get');
|
|
|
|
- $sAuthPwd = utils::ReadParam('auth_pwd', '', 'get');
|
|
|
|
- }
|
|
|
|
- else if ($operation == 'login')
|
|
|
|
- {
|
|
|
|
- $sAuthUser = utils::ReadParam('auth_user', '', 'post');
|
|
|
|
- $sAuthPwd = utils::ReadParam('auth_pwd', '', 'post');
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- $oPage = new LoginWebPage();
|
|
|
|
- $oPage->DisplayLoginForm();
|
|
|
|
- $oPage->output();
|
|
|
|
- exit;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- $sAuthUser = $_SESSION['auth_user'];
|
|
|
|
- $sAuthPwd = $_SESSION['auth_pwd'];
|
|
|
|
- }
|
|
|
|
- if (!UserRights::Login($sAuthUser, $sAuthPwd))
|
|
|
|
- {
|
|
|
|
- self::ResetSession();
|
|
|
|
- $oPage = new LoginWebPage();
|
|
|
|
- $oPage->DisplayLoginForm( true /* failed attempt */);
|
|
|
|
- $oPage->output();
|
|
|
|
- exit;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- $_SESSION['auth_user'] = $sAuthUser ;
|
|
|
|
- $_SESSION['auth_pwd'] = $sAuthPwd;
|
|
|
|
- }
|
|
|
|
|
|
+ self::Login();
|
|
}
|
|
}
|
|
|
|
+
|
|
} // End of class
|
|
} // End of class
|
|
?>
|
|
?>
|