MonitorController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Controllers\Server\Status;
  4. use PhpMyAdmin\DatabaseInterface;
  5. use PhpMyAdmin\ResponseRenderer;
  6. use PhpMyAdmin\Server\Status\Data;
  7. use PhpMyAdmin\Server\SysInfo\SysInfo;
  8. use PhpMyAdmin\Template;
  9. use PhpMyAdmin\Url;
  10. use function is_numeric;
  11. use function microtime;
  12. class MonitorController extends AbstractController
  13. {
  14. /** @var DatabaseInterface */
  15. private $dbi;
  16. public function __construct(ResponseRenderer $response, Template $template, Data $data, DatabaseInterface $dbi)
  17. {
  18. parent::__construct($response, $template, $data);
  19. $this->dbi = $dbi;
  20. }
  21. public function __invoke(): void
  22. {
  23. global $errorUrl;
  24. $errorUrl = Url::getFromRoute('/');
  25. if ($this->dbi->isSuperUser()) {
  26. $this->dbi->selectDb('mysql');
  27. }
  28. $this->addScriptFiles([
  29. 'vendor/jquery/jquery.tablesorter.js',
  30. 'jquery.sortable-table.js',
  31. 'vendor/jqplot/jquery.jqplot.js',
  32. 'vendor/jqplot/plugins/jqplot.pieRenderer.js',
  33. 'vendor/jqplot/plugins/jqplot.enhancedPieLegendRenderer.js',
  34. 'vendor/jqplot/plugins/jqplot.canvasTextRenderer.js',
  35. 'vendor/jqplot/plugins/jqplot.canvasAxisLabelRenderer.js',
  36. 'vendor/jqplot/plugins/jqplot.dateAxisRenderer.js',
  37. 'vendor/jqplot/plugins/jqplot.highlighter.js',
  38. 'vendor/jqplot/plugins/jqplot.cursor.js',
  39. 'jqplot/plugins/jqplot.byteFormatter.js',
  40. 'server/status/monitor.js',
  41. 'server/status/sorter.js',
  42. 'chart.js',// Needed by createProfilingChart in server/status/monitor.js
  43. ]);
  44. $form = [
  45. 'server_time' => (int) (microtime(true) * 1000),
  46. 'server_os' => SysInfo::getOs(),
  47. 'is_superuser' => $this->dbi->isSuperUser(),
  48. 'server_db_isLocal' => $this->data->dbIsLocal,
  49. ];
  50. $javascriptVariableNames = [];
  51. foreach ($this->data->status as $name => $value) {
  52. if (! is_numeric($value)) {
  53. continue;
  54. }
  55. $javascriptVariableNames[] = $name;
  56. }
  57. $this->render('server/status/monitor/index', [
  58. 'javascript_variable_names' => $javascriptVariableNames,
  59. 'form' => $form,
  60. ]);
  61. }
  62. }