index.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. /**
  27. * \file htdocs/public/website/index.php
  28. * \ingroup website
  29. * \brief Wrapper to output pages when website is powered by Dolibarr instead of a native web server
  30. */
  31. if (!defined('NOTOKENRENEWAL')) {
  32. define('NOTOKENRENEWAL', 1); // Disables token renewal
  33. }
  34. if (!defined('NOLOGIN')) {
  35. define("NOLOGIN", 1);
  36. }
  37. if (!defined('NOCSRFCHECK')) {
  38. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  39. }
  40. if (!defined('NOREQUIREMENU')) {
  41. define('NOREQUIREMENU', '1');
  42. }
  43. if (!defined('NOREQUIREHTML')) {
  44. define('NOREQUIREHTML', '1');
  45. }
  46. if (!defined('NOREQUIREAJAX')) {
  47. define('NOREQUIREAJAX', '1');
  48. }
  49. if (!defined('NOIPCHECK')) {
  50. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  51. }
  52. if (!defined('NOBROWSERNOTIF')) {
  53. define('NOBROWSERNOTIF', '1');
  54. }
  55. /**
  56. * Header empty
  57. *
  58. * @return void
  59. */
  60. function llxHeader()
  61. {
  62. }
  63. /**
  64. * Footer empty
  65. *
  66. * @return void
  67. */
  68. function llxFooter()
  69. {
  70. }
  71. require '../../master.inc.php';
  72. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  73. $error = 0;
  74. $websitekey = GETPOST('website', 'alpha');
  75. $pageid = GETPOST('page', 'alpha') ?GETPOST('page', 'alpha') : GETPOST('pageid', 'alpha');
  76. $pageref = GETPOST('pageref', 'alphanohtml') ?GETPOST('pageref', 'alphanohtml') : '';
  77. $accessallowed = 1;
  78. $type = '';
  79. if (empty($pageid)) {
  80. require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
  81. require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
  82. $object = new Website($db);
  83. $object->fetch(0, $websitekey);
  84. if (empty($object->id)) {
  85. if (empty($pageid)) {
  86. // Return header 404
  87. header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
  88. include DOL_DOCUMENT_ROOT.'/public/error-404.php';
  89. exit;
  90. }
  91. }
  92. $objectpage = new WebsitePage($db);
  93. if ($pageref) {
  94. $result = $objectpage->fetch(0, $object->id, $pageref);
  95. if ($result > 0) {
  96. $pageid = $objectpage->id;
  97. } elseif ($result == 0) {
  98. // Page not found from ref=pageurl, we try using alternative alias
  99. $result = $objectpage->fetch(0, $object->id, null, $pageref);
  100. if ($result > 0) {
  101. $pageid = $objectpage->id;
  102. }
  103. }
  104. } else {
  105. if ($object->fk_default_home > 0) {
  106. $result = $objectpage->fetch($object->fk_default_home);
  107. if ($result > 0) {
  108. $pageid = $objectpage->id;
  109. }
  110. }
  111. if (empty($pageid)) {
  112. $array = $objectpage->fetchAll($object->id); // TODO Can filter on container of type pages only ?
  113. if (is_array($array) && count($array) > 0) {
  114. $firstrep = reset($array);
  115. $pageid = $firstrep->id;
  116. }
  117. }
  118. }
  119. }
  120. if (empty($pageid)) {
  121. // Return header 404
  122. header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
  123. $langs->load("website");
  124. if (!GETPOSTISSET('pageref')) {
  125. print $langs->trans("PreviewOfSiteNotYetAvailable", $websitekey);
  126. }
  127. include DOL_DOCUMENT_ROOT.'/public/error-404.php';
  128. exit;
  129. }
  130. $appli = constant('DOL_APPLICATION_TITLE');
  131. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  132. $appli = $conf->global->MAIN_APPLICATION_TITLE;
  133. }
  134. /*
  135. * View
  136. */
  137. //print 'Directory with '.$appli.' websites.<br>';
  138. // Security: Delete string ../ into $original_file
  139. global $dolibarr_main_data_root;
  140. if ($pageid == 'css') { // No more used ?
  141. header('Content-type: text/css');
  142. // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
  143. //if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate');
  144. //else
  145. header('Cache-Control: no-cache');
  146. $original_file = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey.'/styles.css.php';
  147. } else {
  148. $original_file = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey.'/page'.$pageid.'.tpl.php';
  149. }
  150. // Find the subdirectory name as the reference
  151. $refname = basename(dirname($original_file)."/");
  152. // Security:
  153. // Limite acces si droits non corrects
  154. if (!$accessallowed) {
  155. accessforbidden();
  156. }
  157. // Security:
  158. // On interdit les remontees de repertoire ainsi que les pipe dans
  159. // les noms de fichiers.
  160. if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file)) {
  161. dol_syslog("Refused to deliver file ".$original_file);
  162. $file = basename($original_file); // Do no show plain path of original_file in shown error message
  163. dol_print_error(0, $langs->trans("ErrorFileNameInvalid", $file));
  164. exit;
  165. }
  166. clearstatcache();
  167. $filename = basename($original_file);
  168. // Output file on browser
  169. dol_syslog("index.php include $original_file $filename content-type=$type");
  170. $original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset
  171. // This test if file exists should be useless. We keep it to find bug more easily
  172. if (!file_exists($original_file_osencoded)) {
  173. // Return header 404
  174. header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
  175. $langs->load("website");
  176. print $langs->trans("RequestedPageHasNoContentYet", $pageid);
  177. include DOL_DOCUMENT_ROOT.'/public/error-404.php';
  178. exit;
  179. }
  180. // Output page content
  181. define('USEDOLIBARRSERVER', 1);
  182. print '<!-- Page content '.$original_file.' rendered with DOLIBARR SERVER : Html with CSS link and html header + Body that was saved into tpl dir -->'."\n";
  183. include_once $original_file_osencoded; // Note: The pageXXX.tpl.php showed here contains a formatage with dolWebsiteOutput() at end of page.
  184. if (is_object($db)) {
  185. $db->close();
  186. }