Fix: Better support of login method http

This commit is contained in:
Laurent Destailleur 2008-05-02 01:10:00 +00:00
parent 3d2833996f
commit 98ebbf7571
3 changed files with 96 additions and 79 deletions

View File

@ -1,48 +1,47 @@
<?php <?php
/* Copyright (C) 2007 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2007 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* */
* $Id$
*/ /**
\file htdocs/includes/login/functions_http.php
/** \ingroup core
\file htdocs/includes/login/functions_http.php \brief Authentication functions for HTTP Basic
\ingroup core \version $Id$
\brief Authentication functions for HTTP Basic */
*/
/**
/** \brief Check user and password
\brief Check user and password \param usertotest Login
\param usertotest Login \param passwordtotest Password
\param passwordtotest Password \return string Login if ok, '' if ko.
\return string Login if ok, '' if ko. */
*/ function check_user_password_http($usertotest,$passwordtotest)
function check_user_password_http($usertotest,$passwordtotest) {
{ dolibarr_syslog("functions_http::check_user_password_http _SERVER[REMOTE_USER]=".$_SERVER["REMOTE_USER"]);
dolibarr_syslog("functions_http::check_user_password_http _SERVER[REMOTE_USER]=".$_SERVER["REMOTE_USER"]);
$login='';
$login=''; if (! empty($_SERVER["REMOTE_USER"]))
if (! empty($_SERVER["REMOTE_USER"])) {
{ $login=$_SERVER["REMOTE_USER"];
$login=$_SERVER["REMOTE_USER"]; }
}
return $login;
return $login; }
}
?> ?>

View File

@ -190,7 +190,11 @@ if (! isset($_SESSION["dol_login"]))
// Tests de validation user/mot de passe // Tests de validation user/mot de passe
// Si ok, la variable login sera initialisee // Si ok, la variable login sera initialisee
// Si erreur, on a placera message erreur dans session sous le nom dol_loginmesg // Si erreur, on a placera message erreur dans session sous le nom dol_loginmesg
if ($test && isset($_POST["username"])) $goontestloop=false;
if (isset($_SERVER["REMOTE_USER"]) && in_array('http',$authmode)) $goontestloop=true;
if (isset($_POST["username"])) $goontestloop=true;
if ($test && $goontestloop)
{ {
foreach($authmode as $mode) foreach($authmode as $mode)
{ {
@ -205,7 +209,11 @@ if (! isset($_SESSION["dol_login"]))
$passwordtotest=$_POST["password"]; $passwordtotest=$_POST["password"];
$function='check_user_password_'.$mode; $function='check_user_password_'.$mode;
$login=$function($usertotest,$passwordtotest); $login=$function($usertotest,$passwordtotest);
if ($login) $test=false; if ($login)
{
$test=false;
$conf->authmode=$mode; // This properties is defined only when login
}
} }
else else
{ {
@ -327,6 +335,7 @@ if (! isset($_SESSION["dol_login"]))
// Nouvelle session pour ce login // Nouvelle session pour ce login
$_SESSION["dol_login"]=$user->login; $_SESSION["dol_login"]=$user->login;
$_SESSION["dol_password"]=$user->pass_crypted; $_SESSION["dol_password"]=$user->pass_crypted;
$_SESSION["dol_authmode"]=$conf->authmode;
dolibarr_syslog("This is a new started user session. _SESSION['dol_login']=".$_SESSION["dol_login"].' Session id='.session_id()); dolibarr_syslog("This is a new started user session. _SESSION['dol_login']=".$_SESSION["dol_login"].' Session id='.session_id());
$db->begin(); $db->begin();
@ -901,40 +910,47 @@ function top_menu($head, $title="", $target="")
print $menutop->atarget?(' target="'.$menutop->atarget.'"'):''; print $menutop->atarget?(' target="'.$menutop->atarget.'"'):'';
print '>'.$user->login.'</a>'; print '>'.$user->login.'</a>';
// Lien logout // Lien info
if (! isset($_SERVER["REMOTE_USER"]) || ! $_SERVER["REMOTE_USER"]) $htmltext=''; $text='';
if ($_SESSION["dol_authmode"] != 'forceuser'
&& $_SESSION["dol_authmode"] != 'http')
{ {
$title=$langs->trans("Logout").'<br>'; $htmltext=$langs->trans("Logout").'<br>';
$title.='<br><u>'.$langs->trans("User").'</u>'; $htmltext.="<br>";
$title.='<br><b>'.$langs->trans("Name").'</b>: '.$user->fullname;
$title.='<br><b>'.$langs->trans("Login").'</b>: '.$user->login; $text.='<a href="'.DOL_URL_ROOT.'/user/logout.php"';
$title.='<br><b>'.$langs->trans("Administrator").'</b>: '.yn($user->admin); $text.=$menutop->atarget?(' target="'.$menutop->atarget.'"'):'';
$title.='<br><b>'.$langs->trans("Type").'</b>: '.($user->societe_id?$langs->trans("External"):$langs->trans("Internal")); $text.='>';
$title.='<br>'; $text.='<img class="login" border="0" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/logout.png"';
$title.='<br><u>'.$langs->trans("Connection").'</u>'; $text.=' alt="" title=""';
$title.='<br><b>'.$langs->trans("ConnectedSince").'</b>: '.dolibarr_print_date($user->datelastlogin,"dayhour"); $text.='>';
$title.='<br><b>'.$langs->trans("PreviousConnexion").'</b>: '.dolibarr_print_date($user->datepreviouslogin,"dayhour"); $text.='</a>';
if ($dolibarr_main_authentication) $title.='<br><b>'.$langs->trans("AuthenticationMode").'</b>: '.$dolibarr_main_authentication; }
else
{
$text.='<img class="login" border="0" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/logout.png"';
$text.=' alt="" title=""';
$text.='>';
}
$htmltext.='<u>'.$langs->trans("User").'</u>';
$htmltext.='<br><b>'.$langs->trans("Name").'</b>: '.$user->fullname;
$htmltext.='<br><b>'.$langs->trans("Login").'</b>: '.$user->login;
$htmltext.='<br><b>'.$langs->trans("Administrator").'</b>: '.yn($user->admin);
$htmltext.='<br><b>'.$langs->trans("Type").'</b>: '.($user->societe_id?$langs->trans("External"):$langs->trans("Internal"));
$htmltext.='<br>';
$htmltext.='<br><u>'.$langs->trans("Connection").'</u>';
$htmltext.='<br><b>'.$langs->trans("ConnectedSince").'</b>: '.dolibarr_print_date($user->datelastlogin,"dayhour");
$htmltext.='<br><b>'.$langs->trans("PreviousConnexion").'</b>: '.dolibarr_print_date($user->datepreviouslogin,"dayhour");
$htmltext.='<br><b>'.$langs->trans("AuthenticationMode").'</b>: '.$_SESSION["dol_authmode"];
$text=''; $html=new Form($db);
$text.='<a href="'.DOL_URL_ROOT.'/user/logout.php"'; print $html->textwithtooltip('',$htmltext,2,1,$text);
$text.=$menutop->atarget?(' target="'.$menutop->atarget.'"'):'';
$text.='>';
$text.='<img class="login" border="0" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/logout.png"';
$text.=' alt="" title=""';
$text.='>';
$text.='</a>';
$html=new Form($db);
print $html->textwithtooltip('',$title,2,1,$text);
// print '<img class="login" border="0" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/logout.png"'; // print '<img class="login" border="0" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/logout.png"';
// print ' alt="'.$title.'" title="'.$title.'"'; // print ' alt="'.$title.'" title="'.$title.'"';
// print '>'; // print '>';
}
print "\n</div>\n<!-- End top horizontal menu -->\n"; print "\n</div>\n<!-- End top horizontal menu -->\n";
} }

View File

@ -16,17 +16,19 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/ */
/** /**
\file htdocs/user/logout.php \file htdocs/user/logout.php
\brief Fichier de deconnexion \brief Fichier de deconnexion
\version $Id$
*/ */
if (!empty ($_SERVER["REMOTE_USER"])) if ($_SESSION["dol_authmode"] == 'forceuser'
die("La d&eacute;connection ne fonctionne actuellement que pour l'authentification par pear"); && $_SESSION["dol_authmode"] == 'http')
{
die("Deconexion does not work when conexion was made in mode ".$_SESSION["dol_authmode"]);
}
include_once("../conf/conf.php"); include_once("../conf/conf.php");
require_once("../main.inc.php"); require_once("../main.inc.php");