dolibarr 20.0.0
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * Note about $_SERVER:
19 * REQUEST_URI: /test/before_rewrite/script.php/path/info?q=helloword
20 * PHP_SELF: /test/after_rewrite/script.php/path/info
21 * QUERY_STRING: q=helloword
22 * SCRIPT_NAME: /test/after_rewrite/script.php
23 * PATH_INFO: /path/info
24 * SCRIPT_FILENAME: /var/www/test/php/script.php
25 * __FILE__ : /var/www/test/php/script_included.php
26 */
27
34if (!defined('NOTOKENRENEWAL')) {
35 define('NOTOKENRENEWAL', 1); // Disables token renewal
36}
37if (!defined('NOLOGIN')) {
38 define("NOLOGIN", 1);
39}
40if (!defined('NOCSRFCHECK')) {
41 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
42}
43if (!defined('NOREQUIREMENU')) {
44 define('NOREQUIREMENU', '1');
45}
46if (!defined('NOREQUIREHTML')) {
47 define('NOREQUIREHTML', '1');
48}
49if (!defined('NOREQUIREAJAX')) {
50 define('NOREQUIREAJAX', '1');
51}
52if (!defined('NOIPCHECK')) {
53 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
54}
55if (!defined('NOBROWSERNOTIF')) {
56 define('NOBROWSERNOTIF', '1');
57}
58
64function llxHeader()
65{
66}
72function llxFooter()
73{
74}
75
76require '../../master.inc.php';
77require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
78
79
80$error = 0;
81$websitekey = GETPOST('website', 'alpha');
82$pageid = GETPOST('page', 'alpha') ? GETPOST('page', 'alpha') : GETPOST('pageid', 'alpha');
83$pageref = GETPOST('pageref', 'alphanohtml') ? GETPOST('pageref', 'alphanohtml') : '';
84// If page is xx/pagename, xx is a language, we set $pageref to pagename
85$reg = array();
86if (preg_match('/^(\w\w)\/(.*)$/', $pageref, $reg)) {
87 $pageref = $reg[2];
88}
89
90$accessallowed = 1;
91$type = '';
92
93
94if (empty($pageid)) {
95 require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
96 require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
97
98 $object = new Website($db);
99 $object->fetch(0, $websitekey);
100
101 if (empty($object->id)) {
102 if (empty($pageid)) {
103 // Return header 404
104 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
105
106 include DOL_DOCUMENT_ROOT.'/public/error-404.php';
107 exit;
108 }
109 }
110
111 $objectpage = new WebsitePage($db);
112
113 if ($pageref) {
114 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
115 $result = $objectpage->fetch(0, $object->id, $pageref);
116 if ($result > 0) {
117 $pageid = $objectpage->id;
118 } elseif ($result == 0) {
119 // Page not found from ref=pageurl, we try using alternative alias
120 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
121 $result = $objectpage->fetch(0, $object->id, null, $pageref);
122 if ($result > 0) {
123 $pageid = $objectpage->id;
124 }
125 }
126 } else {
127 if ($object->fk_default_home > 0) {
128 $result = $objectpage->fetch($object->fk_default_home);
129 if ($result > 0) {
130 $pageid = $objectpage->id;
131 }
132 }
133
134 if (empty($pageid)) {
135 $array = $objectpage->fetchAll($object->id); // TODO Can filter on container of type pages only ?
136 if (is_array($array) && count($array) > 0) {
137 $firstrep = reset($array);
138 $pageid = $firstrep->id;
139 }
140 }
141 }
142}
143if (empty($pageid)) {
144 // Return header 404
145 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
146
147 $langs->load("website");
148
149 if (!GETPOSTISSET('pageref')) {
150 print $langs->trans("PreviewOfSiteNotYetAvailable", $websitekey);
151 }
152
153 include DOL_DOCUMENT_ROOT.'/public/error-404.php';
154 exit;
155}
156if (empty($pageref)) {
157 $objectpage = new WebsitePage($db);
158 $result = $objectpage->fetch($pageid);
159 if ($result > 0) {
160 $pageref = $objectpage->ref;
161 }
162}
163if (preg_match('/^_(library|service)_page_/', $pageref)) {
164 $originalcontentonly = 1;
165}
166
167$appli = constant('DOL_APPLICATION_TITLE');
168if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
169 $appli = getDolGlobalString('MAIN_APPLICATION_TITLE');
170}
171
172
173
174/*
175 * View
176 */
177
178//print 'Directory with '.$appli.' websites.<br>';
179
180
181// Security: Delete string ../ into $original_file
182global $dolibarr_main_data_root;
183
184if ($pageid == 'css') { // No more used ?
185 header('Content-type: text/css');
186 // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
187 //if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate');
188 //else
189 header('Cache-Control: no-cache');
190 $original_file = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey.'/styles.css.php';
191} else {
192 $original_file = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey.'/page'.$pageid.'.tpl.php';
193}
194
195// Find the subdirectory name as the reference
196$refname = basename(dirname($original_file)."/");
197
198// Security:
199// Limit access if permissions are insufficient
200if (!$accessallowed) {
202}
203
204// Security:
205// On interdit les remontees de repertoire ainsi que les pipe dans
206// les noms de fichiers.
207if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file)) {
208 dol_syslog("Refused to deliver file ".$original_file);
209 $file = basename($original_file); // Do no show plain path of original_file in shown error message
210 dol_print_error(null, $langs->trans("ErrorFileNameInvalid", $file));
211 exit;
212}
213
214clearstatcache();
215
216$filename = basename($original_file);
217
218// Output file on browser
219dol_syslog("index.php include $original_file $filename content-type=$type");
220$original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset
221
222// This test if file exists should be useless. We keep it to find bug more easily
223if (!file_exists($original_file_osencoded)) {
224 // Return header 404
225 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
226
227 $langs->load("website");
228 print $langs->trans("RequestedPageHasNoContentYet", $pageid);
229
230 include DOL_DOCUMENT_ROOT.'/public/error-404.php';
231 exit;
232}
233
234
235// Output page content
236define('USEDOLIBARRSERVER', 1);
237if (!isset($originalcontentonly)) {
238 print '<!-- Page content '.$original_file.' rendered with DOLIBARR SERVER : Html with CSS link and html header + Body that was saved into tpl dir -->'."\n";
239}
240include_once $original_file_osencoded; // Note: The pageXXX.tpl.php showed here contains a formatage with dolWebsiteOutput() at end of page.
241
242if (is_object($db)) {
243 $db->close();
244}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class Website.
Class Websitepage.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=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...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.