info.class.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. /**
  11. * Loads the system info page
  12. *
  13. * @package modx
  14. * @subpackage manager.controllers
  15. */
  16. class SystemInfoManagerController extends modManagerController {
  17. public $pi;
  18. /**
  19. * Check for any permissions or requirements to load page
  20. * @return bool
  21. */
  22. public function checkPermissions() {
  23. return $this->modx->hasPermission('view_sysinfo');
  24. }
  25. /**
  26. * Custom logic code here for setting placeholders, etc
  27. *
  28. * @param array $scriptProperties
  29. * @return array
  30. */
  31. public function process(array $scriptProperties = array()) {
  32. $pi = $this->getPhpInfo(INFO_GENERAL);
  33. $m = $this->parsePHPModules();
  34. $dbtype_mysql = $this->modx->config['dbtype'] == 'mysql';
  35. $dbtype_sqlsrv = $this->modx->config['dbtype'] == 'sqlsrv';
  36. if ($dbtype_mysql && !empty($m['mysql'])) $pi = array_merge($pi,array('mysql' => $m['mysql']));
  37. if ($dbtype_mysql && !empty($m['mysqlnd'])) $pi = array_merge($pi,array('pdo' => $m['mysqlnd']));
  38. if ($dbtype_sqlsrv && !empty($m['sqlsrv'])) $pi = array_merge($pi,array('sqlsrv' => $m['sqlsrv']));
  39. if (!empty($m['PDO'])) $pi = array_merge($pi,array('pdo' => $m['PDO']));
  40. if ($dbtype_mysql && !empty($m['pdo_mysql'])) $pi = array_merge($pi,array('pdo_mysql' => $m['pdo_mysql']));
  41. if ($dbtype_sqlsrv && !empty($m['pdo_sqlsrv'])) $pi = array_merge($pi,array('pdo_sqlsrv' => $m['pdo_sqlsrv']));
  42. if (!empty($m['zip'])) $pi = array_merge($pi,array('zip' => $m['zip']));
  43. $this->pi = array_merge($pi,$this->getPhpInfo(INFO_CONFIGURATION));
  44. return array(
  45. 'pi' => $this->pi,
  46. );
  47. }
  48. /**
  49. * Register custom CSS/JS for the page
  50. * @return void
  51. */
  52. public function loadCustomCssJs() {
  53. $this->addJavascript($this->modx->getOption('manager_url')."assets/modext/widgets/system/{$this->modx->getOption('dbtype')}/modx.grid.databasetables.js");
  54. $this->addJavascript($this->modx->getOption('manager_url').'assets/modext/widgets/resource/modx.grid.resource.active.js');
  55. $this->addJavascript($this->modx->getOption('manager_url').'assets/modext/sections/system/info.js');
  56. $this->addHtml('<script type="text/javascript">
  57. Ext.onReady(function() {
  58. MODx.load({
  59. xtype: "modx-page-system-info"
  60. ,data: '.$this->modx->toJSON($this->pi).'
  61. });
  62. });
  63. </script>');
  64. }
  65. /**
  66. * Return the pagetitle
  67. *
  68. * @return string
  69. */
  70. public function getPageTitle() {
  71. return $this->modx->lexicon('view_sysinfo');
  72. }
  73. /**
  74. * Return the location of the template file
  75. * @return string
  76. */
  77. public function getTemplateFile() {
  78. return '';
  79. }
  80. /**
  81. * Specify the language topics to load
  82. * @return array
  83. */
  84. public function getLanguageTopics() {
  85. return array('system_info');
  86. }
  87. public function getPhpInfo($type = -1) {
  88. ob_start();
  89. phpinfo($type);
  90. $pi = preg_replace(
  91. array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms',
  92. '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#',
  93. "#[ \t]+#", '#&nbsp;#', '# +#', '# class=".*?"#', '%&#039;%',
  94. '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>'
  95. .'<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#',
  96. '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#',
  97. '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#',
  98. "# +#", '#<tr>#', '#</tr>#'),
  99. array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ',
  100. '<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'.
  101. "\n".'<tr><td>PHP Egg</td><td>$1</td></tr>',
  102. '<tr><td>PHP Credits Egg</td><td>$1</td></tr>',
  103. '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" .
  104. '<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'),
  105. ob_get_clean());
  106. $sections = explode('<h2>', strip_tags($pi, '<h2><th><td>'));
  107. unset($sections[0]);
  108. $pi = array();
  109. foreach($sections as $section){
  110. $n = substr($section, 0, strpos($section, '</h2>'));
  111. preg_match_all(
  112. '#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#',
  113. $section, $askapache, PREG_SET_ORDER);
  114. foreach($askapache as $m)
  115. $pi[$n][$m[1]]=(!isset($m[3])||$m[2]==$m[3])?$m[2]:array_slice($m,2);
  116. }
  117. return $pi;
  118. }
  119. public function parsePHPModules() {
  120. ob_start();
  121. phpinfo(INFO_MODULES);
  122. $s = ob_get_contents();
  123. ob_end_clean();
  124. $s = strip_tags($s,'<h2><th><td>');
  125. $s = preg_replace('/<th[^>]*>([^<]+)<\/th>/',"<info>\\1</info>",$s);
  126. $s = preg_replace('/<td[^>]*>([^<]+)<\/td>/',"<info>\\1</info>",$s);
  127. $vTmp = preg_split('/(<h2>[^<]+<\/h2>)/',$s,-1,PREG_SPLIT_DELIM_CAPTURE);
  128. $vModules = array();
  129. for ($i=1;$i<count($vTmp);$i++) {
  130. if (preg_match('/<h2>([^<]+)<\/h2>/',$vTmp[$i],$vMat)) {
  131. $vName = trim($vMat[1]);
  132. $vTmp2 = explode("\n",$vTmp[$i+1]);
  133. foreach ($vTmp2 AS $vOne) {
  134. $vPat = '<info>([^<]+)<\/info>';
  135. $vPat3 = "/$vPat\s*$vPat\s*$vPat/";
  136. $vPat2 = "/$vPat\s*$vPat/";
  137. if (preg_match($vPat3,$vOne,$vMat)) { // 3cols
  138. $vModules[$vName][trim($vMat[1])] = array(trim($vMat[2]),trim($vMat[3]));
  139. } elseif (preg_match($vPat2,$vOne,$vMat)) { // 2cols
  140. $vModules[$vName][trim($vMat[1])] = trim($vMat[2]);
  141. }
  142. }
  143. }
  144. }
  145. return $vModules;
  146. }
  147. }