exec.php 6.8 KB

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