file_options_list.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. //add multi-lingual support
  31. $language = new text;
  32. $text = $language->get();
  33. //include
  34. require_once "header.php";
  35. //define function recure_dir
  36. function recur_dir($dir) {
  37. clearstatcache();
  38. $htmldirlist = '';
  39. $htmlfilelist = '';
  40. $dirlist = opendir($dir);
  41. $dir_array = array();
  42. if($dirlist !== false) {
  43. $x = 0;
  44. while (false !== ($file = readdir($dirlist))) {
  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. $newpath = str_replace ('//', '/', $newpath);
  74. $htmldirlist .= "
  75. <table border=0 cellpadding='0' cellspacing='0' width='100%'>
  76. <tr>
  77. <td nowrap style='padding-left: 16px;'>
  78. <a onclick=\"Toggle(this, '".$newpath."');\" style='cursor: pointer;'><img src='resources/images/icon_folder.png' border='0' align='absmiddle' style='margin: 1px 2px 3px 0px;'>".$dirname."</a><div style='display:none'>".recur_dir($newpath)."</div>
  79. </td>
  80. </tr>
  81. </table>\n";
  82. }
  83. else {
  84. $filename = end($level);
  85. $filesize = round(filesize($newpath)/1024, 2);
  86. $newpath = str_replace ('//', '/', $newpath);
  87. $newpath = str_replace ("\\", "/", $newpath);
  88. $newpath = str_replace ($filename, '', $newpath);
  89. $htmlfilelist .= "
  90. <table border=0 cellpadding='0' cellspacing='0' width='100%'>
  91. <tr>
  92. <td nowrap align='bottom' style='padding-left: 16px;'>
  93. <a href='javascript:void(0);' onclick=\"parent.document.getElementById('filename').value='".$filename."'; parent.document.getElementById('folder').value='".$newpath."';\" title='".$newpath." &#10; ".$filesize." KB'><img src='resources/images/icon_file.png' border='0' align='absmiddle' style='margin: 1px 2px 3px -1px;'>".$filename."</a>
  94. </td>
  95. </tr>
  96. </table>\n";
  97. }
  98. }
  99. closedir($dirlist);
  100. return $htmldirlist ."\n". $htmlfilelist;
  101. }
  102. echo "<script type=\"text/javascript\" language=\"javascript\">\n";
  103. echo " function makeRequest(url, strpost) {\n";
  104. echo " var http_request = false;\n";
  105. echo "\n";
  106. echo " if (window.XMLHttpRequest) { // Mozilla, Safari, ...\n";
  107. echo " http_request = new XMLHttpRequest();\n";
  108. echo " if (http_request.overrideMimeType) {\n";
  109. echo " http_request.overrideMimeType('text/xml');\n";
  110. echo " // See note below about this line\n";
  111. echo " }\n";
  112. echo " } else if (window.ActiveXObject) { // IE\n";
  113. echo " try {\n";
  114. echo " http_request = new ActiveXObject(\"Msxml2.XMLHTTP\");\n";
  115. echo " } catch (e) {\n";
  116. echo " try {\n";
  117. echo " http_request = new ActiveXObject(\"Microsoft.XMLHTTP\");\n";
  118. echo " } catch (e) {}\n";
  119. echo " }\n";
  120. echo " }\n";
  121. echo "\n";
  122. echo " if (!http_request) {\n";
  123. echo " alert('".$text['message-give-up']."');\n";
  124. echo " return false;\n";
  125. echo " }\n";
  126. echo " http_request.onreadystatechange = function() { returnContent(http_request); };\n";
  127. echo " http_request.overrideMimeType('text/html');\n";
  128. echo " http_request.open('POST', url, true);\n";
  129. echo "\n";
  130. echo "\n";
  131. echo " if (strpost.length == 0) {\n";
  132. echo " //http_request.send(null);\n";
  133. echo " http_request.send('name=value&foo=bar');\n";
  134. echo " }\n";
  135. echo " else {\n";
  136. echo " http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');\n";
  137. echo " http_request.send(strpost);\n";
  138. echo " }\n";
  139. echo "\n";
  140. echo " }\n";
  141. echo "\n";
  142. echo " function returnContent(http_request) {\n";
  143. echo "\n";
  144. echo " if (http_request.readyState == 4) {\n";
  145. echo " if (http_request.status == 200) {\n";
  146. echo " parent.editAreaLoader.setValue('edit1', http_request.responseText); \n";
  147. echo "\n";
  148. echo " }\n";
  149. echo " else {\n";
  150. echo " alert('".$text['message-problem']."');\n";
  151. echo " }\n";
  152. echo " }\n";
  153. echo "\n";
  154. echo " }\n";
  155. echo "</script>\n";
  156. echo "<SCRIPT LANGUAGE=\"JavaScript\">\n";
  157. //echo "// ---------------------------------------------\n";
  158. //echo "// --- http://www.codeproject.com/jscript/dhtml_treeview.asp\n";
  159. //echo "// --- Name: Easy DHTML Treeview --\n";
  160. //echo "// --- Author: D.D. de Kerf --\n";
  161. //echo "// --- Version: 0.2 Date: 13-6-2001 --\n";
  162. //echo "// ---------------------------------------------\n";
  163. echo "function Toggle(node, path) {\n";
  164. echo " parent.document.getElementById('folder').value=path; \n";
  165. echo " parent.document.getElementById('filename').value='';\n";
  166. echo " parent.document.getElementById('folder').focus();\n";
  167. echo " // Unfold the branch if it isn't visible\n";
  168. echo " if (node.nextSibling.style.display == 'none') {\n";
  169. echo " node.nextSibling.style.display = 'block';\n";
  170. echo " }\n";
  171. echo " // Collapse the branch if it IS visible\n";
  172. echo " else {\n";
  173. echo " node.nextSibling.style.display = 'none';\n";
  174. echo " }\n";
  175. echo "\n";
  176. echo "}\n";
  177. echo "</SCRIPT>\n";
  178. echo "</head>\n";
  179. echo "<body style='margin: 0; padding: 5px;' onfocus='blur();'>\n";
  180. echo "<div style='text-align: left; margin-left: -16px;'>\n";
  181. if (!isset($_SESSION)) { session_start(); }
  182. //get the directory
  183. if (!isset($_SESSION)) { session_start(); }
  184. switch ($_SESSION["app"]["edit"]["dir"]) {
  185. case 'scripts':
  186. $edit_directory = $settings->get('switch','scripts');
  187. break;
  188. case 'php':
  189. $edit_directory = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH;
  190. break;
  191. case 'grammar':
  192. $edit_directory = $settings->get('switch','scripts');
  193. break;
  194. case 'provision':
  195. switch (PHP_OS) {
  196. case "Linux":
  197. if (file_exists('/usr/share/fusionpbx/templates/provision')) {
  198. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  199. }
  200. elseif (file_exists('/etc/fusionpbx/resources/templates/provision')) {
  201. $edit_directory = '/etc/fusionpbx/resources/templates/provision';
  202. }
  203. else {
  204. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  205. }
  206. break;
  207. case "FreeBSD":
  208. if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
  209. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  210. }
  211. elseif (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) {
  212. $edit_directory = '/usr/local/etc/fusionpbx/resources/templates/provision';
  213. }
  214. else {
  215. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  216. }
  217. break;
  218. case "NetBSD":
  219. if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
  220. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  221. }
  222. else {
  223. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  224. }
  225. break;
  226. case "OpenBSD":
  227. if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
  228. $edit_directory = '/usr/share/fusionpbx/templates/provision';
  229. }
  230. else {
  231. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
  232. }
  233. break;
  234. default:
  235. $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/";
  236. }
  237. break;
  238. case 'xml':
  239. $edit_directory = $_SESSION['switch']['conf']['dir'];
  240. break;
  241. }
  242. if (file_exists($edit_directory)) {
  243. echo recur_dir($edit_directory);
  244. }
  245. echo "</div>\n";
  246. require_once "footer.php";