file_read.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2025
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes files
  22. require_once dirname(__DIR__, 2) . "/resources/require.php";
  23. require_once "resources/check_auth.php";
  24. //check permissions
  25. if (!permission_exists('edit_view')) {
  26. echo "access denied";
  27. exit;
  28. }
  29. //get the directory
  30. if (!isset($_SESSION)) { session_start(); }
  31. switch ($_SESSION["app"]["edit"]["dir"]) {
  32. case 'scripts':
  33. $edit_directory = $settings->get('switch','scripts');
  34. break;
  35. case 'php':
  36. $edit_directory = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH;
  37. break;
  38. case 'grammar':
  39. $edit_directory = $settings->get('switch','grammar');
  40. break;
  41. case 'provision':
  42. switch (PHP_OS) {
  43. case "Linux":
  44. if (file_exists('/usr/share/fusionpbx/templates/provision')) {
  45. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  46. }
  47. elseif (file_exists('/etc/fusionpbx/resources/templates/provision')) {
  48. $edit_directory = '/etc/fusionpbx/resources/templates/provision';
  49. }
  50. else {
  51. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  52. }
  53. break;
  54. case "FreeBSD":
  55. if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
  56. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  57. }
  58. elseif (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) {
  59. $edit_directory = '/usr/local/etc/fusionpbx/resources/templates/provision';
  60. }
  61. else {
  62. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  63. }
  64. break;
  65. case "NetBSD":
  66. if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
  67. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  68. }
  69. else {
  70. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  71. }
  72. break;
  73. case "OpenBSD":
  74. if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
  75. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  76. }
  77. else {
  78. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  79. }
  80. break;
  81. default:
  82. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/";
  83. }
  84. break;
  85. case 'xml':
  86. $edit_directory = $settings->get('switch','conf');
  87. break;
  88. }
  89. if (!isset($edit_directory) && is_array($_SESSION['editor']['path'])) {
  90. foreach ($_SESSION['editor']['path'] as $path) {
  91. if ($_SESSION["app"]["edit"]["dir"] == $path) {
  92. $edit_directory = $path;
  93. break;
  94. }
  95. }
  96. }
  97. //set the file variable
  98. $file_name = $_POST["file"];
  99. //remove attempts to change the directory
  100. $file_name = str_replace('..', '', $file_name);
  101. $file_name = str_replace ("\\", "/", $file_name);
  102. //break the path into an array
  103. $path_array = pathinfo($file_name);
  104. $path_prefix = substr($path_array['dirname'], 0, strlen($edit_directory));
  105. //validate the path
  106. if (realpath($path_prefix) == realpath($edit_directory)) {
  107. //clear the output
  108. ob_clean();
  109. //send the content of the file
  110. echo file_get_contents($file_name);
  111. //get the contents of the file
  112. /*
  113. $handle = fopen($file_name, "r");
  114. if ($handle) {
  115. while (!feof($handle)) {
  116. $buffer = fgets($handle, 4096);
  117. echo $buffer;
  118. }
  119. fclose($handle);
  120. }
  121. */
  122. }