exec.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. // Copyright (C) 2013 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Execute a module page - this is an alternative to invoking /myItop/env-production/myModule/somePage.php
  20. *
  21. * The recommended way to build an URL to a module page is to invoke utils::GetAbsoluteUrlModulePage()
  22. * or its javascript equivalent GetAbsoluteUrlModulePage()
  23. *
  24. * To be compatible with this mechanism, the called page must include approot
  25. * with an absolute path OR not include it at all (losing the direct access to the page)
  26. * if (!defined('__DIR__')) define('__DIR__', dirname(__FILE__));
  27. * require_once(__DIR__.'/../../approot.inc.php');
  28. *
  29. * @copyright Copyright (C) 2013 Combodo SARL
  30. * @license http://opensource.org/licenses/AGPL-3.0
  31. */
  32. require_once('../approot.inc.php');
  33. // Needed to read the parameters (with sanitization)
  34. require_once(APPROOT.'application/utils.inc.php');
  35. $sModule = utils::ReadParam('exec_module', '');
  36. if ($sModule == '')
  37. {
  38. echo "Missing argument 'exec_module'";
  39. exit;
  40. }
  41. $sModule = basename($sModule); // protect against ../.. ...
  42. $sPage = utils::ReadParam('exec_page', '', false, 'raw_data');
  43. if ($sPage == '')
  44. {
  45. echo "Missing argument 'exec_page'";
  46. exit;
  47. }
  48. $sPage = basename($sPage); // protect against ../.. ...
  49. session_name('itop-'.md5(APPROOT));
  50. session_start();
  51. $sEnvironment = utils::ReadParam('exec_env', utils::GetCurrentEnvironment());
  52. session_write_close();
  53. $sTargetPage = APPROOT.'env-'.$sEnvironment.'/'.$sModule.'/'.$sPage;
  54. if (!file_exists($sTargetPage))
  55. {
  56. // Do not recall the parameters (security takes precedence)
  57. echo "Wrong module, page name or environment...";
  58. exit;
  59. }
  60. /////////////////////////////////////////
  61. //
  62. // GO!
  63. //
  64. require_once($sTargetPage);