dolibarr 24.0.0-beta
website.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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
34{
35 global $langs, $conf;
36
37 $h = 0;
38 $head = array();
39
40 $head[$h][0] = DOL_URL_ROOT.'/website/index.php?websiteid='.$object->id.'&action=editcss';
41 $head[$h][1] = $langs->trans("General");
42 $head[$h][2] = 'general';
43 $h++;
44
45 $head[$h][0] = DOL_URL_ROOT.'/website/index.php?websiteid='.$object->id.'&action=editsecurity';
46 $head[$h][1] = $langs->trans("Security");
47 $head[$h][2] = 'security';
48 $h++;
49
50 /*if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
51 $nbNote = 0;
52 if(!empty($object->fields['note_private'])) $nbNote++;
53 if(!empty($object->fields['note_public'])) $nbNote++;
54 $head[$h][0] = dol_buildpath('/monmodule/websiteaccount_note.php', 1).'?id='.$object->id;
55 $head[$h][1] = $langs->trans('Notes');
56 if ($nbNote > 0) $head[$h][1].= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
57 $head[$h][2] = 'note';
58 $h++;
59 }*/
60
61 /*
62 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
63 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
64 $upload_dir = $conf->monmodule->dir_output . "/websiteaccount/" . dol_sanitizeFileName($object->ref);
65 $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
66 $nbLinks=Link::count($db, $object->element, $object->id);
67 $head[$h][0] = dol_buildpath("/monmodule/websiteaccount_document.php", 1).'?id='.$object->id;
68 $head[$h][1] = $langs->trans('Documents');
69 if (($nbFiles+$nbLinks) > 0) $head[$h][1].= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.($nbFiles+$nbLinks).'</span>' : '');
70 $head[$h][2] = 'document';
71 $h++;
72
73 $head[$h][0] = dol_buildpath("/monmodule/websiteaccount_agenda.php", 1).'?id='.$object->id;
74 $head[$h][1] = $langs->trans("Events");
75 $head[$h][2] = 'agenda';
76 $h++;
77 */
78
79 // Show more tabs from modules
80 // Entries must be declared in modules descriptor with line
81 //$this->tabs = array(
82 // 'entity:+tabname:Title:@monmodule:/monmodule/mypage.php?id=__ID__'
83 //); // to add new tab
84 //$this->tabs = array(
85 // 'entity:-tabname:Title:@monmodule:/monmodule/mypage.php?id=__ID__'
86 //); // to remove a tab
87 complete_head_from_modules($conf, $langs, $object, $head, $h, 'websiteaccount@website');
88
89 complete_head_from_modules($conf, $langs, $object, $head, $h, 'websiteaccount@website', 'remove');
90
91 return $head;
92}
93
100{
101 return array(
102 // Fetch directives
103 "child-src" => array("label" => "child-src", "data-directivetype" => "fetch"),
104 "connect-src" => array("label" => "connect-src", "data-directivetype" => "fetch"),
105 "default-src" => array("label" => "default-src", "data-directivetype" => "fetch"),
106 "fenced-frame-src" => array("label" => "fenced-frame-src", "data-directivetype" => "fetch"),
107 "font-src" => array("label" => "font-src", "data-directivetype" => "fetch"),
108 "frame-src" => array("label" => "frame-src", "data-directivetype" => "fetch"),
109 "img-src" => array("label" => "img-src", "data-directivetype" => "fetch"),
110 "manifest-src" => array("label" => "manifest-src", "data-directivetype" => "fetch"),
111 "media-src" => array("label" => "media-src", "data-directivetype" => "fetch"),
112 "object-src" => array("label" => "object-src", "data-directivetype" => "fetch"),
113 "prefetch-src" => array("label" => "prefetch-src", "data-directivetype" => "fetch"),
114 "script-src" => array("label" => "script-src", "data-directivetype" => "fetch"),
115 "script-src-elem" => array("label" => "script-src-elem", "data-directivetype" => "fetch"),
116 "script-src-attr" => array("label" => "script-src-attr", "data-directivetype" => "fetch"),
117 "style-src" => array("label" => "style-src","data-directivetype" => "fetch"),
118 "style-src-elem" => array("label" => "style-src-elem", "data-directivetype" => "fetch"),
119 "style-src-attr" => array("label" => "style-src-attr", "data-directivetype" => "fetch"),
120 "worker-src" => array("label" => "worker-src", "data-directivetype" => "fetch"),
121 // Document directives
122 "base-uri" => array("label" => "base-uri", "data-directivetype" => "document"),
123 "sandbox" => array("label" => "sandbox", "data-directivetype" => "document"),
124 // Navigation directives
125 "form-action" => array("label" => "form-action", "data-directivetype" => "navigation"),
126 "frame-ancestors" => array("label" => "frame-ancestors", "data-directivetype" => "navigation"),
127 // Reporting directives
128 "report-to" => array("label" => "report-to", "data-directivetype" => "reporting"),
129 // Other directives
130 "require-trusted-types-for" => array("label" => "require-trusted-types-for", "data-directivetype" => "require-trusted-types-for"),
131 "trusted-types" => array("label" => "trusted-types", "data-directivetype" => "trusted-types"),
132 "upgrade-insecure-requests" => array("label" => "upgrade-insecure-requests", "data-directivetype" => "none"),
133 );
134}
135
142{
143 return array(
144 // Fetch directives
145 "fetch" => array(
146 "*" => array("label" => "*", "data-sourcetype" => "select"),
147 "data" => array("label" => "data:", "data-sourcetype" => "data"),
148 "self" => array("label" => "self", "data-sourcetype" => "quoted"),
149 "unsafe-eval" => array("label" => "unsafe-eval", "data-sourcetype" => "quoted"),
150 "wasm-unsafe-eval" => array("label" => "wasm-unsafe-eval", "data-sourcetype" => "quoted"),
151 "unsafe-inline" => array("label" => "unsafe-inline", "data-sourcetype" => "quoted"),
152 "unsafe-hashes" => array("label" => "unsafe-hashes", "data-sourcetype" => "quoted"),
153 "inline-speculation-rules" => array("label" => "inline-speculation-rules", "data-sourcetype" => "quoted"),
154 "strict-dynamic" => array("label" => "strict-dynamic", "data-sourcetype" => "quoted"),
155 "report-sample" => array("label" => "report-sample", "data-sourcetype" => "quoted"),
156 "host-source" => array("label" => "host-source (*.mydomain.com)", "data-sourcetype" => "input"),
157 "scheme-source" => array("label" => "scheme-source", "data-sourcetype" => "input"),
158 ),
159 // Document directives
160 "document" => array(
161 "none" => array("label" => "self", "data-sourcetype" => "quoted"),
162 "self" => array("label" => "self", "data-sourcetype" => "quoted"),
163 "host-source" => array("label" => "host-source (*.mydomain.com)", "data-sourcetype" => "input"),
164 "scheme-source" => array("label" => "scheme-source (*.mydomain.com)", "data-sourcetype" => "input"),
165 ),
166 // Navigation directives
167 "navigation" => array(
168 "none" => array("label" => "self", "data-sourcetype" => "quoted"),
169 "self" => array("label" => "self", "data-sourcetype" => "quoted"),
170 "host-source" => array("label" => "host-source (*.mydomain.com)", "data-sourcetype" => "input"),
171 "scheme-source" => array("label" => "scheme-source", "data-sourcetype" => "input"),
172 ),
173 // Reporting directives
174 "reporting" => array(
175 "report-to" => array("label" => "report-to", "data-sourcetype" => "input"),
176 ),
177 // Other directives
178 "require-trusted-types-for" => array(
179 "script" => array("label" => "script", "data-sourcetype" => "select"),
180 ),
181 "trusted-types" => array(
182 "policyName" => array("label" => "policyName", "data-sourcetype" => "input"),
183 "none" => array("label" => "none", "data-sourcetype" => "quoted"),
184 "allow-duplicates" => array("label" => "allow-duplicates", "data-sourcetype" => "quoted"),
185 ),
186 );
187}
188
196{
197 $forceCSPArr = array();
198 $sourceCSPArr = websiteGetContentPolicySources();
199 $sourceCSPArrflatten = array();
200
201 // We remove a level for sources array
202 foreach ($sourceCSPArr as $key => $arr) {
203 $sourceCSPArrflatten = array_merge($sourceCSPArrflatten, array_keys($arr));
204 }
205 // Manage the issue where the data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D string is getting split, as well as the issue with the "add" button.
206 $forceCSP = preg_replace('/;base64,/', "__semicolumnbase64__", $forceCSP);
207 $securitypolicies = explode(";", $forceCSP);
208
209 // Loop on each security policy to create an array
210 foreach ($securitypolicies as $key => $securitypolicy) {
211 if ($securitypolicy == "") {
212 continue;
213 }
214 $securitypolicy = preg_replace('/__semicolumnbase64__/', ";base64,", $securitypolicy);
215 $securitypolicyarr = explode(" ", $securitypolicy);
216 $directive = array_shift($securitypolicyarr);
217 // Remove unwanted spaces
218 while ($directive == "") {
219 $directive = array_shift($securitypolicyarr);
220 }
221 if (empty($directive)) {
222 continue;
223 }
224 $sources = $securitypolicyarr;
225 if (empty($sources)) {
226 $forceCSPArr[$directive] = array();
227 } else {
228 //Loop on each sources to add to the right directive array key
229 foreach ($sources as $key2 => $source) {
230 $source = str_replace("'", "", $source);
231 if (empty($source)) {
232 continue;
233 }
234 if (empty($forceCSPArr[$directive])) {
235 $forceCSPArr[$directive] = array($source);
236 } else {
237 $forceCSPArr[$directive][] = $source;
238 }
239 }
240 }
241 }
242 return $forceCSPArr;
243}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
websiteGetContentPolicyDirectives()
Prepare array of directives for Website.
websiteGetContentPolicySources()
Prepare array of sources for Website.
websiteGetContentPolicyToArray($forceCSP)
Transform a Content Security Policy to an array.
websiteconfigPrepareHead($object)
Prepare array of tabs for Website.