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