35'@phan-var-force string $websitekey';
38include_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
39include_once DOL_DOCUMENT_ROOT.
'/website/class/websitepage.class.php';
47if (isset($_SERVER[
"HTTP_USER_AGENT"]) && is_object(
$conf) && empty(
$conf->browser->name)) {
49 $conf->browser->name = $tmp[
'browsername'];
50 $conf->browser->os = $tmp[
'browseros'];
51 $conf->browser->version = $tmp[
'browserversion'];
52 $conf->browser->layout = $tmp[
'layout'];
55 if (
$conf->browser->layout ==
'phone') {
56 $conf->dol_no_mouse_hover = 1;
60if (is_null($website)) {
62 $website->fetch(0, $websitekey);
65if (empty($pageid) && !empty($websitepagefile)) {
66 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), basename($websitepagefile));
67 if ($pageid ==
'index.php') {
68 $pageid = $website->fk_default_home;
71if (is_null($websitepage)) {
72 $websitepage =
new WebsitePage($db);
75if (is_null($weblangs)) {
78if (is_null($pagelangs)) {
81if (!empty($pageid) && $pageid > 0) {
82 $websitepage->fetch($pageid);
90 if (empty($srclang)) {
91 $srclang = (empty($_COOKIE[
'weblangs-shortcode']) ?
'' : preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $_COOKIE[
'weblangs-shortcode']));
93 if (empty($srclang)) {
96 if (defined(
'USEDOLIBARRSERVER') && !empty($_GET[
'pageref']) && preg_match(
'/^\/?(\w\w)\//', $_GET[
'pageref'], $reg) && $reg[1] !=
'js') {
100 if (defined(
'USEEXTERNALSERVER') && !empty($_SERVER[
'PHP_SELF']) && preg_match(
'/^\/?(\w\w)\//', $_SERVER[
'PHP_SELF'], $reg) && $reg[1] !=
'js') {
104 if (empty($srclang)) {
107 $weblangs->setDefaultLang($srclang);
109 $pagelangs->setDefaultLang($websitepage->lang ? $websitepage->lang : $weblangs->shortlang);
111 if (!defined(
'USEDOLIBARREDITOR') && (in_array($websitepage->type_container, array(
'menu',
'setup',
'other',
'header',
'footer')) || empty($websitepage->status) && !defined(
'USEDOLIBARRSERVER'))) {
112 $weblangs->load(
"website");
117 header(
"X-Content-Type-Options: nosniff");
120 if (empty($websitepage->allowed_in_frames) && !
getDolGlobalString(
'WEBSITE_ALLOW_FRAMES_ON_ALL_PAGES')) {
121 header(
"X-Frame-Options: SAMEORIGIN");
125 http_response_code(404);
126 print
'<center><br><br>'.$weblangs->trans(
"YouTryToAccessToAFileThatIsNotAWebsitePage", $websitepage->pageurl, $websitepage->type_container, $websitepage->status).
'</center>';
131if (!defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
135 header(
"X-Content-Type-Options: nosniff");
138 if (empty($websitepage->allowed_in_frames) && !
getDolGlobalString(
'WEBSITE_ALLOW_FRAMES_ON_ALL_PAGES')) {
139 header(
"X-Frame-Options: SAMEORIGIN");
146 if (!defined(
'WEBSITE_'.$website->id.
'_SECURITY_FORCECSPRO')) {
157 $contentsecuritypolicy =
getDolGlobalString(
'WEBSITE_'.$website->id.
'_SECURITY_FORCECSPRO');
159 if (!is_object($hookmanager)) {
160 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
163 $hookmanager->initHooks(array(
"main"));
165 $parameters = array(
'contentsecuritypolicy' => $contentsecuritypolicy,
'mode' =>
'reportonly');
166 $result = $hookmanager->executeHooks(
'setContentSecurityPolicy', $parameters);
168 $contentsecuritypolicy = $hookmanager->resPrint;
170 $contentsecuritypolicy .= $hookmanager->resPrint;
173 if (!empty($contentsecuritypolicy)) {
174 header(
"Content-Security-Policy-Report-Only: ".$contentsecuritypolicy);
179 if (!defined(
'WEBSITE_'.$website->id.
'_SECURITY_FORCECSP')) {
190 $contentsecuritypolicy =
getDolGlobalString(
'WEBSITE_'.$website->id.
'_SECURITY_FORCECSP');
192 if (!is_object($hookmanager)) {
193 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
196 $hookmanager->initHooks(array(
"main"));
198 $parameters = array(
'contentsecuritypolicy' => $contentsecuritypolicy,
'mode' =>
'active');
199 $result = $hookmanager->executeHooks(
'setContentSecurityPolicy', $parameters);
201 $contentsecuritypolicy = $hookmanager->resPrint;
203 $contentsecuritypolicy .= $hookmanager->resPrint;
206 if (!empty($contentsecuritypolicy)) {
207 header(
"Content-Security-Policy: ".$contentsecuritypolicy);
212 if (!defined(
'WEBSITE_'.$website->id.
'_SECURITY_FORCERP')) {
216 $referrerpolicy =
getDolGlobalString(
'WEBSITE_'.$website->id.
'_SECURITY_FORCERP',
"strict-origin-when-cross-origin");
218 header(
"Referrer-Policy: ".$referrerpolicy);
222 if (!defined(
'WEBSITE_'.$website->id.
'_SECURITY_FORCESTS')) {
228 header(
"Strict-Transport-Security: ".$sts);
233 if (!defined(
'WEBSITE_'.$website->id.
'_SECURITY_FORCEPP')) {
239 header(
"Permissions-Policy: ".$pp);
246 $weblangs->setDefaultLang(
GETPOST(
'l',
'aZ09'));
249if ($_SERVER[
'PHP_SELF'] != DOL_URL_ROOT.
'/website/index.php') {
252 $sql =
"SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
253 $sql .=
" FROM ".MAIN_DB_PREFIX.
"website_page as wp";
254 $sql .=
" WHERE wp.fk_website = ".((int) $website->id);
255 if (!empty($pageid)) {
256 $sql .=
" AND (wp.fk_page = ".((int) $pageid).
" OR wp.rowid = ".((int) $pageid);
260 if (is_object($websitepage) && $websitepage->fk_page > 0) {
261 $sql .=
" OR wp.fk_page = ".((int) $websitepage->fk_page).
" OR wp.rowid = ".((int) $websitepage->fk_page);
264 $sql .=
" AND wp.lang = '".$db->escape(
GETPOST(
'l',
'aZ09')).
"'";
266 $resql = $db->query($sql);
268 $obj = $db->fetch_object($resql);
270 $newpageid = $obj->rowid;
271 if ($newpageid != $pageid) {
272 if (defined(
'USEDOLIBARRSERVER')) {
273 header(
"Location: ".DOL_URL_ROOT.
'/public/website/index.php?website='.urlencode((
string) $websitekey).
'&pageid='.$newpageid.
'&l='.
GETPOST(
'l',
'aZ09'));
276 $newpageref = $obj->pageurl;
277 header(
"Location: ".(($obj->lang && $obj->lang != $website->lang) ?
'/'.$obj->lang.
'/' :
'/').$newpageref.
'.php?l='.
GETPOST(
'l',
'aZ09'));
287if (!defined(
'USEDOLIBARREDITOR') && empty($website->status)) {
291 header(
"X-Content-Type-Options: nosniff");
294 if (empty($websitepage->allowed_in_frames) && !
getDolGlobalString(
'WEBSITE_ALLOW_FRAMES_ON_ALL_PAGES')) {
295 header(
"X-Frame-Options: SAMEORIGIN");
298 $weblangs->load(
"website");
301 http_response_code(503);
302 print
'<center><br><br>'.$weblangs->trans(
"SorryWebsiteIsCurrentlyOffLine").
'</center>';
308$prefix = dol_getprefix(
'');
309$sessionname =
'DOLSESSID_'.$prefix;
314global $dolibarr_website_allow_custom_php;
315$notdisabledsystemfunction =
'';
316$systemfunctions = array(
"exec",
"passthru",
"shell_exec",
"system",
"popen",
"proc_open");
317foreach ($systemfunctions as $systemfunction) {
319 if (function_exists($systemfunction)) {
320 $notdisabledsystemfunction .= ($notdisabledsystemfunction ?
', ' :
'').$systemfunction;
324if (empty($dolibarr_website_allow_custom_php) || ($dolibarr_website_allow_custom_php == 1 && $notdisabledsystemfunction)) {
325 print
'<div style="padding-left: 100px; padding-right: 100px"><div class="justify"><br><br>';
326 print
'Website features are DISABLED by default because the PHP system functions ('.implode(
',', $systemfunctions).
') are NOT disabled for the website context.<br>';
327 print
'The value "'.$notdisabledsystemfunction.
'" has NOT been found into the php parameter <b>current disable_functions</b> ';
329 if (!class_exists(
'Form')) {
330 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
333 $form =
new Form($db);
335 print $form->textwithpicto(
'',
'Current value for disable_functions = '.ini_get(
'disable_functions'));
342 print
'You have 2 solutions to fix this: <br><br>';
343 print
'<b>A)</b> Change setup of your PHP ini (changing this in a virtual host with php_admin_value is not effective):<br>';
344 print
'<pre>disable_functions="exec,passthru,shell_exec,system,popen,proc_open,..."</pre>';
345 print
'but WARNING, this will break the following features:<br>';
346 print
'- 1) Cron tasks calling command line tools.<br>';
347 print
'- 2) Internal backup feature running the database dump tool.<br>';
348 print
'- 3) Command line antivirus check ran when uploading a file.<br>';
350 print
'If you don\'t use these 3 features, you can change your php.ini to exclude the exec functions... or...<br>';
352 print
'<b>B)</b> If you need at least one of this feature, you can bypass this protection by setting ';
353 print
'$dolibarr_website_allow_custom_php to 2 in your dolibarr conf.php file (In this case, we recommend to add a RCE protection like AppArmor or SELinux in this case).';
354 print
'</div></div>';
359$_COOKIE[$sessionname] =
'obfuscatedcookie';
360unset(
$conf->file->instance_unique_id);
362unset($dolibarr_main_instance_unique_id);
363unset($dolibarr_main_dolcrypt_key);
365unset($dolibarr_main_db_host);
366unset($dolibarr_main_db_port);
367unset($dolibarr_main_db_name);
368unset($dolibarr_main_db_user);
369unset($dolibarr_main_db_pass);
370unset($dolibarr_main_db_type);
371unset($dolibarr_main_document_root);
372unset($dolibarr_main_document_root_alt);
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 translations.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
getBrowserInfo($user_agent)
Return information about user browser.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.