file_list.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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-2023
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. James Rose <[email protected]>
  21. */
  22. //includes files
  23. require_once dirname(__DIR__, 2) . "/resources/require.php";
  24. require_once "resources/check_auth.php";
  25. //check permissions
  26. if (permission_exists('edit_view')) {
  27. //access granted
  28. }
  29. else {
  30. echo "access denied";
  31. exit;
  32. }
  33. //add css and javascript
  34. require_once "header.php";
  35. //define function recur_dir
  36. function recur_dir($dir) {
  37. clearstatcache();
  38. $html_dir_list = '';
  39. $html_file_list = '';
  40. $dir_handle = opendir($dir);
  41. $dir_array = array();
  42. if (($dir_handle)) {
  43. $x = 0;
  44. while (false !== ($file = readdir($dir_handle))) {
  45. if ($file != "." AND $file != "..") {
  46. $newpath = $dir.'/'.$file;
  47. $level = explode('/',$newpath);
  48. if (
  49. substr(strtolower($newpath), -4) == ".svn" ||
  50. substr(strtolower($newpath), -4) == ".git" ||
  51. substr(strtolower($newpath), -3) == ".db" ||
  52. substr(strtolower($newpath), -4) == ".jpg" ||
  53. substr(strtolower($newpath), -4) == ".gif" ||
  54. substr(strtolower($newpath), -4) == ".png" ||
  55. substr(strtolower($newpath), -4) == ".ico" ||
  56. substr(strtolower($newpath), -4) == ".ttf"
  57. ) {
  58. //ignore certain files (and folders)
  59. }
  60. else {
  61. $dir_array[] = $newpath;
  62. }
  63. if ($x > 1000) { break; }
  64. $x++;
  65. }
  66. }
  67. }
  68. asort($dir_array);
  69. foreach ($dir_array as $newpath){
  70. $level = explode('/',$newpath);
  71. if (is_dir($newpath)) {
  72. $dirname = end($level);
  73. $html_dir_list .= "<div style='white-space: nowrap; padding-left: 16px;'>\n";
  74. $html_dir_list .= "<a onclick='Toggle(this);' style='display: block; cursor: pointer;'><img src='resources/images/icon_folder.png' border='0' align='absmiddle' style='margin: 1px 2px 3px 0px;'>".$dirname."</a>";
  75. $html_dir_list .= "<div style='display: none;'>".recur_dir($newpath)."</div>\n";
  76. $html_dir_list .= "</div>\n";
  77. }
  78. else {
  79. $filename = end($level);
  80. $filesize = round(filesize($newpath)/1024, 2);
  81. $newpath = str_replace ('//', '/', $newpath);
  82. $newpath = str_replace ("\\", "/", $newpath);
  83. $html_file_list .= "<div style='white-space: nowrap; padding-left: 16px;'>\n";
  84. $html_file_list .= "<a href='javascript:void(0);' onclick=\"document.getElementById('filepath').value='".$newpath."'; document.getElementById('current_file').value = '".$newpath."'; makeRequest('file_read.php','file=".urlencode($newpath)."');\" title='".$newpath." &#10; ".$filesize." KB'>";
  85. $html_file_list .= "<img src='resources/images/icon_file.png' border='0' align='absmiddle' style='margin: 1px 2px 3px -1px;'>".$filename."</a>\n";
  86. $html_file_list .= "</div>\n";
  87. }
  88. }
  89. closedir($dir_handle);
  90. return $html_dir_list ."\n". $html_file_list;
  91. }
  92. //get the directory
  93. if (!isset($_SESSION)) { session_start(); }
  94. switch ($_SESSION["app"]["edit"]["dir"]) {
  95. case 'scripts':
  96. $edit_directory = $_SESSION['switch']['scripts']['dir'];
  97. break;
  98. case 'php':
  99. $edit_directory = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH;
  100. break;
  101. case 'grammar':
  102. $edit_directory = $_SESSION['switch']['grammar']['dir'];
  103. break;
  104. case 'provision':
  105. switch (PHP_OS) {
  106. case "Linux":
  107. if (file_exists('/usr/share/fusionpbx/templates/provision')) {
  108. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  109. }
  110. elseif (file_exists('/etc/fusionpbx/resources/templates/provision')) {
  111. $edit_directory = '/etc/fusionpbx/resources/templates/provision';
  112. }
  113. else {
  114. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  115. }
  116. break;
  117. case "FreeBSD":
  118. if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
  119. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  120. }
  121. elseif (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) {
  122. $edit_directory = '/usr/local/etc/fusionpbx/resources/templates/provision';
  123. }
  124. else {
  125. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  126. }
  127. break;
  128. case "NetBSD":
  129. if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
  130. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  131. }
  132. else {
  133. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  134. }
  135. break;
  136. case "OpenBSD":
  137. if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
  138. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  139. }
  140. else {
  141. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  142. }
  143. break;
  144. default:
  145. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/";
  146. }
  147. break;
  148. case 'xml':
  149. $edit_directory = $_SESSION['switch']['conf']['dir'];
  150. break;
  151. }
  152. if (!isset($edit_directory) && is_array($_SESSION['editor']['path'])) {
  153. foreach ($_SESSION['editor']['path'] as $path) {
  154. if ($_SESSION["app"]["edit"]["dir"] == $path) {
  155. $edit_directory = $path;
  156. break;
  157. }
  158. }
  159. }
  160. // keyboard shortcut bindings
  161. echo "<script src='".PROJECT_PATH."/resources/jquery/jquery-3.6.1.min.js'></script>\n";
  162. echo "<script src='https://code.jquery.com/jquery-migrate-3.1.0.js'></script>\n";
  163. //save file
  164. key_press('ctrl+s', 'down', 'window', null, null, "$('form#frm_edit').submit(); return false;", true);
  165. //open file manager/clip library pane
  166. key_press('ctrl+q', 'down', 'window', null, null, 'toggle_sidebar(); focus_editor(); return false;', true);
  167. //prevent backspace (browser history back)
  168. key_press('backspace', 'down', 'window', null, null, 'return false;', true);
  169. echo "</head>\n";
  170. echo "<body style='margin: 0px; padding: 5px;'>\n";
  171. echo "<div style='text-align: left; padding-top: 3px; padding-bottom: 3px;'><a href='javascript:void(0);' onclick=\"window.open('file_options.php','filewin','left=20,top=20,width=310,height=350,toolbar=0,resizable=0');\" style='text-decoration:none;' title='".$text['label-files']."'><img src='resources/images/icon_gear.png' border='0' align='absmiddle' style='margin: 0px 2px 4px -1px;'>".$text['label-files']."</a></div>\n";
  172. echo "<div style='text-align: left; margin-left: -16px;'>\n";
  173. if (function_exists('apcu_enabled') && apcu_enabled() && apcu_exists('edit_html_list')) {
  174. echo apcu_fetch('edit_html_list');
  175. exit();
  176. }
  177. if (file_exists($edit_directory)) {
  178. $edit_html_list = recur_dir($edit_directory);
  179. if (function_exists('apcu_enabled') && apcu_enabled()) {
  180. apcu_store('edit_html_list', $edit_html_list); // only available for 5 minutes
  181. }
  182. echo $edit_html_list;
  183. }
  184. echo "</div>\n";