1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Elgg diagnostics |
4
|
|
|
* |
5
|
|
|
* @package ElggDiagnostics |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
elgg_register_event_handler('init', 'system', 'diagnostics_init'); |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Initialise the diagnostics tool |
12
|
|
|
*/ |
13
|
|
|
function diagnostics_init() { |
14
|
|
|
|
15
|
|
|
// Add admin menu item |
16
|
|
|
elgg_register_admin_menu_item('administer', 'diagnostics', 'administer_utilities'); |
17
|
|
|
|
18
|
|
|
// Register some actions |
19
|
|
|
$file = elgg_get_plugins_path() . "diagnostics/actions/download.php"; |
20
|
|
|
elgg_register_action("diagnostics/download", $file, 'admin'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Generate a basic report. |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
function diagnostics_basic_hook($hook, $entity_type, $returnvalue, $params) { |
29
|
|
|
|
30
|
|
|
// Get version information |
31
|
|
|
$version = elgg_get_version(); |
32
|
|
|
$release = elgg_get_version(true); |
33
|
|
|
|
34
|
|
|
$returnvalue .= elgg_echo('diagnostics:report:basic', array($release, $version)); |
35
|
|
|
|
36
|
|
|
return $returnvalue; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get some information about the plugins installed on the system. |
41
|
|
|
* |
42
|
|
|
* @return tring |
43
|
|
|
*/ |
44
|
|
|
function diagnostics_plugins_hook($hook, $entity_type, $returnvalue, $params) { |
45
|
|
|
// @todo this is a really bad idea because of the new plugin system |
46
|
|
|
//$returnvalue .= elgg_echo('diagnostics:report:plugins', array(print_r(elgg_get_plugins(), true))); |
47
|
|
|
|
48
|
|
|
return $returnvalue; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Recursively list through a directory tree producing a hash of all installed files |
53
|
|
|
* |
54
|
|
|
* @param starting dir $dir |
55
|
|
|
* @param buffer $buffer |
|
|
|
|
56
|
|
|
*/ |
57
|
|
|
function diagnostics_md5_dir($dir) { |
58
|
|
|
$extensions_allowed = array('.php', '.js', '.css'); |
59
|
|
|
|
60
|
|
|
$buffer = ""; |
61
|
|
|
|
62
|
|
|
if (in_array(strrchr(trim($dir, "/"), '.'), $extensions_allowed)) { |
63
|
|
|
$dir = rtrim($dir, "/"); |
64
|
|
|
$buffer .= md5_file($dir). " " . $dir . "\n"; |
65
|
|
|
} else if (is_dir($dir)) { |
66
|
|
|
$handle = opendir($dir); |
67
|
|
|
while ($file = readdir($handle)) { |
68
|
|
|
if (($file != '.') && ($file != '..')) { |
69
|
|
|
$buffer .= diagnostics_md5_dir($dir . $file. "/"); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
closedir($handle); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $buffer; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get some information about the files installed on a system. |
81
|
|
|
* |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
function diagnostics_sigs_hook($hook, $entity_type, $returnvalue, $params) { |
85
|
|
|
|
86
|
|
|
$base_dir = elgg_get_root_path(); |
87
|
|
|
$returnvalue .= elgg_echo('diagnostics:report:md5', array(diagnostics_md5_dir($base_dir))); |
88
|
|
|
|
89
|
|
|
return $returnvalue; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Get some information about the php install |
94
|
|
|
* |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
function diagnostics_phpinfo_hook($hook, $entity_type, $returnvalue, $params) { |
98
|
|
|
|
99
|
|
|
ob_start(); |
100
|
|
|
phpinfo(); |
101
|
|
|
$phpinfo = array('phpinfo' => array()); |
102
|
|
|
|
103
|
|
|
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)) { |
104
|
|
|
|
105
|
|
|
foreach ($matches as $match) { |
106
|
|
|
if (strlen($match[1])) { |
107
|
|
|
$phpinfo[$match[1]] = array(); |
108
|
|
|
} else if(isset($match[3])) { |
109
|
|
|
$phpinfo[end(array_keys($phpinfo))][$match[2]] = isset($match[4]) ? array($match[3], $match[4]) : $match[3]; |
|
|
|
|
110
|
|
|
} else { |
111
|
|
|
$phpinfo[end(array_keys($phpinfo))][] = $match[2]; |
|
|
|
|
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$returnvalue .= elgg_echo('diagnostics:report:php', array(print_r($phpinfo, true))); |
117
|
|
|
|
118
|
|
|
return $returnvalue; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Get global variables. |
123
|
|
|
* |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
function diagnostics_globals_hook($hook, $entity_type, $returnvalue, $params) { |
127
|
|
|
global $CONFIG; |
128
|
|
|
|
129
|
|
|
$output = str_replace($CONFIG->dbpass, '<<DBPASS>>', print_r($GLOBALS, true)); |
130
|
|
|
$returnvalue .= elgg_echo('diagnostics:report:globals', array($output)); |
131
|
|
|
|
132
|
|
|
return $returnvalue; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_basic_hook", 0); // show basics first |
136
|
|
|
elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_plugins_hook", 2); // Now the plugins |
137
|
|
|
elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_sigs_hook", 1); // Now the signatures |
138
|
|
|
|
139
|
|
|
elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_globals_hook"); // Global variables |
140
|
|
|
elgg_register_plugin_hook_handler("diagnostics:report", "system", "diagnostics_phpinfo_hook"); // PHP info |
141
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.