file_list.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. 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. echo "access denied";
  28. exit;
  29. }
  30. //create the settings object
  31. if (!$settings) {
  32. $settings = new settings();
  33. }
  34. //add css and javascript
  35. require_once "header.php";
  36. //define function recur_dir
  37. function recur_dir($dir) {
  38. clearstatcache();
  39. $html_dir_list = '';
  40. $html_file_list = '';
  41. $dir_handle = opendir($dir);
  42. $dir_array = array();
  43. if (($dir_handle)) {
  44. $x = 0;
  45. while (false !== ($file = readdir($dir_handle))) {
  46. if ($file != "." AND $file != "..") {
  47. $newpath = $dir.'/'.$file;
  48. $level = explode('/',$newpath);
  49. if (
  50. substr(strtolower($newpath), -4) == ".svn" ||
  51. substr(strtolower($newpath), -4) == ".git" ||
  52. substr(strtolower($newpath), -3) == ".db" ||
  53. substr(strtolower($newpath), -4) == ".jpg" ||
  54. substr(strtolower($newpath), -4) == ".gif" ||
  55. substr(strtolower($newpath), -4) == ".png" ||
  56. substr(strtolower($newpath), -4) == ".ico" ||
  57. substr(strtolower($newpath), -4) == ".ttf"
  58. ) {
  59. //ignore certain files (and folders)
  60. }
  61. else {
  62. $dir_array[] = $newpath;
  63. }
  64. if ($x > 1000) { break; }
  65. $x++;
  66. }
  67. }
  68. }
  69. asort($dir_array);
  70. foreach ($dir_array as $newpath){
  71. $level = explode('/',$newpath);
  72. if (is_dir($newpath)) {
  73. $dirname = end($level);
  74. $html_dir_list .= "<div style='white-space: nowrap; padding-left: 16px;'>\n";
  75. $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>";
  76. $html_dir_list .= "<div style='display: none;'>".recur_dir($newpath)."</div>\n";
  77. $html_dir_list .= "</div>\n";
  78. }
  79. else {
  80. $filename = end($level);
  81. $filesize = round(filesize($newpath)/1024, 2);
  82. $newpath = str_replace ('//', '/', $newpath);
  83. $newpath = str_replace ("\\", "/", $newpath);
  84. $html_file_list .= "<div style='white-space: nowrap; padding-left: 16px;'>\n";
  85. $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'>";
  86. $html_file_list .= "<img src='resources/images/icon_file.png' border='0' align='absmiddle' style='margin: 1px 2px 3px -1px;'>".$filename."</a>\n";
  87. $html_file_list .= "</div>\n";
  88. }
  89. }
  90. closedir($dir_handle);
  91. return $html_dir_list ."\n". $html_file_list;
  92. }
  93. //get the directory
  94. if (!isset($_SESSION)) { session_start(); }
  95. switch ($_SESSION["app"]["edit"]["dir"]) {
  96. case 'scripts':
  97. $edit_directory = $settings->get('switch', 'scripts');
  98. break;
  99. case 'php':
  100. $edit_directory = dirname(__DIR__, 2);
  101. break;
  102. case 'grammar':
  103. $edit_directory = $settings->get('switch', 'grammar');
  104. break;
  105. case 'provision':
  106. switch (PHP_OS) {
  107. case "Linux":
  108. if (file_exists('/usr/share/fusionpbx/templates/provision')) {
  109. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  110. }
  111. elseif (file_exists('/etc/fusionpbx/resources/templates/provision')) {
  112. $edit_directory = '/etc/fusionpbx/resources/templates/provision';
  113. }
  114. else {
  115. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  116. }
  117. break;
  118. case "FreeBSD":
  119. if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
  120. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  121. }
  122. elseif (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) {
  123. $edit_directory = '/usr/local/etc/fusionpbx/resources/templates/provision';
  124. }
  125. else {
  126. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  127. }
  128. break;
  129. case "NetBSD":
  130. if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
  131. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  132. }
  133. else {
  134. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  135. }
  136. break;
  137. case "OpenBSD":
  138. if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
  139. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  140. }
  141. else {
  142. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  143. }
  144. break;
  145. default:
  146. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/";
  147. }
  148. break;
  149. case 'xml':
  150. $edit_directory = $settings->get('switch', 'conf');
  151. break;
  152. default:
  153. //do not allow unknown settings
  154. exit();
  155. }
  156. // keyboard shortcut bindings
  157. echo "<script src='".PROJECT_PATH."/resources/jquery/jquery-3.6.1.min.js'></script>\n";
  158. echo "<script src='https://code.jquery.com/jquery-migrate-3.1.0.js'></script>\n";
  159. //save file
  160. key_press('ctrl+s', 'down', 'window', null, null, "$('form#frm_edit').submit(); return false;", true);
  161. //open file manager/clip library pane
  162. key_press('ctrl+q', 'down', 'window', null, null, 'toggle_sidebar(); focus_editor(); return false;', true);
  163. //prevent backspace (browser history back)
  164. key_press('backspace', 'down', 'window', null, null, 'return false;', true);
  165. echo "</head>\n";
  166. echo "<body style='margin: 0px; padding: 5px;'>\n";
  167. 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";
  168. echo "<div style='text-align: left; margin-left: -16px;'>\n";
  169. if (file_exists($edit_directory)) {
  170. $edit_html_list = recur_dir($edit_directory);
  171. echo $edit_html_list;
  172. }
  173. echo "</div>\n";