37include_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
38include_once DOL_DOCUMENT_ROOT.
'/website/class/websitepage.class.php';
46if (isset($_SERVER[
"HTTP_USER_AGENT"]) && is_object(
$conf) && empty(
$conf->browser->name)) {
48 $conf->browser->name = $tmp[
'browsername'];
49 $conf->browser->os = $tmp[
'browseros'];
50 $conf->browser->version = $tmp[
'browserversion'];
51 $conf->browser->layout = $tmp[
'layout'];
54 if (
$conf->browser->layout ==
'phone') {
55 $conf->dol_no_mouse_hover = 1;
59if (is_null($website)) {
61 $website->fetch(0, $websitekey);
64if (empty($pageid) && !empty($websitepagefile)) {
65 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), basename($websitepagefile));
66 if ($pageid ==
'index.php') {
67 $pageid = $website->fk_default_home;
70if (is_null($websitepage)) {
71 $websitepage =
new WebsitePage(
$db);
74if (is_null($weblangs)) {
77if (is_null($pagelangs)) {
80if (!empty($pageid) && $pageid > 0) {
81 $websitepage->fetch($pageid);
88 $srclang = GETPOSTISSET(
'lang') ?
GETPOST(
'lang',
'aZ09') :
'';
89 if (empty($srclang)) {
90 $srclang = (empty($_COOKIE[
'weblangs-shortcode']) ?
'' : preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $_COOKIE[
'weblangs-shortcode']));
92 if (empty($srclang)) {
95 if (defined(
'USEDOLIBARRSERVER') && !empty($_GET[
'pageref']) && preg_match(
'/^\/?(\w\w)\//', $_GET[
'pageref'], $reg) && $reg[1] !=
'js') {
99 if (defined(
'USEEXTERNALSERVER') && !empty($_SERVER[
'PHP_SELF']) && preg_match(
'/^\/?(\w\w)\//', $_SERVER[
'PHP_SELF'], $reg) && $reg[1] !=
'js') {
103 if (empty($srclang)) {
106 $weblangs->setDefaultLang($srclang);
108 $pagelangs->setDefaultLang($websitepage->lang ? $websitepage->lang : $weblangs->shortlang);
110 if (!defined(
'USEDOLIBARREDITOR') && (in_array($websitepage->type_container, array(
'menu',
'setup',
'other')) || empty($websitepage->status) && !defined(
'USEDOLIBARRSERVER'))) {
111 $weblangs->load(
"website");
116 header(
"X-Content-Type-Options: nosniff");
119 if (empty($websitepage->allowed_in_frames) && !
getDolGlobalString(
'WEBSITE_ALLOW_FRAMES_ON_ALL_PAGES')) {
120 header(
"X-Frame-Options: SAMEORIGIN");
124 http_response_code(404);
125 print
'<center><br><br>'.$weblangs->trans(
"YouTryToAccessToAFileThatIsNotAWebsitePage", $websitepage->pageurl, $websitepage->type_container, $websitepage->status).
'</center>';
130if (!defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
134 header(
"X-Content-Type-Options: nosniff");
137 if (empty($websitepage->allowed_in_frames) && !
getDolGlobalString(
'WEBSITE_ALLOW_FRAMES_ON_ALL_PAGES')) {
138 header(
"X-Frame-Options: SAMEORIGIN");
145 if (!defined(
'WEBSITE_'.$website->id.
'_SECURITY_FORCECSPRO')) {
156 $contentsecuritypolicy =
getDolGlobalString(
'WEBSITE_'.$website->id.
'_SECURITY_FORCECSPRO');
158 if (!is_object($hookmanager)) {
159 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
162 $hookmanager->initHooks(array(
"main"));
164 $parameters = array(
'contentsecuritypolicy' => $contentsecuritypolicy,
'mode' =>
'reportonly');
165 $result = $hookmanager->executeHooks(
'setContentSecurityPolicy', $parameters);
167 $contentsecuritypolicy = $hookmanager->resPrint;
169 $contentsecuritypolicy .= $hookmanager->resPrint;
172 if (!empty($contentsecuritypolicy)) {
173 header(
"Content-Security-Policy-Report-Only: ".$contentsecuritypolicy);
178 if (!defined(
'WEBSITE_'.$website->id.
'_SECURITY_FORCECSP')) {
189 $contentsecuritypolicy =
getDolGlobalString(
'WEBSITE_'.$website->id.
'_SECURITY_FORCECSP');
191 if (!is_object($hookmanager)) {
192 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
195 $hookmanager->initHooks(array(
"main"));
197 $parameters = array(
'contentsecuritypolicy' => $contentsecuritypolicy,
'mode' =>
'active');
198 $result = $hookmanager->executeHooks(
'setContentSecurityPolicy', $parameters);
200 $contentsecuritypolicy = $hookmanager->resPrint;
202 $contentsecuritypolicy .= $hookmanager->resPrint;
205 if (!empty($contentsecuritypolicy)) {
206 header(
"Content-Security-Policy: ".$contentsecuritypolicy);
211 if (!defined(
'WEBSITE_'.$website->id.
'_SECURITY_FORCERP')) {
215 $referrerpolicy =
getDolGlobalString(
'WEBSITE_'.$website->id.
'_SECURITY_FORCERP',
"strict-origin-when-cross-origin");
217 header(
"Referrer-Policy: ".$referrerpolicy);
221 if (!defined(
'WEBSITE_'.$website->id.
'_SECURITY_FORCESTS')) {
227 header(
"Strict-Transport-Security: ".$sts);
232 if (!defined(
'WEBSITE_'.$website->id.
'_SECURITY_FORCEPP')) {
238 header(
"Permissions-Policy: ".$pp);
245 $weblangs->setDefaultLang(
GETPOST(
'l',
'aZ09'));
248if ($_SERVER[
'PHP_SELF'] != DOL_URL_ROOT.
'/website/index.php') {
251 $sql =
"SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
252 $sql .=
" FROM ".MAIN_DB_PREFIX.
"website_page as wp";
253 $sql .=
" WHERE wp.fk_website = ".((int) $website->id);
254 $sql .=
" AND (wp.fk_page = ".((int) $pageid).
" OR wp.rowid = ".((int) $pageid);
255 if (is_object($websitepage) && $websitepage->fk_page > 0) {
256 $sql .=
" OR wp.fk_page = ".((int) $websitepage->fk_page).
" OR wp.rowid = ".((int) $websitepage->fk_page);
259 $sql .=
" AND wp.lang = '".$db->escape(
GETPOST(
'l',
'aZ09')).
"'";
261 $resql =
$db->query($sql);
263 $obj =
$db->fetch_object($resql);
265 $newpageid = $obj->rowid;
266 if ($newpageid != $pageid) {
267 if (defined(
'USEDOLIBARRSERVER')) {
268 header(
"Location: ".DOL_URL_ROOT.
'/public/website/index.php?website='.$websitekey.
'&pageid='.$newpageid.
'&l='.
GETPOST(
'l',
'aZ09'));
271 $newpageref = $obj->pageurl;
272 header(
"Location: ".(($obj->lang && $obj->lang != $website->lang) ?
'/'.$obj->lang.
'/' :
'/').$newpageref.
'.php?l='.
GETPOST(
'l',
'aZ09'));
282if (!defined(
'USEDOLIBARREDITOR') && empty($website->status)) {
286 header(
"X-Content-Type-Options: nosniff");
289 if (empty($websitepage->allowed_in_frames) && !
getDolGlobalString(
'WEBSITE_ALLOW_FRAMES_ON_ALL_PAGES')) {
290 header(
"X-Frame-Options: SAMEORIGIN");
293 $weblangs->load(
"website");
296 http_response_code(503);
297 print
'<center><br><br>'.$weblangs->trans(
"SorryWebsiteIsCurrentlyOffLine").
'</center>';
303$prefix = dol_getprefix(
'');
304$sessionname =
'DOLSESSID_'.$prefix;
309global $dolibarr_website_allow_custom_php;
310$notdisabledsystemfunction =
'';
311$systemfunctions = array(
"exec",
"passthru",
"shell_exec",
"system",
"popen",
"proc_open");
312foreach ($systemfunctions as $systemfunction) {
314 if (function_exists($systemfunction)) {
315 $notdisabledsystemfunction .= ($notdisabledsystemfunction ?
', ' :
'').$systemfunction;
319if (empty($dolibarr_website_allow_custom_php) || ($dolibarr_website_allow_custom_php == 1 && $notdisabledsystemfunction)) {
320 print
'<center><br><br>';
321 print
'Website features are DISABLED if the PHP system functions ('.implode(
',', $systemfunctions).
') are NOT disabled for the website context.<br>';
322 print
'The value "'.$notdisabledsystemfunction.
'" has NOT been found into the php parameter <b>current disable_functions</b> ';
325 print $form->textwithpicto(
'',
'Current value for disable_functions = '.ini_get(
'disable_functions'));
332 print
'You can fix this by changing setup of your PHP ini (changing this in a virtual host with php_admin_value is not effective):<br>';
333 print
'disable_functions="exec,passthru,shell_exec,system,popen,proc_open,..."<br>';
334 print
'but WARNING, this will break this 3 features for:<br>';
335 print
'- 1) Cron tasks calling command line tools.<br>';
336 print
'- 2) Internal backup feature running the database dump tool.<br>';
337 print
'- 3) Command line antivirus check ran when uploading a file.<br>';
339 print
'If you don\'t use this 3 feature, you can change your php.ini to exclude the exec functions.<br>If you need at least one, you can bypass this protection by setting $dolibarr_website_allow_custom_php to 2 in your dolibarr config file (Add RCE protection like AppArmor or SELinux in this case).';
345$_COOKIE[$sessionname] =
'obfuscatedcookie';
346unset(
$conf->file->instance_unique_id);
348unset($dolibarr_main_instance_unique_id);
349unset($dolibarr_main_dolcrypt_key);
351unset($dolibarr_main_db_host);
352unset($dolibarr_main_db_port);
353unset($dolibarr_main_db_name);
354unset($dolibarr_main_db_user);
355unset($dolibarr_main_db_pass);
356unset($dolibarr_main_db_type);
357unset($dolibarr_main_document_root);
358unset($dolibarr_main_document_root_alt);
Class to manage translations.
getBrowserInfo($user_agent)
Return information about user browser.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.