38 if ($mode ==
'user') {
39 $t = getenv(
'APACHE_RUN_USER');
41 if ($mode ==
'group') {
42 $t = getenv(
'APACHE_RUN_GROUP');
63 if ($entitytotest ==
'') {
67 dol_syslog(
"checkLoginPassEntity usertotest=".$usertotest.
" entitytotest=".$entitytotest.
" authmode=".join(
',', $authmode));
73 foreach ($authmode as $mode) {
74 if ($test && $mode && !$login) {
77 $authfile =
'functions_'.$mode.
'.php';
80 $dirlogin = array_merge(array(
"/core/login"), (array) $conf->modules_parts[
'login']);
81 foreach ($dirlogin as $reldir) {
86 $tmpnewauthfile = $newdir.(preg_match(
'/\/$/', $newdir) ?
'' :
'/').$authfile;
87 if (is_file($tmpnewauthfile)) {
88 $fullauthfile = $tmpnewauthfile;
94 $result = include_once $fullauthfile;
96 if ($fullauthfile && $result) {
98 $function =
'check_user_password_'.$mode;
99 $login = call_user_func($function, $usertotest, $passwordtotest, $entitytotest, $context);
100 if ($login && $login !=
'--bad-login-validity--') {
102 $conf->authmode = $mode;
105 $dol_screenwidth =
GETPOST(
'screenwidth');
106 $dol_screenheight =
GETPOST(
'screenheight');
109 dol_syslog(
"Authentication KO - failed to load file '".$authfile.
"'", LOG_ERR);
112 $langs->loadLangs(array(
'other',
'main',
'errors'));
114 $_SESSION[
"dol_loginmesg"] = (empty($_SESSION[
"dol_loginmesg"]) ?
'' : $_SESSION[
"dol_loginmesg"].
', ').$langs->transnoentitiesnoconv(
"ErrorFailedToLoadLoginFileForMode", $mode);
124 if (!function_exists(
'dol_loginfunction')) {
134 function dol_loginfunction($langs, $conf, $mysoc)
136 global $dolibarr_main_demo, $dolibarr_main_force_https;
137 global $db, $hookmanager;
139 $langs->loadLangs(array(
"main",
"other",
"help",
"admin"));
142 $hookmanager->initHooks(array(
'mainloginpage'));
144 $main_authentication = $conf->file->main_authentication;
146 $session_name = session_name();
151 $appli = constant(
'DOL_APPLICATION_TITLE');
152 $title = $appli.
' '.constant(
'DOL_VERSION');
153 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
154 $title = $conf->global->MAIN_APPLICATION_TITLE;
156 $titletruedolibarrversion = constant(
'DOL_VERSION');
177 if (!empty($conf->modules_parts[
'tpl'])) {
178 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array(
'/core/tpl/'));
179 foreach ($dirtpls as $reldir) {
181 if (file_exists($tmp)) {
182 $template_dir = preg_replace(
'/login\.tpl\.php$/',
'', $tmp);
187 $template_dir = DOL_DOCUMENT_ROOT.
"/core/tpl/";
192 $prefix = dol_getprefix(
'');
193 $sessiontimeout =
'DOLSESSTIMEOUT_'.$prefix;
195 if (!empty($conf->global->MAIN_SESSION_TIMEOUT)) {
196 if (session_status() != PHP_SESSION_ACTIVE) {
197 if (PHP_VERSION_ID < 70300) {
198 session_set_cookie_params(0,
'/',
null, ((empty($dolibarr_main_force_https) &&
isHTTPS() ===
false) ?
false :
true),
true);
201 $sessioncookieparams = array(
205 'secure' => ((empty($dolibarr_main_force_https) &&
isHTTPS() ===
false) ?
false :
true),
209 session_set_cookie_params($sessioncookieparams);
212 setcookie($sessiontimeout, $conf->global->MAIN_SESSION_TIMEOUT, 0,
"/",
null, (empty($dolibarr_main_force_https) ?
false :
true),
true);
216 if (
GETPOST(
'urlfrom',
'alpha')) {
217 $_SESSION[
"urlfrom"] =
GETPOST(
'urlfrom',
'alpha');
219 unset($_SESSION[
"urlfrom"]);
222 if (!
GETPOST(
"username",
'alpha')) {
223 $focus_element =
'username';
225 $focus_element =
'password';
230 if (!empty($dolibarr_main_demo)) {
231 $tab = explode(
',', $dolibarr_main_demo);
232 $demologin = $tab[0];
233 $demopassword = $tab[1];
237 $parameters = array(
'entity' =>
GETPOST(
'entity',
'int'),
'switchentity' =>
GETPOST(
'switchentity',
'int'));
238 $reshook = $hookmanager->executeHooks(
'getLoginPageOptions', $parameters);
239 $morelogincontent = $hookmanager->resPrint;
242 $parameters = array(
'entity' =>
GETPOST(
'entity',
'int'),
'switchentity' =>
GETPOST(
'switchentity',
'int'));
243 $reshook = $hookmanager->executeHooks(
'getLoginPageExtraOptions', $parameters);
244 $moreloginextracontent = $hookmanager->resPrint;
247 $parameters = array(
'entity' =>
GETPOST(
'entity',
'int'),
'switchentity' =>
GETPOST(
'switchentity',
'int'));
248 $reshook = $hookmanager->executeHooks(
'redirectAfterConnection', $parameters);
249 $php_self = $hookmanager->resPrint;
252 $login = (!empty($hookmanager->resArray[
'username']) ? $hookmanager->resArray[
'username'] : (
GETPOST(
"username",
"alpha") ?
GETPOST(
"username",
"alpha") : $demologin));
253 $password = $demopassword;
257 $urllogo = DOL_URL_ROOT.
'/theme/common/login_logo.png';
259 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small)) {
260 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_small);
261 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo)) {
262 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/'.$mysoc->logo);
264 } elseif (!empty($mysoc->logo_squarred_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_squarred_small)) {
265 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_squarred_small);
266 } elseif (is_readable(DOL_DOCUMENT_ROOT.
'/theme/dolibarr_logo.svg')) {
267 $urllogo = DOL_URL_ROOT.
'/theme/dolibarr_logo.svg';
272 $captcha_refresh =
'';
273 if (function_exists(
"imagecreatefrompng") && !empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA)) {
275 $captcha_refresh =
img_picto($langs->trans(
"Refresh"),
'refresh',
'id="captcha_refresh_img"');
281 if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK) || empty($conf->global->MAIN_HELPCENTER_DISABLELINK)) {
282 if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK)) {
286 if (empty($conf->global->MAIN_HELPCENTER_DISABLELINK)) {
293 if (!empty($conf->global->MAIN_HOME)) {
296 $texttoshow =
make_substitutions($conf->global->MAIN_HOME, $substitutionarray, $langs);
302 $main_google_ad_client = ((!empty($conf->global->MAIN_GOOGLE_AD_CLIENT) && !empty($conf->global->MAIN_GOOGLE_AD_SLOT)) ? 1 : 0);
305 $dol_loginmesg = (!empty($_SESSION[
"dol_loginmesg"]) ? $_SESSION[
"dol_loginmesg"] :
'');
307 $favicon = DOL_URL_ROOT.
'/theme/dolibarr_256x256_color.png';
308 if (!empty($mysoc->logo_squarred_mini)) {
309 $favicon = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_squarred_mini);
311 if (!empty($conf->global->MAIN_FAVICON_URL)) {
312 $favicon = $conf->global->MAIN_FAVICON_URL;
315 $jquerytheme =
'base';
316 if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) {
317 $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
321 $dol_hide_topmenu =
GETPOST(
'dol_hide_topmenu',
'int');
322 $dol_hide_leftmenu =
GETPOST(
'dol_hide_leftmenu',
'int');
323 $dol_optimize_smallscreen =
GETPOST(
'dol_optimize_smallscreen',
'int');
324 $dol_no_mouse_hover =
GETPOST(
'dol_no_mouse_hover',
'int');
325 $dol_use_jmobile =
GETPOST(
'dol_use_jmobile',
'int');
328 include $template_dir.
'login.tpl.php';
333 $_SESSION[
"dol_loginmesg"] =
'';
368 $salt .= chr(mt_rand(64, 126));
371 $result = $saltprefix.$salt.$saltsuffix;
384 dol_syslog(
"encodedecode_dbpassconf level=".$level, LOG_DEBUG);
387 $passwd_crypted =
'';
389 if ($fp = fopen(DOL_DOCUMENT_ROOT.
'/conf/conf.php',
'r')) {
391 $buffer = fgets($fp, 4096);
396 if (preg_match(
'/^[^#]*dolibarr_main_db_encrypted_pass[\s]*=[\s]*(.*)/i', $buffer, $reg)) {
397 $val = trim($reg[1]);
398 $val = preg_replace(
'/^["\']/',
'', $val);
399 $val = preg_replace(
'/["\'][\s;]*$/',
'', $val);
401 $passwd_crypted = $val;
408 } elseif (preg_match(
'/^[^#]*dolibarr_main_db_pass[\s]*=[\s]*(.*)/i', $buffer, $reg)) {
409 $val = trim($reg[1]);
410 $val = preg_replace(
'/^["\']/',
'', $val);
411 $val = preg_replace(
'/["\'][\s;]*$/',
'', $val);
412 if (preg_match(
'/crypted:/i', $buffer)) {
414 $val = preg_replace(
'/crypted:/i',
'', $val);
415 $passwd_crypted = $val;
418 } elseif (preg_match(
'/^dolcrypt:([^:]+):(.*)$/i', $buffer, $reg)) {
420 $val = preg_replace(
'/crypted:([^:]+):/i',
'', $val);
421 $passwd_crypted = $val;
427 $passwd_crypted = $val;
436 $config .=
'$dolibarr_main_db_pass=\''.$passwd.
'\';
'."\n";
439 $config .= '$dolibarr_main_db_pass=\
'crypted:'.$passwd_crypted.
'\';
'."\n";
442 //print 'passwd =
'.$passwd.' - passwd_crypted =
'.$passwd_crypted;
450 // Write new conf file
451 $file = DOL_DOCUMENT_ROOT.'/
conf/
conf.php
';
452 if ($fp = @fopen($file, 'w
')) {
458 // It's config file, so we
set read permission
for creator only.
464 dol_syslog(
"encodedecode_dbpassconf Failed to open conf.php file for writing", LOG_WARNING);
468 dol_syslog(
"encodedecode_dbpassconf Failed to read conf.php", LOG_ERR);
484 global $db, $conf, $langs, $user;
486 $generated_password =
'';
488 $lowercase =
"qwertyuiopasdfghjklzxcvbnm";
489 $uppercase =
"ASDFGHJKLZXCVBNMQWERTYUIOP";
490 $numbers =
"1234567890";
492 $nbofchar = round($length / 3);
493 $nbofcharlast = ($length - 2 * $nbofchar);
495 if (function_exists(
'random_int')) {
496 $max = strlen($lowercase) - 1;
497 for ($x = 0; $x < $nbofchar; $x++) {
498 $tmp = random_int(0, $max);
499 $randomCode .= $lowercase[$tmp];
501 $max = strlen($uppercase) - 1;
502 for ($x = 0; $x < $nbofchar; $x++) {
503 $tmp = random_int(0, $max);
504 $randomCode .= $uppercase[$tmp];
506 $max = strlen($numbers) - 1;
507 for ($x = 0; $x < $nbofcharlast; $x++) {
508 $tmp = random_int(0, $max);
509 $randomCode .= $numbers[$tmp];
512 $generated_password = str_shuffle($randomCode);
515 $max = strlen($lowercase) - 1;
516 for ($x = 0; $x < $nbofchar; $x++) {
517 $tmp = mt_rand(0, $max);
518 $randomCode .= $lowercase[$tmp];
520 $max = strlen($uppercase) - 1;
521 for ($x = 0; $x < $nbofchar; $x++) {
522 $tmp = mt_rand(0, $max);
523 $randomCode .= $uppercase[$tmp];
525 $max = strlen($numbers) - 1;
526 for ($x = 0; $x < $nbofcharlast; $x++) {
527 $tmp = mt_rand(0, $max);
528 $randomCode .= $numbers[$tmp];
531 $generated_password = str_shuffle($randomCode);
533 } elseif (!empty($conf->global->USER_PASSWORD_GENERATED)) {
534 $nomclass =
"modGeneratePass".ucfirst($conf->global->USER_PASSWORD_GENERATED);
535 $nomfichier = $nomclass.
".class.php";
537 require_once DOL_DOCUMENT_ROOT.
"/core/modules/security/generate/".$nomfichier;
538 $genhandler =
new $nomclass($db, $conf, $langs, $user);
539 $generated_password = $genhandler->getNewGeneratedPassword();
544 if (is_array($replaceambiguouschars) && count($replaceambiguouschars) > 0) {
546 $max = strlen($numbers) - 1;
547 if (function_exists(
'random_int')) {
548 $tmp = random_int(0, $max);
549 $generated_password = str_replace($replaceambiguouschars, $numbers[$tmp], $generated_password);
551 $tmp = mt_rand(0, $max);
552 $generated_password = str_replace($replaceambiguouschars, $numbers[$tmp], $generated_password);
556 return $generated_password;
571 if (!empty($conf->use_javascript_ajax)) {
572 print
"\n".
'<!-- Js code to suggest a security key --><script type="text/javascript">';
573 print
'$(document).ready(function () {
574 $("#'.dol_escape_js($htmlnameofbutton).
'").click(function() {
575 console.log("We click on the button to suggest a key");
576 $.get( "'.DOL_URL_ROOT.
'/core/ajax/security.php", {
577 action: \'getrandompassword\',
582 $(
"#'.dol_escape_js($htmlname).'").val(result);
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
isHTTPS()
Return if we are using a HTTPS connexion Check HTTPS (no way to be modified by user but may be empty ...
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_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
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...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
if($reshook< 0) if(empty($reshook)) $dol_url_root
View.
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token')
Ouput javacript to autoset a generated password using default module into a HTML element.
dol_getwebuser($mode)
Return user/group account of web server.
encodedecode_dbpassconf($level=0)
Encode or decode database password in config file.
checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode, $context='')
Return a login if login/pass was successfull.
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
if(!function_exists('dol_loginfunction')) makesalt($type=CRYPT_SALT_LENGTH)
Fonction pour initialiser un salt pour la fonction crypt.
dol_encode($chain, $key='1')
Encode a string with base 64 algorithm + specific delta change.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='')
Decode a string with a symetric encryption.