dolibarr 22.0.5
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-2025 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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 * Note about $_SERVER:
20 * REQUEST_URI: /test/before_rewrite/script.php/path/info?q=helloword
21 * PHP_SELF: /test/after_rewrite/script.php/path/info
22 * QUERY_STRING: q=helloword
23 * SCRIPT_NAME: /test/after_rewrite/script.php
24 * PATH_INFO: /path/info
25 * SCRIPT_FILENAME: /var/www/test/php/script.php
26 * __FILE__ : /var/www/test/php/script_included.php
27 */
28
35if (!defined('NOTOKENRENEWAL')) {
36 define('NOTOKENRENEWAL', 1); // Disables token renewal
37}
38if (!defined('NOLOGIN')) {
39 define("NOLOGIN", 1);
40}
41if (!defined('NOCSRFCHECK')) {
42 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
43}
44if (!defined('NOREQUIREMENU')) {
45 define('NOREQUIREMENU', '1');
46}
47if (!defined('NOREQUIREHTML')) {
48 define('NOREQUIREHTML', '1');
49}
50if (!defined('NOREQUIREAJAX')) {
51 define('NOREQUIREAJAX', '1');
52}
53if (!defined('NOIPCHECK')) {
54 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
55}
56if (!defined('NOBROWSERNOTIF')) {
57 define('NOBROWSERNOTIF', '1');
58}
59
82function llxHeader($head = '', $title = '', $help_url = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $morequerystring = '', $morecssonbody = '', $replacemainareaby = '', $disablenofollow = 0, $disablenoindex = 0) // @phan-suppress-current-line PhanRedefineFunction
83{
84}
95function llxFooter($comment = '', $zone = 'private', $disabledoutputofmessages = 0) // @phan-suppress-current-line PhanRedefineFunction
96{
97}
98
99require '../../master.inc.php';
100require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
101
102
103$error = 0;
104$websitekey = GETPOST('website', 'alpha');
105$pageid = GETPOST('page', 'alpha') ? GETPOST('page', 'alpha') : GETPOST('pageid', 'alpha');
106$pageref = GETPOST('pageref', 'alphanohtml') ? GETPOST('pageref', 'alphanohtml') : '';
107// If page is xx/pagename, xx is a language, we set $pageref to pagename
108$reg = array();
109if (preg_match('/^(\w\w)\/(.*)$/', $pageref, $reg)) {
110 $pageref = $reg[2];
111}
112
113$accessallowed = 1;
114$type = '';
115
116
117if (empty($pageid)) {
118 require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
119 require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
120
121 $object = new Website($db);
122 $object->fetch(0, $websitekey);
123
124 if (empty($object->id)) {
125 if (empty($pageid)) {
126 // Return header 404
127 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
128
129 include DOL_DOCUMENT_ROOT.'/public/error-404.php';
130 exit;
131 }
132 }
133
134 $objectpage = new WebsitePage($db);
135
136 if ($pageref) {
137 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
138 $result = $objectpage->fetch(0, (string) $object->id, $pageref);
139 if ($result > 0) {
140 $pageid = $objectpage->id;
141 } elseif ($result == 0) {
142 // Page not found from ref=pageurl, we try using alternative alias
143 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
144 $result = $objectpage->fetch(0, (string) $object->id, null, $pageref);
145 if ($result > 0) {
146 $pageid = $objectpage->id;
147 }
148 }
149 } else {
150 if ($object->fk_default_home > 0) {
151 $result = $objectpage->fetch($object->fk_default_home);
152 if ($result > 0) {
153 $pageid = $objectpage->id;
154 }
155 }
156
157 if (empty($pageid)) {
158 $array = $objectpage->fetchAll($object->id); // TODO Can filter on container of type pages only ?
159 if (is_array($array) && count($array) > 0) {
160 $firstrep = reset($array);
161 $pageid = $firstrep->id;
162 }
163 }
164 }
165}
166if (empty($pageid)) {
167 // Return header 404
168 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
169
170 $langs->load("website");
171
172 if (!GETPOSTISSET('pageref')) {
173 print $langs->trans("PreviewOfSiteNotYetAvailable", $websitekey);
174 }
175
176 include DOL_DOCUMENT_ROOT.'/public/error-404.php';
177 exit;
178}
179if (empty($pageref)) {
180 $objectpage = new WebsitePage($db);
181 $result = $objectpage->fetch($pageid);
182 if ($result > 0) {
183 $pageref = $objectpage->ref;
184 }
185}
186if (preg_match('/^_(library|service)_page_/', $pageref)) {
187 $originalcontentonly = 1;
188}
189
190$appli = constant('DOL_APPLICATION_TITLE');
191if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
192 $appli = getDolGlobalString('MAIN_APPLICATION_TITLE');
193}
194
195
196
197/*
198 * View
199 */
200
201//print 'Directory with '.$appli.' websites.<br>';
202
203
204// Security: Delete string ../ into $original_file
205global $dolibarr_main_data_root;
206
207if ($pageid == 'css') { // No more used ?
208 header('Content-type: text/css');
209 // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
210 //if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate');
211 //else
212 header('Cache-Control: no-cache');
213 $original_file = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey.'/styles.css.php';
214} else {
215 $original_file = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey.'/page'.$pageid.'.tpl.php';
216}
217
218// Find the subdirectory name as the reference
219$refname = basename(dirname($original_file)."/");
220
221// Security:
222// Limit access if permissions are insufficient
223if (!$accessallowed) {
225}
226
227// Security:
228// On interdit les remontees de repertoire ainsi que les pipe dans
229// les noms de fichiers.
230if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file)) {
231 dol_syslog("Refused to deliver file ".$original_file);
232 $file = basename($original_file); // Do no show plain path of original_file in shown error message
233 dol_print_error(null, $langs->trans("ErrorFileNameInvalid", $file));
234 exit;
235}
236
237clearstatcache();
238
239$filename = basename($original_file);
240
241// Output file on browser
242dol_syslog("index.php include $original_file $filename content-type=$type");
243$original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset
244
245// This test if file exists should be useless. We keep it to find bug more easily
246if (!file_exists($original_file_osencoded)) {
247 // Return header 404
248 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
249
250 $langs->load("website");
251 print $langs->trans("RequestedPageHasNoContentYet", $pageid);
252
253 include DOL_DOCUMENT_ROOT.'/public/error-404.php';
254 exit;
255}
256
257
258// Output page content
259define('USEDOLIBARRSERVER', 1);
260if (!isset($originalcontentonly)) {
261 print '<!-- Page content '.$original_file.' rendered with DOLIBARR SERVER : Html with CSS link and html header + Body that was saved into tpl dir -->'."\n";
262}
263include_once $original_file_osencoded; // Note: The pageXXX.tpl.php showed here contains a formatage with dolWebsiteOutput() at end of page.
264
265if (is_object($db)) {
266 $db->close();
267}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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
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 a 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.