exec.php 6.7 KB

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