Report errors based on user preference. All the cases taken care of.
Signed-off-by: Dhananjay Nakrani <dhananjaynakrani@gmail.com>
This commit is contained in:
parent
8bfa0be157
commit
e74cd6ec1d
167
error_report.php
167
error_report.php
@ -10,63 +10,132 @@ require_once 'libraries/error_report.lib.php';
|
||||
|
||||
$response = PMA_Response::getInstance();
|
||||
|
||||
if (isset($_REQUEST['send_error_report'])
|
||||
&& $_REQUEST['send_error_report'] == true
|
||||
) {
|
||||
$server_response = PMA_sendErrorReport(PMA_getReportData());
|
||||
if (isset($_REQUEST['exception_type'])
|
||||
&& $_REQUEST['exception_type'] == 'js'
|
||||
) {
|
||||
if (isset($_REQUEST['send_error_report'])
|
||||
&& $_REQUEST['send_error_report'] == true
|
||||
) {
|
||||
$server_response = PMA_sendErrorReport(PMA_getReportData());
|
||||
|
||||
if ($server_response === false) {
|
||||
$success = false;
|
||||
} else {
|
||||
$decoded_response = json_decode($server_response, true);
|
||||
$success = !empty($decoded_response) ? $decoded_response["success"] : false;
|
||||
}
|
||||
if ($server_response === false) {
|
||||
$success = false;
|
||||
} else {
|
||||
$decoded_response = json_decode($server_response, true);
|
||||
$success = !empty($decoded_response) ? $decoded_response["success"] : false;
|
||||
}
|
||||
|
||||
/* Message to show to the user */
|
||||
if ($success) {
|
||||
if (isset($_REQUEST['automatic'])
|
||||
&& $_REQUEST['automatic'] === "true"
|
||||
) {
|
||||
/* Message to show to the user */
|
||||
if ($success) {
|
||||
if (isset($_REQUEST['automatic'])
|
||||
&& $_REQUEST['automatic'] === "true"
|
||||
) {
|
||||
$message = __(
|
||||
'An error has been detected and an error report has been '
|
||||
. 'automatically submitted based on your settings.'
|
||||
);
|
||||
} else {
|
||||
$message = __('Thank you for submitting this report.');
|
||||
}
|
||||
} else {
|
||||
$message = __(
|
||||
'An error has been detected and an error report has been '
|
||||
. 'automatically submitted based on your settings.'
|
||||
. 'generated but failed to be sent.'
|
||||
)
|
||||
. ' '
|
||||
. __(
|
||||
'If you experience any '
|
||||
. 'problems please submit a bug report manually.'
|
||||
);
|
||||
} else {
|
||||
$message = __('Thank you for submitting this report.');
|
||||
}
|
||||
$message .= ' ' . __('You may want to refresh the page.');
|
||||
|
||||
/* Create message object */
|
||||
if ($success) {
|
||||
$message = PMA_Message::notice($message);
|
||||
} else {
|
||||
$message = PMA_Message::error($message);
|
||||
}
|
||||
|
||||
/* Add message to JSON response */
|
||||
$response->addJSON('message', $message);
|
||||
|
||||
/* Persist always send settings */
|
||||
if (! isset($_REQUEST['automatic'])
|
||||
&& $_REQUEST['automatic'] !== "true"
|
||||
&& isset($_REQUEST['always_send'])
|
||||
&& $_REQUEST['always_send'] === "true"
|
||||
) {
|
||||
PMA_persistOption("SendErrorReports", "always", "ask");
|
||||
}
|
||||
} elseif (! empty($_REQUEST['get_settings'])) {
|
||||
$response->addJSON('report_setting', $GLOBALS['cfg']['SendErrorReports']);
|
||||
} else {
|
||||
$message = __(
|
||||
'An error has been detected and an error report has been '
|
||||
. 'generated but failed to be sent.'
|
||||
)
|
||||
. ' '
|
||||
. __(
|
||||
'If you experience any '
|
||||
. 'problems please submit a bug report manually.'
|
||||
);
|
||||
$response->addHTML(PMA_getErrorReportForm());
|
||||
}
|
||||
$message .= ' ' . __('You may want to refresh the page.');
|
||||
}elseif (isset($_REQUEST['exception_type'])
|
||||
&& $_REQUEST['exception_type'] == 'php'
|
||||
) {
|
||||
if (isset($_REQUEST['send_error_report'])
|
||||
&& $_REQUEST['send_error_report'] == '1'
|
||||
) {
|
||||
$reportData = PMA_getReportData('php');
|
||||
$server_response = PMA_sendErrorReport($reportData);
|
||||
if ($server_response === false) {
|
||||
$success = false;
|
||||
} else {
|
||||
$decoded_response = json_decode($server_response, true);
|
||||
$success = !empty($decoded_response) ? $decoded_response["success"] : false;
|
||||
}
|
||||
|
||||
if($GLOBALS['cfg']['SendErrorReports'] == 'ask'){
|
||||
if($success) {
|
||||
$errSubmitMsg = PMA_Message::error(
|
||||
__('Thank You for subitting error report!!')
|
||||
. __('Report has been succesfully submitted.')
|
||||
);
|
||||
} else {
|
||||
$errSubmitMsg = PMA_Message::error(
|
||||
__('Thank You for subitting error report!!')
|
||||
. '<br/>'
|
||||
. __(' Unfortunately submission failed.')
|
||||
. '<br/>'
|
||||
. __(' If you experience any problems please submit a bug report manually.')
|
||||
);
|
||||
}
|
||||
} elseif($GLOBALS['cfg']['SendErrorReports'] == 'always') {
|
||||
if($success) {
|
||||
$errSubmitMsg = PMA_Message::error(
|
||||
__(
|
||||
'An error has been detected on the server and an error report has been '
|
||||
. 'automatically submitted based on your settings.'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$errSubmitMsg = PMA_Message::error(
|
||||
__(
|
||||
'An error has been detected and an error report has been '
|
||||
. 'generated but failed to be sent.'
|
||||
)
|
||||
. '<br/>'
|
||||
. __('If you experience any problems please submit a bug report manually.')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* Create message object */
|
||||
if ($success) {
|
||||
$message = PMA_Message::notice($message);
|
||||
} else {
|
||||
$message = PMA_Message::error($message);
|
||||
}
|
||||
|
||||
/* Add message to JSON response */
|
||||
$response->addJSON('message', $message);
|
||||
|
||||
/* Persist always send settings */
|
||||
if (! isset($_REQUEST['automatic'])
|
||||
&& $_REQUEST['automatic'] !== "true"
|
||||
&& isset($_REQUEST['always_send'])
|
||||
&& $_REQUEST['always_send'] === "true"
|
||||
) {
|
||||
PMA_persistOption("SendErrorReports", "always", "ask");
|
||||
}
|
||||
} elseif (! empty($_REQUEST['get_settings'])) {
|
||||
$response->addJSON('report_setting', $GLOBALS['cfg']['SendErrorReports']);
|
||||
if($response->isAjax()) {
|
||||
$response->addJSON('_errSubmitMsg',$errSubmitMsg);
|
||||
} else {
|
||||
$jsCode = 'PMA_ajaxShowMessage("<div class=\"error\">'
|
||||
.$errSubmitMsg
|
||||
.'</div>", false);';
|
||||
$response->getFooter()->getScripts()->addCode($jsCode);
|
||||
}
|
||||
}
|
||||
// clear previous errors & save new ones.
|
||||
$GLOBALS['error_handler']->savePreviousErrors();
|
||||
} else {
|
||||
$response->addHTML(PMA_getErrorReportForm());
|
||||
die('Oops, something went wrong!!');
|
||||
}
|
||||
|
||||
require_once 'libraries/common_error_reporting.inc.php';
|
||||
@ -290,7 +290,10 @@ class PMA_Error_Handler
|
||||
public function getDispErrors()
|
||||
{
|
||||
$retval = '';
|
||||
if ($GLOBALS['cfg']['Error_Handler']['display']) {
|
||||
// display errors if SendErrorReports is set to 'ask'.
|
||||
if ($GLOBALS['cfg']['SendErrorReports'] != 'never'
|
||||
|| $GLOBALS['cfg']['Error_Handler']['display']
|
||||
) {
|
||||
foreach ($this->getErrors() as $error) {
|
||||
if ($error instanceof PMA_Error) {
|
||||
if (! $error->isDisplayed()) {
|
||||
@ -306,6 +309,27 @@ class PMA_Error_Handler
|
||||
} else {
|
||||
$retval .= $this->getDispUserErrors();
|
||||
}
|
||||
if($GLOBALS['cfg']['SendErrorReports'] == 'ask'){
|
||||
// add report button.
|
||||
$retval .= '<form method="post" action="error_report.php" id="pma_report_errors_form">'
|
||||
. '<input type="hidden" name="token" value="'
|
||||
. $_SESSION[' PMA_token ']
|
||||
. '"/>'
|
||||
. '<input type="hidden" name="exception_type" value="php"/>'
|
||||
. '<input type="hidden" name="send_error_report" value="1" />'
|
||||
. '<input type="submit" value="'
|
||||
. __('Report')
|
||||
. '" id="pma_report_errors" style="float: right; margin: 20px;">'
|
||||
. '</form>';
|
||||
|
||||
// add ignore buttons
|
||||
$retval .='<input type="submit" value="'.__('Ignore')
|
||||
.'" id="pma_ignore_errors" onclick="PMA_ignorePhpErrors(true)" '
|
||||
.'style="float: right; margin: 20px;">';
|
||||
$retval .='<input type="submit" value="'.__('Ignore All')
|
||||
.'" id="pma_ignore_all_errors" onclick="PMA_ignorePhpErrors(false)" '
|
||||
.'style="float: right; margin: 20px;">';
|
||||
}
|
||||
return $retval;
|
||||
}
|
||||
|
||||
@ -398,7 +422,9 @@ class PMA_Error_Handler
|
||||
*/
|
||||
public function countDisplayErrors()
|
||||
{
|
||||
if ($GLOBALS['cfg']['Error_Handler']['display']) {
|
||||
if ($GLOBALS['cfg']['SendErrorReports'] != 'never'
|
||||
|| $GLOBALS['cfg']['Error_Handler']['display']
|
||||
) {
|
||||
return $this->countErrors();
|
||||
} else {
|
||||
return $this->countUserErrors();
|
||||
@ -414,5 +440,17 @@ class PMA_Error_Handler
|
||||
{
|
||||
return (bool) $this->countDisplayErrors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes prevsiously stored errors in SESSION.
|
||||
* Saves current errors in session as previous errros.
|
||||
* Required to save current errors in case 'ask'
|
||||
*
|
||||
*/
|
||||
public function savePreviousErrors()
|
||||
{
|
||||
unset($_SESSION['prev_errors']);
|
||||
$_SESSION['prev_errors'] = $GLOBALS['error_handler']->getCurrentErrors();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@ -316,6 +316,9 @@ class PMA_Response
|
||||
if (strlen($errors)) {
|
||||
$this->addJSON('_errors', $errors);
|
||||
}
|
||||
$promptPhpErrors = ($GLOBALS['cfg']['SendErrorReports'] != 'never' || $GLOBALS['cfg']['Error_Handler']['display']);
|
||||
$this->addJSON('_promptPhpErrors', $promptPhpErrors);
|
||||
|
||||
if (empty($GLOBALS['error_message'])) {
|
||||
// set current db, table and sql query in the querywindow
|
||||
$query = '';
|
||||
|
||||
@ -13,50 +13,43 @@ if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/** if there were any errors currently write them to a log file.
|
||||
* Later it will be changed to submit them to the error reporting server.
|
||||
/**
|
||||
* if there were any errors then take appropriate actions based on user preferences.
|
||||
*/
|
||||
if($GLOBALS['error_handler']->hasErrors()) {
|
||||
// then log them in a local file.
|
||||
$path = "./pma_error_log.txt";
|
||||
$fp = fopen($path, "w");
|
||||
// Delete all the prev_errors in session & store new prev_errors in session
|
||||
$GLOBALS['error_handler']->savePreviousErrors();
|
||||
|
||||
// for each errors in the list
|
||||
foreach($GLOBALS['error_handler']->getCurrentErrors() as $errObj ) {
|
||||
/**
|
||||
* Following check is to avoid error reported by PMA_warnMissingExtension();
|
||||
*
|
||||
*/
|
||||
if ($errObj->getLine() && $errObj->getType()) {
|
||||
$str = "\n\n".$errObj->getFile() . "(#" . $errObj->getLine() . ")\n\t". $errObj->getTitle();
|
||||
// for stack trace
|
||||
// ------------------------------------------------------------------------------------------
|
||||
$backtrace = $errObj->getBacktrace();
|
||||
$error_str= "";
|
||||
foreach($backtrace as $i=>$stack_frame)
|
||||
{
|
||||
$error_str .= "\n \t\t\t Frame[".$i."]: \tfile:".$stack_frame["file"]."\tline:".$stack_frame["line"]."\tfunction:".$stack_frame["function"]."(";
|
||||
foreach($stack_frame["args"] as $j=>$arg)
|
||||
{
|
||||
if($j != 0)
|
||||
{
|
||||
$error_str .= ", ";
|
||||
}
|
||||
if($GLOBALS['cfg']['SendErrorReports'] == 'always'){
|
||||
//send the error reports directly
|
||||
|
||||
$_REQUEST['exception_type'] = 'php';
|
||||
$_REQUEST['send_error_report'] = '1';
|
||||
require_once('error_report.php');
|
||||
|
||||
// The errors are already sent. Just focus on errors division upon load event.
|
||||
$jsCode = '$("html, body").animate({scrollTop:$(document).height()}, "slow");';
|
||||
$response = PMA_Response::getInstance();
|
||||
$response->getFooter()->getScripts()->addCode($jsCode);
|
||||
}
|
||||
elseif($GLOBALS['cfg']['SendErrorReports'] == 'ask') {
|
||||
//ask user whether to submit errors or not.
|
||||
if($response->isAjax()) {
|
||||
// Send the errors in '_error' param. That is Already done in PMA_Response::_ajaxResponse().
|
||||
}
|
||||
else {
|
||||
// The errors are already sent. Just focus on errors division upon load event.
|
||||
$jsCode = 'PMA_ajaxShowMessage(PMA_messages["phpErrorsFound"], 2000);'
|
||||
. '$("html, body").animate({scrollTop:$(document).height()}, "slow");';
|
||||
|
||||
$response = PMA_Response::getInstance();
|
||||
$response->getFooter()->getScripts()->addCode($jsCode);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
//$GLOBALS['cfg']['SendErrorReports'] set to 'never'. Do not submit error reports.
|
||||
|
||||
$error_str .= "arg[".$j."] = ".$arg;
|
||||
}
|
||||
$error_str .= ")";
|
||||
|
||||
if($i >= 5) // MAX 5 of stack frames.
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------
|
||||
$retVal = fwrite ($fp , $str);
|
||||
$retVal = fwrite ($fp , $error_str);
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
?>
|
||||
|
||||
@ -27,7 +27,8 @@ if (is_readable('js/line_counts.php')) {
|
||||
/**
|
||||
* the url where to submit reports to
|
||||
*/
|
||||
define('SUBMISSION_URL', "http://reports.phpmyadmin.net/incidents/create");
|
||||
// define('SUBMISSION_URL', "http://reports.phpmyadmin.net/incidents/create");
|
||||
define('SUBMISSION_URL', "http://127.0.0.1/error-reporting-server/incidents/create");
|
||||
|
||||
/**
|
||||
* returns the pretty printed error report data collected from the
|
||||
@ -54,35 +55,64 @@ function PMA_getPrettyReportData()
|
||||
*
|
||||
* @return Array the report
|
||||
*/
|
||||
function PMA_getReportData()
|
||||
function PMA_getReportData($exception_type = 'js')
|
||||
{
|
||||
if (empty($_REQUEST['exception'])) {
|
||||
return array();
|
||||
}
|
||||
$exception = $_REQUEST['exception'];
|
||||
$exception["stack"] = PMA_translateStacktrace($exception["stack"]);
|
||||
List($uri, $script_name) = PMA_sanitizeUrl($exception["url"]);
|
||||
$exception["uri"] = $uri;
|
||||
unset($exception["url"]);
|
||||
// common params for both, php & js execptions
|
||||
$report = array(
|
||||
"exception" => $exception,
|
||||
"script_name" => $script_name,
|
||||
"pma_version" => PMA_VERSION,
|
||||
"browser_name" => PMA_USR_BROWSER_AGENT,
|
||||
"browser_version" => PMA_USR_BROWSER_VER,
|
||||
"user_os" => PMA_USR_OS,
|
||||
"server_software" => $_SERVER['SERVER_SOFTWARE'],
|
||||
"user_agent_string" => $_SERVER['HTTP_USER_AGENT'],
|
||||
"locale" => $_COOKIE['pma_lang'],
|
||||
"configuration_storage" =>
|
||||
empty($GLOBALS['cfg']['Servers'][1]['pmadb']) ? "disabled" :
|
||||
"enabled",
|
||||
"php_version" => phpversion(),
|
||||
"microhistory" => $_REQUEST['microhistory'],
|
||||
);
|
||||
"pma_version" => PMA_VERSION,
|
||||
"browser_name" => PMA_USR_BROWSER_AGENT,
|
||||
"browser_version" => PMA_USR_BROWSER_VER,
|
||||
"user_os" => PMA_USR_OS,
|
||||
"server_software" => $_SERVER['SERVER_SOFTWARE'],
|
||||
"user_agent_string" => $_SERVER['HTTP_USER_AGENT'],
|
||||
"locale" => $_COOKIE['pma_lang'],
|
||||
"configuration_storage" =>
|
||||
empty($GLOBALS['cfg']['Servers'][1]['pmadb']) ? "disabled" :
|
||||
"enabled",
|
||||
"php_version" => phpversion()
|
||||
);
|
||||
|
||||
if (! empty($_REQUEST['description'])) {
|
||||
$report['steps'] = $_REQUEST['description'];
|
||||
if($exception_type == 'js') {
|
||||
if (empty($_REQUEST['exception'])) {
|
||||
return '';
|
||||
}
|
||||
$exception = $_REQUEST['exception'];
|
||||
$exception["stack"] = PMA_translateStacktrace($exception["stack"]);
|
||||
List($uri, $script_name) = PMA_sanitizeUrl($exception["url"]);
|
||||
$exception["uri"] = $uri;
|
||||
unset($exception["url"]);
|
||||
|
||||
$report ["exception_type"] = 'js';
|
||||
$report ["exception"] = $exception;
|
||||
$report ["script_name"] = $script_name;
|
||||
$report ["microhistory"] = $_REQUEST['microhistory'];
|
||||
);
|
||||
|
||||
if (! empty($_REQUEST['description'])) {
|
||||
$report['steps'] = $_REQUEST['description'];
|
||||
}
|
||||
}
|
||||
elseif($exception_type == 'php'){
|
||||
$errors = array();
|
||||
// create php error report
|
||||
$i=0;
|
||||
foreach($_SESSION['prev_errors'] as $errorObj ) {
|
||||
if ($errorObj->getLine() && $errorObj->getType() && $errorObj->getNumber() != E_USER_WARNING) {
|
||||
$errors[$i++] = array(
|
||||
"lineNum" => $errorObj->getLine(),
|
||||
"file" => $errorObj->getFile(),
|
||||
"type" => $errorObj->getType(),
|
||||
"msg" => $errorObj->getMessage(),
|
||||
"stackTrace" => $errorObj->getBacktraceDisplay(5)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
$report ["exception_type"] = 'php';
|
||||
$report["errors"] = $errors;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $report;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user