dolibarr 21.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 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
31
32// Load translation files required by the page
33$langs->loadLangs(array("users", "admin", "other"));
34
35if (!$user->admin) {
37}
38
39$action = GETPOST('action', 'aZ09');
40
41
42
43/*
44 * Actions
45 */
46
47if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
48 $code = $reg[1];
49 $value = (GETPOST($code, 'alpha') ? GETPOST($code, 'alpha') : 1);
50 if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0) {
51 header("Location: ".$_SERVER["PHP_SELF"]);
52 exit;
53 } else {
54 dol_print_error($db);
55 }
56} elseif (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
57 $code = $reg[1];
58 if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
59 header("Location: ".$_SERVER["PHP_SELF"]);
60 exit;
61 } else {
62 dol_print_error($db);
63 }
64} elseif ($action == 'updateform') {
65 $res1 = 1;
66 $res2 = 1;
67 $res3 = 1;
68 $res4 = 1;
69 $res5 = 1;
70 if (GETPOSTISSET('MAIN_APPLICATION_TITLE')) {
71 $res1 = dolibarr_set_const($db, "MAIN_APPLICATION_TITLE", GETPOST("MAIN_APPLICATION_TITLE", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
72 }
73 if (GETPOSTISSET('MAIN_SESSION_TIMEOUT')) {
74 $res2 = dolibarr_set_const($db, "MAIN_SESSION_TIMEOUT", GETPOST("MAIN_SESSION_TIMEOUT", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
75 }
76 if (GETPOSTISSET('MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT')) {
77 $res3 = dolibarr_set_const($db, "MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", GETPOST("MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 'alphanohtml'), 'int', 0, '', $conf->entity);
78 }
79 if (GETPOSTISSET('MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS')) {
80 $res4 = dolibarr_set_const($db, "MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", GETPOST("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 'alphanohtml'), 'int', 0, '', $conf->entity);
81 }
82 if (GETPOSTISSET('MAIN_SECURITY_MAX_ATTACHMENT_ON_FORMS')) {
83 $res5 = dolibarr_set_const($db, "MAIN_SECURITY_MAX_ATTACHMENT_ON_FORMS", GETPOST("MAIN_SECURITY_MAX_ATTACHMENT_ON_FORMS", 'alphanohtml'), 'int', 0, '', $conf->entity);
84 }
85 if ($res1 && $res2 && $res3 && $res4 && $res5) {
86 setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
87 }
88}
89
90
91
92/*
93 * View
94 */
95
96$form = new Form($db);
97
98$wikihelp = 'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
99llxHeader('', $langs->trans("Miscellaneous"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-security_other');
100
101print load_fiche_titre($langs->trans("SecuritySetup"), '', 'title_setup');
102
103print '<span class="opacitymedium">'.$langs->trans("CaptchaDesc")."</span><br>\n";
104print "<br>\n";
105
106
107// Load array with all captcha generation modules
108$dir = "../core/modules/security/captcha";
109clearstatcache();
110$handle = opendir($dir);
111$i = 1;
112$arrayhandler = array();
113if (is_resource($handle)) {
114 while (($file = readdir($handle)) !== false) {
115 $reg = array();
116 if (preg_match('/(modCaptcha[a-z]+)\.class\.php$/i', $file, $reg)) {
117 // Charging the numbering class
118 $classname = $reg[1];
119 require_once $dir.'/'.$file;
120
121 $obj = new $classname($db, $conf, $langs, $user);
122 '@phan-var-force ModeleCaptcha $obj';
123 $arrayhandler[$obj->id] = $obj;
124 $i++;
125 }
126 }
127 closedir($handle);
128}
129asort($arrayhandler);
130
131
132
133print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
134print '<input type="hidden" name="token" value="'.newToken().'">';
135print '<input type="hidden" name="action" value="updateform">';
136
137$head = security_prepare_head();
138
139print dol_get_fiche_head($head, 'captcha', '', -1);
140
141print '<br>';
142
143
144print $langs->trans("UseCaptchaCode");
145if (function_exists("imagecreatefrompng")) {
146 if (!empty($conf->use_javascript_ajax)) {
147 print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA', array(), null, 0, 0, 1);
148 } else {
149 if (!getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) {
150 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
151 } else {
152 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
153 }
154 }
155} else {
156 $desc = $form->textwithpicto('', $langs->transnoentities("EnableGDLibraryDesc"), 1, 'warning');
157 print $desc;
158}
159
160
161if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) {
162 print '<br>';
163 print '<br>';
164 print '<br>';
165
166 // List of all available captcha
167 print '<table class="noborder centpercent">';
168 print '<tr class="liste_titre">';
169 print '<td colspan="2">'.$langs->trans("Captcha").'</td>';
170 print '<td>'.$langs->trans("Example").'</td>';
171 print '<td class="right" width="100">'.$langs->trans("Status").'</td>';
172 print '</tr>';
173
174 $arrayofcaptcha = array(
175 'standard' => array('label' => 'Standard', 'picto' => 'ee')
176 );
177 //$arrayofcaptcha['google'] = array('label' => 'Google');
178
179 $selectedcaptcha = 'standard';
180
181 // Loop on each available captcha
182 foreach ($arrayhandler as $key => $module) {
183 print '<tr class="oddeven">';
184 print '<td>';
185 print img_picto('', $module->picto, 'class="width25 size15x marginrightonly"').' ';
186 print ucfirst($key);
187 print '</td>';
188 print '<td>';
189 print $module->getDescription().'<br>';
190 print '</td>';
191 print '<td>';
192 print $module->getExample().'<br>';
193 print '</td>';
194 print '<td class="right" width="100">';
195 if ($key == $selectedcaptcha) {
196 print 'On';
197 }
198 print '</td>';
199 print '</tr>';
200 }
201
202 print '</table>';
203
204 //print $form->buttonsSaveCancel("Modify", '');
205}
206
207print dol_get_fiche_end();
208
209print '</form>';
210
211// End of page
212llxFooter();
213$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:70
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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_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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.