dolibarr 21.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 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");
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('ticket')) {
150 print '<br>';
151 print $langs->trans("TicketUseCaptchaCodeHelp");
152 if (!empty($conf->use_javascript_ajax)) {
153 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA_TICKET', array(), null, 0, 0, 1);
154 } else {
155 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_TICKET')) {
156 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA_TICKET&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
157 } else {
158 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA_TICKET&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
159 }
160 }
161}
162
163$showavailablecaptcha = 0;
164if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) {
165 $showavailablecaptcha = 1;
166}
167if (isModEnabled('ticket') && getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_TICKET')) {
168 $showavailablecaptcha = 1;
169}
170
171$selectedcaptcha = getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_HANDLER', 'standard');
172
173if ($showavailablecaptcha) {
174 print '<br>';
175 print '<br>';
176 print '<br>';
177
178 // List of all available captcha
179 print '<table class="noborder centpercent">';
180 print '<tr class="liste_titre">';
181 print '<td colspan="2">'.$langs->trans("Captcha").'</td>';
182 print '<td>'.$langs->trans("Example").'</td>';
183 print '<td class="right" width="100">'.$langs->trans("Status").'</td>';
184 print '</tr>';
185
186 // Loop on each available captcha
187 foreach ($arrayhandler as $key => $module) {
188 print '<tr class="oddeven">';
189 print '<td>';
190 print img_picto('', $module->picto, 'class="width25 size15x marginrightonly"').' ';
191 print ucfirst($key);
192 print '</td>';
193 print '<td>';
194 print $module->getDescription().'<br>';
195 print '</td>';
196 print '<td>';
197 print $module->getExample().'<br>';
198 print '</td>';
199 print '<td class="right" width="100">';
200
201 if (function_exists("imagecreatefrompng")) {
202 if ($key != $selectedcaptcha) {
203 print '<a href="'.$_SERVER['PHP_SELF'].'?action=setcaptchahandler&token='.newToken().'&value='.$key.'">';
204 print img_picto($langs->trans("Disabled"), 'switch_off');
205 print '</a>';
206 } else {
207 print img_picto($langs->trans("Enabled"), 'switch_on');
208 }
209 } else {
210 $desc = $form->textwithpicto('', $langs->transnoentities("EnableGDLibraryDesc"), 1, 'warning');
211 print $desc;
212 }
213
214 print '</td>';
215 print '</tr>';
216 }
217
218 print '</table>';
219
220 //print $form->buttonsSaveCancel("Modify", '');
221}
222
223print dol_get_fiche_end();
224
225print '</form>';
226
227// End of page
228llxFooter();
229$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.
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:71
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
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)
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)
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.