dolibarr 25.0.0-alpha
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 {
76 dol_print_error($db);
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 {
84 dol_print_error($db);
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
340
341print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" spellcheck="false">';
342
343print '<input type="hidden" name="token" value="'.newToken().'">';
344print '<input type="hidden" name="action" value="updateform">';
345
346print '<div class="div-table-responsive-no-min">';
347print '<table class="noborder centpercent">';
348print '<tr class="liste_titre">';
349print '<td>'.$langs->trans("HTTPHeader").'</td>';
350print '<td></td>'."\n";
351print '</tr>';
352
353// Force RP
354print '<tr class="oddeven">';
355print '<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>';
356print '<td><input class="minwidth500" name="MAIN_SECURITY_FORCERP" id="MAIN_SECURITY_FORCERP" value="'.getDolGlobalString("MAIN_SECURITY_FORCERP").'" spellcheck="false"></td>';
357print '</tr>';
358// Force STS
359print '<tr class="oddeven">';
360print '<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>';
361print '<td><input class="minwidth500" name="MAIN_SECURITY_FORCESTS" id="MAIN_SECURITY_FORCESTS" value="'.getDolGlobalString("MAIN_SECURITY_FORCESTS").'" spellcheck="false"></td>';
362print '</tr>';
363// Force PP
364print '<tr class="oddeven">';
365print '<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>';
366print '<td><input class="minwidth500" name="MAIN_SECURITY_FORCEPP" id="MAIN_SECURITY_FORCEPP" value="'.getDolGlobalString("MAIN_SECURITY_FORCEPP").'" spellcheck="false"></td>';
367print '</tr>';
368
369$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;";
370
371// Force CSP - Content Security Policy
372print '<tr class="oddeven nohover">';
373print '<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>';
374print '<td>';
375
376print '<div class="div-table-responsive-no-min">';
377
378print '<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>';
379
380print '<br class="selectaddcontentsecuritypolicy hidden">';
381
382print '<div id="selectaddcontentsecuritypolicy" class="hidden selectaddcontentsecuritypolicy">';
383print $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');
384print ' ';
385print '<input type="hidden" id="select_source_MAIN_SECURITY_FORCECSP" name="select_source_MAIN_SECURITY_FORCECSP">';
386foreach ($selectarrayCSPSources as $key => $values) {
387 print '<div class="div_MAIN_SECURITY_FORCECSP hidden inline-block maxwidth350" id="div_'.$key.'_MAIN_SECURITY_FORCECSP">';
388 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');
389 print '</div>';
390}
391print ' ';
392print '<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>';
393print ' ';
394print '<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>';
395print '<br><br>';
396print '</div>';
397
398if (!empty($forceCSP)) {
399 // Content Security Policy list of selected rules
400 print '<br>';
401 print '<div class="div-table-responsive-no-min">';
402 print img_picto('', 'graph', 'class="pictofixedwidth"').$langs->trans("HierarchicView").'<br>';
403 print '<ul>';
404 foreach ($forceCSPArr as $directive => $sources) {
405 print '<li>';
406 if (in_array($directive, array_keys($selectarrayCSPDirectives))) {
407 print '<span>'.$directive.'</span>';
408 } else {
409 print $form->textwithpicto($directive, $langs->trans("UnknowContentSecurityPolicyDirective"), 1, 'warning');
410 }
411 if (!empty($sources)) {
412 print '<ul>';
413 foreach ($sources as $key => $source) {
414 print '<li><span>'.$source.'</span>&nbsp;<a href="'.$_SERVER["PHP_SELF"].'?action=removecspsource&sourcecsp='.$directive.'_'.$key.'&token='.newToken().'">'.img_delete().'</a></li>';
415 }
416 print '</ul>';
417 } else {
418 print '&nbsp;<a href="'.$_SERVER["PHP_SELF"].'?action=removecspsource&sourcecsp='.$directive.'&token='.newToken().'">'.img_delete().'</a>';
419 }
420 print '</li>';
421 }
422 print '</ul>';
423 print '</div>';
424}
425print '</div>';
426
427print '</td>';
428print '</tr>';
429
430// Force CSPRO
431if (getDolGlobalString("MAIN_SECURITY_FORCECSPRO")) {
432 print '<tr class="oddeven">';
433 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>';
434 print '<td><input class="minwidth500" name="MAIN_SECURITY_FORCECSPRO" id="MAIN_SECURITY_FORCECSPRO" value="'.getDolGlobalString("MAIN_SECURITY_FORCECSPRO").'"></td>';
435 print '</tr>';
436}
437
438print '</table>';
439print '</div>';
440
441
442print '<div class="center">';
443
444print '<input type="submit" class="button small" name="updateandstay" value="'.$langs->trans("Save").'">';
445print '<input class="button button-cancel small" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
446
447print '</div>';
448
449
450print '<script>
451 $(document).ready(function() {
452 $("#btnaddcontentsecuritypolicy").on("click", function(){
453 if($("#selectaddcontentsecuritypolicy").is(":visible")){
454 console.log("We hide select to add Content Security Policy");
455 $(".selectaddcontentsecuritypolicy").hide();
456 } else {
457 console.log("We show select to add Content Security Policy");
458 $(".selectaddcontentsecuritypolicy").show();
459 }
460 });
461
462 $("#select_identifier_MAIN_SECURITY_FORCECSP").on("change", function() {
463 key = $(this).find(":selected").data("directivetype");
464 console.log("We hide all select div");
465 $(".div_MAIN_SECURITY_FORCECSP").hide();
466 $(".select_MAIN_SECURITY_FORCECSP").val(null).trigger("change");
467 $(".div_input_data_MAIN_SECURITY_FORCECSP").hide();
468 $("#btn_MAIN_SECURITY_FORCECSP").prop("disabled",true);
469 if (key == "none"){
470 $("#btn_MAIN_SECURITY_FORCECSP").prop("disabled",false);
471 } else {
472 console.log("We show div select with key "+key);
473 $("#div_"+key+"_MAIN_SECURITY_FORCECSP").css("display", "inline-block");
474 }
475 });
476
477 $(".select_MAIN_SECURITY_FORCECSP").on("change", function() {
478 keysource = $(this).find(":selected").data("sourcetype");
479 $("#select_source_MAIN_SECURITY_FORCECSP").val($(this).val());
480 console.log("We hide and show fields");
481 if (keysource == "data" || keysource == "input") {
482 $(".div_input_data_MAIN_SECURITY_FORCECSP").css("display", "inline-block");
483 $("#btn_MAIN_SECURITY_FORCECSP").prop("disabled",true);
484 } else {
485 $("#input_data_MAIN_SECURITY_FORCECSP").val("");
486 $(".div_input_data_MAIN_SECURITY_FORCECSP").hide();
487 if (keysource != undefined) {
488 $("#btn_MAIN_SECURITY_FORCECSP").prop("disabled",false);
489 } else {
490 $("#btn_MAIN_SECURITY_FORCECSP").prop("disabled",true);
491 }
492 }
493 });
494
495 $("#input_data_MAIN_SECURITY_FORCECSP").on("change keyup", function(){
496 if ($(this).val() != "") {
497 console.log("We show add button");
498 $("#btn_MAIN_SECURITY_FORCECSP").prop("disabled",false);
499 } else {
500 console.log("We hide add button");
501 $("#btn_MAIN_SECURITY_FORCECSP").prop("disabled",true);
502 }
503 });
504 });
505</script>';
506
507print '</form>';
508
509print dol_get_fiche_end();
510print '</div>';
511
512// End of page
513llxFooter();
514$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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage generation of HTML components Only common components must be here.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.