Ajout message erreur connection

This commit is contained in:
Laurent Destailleur 2006-09-02 01:17:50 +00:00
parent fd5ccdd76a
commit cf546acabb
6 changed files with 222 additions and 98 deletions

View File

@ -8,6 +8,8 @@ ErrorRecordAlreadyExists=Record already exists
ErrorCantReadFile=Failed to read file '%s'
ErrorCantReadDir=Failed to read directory '%s'
ErrorFailedToFindEntity=Failed to read entity '%s'
ErrorBadLoginPassword=Bad value for login or password
ErrorLoginDisabled=Your account has been disabled
Calendar=Calendar
AddTrip=Add trip
Tools=Tools

View File

@ -8,6 +8,8 @@ ErrorRecordAlreadyExists=Enregistrement d
ErrorCantReadFile=Echec de lecture du fichier '%s'
ErrorCantReadDir=Echec de lecture du répertoire '%s'
ErrorFailedToFindEntity=Echec de lecture de l'entité '%s'
ErrorBadLoginPassword=Identifiants login ou mot de passe incorrects
ErrorLoginDisabled=Votre compte est désactivé
Calendar=Calendrier
AddTrip=Créer déplacement
Tools=Outils

View File

@ -986,13 +986,14 @@ function info_admin($texte)
/**
\brief Affiche formulaire de login
\remarks il faut changer le code html dans cette fonction pour changer le design
\brief Affiche formulaire de login PEAR
\remarks Il faut changer le code html dans cette fonction pour changer le design
*/
function loginfunction()
function dol_loginfunction($notused,$pearstatus)
{
global $langs,$conf;
$langs->load("main");
$langs->load("other");
$conf->css = "theme/".$conf->theme."/".$conf->theme.".css";
// Si feuille de style en php existe
@ -1013,7 +1014,7 @@ function loginfunction()
print '<!--'."\n";
print '#login {';
print ' margin-top: 70px;';
print ' margin-bottom: 50px;';
print ' margin-bottom: 30px;';
print ' text-align: center;';
print ' font: 12px arial,helvetica;';
print '}'."\n";
@ -1037,8 +1038,9 @@ function loginfunction()
print "}\n";
print '</script>'."\n";
print '</head>'."\n";
print '<body class="body" onload="donnefocus();">';
print '<body class="body" onload="donnefocus();">';
print '<form id="login" name="login" method="post" action="';
print $_SERVER['PHP_SELF'];
print $_SERVER["QUERY_STRING"]?'?'.$_SERVER["QUERY_STRING"]:'';
@ -1097,20 +1099,40 @@ function loginfunction()
print '</form>';
// Message
if ($_SESSION["loginmesg"] || ! empty($pearstatus))
{
print '<center><table width="60%"><tr><td align="center" class="small"><div class="error">';
if ($pearstatus == AUTH_EXPIRED) print "<i>Your session expired. Please login again!</i>\n";
elseif ($pearstatus == AUTH_IDLED) print "<i>You have been idle for too long. Please login again!</i>\n";
elseif ($pearstatus == AUTH_WRONG_LOGIN) print $langs->trans("ErrorBadLoginPassword");
elseif ($_SESSION["loginmesg"])
{
print $_SESSION["loginmesg"];
$_SESSION["loginmesg"]="";
}
print '</div></td></tr></table></center>';
}
print "\n</body>\n</html>";
}
/**
\brief Affiche message erreur de type acces interdit et arrete le programme
\param message Force error message
\remarks L'appel a cette fonction termine le code.
*/
function accessforbidden()
function accessforbidden($message='')
{
global $user, $langs;
$langs->load("other");
llxHeader();
print '<div class="error">'.$langs->trans("ErrorForbidden").'</div>';
print '<div class="error">';
if (! $message) print $langs->trans("ErrorForbidden");
else print $message;
print '</div>';
print '<br>';
if ($user->login)
{

View File

@ -45,9 +45,9 @@ function stripslashes_deep($value)
}
if (get_magic_quotes_gpc())
{
$_GET = array_map('stripslashes_deep', $_GET);
$_POST = array_map('stripslashes_deep', $_POST);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_GET = array_map('stripslashes_deep', $_GET);
$_POST = array_map('stripslashes_deep', $_POST);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}
@ -114,7 +114,7 @@ if (! session_id() && ! isset($_SESSION["dol_user"]) && ! isset($_SESSION["dol_
"cryptType" => "none",
);
$aDol = new DOLIAuth("DB", $params, "loginfunction");
$aDol = new DOLIAuth("DB", $params, "dol_loginfunction");
$aDol->setSessionName("DOLSESSID_".$dolibarr_main_db_name);
$aDol->start();
$result = $aDol->getAuth(); // Si deja logue avec succes, renvoie vrai, sinon effectue un redirect sur page loginfunction et renvoie false
@ -136,70 +136,61 @@ if (! session_id() && ! isset($_SESSION["dol_user"]) && ! isset($_SESSION["dol_
// Non authentifie
//dolibarr_syslog("Authentification non realise");
}
// Le debut de la page a ete affichee par getAuth qui a utilisé loginfunction.
// On ferme donc juste la page de logon.
print "\n</body>\n</html>";
exit;
}
}
// MODE LDAP
if (in_array('ldap',$authmode) && ! $login)
if ($conf->ldap->enabled && in_array('ldap',$authmode) && ! $login)
{
if ($conf->ldap->enabled)
{
// Authentification Apache KO ou non active, pas de mode force on demande le login
require_once(DOL_DOCUMENT_ROOT."/includes/pear/Auth/Auth.php");
//if ($conf->global->LDAP_SERVER_PROTOCOLVERSION == 3)
//{
$ldap = 'ldap://'.$conf->global->LDAP_ADMIN_DN.':'.$conf->global->LDAP_ADMIN_PASS.'@'.$conf->global->LDAP_SERVER_HOST.':'.$conf->global->LDAP_SERVER_PORT.'/'.$conf->global->LDAP_SERVER_DN;
//}
//else
//{
// $ldap = 'ldap2://'.$conf->global->LDAP_ADMIN_DN.':'.$conf->global->LDAP_ADMIN_PASS.'@'.$conf->global->LDAP_SERVER_HOST.':'.$conf->global->LDAP_SERVER_PORT.'/'.$conf->global->LDAP_SERVER_DN;
//}
$params = array(
'dsn' => $ldap,
'host' => $conf->global->LDAP_SERVER_HOST,
'port' => $conf->global->LDAP_SERVER_PORT,
'version' => $conf->global->LDAP_SERVER_PORT,
'basedn' => $conf->global->LDAP_SERVER_DN,
'binddn' => $conf->global->LDAP_ADMIN_DN,
'bindpw' => $conf->global->LDAP_ADMIN_PASS,
//'userattr' => $conf->global->LDAP_FIELD_LOGIN_SAMBA,
'userattr' => 'samAccountName',
'userfilter' => '(objectClass=user)',
);
// Authentification Apache KO ou non active, pas de mode force on demande le login
require_once(DOL_DOCUMENT_ROOT."/includes/pear/Auth/Auth.php");
//if ($conf->global->LDAP_SERVER_PROTOCOLVERSION == 3)
//{
$ldap = 'ldap://'.$conf->global->LDAP_ADMIN_DN.':'.$conf->global->LDAP_ADMIN_PASS.'@'.$conf->global->LDAP_SERVER_HOST.':'.$conf->global->LDAP_SERVER_PORT.'/'.$conf->global->LDAP_SERVER_DN;
//}
//else
//{
// $ldap = 'ldap2://'.$conf->global->LDAP_ADMIN_DN.':'.$conf->global->LDAP_ADMIN_PASS.'@'.$conf->global->LDAP_SERVER_HOST.':'.$conf->global->LDAP_SERVER_PORT.'/'.$conf->global->LDAP_SERVER_DN;
//}
$params = array(
'dsn' => $ldap,
'host' => $conf->global->LDAP_SERVER_HOST,
'port' => $conf->global->LDAP_SERVER_PORT,
'version' => $conf->global->LDAP_SERVER_PORT,
'basedn' => $conf->global->LDAP_SERVER_DN,
'binddn' => $conf->global->LDAP_ADMIN_DN,
'bindpw' => $conf->global->LDAP_ADMIN_PASS,
//'userattr' => $conf->global->LDAP_FIELD_LOGIN_SAMBA,
'userattr' => 'samAccountName',
'userfilter' => '(objectClass=user)',
);
$aDol = new DOLIAuth("LDAP", $params, "loginfunction");
$aDol->start();
$result = $aDol->getAuth(); // Si deja logue avec succes, renvoie vrai, sinon effectue un redirect sur page loginfunction et renvoie false
if ($result)
{
// Authentification Auth OK, on va chercher le login
$login=$aDol->getUsername();
dolibarr_syslog ("Authentification ok (en mode Pear Base LDAP)");
}
else
{
if (isset($_POST["loginfunction"]))
{
// Echec authentification
dolibarr_syslog("Authentification ko (en mode Pear Base LDAP) pour '".$_POST["username"]."'");
}
else
{
// Non authentifie
//dolibarr_syslog("Authentification non realise");
}
// Le debut de la page a ete affichee par getAuth qui a utilisé loginfunction.
// On ferme donc juste la page de logon.
print "</div>\n</div>\n</body>\n</html>";
exit;
}
}
$aDol = new DOLIAuth("LDAP", $params, "dol_loginfunction");
$aDol->start();
$result = $aDol->getAuth(); // Si deja logue avec succes, renvoie vrai, sinon effectue un redirect sur page loginfunction et renvoie false
if ($result)
{
// Authentification Auth OK, on va chercher le login
$login=$aDol->getUsername();
dolibarr_syslog ("Authentification ok (en mode Pear Base LDAP)");
}
else
{
if (isset($_POST["loginfunction"]))
{
// Echec authentification
dolibarr_syslog("Authentification ko (en mode Pear Base LDAP) pour '".$_POST["username"]."'");
}
else
{
// Non authentifie
//dolibarr_syslog("Authentification non realise");
}
exit;
}
}
}
else
@ -208,10 +199,9 @@ else
$login=$_SESSION["dol_user"];
}
// Charge l'objet user depuis son login
$user->fetch($login);
if (! $user->id)
$result=$user->fetch($login);
if ($result <= 0)
{
dolibarr_print_error($langs->trans("ErrorCantLoadUserFromDolibarrDatabase"));
exit;
@ -292,6 +282,17 @@ else // Si utilisateur externe
// Tentative de hacking ?
if (! $user->login) accessforbidden();
// Verifie si user actif
if ($user->statut < 1)
{
// Si non actif, on delogue le user
$langs->load("other");
dolibarr_syslog ("Authentification ko (en mode Pear Base Dolibarr) car login desactive");
accessforbidden($langs->trans("ErrorLoginDisabled"));
exit;
}
dolibarr_syslog("Access to ".$_SERVER["PHP_SELF"]);
@ -351,6 +352,8 @@ function top_htmlhead($head, $title="", $target="")
{
global $user, $conf, $langs, $db;
if (! $conf->css) $conf->css ='/theme/eldy/eldy.css.php';
//header("Content-type: text/html; charset=UTF-8");
header("Content-type: text/html; charset=iso-8859-1");
@ -419,6 +422,9 @@ function top_menu($head, $title="", $target="")
{
global $user, $conf, $langs, $db;
if (! $conf->top_menu) $conf->top_menu ='eldy_backoffice.php';
if (! $conf->left_menu) $conf->left_menu='eldy_backoffice.php';
top_htmlhead($head, $title, $target);
print '<body id="mainbody"><div id="dhtmltooltip"></div>';

View File

@ -503,16 +503,18 @@ class User
/**
* \brief Désactive un utilisateur
* \brief Change statut d'un utilisateur
* \return int <0 si ko, >0 si ok
*/
function disable()
function setstatus($statut)
{
$error=0;
$this->db->begin();
// Désactive utilisateur
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
$sql.= " SET login = NULL";
$sql.= " SET statut = ".$statut;
$sql.= " WHERE rowid = ".$this->id;
$result = $this->db->query($sql);
@ -528,10 +530,12 @@ class User
if ($error)
{
$this->db->rollback();
return -$error;
}
else
{
$this->db->commit();
return 1;
}
}
@ -1115,7 +1119,62 @@ class User
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowUser"),'user').$lienfin.' ');
$result.=$lien.$this->login.$lienfin;
return $result;
}
}
/**
* \brief Retourne le libellé du statut d'un user (actif, inactif)
* \param mode 0=libellé long, 1=libellé court, 2=Picto + Libellé court, 3=Picto, 4=Picto + Libellé long
* \return string Libelle
*/
function getLibStatut($mode=0)
{
return $this->LibStatut($this->statut,$mode);
}
/**
* \brief Renvoi le libellé d'un statut donné
* \param statut Id statut
* \param mode 0=libellé long, 1=libellé court, 2=Picto + Libellé court, 3=Picto, 4=Picto + Libellé long, 5=Libellé court + Picto
* \return string Libellé du statut
*/
function LibStatut($statut,$mode=0)
{
global $langs;
$langs->load('users');
if ($mode == 0)
{
$prefix='';
if ($statut == 1) return $langs->trans('Enabled');
if ($statut == 0) return $langs->trans('Disabled');
}
if ($mode == 1)
{
if ($statut == 1) return $langs->trans('Enabled');
if ($statut == 0) return $langs->trans('Disabled');
}
if ($mode == 2)
{
if ($statut == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
if ($statut == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
}
if ($mode == 3)
{
if ($statut == 1) return img_picto($langs->trans('Enabled'),'statut4');
if ($statut == 0) return img_picto($langs->trans('Disabled'),'statut5');
}
if ($mode == 4)
{
if ($statut == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
if ($statut == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
}
if ($mode == 5)
{
if ($statut == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
if ($statut == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
}
}
}
?>

View File

@ -87,7 +87,18 @@ if ($_POST["action"] == 'confirm_disable' && $_POST["confirm"] == "yes")
{
$edituser = new User($db, $_GET["id"]);
$edituser->fetch($_GET["id"]);
$edituser->disable();
$edituser->setstatus(0);
Header("Location: ".DOL_URL_ROOT.'/user/fiche.php?id='.$_GET["id"]);
exit;
}
}
if ($_POST["action"] == 'confirm_enable' && $_POST["confirm"] == "yes")
{
if ($_GET["id"] <> $user->id)
{
$edituser = new User($db, $_GET["id"]);
$edituser->fetch($_GET["id"]);
$edituser->setstatus(1);
Header("Location: ".DOL_URL_ROOT.'/user/fiche.php?id='.$_GET["id"]);
exit;
}
@ -106,7 +117,7 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes")
}
//reactive un compte ldap
if ($conf->ldap->enabled && $_GET["action"] == 'reactivate' && $canadduser)
if ($conf->ldap->enabled && $_GET["action"] == 'reactivate' && $candisableuser)
{
if ($_GET["id"] <> $user->id)
{
@ -240,8 +251,8 @@ if ($_POST["action"] == 'update' && $caneditfield)
$edituser->pass = trim($_POST["pass"]);
$edituser->admin = trim($_POST["admin"]);
$edituser->office_phone = trim($_POST["office_phone"]);
$edituser->office_fax = trim($_POST["office_fax"]);
$edituser->user_mobile = trim($_POST["user_mobile"]);
$edituser->office_fax = trim($_POST["office_fax"]);
$edituser->user_mobile = trim($_POST["user_mobile"]);
$edituser->email = trim($_POST["email"]);
$edituser->note = trim($_POST["note"]);
$edituser->webcal_login = trim($_POST["webcal_login"]);
@ -565,6 +576,7 @@ if (($action == 'create') || ($action == 'adduserldap'))
}
print '</td></tr>';
// EMail
print '<tr><td valign="top">'.$langs->trans("EMail").'</td>';
print '<td>';
if ($ldap_mail)
@ -709,6 +721,15 @@ else
print '<br>';
}
/*
* Confirmation activation
*/
if ($action == 'enable')
{
$html->form_confirm("fiche.php?id=$fuser->id",$langs->trans("EnableAUser"),$langs->trans("ConfirmEnabledUser",$fuser->login),"confirm_enable");
print '<br>';
}
/*
* Confirmation suppression
*/
@ -744,20 +765,17 @@ else
print '<td width="50%">'.$fuser->prenom.'</td>';
print "</tr>\n";
// Login
print '<tr><td width="25%" valign="top">'.$langs->trans("Login").'</td>';
if ($fuser->login)
if ($fuser->ldap_sid)
{
print '<td width="50%">'.$fuser->login;
}
else if ($fuser->ldap_sid)
{
print '<td width="50%" class="error">'.$langs->trans("LoginAccountDisableInDolibarr");
print '<td width="50%" class="error">'.$langs->trans("LoginAccountDisableInDolibarr").'</td>';
}
else
{
print '<td width="50%" class="error">'.$langs->trans("LoginAccountDisable");
print '<td width="50%">'.$fuser->login.'</td>';
}
print '</td></tr>';
print '</tr>';
// Password
print '<tr><td width="25%" valign="top">'.$langs->trans("Password").'</td>';
@ -836,10 +854,17 @@ else
print '<tr><td width="25%" valign="top">'.$langs->trans("Mobile").'</td>';
print '<td width="50%">'.$fuser->user_mobile.'</td>';
// EMail
print '<tr><td width="25%" valign="top">'.$langs->trans("EMail").'</td>';
print '<td width="50%"><a href="mailto:'.$fuser->email.'">'.$fuser->email.'</a></td>';
print "</tr>\n";
// Statut
print '<tr><td valign="top">'.$langs->trans("Status").'</td>';
print '<td>';
print $fuser->getLibStatut(4);
print '</td></tr>';
print '<tr><td width="25%" valign="top">'.$langs->trans("DateCreation").'</td>';
print '<td>'.dolibarr_print_date($fuser->datec,"%d/%m/%Y %H:%M:%S").'</td>';
print "</tr>\n";
@ -883,18 +908,12 @@ else
print '<div class="tabsAction">';
if ($caneditfield && (!$fuser->ldap_sid || !$fuser->login))
if ($caneditfield)
{
if ($canadduser && $fuser->ldap_sid && !$fuser->login)
{
print '<a class="butAction" href="fiche.php?id='.$fuser->id.'&amp;action=reactivate">'.$langs->trans("Reactivate").'</a>';
}
else
{
print '<a class="butAction" href="fiche.php?id='.$fuser->id.'&amp;action=edit">'.$langs->trans("Edit").'</a>';
}
print '<a class="butAction" href="fiche.php?id='.$fuser->id.'&amp;action=edit">'.$langs->trans("Edit").'</a>';
}
elseif ($caneditpassword && !$fuser->ldap_sid)
elseif ($caneditpassword && ! $fuser->ldap_sid)
{
print '<a class="butAction" href="fiche.php?id='.$fuser->id.'&amp;action=edit">'.$langs->trans("EditPassword").'</a>';
}
@ -913,7 +932,13 @@ else
}
}
if ($user->id <> $_GET["id"] && $candisableperms && $fuser->login)
// Activer
if ($user->id <> $_GET["id"] && $candisableperms && $fuser->statut == 0)
{
print '<a class="butAction" href="fiche.php?id='.$fuser->id.'&amp;action=enable">'.$langs->trans("Reactivate").'</a>';
}
// Desactiver
if ($user->id <> $_GET["id"] && $candisableperms && $fuser->statut == 1)
{
print '<a class="butActionDelete" href="fiche.php?action=disable&amp;id='.$fuser->id.'">'.$langs->trans("DisableUser").'</a>';
}
@ -1184,12 +1209,20 @@ else
else print $fuser->user_mobile;
print '</td></tr>';
// EMail
print "<tr>".'<td valign="top">'.$langs->trans("EMail").'</td>';
print '<td>';
if ($caneditfield) print '<input size="40" type="text" name="email" class="flat" value="'.$fuser->email.'">';
else print $fuser->email;
print '</td></tr>';
// Statut
print '<tr><td valign="top">'.$langs->trans("Status").'</td>';
print '<td>';
print $fuser->getLibStatut(4);
print '</td></tr>';
// Note
print '<tr><td valign="top">'.$langs->trans("Note").'</td><td colspan="2">';
if ($caneditfield)
{