exec.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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-2019
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. James Rose <[email protected]>
  21. */
  22. //includes
  23. include "root.php";
  24. require_once "resources/require.php";
  25. require_once "resources/check_auth.php";
  26. //permissions
  27. if (permission_exists('exec_view')) {
  28. //access granted
  29. }
  30. else {
  31. echo "access denied";
  32. exit;
  33. }
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. // load editor preferences/defaults
  38. $setting_size = ($_SESSION["editor"]["font_size"]["text"] != '') ? $_SESSION["editor"]["font_size"]["text"] : '12px';
  39. $setting_theme = ($_SESSION["editor"]["theme"]["text"] != '') ? $_SESSION["editor"]["theme"]["text"] : 'cobalt';
  40. $setting_invisibles = ($_SESSION["editor"]["invisibles"]["boolean"] != '') ? $_SESSION["editor"]["invisibles"]["boolean"] : 'false';
  41. $setting_indenting = ($_SESSION["editor"]["indent_guides"]["boolean"] != '') ? $_SESSION["editor"]["indent_guides"]["boolean"] : 'false';
  42. $setting_numbering = ($_SESSION["editor"]["line_numbers"]["boolean"] != '') ? $_SESSION["editor"]["line_numbers"]["boolean"] : 'true';
  43. $setting_preview = ($_SESSION["editor"]["live_preview"]["boolean"] != '') ? $_SESSION["editor"]["live_preview"]["boolean"] : 'true';
  44. //get the html values and set them as variables
  45. $handler = ($_REQUEST["handler"] != '') ? trim($_REQUEST["handler"]) : ((permission_exists('exec_switch')) ? 'switch' : null);
  46. $code = trim($_POST["code"]);
  47. $command = trim($_POST["command"]);
  48. //check the captcha
  49. $command_authorized = false;
  50. if (strlen($code) > 0) {
  51. if (strtolower($_SESSION['captcha']) == strtolower($code)) {
  52. $command_authorized = true;
  53. }
  54. }
  55. //set editor moder
  56. switch ($handler) {
  57. case 'php': $mode = 'php'; break;
  58. case 'sql': $mode = 'sql'; break;
  59. default: $mode = 'text';
  60. }
  61. //show the header
  62. require_once "resources/header.php";
  63. $document['title'] = $text['title-command'];
  64. //pdo database connection
  65. if (permission_exists('exec_sql')) {
  66. require_once "sql_query_pdo.php";
  67. }
  68. //scripts and styles
  69. ?>
  70. <script language="JavaScript" type="text/javascript">
  71. function submit_check() {
  72. document.getElementById('command').value = editor.getSession().getValue();
  73. if (document.getElementById('mode').value == 'sql') {
  74. $('#frm').prop('target', 'iframe').prop('action', 'sql_query_result.php?code='+ document.getElementById('code').value);
  75. $('#sql_response').show();
  76. }
  77. else {
  78. if (document.getElementById('command').value == '') {
  79. focus_editor();
  80. return false;
  81. }
  82. $('#frm').prop('target', '').prop('action', '');
  83. }
  84. return true;
  85. }
  86. function toggle_option(opt) {
  87. switch (opt) {
  88. case 'numbering': toggle_option_do('showLineNumbers'); toggle_option_do('fadeFoldWidgets'); break;
  89. case 'invisibles': toggle_option_do('showInvisibles'); break;
  90. case 'indenting': toggle_option_do('displayIndentGuides'); break;
  91. }
  92. focus_editor();
  93. }
  94. function toggle_option_do(opt_name) {
  95. var opt_val = editor.getOption(opt_name);
  96. editor.setOption(opt_name, ((opt_val) ? false : true));
  97. }
  98. function insert_clip(before, after) {
  99. var selected_text = editor.session.getTextRange(editor.getSelectionRange());
  100. editor.insert(before + selected_text + after);
  101. focus_editor();
  102. }
  103. function focus_editor() {
  104. editor.focus();
  105. }
  106. function set_handler(handler) {
  107. switch (handler) {
  108. <?php if (permission_exists('exec_switch')) { ?>
  109. case 'switch':
  110. document.getElementById('description').innerHTML = "<?php echo $text['description-switch'];?>";
  111. editor.getSession().setMode('ace/mode/text');
  112. $('#mode option[value=text]').prop('selected',true);
  113. <?php if (permission_exists('exec_sql')) { ?>
  114. $('.sql_controls').hide();
  115. document.getElementById('sql_type').selectedIndex = 0;
  116. document.getElementById('table_name').selectedIndex = 0;
  117. $('#iframe').prop('src','');
  118. $('#sql_response').hide();
  119. <?php } ?>
  120. $('#response').show();
  121. break;
  122. <?php } ?>
  123. <?php if (permission_exists('exec_php')) { ?>
  124. case 'php':
  125. document.getElementById('description').innerHTML = "<?php echo $text['description-php'];?>";
  126. editor.getSession().setMode({path:'ace/mode/php', inline:true}); //highlight without opening tag
  127. $('#mode option[value=php]').prop('selected',true);
  128. <?php if (permission_exists('exec_sql')) { ?>
  129. $('.sql_controls').hide();
  130. document.getElementById('sql_type').selectedIndex = 0;
  131. document.getElementById('table_name').selectedIndex = 0;
  132. $('#iframe').prop('src','');
  133. $('#sql_response').hide();
  134. <?php } ?>
  135. $('#response').show();
  136. break;
  137. <?php } ?>
  138. <?php if (permission_exists('exec_command')) { ?>
  139. case 'shell':
  140. document.getElementById('description').innerHTML = "<?php echo $text['description-shell'];?>";
  141. editor.getSession().setMode('ace/mode/text');
  142. $('#mode option[value=text]').prop('selected',true);
  143. <?php if (permission_exists('exec_sql')) { ?>
  144. $('.sql_controls').hide();
  145. document.getElementById('sql_type').selectedIndex = 0;
  146. document.getElementById('table_name').selectedIndex = 0;
  147. $('#iframe').prop('src','');
  148. $('#sql_response').hide();
  149. <?php } ?>
  150. $('#response').show();
  151. break;
  152. <?php } ?>
  153. <?php if (permission_exists('exec_sql')) { ?>
  154. case 'sql':
  155. document.getElementById('description').innerHTML = "<?php echo $text['description-sql'];?>";
  156. editor.getSession().setMode('ace/mode/sql');
  157. $('#mode option[value=sql]').prop('selected',true);
  158. $('.sql_controls').show();
  159. $('#response').hide();
  160. break;
  161. <?php } ?>
  162. default:
  163. break;
  164. }
  165. focus_editor();
  166. }
  167. function reset_editor() {
  168. editor.getSession().setValue('');
  169. $('#command').val('');
  170. $('#response').hide();
  171. <?php if (permission_exists('exec_sql')) { ?>
  172. $('#iframe').prop('src','');
  173. $('#sql_response').hide();
  174. <?php } ?>
  175. focus_editor();
  176. }
  177. </script>
  178. <style>
  179. img.control {
  180. cursor: pointer;
  181. width: auto;
  182. height: 23px;
  183. border: none;
  184. opacity: 0.5;
  185. }
  186. img.control:hover {
  187. opacity: 1.0;
  188. }
  189. div#editor {
  190. box-shadow: 0 3px 10px #333;
  191. text-align: left;
  192. width: 100%;
  193. height: calc(100% - 30px);
  194. font-size: 12px;
  195. }
  196. </style>
  197. <?php
  198. //gnerate the captcha image
  199. $_SESSION['captcha'] = generate_password(7, 2);
  200. $captcha = new captcha;
  201. $captcha->code = $_SESSION['captcha'];
  202. $image_base64 = $captcha->image_base64();
  203. //show the header
  204. echo "<form method='post' name='frm' id='frm' action='exec.php' style='margin: 0;' onsubmit='return submit_check();'>\n";
  205. echo "<table cellpadding='0' cellspacing='0' border='0' width='100%'>";
  206. echo " <tr>";
  207. echo " <td valign='top' align='left' width='50%'>";
  208. echo " <b>".$text['label-execute']."</b>\n";
  209. echo " </td>";
  210. echo " <td valign='top' align='right' nowrap='nowrap'>";
  211. //add the captcha
  212. echo " <img src=\"data:image/png;base64, ".$image_base64."\" /><input type='text' class='txt' style='width: 150px; margin-left: 15px;' name='code' id='code' value=''>\n";
  213. echo " &nbsp; &nbsp; &nbsp;\n";
  214. if (permission_exists('exec_switch') || permission_exists('exec_php') || permission_exists('exec_command') || permission_exists('exec_sql')) {
  215. echo " <select name='handler' id='handler' class='formfld' style='width:100px;' onchange=\"handler=this.value;set_handler(this.value);\">\n";
  216. if (permission_exists('exec_switch')) { echo "<option value='switch' ".(($handler == 'switch') ? "selected='selected'" : null).">".$text['label-switch']."</option>\n"; }
  217. if (permission_exists('exec_php')) { echo "<option value='php' ".(($handler == 'php') ? "selected='selected'" : null).">".$text['label-php']."</option>\n"; }
  218. if (permission_exists('exec_command')) { echo "<option value='shell' ".(($handler == 'shell') ? "selected='selected'" : null).">".$text['label-shell']."</option>\n"; }
  219. if (permission_exists('exec_sql')) { echo "<option value='sql' ".(($handler == 'sql') ? "selected='selected'" : null).">".$text['label-sql']."</option>\n"; }
  220. echo " </select>\n";
  221. }
  222. //sql controls
  223. if (permission_exists('exec_sql')) {
  224. echo " <span class='sql_controls' ".(($handler != 'sql') ? "style='display: none;'" : null).">";
  225. //echo " ".$text['label-table']."<br />";
  226. echo " <select name='table_name' id='table_name' class='formfld'>\n";
  227. echo " <option value=''></option>\n";
  228. switch ($db_type) {
  229. case 'sqlite': $sql = "select name from sqlite_master where type='table' order by name;"; break;
  230. case 'pgsql': $sql = "select table_name as name from information_schema.tables where table_schema='public' and table_type='BASE TABLE' order by table_name"; break;
  231. case 'mysql': $sql = "show tables"; break;
  232. }
  233. $prep_statement = $db->prepare(check_sql($sql));
  234. $prep_statement->execute();
  235. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  236. foreach ($result as &$row) {
  237. $row = array_values($row);
  238. echo " <option value='".$row[0]."'>".$row[0]."</option>\n";
  239. }
  240. echo " </select>\n";
  241. //echo " <br /><br />\n";
  242. //echo " ".$text['label-result_type']."<br />";
  243. echo " <select name='sql_type' id='sql_type' class='formfld'>\n";
  244. echo " <option value=''>".$text['option-result_type_view']."</option>\n";
  245. echo " <option value='csv'>".$text['option-result_type_csv']."</option>\n";
  246. echo " <option value='inserts'>".$text['option-result_type_insert']."</option>\n";
  247. echo " </select>\n";
  248. echo " </span>";
  249. }
  250. echo " <input type='button' class='btn' style='margin-top: 0px;' title=\"".$text['button-execute']." [Ctrl+Enter]\" value=\" ".$text['button-execute']." \" onclick=\"$('form#frm').submit();\">";
  251. echo " <input type='button' class='btn' style='margin-top: 0px;' title=\"\" value=\" ".$text['button-reset']." \" onclick=\"reset_editor();\">";
  252. if (permission_exists('exec_sql')) {
  253. echo " <span class='sql_controls' ".(($handler != 'sql') ? "style='display: none;'" : null).">";
  254. //echo " <input type='button' class='btn' alt='".$text['button-select_database']."' onclick=\"document.location.href='sql_query_db.php'\" value='".$text['button-select_database']."'>\n";
  255. if (permission_exists('exec_sql_backup')) {
  256. echo " <input type='button' class='btn' alt='".$text['button-backup']."' onclick=\"document.location.href='sql_backup.php".((strlen($_REQUEST['id']) > 0) ? "?id=".$_REQUEST['id'] : null)."'\" value='".$text['button-backup']."'>\n";
  257. }
  258. echo " </span>";
  259. }
  260. echo " </td>";
  261. echo " </tr>";
  262. echo " <tr><td colspan='2'>\n";
  263. echo $text['description-execute']."\n";
  264. echo " </tr>\n";
  265. echo "</table>";
  266. echo "<br>";
  267. //html form
  268. echo "<input type='hidden' name='id' value='".$_REQUEST['id']."'>\n"; //sql db id
  269. echo "<textarea name='command' id='command' style='display: none;'></textarea>";
  270. echo "<table cellpadding='0' cellspacing='0' border='0' style='width: 100%;'>\n";
  271. echo " <tr>";
  272. echo " <td style='width: 210px;' valign='top' nowrap>";
  273. echo " <table cellpadding='0' cellspacing='0' border='0' width='100%' height='100%'>";
  274. if (permission_exists('script_editor_view') && file_exists($_SERVER["PROJECT_ROOT"]."/app/edit/")) {
  275. echo " <tr>";
  276. echo " <td valign='top' height='100%'>";
  277. echo " <iframe id='clip_list' src='".PROJECT_PATH."/app/edit/cliplist.php' style='border: none; border-top: 1px solid #ccc; border-bottom: 1px solid #ccc; height: calc(100% - 2px); width: calc(100% - 15px);'></iframe>\n";
  278. echo " </td>";
  279. echo " </tr>";
  280. }
  281. echo " </table>";
  282. echo " </td>";
  283. echo " <td valign='top' style='height: 300px;'>"
  284. ?>
  285. <table cellpadding='0' cellspacing='0' border='0' style='width: 100%;'>
  286. <tr>
  287. <td valign='middle' style='padding: 0 6px;' width='100%'><span id='description'><?php echo $text['description-'.$handler]; ?></span></td>
  288. <td valign='middle' style='padding: 0;'><img src='resources/images/blank.gif' style='width: 1px; height: 30px; border: none;'></td>
  289. <td valign='middle' style='padding-left: 6px;'><img src='resources/images/icon_numbering.png' title='Toggle Line Numbers' class='control' onclick="toggle_option('numbering');"></td>
  290. <td valign='middle' style='padding-left: 6px;'><img src='resources/images/icon_invisibles.png' title='Toggle Invisibles' class='control' onclick="toggle_option('invisibles');"></td>
  291. <td valign='middle' style='padding-left: 6px;'><img src='resources/images/icon_indenting.png' title='Toggle Indent Guides' class='control' onclick="toggle_option('indenting');"></td>
  292. <!--<td valign='middle' style='padding-left: 6px;'><img src='resources/images/icon_replace.png' title='Show Find/Replace [Ctrl+H]' class='control' onclick="editor.execCommand('replace');"></td>-->
  293. <td valign='middle' style='padding-left: 6px;'><img src='resources/images/icon_goto.png' title='Show Go To Line' class='control' onclick="editor.execCommand('gotoline');"></td>
  294. <td valign='middle' style='padding-left: 10px;'>
  295. <select id='mode' style='height: 23px;' onchange="editor.getSession().setMode((this.options[this.selectedIndex].value == 'php') ? {path:'ace/mode/php', inline:true} : 'ace/mode/' + this.options[this.selectedIndex].value); focus_editor();">
  296. <?php
  297. $modes['php'] = 'PHP';
  298. $modes['css'] = 'CSS';
  299. $modes['html'] = 'HTML';
  300. $modes['javascript'] = 'JS';
  301. $modes['json'] = 'JSON';
  302. $modes['ini'] = 'Conf';
  303. $modes['lua'] = 'Lua';
  304. $modes['text'] = 'Text';
  305. $modes['xml'] = 'XML';
  306. $modes['sql'] = 'SQL';
  307. foreach ($modes as $value => $label) {
  308. if ($setting_preview == 'true') {
  309. $preview = "onmouseover=\"editor.getSession().setMode(".(($value == 'php') ? "{path:'ace/mode/php', inline:true}" : "'ace/mode/' + this.value").");\"";
  310. }
  311. $selected = ($value == $mode) ? 'selected' : null;
  312. echo "<option value='".$value."' ".$selected." ".$preview.">".$label."</option>\n";
  313. }
  314. ?>
  315. </select>
  316. </td>
  317. <td valign='middle' style='padding-left: 4px;'>
  318. <select id='size' style='height: 23px;' onchange="document.getElementById('editor').style.fontSize = this.options[this.selectedIndex].value; focus_editor();">
  319. <?php
  320. $sizes = explode(',','9px,10px,11px,12px,14px,16px,18px,20px');
  321. $preview = ($setting_preview == 'true') ? "onmouseover=\"document.getElementById('editor').style.fontSize = this.value;\"" : null;
  322. if (!in_array($setting_size, $sizes)) {
  323. echo "<option value='".$setting_size."' ".$preview.">".$setting_size."</option>\n";
  324. echo "<option value='' disabled='disabled'></option>\n";
  325. }
  326. foreach ($sizes as $size) {
  327. $selected = ($size == $setting_size) ? 'selected' : null;
  328. echo "<option value='".$size."' ".$selected." ".$preview.">".$size."</option>\n";
  329. }
  330. ?>
  331. </select>
  332. </td>
  333. <td valign='middle' style='padding-left: 4px; padding-right: 0px;'>
  334. <select id='theme' style='height: 23px;' onchange="editor.setTheme('ace/theme/' + this.options[this.selectedIndex].value); focus_editor();">
  335. <?php
  336. $themes['Bright']['chrome']= 'Chrome';
  337. $themes['Bright']['clouds']= 'Clouds';
  338. $themes['Bright']['crimson_editor']= 'Crimson Editor';
  339. $themes['Bright']['dawn']= 'Dawn';
  340. $themes['Bright']['dreamweaver']= 'Dreamweaver';
  341. $themes['Bright']['eclipse']= 'Eclipse';
  342. $themes['Bright']['github']= 'GitHub';
  343. $themes['Bright']['iplastic']= 'IPlastic';
  344. $themes['Bright']['solarized_light']= 'Solarized Light';
  345. $themes['Bright']['textmate']= 'TextMate';
  346. $themes['Bright']['tomorrow']= 'Tomorrow';
  347. $themes['Bright']['xcode']= 'XCode';
  348. $themes['Bright']['kuroir']= 'Kuroir';
  349. $themes['Bright']['katzenmilch']= 'KatzenMilch';
  350. $themes['Bright']['sqlserver']= 'SQL Server';
  351. $themes['Dark']['ambiance']= 'Ambiance';
  352. $themes['Dark']['chaos']= 'Chaos';
  353. $themes['Dark']['clouds_midnight']= 'Clouds Midnight';
  354. $themes['Dark']['cobalt']= 'Cobalt';
  355. $themes['Dark']['idle_fingers']= 'idle Fingers';
  356. $themes['Dark']['kr_theme']= 'krTheme';
  357. $themes['Dark']['merbivore']= 'Merbivore';
  358. $themes['Dark']['merbivore_soft']= 'Merbivore Soft';
  359. $themes['Dark']['mono_industrial']= 'Mono Industrial';
  360. $themes['Dark']['monokai']= 'Monokai';
  361. $themes['Dark']['pastel_on_dark']= 'Pastel on dark';
  362. $themes['Dark']['solarized_dark']= 'Solarized Dark';
  363. $themes['Dark']['terminal']= 'Terminal';
  364. $themes['Dark']['tomorrow_night']= 'Tomorrow Night';
  365. $themes['Dark']['tomorrow_night_blue']= 'Tomorrow Night Blue';
  366. $themes['Dark']['tomorrow_night_bright']= 'Tomorrow Night Bright';
  367. $themes['Dark']['tomorrow_night_eighties']= 'Tomorrow Night 80s';
  368. $themes['Dark']['twilight']= 'Twilight';
  369. $themes['Dark']['vibrant_ink']= 'Vibrant Ink';
  370. $preview = ($setting_preview == 'true') ? "onmouseover=\"editor.setTheme('ace/theme/' + this.value);\"" : null;
  371. foreach ($themes as $optgroup => $theme) {
  372. echo "<optgroup label='".$optgroup."'>\n";
  373. foreach ($theme as $value => $label) {
  374. $selected = (strtolower($label) == strtolower($setting_theme)) ? 'selected' : null;
  375. echo "<option value='".$value."' ".$selected." ".$preview.">".$label."</option>\n";
  376. }
  377. echo "</optgroup>\n";
  378. }
  379. ?>
  380. </select>
  381. </td>
  382. </tr>
  383. </table>
  384. <div id='editor'><?php echo htmlentities($command); ?></div>
  385. <?php
  386. echo " </td>";
  387. echo " </tr>\n";
  388. echo "</table>";
  389. echo "</form>";
  390. echo "<br /><br />";
  391. ?>
  392. <script type="text/javascript" src="<?php echo PROJECT_PATH; ?>/resources/ace/ace.js" charset="utf-8"></script>
  393. <script type="text/javascript">
  394. //load ace editor
  395. var editor = ace.edit("editor");
  396. editor.setOptions({
  397. mode: 'ace/mode/<?php echo $mode;?>',
  398. theme: 'ace/theme/'+document.getElementById('theme').options[document.getElementById('theme').selectedIndex].value,
  399. selectionStyle: 'text',
  400. cursorStyle: 'smooth',
  401. showInvisibles: <?php echo $setting_invisibles;?>,
  402. displayIndentGuides: <?php echo $setting_indenting;?>,
  403. showLineNumbers: <?php echo $setting_numbering;?>,
  404. showGutter: true,
  405. scrollPastEnd: true,
  406. fadeFoldWidgets: <?php echo $setting_numbering;?>,
  407. showPrintMargin: false,
  408. highlightGutterLine: false,
  409. useSoftTabs: false
  410. });
  411. <?php if ($mode == 'php') { ?>
  412. editor.getSession().setMode({path:'ace/mode/php', inline:true});
  413. <?php } ?>
  414. document.getElementById('editor').style.fontSize='<?php echo $setting_size;?>';
  415. focus_editor();
  416. //keyboard shortcut to execute command
  417. <?php key_press('ctrl+enter', 'down', 'window', null, null, "$('form#frm').submit();", false); ?>
  418. //remove certain keyboard shortcuts
  419. editor.commands.bindKey("Ctrl-T", null); //disable transpose letters - prefer new browser tab
  420. editor.commands.bindKey("Ctrl-F", null); //disable find - control broken with bootstrap
  421. editor.commands.bindKey("Ctrl-H", null); //disable replace - control broken with bootstrap
  422. </script>
  423. <?php
  424. //show the result
  425. if (is_array($_POST)) {
  426. if ($command != '') {
  427. $result = '';
  428. switch ($handler) {
  429. case 'shell':
  430. if (permission_exists('exec_command') && $command_authorized) {
  431. $result = htmlentities(shell_exec($command . " 2>&1"));
  432. }
  433. break;
  434. case 'php':
  435. if (permission_exists('exec_php') && $command_authorized) {
  436. ob_start();
  437. eval($command);
  438. $result = ob_get_contents();
  439. ob_end_clean();
  440. }
  441. break;
  442. case 'switch':
  443. if (permission_exists('exec_switch') && $command_authorized) {
  444. $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
  445. if ($fp) {
  446. $result = event_socket_request($fp, 'api '.$command);
  447. $result = htmlspecialchars(utf8_encode($result), ENT_QUOTES);
  448. }
  449. }
  450. break;
  451. }
  452. if ($result != '') {
  453. echo "<span id='response'>";
  454. echo "<b>".$text['label-response']."</b>\n";
  455. echo "<br /><br />\n";
  456. echo ($handler == 'switch') ? "<textarea style='width: 100%; height: 450px; font-family: monospace; padding: 15px;' wrap='off'>".$result."</textarea>\n" : "<pre>".$result."</pre>";
  457. echo "</span>";
  458. }
  459. }
  460. }
  461. //sql result
  462. if (permission_exists('exec_sql')) {
  463. echo "<span id='sql_response' style='display: none;'>";
  464. echo "<b>".$text['label-results']."</b>\n";
  465. echo "<br /><br />\n";
  466. echo "<iframe name='iframe' id='iframe' style='width: calc(100% - 3px); height: 500px; background-color: #fff; border: 1px solid #c0c0c0;'></iframe>\n";
  467. echo "</span>";
  468. }
  469. //show the footer
  470. require_once "resources/footer.php";
  471. ?>