dolibarr 23.0.3
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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
40
41// Load translation files required by the page
42$langs->loadLangs(array("users", "admin", "other"));
43
44if (!$user->admin) {
46}
47
48$action = GETPOST('action', 'aZ09');
49$handler = GETPOST('handler', 'aZ09');
50
51
52/*
53 * Actions
54 */
55
56if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
57 $code = $reg[1];
58 $value = (GETPOST($code, 'alpha') ? GETPOST($code, 'alpha') : 1);
59 if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0) {
60 header("Location: ".$_SERVER["PHP_SELF"]);
61 exit;
62 } else {
63 dol_print_error($db);
64 }
65} elseif (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
66 $code = $reg[1];
67 if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
68 header("Location: ".$_SERVER["PHP_SELF"]);
69 exit;
70 } else {
71 dol_print_error($db);
72 }
73} elseif ($action == 'setcaptchahandler') {
74 if (!dolibarr_set_const($db, 'MAIN_SECURITY_ENABLECAPTCHA_HANDLER', GETPOST("value", "aZ09"), 'chaine', 0, '', $conf->entity)) {
75 dol_print_error($db);
76 }
77}
78
79
80/*
81 * View
82 */
83
84$form = new Form($db);
85
86$wikihelp = 'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
87llxHeader('', $langs->trans("Miscellaneous"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-security_other');
88
89print load_fiche_titre($langs->trans("SecuritySetup"), '', 'title_setup');
90
91print '<span class="opacitymedium">'.$langs->trans("CaptchaDesc")."</span><br>\n";
92print "<br>\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">';
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
246print '</table>';
247print '</div>';
248
249
250$selectedcaptcha = getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_HANDLER', 'standard');
251
252if ($showavailablecaptcha) {
253 print '<br>';
254 print '<br>';
255 print '<br>';
256
257 // List of all available captcha
258 print '<div class="div-table-responsive">';
259 print '<table class="noborder centpercent">';
260 print '<tr class="liste_titre">';
261 print '<td colspan="3">'.$langs->trans("Captcha").'</td>';
262 print '<td>'.$langs->trans("Example").'</td>';
263 print '<td class="right" width="100">'.$langs->trans("Status").'</td>';
264 print '</tr>';
265
266 // Loop on each available captcha
267 foreach ($arrayhandler as $key => $module) {
268 print '<tr class="oddeven">';
269 print '<td style="width: 26px" class="center">';
270 print img_picto('', $module->picto, 'class="width25 size15x"');
271 print '</td>';
272 print '<td>';
273 print ucfirst($key);
274 print '</td>';
275 print '<td>';
276 print $module->getDescription().'<br>';
277 print '</td>';
278 print '<td>';
279 print $module->getExample().'<br>';
280 print '</td>';
281 print '<td class="right" width="100">';
282
283 if (function_exists("imagecreatefrompng")) {
284 if ($key != $selectedcaptcha) {
285 print '<a href="'.$_SERVER['PHP_SELF'].'?action=setcaptchahandler&token='.newToken().'&value='.$key.'">';
286 print img_picto($langs->trans("Disabled"), 'switch_off');
287 print '</a>';
288 } else {
289 print img_picto($langs->trans("Enabled"), 'switch_on');
290 }
291 } else {
292 $desc = $form->textwithpicto('', $langs->transnoentities("EnableGDLibraryDesc"), 1, 'warning');
293 print $desc;
294 }
295
296 print '</td>';
297 print '</tr>';
298 }
299
300 print '</table>';
301 print '</div>';
302 //print $form->buttonsSaveCancel("Modify", '');
303}
304
305print dol_get_fiche_end();
306
307print '</form>';
308
309// End of page
310llxFooter();
311$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.
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...
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)
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.