diff --git a/htdocs/admin/security_captcha.php b/htdocs/admin/security_captcha.php index 84b3faf29f2..18a9e51e240 100644 --- a/htdocs/admin/security_captcha.php +++ b/htdocs/admin/security_captcha.php @@ -105,7 +105,7 @@ print "
\n"; // Load array with all captcha generation modules -$dir = "../core/modules/security/captcha"; +$dir = DOL_DOCUMENT_ROOT."/core/modules/security/captcha"; clearstatcache(); $handle = opendir($dir); $i = 1; @@ -142,23 +142,41 @@ print '
'; print $langs->trans("UseCaptchaCode"); -if (function_exists("imagecreatefrompng")) { - if (!empty($conf->use_javascript_ajax)) { - print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA', array(), null, 0, 0, 1); - } else { - if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) { - print ''.img_picto($langs->trans("Disabled"), 'off').''; - } else { - print ''.img_picto($langs->trans("Enabled"), 'on').''; - } - } +if (!empty($conf->use_javascript_ajax)) { + print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA', array(), null, 0, 0, 1); } else { - $desc = $form->textwithpicto('', $langs->transnoentities("EnableGDLibraryDesc"), 1, 'warning'); - print $desc; + if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) { + print ''.img_picto($langs->trans("Disabled"), 'off').''; + } else { + print ''.img_picto($langs->trans("Enabled"), 'on').''; + } } +if (isModEnabled('ticket')) { + print '
'; + print $langs->trans("TicketUseCaptchaCodeHelp"); + if (!empty($conf->use_javascript_ajax)) { + print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_TICKET', array(), null, 0, 0, 1); + } else { + if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_TICKET')) { + print ''.img_picto($langs->trans("Disabled"), 'off').''; + } else { + print ''.img_picto($langs->trans("Enabled"), 'on').''; + } + } +} +$showavailablecaptcha = 0; if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) { + $showavailablecaptcha = 1; +} +if (isModEnabled('ticket') && getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_TICKET')) { + $showavailablecaptcha = 1; +} + +$selectedcaptcha = getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_HANDLER', 'standard'); + +if ($showavailablecaptcha) { print '
'; print '
'; print '
'; @@ -171,13 +189,6 @@ if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) { print ''.$langs->trans("Status").''; print ''; - $arrayofcaptcha = array( - 'standard' => array('label' => 'Standard', 'picto' => 'ee') - ); - //$arrayofcaptcha['google'] = array('label' => 'Google'); - - $selectedcaptcha = 'standard'; - // Loop on each available captcha foreach ($arrayhandler as $key => $module) { print ''; @@ -192,9 +203,22 @@ if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) { print $module->getExample().'
'; print ''; print ''; - if ($key == $selectedcaptcha) { - print 'On'; + + if (function_exists("imagecreatefrompng")) { + if ($key != $selectedcaptcha) { + print ''; + } else { + print ''; + } + } else { + $desc = $form->textwithpicto('', $langs->transnoentities("EnableGDLibraryDesc"), 1, 'warning'); + print $desc; } + print ''; print ''; } diff --git a/htdocs/core/lib/security2.lib.php b/htdocs/core/lib/security2.lib.php index 627a6ac4634..7a6b9c14f72 100644 --- a/htdocs/core/lib/security2.lib.php +++ b/htdocs/core/lib/security2.lib.php @@ -273,9 +273,11 @@ if (!function_exists('dol_loginfunction')) { // Security graphical code $captcha = 0; $captcha_refresh = ''; - if (function_exists("imagecreatefrompng") && getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) { - $captcha = 1; - $captcha_refresh = img_picto($langs->trans("Refresh"), 'refresh', 'id="captcha_refresh_img"'); + if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) { + $captcha = getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_HANDLER', 'standard'); + if ($captcha == 'standard') { + $captcha_refresh = img_picto($langs->trans("Refresh"), 'refresh', 'id="captcha_refresh_img"'); + } } // Extra link diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index 0dad08cad4e..94ff4126872 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -41,6 +41,7 @@ if ($size > 10000) { require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; ' +@phan-var-force string $captcha @phan-var-force string $captcha_refresh @phan-var-force int<0,1> $dol_hide_leftmenu @phan-var-force int<0,1> $dol_hide_topmenu @@ -278,7 +279,22 @@ if (!empty($captcha)) { } else { $php_self .= '?time='.dol_print_date(dol_now(), 'dayhourlog'); } - // TODO: provide accessible captcha variants?> + + $classfile = DOL_DOCUMENT_ROOT."/core/modules/security/captcha/modCaptcha".ucfirst($captcha).'.class.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $captchaobj = null; + if (dol_is_file($classfile)) { + // Charging the numbering class + $classname = "modCaptcha".ucfirst($captcha); + require_once $classfile; + + $captchaobj = new $classname($db, $conf, $langs, $user); + } + + if (is_object($captchaobj) && method_exists($captchaobj, 'getCaptchaCodeForForm')) { + // TODO: get this code using a method of captcha + } else { + ?>
@@ -293,7 +309,8 @@ if (!empty($captcha)) {
- - * Copyright (C) 2011-2013 Laurent Destailleur +/* Copyright (C) 2009-2010 Regis Houssin + * Copyright (C) 2011-2024 Laurent Destailleur * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -17,6 +17,8 @@ * along with this program. If not, see . */ +// Page to ask email for password forgotten + if (!defined('NOBROWSERNOTIF')) { define('NOBROWSERNOTIF', 1); } @@ -164,7 +166,22 @@ if (!empty($captcha)) { } else { $php_self .= '?time='.dol_print_date(dol_now(), 'dayhourlog'); } - // TODO: provide accessible captcha variants?> + + $classfile = DOL_DOCUMENT_ROOT."/core/modules/security/captcha/modCaptcha".ucfirst($captcha).'.class.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $captchaobj = null; + if (dol_is_file($classfile)) { + // Charging the numbering class + $classname = "modCaptcha".ucfirst($captcha); + require_once $classfile; + + $captchaobj = new $classname($db, $conf, $langs, $user); + } + + if (is_object($captchaobj) && method_exists($captchaobj, 'getCaptchaCodeForForm')) { + // TODO: get this code using a method of captcha + } else { + ?>
@@ -179,7 +196,8 @@ if (!empty($captcha)) {
- - * Copyright (C) 2024 Frédéric France +/* Copyright (C) 2022 Laurent Destailleur + * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -205,7 +205,22 @@ if (!empty($captcha)) { } else { $php_self .= '?time='.dol_print_date(dol_now(), 'dayhourlog'); } - // TODO: provide accessible captcha variants?> + + $classfile = DOL_DOCUMENT_ROOT."/core/modules/security/captcha/modCaptcha".ucfirst($captcha).'.class.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $captchaobj = null; + if (dol_is_file($classfile)) { + // Charging the numbering class + $classname = "modCaptcha".ucfirst($captcha); + require_once $classfile; + + $captchaobj = new $classname($db, $conf, $langs, $user); + } + + if (is_object($captchaobj) && method_exists($captchaobj, 'getCaptchaCodeForForm')) { + // TODO: get this code using a method of captcha + } else { + ?>
@@ -220,7 +235,8 @@ if (!empty($captcha)) {
-