styles.css.php 4.3 KB

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