MonitorController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Controllers\Server\Status;
  4. use PhpMyAdmin\DatabaseInterface;
  5. use PhpMyAdmin\Response;
  6. use PhpMyAdmin\Server\Status\Data;
  7. use PhpMyAdmin\Server\Status\Monitor;
  8. use PhpMyAdmin\Server\SysInfo\SysInfo;
  9. use PhpMyAdmin\Template;
  10. use PhpMyAdmin\Url;
  11. use function is_numeric;
  12. use function microtime;
  13. class MonitorController extends AbstractController
  14. {
  15. /** @var Monitor */
  16. private $monitor;
  17. /** @var DatabaseInterface */
  18. private $dbi;
  19. /**
  20. * @param Response $response
  21. * @param Data $data
  22. * @param Monitor $monitor
  23. * @param DatabaseInterface $dbi
  24. */
  25. public function __construct($response, Template $template, $data, $monitor, $dbi)
  26. {
  27. parent::__construct($response, $template, $data);
  28. $this->monitor = $monitor;
  29. $this->dbi = $dbi;
  30. }
  31. public function index(): void
  32. {
  33. global $PMA_Theme, $err_url;
  34. $err_url = Url::getFromRoute('/');
  35. if ($this->dbi->isSuperUser()) {
  36. $this->dbi->selectDb('mysql');
  37. }
  38. $this->addScriptFiles([
  39. 'vendor/jquery/jquery.tablesorter.js',
  40. 'jquery.sortable-table.js',
  41. 'vendor/jqplot/jquery.jqplot.js',
  42. 'vendor/jqplot/plugins/jqplot.pieRenderer.js',
  43. 'vendor/jqplot/plugins/jqplot.enhancedPieLegendRenderer.js',
  44. 'vendor/jqplot/plugins/jqplot.canvasTextRenderer.js',
  45. 'vendor/jqplot/plugins/jqplot.canvasAxisLabelRenderer.js',
  46. 'vendor/jqplot/plugins/jqplot.dateAxisRenderer.js',
  47. 'vendor/jqplot/plugins/jqplot.highlighter.js',
  48. 'vendor/jqplot/plugins/jqplot.cursor.js',
  49. 'jqplot/plugins/jqplot.byteFormatter.js',
  50. 'server/status/monitor.js',
  51. 'server/status/sorter.js',
  52. ]);
  53. $form = [
  54. 'server_time' => (int) (microtime(true) * 1000),
  55. 'server_os' => SysInfo::getOs(),
  56. 'is_superuser' => $this->dbi->isSuperUser(),
  57. 'server_db_isLocal' => $this->data->dbIsLocal,
  58. ];
  59. $javascriptVariableNames = [];
  60. foreach ($this->data->status as $name => $value) {
  61. if (! is_numeric($value)) {
  62. continue;
  63. }
  64. $javascriptVariableNames[] = $name;
  65. }
  66. $this->render('server/status/monitor/index', [
  67. 'image_path' => $PMA_Theme->getImgPath(),
  68. 'javascript_variable_names' => $javascriptVariableNames,
  69. 'form' => $form,
  70. ]);
  71. }
  72. public function chartingData(): void
  73. {
  74. global $err_url;
  75. $params = ['requiredData' => $_POST['requiredData'] ?? null];
  76. $err_url = Url::getFromRoute('/');
  77. if ($this->dbi->isSuperUser()) {
  78. $this->dbi->selectDb('mysql');
  79. }
  80. if (! $this->response->isAjax()) {
  81. return;
  82. }
  83. $this->response->addJSON([
  84. 'message' => $this->monitor->getJsonForChartingData(
  85. $params['requiredData'] ?? ''
  86. ),
  87. ]);
  88. }
  89. public function logDataTypeSlow(): void
  90. {
  91. global $err_url;
  92. $params = [
  93. 'time_start' => $_POST['time_start'] ?? null,
  94. 'time_end' => $_POST['time_end'] ?? null,
  95. ];
  96. $err_url = Url::getFromRoute('/');
  97. if ($this->dbi->isSuperUser()) {
  98. $this->dbi->selectDb('mysql');
  99. }
  100. if (! $this->response->isAjax()) {
  101. return;
  102. }
  103. $this->response->addJSON([
  104. 'message' => $this->monitor->getJsonForLogDataTypeSlow(
  105. (int) $params['time_start'],
  106. (int) $params['time_end']
  107. ),
  108. ]);
  109. }
  110. public function logDataTypeGeneral(): void
  111. {
  112. global $err_url;
  113. $params = [
  114. 'time_start' => $_POST['time_start'] ?? null,
  115. 'time_end' => $_POST['time_end'] ?? null,
  116. 'limitTypes' => $_POST['limitTypes'] ?? null,
  117. 'removeVariables' => $_POST['removeVariables'] ?? null,
  118. ];
  119. $err_url = Url::getFromRoute('/');
  120. if ($this->dbi->isSuperUser()) {
  121. $this->dbi->selectDb('mysql');
  122. }
  123. if (! $this->response->isAjax()) {
  124. return;
  125. }
  126. $this->response->addJSON([
  127. 'message' => $this->monitor->getJsonForLogDataTypeGeneral(
  128. (int) $params['time_start'],
  129. (int) $params['time_end'],
  130. (bool) $params['limitTypes'],
  131. (bool) $params['removeVariables']
  132. ),
  133. ]);
  134. }
  135. public function loggingVars(): void
  136. {
  137. global $err_url;
  138. $params = [
  139. 'varName' => $_POST['varName'] ?? null,
  140. 'varValue' => $_POST['varValue'] ?? null,
  141. ];
  142. $err_url = Url::getFromRoute('/');
  143. if ($this->dbi->isSuperUser()) {
  144. $this->dbi->selectDb('mysql');
  145. }
  146. if (! $this->response->isAjax()) {
  147. return;
  148. }
  149. $this->response->addJSON([
  150. 'message' => $this->monitor->getJsonForLoggingVars(
  151. $params['varName'],
  152. $params['varValue']
  153. ),
  154. ]);
  155. }
  156. public function queryAnalyzer(): void
  157. {
  158. global $err_url;
  159. $params = [
  160. 'database' => $_POST['database'] ?? null,
  161. 'query' => $_POST['query'] ?? null,
  162. ];
  163. $err_url = Url::getFromRoute('/');
  164. if ($this->dbi->isSuperUser()) {
  165. $this->dbi->selectDb('mysql');
  166. }
  167. if (! $this->response->isAjax()) {
  168. return;
  169. }
  170. $this->response->addJSON([
  171. 'message' => $this->monitor->getJsonForQueryAnalyzer(
  172. $params['database'] ?? '',
  173. $params['query'] ?? ''
  174. ),
  175. ]);
  176. }
  177. }