styles.css.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. /**
  18. * \file htdocs/public/website/styles.css.php
  19. * \ingroup website
  20. * \brief Page to output style page. Called with <link rel="stylesheet" href="styles.css.php?websiteid=123" type="text/css" />
  21. */
  22. if (!defined('NOTOKENRENEWAL')) {
  23. define('NOTOKENRENEWAL', 1); // Disables token renewal
  24. }
  25. if (!defined('NOLOGIN')) {
  26. define("NOLOGIN", 1);
  27. }
  28. if (!defined('NOCSRFCHECK')) {
  29. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  30. }
  31. if (!defined('NOREQUIREMENU')) {
  32. define('NOREQUIREMENU', '1');
  33. }
  34. if (!defined('NOREQUIREHTML')) {
  35. define('NOREQUIREHTML', '1');
  36. }
  37. if (!defined('NOREQUIREAJAX')) {
  38. define('NOREQUIREAJAX', '1');
  39. }
  40. if (!defined('NOIPCHECK')) {
  41. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  42. }
  43. if (!defined('NOBROWSERNOTIF')) {
  44. define('NOBROWSERNOTIF', '1');
  45. }
  46. /**
  47. * Header empty
  48. *
  49. * @return void
  50. */
  51. function llxHeader()
  52. {
  53. }
  54. /**
  55. * Footer empty
  56. *
  57. * @return void
  58. */
  59. function llxFooter()
  60. {
  61. }
  62. require '../../master.inc.php';
  63. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  64. $error = 0;
  65. $website = GETPOST('website', 'alpha');
  66. $websiteid = GETPOST('websiteid', 'int');
  67. $pageid = GETPOST('page', 'alpha') ?GETPOST('page', 'alpha') : GETPOST('pageid', 'alpha');
  68. $accessallowed = 1;
  69. $type = '';
  70. /*
  71. * View
  72. */
  73. $appli = constant('DOL_APPLICATION_TITLE');
  74. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  75. $appli = $conf->global->MAIN_APPLICATION_TITLE;
  76. }
  77. //print 'Directory with '.$appli.' websites.<br>';
  78. if (empty($pageid)) {
  79. require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
  80. require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
  81. $object = new Website($db);
  82. if ($websiteid) {
  83. $object->fetch($websiteid);
  84. $website = $object->ref;
  85. } else {
  86. $object->fetch(0, $website);
  87. }
  88. $objectpage = new WebsitePage($db);
  89. /* Not required for CSS file
  90. $array=$objectpage->fetchAll($object->id);
  91. if (is_array($array) && count($array) > 0)
  92. {
  93. $firstrep=reset($array);
  94. $pageid=$firstrep->id;
  95. }
  96. */
  97. }
  98. /* Not required for CSS file
  99. if (empty($pageid))
  100. {
  101. $langs->load("website");
  102. print $langs->trans("PreviewOfSiteNotYetAvailable");
  103. exit;
  104. }
  105. */
  106. // Security: Delete string ../ into $original_file
  107. global $dolibarr_main_data_root;
  108. $original_file = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$website.'/styles.css.php';
  109. // Find the subdirectory name as the reference
  110. $refname = basename(dirname($original_file)."/");
  111. // Security:
  112. // Limite acces si droits non corrects
  113. if (!$accessallowed) {
  114. accessforbidden();
  115. }
  116. // Security:
  117. // On interdit les remontees de repertoire ainsi que les pipe dans
  118. // les noms de fichiers.
  119. if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file)) {
  120. dol_syslog("Refused to deliver file ".$original_file);
  121. $file = basename($original_file); // Do no show plain path of original_file in shown error message
  122. dol_print_error(0, $langs->trans("ErrorFileNameInvalid", $file));
  123. exit;
  124. }
  125. clearstatcache();
  126. $filename = basename($original_file);
  127. // Output file on browser
  128. dol_syslog("styles.css.php include $original_file $filename content-type=$type");
  129. $original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset
  130. // This test if file exists should be useless. We keep it to find bug more easily
  131. if (!file_exists($original_file_osencoded)) {
  132. $langs->load("website");
  133. print $langs->trans("RequestedPageHasNoContentYet", $pageid);
  134. //dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file));
  135. exit;
  136. }
  137. // Output page content
  138. define('USEDOLIBARRSERVER', 1);
  139. print '/* Page content '.$original_file.' : CSS content that was saved into tpl dir */'."\n";
  140. require_once $original_file_osencoded;
  141. if (is_object($db)) {
  142. $db->close();
  143. }