/[drupal]/contributions/modules/systeminfo/systeminfo.module
ViewVC logotype

Contents of /contributions/modules/systeminfo/systeminfo.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.43 - (show annotations) (download) (as text)
Sun Nov 2 18:37:03 2008 UTC (12 months, 3 weeks ago) by flanker
Branch: MAIN
CVS Tags: HEAD
Changes since 1.42: +5 -1 lines
File MIME type: text/x-php
Added information about content to main page.
1 <?php
2 // $Id: systeminfo.module,v 1.42 2008/11/02 17:56:45 flanker Exp $
3 // $Name: $
4
5 /**
6 * @file
7 * Displays information of the drupal install and system environment.
8 */
9
10
11 /**
12 * Implementation of hook_help().
13 */
14 function systeminfo_help($section) {
15 switch ($section) {
16 case 'admin/help#systeminfo':
17 $output = '<p>'. t('This module displays information of the drupal install and system environment.') .'</p>';
18 $output .= '<h4>'. t('System requirements') .'</h4>';
19 $output .= '<p>'. t('For detailed information about Drupal requirements, see <a href="@requirements">System requirements</a> in the Drupal handbook.', array('@requirements' => 'http://drupal.org/requirements/')) .'</p>';
20 return $output;
21 case 'admin/reports/systeminfo':
22 return '<p>'. t('Information of the drupal install and system environment.') .'</p>';
23 }
24 }
25
26
27 /**
28 * Implementation of hook_perm().
29 */
30 function systeminfo_perm() {
31 return array('access system info' => t('View information of the drupal install and system environment. %warning', array('%warning' => t('Warning: Give to trusted roles only; this permission has security implications.'))));
32 }
33
34
35 /**
36 * Implementation of hook_menu().
37 */
38 function systeminfo_menu() {
39 $items = array();
40
41 $items['admin/reports/systeminfo'] = array(
42 'title' => t('System info'),
43 'description' => t('Displays information of the drupal install and system environment.'),
44 'page callback' => 'systeminfo_display_information',
45 'access arguments' => array('access system info'),
46 );
47 $items['admin/reports/systeminfo/drupal'] = array(
48 'title' => 'Drupal',
49 'description' => t('Display information about the drupal installation.'),
50 'page callback' => 'systeminfo_display_drupal',
51 'access arguments' => array('access system info'),
52 'weight' => 1,
53 );
54 $items['admin/reports/systeminfo/webserver'] = array(
55 'title' => t('Web server'),
56 'description' => t('Display information about the web server.'),
57 'page callback' => 'systeminfo_display_webserver',
58 'access arguments' => array('access system info'),
59 'weight' => 2,
60 );
61 $items['admin/reports/systeminfo/php'] = array(
62 'title' => 'PHP',
63 'description' => t('Display current state of PHP.'),
64 'page callback' => 'systeminfo_display_php',
65 'access arguments' => array('access system info'),
66 'weight' => 3,
67 );
68 $items['admin/reports/systeminfo/database'] = array(
69 'title' => t('Database server'),
70 'description' => t('Display information about the database server.'),
71 'page callback' => 'systeminfo_display_database',
72 'access arguments' => array('access system info'),
73 'weight' => 4,
74 );
75
76 return $items;
77 }
78
79
80 /**
81 * Menu callback of page 'system info'.
82 */
83 function systeminfo_display_information() {
84 global $base_url, $db_prefix, $db_url;
85
86 drupal_add_css(drupal_get_path('module', 'systeminfo') .'/systeminfo.css');
87
88
89 // Drupal
90 $rows = array();
91 $rows[] = array(t('Version'), VERSION);
92 $rows[] = array(t('Configuration file'), conf_path() .'/settings.php');
93 $rows[] = array(t('Content'), t('!nodes', array('!nodes' => format_plural(db_result(db_query("SELECT COUNT(nid) FROM {node}")), '1 node', '@count nodes'))));
94 foreach (node_get_types('names')as $type_type => $type_name) {
95 $rows[] = array(array('data' => t($type_name), 'class' => 'subtitle'), t('!nodes', array('!nodes' => format_plural(db_result(db_query("SELECT COUNT(nid) FROM {node} WHERE type = '%s'", $type_type)), '1 node', '@count nodes'))));
96 }
97 $cron_last = variable_get('cron_last', NULL);
98 $rows[] = array(t('Cron'), isset($cron_last) ? t('Last run !time ago', array('!time' => format_interval(time() - $cron_last))) : t('Not run yet'));
99 $rows[] = array(t('File system path'), file_directory_path());
100 $rows[] = array(t('Users'), t('!accounts', array('!accounts' => format_plural(db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE uid != 0")), '1 account', '@count accounts'))));
101 $rows[] = array(array('data' => t('Active'), 'class' => 'subtitle'), t('!accounts', array('!accounts' => format_plural(db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE uid != 0 AND status = 1")), '1 account', '@count accounts'))));
102 $rows[] = array(array('data' => t('Blocked'), 'class' => 'subtitle'), t('!accounts', array('!accounts' => format_plural(db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE uid != 0 AND status = 0")), '1 account', '@count accounts'))));
103
104 $output = '<h3>Drupal</h3>';
105 $output .= theme('table', NULL, $rows, array('class' => 'systeminfo'));
106 $output .= '<p>'. t('More information about the drupal installation can be found <a href="@drupal" title="Display information about the drupal installation.">here</a>.', array('@drupal' => url('admin/reports/systeminfo/drupal'))) .'</p>';
107
108
109 // Web server
110 if (preg_match('/Apache\/?([0-9|\.]*)/i', $_SERVER['SERVER_SOFTWARE'], $webserver_version)) {
111 // Apache
112 $webserver_type = 'Apache';
113 }
114 elseif (preg_match('/lighttpd\/?([0-9|\.]*)/i', $_SERVER['SERVER_SOFTWARE'], $webserver_version)) {
115 // LightTPD
116 $webserver_type = 'LightTPD';
117 }
118 elseif (preg_match('/IIS\/?([0-9|\.]*)/i', $_SERVER['SERVER_SOFTWARE'], $webserver_version)) {
119 // Microsoft IIS
120 $webserver_type = 'Microsoft IIS';
121 }
122
123 $rows = array();
124 $rows[] = array(t('Type'), isset($webserver_type) ? $webserver_type : t('Unknown'));
125 $rows[] = array(t('Version'), isset($webserver_version) ? (!empty($webserver_version[1]) ? $webserver_version[1] : t('Unknown')) : $_SERVER['SERVER_SOFTWARE']);
126 $rows[] = array(t('Operating system'), php_uname('s'));
127 if ('Apache' == $webserver_type) {
128 $rows[] = array(t('PHP interface'), php_sapi_name());
129 }
130 $rows[] = array(t('URL'), $base_url);
131 if ('Apache' == $webserver_type && function_exists('apache_get_modules')) {
132 $rows[] = array(array('data' => t('Modules'), 'class' => 'subheader', 'colspan' => '2'));
133 $apache_modules = apache_get_modules();
134 $rows[] = array(array('data' => t('Rewrite'), 'class' => 'subtitle'), in_array('mod_rewrite', $apache_modules) ? t('Loaded') : t('Not loaded'));
135 $rows[] = array(array('data' => t('SSL'), 'class' => 'subtitle'), in_array('mod_ssl', $apache_modules) ? t('Loaded') : t('Not loaded'));
136 }
137
138 $output .= '<h3>'. t('Web server') .'</h3>';
139 $output .= theme('table', NULL, $rows, array('class' => 'systeminfo'));
140 $output .= '<p>'. t('More information about the web server can be found <a href="@webserver" title="Display information about the web server.">here</a>.', array('@webserver' => url('admin/reports/systeminfo/webserver'))) .'</p>';
141
142
143 // PHP
144 $rows = array();
145 $rows[] = array(t('Version'), phpversion());
146 $rows[] = array(t('Magic quotes GPC'), ini_get('magic_quotes_gpc') ? t('On') : t('Off'));
147 $rows[] = array(t('Magic quotes runtime'), ini_get('magic_quotes_runtime') ? t('On') : t('Off'));
148 $rows[] = array(t('Max execution time'), ini_get('max_execution_time'));
149 $rows[] = array(t('Max input time'), ini_get('max_input_time'));
150 $rows[] = array(t('Memory limit'), ini_get('memory_limit'));
151 $rows[] = array(t('Post max size'), ini_get('post_max_size'));
152 $rows[] = array(t('Register globals'), ini_get('register_globals') ? t('On') : t('Off'));
153 $rows[] = array(t('Safe mode'), ini_get('safe_mode') ? t('On') : t('Off'));
154 $rows[] = array(t('Session cache limiter'), ini_get('session.cache_limiter'));
155 $cookie_params = session_get_cookie_params();
156 $rows[] = array(t('Session cookie domain'), !empty($cookie_params['domain']) ? $cookie_params['domain'] : '<em>'. t('no value') .'</em>');
157 $rows[] = array(t('Session name'), session_name());
158 $rows[] = array(t('Session save handler'), ini_get('session.save_handler'));
159 $rows[] = array(t('Upload max filesize'), ini_get('upload_max_filesize'));
160 // PHP extensions
161 $rows[] = array(array('data' => t('Extensions'), 'class' => 'subheader', 'colspan' => '2'));
162 if (extension_loaded('curl')) {
163 $curl = curl_version();
164 $rows[] = array(array('data' => t('CURL version'), 'class' => 'subtitle'), $curl['version']);
165 }
166 else {
167 $rows[] = array(array('data' => t('CURL support'), 'class' => 'subtitle'), t('Disabled'));
168 }
169 if (extension_loaded('gd')) {
170 $gd = gd_info();
171 $rows[] = array(array('data' => t('GD version'), 'class' => 'subtitle'), $gd['GD Version']);
172 $rows[] = array(array('data' => t('FreeType support'), 'class' => 'subsubtitle'), $gd['FreeType Support'] ? t('Enabled') : t('Disabled'));
173 $rows[] = array(array('data' => t('JPG support'), 'class' => 'subsubtitle'), $gd['JPG Support'] ? t('Enabled') : t('Disabled'));
174 $rows[] = array(array('data' => t('PNG support'), 'class' => 'subsubtitle'), $gd['PNG Support'] ? t('Enabled') : t('Disabled'));
175 }
176 else {
177 $rows[] = array(array('data' => t('GD support'), 'class' => 'subtitle'), t('Disabled'));
178 }
179 $rows[] = array(array('data' => t('Multibyte support'), 'class' => 'subtitle'), extension_loaded('mbstring') ? t('Enabled') : t('Disabled'));
180 $rows[] = array(array('data' => t('XML support'), 'class' => 'subtitle'), extension_loaded('xml') ? t('Enabled') : t('Disabled'));
181 $rows[] = array(array('data' => t('Zip support'), 'class' => 'subtitle'), extension_loaded('zip') ? t('Enabled') : t('Disabled'));
182 $rows[] = array(array('data' => t('Zlib support'), 'class' => 'subtitle'), extension_loaded('zlib') ? t('Enabled') : t('Disabled'));
183
184 $output .= '<h3>PHP</h3>';
185 $output .= theme('table', NULL, $rows, array('class' => 'systeminfo'));
186 $output .= '<p>'. t('More information about the current state of PHP can be found <a href="@php" title="Display current state of PHP." >here</a>.', array('@php' => url('admin/reports/systeminfo/php'))) .'</p>';
187
188
189 // Database server
190 $rows = array();
191 $databases = is_array($db_url) ? $db_url : array('default' => $db_url);
192 foreach ($databases as $key => $value) {
193 db_set_active($key);
194 $db = parse_url($value);
195
196 if ('mysql' == $db['scheme']) {
197 // MySQL
198 $database_type = 'MySQL';
199 $database_version = db_version();
200 }
201 elseif ('mysqli' == $db['scheme']) {
202 // MySQLi
203 $database_type = 'MySQLi';
204 $database_version = db_version();
205 }
206 elseif ('pgsql' == $db['scheme']) {
207 // PostgreSQL
208 $database_type = 'PostgreSQL';
209 $database_version = db_version();
210 }
211
212 $class_header = is_array($db_url) ? 'subheader' : '';
213 $class_title = is_array($db_url) ? 'subtitle' : '';
214 $class_subheader = is_array($db_url) ? 'subsubheader' : 'subheader';
215 $class_subtitle = is_array($db_url) ? 'subsubtitle' : 'subtitle';
216 if (is_array($db_url)) {
217 $rows[] = array(array('data' => $key, 'class' => 'subheader', 'colspan' => '2'));
218 }
219 $rows[] = array(array('data' => t('Host'), 'class' => $class_title), isset($url['port']) ? $db['host'] .':'. $db['port'] : $db['host']);
220 $rows[] = array(array('data' => t('Name'), 'class' => $class_title), substr($db['path'], 1));
221 $rows[] = array(array('data' => t('Type'), 'class' => $class_title), isset($database_type) ? $database_type : t('Unknown'));
222 $rows[] = array(array('data' => t('Version'), 'class' => $class_title), isset($database_version) ? $database_version : t('Unknown'));
223 if (('MySQL' == $database_type && version_compare($database_version, '4.1.0', '>=')) || 'MySQLi' == $database_type) {
224 $rows[] = array(array('data' => t('Charset'), 'class' => $class_title), db_result(db_query('SELECT CHARSET(USER())')));
225 $rows[] = array(array('data' => t('Collation'), 'class' => $class_title), db_result(db_query('SELECT COLLATION(USER())')));
226 }
227 if ('MySQL' == $database_type || 'MySQLi' == $database_type) {
228 $rows[] = array(array('data' => t('Permissions'), 'class' => $class_subheader, 'colspan' => '2'));
229 $rows[] = array(array('data' => t('Create temporary tables'), 'class' => $class_subtitle), preg_match('/(ALL PRIVILEGES|CREATE TEMPORARY TABLES)/i', db_result(db_query('SHOW GRANTS'))) ? t('Allowed') : t('Disallowed'));
230 $rows[] = array(array('data' => t('Lock tables'), 'class' => $class_subtitle), preg_match('/(ALL PRIVILEGES|LOCK TABLES)/i', db_result(db_query('SHOW GRANTS'))) ? t('Allowed') : t('Disallowed'));
231 }
232 if (!is_array($db_prefix)) {
233 $rows[] = array(array('data' => t('Table prefix'), 'class' => $class_title), $db_prefix);
234 }
235 else {
236 $rows[] = array(array('data' => t('Table prefixes'), 'class' => $class_subheader, 'colspan' => '2'));
237 foreach($db_prefix as $key => $value) {
238 if (strpos($value, '.') === FALSE) {
239 $rows[] = array(array('data' => $key, 'class' => $class_subtitle), $value);
240 }
241 else {
242 list($database_name, $database_prefix) = explode('.', $value);
243 if (substr($db['path'], 1) == $database_name) {
244 $rows[] = array(array('data' => $key, 'class' => $class_subtitle), $database_prefix);
245 }
246 }
247 }
248 }
249 }
250
251 $output .= '<h3>'. t('Database server') .'</h3>';
252 $output .= theme('table', NULL, $rows, array('class' => 'systeminfo'));
253 $output .= '<p>'. t('More information about the database server can be found <a href="@database" title="Display information about the database server.">here</a>.', array('@database' => url('admin/reports/systeminfo/database'))) .'</p>';
254
255
256 return $output;
257 }
258
259
260 /**
261 * Menu callback of page 'Drupal'.
262 */
263 function systeminfo_display_drupal() {
264
265 drupal_add_css(drupal_get_path('module', 'systeminfo') .'/systeminfo.css');
266
267 $output = '<p>'. t('Information about the drupal installation.') .'</p>';
268
269
270 // Users
271 $header = array(t('Group'), t('Accounts'));
272 $rows = array();
273 $rows[] = array(t('Users'), db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE uid != 0")));
274 $rows[] = array(array('data' => t('Status'), 'class' => 'subheader', 'colspan' => '2'));
275 $rows[] = array(array('data' => t('Active'), 'class' => 'subtitle'), db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE uid != 0 AND status = 1")));
276 $rows[] = array(array('data' => t('Already logged in'), 'class' => 'subsubtitle'), db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE uid != 0 AND status = 1 AND login != 0")));
277 $rows[] = array(array('data' => t('Not yet logged in'), 'class' => 'subsubtitle'), db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE uid != 0 AND status = 1 AND login = 0")));
278 $rows[] = array(array('data' => t('Blocked'), 'class' => 'subtitle'), db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE uid != 0 AND status = 0")));
279 $rows[] = array(array('data' => t('Roles'), 'class' => 'subheader', 'colspan' => '2'));
280 foreach (user_roles() as $rid => $name) {
281 if ($rid != DRUPAL_ANONYMOUS_RID) {
282 $count = $rid != DRUPAL_AUTHENTICATED_RID ? db_result(db_query("SELECT COUNT(uid) FROM {users_roles} WHERE rid = %d", $rid)) : db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE uid != 0"));
283 $rows[] = array(array('data' => $name, 'class' => 'subtitle'), $count);
284 }
285 }
286
287 $output .= '<h3>'. t('Users') .'</h3>';
288 $output .= theme('table', $header, $rows, array('class' => 'systeminfo'));
289
290
291 // Roles
292 $header = array(t('Name'), t('Permissions'));
293 $rows = array();
294 foreach (user_roles() as $rid => $name) {
295 $role_permissions = user_role_permissions(array($rid => $name));
296 $perms = array();
297 foreach ($role_permissions[$rid] as $perm => $tmp) {
298 $perms[] = $perm;
299 }
300 $rows[] = array($name, !empty($perms) ? theme('item_list', $perms) : '');
301 }
302
303 $output .= '<h3>'. t('Roles') .'</h3>';
304 $output .= theme('table', $header, $rows, array('class' => 'systeminfo'));
305
306
307 // Modules
308 $header = array(t('Name'), t('Version'), t('Filename'), t('Weight'));
309 $rows = array();
310 foreach (module_list() as $module) {
311 $file = db_fetch_object(db_query("SELECT info, filename, weight FROM {system} WHERE type = 'module' AND name = '%s'", $module));
312 $file->info = unserialize($file->info);
313 $rows[] = array($file->info['name'], $file->info['version'], $file->filename, $file->weight);
314 }
315
316 $output .= '<h3>'. t('Modules') .'</h3>';
317 $output .= theme('table', $header, $rows, array('class' => 'systeminfo'));
318
319
320 // Themes
321 $header = array(t('Name'), t('Version'), t('Filename'));
322 $rows = array();
323 foreach (list_themes() as $theme) {
324 if ($theme->status) {
325 $rows[] = array($theme->info['name'], $theme->info['version'], $theme->filename);
326 }
327 }
328
329 $output .= '<h3>'. t('Themes') .'</h3>';
330 $output .= theme('table', $header, $rows, array('class' => 'systeminfo'));
331
332
333 return $output;
334 }
335
336
337 /**
338 * Menu callback of page 'Web server'.
339 */
340 function systeminfo_display_webserver() {
341
342 return '';
343 }
344
345
346 /**
347 * Menu callback of page 'PHP'.
348 */
349 function systeminfo_display_php() {
350
351 phpinfo();
352 exit();
353 }
354
355
356 /**
357 * Menu callback of page 'Database'.
358 */
359 function systeminfo_display_database() {
360 global $db_url;
361
362 $output = '<p>'. t('Information about the database.') .'</p>';
363
364 $database = is_array($db_url) ? $db_url : array('default' => $db_url);
365 foreach ($database as $key => $value) {
366 db_set_active($key);
367 $db = parse_url($value);
368
369 if (is_array($db_url)) {
370 $output .= '<h3>'. t('Database') .' <em>'. $key .'</em></h3>';
371 }
372
373 // Show status
374 $rows = array();
375 $result = db_query('SHOW STATUS');
376 while ($var = db_fetch_array($result)) {
377 $header = array();
378 $row = array();
379 foreach ($var as $var_key => $var_value) {
380 $header[] = $var_key;
381 $row[] = $var_value;
382 }
383 $rows[] = $row;
384 }
385 $output .= '<h4>SHOW STATUS</h4>';
386 $output .= '<p>'. theme('table', $header, $rows) .'</p>';
387
388 if ('mysql' == $db['scheme'] || 'mysqli' == $db['scheme']) {
389 // Show table status
390 $rows = array();
391 $result = db_query('SHOW TABLE STATUS');
392 while ($var = db_fetch_array($result)) {
393 $header = array();
394 $row = array();
395 foreach ($var as $var_key => $var_value) {
396 $header[] = $var_key;
397 $row[] = $var_value;
398 }
399 $rows[] = $row;
400 }
401 $output .= '<h4>SHOW TABLE STATUS</h4>';
402 $output .= '<p>'. theme('table', $header, $rows) .'</p>';
403 }
404
405 if ('mysql' == $db['scheme'] || 'mysqli' == $db['scheme']) {
406 // Show variables
407 $rows = array();
408 $result = db_query('SHOW VARIABLES');
409 while ($var = db_fetch_array($result)) {
410 $header = array();
411 $row = array();
412 foreach ($var as $var_key => $var_value) {
413 $header[] = $var_key;
414 $row[] = $var_value;
415 }
416 $rows[] = $row;
417 }
418 $output .= '<h4>SHOW VARIABLES</h4>';
419 $output .= '<p>'. theme('table', $header, $rows) .'</p>';
420 }
421 }
422
423 return $output;
424 }

  ViewVC Help
Powered by ViewVC 1.1.2