2
0
forked from Wavyzz/dolibarr

Qual: Reduce memory usage by moving a not required function into a library loaded only when required.

This commit is contained in:
Laurent Destailleur
2011-02-20 12:56:50 +00:00
parent 97b4fef379
commit 4e9ccd8571
2 changed files with 71 additions and 71 deletions

View File

@@ -26,10 +26,64 @@
/** /**
* \brief Show Dolibarr default login page * Return list of login methods provided by external third party modules.
* \param langs Lang object (must be initialized by a new). * @return array
* \param conf Conf object */
* \param mysoc Company object function getLoginMethod()
{
global $conf,$langs;
$login = '';
foreach($conf->login_method_modules as $dir)
{
// Check if directory exists
if (!is_dir($dir)) continue;
$handle=opendir($dir);
if (is_resource($handle))
{
while (($file = readdir($handle))!==false)
{
if (is_readable($dir.'/'.$file) && preg_match('/^functions_([^_]+)\.php/',$file,$reg))
{
$authfile = $dir.'/'.$file;
$mode = $reg[1];
$result=include_once($authfile);
if ($result)
{
// Call function to check user/password
$usertotest=$_POST["username"];
$passwordtotest=$_POST["password"];
$function='check_user_password_'.$mode;
$login=$function($usertotest,$passwordtotest);
if ($login)
{
$conf->authmode=$mode; // This properties is defined only when logged
}
}
else
{
dol_syslog("Authentification ko - failed to load file '".$authfile."'",LOG_ERR);
sleep(1);
$langs->load('main');
$langs->load('other');
$_SESSION["dol_loginmesg"]=$langs->trans("ErrorFailedToLoadLoginFileForMode",$mode);
}
}
}
}
closedir($handle);
}
return $login;
}
/**
* Show Dolibarr default login page
* @param langs Lang object (must be initialized by a new).
* @param conf Conf object
* @param mysoc Company object
*/ */
function dol_loginfunction($langs,$conf,$mysoc) function dol_loginfunction($langs,$conf,$mysoc)
{ {
@@ -210,11 +264,11 @@ function dol_loginfunction($langs,$conf,$mysoc)
} }
/** /**
* \brief Fonction pour initialiser un salt pour la fonction crypt * Fonction pour initialiser un salt pour la fonction crypt
* \param $type 2=>renvoi un salt pour cryptage DES * @param $type 2=>renvoi un salt pour cryptage DES
* 12=>renvoi un salt pour cryptage MD5 * 12=>renvoi un salt pour cryptage MD5
* non defini=>renvoi un salt pour cryptage par defaut * non defini=>renvoi un salt pour cryptage par defaut
* \return string Chaine salt * @return string Chaine salt
*/ */
function makesalt($type=CRYPT_SALT_LENGTH) function makesalt($type=CRYPT_SALT_LENGTH)
{ {
@@ -238,9 +292,9 @@ function makesalt($type=CRYPT_SALT_LENGTH)
} }
/** /**
* \brief Encode\decode database password in config file * Encode\decode database password in config file
* \param level Encode level: 0 no encoding, 1 encoding * @param level Encode level: 0 no encoding, 1 encoding
* \return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function encodedecode_dbpassconf($level=0) function encodedecode_dbpassconf($level=0)
{ {
@@ -340,9 +394,9 @@ function encodedecode_dbpassconf($level=0)
} }
/** /**
* \brief Encode une chaine de caractere * Encode a string
* \param chaine chaine de caracteres a encoder * @param chaine chaine de caracteres a encoder
* \return string_coded chaine de caracteres encodee * @return string_coded chaine de caracteres encodee
*/ */
function dol_encode($chain) function dol_encode($chain)
{ {
@@ -356,9 +410,9 @@ function dol_encode($chain)
} }
/** /**
* \brief Decode une chaine de caractere * Decode a string
* \param chain chaine de caracteres a decoder * @param chain chaine de caracteres a decoder
* \return string_coded chaine de caracteres decodee * @return string_coded chaine de caracteres decodee
*/ */
function dol_decode($chain) function dol_decode($chain)
{ {
@@ -376,7 +430,6 @@ function dol_decode($chain)
/** /**
* Return array of ciphers mode available * Return array of ciphers mode available
*
* @return strAv Configuration file content * @return strAv Configuration file content
*/ */
function dol_efc_config() function dol_efc_config()

View File

@@ -364,6 +364,7 @@ if (! defined('NOLOGIN'))
// Validation of third party module login method // Validation of third party module login method
if (is_array($conf->login_method_modules) && !empty($conf->login_method_modules)) if (is_array($conf->login_method_modules) && !empty($conf->login_method_modules))
{ {
include_once(DOL_DOCUMENT_ROOT . "/lib/security.lib.php");
$login = getLoginMethod(); $login = getLoginMethod();
if ($login) $test=false; if ($login) $test=false;
} }
@@ -1468,60 +1469,6 @@ function printSearchForm($urlaction,$urlobject,$title,$htmlmodesearch='search',$
return $ret; return $ret;
} }
/**
* Return list of login method of third party module.
* @return array
* TODO Move this into security.lib.php
*/
function getLoginMethod()
{
global $conf,$langs;
$login = '';
foreach($conf->login_method_modules as $dir)
{
// Check if directory exists
if (!is_dir($dir)) continue;
$handle=opendir($dir);
if (is_resource($handle))
{
while (($file = readdir($handle))!==false)
{
if (is_readable($dir.'/'.$file) && preg_match('/^functions_([^_]+)\.php/',$file,$reg))
{
$authfile = $dir.'/'.$file;
$mode = $reg[1];
$result=include_once($authfile);
if ($result)
{
// Call function to check user/password
$usertotest=$_POST["username"];
$passwordtotest=$_POST["password"];
$function='check_user_password_'.$mode;
$login=$function($usertotest,$passwordtotest);
if ($login)
{
$conf->authmode=$mode; // This properties is defined only when logged
}
}
else
{
dol_syslog("Authentification ko - failed to load file '".$authfile."'",LOG_ERR);
sleep(1);
$langs->load('main');
$langs->load('other');
$_SESSION["dol_loginmesg"]=$langs->trans("ErrorFailedToLoadLoginFileForMode",$mode);
}
}
}
}
closedir($handle);
}
return $login;
}
/** /**
* Show HTML footer * Show HTML footer