PageRenderTime 36ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/glpi/inc/includes.php

#
PHP | 165 lines | 132 code | 2 blank | 31 comment | 1 complexity | 051354d2b0fdca7ab512755fa3888d9d MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. * @version $Id: includes.php 18872 2012-07-10 09:52:13Z moyo $
  4. -------------------------------------------------------------------------
  5. GLPI - Gestionnaire Libre de Parc Informatique
  6. Copyright (C) 2003-2012 by the INDEPNET Development Team.
  7. http://indepnet.net/ http://glpi-project.org
  8. -------------------------------------------------------------------------
  9. LICENSE
  10. This file is part of GLPI.
  11. GLPI is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15. GLPI is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with GLPI. If not, see <http://www.gnu.org/licenses/>.
  21. --------------------------------------------------------------------------
  22. */
  23. // ----------------------------------------------------------------------
  24. // Original Author of file:
  25. // Purpose of file:
  26. // ----------------------------------------------------------------------
  27. if (!defined('GLPI_ROOT')) {
  28. die("Sorry. You can't access directly to this file");
  29. }
  30. include_once (GLPI_ROOT . "/inc/autoload.function.php");
  31. // Init Timer to compute time of display
  32. $TIMER_DEBUG = new Timer();
  33. $TIMER_DEBUG->start();
  34. /// TODO try to remove them if possible
  35. include_once (GLPI_ROOT . "/inc/db.function.php");
  36. // Standard includes
  37. include_once (GLPI_ROOT . "/config/config.php");
  38. // Security of PHP_SELF
  39. $_SERVER['PHP_SELF'] = Html::cleanParametersURL($_SERVER['PHP_SELF']);
  40. // Load Language file
  41. Session::loadLanguage();
  42. if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
  43. $SQL_TOTAL_REQUEST=0;
  44. $DEBUG_SQL["queries"]=array();
  45. $DEBUG_SQL["errors"]=array();
  46. $DEBUG_SQL["times"]=array();
  47. $DEBUG_AUTOLOAD=array();
  48. }
  49. // Security system
  50. if (isset($_POST)) {
  51. if (Toolbox::get_magic_quotes_gpc()) {
  52. $_POST = array_map(array('Toolbox', 'stripslashes_deep'), $_POST);
  53. }
  54. $_POST = array_map(array('Toolbox','addslashes_deep'), $_POST);
  55. $_POST = array_map(array('Toolbox', 'clean_cross_side_scripting_deep'), $_POST);
  56. }
  57. if (isset($_GET)) {
  58. if (Toolbox::get_magic_quotes_gpc()) {
  59. $_GET = array_map(array('Toolbox', 'stripslashes_deep'), $_GET);
  60. }
  61. $_GET = array_map(array('Toolbox','addslashes_deep'), $_GET);
  62. $_GET = array_map(array('Toolbox', 'clean_cross_side_scripting_deep'), $_GET);
  63. }
  64. // Mark if Header is loaded or not :
  65. $HEADER_LOADED=false;
  66. $FOOTER_LOADED=false;
  67. if (isset($AJAX_INCLUDE)) {
  68. $HEADER_LOADED=true;
  69. }
  70. /* On startup, register all plugins configured for use. */
  71. if (!isset($AJAX_INCLUDE) && !isset($PLUGINS_INCLUDED)) {
  72. // PLugin already included
  73. $PLUGINS_INCLUDED=1;
  74. $LOADED_PLUGINS=array();
  75. $plugin = new Plugin();
  76. if (!isset($_SESSION["glpi_plugins"])) {
  77. $plugin->init();
  78. }
  79. if (isset($_SESSION["glpi_plugins"]) && is_array($_SESSION["glpi_plugins"])) {
  80. //Plugin::doHook("config");
  81. if (count($_SESSION["glpi_plugins"])) {
  82. foreach ($_SESSION["glpi_plugins"] as $name) {
  83. Plugin::load($name);
  84. }
  85. }
  86. // For plugins which require action after all plugin init
  87. Plugin::doHook("post_init");
  88. }
  89. }
  90. if (!isset($_SESSION["MESSAGE_AFTER_REDIRECT"])) {
  91. $_SESSION["MESSAGE_AFTER_REDIRECT"]="";
  92. }
  93. // Manage force tab
  94. if (isset($_REQUEST['forcetab'])) {
  95. if (preg_match('/([a-zA-Z]+).form.php/',$_SERVER['PHP_SELF'],$matches)) {
  96. $itemtype=$matches[1];
  97. Session::setActiveTab($matches[1],$_REQUEST['forcetab']);
  98. }
  99. }
  100. // Manage tabs
  101. if (isset($_REQUEST['glpi_tab']) && isset($_REQUEST['itemtype'])) {
  102. Session::setActiveTab($_REQUEST['itemtype'],$_REQUEST['glpi_tab']);
  103. }
  104. // Override list-limit if choosen
  105. if (isset($_REQUEST['glpilist_limit'])) {
  106. $_SESSION['glpilist_limit']=$_REQUEST['glpilist_limit'];
  107. }
  108. // Security : Check HTTP_REFERRER : need to be in GLPI.
  109. if (!defined('DO_NOT_CHECK_HTTP_REFERER') && !isCommandLine()
  110. && isset($_POST) && is_array($_POST) && count($_POST)) {
  111. // Do not applyed for plugins on 0.83
  112. if (strstr($_SERVER['REQUEST_URI'],$CFG_GLPI['root_doc'].'/plugins/') === FALSE) {
  113. if (!isset($_SERVER['HTTP_REFERER'])
  114. || !is_array($url=parse_url($_SERVER['HTTP_REFERER']))
  115. || !isset($url['host'])
  116. || ($url['host']!=$_SERVER['SERVER_NAME'])
  117. || !isset($url['path'])
  118. || (!empty($CFG_GLPI['root_doc']) && strpos($url['path'], $CFG_GLPI['root_doc'])!==0)) {
  119. Html::displayErrorAndDie("Error calling the previous page from forbidden one.", true);
  120. }
  121. }
  122. }
  123. // Security : check CSRF token
  124. // No CSRF check if a plugin is not compliant
  125. if (GLPI_USE_CSRF_CHECK
  126. && isset($_POST) && is_array($_POST) && count($_POST)
  127. && Plugin::isAllPluginsCSRFCompliant()) {
  128. // No ajax pages
  129. if (!preg_match(':'.$CFG_GLPI['root_doc'].'(/plugins/[^/]*|)/ajax/:', $_SERVER['REQUEST_URI'])) {
  130. if (!Session::validateCSRF($_POST)) {
  131. Html::displayErrorAndDie("The action you have requested is not allowed. Reload previous page before doing action again.", true);
  132. }
  133. }
  134. }
  135. // SET new global Token
  136. $CURRENTCSRFTOKEN = '';
  137. ?>