Add: just used cookie for remind last user and last entity

Look: use cookie for view logo of last used entity
This commit is contained in:
Regis Houssin 2009-05-23 17:44:36 +00:00
parent 1420692e53
commit f45caf216f
4 changed files with 103 additions and 3 deletions

View File

@ -126,7 +126,87 @@
return $decryptValue;
}
/**
* \brief Add cookie cryptkey in config file
* \return int <0 if KO, >0 if OK
*/
function add_cookiecryptkeyconf()
{
dol_syslog("cookie.class::add_cookiecryptkeyconf", LOG_DEBUG);
$config = '';
$added=0;
if ($fp = fopen(DOL_DOCUMENT_ROOT.'/conf/conf.php','r'))
{
while(!feof($fp))
{
$buffer = fgets($fp,4096);
if (strstr($buffer,"\$dolibarr_main_cookie_cryptkey"))
{
$config .= "\$dolibarr_main_cookie_cryptkey=\"$this->myKey\";\n";
$added++;
}
else
{
$config .= $buffer;
}
}
fclose($fp);
if (!$added)
{
$config = '';
if ($fp = fopen(DOL_DOCUMENT_ROOT.'/conf/conf.php','r'))
{
while(!feof($fp))
{
$buffer = fgets($fp,4096);
if (strstr($buffer,"\$dolibarr_main_authentication"))
{
$config .= $buffer;
$config .= "\$dolibarr_main_cookie_cryptkey=\"$this->myKey\";\n";
}
else
{
$config .= $buffer;
}
}
fclose($fp);
}
else
{
dol_syslog("cookie.class::add_cookiecryptkeyconf Failed to read conf.php", LOG_ERR);
return -2;
}
}
$file=DOL_DOCUMENT_ROOT.'/conf/conf.php';
if ($fp = @fopen($file,'w'))
{
fputs($fp, $config, strlen($config));
fclose($fp);
// It's config file, so we set permission for creator only
// @chmod($file, octdec('0600'));
return 1;
}
else
{
dol_syslog("cookie.class::add_cookiecryptkeyconf Failed to open conf.php file for writing", LOG_WARNING);
return -1;
}
}
else
{
dol_syslog("cookie.class::add_cookiecryptkeyconf Failed to read conf.php", LOG_ERR);
return -2;
}
}
}
?>
?>

View File

@ -141,7 +141,7 @@ function dol_loginfunction($langs,$conf,$mysoc)
{
include_once(DOL_DOCUMENT_ROOT . "/core/cookie.class.php");
$cryptkey = (! empty($conf->global->MAIN_MULTICOMPANY_COOKIE_CRYPTKEY) ? $conf->global->MAIN_MULTICOMPANY_COOKIE_CRYPTKEY : '' );
$cryptkey = ( isset($conf->cookie->cryptkey) ? $conf->cookie->cryptkey : '' );
$entityCookie = new DolCookie($cryptkey);
$cookieValue = $entityCookie->_getCookie($entityCookieName);

View File

@ -450,7 +450,7 @@ if (! isset($_SESSION["dol_login"]))
// TTL : sera defini dans la page de config multicompany
$ttl = (! empty($conf->global->MAIN_MULTICOMPANY_COOKIE_TTL) ? $conf->global->MAIN_MULTICOMPANY_COOKIE_TTL : time()+60*60*8 );
// Cryptkey : sera cree aleatoirement dans la page de config multicompany
$cryptkey = (! empty($conf->global->MAIN_MULTICOMPANY_COOKIE_CRYPTKEY) ? $conf->global->MAIN_MULTICOMPANY_COOKIE_CRYPTKEY : '' );
$cryptkey = ( isset($conf->cookie->cryptkey) ? $conf->cookie->cryptkey : '' );
$entityCookie = new DolCookie($cryptkey);
$entityCookie->_setCookie($entityCookieName, $entity, $ttl);

View File

@ -136,6 +136,11 @@ $conf->file->main_force_https = empty($dolibarr_main_force_https)?'':$dolibarr_m
// Define charset for HTML Output (can set hidden value force_charset in conf.php file)
if (empty($force_charset_do_notuse)) $force_charset_do_notuse='UTF-8';
$conf->file->character_set_client=strtoupper($force_charset_do_notuse);
// Cookie cryptkey
if (! empty($dolibarr_main_cookie_cryptkey))
{
$conf->cookie->cryptkey = $dolibarr_main_cookie_cryptkey;
}
// Define array of document root directories
$conf->file->dol_document_root=array(DOL_DOCUMENT_ROOT);
@ -205,6 +210,8 @@ if (! defined('NOREQUIREUSER'))
*/
if (! defined('NOREQUIREDB'))
{
$entityCookieName = 'DOLENTITYID_'.md5($_SERVER["SERVER_NAME"].$_SERVER["DOCUMENT_ROOT"]);
if (session_id() && isset($_SESSION["dol_entity"])) // Entity inside an opened session
{
$conf->entity = $_SESSION["dol_entity"];
@ -217,6 +224,19 @@ if (! defined('NOREQUIREDB'))
{
$conf->entity = $_POST["entity"];
}
elseif (isset($_COOKIE[$entityCookieName]) && isset($conf->cookie->cryptkey)) // Just for view specific login page
{
include_once(DOL_DOCUMENT_ROOT."/core/cookie.class.php");
$lastuser = '';
$lastentity = '';
$entityCookie = new DolCookie($conf->cookie->cryptkey);
$cookieValue = $entityCookie->_getCookie($entityCookieName);
list($lastuser, $lastentity) = split('\|', $cookieValue);
$conf->entity = $lastentity;
}
$conf->setValues($db);
}