exec.php 6.6 KB

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