file_options_list.php 9.2 KB

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