1 | <?php |
||
2 | /* vim: set expandtab sw=4 ts=4 sts=4: */ |
||
3 | /** |
||
4 | * Handle error report submission |
||
5 | * |
||
6 | * @package PhpMyAdmin |
||
7 | */ |
||
8 | declare(strict_types=1); |
||
9 | |||
10 | use PhpMyAdmin\ErrorReport; |
||
11 | use PhpMyAdmin\Message; |
||
12 | use PhpMyAdmin\Response; |
||
13 | use PhpMyAdmin\UserPreferences; |
||
14 | use PhpMyAdmin\Utils\HttpRequest; |
||
0 ignored issues
–
show
|
|||
15 | |||
16 | require_once 'libraries/common.inc.php'; |
||
17 | |||
18 | if (!isset($_REQUEST['exception_type']) |
||
19 | || !in_array($_REQUEST['exception_type'], ['js', 'php']) |
||
20 | ) { |
||
21 | die('Oops, something went wrong!!'); |
||
22 | } |
||
23 | |||
24 | $response = Response::getInstance(); |
||
25 | |||
26 | $errorReport = new ErrorReport(new HttpRequest()); |
||
27 | |||
28 | if (isset($_REQUEST['send_error_report']) |
||
29 | && ($_REQUEST['send_error_report'] == true |
||
30 | || $_REQUEST['send_error_report'] == '1') |
||
31 | ) { |
||
32 | if ($_REQUEST['exception_type'] == 'php') { |
||
33 | /** |
||
34 | * Prevent infinite error submission. |
||
35 | * Happens in case error submissions fails. |
||
36 | * If reporting is done in some time interval, |
||
37 | * just clear them & clear json data too. |
||
38 | */ |
||
39 | if (isset($_SESSION['prev_error_subm_time']) |
||
40 | && isset($_SESSION['error_subm_count']) |
||
41 | && $_SESSION['error_subm_count'] >= 3 |
||
42 | && ($_SESSION['prev_error_subm_time'] - time()) <= 3000 |
||
43 | ) { |
||
44 | $_SESSION['error_subm_count'] = 0; |
||
45 | $_SESSION['prev_errors'] = ''; |
||
46 | $response->addJSON('_stopErrorReportLoop', '1'); |
||
47 | } else { |
||
48 | $_SESSION['prev_error_subm_time'] = time(); |
||
49 | $_SESSION['error_subm_count'] = ( |
||
50 | (isset($_SESSION['error_subm_count'])) |
||
51 | ? ($_SESSION['error_subm_count'] + 1) |
||
52 | : (0) |
||
53 | ); |
||
54 | } |
||
55 | } |
||
56 | $reportData = $errorReport->getData($_REQUEST['exception_type']); |
||
57 | // report if and only if there were 'actual' errors. |
||
58 | if (count($reportData) > 0) { |
||
59 | $server_response = $errorReport->send($reportData); |
||
60 | if ($server_response === false) { |
||
0 ignored issues
–
show
|
|||
61 | $success = false; |
||
62 | } else { |
||
63 | $decoded_response = json_decode($server_response, true); |
||
64 | $success = !empty($decoded_response) ? |
||
65 | $decoded_response["success"] : false; |
||
66 | } |
||
67 | |||
68 | /* Message to show to the user */ |
||
69 | if ($success) { |
||
70 | if ((isset($_REQUEST['automatic']) |
||
71 | && $_REQUEST['automatic'] === "true") |
||
72 | || $GLOBALS['cfg']['SendErrorReports'] == 'always' |
||
73 | ) { |
||
74 | $msg = __( |
||
75 | 'An error has been detected and an error report has been ' |
||
76 | . 'automatically submitted based on your settings.' |
||
77 | ); |
||
78 | } else { |
||
79 | $msg = __('Thank you for submitting this report.'); |
||
80 | } |
||
81 | } else { |
||
82 | $msg = __( |
||
83 | 'An error has been detected and an error report has been ' |
||
84 | . 'generated but failed to be sent.' |
||
85 | ) |
||
86 | . ' ' |
||
87 | . __( |
||
88 | 'If you experience any ' |
||
89 | . 'problems please submit a bug report manually.' |
||
90 | ); |
||
91 | } |
||
92 | $msg .= ' ' . __('You may want to refresh the page.'); |
||
93 | |||
94 | /* Create message object */ |
||
95 | if ($success) { |
||
96 | $msg = Message::notice($msg); |
||
97 | } else { |
||
98 | $msg = Message::error($msg); |
||
99 | } |
||
100 | |||
101 | /* Add message to response */ |
||
102 | if ($response->isAjax()) { |
||
103 | if ($_REQUEST['exception_type'] == 'js') { |
||
104 | $response->addJSON('message', $msg); |
||
105 | } else { |
||
106 | $response->addJSON('_errSubmitMsg', $msg); |
||
107 | } |
||
108 | } elseif ($_REQUEST['exception_type'] == 'php') { |
||
109 | $jsCode = 'PMA_ajaxShowMessage("<div class=\"error\">' |
||
110 | . $msg |
||
111 | . '</div>", false);'; |
||
112 | $response->getFooter()->getScripts()->addCode($jsCode); |
||
113 | } |
||
114 | |||
115 | if ($_REQUEST['exception_type'] == 'php') { |
||
116 | // clear previous errors & save new ones. |
||
117 | $GLOBALS['error_handler']->savePreviousErrors(); |
||
118 | } |
||
119 | |||
120 | /* Persist always send settings */ |
||
121 | if (isset($_REQUEST['always_send']) |
||
122 | && $_REQUEST['always_send'] === "true" |
||
123 | ) { |
||
124 | $userPreferences = new UserPreferences(); |
||
125 | $userPreferences->persistOption("SendErrorReports", "always", "ask"); |
||
126 | } |
||
127 | } |
||
128 | } elseif (! empty($_REQUEST['get_settings'])) { |
||
129 | $response->addJSON('report_setting', $GLOBALS['cfg']['SendErrorReports']); |
||
130 | } else { |
||
131 | if ($_REQUEST['exception_type'] == 'js') { |
||
132 | $response->addHTML($errorReport->getForm()); |
||
133 | } else { |
||
134 | // clear previous errors & save new ones. |
||
135 | $GLOBALS['error_handler']->savePreviousErrors(); |
||
136 | } |
||
137 | } |
||
138 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: