|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Elgg diagnostics |
|
4
|
|
|
* |
|
5
|
|
|
* @package ElggDiagnostics |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Initialise the diagnostics tool |
|
10
|
|
|
* |
|
11
|
|
|
* @return void |
|
12
|
|
|
*/ |
|
13
|
|
|
function diagnostics_init() { |
|
14
|
31 |
|
elgg_register_menu_item('page', [ |
|
15
|
31 |
|
'name' => 'diagnostics', |
|
16
|
31 |
|
'text' => elgg_echo('admin:diagnostics'), |
|
17
|
31 |
|
'href' => 'admin/diagnostics', |
|
18
|
31 |
|
'section' => 'information', |
|
19
|
31 |
|
'context' => 'admin', |
|
20
|
|
|
]); |
|
21
|
31 |
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Generate a basic report |
|
25
|
|
|
* |
|
26
|
|
|
* @param string $hook 'diagnostics:report' |
|
27
|
|
|
* @param string $type 'system' |
|
28
|
|
|
* @param string $returnvalue current return value |
|
29
|
|
|
* @param mixed $params supplied params |
|
30
|
|
|
* |
|
31
|
|
|
* @return string |
|
32
|
|
|
*/ |
|
33
|
|
|
function diagnostics_basic_hook($hook, $type, $returnvalue, $params) { |
|
34
|
|
|
|
|
35
|
|
|
// Get version information |
|
36
|
|
|
$version = elgg_get_version(); |
|
37
|
|
|
$release = elgg_get_version(true); |
|
38
|
|
|
|
|
39
|
|
|
$returnvalue .= elgg_echo('diagnostics:report:basic', [$release, $version]); |
|
40
|
|
|
|
|
41
|
|
|
return $returnvalue; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Recursively list through a directory tree producing a hash of all installed files |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $dir starting dir |
|
48
|
|
|
* |
|
49
|
|
|
* @return string |
|
50
|
|
|
*/ |
|
51
|
|
|
function diagnostics_md5_dir($dir) { |
|
52
|
|
|
$extensions_allowed = ['.php', '.js', '.css']; |
|
53
|
|
|
|
|
54
|
|
|
$buffer = ""; |
|
55
|
|
|
|
|
56
|
|
|
if (in_array(strrchr(trim($dir, "/"), '.'), $extensions_allowed)) { |
|
57
|
|
|
$dir = rtrim($dir, "/"); |
|
58
|
|
|
$buffer .= md5_file($dir). " " . $dir . "\n"; |
|
59
|
|
|
} else if (is_dir($dir)) { |
|
60
|
|
|
$handle = opendir($dir); |
|
61
|
|
|
while ($file = readdir($handle)) { |
|
|
|
|
|
|
62
|
|
|
if (($file != '.') && ($file != '..')) { |
|
63
|
|
|
$buffer .= diagnostics_md5_dir($dir . $file. "/"); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
closedir($handle); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $buffer; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get some information about the files installed on a system |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $hook 'diagnostics:report' |
|
77
|
|
|
* @param string $type 'system' |
|
78
|
|
|
* @param string $returnvalue current return value |
|
79
|
|
|
* @param mixed $params supplied params |
|
80
|
|
|
* |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
|
|
function diagnostics_sigs_hook($hook, $type, $returnvalue, $params) { |
|
84
|
|
|
|
|
85
|
|
|
$base_dir = elgg_get_root_path(); |
|
86
|
|
|
$returnvalue .= elgg_echo('diagnostics:report:md5', [diagnostics_md5_dir($base_dir)]); |
|
87
|
|
|
|
|
88
|
|
|
return $returnvalue; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get some information about the php install |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $hook 'diagnostics:report' |
|
95
|
|
|
* @param string $type 'system' |
|
96
|
|
|
* @param string $returnvalue current return value |
|
97
|
|
|
* @param mixed $params supplied params |
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
|
|
function diagnostics_phpinfo_hook($hook, $type, $returnvalue, $params) { |
|
102
|
|
|
|
|
103
|
|
|
ob_start(); |
|
104
|
|
|
phpinfo(); |
|
105
|
|
|
$phpinfo = ['phpinfo' => []]; |
|
106
|
|
|
|
|
107
|
|
|
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)) { |
|
108
|
|
|
foreach ($matches as $match) { |
|
109
|
|
|
if (strlen($match[1])) { |
|
110
|
|
|
$phpinfo[$match[1]] = []; |
|
111
|
|
|
} else if (isset($match[3])) { |
|
112
|
|
|
$phpinfo[end(array_keys($phpinfo))][$match[2]] = isset($match[4]) ? [$match[3], $match[4]] : $match[3]; |
|
113
|
|
|
} else { |
|
114
|
|
|
$phpinfo[end(array_keys($phpinfo))][] = $match[2]; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$returnvalue .= elgg_echo('diagnostics:report:php', [print_r($phpinfo, true)]); |
|
120
|
|
|
|
|
121
|
|
|
return $returnvalue; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Get global variables |
|
126
|
|
|
* |
|
127
|
|
|
* @param string $hook 'diagnostics:report' |
|
128
|
|
|
* @param string $type 'system' |
|
129
|
|
|
* @param string $returnvalue current return value |
|
130
|
|
|
* @param mixed $params supplied params |
|
131
|
|
|
* |
|
132
|
|
|
* @return string |
|
133
|
|
|
*/ |
|
134
|
|
|
function diagnostics_globals_hook($hook, $type, $returnvalue, $params) { |
|
135
|
|
|
|
|
136
|
|
|
$output = str_replace(elgg_get_config('dbpass'), '<<DBPASS>>', print_r($GLOBALS, true)); |
|
137
|
|
|
$returnvalue .= elgg_echo('diagnostics:report:globals', [$output]); |
|
138
|
|
|
|
|
139
|
|
|
return $returnvalue; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
return function() { |
|
143
|
18 |
|
elgg_register_event_handler('init', 'system', 'diagnostics_init'); |
|
144
|
|
|
|
|
145
|
18 |
|
elgg_register_plugin_hook_handler('diagnostics:report', 'system', 'diagnostics_basic_hook', 0); // show basics first |
|
146
|
18 |
|
elgg_register_plugin_hook_handler('diagnostics:report', 'system', 'diagnostics_sigs_hook', 1); // Now the signatures |
|
147
|
|
|
|
|
148
|
18 |
|
elgg_register_plugin_hook_handler('diagnostics:report', 'system', 'diagnostics_globals_hook'); // Global variables |
|
149
|
18 |
|
elgg_register_plugin_hook_handler('diagnostics:report', 'system', 'diagnostics_phpinfo_hook'); // PHP info |
|
150
|
|
|
}; |
|
151
|
|
|
|