dolibarr 24.0.2
security_headers_http.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// We force the CSP to none on thispage, so if we make an error, we can still have access to fix it
28define('MAIN_SECURITY_FORCECSP', '*');
29
30// Load Dolibarr environment
31require '../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
42
43// Load translation files required by the page
44$langs->loadLangs(array("users", "admin", "other", "website"));
45
46if (!$user->admin) {
48}
49
50$action = GETPOST('action', 'aZ09');
51$cancel = GETPOST('cancel', 'alpha');
52
53$forceCSP = getDolGlobalString("MAIN_SECURITY_FORCECSP");
54$selectarrayCSPDirectives = GetContentPolicyDirectives();
55$selectarrayCSPSources = GetContentPolicySources();
56$forceCSPArr = GetContentPolicyToArray($forceCSP);
57$error = 0;
58
59
60/*
61 * Actions
62 */
63
64if ($cancel) {
65 $action = '';
66}
67
68$reg = array();
69if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
70 $code = $reg[1];
71 $value = (GETPOST($code, 'alpha') ? GETPOST($code, 'alpha') : 1);
72 if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0) {
73 header("Location: ".$_SERVER["PHP_SELF"]);
74 exit;
75 } else {
77 }
78} elseif (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
79 $code = $reg[1];
80 if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
81 header("Location: ".$_SERVER["PHP_SELF"]);
82 exit;
83 } else {
85 }
86} elseif ($action == 'removecspsource') {
87 $db->begin();
88 $sourcetype = "";
89 $sourcecsp = explode("_", GETPOST("sourcecsp"));
90 $directive = $sourcecsp[0];
91 $sourcekey = isset($sourcecsp[1]) ? $sourcecsp[1] : null;
92 $sourcedata = isset($sourcecsp[2]) ? $sourcecsp[2] : null;
93 $forceCSPArr = GetContentPolicyToArray($forceCSP);
94 $directivesarray = GetContentPolicyDirectives();
95 $sourcesarray = GetContentPolicySources();
96 if (empty($directive)) {
97 $error++;
98 }
99
100 if (!empty($directivesarray[$directive])) {
101 $directivetype = (string) $directivesarray[$directive]["data-directivetype"];
102 if (isset($sourcekey)) {
103 $sourcetype = $sourcesarray[$directivetype][$sourcekey]["data-sourcetype"];
104 }
105 }
106
107 $securitycspstring = "";
108 if (!$error && !empty($forceCSPArr)) {
109 if (isset($sourcekey) && !empty($forceCSPArr[$directive][$sourcekey])) {
110 unset($forceCSPArr[$directive][$sourcekey]);
111 }
112 if (count($forceCSPArr[$directive]) == 0) {
113 unset($forceCSPArr[$directive]);
114 }
115 foreach ($forceCSPArr as $directive => $sourcekeys) {
116 if ($securitycspstring != "") {
117 $securitycspstring .= "; ";
118 }
119 $sourcestring = "";
120 foreach ($sourcekeys as $key => $source) {
121 $directivetype = $directivesarray[$directive]["data-directivetype"];
122 $sourcetype = $sourcesarray[$directivetype][$source]["data-sourcetype"];
123 if ($sourcetype == "quoted") {
124 $sourcestring .= " '".$source."'";
125 } else {
126 $sourcestring .= " ".$source;
127 }
128 }
129 $securitycspstring .= $directive . $sourcestring;
130 }
131
132 // Add a protection against bad setup that break Dolibarr
133 $securitycspstring = cleanSecurityCSP($securitycspstring);
134
135 $res = dolibarr_set_const($db, 'MAIN_SECURITY_FORCECSP', $securitycspstring, 'chaine', 0, '', $conf->entity);
136 if ($res <= 0) {
137 $error++;
138 }
139 }
140
141 if (!$error) {
142 $db->commit();
143 setEventMessages($langs->trans("MainSecurityPolicySucesfullyRemoved"), null, 'mesgs');
144 } else {
145 $db->rollback();
146 setEventMessages($langs->trans("MainErrorRemovingSecurityPolicy"), null, 'errors');
147 }
148
149 header("Location: ".$_SERVER["PHP_SELF"]);
150 exit;
151} elseif ($action == "updateform" && GETPOST("btn_MAIN_SECURITY_FORCECSP")) {
152 $directivecsp = GETPOST("select_identifier_MAIN_SECURITY_FORCECSP");
153 $sourcecsp = GETPOST("select_source_MAIN_SECURITY_FORCECSP");
154 $sourcedatacsp = GETPOST("input_data_MAIN_SECURITY_FORCECSP");
155 $sourcetype = "";
156
157 $forceCSPArr = GetContentPolicyToArray($forceCSP);
158 $directivesarray = GetContentPolicyDirectives();
159 $sourcesarray = GetContentPolicySources();
160 if (empty($directivecsp)) {
161 $error++;
162 }
163 if ($error || (!isset($sourcecsp) && $directivesarray[$directivecsp]["data-directivetype"] != "none")) {
164 $error++;
165 }
166 if (!$error) {
167 $directivetype = $directivesarray[$directivecsp]["data-directivetype"];
168 if (isset($sourcecsp)) {
169 $sourcetype = $sourcesarray[$directivetype][$sourcecsp]["data-sourcetype"];
170 }
171 $securitycspstring = "";
172 if ($sourcetype == "data") {
173 $forceCSPArr[$directivecsp][] = "data:".$sourcedatacsp;
174 } elseif (isset($sourcetype) && $sourcetype == "blob") {
175 $forceCSPArr[$directivecsp][] = "blob:".$sourcedatacsp;
176 } elseif (isset($sourcetype) && $sourcetype == "input") {
177 if (empty($forceCSPArr[$directivecsp])) {
178 $forceCSPArr[$directivecsp] = array();
179 }
180 $forceCSPArr[$directivecsp] = array_merge(explode(" ", $sourcedatacsp), $forceCSPArr[$directivecsp]);
181 } else {
182 if (empty($forceCSPArr[$directivecsp])) {
183 $forceCSPArr[$directivecsp] = array();
184 }
185 if (!isset($sourcecsp)) {
186 $sourcecsp = "";
187 }
188 array_unshift($forceCSPArr[$directivecsp], $sourcecsp);
189 }
190 foreach ($forceCSPArr as $directive => $sourcekeys) {
191 if ($securitycspstring != "") {
192 $securitycspstring .= "; ";
193 }
194 $sourcestring = "";
195 foreach ($sourcekeys as $key => $source) {
196 $directivetype = $directivesarray[$directive]["data-directivetype"];
197 $sourcetype = $sourcesarray[$directivetype][$source]["data-sourcetype"];
198 if (isset($sourcetype) && $sourcetype == "quoted") {
199 $sourcestring .= " '".$source."'";
200 } elseif ($directivetype != "none") {
201 $sourcestring .= " ".$source;
202 }
203 }
204 $securitycspstring .= $directive . $sourcestring;
205 }
206
207 // Add a protection against bad setup that break Dolibarr
208 $securitycspstring = cleanSecurityCSP($securitycspstring);
209
210 $res = dolibarr_set_const($db, 'MAIN_SECURITY_FORCECSP', $securitycspstring, 'chaine', 0, '', $conf->entity);
211 if ($res <= 0) {
212 $error++;
213 }
214 }
215
216 if (!$error) {
217 $db->commit();
218 setEventMessages($langs->trans("MainSecurityPolicySucesfullyAdded"), null, 'mesgs');
219 } else {
220 $db->rollback();
221 setEventMessages($langs->trans("MainErrorAddingSecurityPolicy"), null, 'errors');
222 }
223 header("Location: ".$_SERVER["PHP_SELF"]);
224 exit;
225} elseif ($action == "updateform") {
226 $db->begin();
227 $res1 = $res2 = $res3 = $res4 = 0;
228 $securityrp = GETPOST('MAIN_SECURITY_FORCERP', 'alpha');
229 $securitysts = GETPOST('MAIN_SECURITY_FORCESTS', 'alpha');
230 $securitypp = GETPOST('MAIN_SECURITY_FORCEPP', 'alpha');
231 $securitycsp = GETPOST('MAIN_SECURITY_FORCECSP', 'alpha');
232 $securitycspro = GETPOST('MAIN_SECURITY_FORCECSPRO', 'alpha');
233
234 // Add a protection against bad setup that break Dolibarr
235 $securitycsp = cleanSecurityCSP($securitycsp);
236 $securitycspro = cleanSecurityCSP($securitycspro);
237
238 $res1 = dolibarr_set_const($db, 'MAIN_SECURITY_FORCERP', $securityrp, 'chaine', 0, '', $conf->entity);
239 $res2 = dolibarr_set_const($db, 'MAIN_SECURITY_FORCESTS', $securitysts, 'chaine', 0, '', $conf->entity);
240 $res3 = dolibarr_set_const($db, 'MAIN_SECURITY_FORCEPP', $securitypp, 'chaine', 0, '', $conf->entity);
241 $res4 = dolibarr_set_const($db, 'MAIN_SECURITY_FORCECSP', $securitycsp, 'chaine', 0, '', $conf->entity);
242 $res5 = dolibarr_set_const($db, 'MAIN_SECURITY_FORCECSPRO', $securitycspro, 'chaine', 0, '', $conf->entity);
243
244 if ($res1 >= 0 && $res2 >= 0 && $res3 >= 0 && $res4 >= 0 && $res5 >= 0) {
245 $db->commit();
246 setEventMessages($langs->trans("Saved"), null, 'mesgs');
247
248 header("Location: ".$_SERVER["PHP_SELF"]);
249 exit;
250 } else {
251 $db->rollback();
252 setEventMessages($langs->trans("ErrorSavingChanges"), null, 'errors');
253 }
254 $action = '';
255 $forceCSP = getDolGlobalString("MAIN_SECURITY_FORCECSP");
256}
257
264function cleanSecurityCSP($securitycsp)
265{
266 if (!empty($securitycsp)) {
267 // We check if script-src contains self and unsafe-inline (if not the app will not work correctly)
268 if (!preg_match('/script-src[^;]*self/', $securitycsp) || !preg_match('/script-src[^;]*unsafe-inline/', $securitycsp)) {
269 if (!preg_match('/script-src/', $securitycsp)) {
270 // TODO Show a warning to explain we add added entry to avoid app hanging ?
271 $securitycsp .= (preg_match('/;\s*$/', $securitycsp) ? '' : '; ').' script-src \'self\' \'unsafe-inline\'';
272 if (isModEnabled('paypal')) {
273 $securitycsp .= ' *.paypal.com';
274 }
275 if (isModEnabled('stripe')) {
276 $securitycsp .= ' *.stripe.com'; // Must be added as they may be used by the core modules
277 }
278 $securitycsp .= ';';
279 } else {
280 if (!preg_match('/script-src[^;]*self/', $securitycsp)) {
281 $securitycsp = preg_replace('/script-src\s+/', 'script-src \'self\' ', $securitycsp);
282 }
283 if (!preg_match('/script-src[^;]*unsafe-inline/', $securitycsp)) {
284 $securitycsp = preg_replace('/script-src\s+/', 'script-src \'unsafe-inline\' ', $securitycsp);
285 }
286 // We check if entry for paypal or stripe are present
287 if (isModEnabled('paypal') && !preg_match('/script-src[^;]*paypal/', $securitycsp)) {
288 $securitycsp = preg_replace('/script-src\s+/', 'script-src *.paypal.com ', $securitycsp);
289 }
290 if (isModEnabled('stripe') && !preg_match('/script-src[^;]*stripe/', $securitycsp)) {
291 $securitycsp = preg_replace('/script-src\s+/', 'script-src *.stripe.com ', $securitycsp);
292 }
293 }
294 }
295 // We check if style-src contains self and unsafe-inline (if not the app will not work correctly)
296 if (!preg_match('/style-src[^;]*self/', $securitycsp) || !preg_match('/style-src[^;]*unsafe-inline/', $securitycsp)) {
297 if (!preg_match('/style-src/', $securitycsp)) {
298 $securitycsp .= (preg_match('/;\s*$/', $securitycsp) ? '' : '; ').' style-src \'self\' \'unsafe-inline\';';
299 } else {
300 if (!preg_match('/style-src[^;]*self/', $securitycsp)) {
301 $securitycsp = preg_replace('/style-src\s+/', 'style-src \'self\' ', $securitycsp);
302 }
303 if (!preg_match('/style-src[^;]*unsafe-inline/', $securitycsp)) {
304 $securitycsp = preg_replace('/style-src\s+/', 'style-src \'unsafe-inline\' ', $securitycsp);
305 }
306 }
307 }
308 if (!preg_match('/dolibarr\.org/', $securitycsp)) {
309 if (!preg_match('/default-src/', $securitycsp)) {
310 $securitycsp .= (preg_match('/;\s*$/', $securitycsp) ? '' : '; ').' default-src *.dolibarr.org;';
311 } else {
312 $securitycsp = preg_replace('/default-src\s+/', 'default-src *.dolibarr.org ', $securitycsp);
313 }
314 }
315 }
316 $securitycsp = preg_replace('/\s+/', ' ', $securitycsp);
317
318 return $securitycsp;
319}
320
321
322/*
323 * View
324 */
325
326$form = new Form($db);
327
328$wikihelp = 'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
329llxHeader('', $langs->trans("MainHttpSecurityHeaders"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-security_other');
330
331print load_fiche_titre($langs->trans("SecuritySetup"), '', 'title_setup');
332$head = security_prepare_head();
333
334print '<div class="info">'.$langs->trans("HTTPHeaderEditor").'. '.$langs->trans("ReservedToAdvancedUsers").'.</div>';
335
336print dol_get_fiche_head($head, 'headers_http', '', -1);
337
338print '<br>';
339
340print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
341print '<input type="hidden" name="token" value="'.newToken().'">';
342print '<input type="hidden" name="action" value="updateform">';
343
344print '<div class="div-table-responsive-no-min">';
345print '<table class="noborder centpercent">';
346print '<tr class="liste_titre">';
347print '<td>'.$langs->trans("HTTPHeader").'</td>';
348print '<td></td>'."\n";
349print '</tr>';
350
351// Force RP
352print '<tr class="oddeven">';
353print '<td>'.$form->textwithpicto($langs->trans('MainSecurityForceRP'), 'HTTP Header Referer-Policy<br><br>'.$langs->trans("Recommended").':<br>strict-origin-when-cross-origin <span class="opacitymedium"> &nbsp; '.$langs->trans("or").' &nbsp; </span> same-origin <span class="opacitymedium">(more secured)</span>', 1, 'help', 'valignmiddle', 0, 3, 'MAIN_SECURITY_FORCERP').'</td>';
354print '<td><input class="minwidth500" name="MAIN_SECURITY_FORCERP" id="MAIN_SECURITY_FORCERP" value="'.getDolGlobalString("MAIN_SECURITY_FORCERP").'" spellcheck="false"></td>';
355print '</tr>';
356// Force STS
357print '<tr class="oddeven">';
358print '<td>'.$form->textwithpicto($langs->trans('MainSecurityForceSTS'), 'HTTP Header Strict-Transport-Security<br><br>'.$langs->trans("Example").':<br>max-age=31536000; includeSubDomains', 1, 'help', 'valignmiddle', 0, 3, 'MAIN_SECURITY_FORCESTS').'</td>';
359print '<td><input class="minwidth500" name="MAIN_SECURITY_FORCESTS" id="MAIN_SECURITY_FORCESTS" value="'.getDolGlobalString("MAIN_SECURITY_FORCESTS").'" spellcheck="false"></td>';
360print '</tr>';
361// Force PP
362print '<tr class="oddeven">';
363print '<td>'.$form->textwithpicto($langs->trans('MainSecurityForcePP'), 'HTTP Header Permissions-Policy<br><br>'.$langs->trans("Example").':<br>camera=*, microphone=(), geolocation=*', 1, 'help', 'valignmiddle', 0, 3, 'MAIN_SECURITY_FORCEPP').'</td>';
364print '<td><input class="minwidth500" name="MAIN_SECURITY_FORCEPP" id="MAIN_SECURITY_FORCEPP" value="'.getDolGlobalString("MAIN_SECURITY_FORCEPP").'" spellcheck="false"></td>';
365print '</tr>';
366
367$examplecsprule = "frame-ancestors 'self'; img-src * data:; font-src *; default-src 'self' 'unsafe-inline' 'unsafe-eval' *.paypal.com *.stripe.com *.google.com *.googleapis.com *.google-analytics.com *.googletagmanager.com;";
368
369// Force CSP - Content Security Policy
370print '<tr class="oddeven nohover">';
371print '<td class="tdtop">'.$form->textwithpicto($langs->trans('MainContentSecurityPolicy'), 'HTTP Header Content-Security-Policy<br><br>'.$langs->trans("Example").":<br>".$examplecsprule, 1, 'help', 'valignmiddle', 0, 3, 'MAIN_SECURITY_FORCECSP').'</td>';
372print '<td>';
373
374print '<div class="div-table-responsive-no-min">';
375
376print '<input class="minwidth500 quatrevingtpercent" name="MAIN_SECURITY_FORCECSP" id="MAIN_SECURITY_FORCECSP" value="'.$forceCSP.'" spellcheck="false"> <span id="btnaddcontentsecuritypolicy" class="cursorpointer">'.img_picto('', 'add').'</span><br>';
377
378print '<br class="selectaddcontentsecuritypolicy hidden">';
379
380print '<div id="selectaddcontentsecuritypolicy" class="hidden selectaddcontentsecuritypolicy">';
381print $form->selectarray("select_identifier_MAIN_SECURITY_FORCECSP", $selectarrayCSPDirectives, "select_identifier_MAIN_SECURITY_FORCECSP", $langs->trans("FillCSPDirective"), 0, 0, '', 0, 0, 0, '', 'minwidth200 maxwidth350 inline-block');
382print ' ';
383print '<input type="hidden" id="select_source_MAIN_SECURITY_FORCECSP" name="select_source_MAIN_SECURITY_FORCECSP">';
384foreach ($selectarrayCSPSources as $key => $values) {
385 print '<div class="div_MAIN_SECURITY_FORCECSP hidden inline-block maxwidth350" id="div_'.$key.'_MAIN_SECURITY_FORCECSP">';
386 print $form->selectarray("select_".$key."_MAIN_SECURITY_FORCECSP", $values, "select_".$key."_MAIN_SECURITY_FORCECSP", $langs->trans("FillCSPSource"), 0, 0, '', 0, 0, 0, '', 'minwidth200 maxwidth300 inline-block select_MAIN_SECURITY_FORCECSP');
387 print '</div>';
388}
389print ' ';
390print '<div class="div_input_data_MAIN_SECURITY_FORCECSP hidden inline-block maxwidth200"><input id="input_data_MAIN_SECURITY_FORCECSP" name="input_data_MAIN_SECURITY_FORCECSP" class="valignmiddle marginright"></div>';
391print ' ';
392print '<div class="div_btn_class_MAIN_SECURITY_FORCECSP inline-block maxwidth200 marginleftonly"><input type="submit" id="btn_MAIN_SECURITY_FORCECSP" name="btn_MAIN_SECURITY_FORCECSP" class="butAction small smallpaddingimp valignmiddle" value="'.$langs->trans("Add").'" disabled></div>';
393print '<br><br>';
394print '</div>';
395
396if (!empty($forceCSP)) {
397 // Content Security Policy list of selected rules
398 print '<br>';
399 print '<div class="div-table-responsive-no-min">';
400 print img_picto('', 'graph', 'class="pictofixedwidth"').$langs->trans("HierarchicView").'<br>';
401 print '<ul>';
402 foreach ($forceCSPArr as $directive => $sources) {
403 print '<li>';
404 if (in_array($directive, array_keys($selectarrayCSPDirectives))) {
405 print '<span>'.$directive.'</span>';
406 } else {
407 print $form->textwithpicto($directive, $langs->trans("UnknowContentSecurityPolicyDirective"), 1, 'warning');
408 }
409 if (!empty($sources)) {
410 print '<ul>';
411 foreach ($sources as $key => $source) {
412 print '<li><span>'.$source.'</span>&nbsp;<a href="'.$_SERVER["PHP_SELF"].'?action=removecspsource&sourcecsp='.$directive.'_'.$key.'&token='.newToken().'">'.img_delete().'</a></li>';
413 }
414 print '</ul>';
415 } else {
416 print '&nbsp;<a href="'.$_SERVER["PHP_SELF"].'?action=removecspsource&sourcecsp='.$directive.'&token='.newToken().'">'.img_delete().'</a>';
417 }
418 print '</li>';
419 }
420 print '</ul>';
421 print '</div>';
422}
423print '</div>';
424
425print '</td>';
426print '</tr>';
427
428// Force CSPRO
429if (getDolGlobalString("MAIN_SECURITY_FORCECSPRO")) {
430 print '<tr class="oddeven">';
431 print '<td>'.$form->textwithpicto($langs->trans('MainSecurityForceCSPRO'), 'HTTP Header Content-Security-Policy-Report-Only<br><br>'.$langs->trans("Example").":<br>".$examplecsprule, 1, 'help', 'valignmiddle', 0, 3, 'MAIN_SECURITY_FORCECSPRO').'</td>';
432 print '<td><input class="minwidth500" name="MAIN_SECURITY_FORCECSPRO" id="MAIN_SECURITY_FORCECSPRO" value="'.getDolGlobalString("MAIN_SECURITY_FORCECSPRO").'"></td>';
433 print '</tr>';
434}
435
436print '</table>';
437print '</div>';
438
439
440print '<div class="center">';
441
442print '<input type="submit" class="button small" name="updateandstay" value="'.$langs->trans("Save").'">';
443print '<input class="button button-cancel small" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
444
445print '</div>';
446
447
448print '<script>
449 $(document).ready(function() {
450 $("#btnaddcontentsecuritypolicy").on("click", function(){
451 if($("#selectaddcontentsecuritypolicy").is(":visible")){
452 console.log("We hide select to add Content Security Policy");
453 $(".selectaddcontentsecuritypolicy").hide();
454 } else {
455 console.log("We show select to add Content Security Policy");
456 $(".selectaddcontentsecuritypolicy").show();
457 }
458 });
459
460 $("#select_identifier_MAIN_SECURITY_FORCECSP").on("change", function() {
461 key = $(this).find(":selected").data("directivetype");
462 console.log("We hide all select div");
463 $(".div_MAIN_SECURITY_FORCECSP").hide();
464 $(".select_MAIN_SECURITY_FORCECSP").val(null).trigger("change");
465 $(".div_input_data_MAIN_SECURITY_FORCECSP").hide();
466 $("#btn_MAIN_SECURITY_FORCECSP").prop("disabled",true);
467 if (key == "none"){
468 $("#btn_MAIN_SECURITY_FORCECSP").prop("disabled",false);
469 } else {
470 console.log("We show div select with key "+key);
471 $("#div_"+key+"_MAIN_SECURITY_FORCECSP").css("display", "inline-block");
472 }
473 });
474
475 $(".select_MAIN_SECURITY_FORCECSP").on("change", function() {
476 keysource = $(this).find(":selected").data("sourcetype");
477 $("#select_source_MAIN_SECURITY_FORCECSP").val($(this).val());
478 console.log("We hide and show fields");
479 if (keysource == "data" || keysource == "input") {
480 $(".div_input_data_MAIN_SECURITY_FORCECSP").css("display", "inline-block");
481 $("#btn_MAIN_SECURITY_FORCECSP").prop("disabled",true);
482 } else {
483 $("#input_data_MAIN_SECURITY_FORCECSP").val("");
484 $(".div_input_data_MAIN_SECURITY_FORCECSP").hide();
485 if (keysource != undefined) {
486 $("#btn_MAIN_SECURITY_FORCECSP").prop("disabled",false);
487 } else {
488 $("#btn_MAIN_SECURITY_FORCECSP").prop("disabled",true);
489 }
490 }
491 });
492
493 $("#input_data_MAIN_SECURITY_FORCECSP").on("change keyup", function(){
494 if ($(this).val() != "") {
495 console.log("We show add button");
496 $("#btn_MAIN_SECURITY_FORCECSP").prop("disabled",false);
497 } else {
498 console.log("We hide add button");
499 $("#btn_MAIN_SECURITY_FORCECSP").prop("disabled",true);
500 }
501 });
502 });
503</script>';
504
505print '</form>';
506
507print dol_get_fiche_end();
508print '</div>';
509
510// End of page
511llxFooter();
512$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.
GetContentPolicySources()
Prepare array of sources for HTTP headers.
GetContentPolicyToArray($forceCSP)
Transform a Content Security Policy to an array.
GetContentPolicyDirectives()
Prepare array of directives for HTTP headers.
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.
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, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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, $nodefault=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...
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) elseif(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) elseif( $action=='removecspsource') elseif($action=="updateform" &&GETPOST("btn_MAIN_SECURITY_FORCECSP")) elseif( $action=="updateform" cleanSecurityCSP)($securitycsp)
Function to fix a bad security CSP string.