dolibarr 24.0.0-beta
security_captcha.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2026 Charlene Benke <Charlene@patas-monkey.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
41
42// Load translation files required by the page
43$langs->loadLangs(array("users", "admin", "other"));
44
45if (!$user->admin) {
47}
48
49$action = GETPOST('action', 'aZ09');
50$handler = GETPOST('handler', 'aZ09');
51
52
53/*
54 * Actions
55 */
56
57if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
58 $code = $reg[1];
59 $value = (GETPOST($code, 'alpha') ? GETPOST($code, 'alpha') : 1);
60 if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0) {
61 header("Location: ".$_SERVER["PHP_SELF"]);
62 exit;
63 } else {
65 }
66} elseif (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
67 $code = $reg[1];
68 if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
69 header("Location: ".$_SERVER["PHP_SELF"]);
70 exit;
71 } else {
73 }
74} elseif ($action == 'setcaptchahandler') {
75 if (!dolibarr_set_const($db, 'MAIN_SECURITY_ENABLECAPTCHA_HANDLER', GETPOST("value", "aZ09"), 'chaine', 0, '', $conf->entity)) {
77 }
78}
79
80
81/*
82 * View
83 */
84
85$form = new Form($db);
86
87$wikihelp = 'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
88llxHeader('', $langs->trans("Miscellaneous"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-security_other');
89
90print load_fiche_titre($langs->trans("SecuritySetup"), '', 'title_setup');
91
92print '<span class="opacitymedium">'.$langs->trans("CaptchaDesc")."</span><br>\n";
93print "<br>\n";
94
95$dirModCaptcha = array_merge(array('/core/modules/security/captcha/'), (isset($conf->modules_parts['captcha']) && is_array($conf->modules_parts['captcha'])) ? $conf->modules_parts['captcha'] : array());
96
97// Load array with all captcha generation modules
98$arrayhandler = array();
99
100foreach ($dirModCaptcha as $dirroot) {
101 $dir = dol_buildpath($dirroot, 0);
102
103 $handle = @opendir($dir);
104
105 $i = 1;
106 if (is_resource($handle)) {
107 while (($file = readdir($handle)) !== false) {
108 $reg = array();
109 if (preg_match('/(modCaptcha[a-z]+)\.class\.php$/i', $file, $reg)) {
110 // Charging the numbering class
111 $classname = $reg[1];
112 require_once $dir.'/'.$file;
113
114 $obj = new $classname($db, $conf, $langs, $user);
115 '@phan-var-force ModeleCaptcha $obj';
117 $arrayhandler[$obj->id] = $obj;
118 $i++;
119 }
120 }
121 closedir($handle);
122 }
123}
124$arrayhandler = dol_sort_array($arrayhandler, 'position');
125
126
127print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
128print '<input type="hidden" name="token" value="'.newToken().'">';
129print '<input type="hidden" name="action" value="updateform">';
130
131$head = security_prepare_head();
132
133print dol_get_fiche_head($head, 'captcha', '', -1);
134
135print '<br>';
136
137// Set if a captcha is used on at least one place
138$showavailablecaptcha = 0;
139if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) {
140 $showavailablecaptcha = 1;
141}
142
143print '<div class="div-table-responsive">';
144print '<table class="noborder centpercent">';
145print '<tr class="liste_titre">';
146print '<td>'.$langs->trans("Captcha").'</td>';
147print '<td class="right" width="100">'.$langs->trans("Status").'</td>';
148print '</tr>';
149
150print '<tr class="oddeven"><td>' . $langs->trans("UseCaptchaCode").' - Login</td><td class="right" width="100">';
151if (!empty($conf->use_javascript_ajax)) {
152 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA', array(), null, 0, 0, 1);
153} else {
154 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) {
155 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
156 } else {
157 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
158 }
159}
160print '</td></tr>';
161
162if (isModEnabled('societe')) {
163 print '<tr class="oddeven"><td>' . $langs->trans("UseCaptchaCode").' - Thirdparty public contact form</td><td class="right" width="100">';
164 if (!empty($conf->use_javascript_ajax)) {
165 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY', array(), null, 0, 0, 1);
166 } else {
167 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY')) {
168 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
169 } else {
170 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
171 }
172 }
173 print '</td></tr>';
174 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY')) {
175 $showavailablecaptcha = 1;
176 }
177}
178
179if (isModEnabled('ticket')) {
180 print '<tr class="oddeven"><td>' . $langs->trans("UseCaptchaCode").' - Public ticket creation</td><td class="right" width="100">';
181 if (!empty($conf->use_javascript_ajax)) {
182 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_TICKET', array(), null, 0, 0, 1);
183 } else {
184 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_TICKET')) {
185 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_TICKET&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
186 } else {
187 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_TICKET&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
188 }
189 }
190 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_TICKET')) {
191 $showavailablecaptcha = 1;
192 }
193 print '</td></tr>';
194}
195
196if (isModEnabled('member')) {
197 print '<tr class="oddeven"><td>' . $langs->trans("UseCaptchaCode").' - Membership public subscription</td><td class="right" width="100">';
198 if (!empty($conf->use_javascript_ajax)) {
199 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_MEMBER', array(), null, 0, 0, 1);
200 } else {
201 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_MEMBER')) {
202 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_MEMBER&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
203 } else {
204 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_MEMBER&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
205 }
206 }
207 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_MEMBER')) {
208 $showavailablecaptcha = 1;
209 }
210 print '</td></tr>';
211}
212
213if (isModEnabled('don')) {
214 print '<tr class="oddeven"><td>' . $langs->trans("UseCaptchaCode").' - Donation public form</td><td class="right" width="100">';
215 if (!empty($conf->use_javascript_ajax)) {
216 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_DONATION', array(), null, 0, 0, 1);
217 } else {
218 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_DONATION')) {
219 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_DONATION&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
220 } else {
221 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_DONATION&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
222 }
223 }
224 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_DONATION')) {
225 $showavailablecaptcha = 1;
226 }
227 print '</td></tr>';
228}
229
230if (isModEnabled('recruitment')) {
231 print '<tr class="oddeven"><td>' . $langs->trans("UseCaptchaCode").' - Recruitment public form</td><td class="right" width="100">';
232 if (!empty($conf->use_javascript_ajax)) {
233 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_RECRUITMENT', array(), null, 0, 0, 1);
234 } else {
235 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_RECRUITMENT')) {
236 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_RECRUITMENT&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
237 } else {
238 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_RECRUITMENT&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
239 }
240 }
241 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_RECRUITMENT')) {
242 $showavailablecaptcha = 1;
243 }
244 print '</td></tr>';
245}
246
247
248if (isModEnabled('webportal')) {
249 print '<tr class="oddeven"><td>' . $langs->trans("UseCaptchaCode").' - WebPortal public form</td><td class="right" width="100">';
250 if (!empty($conf->use_javascript_ajax)) {
251 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_WEBPORTAL', array(), null, 0, 0, 1);
252 } else {
253 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_WEBPORTAL')) {
254 print '<a href="'.$_SERVER['PHP_SELF'].'?action=MAIN_SECURITY_ENABLECAPTCHA_WEBPORTAL&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
255 } else {
256 print '<a href="'.$_SERVER['PHP_SELF'].'?action=MAIN_SECURITY_ENABLECAPTCHA_WEBPORTAL&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
257 }
258 }
259 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_WEBPORTAL')) {
260 $showavailablecaptcha = 1;
261 }
262 print '</td></tr>';
263}
264
265print '</table>';
266print '</div>';
267
268
269$selectedcaptcha = getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_HANDLER', 'standard');
270
271if ($showavailablecaptcha) {
272 print '<br>';
273 print '<br>';
274 print '<br>';
275
276 // List of all available captcha
277 print '<div class="div-table-responsive">';
278 print '<table class="noborder centpercent">';
279 print '<tr class="liste_titre">';
280 print '<td colspan="3">'.$langs->trans("Captcha").'</td>';
281 print '<td>'.$langs->trans("Example").'</td>';
282 print '<td class="right" width="100">'.$langs->trans("Status").'</td>';
283 print '</tr>';
284
285 // Loop on each available captcha
286 foreach ($arrayhandler as $key => $module) {
287 print '<tr class="oddeven">';
288 print '<td style="width: 26px" class="center">';
289 print img_picto('', $module->picto, 'class="width25 size15x"');
290 print '</td>';
291 print '<td>';
292 print ucfirst($key);
293 print '</td>';
294 print '<td>';
295 print $module->getDescription().'<br>';
296 print '</td>';
297 print '<td>';
298 print $module->getExample().'<br>';
299 print '</td>';
300 print '<td class="right" width="100">';
301
302 if (function_exists("imagecreatefrompng")) {
303 if ($key != $selectedcaptcha) {
304 print '<a href="'.$_SERVER['PHP_SELF'].'?action=setcaptchahandler&token='.newToken().'&value='.$key.'">';
305 print img_picto($langs->trans("Disabled"), 'switch_off');
306 print '</a>';
307 } else {
308 print img_picto($langs->trans("Enabled"), 'switch_on');
309 }
310 } else {
311 $desc = $form->textwithpicto('', $langs->transnoentities("EnableGDLibraryDesc"), 1, 'warning');
312 print $desc;
313 }
314
315 print '</td>';
316 print '</tr>';
317 }
318
319 print '</table>';
320 print '</div>';
321 //print $form->buttonsSaveCancel("Modify", '');
322}
323
324print dol_get_fiche_end();
325
326print '</form>';
327
328// End of page
329llxFooter();
330$db->close();
security_prepare_head()
Prepare array with list of tabs.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.