1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
<?php
/**
* Elgg diagnostics
*
* @package ElggDiagnostics
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Curverider Ltd
* @copyright Curverider Ltd 2008
* @link http://elgg.com/
*/
/**
* Initialise the diagnostics tool
*
*/
function diagnostics_init()
{
global $CONFIG;
// Register a page handler, so we can have nice URLs
register_page_handler('diagnostics','diagnostics_page_handler');
// Register some actions
register_action("diagnostics/download",false, $CONFIG->pluginspath . "diagnostics/actions/download.php");
}
/**
* Adding the diagnostics to the admin menu
*
*/
function diagnostics_pagesetup()
{
if (get_context() == 'admin' && isadminloggedin()) {
global $CONFIG;
add_submenu_item(elgg_echo('diagnostics'), $CONFIG->wwwroot . 'pg/diagnostics/');
}
}
/**
* Diagnostics page.
*
* @param array $page Array of page elements, forwarded by the page handling mechanism
*/
function diagnostics_page_handler($page)
{
global $CONFIG;
// only interested in one page for now
include($CONFIG->pluginspath . "diagnostics/index.php");
}
/**
* Generate a basic report.
*
* @param unknown_type $hook
* @param unknown_type $entity_type
* @param unknown_type $returnvalue
* @param unknown_type $params
*/
function diagnostics_basic_hook($hook, $entity_type, $returnvalue, $params)
{
global $CONFIG;
include_once($CONFIG->path . "version.php");
$returnvalue .= sprintf(elgg_echo('diagnostics:report:basic'), $release, $version);
return $returnvalue;
}
/**
* Get some information about the plugins installed on the system.
*
* @param unknown_type $hook
* @param unknown_type $entity_type
* @param unknown_type $returnvalue
* @param unknown_type $params
*/
function diagnostics_plugins_hook($hook, $entity_type, $returnvalue, $params)
{
$returnvalue .= sprintf(elgg_echo('diagnostics:report:plugins'), print_r(get_installed_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)
{
//if (is_file(trim($dir, "/"))) {
$extensions_allowed = array('.php', '.gif', '.png', '.jpg');
$buffer = "";
if (in_array(strrchr(trim($dir, "/"), '.'), $extensions_allowed))
{
//$dir = trim($dir, "/");
$buffer .= md5_file($dir). " " . trim($dir, "/") . "\n";
} else if ($handle = opendir($dir)) {
while ($file = readdir($handle)) {
if (($file != '.') && ($file != '..')) {
$buffer .= diagnostics_md5_dir($dir . $file. "/", $buffer);
}
}
}
return $buffer;
}
/**
* Get some information about the files installed on a system.
*
* @param unknown_type $hook
* @param unknown_type $entity_type
* @param unknown_type $returnvalue
* @param unknown_type $params
*/
function diagnostics_sigs_hook($hook, $entity_type, $returnvalue, $params)
{
global $CONFIG;
$returnvalue .= sprintf(elgg_echo('diagnostics:report:md5'), diagnostics_md5_dir($CONFIG->path));
return $returnvalue;
}
/**
* Get some information about the current session
*
* @param unknown_type $hook
* @param unknown_type $entity_type
* @param unknown_type $returnvalue
* @param unknown_type $params
*/
function diagnostics_session_hook($hook, $entity_type, $returnvalue, $params)
{
global $CONFIG;
$returnvalue .= sprintf(elgg_echo('diagnostics:report:session'), print_r($_SESSION, true));
return $returnvalue;
}
// Initialise log browser
register_elgg_event_handler('init','system','diagnostics_init');
register_elgg_event_handler('pagesetup','system','diagnostics_pagesetup');
register_plugin_hook("diagnostics:report", "all", "diagnostics_basic_hook", 0); // show basics first
register_plugin_hook("diagnostics:report", "all", "diagnostics_plugins_hook", 2); // Now the plugins
register_plugin_hook("diagnostics:report", "all", "diagnostics_sigs_hook", 1); // Now the signatures
register_plugin_hook("diagnostics:report", "all", "diagnostics_session_hook"); // Session
?>
|