dolibarr 22.0.5
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 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';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32
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}
123asort($arrayhandler);
124
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
138print $langs->trans("UseCaptchaCode").' - Login';
139if (!empty($conf->use_javascript_ajax)) {
140 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA', array(), null, 0, 0, 1);
141} else {
142 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) {
143 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
144 } else {
145 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
146 }
147}
148
149if (isModEnabled('societe')) {
150 print '<br>';
151 print $langs->trans("UseCaptchaCode").' - Thirdparty public contact form';
152 if (!empty($conf->use_javascript_ajax)) {
153 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY', array(), null, 0, 0, 1);
154 } else {
155 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY')) {
156 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
157 } else {
158 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
159 }
160 }
161}
162
163if (isModEnabled('ticket')) {
164 print '<br>';
165 print $langs->trans("UseCaptchaCode").' - Public ticket creation';
166 if (!empty($conf->use_javascript_ajax)) {
167 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_TICKET', array(), null, 0, 0, 1);
168 } else {
169 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_TICKET')) {
170 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_TICKET&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
171 } else {
172 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_TICKET&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
173 }
174 }
175}
176
177if (isModEnabled('member')) {
178 print '<br>';
179 print $langs->trans("UseCaptchaCode").' - Membership public subcription';
180 if (!empty($conf->use_javascript_ajax)) {
181 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_MEMBER', array(), null, 0, 0, 1);
182 } else {
183 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_MEMBER')) {
184 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_MEMBER&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
185 } else {
186 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_MEMBER&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
187 }
188 }
189}
190
191if (isModEnabled('don')) {
192 print '<br>';
193 print $langs->trans("UseCaptchaCode").' - Donation public form';
194 if (!empty($conf->use_javascript_ajax)) {
195 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_DONATION', array(), null, 0, 0, 1);
196 } else {
197 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_DONATION')) {
198 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_DONATION&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
199 } else {
200 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_DONATION&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
201 }
202 }
203}
204
205// Set if a captcha is used on at least one place
206$showavailablecaptcha = 0;
207if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) {
208 $showavailablecaptcha = 1;
209}
210if (isModEnabled('societe') && getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_THIRDPARTY')) {
211 $showavailablecaptcha = 1;
212}
213if (isModEnabled('ticket') && getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_TICKET')) {
214 $showavailablecaptcha = 1;
215}
216if (isModEnabled('member') && getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_MEMBER')) {
217 $showavailablecaptcha = 1;
218}
219if (isModEnabled('don') && getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_DONATION')) {
220 $showavailablecaptcha = 1;
221}
222
223$selectedcaptcha = getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_HANDLER', 'standard');
224
225if ($showavailablecaptcha) {
226 print '<br>';
227 print '<br>';
228 print '<br>';
229
230 // List of all available captcha
231 print '<table class="noborder centpercent">';
232 print '<tr class="liste_titre">';
233 print '<td colspan="2">'.$langs->trans("Captcha").'</td>';
234 print '<td>'.$langs->trans("Example").'</td>';
235 print '<td class="right" width="100">'.$langs->trans("Status").'</td>';
236 print '</tr>';
237
238 // Loop on each available captcha
239 foreach ($arrayhandler as $key => $module) {
240 print '<tr class="oddeven">';
241 print '<td>';
242 print img_picto('', $module->picto, 'class="width25 size15x marginrightonly"').' ';
243 print ucfirst($key);
244 print '</td>';
245 print '<td>';
246 print $module->getDescription().'<br>';
247 print '</td>';
248 print '<td>';
249 print $module->getExample().'<br>';
250 print '</td>';
251 print '<td class="right" width="100">';
252
253 if (function_exists("imagecreatefrompng")) {
254 if ($key != $selectedcaptcha) {
255 print '<a href="'.$_SERVER['PHP_SELF'].'?action=setcaptchahandler&token='.newToken().'&value='.$key.'">';
256 print img_picto($langs->trans("Disabled"), 'switch_off');
257 print '</a>';
258 } else {
259 print img_picto($langs->trans("Enabled"), 'switch_on');
260 }
261 } else {
262 $desc = $form->textwithpicto('', $langs->transnoentities("EnableGDLibraryDesc"), 1, 'warning');
263 print $desc;
264 }
265
266 print '</td>';
267 print '</tr>';
268 }
269
270 print '</table>';
271
272 //print $form->buttonsSaveCancel("Modify", '');
273}
274
275print dol_get_fiche_end();
276
277print '</form>';
278
279// End of page
280llxFooter();
281$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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.