summaryrefslogtreecommitdiffstats
path: root/src/usr/local/www/diag_command.php
diff options
context:
space:
mode:
authorstilez <stilez@users.noreply.github.com>2017-05-27 13:49:30 +0100
committerGitHub <noreply@github.com>2017-05-27 13:49:30 +0100
commit1155cd631886c4814be6a1e42b0a441c80cf40e7 (patch)
tree0c01c0a6cef42da64402ab10333863b8d3fcff3e /src/usr/local/www/diag_command.php
parent8d80a771e32483112070ccee3d949dbbe558b064 (diff)
downloadpfsense-1155cd631886c4814be6a1e42b0a441c80cf40e7.zip
pfsense-1155cd631886c4814be6a1e42b0a441c80cf40e7.tar.gz
Various updates to PR
1) convert echo to print, and add infobox, as requested in PR comments 2) If no identifiable line number, say so 3) EVAL gives an error message format that wasn't picked up, it is now. Test case - enter as the code: eval("X"); 4) Warn that EVAL gives a "spurious" "error at line 1" as well, the real error is in the (...). See above test case for this. 5) Simplify translators' job a bit 6) Try to reduce errors in user code giving NOTICES (see PR comments). Start by defining a dir for user code (only) and putting code in it.
Diffstat (limited to 'src/usr/local/www/diag_command.php')
-rwxr-xr-xsrc/usr/local/www/diag_command.php38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/usr/local/www/diag_command.php b/src/usr/local/www/diag_command.php
index 0d8242b..6e4e78e 100755
--- a/src/usr/local/www/diag_command.php
+++ b/src/usr/local/www/diag_command.php
@@ -260,7 +260,8 @@ if ($_POST['submit'] == "EXEC" && !isBlank($_POST['txtCommand'])):?>
// This is intended to prevent bad code from breaking the GUI
if ($_POST['submit'] == "EXECPHP" && !isBlank($_POST['txtPHPCommand'])) {
- $tmpfile = tempnam("/tmp", "");
+ safe_mkdir($g[tmp_path_user_code]); //create if doesn't exist
+ $tmpfile = tempnam($g[tmp_path_user_code], "");
$phpcode = <<<END_FILE
<?php
require_once("/etc/inc/config.inc");
@@ -282,36 +283,36 @@ END_FILE;
puts('<div class="panel panel-success responsive"><div class="panel-heading"><h2 class="panel-title">PHP Response</h2></div>');
// 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:)`i", implode("\n", $output), $matches);
-
+ $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]
*/
- $errline = $matches[1] - $lineno_correction;
+ 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 .= '<br/>' . 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 <br> separated.
$syntax_output = explode("<br />", $syntax_output[1]);
- // Align line numbers right padded when building html
- $chars = strlen(count($syntax_output)) + 1;
+ $margin_layout = '%3s %' . strlen(count($syntax_output)) . 'd:';
for ($lineno = 1; $lineno < count($syntax_output) - $lineno_correction; $lineno++) {
- if ($lineno == $errline) {
- $lineno_prefix = "&gt;&gt;&gt;" . str_repeat('&nbsp;', $chars - strlen($lineno));
- } else {
- $lineno_prefix = str_repeat('&nbsp;', ($chars + 3) - strlen($lineno));
- }
- $html .= "<span style='color:black;backgroundcolor:lightgrey'><tt>" . $lineno_prefix . $lineno . ":</tt></span>&nbsp;&nbsp;{$syntax_output[$lineno + $lineno_correction - 1]}<br/>\n";
+ $margin = str_replace(' ', '&nbsp;', sprintf($margin_layout, ($lineno == $errline ? '&gt;&gt;&gt;' : ''), $lineno));
+ $html .= "<span style='color:black;backgroundcolor:lightgrey'><tt>{$margin}</tt></span>&nbsp;&nbsp;{$syntax_output[$lineno + $lineno_correction - 1]}<br/>\n";
}
- echo sprintf(gettext('Line %s appears to have generated an error, and has been highlighted. The full response is below.<br/>' .
- 'Note that the line number in the full PHP response will be %s lines too large.'), $errline, $lineno_correction);
- echo "<div style='margin:20px'><b>" . gettext("Error locator:") . "</b>\n";
- echo "<div id='errdiv' style='height:7em; width:60%; overflow:auto; white-space: nowrap; border:darkgrey solid 1px; margin-top: 20px'>\n";
- echo $html . "\n</div></div>\n";
+ print_info_box($errtext, 'danger');
+ print "<div style='margin:20px'><b>" . gettext("Error locator:") . "</b>\n";
+ print "<div id='errdiv' style='height:7em; width:60%; overflow:auto; white-space: nowrap; border:darkgrey solid 1px; margin-top: 20px'>\n";
+ print $html . "\n</div></div>\n";
}
$output = implode("\n", $output);
@@ -334,7 +335,6 @@ END_FILE;
});
//]]>
</script>
-
<?php
}
?>
OpenPOWER on IntegriCloud