navig.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. require_once('includes/helpers.php');
  25. navigation();
  26. function navigation() {
  27. global $db;
  28. if ( isset($_REQUEST['m']) )
  29. {
  30. if ( preg_match('[/|\\|;|\.]',$_REQUEST['m']) !== 0 )
  31. {
  32. // Unallowed characters found.
  33. print_failure("Unallowed characters found from m.");
  34. return;
  35. }
  36. // If module is not installed we must not allow access.
  37. if ( $db->isModuleInstalled($_REQUEST['m']) === FALSE )
  38. {
  39. print_failure(get_lang('module_not_installed'));
  40. return;
  41. }
  42. // If module dir does not exist there has been some error...
  43. if ( !is_dir( MODULES.$_REQUEST['m'] ) )
  44. {
  45. print_failure("Invalid module ".$_REQUEST['m'].".");
  46. return;
  47. }
  48. // There is navigation.xml file lets parse the information.
  49. if ( is_file( MODULES.$_REQUEST['m'].'/navigation.xml') )
  50. {
  51. $xml_navig = simplexml_load_file( MODULES.$_REQUEST['m'].'/navigation.xml' );
  52. if ( $xml_navig === FALSE )
  53. {
  54. print_failure("Invalid XML navigation file.");
  55. return;
  56. }
  57. // If the subpage is not defined we use the default page.
  58. $wanted_page = isset($_REQUEST['p']) ? $_REQUEST['p'] : "default";
  59. foreach ( $xml_navig->page as $page )
  60. {
  61. if ( $page["key"] != $wanted_page )
  62. continue;
  63. $access_groups = explode(",",$page['access']);
  64. if ( basename($_SERVER['PHP_SELF']) != "index.php" )
  65. {
  66. if( array_search($_SESSION['users_group'], $access_groups) === FALSE )
  67. {
  68. print_failure(get_lang('no_rights') );
  69. return;
  70. }
  71. }
  72. else
  73. {
  74. if( array_search("guest", $access_groups) === FALSE )
  75. {
  76. print_failure(get_lang('no_rights') );
  77. return;
  78. }
  79. }
  80. $include_file = MODULES.$_REQUEST['m'].'/'.$page['file'];
  81. if ( !is_file( $include_file ) )
  82. {
  83. print_failure("File (".$include_file.") missing from module.");
  84. return;
  85. }
  86. include_once( $include_file );
  87. if ( !function_exists( 'exec_ogp_module' ) )
  88. {
  89. print_failure("Missing module execute function.");
  90. return;
  91. }
  92. exec_ogp_module();
  93. return;
  94. }
  95. print_failure("Invalid subpage given.");
  96. return;
  97. }
  98. // If no navigation file then we load file with same filename than the module.
  99. else if ( is_file( MODULES.$_REQUEST['m'].'/'.$_REQUEST['m'].'.php') )
  100. {
  101. include( MODULES.$_REQUEST['m'].'/'.$_REQUEST['m'].'.php');
  102. if ( !function_exists( 'exec_ogp_module' ) )
  103. {
  104. print_failure("Missing module execute function.");
  105. return;
  106. }
  107. exec_ogp_module();
  108. }
  109. // If files above are not found then we print an error.
  110. else
  111. {
  112. print_failure("Invalid module ".$_REQUEST['m'].".");
  113. return;
  114. }
  115. }
  116. }
  117. ?>