dolibarr
25.0.0-alpha
Main Page
Related Pages
Topics
Classes
Files
Examples
File List
File Members
dolibarr_dev
htdocs
core
modules
security
captcha
modCaptchaStandard.class.php
Go to the documentation of this file.
1
<?php
2
/* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18
* or see https://www.gnu.org/
19
*/
20
27
require_once DOL_DOCUMENT_ROOT.
'/core/modules/security/captcha/modules_captcha.php'
;
28
require_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/modGeneratePassStandard.class.php'
;
29
30
34
class
modCaptchaStandard
extends
ModeleCaptcha
35
{
39
public
$id;
40
44
public
$picto =
'fa-shield-alt'
;
45
49
public
$position = 10;
50
51
60
public
function
__construct
($db, $conf, $langs, $user)
61
{
62
$this->
id
= strtolower(preg_replace(
'/^modCaptcha/i'
,
''
, get_class($this)));
63
64
$this->db = $db;
65
$this->
conf
= $conf;
66
$this->langs = $langs;
67
$this->
user
= $user;
68
}
69
75
public
function
getDescription
()
76
{
77
global $langs;
78
return
$langs->trans(
"DolibarrStandardCaptcha"
);
79
}
80
86
public
function
getExample
()
87
{
88
global $db, $conf, $langs, $user;
89
90
$generator =
new
modGeneratePassStandard
($db,
$conf
, $langs, $user);
91
$generator->length =
'5'
;
92
$example = $generator->getExample();
93
94
if
(function_exists(
"imagecreate"
) && function_exists(
"imagepng"
)) {
95
$img = imagecreate(80, 32);
96
if
(!$img) {
97
return
"Problem with GD creation"
;
98
}
99
$background_color = imagecolorallocate($img, 250, 250, 250);
// do not comment this line
100
$ecriture_color = imagecolorallocate($img, 0, 0, 0);
101
imagestring($img, 4, 15, 8, $example, $ecriture_color);
102
103
ob_start();
104
imagepng($img);
105
$image_data = ob_get_contents();
106
ob_end_clean();
107
108
return
'<img class="inline-block valignmiddle" src="data:image/png;base64,'
. base64_encode($image_data) .
'" border="0" width="80" height="32" />'
;
109
}
else
{
110
// Image grise
111
$image_data_base64 =
'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAFElEQVR4nGNsaGhgwA2Y8MiNYGkA22EBlPG3fjQAAAAASUVORK5CYII='
;
112
return
'<img class="inline-block valignmiddle" src="data:image/png;base64,'
. $image_data_base64 .
'" border="0" width="80" height="32" />'
;
113
}
114
}
115
122
public
function
getCaptchaCodeForForm
($php_self =
''
)
123
{
124
global $langs;
125
126
$idofbutton =
"actionlogin"
;
127
128
// Output the image by calling /core/antispamimage.php
129
// This antispamimage also record the value of code into $_SESSION['dol_antispam_value'] so we will be able to validate by calling
130
// validateCodeAfterLoginSubmit() later when we submit the login form.
131
132
$out =
'<!-- Captcha -->
133
<div class="trinputlogin">
134
<div class="tagtd tdinputlogin nowrap none valignmiddle">
135
136
<span class="fa fa-unlock"></span>
137
<span class="nofa span-icon-security inline-block">
138
<input id="securitycode" placeholder="'
.$langs->trans(
"SecurityCode"
).
'" class="flat input-icon-security width125" type="text" maxlength="5" name="code" tabindex="3" autocomplete="off" />
139
</span>
140
<span class="nowrap inline-block">
141
<img class="inline-block valignmiddle" src="'
.DOL_URL_ROOT.
'/core/antispamimage.php" border="0" width="80" height="32" id="img_securitycode" />
142
<a class="inline-block valignmiddle" href="'
.$php_self.
'" tabindex="4" data-role="button" onclick="submitFormFromCaptcha(event)">'
.img_picto($langs->trans(
"Refresh"
),
'refresh'
,
'id="captcha_refresh_img"'
).
'</a>
143
</span>
144
145
</div>
146
</div>
147
148
<script>
149
function submitFormFromCaptcha(event) {
150
console.log("submitFormFromCaptcha");
151
152
// Prevent the default action of the link
153
event.preventDefault();
154
// Search the form
155
const form = event.target.closest("form");
156
157
// Submit the form if found
158
if (form) {
159
console.log(\'we set '
.
dol_escape_js
($idofbutton).
' to value "disabled" if found\'); /* TODO Why this ? #actionlogn seems to not exists */
160
elementid = document.getElementById(\''
.
dol_escape_js
($idofbutton).
'\'
);
161
console.log(elementid);
162
if
(elementid) {
163
elementid.value =
"disabled"
;
164
}
165
166
form.submit();
167
}
168
}
169
</script>
170
<!-- End code
for
Captcha -->
'."\n";
171
172
return $out;
173
}
174
175
176
183
public function validateCodeAfterLoginSubmit()
184
{
185
$sessionkey = 'dol_antispam_value
'; // The same key than set into the /core/antispamimage.php file.
186
187
$ok = (array_key_exists($sessionkey, $_SESSION) && (strtolower($_SESSION[$sessionkey]) === strtolower(GETPOST('
code
', '
restricthtml
')))) ? 1 : 0;
188
189
return $ok;
190
}
191
}
$conf
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Definition
chat_history.php:55
ModeleCaptcha
Parent class for password rules/management modules.
Definition
modules_captcha.php:32
modCaptchaStandard
Class to generate a password according to a dolibarr standard rule (12 random chars)
Definition
modCaptchaStandard.class.php:35
modCaptchaStandard\getCaptchaCodeForForm
getCaptchaCodeForForm($php_self='')
Return the HTML content to output on a form that need the captcha.
Definition
modCaptchaStandard.class.php:122
modCaptchaStandard\__construct
__construct($db, $conf, $langs, $user)
Constructor.
Definition
modCaptchaStandard.class.php:60
modCaptchaStandard\getDescription
getDescription()
Return description of module.
Definition
modCaptchaStandard.class.php:75
modCaptchaStandard\getExample
getExample()
Return an example of password generated by this module.
Definition
modCaptchaStandard.class.php:86
modGeneratePassStandard
Class to generate a password according to a dolibarr standard rule (12 random chars)
Definition
modGeneratePassStandard.class.php:33
dol_escape_js
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
Definition
functions.lib.php:2332
conf
conf($dolibarr_main_document_root, $realpathconf=null)
Load conf file (file must exists)
Definition
inc.php:431
user
$conf db user
Active Directory does not allow anonymous connections.
Definition
repair.php:166
Generated on Sun Nov 1 2026 01:00:22 for
dolibarr
by Doxygen 1.11.0