dolibarr 25.0.0-alpha
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 '<div class="info">'.$langs->trans("CaptchaDesc")."</div>\n";
93
94$dirModCaptcha = array_merge(array('/core/modules/security/captcha/'), (isset($conf->modules_parts['captcha']) && is_array($conf->modules_parts['captcha'])) ? $conf->modules_parts['captcha'] : array());
95
96// Load array with all captcha generation modules
97$arrayhandler = array();
98
99foreach ($dirModCaptcha as $dirroot) {
100 $dir = dol_buildpath($dirroot, 0);
101
102 $handle = @opendir($dir);
103
104 $i = 1;
105 if (is_resource($handle)) {
106 while (($file = readdir($handle)) !== false) {
107 $reg = array();
108 if (preg_match('/(modCaptcha[a-z]+)\.class\.php$/i', $file, $reg)) {
109 // Charging the numbering class
110 $classname = $reg[1];
111 require_once $dir.'/'.$file;
112
113 $obj = new $classname($db, $conf, $langs, $user);
114 '@phan-var-force ModeleCaptcha $obj';
116 $arrayhandler[$obj->id] = $obj;
117 $i++;
118 }
119 }
120 closedir($handle);
121 }
122}
123$arrayhandler = dol_sort_array($arrayhandler, 'position');
124
125
126print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" spellcheck="false">';
127print '<input type="hidden" name="token" value="'.newToken().'">';
128print '<input type="hidden" name="action" value="updateform">';
129
130$head = security_prepare_head();
131
132print dol_get_fiche_head($head, 'captcha', '', -1);
133
134print '<br>';
135
136// Set if a captcha is used on at least one place
137$showavailablecaptcha = 0;
138if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) {
139 $showavailablecaptcha = 1;
140}
141
142print '<div class="div-table-responsive">';
143print '<table class="noborder centpercent">';
144print '<tr class="liste_titre">';
145print '<td>'.$langs->trans("Captcha").'</td>';
146print '<td class="right" width="100">'.$langs->trans("Status").'</td>';
147print '</tr>';
148
149print '<tr class="oddeven"><td>' . $langs->trans("UseCaptchaCode").' - Login</td><td class="right" width="100">';
150if (!empty($conf->use_javascript_ajax)) {
151 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA', array(), null, 0, 0, 1);
152} else {
153 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) {
154 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
155 } else {
156 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
157 }
158}
159print '</td></tr>';
160
161if (isModEnabled('societe')) {
162 print '<tr class="oddeven"><td>' . $langs->trans("UseCaptchaCode").' - Thirdparty public contact form</td><td class="right" width="100">';
163 if (!empty($conf->use_javascript_ajax)) {
164 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY', array(), null, 0, 0, 1);
165 } else {
166 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY')) {
167 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
168 } else {
169 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
170 }
171 }
172 print '</td></tr>';
173 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY')) {
174 $showavailablecaptcha = 1;
175 }
176}
177
178if (isModEnabled('ticket')) {
179 print '<tr class="oddeven"><td>' . $langs->trans("UseCaptchaCode").' - Public ticket creation</td><td class="right" width="100">';
180 if (!empty($conf->use_javascript_ajax)) {
181 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_TICKET', array(), null, 0, 0, 1);
182 } else {
183 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_TICKET')) {
184 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_TICKET&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
185 } else {
186 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_TICKET&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
187 }
188 }
189 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_TICKET')) {
190 $showavailablecaptcha = 1;
191 }
192 print '</td></tr>';
193}
194
195if (isModEnabled('member')) {
196 print '<tr class="oddeven"><td>' . $langs->trans("UseCaptchaCode").' - Membership public subscription</td><td class="right" width="100">';
197 if (!empty($conf->use_javascript_ajax)) {
198 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_MEMBER', array(), null, 0, 0, 1);
199 } else {
200 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_MEMBER')) {
201 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_MEMBER&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
202 } else {
203 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_MEMBER&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
204 }
205 }
206 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_MEMBER')) {
207 $showavailablecaptcha = 1;
208 }
209 print '</td></tr>';
210}
211
212if (isModEnabled('don')) {
213 print '<tr class="oddeven"><td>' . $langs->trans("UseCaptchaCode").' - Donation public form</td><td class="right" width="100">';
214 if (!empty($conf->use_javascript_ajax)) {
215 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_DONATION', array(), null, 0, 0, 1);
216 } else {
217 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_DONATION')) {
218 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_DONATION&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
219 } else {
220 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_DONATION&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
221 }
222 }
223 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_DONATION')) {
224 $showavailablecaptcha = 1;
225 }
226 print '</td></tr>';
227}
228
229if (isModEnabled('recruitment')) {
230 print '<tr class="oddeven"><td>' . $langs->trans("UseCaptchaCode").' - Recruitment public form</td><td class="right" width="100">';
231 if (!empty($conf->use_javascript_ajax)) {
232 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_RECRUITMENT', array(), null, 0, 0, 1);
233 } else {
234 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_RECRUITMENT')) {
235 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_RECRUITMENT&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
236 } else {
237 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_RECRUITMENT&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
238 }
239 }
240 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_RECRUITMENT')) {
241 $showavailablecaptcha = 1;
242 }
243 print '</td></tr>';
244}
245
246
247if (isModEnabled('webportal')) {
248 print '<tr class="oddeven"><td>' . $langs->trans("UseCaptchaCode").' - WebPortal public form</td><td class="right" width="100">';
249 if (!empty($conf->use_javascript_ajax)) {
250 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_WEBPORTAL', array(), null, 0, 0, 1);
251 } else {
252 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_WEBPORTAL')) {
253 print '<a href="'.$_SERVER['PHP_SELF'].'?action=MAIN_SECURITY_ENABLECAPTCHA_WEBPORTAL&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
254 } else {
255 print '<a href="'.$_SERVER['PHP_SELF'].'?action=MAIN_SECURITY_ENABLECAPTCHA_WEBPORTAL&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
256 }
257 }
258 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_WEBPORTAL')) {
259 $showavailablecaptcha = 1;
260 }
261 print '</td></tr>';
262}
263
264print '</table>';
265print '</div>';
266
267
268$selectedcaptcha = getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_HANDLER', 'standard');
269
270if ($showavailablecaptcha) {
271 print '<br>';
272 print '<br>';
273 print '<br>';
274
275 // List of all available captcha
276 print '<div class="div-table-responsive">';
277 print '<table class="noborder centpercent">';
278 print '<tr class="liste_titre">';
279 print '<td colspan="3">'.$langs->trans("Captcha").'</td>';
280 print '<td>'.$langs->trans("Example").'</td>';
281 print '<td class="right" width="100">'.$langs->trans("Status").'</td>';
282 print '</tr>';
283
284 // Loop on each available captcha
285 foreach ($arrayhandler as $key => $module) {
286 print '<tr class="oddeven">';
287 print '<td style="width: 26px" class="center">';
288 print img_picto('', $module->picto, 'class="width25 size15x"');
289 print '</td>';
290 print '<td>';
291 print ucfirst($key);
292 print '</td>';
293 print '<td>';
294 print $module->getDescription().'<br>';
295 print '</td>';
296 print '<td>';
297 print $module->getExample().'<br>';
298 print '</td>';
299 print '<td class="right" width="100">';
300
301 if (function_exists("imagecreatefrompng")) {
302 if ($key != $selectedcaptcha) {
303 print '<a href="'.$_SERVER['PHP_SELF'].'?action=setcaptchahandler&token='.newToken().'&value='.$key.'">';
304 print img_picto($langs->trans("Disabled"), 'switch_off');
305 print '</a>';
306 } else {
307 print img_picto($langs->trans("Enabled"), 'switch_on');
308 }
309 } else {
310 $desc = $form->textwithpicto('', $langs->transnoentities("EnableGDLibraryDesc"), 1, 'warning');
311 print $desc;
312 }
313
314 print '</td>';
315 print '</tr>';
316 }
317
318 print '</table>';
319 print '</div>';
320 //print $form->buttonsSaveCancel("Modify", '');
321}
322
323print dol_get_fiche_end();
324
325print '</form>';
326
327// End of page
328llxFooter();
329$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.
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...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
Definition html.lib.php:519
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:717
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.