dolibarr 24.0.0-beta
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-2025 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';
107$error = 0;
108$websitekey = GETPOST('website', 'alpha');
109$pageid = GETPOST('page', 'alpha') ? GETPOST('page', 'alpha') : GETPOST('pageid', 'alpha');
110$pageref = GETPOST('pageref', 'alphanohtml') ? GETPOST('pageref', 'alphanohtml') : '';
111// If page is xx/pagename, xx is a language, we set $pageref to pagename
112$reg = array();
113if (preg_match('/^(\w\w)\/(.*)$/', $pageref, $reg)) {
114 $pageref = $reg[2];
115}
116
117$accessallowed = 1;
118$type = '';
119
120
121if (empty($pageid)) {
122 require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
123 require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
124
125 $object = new Website($db);
126 $object->fetch(0, $websitekey);
127
128 if (empty($object->id)) {
129 if (empty($pageid)) {
130 // Return header 404
131 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
132
133 include DOL_DOCUMENT_ROOT.'/public/error-404.php';
134 exit;
135 }
136 }
137
138 $objectpage = new WebsitePage($db);
139
140 if ($pageref) {
141 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
142 $result = $objectpage->fetch(0, (string) $object->id, $pageref);
143 if ($result > 0) {
144 $pageid = $objectpage->id;
145 } elseif ($result == 0) {
146 // Page not found from ref=pageurl, we try using alternative alias
147 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
148 $result = $objectpage->fetch(0, (string) $object->id, null, $pageref);
149 if ($result > 0) {
150 $pageid = $objectpage->id;
151 }
152 }
153 } else {
154 if ($object->fk_default_home > 0) {
155 $result = $objectpage->fetch($object->fk_default_home);
156 if ($result > 0) {
157 $pageid = $objectpage->id;
158 }
159 }
160
161 if (empty($pageid)) {
162 $array = $objectpage->fetchAll($object->id); // TODO Can filter on container of type pages only ?
163 if (is_array($array) && count($array) > 0) {
164 $firstrep = reset($array);
165 $pageid = $firstrep->id;
166 }
167 }
168 }
169}
170if (empty($pageid)) {
171 // Return header 404
172 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
173
174 $langs->load("website");
175
176 if (!GETPOSTISSET('pageref')) {
177 print $langs->trans("PreviewOfSiteNotYetAvailable", $websitekey);
178 }
179
180 include DOL_DOCUMENT_ROOT.'/public/error-404.php';
181 exit;
182}
183if (empty($pageref)) {
184 $objectpage = new WebsitePage($db);
185 $result = $objectpage->fetch($pageid);
186 if ($result > 0) {
187 $pageref = (string) $objectpage->ref;
188 }
189}
190if (preg_match('/^_(library|service)_page_/', $pageref)) {
191 $originalcontentonly = 1;
192}
193
194$appli = constant('DOL_APPLICATION_TITLE');
195if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
196 $appli = getDolGlobalString('MAIN_APPLICATION_TITLE');
197}
198
199
200
201/*
202 * View
203 */
204
205//print 'Directory with '.$appli.' websites.<br>';
206
207
208// Security: Delete string ../ into $original_file
209global $dolibarr_main_data_root;
210
211if ($pageid == 'css') { // No more used ?
212 header('Content-type: text/css');
213 // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
214 //header('Cache-Control: max-age=3600, public, must-revalidate');
215 header('Cache-Control: no-cache');
216 $original_file = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey.'/styles.css.php';
217} else {
218 $original_file = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey.'/page'.$pageid.'.tpl.php';
219}
220
221// Find the subdirectory name as the reference
222$refname = basename(dirname($original_file)."/");
223
224// Security:
225// Limit access if permissions are insufficient
226if (!$accessallowed) {
228}
229
230// Security:
231// On interdit les remontees de repertoire ainsi que les pipe dans
232// les noms de fichiers.
233if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file)) {
234 dol_syslog("Refused to deliver file ".$original_file);
235 $file = basename($original_file); // Do no show plain path of original_file in shown error message
236 dol_print_error(null, $langs->trans("ErrorFileNameInvalid", $file));
237 exit;
238}
239
240clearstatcache();
241
242$filename = basename($original_file);
243
244// Output file on browser
245dol_syslog("index.php include $original_file $filename content-type=$type");
246$original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset
247
248// This test if file exists should be useless. We keep it to find bug more easily
249if (!file_exists($original_file_osencoded)) {
250 // Return header 404
251 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
252
253 $langs->load("website");
254 print $langs->trans("RequestedPageHasNoContentYet", $pageid);
255
256 include DOL_DOCUMENT_ROOT.'/public/error-404.php';
257 exit;
258}
259
260
261// Output page content
262define('USEDOLIBARRSERVER', 1);
263if (!isset($originalcontentonly)) {
264 print '<!-- Page content '.$original_file.' rendered with DOLIBARR SERVER : Html with CSS link and html header + Body that was saved into tpl dir -->'."\n";
265}
266include_once $original_file_osencoded; // Note: The pageXXX.tpl.php showed here contains a formatage with dolWebsiteOutput() at end of page.
267
268if (is_object($db)) {
269 $db->close();
270}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.