diff options
Diffstat (limited to 'mod/diagnostics')
-rw-r--r-- | mod/diagnostics/actions/download.php | 18 | ||||
-rw-r--r-- | mod/diagnostics/languages/en.php | 45 | ||||
-rw-r--r-- | mod/diagnostics/manifest.xml | 17 | ||||
-rw-r--r-- | mod/diagnostics/start.php | 140 | ||||
-rw-r--r-- | mod/diagnostics/views/default/admin/administer_utilities/diagnostics.php | 17 |
5 files changed, 237 insertions, 0 deletions
diff --git a/mod/diagnostics/actions/download.php b/mod/diagnostics/actions/download.php new file mode 100644 index 000000000..97775c92e --- /dev/null +++ b/mod/diagnostics/actions/download.php @@ -0,0 +1,18 @@ +<?php +/** + * Elgg diagnostics + * + * @package ElggDiagnostics + */ + +$output = elgg_echo('diagnostics:header', array(date('r'), elgg_get_logged_in_user_entity()->name)); +$output = elgg_trigger_plugin_hook('diagnostics:report', 'system', null, $output); + +header("Cache-Control: public"); +header("Content-Description: File Transfer"); +header('Content-disposition: attachment; filename=elggdiagnostic.txt'); +header("Content-Type: text/plain"); +header('Content-Length: ' . strlen($output)); + +echo $output; +exit; diff --git a/mod/diagnostics/languages/en.php b/mod/diagnostics/languages/en.php new file mode 100644 index 000000000..54859941d --- /dev/null +++ b/mod/diagnostics/languages/en.php @@ -0,0 +1,45 @@ +<?php +/** + * Elgg diagnostics language pack. + * + * @package ElggDiagnostics + */ + +$english = array( + 'admin:administer_utilities:diagnostics' => 'System Diagnostics', + 'diagnostics' => 'System diagnostics', + 'diagnostics:report' => 'Diagnostics Report', + 'diagnostics:description' => 'The following diagnostic report can be useful for diagnosing problems with Elgg. The developers of Elgg may request that you attach it to a bug report.', + 'diagnostics:download' => 'Download', + 'diagnostics:header' => '======================================================================== +Elgg Diagnostic Report +Generated %s by %s +======================================================================== + +', + 'diagnostics:report:basic' => ' +Elgg Release %s, version %s + +------------------------------------------------------------------------', + 'diagnostics:report:php' => ' +PHP info: +%s +------------------------------------------------------------------------', + 'diagnostics:report:plugins' => ' +Installed plugins and details: + +%s +------------------------------------------------------------------------', + 'diagnostics:report:md5' => ' +Installed files and checksums: + +%s +------------------------------------------------------------------------', + 'diagnostics:report:globals' => ' +Global variables: + +%s +------------------------------------------------------------------------', +); + +add_translation("en", $english); diff --git a/mod/diagnostics/manifest.xml b/mod/diagnostics/manifest.xml new file mode 100644 index 000000000..21e847d22 --- /dev/null +++ b/mod/diagnostics/manifest.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> + <name>Diagnostics</name> + <author>Core developers</author> + <version>1.8</version> + <category>bundled</category> + <category>development</category> + <category>admin</category> + <description>Elgg diagnostics tool</description> + <website>http://www.elgg.org/</website> + <copyright>See COPYRIGHT.txt</copyright> + <license>GNU General Public License version 2</license> + <requires> + <type>elgg_release</type> + <version>1.8</version> + </requires> +</plugin_manifest> diff --git a/mod/diagnostics/start.php b/mod/diagnostics/start.php new file mode 100644 index 000000000..55842800a --- /dev/null +++ b/mod/diagnostics/start.php @@ -0,0 +1,140 @@ +<?php +/** + * Elgg diagnostics + * + * @package ElggDiagnostics + */ + +elgg_register_event_handler('init', 'system', 'diagnostics_init'); + +/** + * Initialise the diagnostics tool + */ +function diagnostics_init() { + + // Add admin menu item + elgg_register_admin_menu_item('administer', 'diagnostics', 'administer_utilities'); + + // Register some actions + $file = elgg_get_plugins_path() . "diagnostics/actions/download.php"; + elgg_register_action("diagnostics/download", $file, 'admin'); +} + +/** + * Generate a basic report. + * + * @return string + */ +function diagnostics_basic_hook($hook, $entity_type, $returnvalue, $params) { + + // Get version information + $version = get_version(); + $release = get_version(true); + + $returnvalue .= elgg_echo('diagnostics:report:basic', array($release, $version)); + + return $returnvalue; +} + +/** + * Get some information about the plugins installed on the system. + * + * @return tring + */ +function diagnostics_plugins_hook($hook, $entity_type, $returnvalue, $params) { + // @todo this is a really bad idea because of the new plugin system + //$returnvalue .= elgg_echo('diagnostics:report:plugins', array(print_r(elgg_get_plugins(), true))); + + return $returnvalue; +} + +/** + * Recursively list through a directory tree producing a hash of all installed files + * + * @param starting dir $dir + * @param buffer $buffer + */ +function diagnostics_md5_dir($dir) { + $extensions_allowed = array('.php', '.js', '.css'); + + $buffer = ""; + + if (in_array(strrchr(trim($dir, "/"), '.'), $extensions_allowed)) { + $dir = rtrim($dir, "/"); + $buffer .= md5_file($dir). " " . $dir . "\n"; + } else if (is_dir($dir)) { + $handle = opendir($dir); + while ($file = readdir($handle)) { + if (($file != '.') && ($file != '..')) { + $buffer .= diagnostics_md5_dir($dir . $file. "/", $buffer); + } + } + + closedir($handle); + } + + return $buffer; +} + +/** + * Get some information about the files installed on a system. + * + * @return string + */ +function diagnostics_sigs_hook($hook, $entity_type, $returnvalue, $params) { + + $base_dir = elgg_get_root_path(); + $returnvalue .= elgg_echo('diagnostics:report:md5', array(diagnostics_md5_dir($base_dir))); + + return $returnvalue; +} + +/** + * Get some information about the php install + * + * @return string + */ +function diagnostics_phpinfo_hook($hook, $entity_type, $returnvalue, $params) { + + ob_start(); + phpinfo(); + $phpinfo = array('phpinfo' => array()); + + 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)) { + + foreach ($matches as $match) { + if (strlen($match[1])) { + $phpinfo[$match[1]] = array(); + } else if(isset($match[3])) { + $phpinfo[end(array_keys($phpinfo))][$match[2]] = isset($match[4]) ? array($match[3], $match[4]) : $match[3]; + } else { + $phpinfo[end(array_keys($phpinfo))][] = $match[2]; + } + } + } + + $returnvalue .= elgg_echo('diagnostics:report:php', array(print_r($phpinfo, true))); + + return $returnvalue; +} + +/** + * Get global variables. + * + * @return string + */ +function diagnostics_globals_hook($hook, $entity_type, $returnvalue, $params) { + global $CONFIG; + + $output = str_replace($CONFIG->dbpass, '<<DBPASS>>', print_r($GLOBALS, true)); + $returnvalue .= elgg_echo('diagnostics:report:globals', array($output)); + + return $returnvalue; +} + +elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_basic_hook", 0); // show basics first +elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_plugins_hook", 2); // Now the plugins +elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_sigs_hook", 1); // Now the signatures + +elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_globals_hook"); // Global variables +elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_phpinfo_hook"); // PHP info diff --git a/mod/diagnostics/views/default/admin/administer_utilities/diagnostics.php b/mod/diagnostics/views/default/admin/administer_utilities/diagnostics.php new file mode 100644 index 000000000..c7ff3d5fc --- /dev/null +++ b/mod/diagnostics/views/default/admin/administer_utilities/diagnostics.php @@ -0,0 +1,17 @@ +<?php +/** + * Diagnostics admin page + */ + +$diagnostics_title = elgg_echo('diagnostics:report'); +$diagnostics = '<p>' . elgg_echo('diagnostics:description') .'</p>'; +$params = array( + 'text' => elgg_echo('diagnostics:download'), + 'href' => 'action/diagnostics/download', + 'class' => 'elgg-button elgg-button-submit', + 'is_action' => true, + 'is_trusted' => true, +); +$diagnostics .= '<p>' . elgg_view('output/url', $params) . '</p>'; + +echo elgg_view_module('inline', $diagnostics_title, $diagnostics, array('class' => 'elgg-form-settings')); |