)\ * * originally based on m0n0wall (http://m0n0.ch/wall) * Copyright (c) 2003-2004 Manuel Kasper . * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ ##|+PRIV ##|*IDENT=page-diagnostics-command ##|*NAME=Diagnostics: Command ##|*DESCR=Allow access to the 'Diagnostics: Command' page. ##|*WARN=standard-warning-root ##|*MATCH=diag_command.php* ##|-PRIV $allowautocomplete = true; require_once("guiconfig.inc"); if ($_POST['submit'] == "DOWNLOAD" && file_exists($_POST['dlPath'])) { session_cache_limiter('public'); $fd = fopen($_POST['dlPath'], "rb"); header("Content-Type: application/octet-stream"); header("Content-Length: " . filesize($_POST['dlPath'])); header("Content-Disposition: attachment; filename=\"" . trim(htmlentities(basename($_POST['dlPath']))) . "\""); if (isset($_SERVER['HTTPS'])) { header('Pragma: '); header('Cache-Control: '); } else { header("Pragma: private"); header("Cache-Control: private, must-revalidate"); } fpassthru($fd); exit; } else if ($_POST['submit'] == "UPLOAD" && is_uploaded_file($_FILES['ulfile']['tmp_name'])) { move_uploaded_file($_FILES['ulfile']['tmp_name'], $g["tmp_path"] . "/" . $_FILES['ulfile']['name']); $ulmsg = sprintf(gettext('Uploaded file to %s.'), $g["tmp_path"] . "/" . htmlentities($_FILES['ulfile']['name'])); } // Function: is Blank // Returns true or false depending on blankness of argument. function isBlank($arg) { return preg_match("/^\s*$/", $arg); } // Function: Puts // Put string, Ruby-style. function puts($arg) { echo "$arg\n"; } $pgtitle = array(gettext("Diagnostics"), gettext("Command Prompt")); include("head.inc"); ?>

&1', $output); $output = implode("\n", $output); print("
" . htmlspecialchars($output) . "
"); ?>






END_FILE; $lineno_correction = 6; // line numbering correction, this should be the number of lines added above, BEFORE the user's code file_put_contents($tmpfile, sprintf($phpcode, $_POST['txtPHPCommand'])); $output = $matches = array(); $retval = 0; exec("/usr/local/bin/php -d log_errors=off {$tmpfile}", $output, $retval); puts('

PHP Response

'); // Help user to find bad code line, if it gave an error $errmsg_found = preg_match("`error.*:.* (?:in|File:) {$tmpfile}(?:\(| on line |, Line: )(\d+)(?:, Message:|\).* eval\(\)'d code|$)`i", implode("\n", $output), $matches); if ($retval || $errmsg_found) { /* Trap failed code - test both retval and output message * Typical messages as at 2.3.x: * "Parse error: syntax error, ERR_DETAILS in FILE on line NN" * "PHP ERROR: Type: NN, File: FILE, Line: NN, Message: ERR_DETAILS" * "Parse error: syntax error, unexpected end of file in FILE(NN) : eval()'d code on line 1" [the number in (..) is the error line] */ if ($matches[1] > $lineno_correction) { $errline = $matches[1] - $lineno_correction; $errtext = sprintf(gettext('Line %s appears to have generated an error, and has been highlighted. The full response is below.'), $errline); } else { $errline = -1; $errtext = gettext('The code appears to have generated an error, but the line responsible cannot be identified. The full response is below.'); } $errtext .= '
' . sprintf(gettext('Note that the line number in the full PHP response will be %s lines too large. Nested code and eval() errors may incorrectly point to "line 1".'), $lineno_correction); $syntax_output = array(); $html = ""; exec("/usr/local/bin/php -s -d log_errors=off {$tmpfile}", $syntax_output); // Lines 0, 2 and 3 are CSS wrapper for the syntax highlighted code which is at line 1
separated. $syntax_output = explode("
", $syntax_output[1]); $margin_layout = '%3s %' . strlen(count($syntax_output)) . 'd:'; for ($lineno = 1; $lineno < count($syntax_output) - $lineno_correction; $lineno++) { $margin = str_replace(' ', ' ', sprintf($margin_layout, ($lineno == $errline ? '>>>' : ''), $lineno)); $html .= "{$margin}  {$syntax_output[$lineno + $lineno_correction - 1]}
\n"; } print_info_box($errtext, 'danger'); print "
" . gettext("Error locator:") . "\n"; print "
\n"; print $html . "\n
\n"; } $output = implode("\n", $output); print("
" . htmlspecialchars($output) . "
"); // echo eval($_POST['txtPHPCommand']); puts("
"); unlink($tmpfile); ?>


: print("Hello World!");