start.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * Elgg diagnostics
  4. *
  5. * @package ElggDiagnostics
  6. */
  7. elgg_register_event_handler('init', 'system', 'diagnostics_init');
  8. /**
  9. * Initialise the diagnostics tool
  10. */
  11. function diagnostics_init() {
  12. // Add admin menu item
  13. elgg_register_admin_menu_item('administer', 'diagnostics', 'administer_utilities');
  14. // Register some actions
  15. $file = elgg_get_plugins_path() . "diagnostics/actions/download.php";
  16. elgg_register_action("diagnostics/download", $file, 'admin');
  17. }
  18. /**
  19. * Generate a basic report.
  20. *
  21. * @return string
  22. */
  23. function diagnostics_basic_hook($hook, $entity_type, $returnvalue, $params) {
  24. // Get version information
  25. $version = elgg_get_version();
  26. $release = elgg_get_version(true);
  27. $returnvalue .= elgg_echo('diagnostics:report:basic', array($release, $version));
  28. return $returnvalue;
  29. }
  30. /**
  31. * Get some information about the plugins installed on the system.
  32. *
  33. * @return tring
  34. */
  35. function diagnostics_plugins_hook($hook, $entity_type, $returnvalue, $params) {
  36. // @todo this is a really bad idea because of the new plugin system
  37. //$returnvalue .= elgg_echo('diagnostics:report:plugins', array(print_r(elgg_get_plugins(), true)));
  38. return $returnvalue;
  39. }
  40. /**
  41. * Recursively list through a directory tree producing a hash of all installed files
  42. *
  43. * @param starting dir $dir
  44. * @param buffer $buffer
  45. */
  46. function diagnostics_md5_dir($dir) {
  47. $extensions_allowed = array('.php', '.js', '.css');
  48. $buffer = "";
  49. if (in_array(strrchr(trim($dir, "/"), '.'), $extensions_allowed)) {
  50. $dir = rtrim($dir, "/");
  51. $buffer .= md5_file($dir). " " . $dir . "\n";
  52. } else if (is_dir($dir)) {
  53. $handle = opendir($dir);
  54. while ($file = readdir($handle)) {
  55. if (($file != '.') && ($file != '..')) {
  56. $buffer .= diagnostics_md5_dir($dir . $file. "/");
  57. }
  58. }
  59. closedir($handle);
  60. }
  61. return $buffer;
  62. }
  63. /**
  64. * Get some information about the files installed on a system.
  65. *
  66. * @return string
  67. */
  68. function diagnostics_sigs_hook($hook, $entity_type, $returnvalue, $params) {
  69. $base_dir = elgg_get_root_path();
  70. $returnvalue .= elgg_echo('diagnostics:report:md5', array(diagnostics_md5_dir($base_dir)));
  71. return $returnvalue;
  72. }
  73. /**
  74. * Get some information about the php install
  75. *
  76. * @return string
  77. */
  78. function diagnostics_phpinfo_hook($hook, $entity_type, $returnvalue, $params) {
  79. ob_start();
  80. phpinfo();
  81. $phpinfo = array('phpinfo' => array());
  82. if (preg_match_all('#(?:<h2>(?:<a name=".*?">)?(.*?)(?:</a>)?</h2>)|(?:<tr(?: class=".*?")?><t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>)?)?</tr>)#s', ob_get_clean(), $matches, PREG_SET_ORDER)) {
  83. foreach ($matches as $match) {
  84. if (strlen($match[1])) {
  85. $phpinfo[$match[1]] = array();
  86. } else if(isset($match[3])) {
  87. $phpinfo[end(array_keys($phpinfo))][$match[2]] = isset($match[4]) ? array($match[3], $match[4]) : $match[3];
  88. } else {
  89. $phpinfo[end(array_keys($phpinfo))][] = $match[2];
  90. }
  91. }
  92. }
  93. $returnvalue .= elgg_echo('diagnostics:report:php', array(print_r($phpinfo, true)));
  94. return $returnvalue;
  95. }
  96. /**
  97. * Get global variables.
  98. *
  99. * @return string
  100. */
  101. function diagnostics_globals_hook($hook, $entity_type, $returnvalue, $params) {
  102. global $CONFIG;
  103. $output = str_replace($CONFIG->dbpass, '<<DBPASS>>', print_r($GLOBALS, true));
  104. $returnvalue .= elgg_echo('diagnostics:report:globals', array($output));
  105. return $returnvalue;
  106. }
  107. elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_basic_hook", 0); // show basics first
  108. elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_plugins_hook", 2); // Now the plugins
  109. elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_sigs_hook", 1); // Now the signatures
  110. elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_globals_hook"); // Global variables
  111. elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_phpinfo_hook"); // PHP info