38 if ($mode ==
'user') $t = getenv(
'APACHE_RUN_USER');
39 if ($mode ==
'group') $t = getenv(
'APACHE_RUN_GROUP');
59 if ($entitytotest ==
'') $entitytotest = 1;
61 dol_syslog(
"checkLoginPassEntity usertotest=".$usertotest.
" entitytotest=".$entitytotest.
" authmode=".join(
',', $authmode));
68 foreach ($authmode as $mode)
70 if ($test && $mode && !$login)
74 $authfile =
'functions_'.$mode.
'.php';
77 $dirlogin = array_merge(array(
"/core/login"), (array) $conf->modules_parts[
'login']);
78 foreach ($dirlogin as $reldir)
84 $tmpnewauthfile = $newdir.(preg_match(
'/\/$/', $newdir) ?
'' :
'/').$authfile;
85 if (is_file($tmpnewauthfile)) $fullauthfile = $tmpnewauthfile;
89 if ($fullauthfile) $result = include_once $fullauthfile;
90 if ($fullauthfile && $result)
93 $function =
'check_user_password_'.$mode;
94 $login = call_user_func($function, $usertotest, $passwordtotest, $entitytotest, $context);
95 if ($login && $login !=
'--bad-login-validity--')
98 $conf->authmode = $mode;
101 $dol_screenwidth =
GETPOST(
'screenwidth');
102 $dol_screenheight =
GETPOST(
'screenheight');
105 dol_syslog(
"Authentication KO - failed to load file '".$authfile.
"'", LOG_ERR);
108 $langs->loadLangs(array(
'other',
'main',
'errors'));
110 $_SESSION[
"dol_loginmesg"] = $langs->trans(
"ErrorFailedToLoadLoginFileForMode", $mode);
120 if (!function_exists(
'dol_loginfunction'))
131 function dol_loginfunction($langs, $conf, $mysoc)
133 global $dolibarr_main_demo, $dolibarr_main_force_https;
134 global $db, $hookmanager;
136 $langs->loadLangs(array(
"main",
"other",
"help",
"admin"));
139 $hookmanager->initHooks(array(
'mainloginpage'));
141 $main_authentication = $conf->file->main_authentication;
143 $session_name = session_name();
148 $appli = constant(
'DOL_APPLICATION_TITLE');
149 $title = $appli.
' '.constant(
'DOL_VERSION');
150 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $title = $conf->global->MAIN_APPLICATION_TITLE;
151 $titletruedolibarrversion = constant(
'DOL_VERSION');
172 if (!empty($conf->modules_parts[
'tpl']))
174 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array(
'/core/tpl/'));
175 foreach ($dirtpls as $reldir)
178 if (file_exists($tmp)) { $template_dir = preg_replace(
'/login\.tpl\.php$/',
'', $tmp);
break; }
181 $template_dir = DOL_DOCUMENT_ROOT.
"/core/tpl/";
185 $prefix = dol_getprefix(
'');
186 $sessiontimeout =
'DOLSESSTIMEOUT_'.$prefix;
187 if (!empty($conf->global->MAIN_SESSION_TIMEOUT)) setcookie($sessiontimeout, $conf->global->MAIN_SESSION_TIMEOUT, 0,
"/", null, (empty($dolibarr_main_force_https) ?
false :
true),
true);
189 if (
GETPOST(
'urlfrom',
'alpha')) $_SESSION[
"urlfrom"] =
GETPOST(
'urlfrom',
'alpha');
190 else unset($_SESSION[
"urlfrom"]);
192 if (!
GETPOST(
"username",
'alpha')) $focus_element =
'username';
193 else $focus_element =
'password';
197 if (!empty($dolibarr_main_demo))
199 $tab = explode(
',', $dolibarr_main_demo);
200 $demologin = $tab[0];
201 $demopassword = $tab[1];
205 $parameters = array(
'entity' =>
GETPOST(
'entity',
'int'));
206 $reshook = $hookmanager->executeHooks(
'getLoginPageOptions', $parameters);
207 $morelogincontent = $hookmanager->resPrint;
210 $parameters = array(
'entity' =>
GETPOST(
'entity',
'int'));
211 $reshook = $hookmanager->executeHooks(
'getLoginPageExtraOptions', $parameters);
212 $moreloginextracontent = $hookmanager->resPrint;
215 $login = (!empty($hookmanager->resArray[
'username']) ? $hookmanager->resArray[
'username'] : (
GETPOST(
"username",
"alpha") ?
GETPOST(
"username",
"alpha") : $demologin));
216 $password = $demopassword;
220 $urllogo = DOL_URL_ROOT.
'/theme/common/login_logo.png';
222 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small))
224 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_small);
225 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo))
227 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/'.$mysoc->logo);
229 } elseif (is_readable(DOL_DOCUMENT_ROOT.
'/theme/dolibarr_logo.svg'))
231 $urllogo = DOL_URL_ROOT.
'/theme/dolibarr_logo.svg';
236 $captcha_refresh =
'';
237 if (function_exists(
"imagecreatefrompng") && !empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA))
240 $captcha_refresh =
img_picto($langs->trans(
"Refresh"),
'refresh',
'id="captcha_refresh_img"');
246 if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK) || empty($conf->global->MAIN_HELPCENTER_DISABLELINK))
248 if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK))
253 if (empty($conf->global->MAIN_HELPCENTER_DISABLELINK))
261 if (!empty($conf->global->MAIN_HOME))
265 $texttoshow =
make_substitutions($conf->global->MAIN_HOME, $substitutionarray, $langs);
271 $main_google_ad_client = ((!empty($conf->global->MAIN_GOOGLE_AD_CLIENT) && !empty($conf->global->MAIN_GOOGLE_AD_SLOT)) ? 1 : 0);
274 $dol_loginmesg = (!empty($_SESSION[
"dol_loginmesg"]) ? $_SESSION[
"dol_loginmesg"] :
'');
276 $favicon = DOL_URL_ROOT.
'/theme/dolibarr_256x256_color.png';
277 if (!empty($mysoc->logo_squarred_mini)) $favicon = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_squarred_mini);
278 if (!empty($conf->global->MAIN_FAVICON_URL)) $favicon = $conf->global->MAIN_FAVICON_URL;
280 $jquerytheme =
'base';
281 if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
284 $dol_hide_topmenu =
GETPOST(
'dol_hide_topmenu',
'int');
285 $dol_hide_leftmenu =
GETPOST(
'dol_hide_leftmenu',
'int');
286 $dol_optimize_smallscreen =
GETPOST(
'dol_optimize_smallscreen',
'int');
287 $dol_no_mouse_hover =
GETPOST(
'dol_no_mouse_hover',
'int');
288 $dol_use_jmobile =
GETPOST(
'dol_use_jmobile',
'int');
291 include $template_dir.
'login.tpl.php';
296 $_SESSION[
"dol_loginmesg"] =
'';
314 $saltlen = 8; $saltprefix =
'$1$'; $saltsuffix =
'$';
break;
316 $saltlen = 8; $saltprefix =
'$1$'; $saltsuffix =
'$';
break;
319 $saltlen = 2; $saltprefix =
''; $saltsuffix =
'';
break;
322 while (
dol_strlen($salt) < $saltlen) $salt .= chr(mt_rand(64, 126));
324 $result = $saltprefix.$salt.$saltsuffix;
337 dol_syslog(
"encodedecode_dbpassconf level=".$level, LOG_DEBUG);
340 $passwd_crypted =
'';
342 if ($fp = fopen(DOL_DOCUMENT_ROOT.
'/conf/conf.php',
'r'))
346 $buffer = fgets($fp, 4096);
350 if (preg_match(
'/^[^#]*dolibarr_main_db_encrypted_pass[\s]*=[\s]*(.*)/i', $buffer, $reg))
352 $val = trim($reg[1]);
353 $val = preg_replace(
'/^["\']/',
'', $val);
354 $val = preg_replace(
'/["\'][\s;]*$/',
'', $val);
357 $passwd_crypted = $val;
362 } elseif (preg_match(
'/^[^#]*dolibarr_main_db_pass[\s]*=[\s]*(.*)/i', $buffer, $reg))
364 $val = trim($reg[1]);
365 $val = preg_replace(
'/^["\']/',
'', $val);
366 $val = preg_replace(
'/["\'][\s;]*$/',
'', $val);
367 if (preg_match(
'/crypted:/i', $buffer))
369 $val = preg_replace(
'/crypted:/i',
'', $val);
370 $passwd_crypted = $val;
376 $passwd_crypted = $val;
387 $config .=
'$dolibarr_main_db_pass=\''.$passwd.
'\';
'."\n";
391 $config .= '$dolibarr_main_db_pass=\
'crypted:'.$passwd_crypted.
'\';
'."\n";
394 //print 'passwd =
'.$passwd.' - passwd_crypted =
'.$passwd_crypted;
402 // Write new conf file
403 $file = DOL_DOCUMENT_ROOT.'/
conf/
conf.php
';
404 if ($fp = @fopen($file, 'w
'))
411 // It's config file, so we set read permission
for creator only.
417 dol_syslog(
"encodedecode_dbpassconf Failed to open conf.php file for writing", LOG_WARNING);
421 dol_syslog(
"encodedecode_dbpassconf Failed to read conf.php", LOG_ERR);
437 global $db, $conf, $langs, $user;
439 $generated_password =
'';
442 $lowercase =
"qwertyuiopasdfghjklzxcvbnm";
443 $uppercase =
"ASDFGHJKLZXCVBNMQWERTYUIOP";
444 $numbers =
"1234567890";
446 $nbofchar = round($length / 3);
447 $nbofcharlast = ($length - 2 * $nbofchar);
449 if (function_exists(
'random_int'))
451 $max = strlen($lowercase) - 1;
452 for ($x = 0; $x < $nbofchar; $x++) {
453 $tmp = random_int(0, $max);
454 $randomCode .= $lowercase[$tmp];
456 $max = strlen($uppercase) - 1;
457 for ($x = 0; $x < $nbofchar; $x++) {
458 $tmp = random_int(0, $max);
459 $randomCode .= $uppercase[$tmp];
461 $max = strlen($numbers) - 1;
462 for ($x = 0; $x < $nbofcharlast; $x++) {
463 $tmp = random_int(0, $max);
464 $randomCode .= $numbers[$tmp];
467 $generated_password = str_shuffle($randomCode);
470 $max = strlen($lowercase) - 1;
471 for ($x = 0; $x < $nbofchar; $x++) {
472 $tmp = mt_rand(0, $max);
473 $randomCode .= $lowercase[$tmp];
475 $max = strlen($uppercase) - 1;
476 for ($x = 0; $x < $nbofchar; $x++) {
477 $tmp = mt_rand(0, $max);
478 $randomCode .= $uppercase[$tmp];
480 $max = strlen($numbers) - 1;
481 for ($x = 0; $x < $nbofcharlast; $x++) {
482 $tmp = mt_rand(0, $max);
483 $randomCode .= $numbers[$tmp];
486 $generated_password = str_shuffle($randomCode);
488 } elseif (!empty($conf->global->USER_PASSWORD_GENERATED))
490 $nomclass =
"modGeneratePass".ucfirst($conf->global->USER_PASSWORD_GENERATED);
491 $nomfichier = $nomclass.
".class.php";
493 require_once DOL_DOCUMENT_ROOT.
"/core/modules/security/generate/".$nomfichier;
494 $genhandler =
new $nomclass($db, $conf, $langs, $user);
495 $generated_password = $genhandler->getNewGeneratedPassword();
500 if (is_array($replaceambiguouschars) && count($replaceambiguouschars) > 0)
503 $max = strlen($numbers) - 1;
504 if (function_exists(
'random_int')) {
505 $tmp = random_int(0, $max);
506 $generated_password = str_replace($replaceambiguouschars, $numbers[$tmp], $generated_password);
508 $tmp = mt_rand(0, $max);
509 $generated_password = str_replace($replaceambiguouschars, $numbers[$tmp], $generated_password);
513 return $generated_password;
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
dol_decode($chain, $key= '1')
Decode a base 64 encoded + specific delta change.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
if(!function_exists('dol_loginfunction')) makesalt($type=CRYPT_SALT_LENGTH)
Fonction pour initialiser un salt pour la fonction crypt.
if($reshook< 0) if(empty($reshook)) $dol_url_root
View.
dol_getwebuser($mode)
Return user/group account of web server.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_encode($chain, $key= '1')
Encode a string with base 64 algorithm + specific delta change.
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode, $context= '')
Return a login if login/pass was successfull.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
encodedecode_dbpassconf($level=0)
Encode or decode database password in config file.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...