exec.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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-2012
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. include "root.php";
  22. require_once "includes/require.php";
  23. require_once "includes/checkauth.php";
  24. if (permission_exists('exec_command_line') || permission_exists('exec_php_command') || permission_exists('exec_switch')) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. //get the html values and set them as variables
  32. if (count($_POST)>0) {
  33. $shell_cmd = trim($_POST["shell_cmd"]);
  34. $php_cmd = trim($_POST["php_cmd"]);
  35. $switch_cmd = trim($_POST["switch_cmd"]);
  36. }
  37. //show the header
  38. require_once "includes/header.php";
  39. //edit area
  40. echo " <script language=\"javascript\" type=\"text/javascript\" src=\"".PROJECT_PATH."/includes/edit_area/edit_area_full.js\"></script>\n";
  41. echo " <script language=\"Javascript\" type=\"text/javascript\">\n";
  42. echo " // initialisation //load,\n";
  43. echo " editAreaLoader.init({\n";
  44. echo " id: \"shell_cmd\" // id of the textarea to transform //, |, help\n";
  45. echo " ,start_highlight: false\n";
  46. echo " ,display: \"later\"\n";
  47. echo " ,font_size: \"8\"\n";
  48. echo " ,allow_toggle: true\n";
  49. echo " ,language: \"en\"\n";
  50. echo " ,syntax: \"html\"\n";
  51. echo " ,toolbar: \"search, go_to_line,|, fullscreen, |, undo, redo, |, select_font, |, syntax_selection, |, change_smooth_selection, highlight, reset_highlight, |, help\" //new_document,\n";
  52. echo " ,plugins: \"charmap\"\n";
  53. echo " ,charmap_default: \"arrows\"\n";
  54. echo " });\n";
  55. echo "\n";
  56. echo " editAreaLoader.init({\n";
  57. echo " id: \"php_cmd\" // id of the textarea to transform //, |, help\n";
  58. echo " ,start_highlight: false\n";
  59. echo " ,display: \"later\"\n";
  60. echo " ,font_size: \"8\"\n";
  61. echo " ,allow_toggle: true\n";
  62. echo " ,language: \"en\"\n";
  63. echo " ,syntax: \"php\"\n";
  64. echo " ,toolbar: \"search, go_to_line,|, fullscreen, |, undo, redo, |, select_font, |, syntax_selection, |, change_smooth_selection, highlight, reset_highlight, |, help\" //new_document,\n";
  65. echo " ,plugins: \"charmap\"\n";
  66. echo " ,charmap_default: \"arrows\"\n";
  67. echo " });\n";
  68. echo "\n";
  69. echo " editAreaLoader.init({\n";
  70. echo " id: \"switch_cmd\" // id of the textarea to transform //, |, help\n";
  71. echo " ,start_highlight: false\n";
  72. echo " ,display: \"later\"\n";
  73. echo " ,font_size: \"8\"\n";
  74. echo " ,allow_toggle: true\n";
  75. echo " ,language: \"en\"\n";
  76. echo " ,syntax: \"php\"\n";
  77. echo " ,toolbar: \"search, go_to_line,|, fullscreen, |, undo, redo, |, select_font, |, syntax_selection, |, change_smooth_selection, highlight, reset_highlight, |, help\" //new_document,\n";
  78. echo " ,plugins: \"charmap\"\n";
  79. echo " ,charmap_default: \"arrows\"\n";
  80. echo " });\n";
  81. echo " </script>";
  82. //show the header
  83. echo "<div align='center'>";
  84. echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
  85. echo "<tr>\n";
  86. echo "<td colspan='2' align='left' nowrap=\"nowrap\"><b>Execute Command</b></td>\n";
  87. echo "</tr>\n";
  88. echo "<tr>\n";
  89. echo " <td align=\"left\" colspan='2'>\n";
  90. echo " Provides a conventient way to execute system, PHP, and switch commands.\n";
  91. echo " <br />\n";
  92. echo " <br />\n";
  93. echo " </td>\n";
  94. echo "</tr>\n";
  95. //show the result
  96. if (count($_POST)>0) {
  97. echo " <tr>\n";
  98. echo " <td colspan='2' align=\"left\">\n";
  99. //shell_cmd
  100. if (strlen($shell_cmd) > 0 && permission_exists('exec_command_line')) {
  101. echo "<b>$shell_cmd</b>\n";
  102. echo "<!--\n";
  103. $shell_result = shell_exec($shell_cmd);
  104. echo "-->\n";
  105. echo "<pre>";
  106. echo htmlentities($shell_result);
  107. echo "</pre>\n";
  108. }
  109. //php_cmd
  110. if (strlen($php_cmd) > 0 && permission_exists('exec_php_command')) {
  111. //echo "<b></b>\n";
  112. echo "<pre>";
  113. $php_result = eval($php_cmd);
  114. echo htmlentities($php_result);
  115. echo "</pre>\n";
  116. }
  117. //fs cmd
  118. if (strlen($switch_cmd) > 0 && permission_exists('exec_switch')) {
  119. echo "<b>$switch_cmd</b>\n";
  120. echo "<pre>";
  121. $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
  122. if ($fp) {
  123. $switch_result = event_socket_request($fp, 'api '.$switch_cmd);
  124. //$switch_result = eval($switch_cmd);
  125. echo htmlentities($switch_result);
  126. }
  127. echo "</pre>\n";
  128. }
  129. echo " <br />\n";
  130. echo " </td>\n";
  131. echo " </tr>";
  132. }
  133. //html form
  134. echo "<form method='post' name='frm' action=''>\n";
  135. if (permission_exists('exec_command_line')) {
  136. echo "<tr>\n";
  137. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  138. echo " Shell command:\n";
  139. echo "</td>\n";
  140. echo "<td class='vtable' align='left'>\n";
  141. echo " <textarea name='shell_cmd' id='shell_cmd' rows='2' class='txt' wrap='off'>$shell_cmd</textarea\n";
  142. echo " <br />\n";
  143. echo " System commands.\n";
  144. echo "</td>\n";
  145. echo "</tr>\n";
  146. }
  147. if (permission_exists('exec_php_command')) {
  148. echo "<tr>\n";
  149. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  150. echo " PHP command:\n";
  151. echo "</td>\n";
  152. echo "<td class='vtable' align='left'>\n";
  153. echo " <textarea name='php_cmd' id='php_cmd' rows='7' class='txt' wrap='off'>$php_cmd</textarea\n";
  154. echo " <br />\n";
  155. echo " Use the following link as a reference for PHP: <a href='http://php.net/manual/en/index.php' target='_blank'>PHP Manual</a>\n";
  156. echo "</td>\n";
  157. echo "</tr>\n";
  158. }
  159. if (permission_exists('exec_switch')) {
  160. echo "<tr>\n";
  161. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  162. echo " Switch Command:\n";
  163. echo "</td>\n";
  164. echo "<td class='vtable' align='left'>\n";
  165. echo " <textarea name='switch_cmd' id='switch_cmd' rows='2' class='txt' wrap='off'>$switch_cmd</textarea\n";
  166. echo " <br />\n";
  167. echo " For a list of the valid commands use: help\n";
  168. echo "</td>\n";
  169. echo "</tr>\n";
  170. }
  171. echo " <tr>\n";
  172. echo " <td colspan='2' align='right'>\n";
  173. echo " <input type='submit' name='submit' class='btn' value='Execute'>\n";
  174. echo " </td>\n";
  175. echo " </tr>";
  176. echo "</form>";
  177. echo "</table>";
  178. echo "</div>";
  179. //show the footer
  180. require_once "includes/footer.php";
  181. ?>