PluginProbe
WP-ServerInfo / 1.30
WP-ServerInfo v1.30
3.0.0 trunk 1.00 1.30 1.31 1.40 1.50 1.65 1.66 2.0.0
wp-serverinfo / wp-serverinfo.php

wp-serverinfo.php in WP-ServerInfo 1.30, at wp-serverinfo.php

506 lines 17.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP-ServerInfo
4 Plugin URI: http://lesterchan.net/portfolio/programming/php/
5 Description: Display your host's server PHP and MYSQL information (integrated into WordPress Admin Style) on your WordPress dashboard.
6 Version: 1.30
7 Author: Lester 'GaMerZ' Chan
8 Author URI: http://lesterchan.net
9 */
10
11
12 /*
13 Copyright 2008 Lester Chan (email : lesterchan@gmail.com)
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 */
29
30
31 ### Create Text Domain For Translations
32 add_action('init', 'serverinfo_textdomain');
33 function serverinfo_textdomain() {
34 load_plugin_textdomain('wp-serverinfo', 'wp-content/plugins/wp-serverinfo');
35 }
36
37
38 ### Function: WP-ServerInfo Menu
39 add_action('admin_menu', 'serverinfo_menu');
40 function serverinfo_menu() {
41 if (function_exists('add_submenu_page')) {
42 add_submenu_page('index.php', __('WP-ServerInfo', 'wp-serverinfo'), __('WP-ServerInfo', 'wp-serverinfo'), 1, 'wp-serverinfo/wp-serverinfo.php', 'display_serverinfo');
43 }
44 }
45
46
47 ### Function: ServerInfo Header
48 add_action('admin_head', 'serverinfo_head');
49 function serverinfo_head() {
50 wp_register_script('wp-serverinfo', '/wp-content/plugins/wp-serverinfo/serverinfo-js-packed.js', false, '1.30');
51 echo "\n".'<!-- Start Of Script Generated By WP-ServerInfo 1.30 -->'."\n";
52 wp_print_scripts('wp-serverinfo');
53 echo '<!-- End Of Script Generated By WP-ServerInfo 1.30 -->'."\n";
54 }
55
56
57 ### Display WP-ServerInfo Admin Page
58 function display_serverinfo() {
59 serverinfo_subnavi();
60 get_generalinfo();
61 get_phpinfo();
62 get_mysqlinfo();
63 }
64
65
66 ### Get General Information
67 function get_generalinfo() {
68 ?>
69 <div class="wrap" id="GeneralOverview">
70 <h2><?php _e('General Overview','wp-serverinfo'); ?></h2>
71 <br class="clear" />
72 <table class="widefat">
73 <thead>
74 <tr>
75 <th><?php _e('Variable Name', 'wp-serverinfo'); ?></th>
76 <th><?php _e('Value', 'wp-serverinfo'); ?></th>
77 <th><?php _e('Variable Name', 'wp-serverinfo'); ?></th>
78 <th><?php _e('Value', 'wp-serverinfo'); ?></th>
79 </tr>
80 </thead>
81 <tbody>
82 <tr>
83 <td><?php _e('OS', 'wp-serverinfo'); ?></td>
84 <td><?php echo PHP_OS; ?></td>
85 <td><?php _e('Database Data Disk Usage', 'wp-serverinfo'); ?></td>
86 <td><?php echo format_filesize(get_mysql_data_usage()); ?></td>
87 </tr>
88 <tr class="alternate">
89 <td><?php _e('Server', 'wp-serverinfo'); ?></td>
90 <td><?php echo $_SERVER["SERVER_SOFTWARE"]; ?></td>
91 <td><?php _e('Database Index Disk Usage', 'wp-serverinfo'); ?></td>
92 <td><?php echo format_filesize(get_mysql_index_usage()); ?></td>
93 </tr>
94 <tr>
95 <td>PHP</td>
96 <td>v<?php echo PHP_VERSION; ?></td>
97 <td><?php _e('MYSQL Maximum Packet Size', 'wp-serverinfo'); ?></td>
98 <td><?php echo format_filesize(get_mysql_max_allowed_packet()); ?></td>
99 </tr>
100 <tr class="alternate">
101 <td>MYSQL</td>
102 <td>v<?php echo get_mysql_version(); ?></td>
103 <td><?php _e('MYSQL Maximum No. Connection', 'wp-serverinfo'); ?></td>
104 <td><?php echo number_format_i18n(get_mysql_max_allowed_connections()); ?></td>
105 </tr>
106 <tr>
107 <td>GD</td>
108 <td><?php echo get_gd_version(); ?></td>
109 <td><?php _e('PHP Short Tag', 'wp-serverinfo'); ?></td>
110 <td><?php echo get_php_short_tag(); ?></td>
111 </tr>
112 <tr class="alternate">
113 <td><?php _e('Server Hostname', 'wp-serverinfo'); ?></td>
114 <td><?php echo $_SERVER['SERVER_NAME']; ?></td>
115 <td><?php _e('PHP Safe Mode', 'wp-serverinfo'); ?></td>
116 <td><?php echo get_php_safe_mode(); ?></td>
117 </tr>
118 <tr>
119 <td><?php _e('Server IP:Port','wp-serverinfo'); ?></td>
120 <td><?php echo $_SERVER['SERVER_ADDR']; ?>:<?php echo $_SERVER['SERVER_PORT']; ?></td>
121 <td><?php _e('PHP Magic Quotes GPC', 'wp-serverinfo'); ?></td>
122 <td><?php echo get_php_magic_quotes_gpc(); ?></td>
123 </tr>
124 <tr class="alternate">
125 <td><?php _e('Server Document Root','wp-serverinfo'); ?></td>
126 <td><?php echo $_SERVER['DOCUMENT_ROOT']; ?></td>
127 <td><?php _e('PHP Memory Limit', 'wp-serverinfo'); ?></td>
128 <td><?php echo get_php_memory_limit(); ?></td>
129 </tr>
130 <tr>
131 <td><?php _e('Server Admin', 'wp-serverinfo'); ?></td>
132 <td><?php echo $_SERVER['SERVER_ADMIN']; ?></td>
133 <td><?php _e('PHP Max Upload Size', 'wp-serverinfo'); ?></td>
134 <td><?php echo get_php_upload_max(); ?></td>
135 </tr>
136 <tr class="alternate">
137 <td><?php _e('Server Load', 'wp-serverinfo'); ?></td>
138 <td><?php echo get_ServerLoad(); ?></td>
139 <td><?php _e('PHP Max Post Size', 'wp-serverinfo'); ?></td>
140 <td><?php echo get_php_post_max(); ?></td>
141 </tr>
142 <tr>
143 <td><?php _e('Server Date/Time', 'wp-serverinfo'); ?></td>
144 <td><?php echo date(sprintf(__('%s @ %s', 'wp-serverinfo'), get_option('date_format'), get_option('time_format'))); ?></td>
145 <td><?php _e('PHP Max Script Execute Time', 'wp-serverinfo'); ?></td>
146 <td><?php echo get_php_max_execution(); ?>s</td>
147 </tr>
148 </tbody>
149 </table>
150 </div>
151 <?php
152 }
153
154
155 ### Get PHP Information
156 function get_phpinfo() {
157 ob_start();
158 phpinfo();
159 $phpinfo = ob_get_contents();
160 ob_end_clean();
161 // Strip Tags
162 $phpinfo = strip_tags($phpinfo, '<table><tr><th><td>');
163 // Strip Unwanted Contents
164 $phpinfo = eregi('<table border="0" cellpadding="3" width="600">(.*)</table>', $phpinfo, $data);
165 $phpinfo = $data[0];
166 // PHP Version Header
167 $phpinfo = preg_replace("!<table border=\"0\" cellpadding=\"3\" width=\"600\">\n<tr class=\"h\"><td>\n(.*?)\n</td></tr>\n</table>!", "<h2>$1</h2>", $phpinfo);
168 // Normal Header
169 $phpinfo = preg_replace("!<\/table>\n(.*?)\n<table border=\"0\" cellpadding=\"3\" width=\"600\">!", "</table>\n\n<br style=\"clear\" /><h2>$1</h2>\n<table class=\"widefat\">", $phpinfo);
170 // Fixed For Credits
171 $phpinfo = preg_replace("!</table>\n<table border=\"0\" cellpadding=\"3\" width=\"600\">\n<tr class=\"v\"><td>\n\n(.*?)</td></tr>\n</table>!", "<tr onmouseover=\"this.className='highlight'\" onmouseout=\"this.className=''\"><td colspan=\"2\">$1</td></tr>\n</table>", $phpinfo);
172 // Change Width To 100%
173 $phpinfo = str_replace('<table border="0" cellpadding="3" width="600">', '<br style="clear" /><table class="widefat">', $phpinfo);
174 // Replace TR Class
175 $phpinfo = str_replace('<tr class="h">', '<tr class="thead">', $phpinfo);
176 // Get Rid Of TD Class
177 $phpinfo = str_replace('<td class="e">', '<td>', $phpinfo);
178 $phpinfo = str_replace('<td class="v">', '<td>', $phpinfo);
179 // Remove PHP Credits, Will Add It In Later
180 $phpinfo = str_replace('PHP Credits', '', $phpinfo);
181 // Can't Find A Better Way Of Doing This
182 $phpinfo = str_replace("Configuration\nPHP Core", '<br /><h2>PHP Core Configuration</h2>', $phpinfo);
183 // Make Mouse Over Effect
184 $phpinfo = str_replace('<tr>', '<tr onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'">', $phpinfo);
185 echo '<div class="wrap" id="PHPinfo" style="display: none;">'."\n";
186 echo $phpinfo;
187 echo '</div>'."\n";
188 }
189
190
191 ### Get MYSQL Information
192 function get_mysqlinfo() {
193 global $wpdb;
194 $sqlversion = $wpdb->get_var("SELECT VERSION() AS version");
195 $mysqlinfo = $wpdb->get_results("SHOW VARIABLES");
196 echo '<div class="wrap" id="MYSQLinfo" style="display: none;">'."\n";
197 echo "<h2>MYSQL $sqlversion</h2>\n";
198 if($mysqlinfo) {
199 echo '<br class="clear" />'."\n";
200 echo '<table class="widefat">'."\n";
201 echo '<thead><tr><th>'.__('Variable Name', 'wp-serverinfo').'</th><th>'.__('Value', 'wp-serverinfo').'</th></tr></thead><tbody>'."\n";
202 foreach($mysqlinfo as $info) {
203 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>'.$info->Variable_name.'</td><td>'.htmlspecialchars($info->Value).'</td></tr>'."\n";
204 }
205 echo '</tbody></table>'."\n";
206 }
207 echo '</div>'."\n";
208 }
209
210
211 ### WP-Server Sub Navigation
212 function serverinfo_subnavi() {
213 ?>
214 <div class="wrap" style="text-align: center">
215 <a href="#DisplayGeneral" onclick="toggle_general(); return false;"><?php _e('Display General Overview', 'wp-serverinfo'); ?></a> - <a href="#DisplayPHP" onclick="toggle_php(); return false;"><?php _e('Display PHP Information', 'wp-serverinfo'); ?></a> - <a href="#DisplayMYSQL" onclick="toggle_mysql(); return false;"><?php _e('Display MYSQL Information', 'wp-serverinfo'); ?></a>
216 </div>
217 <?php
218 }
219
220
221 ### Function: Format Bytes Into TiB/GiB/MiB/KiB/Bytes
222 if(!function_exists('format_filesize')) {
223 function format_filesize($rawSize) {
224 if($rawSize / 1099511627776 > 1) {
225 return round($rawSize/1099511627776, 1).' '.__('TiB', 'wp-serverinfo');
226 } elseif($rawSize / 1073741824 > 1) {
227 return round($rawSize/1073741824, 1).' '.__('GiB', 'wp-serverinfo');
228 } elseif($rawSize / 1048576 > 1) {
229 return round($rawSize/1048576, 1).' '.__('MiB', 'wp-serverinfo');
230 } elseif($rawSize / 1024 > 1) {
231 return round($rawSize/1024, 1).' '.__('KiB', 'wp-serverinfo');
232 } elseif($rawSize > 1) {
233 return round($rawSize, 1).' '.__('bytes', 'wp-serverinfo');
234 } else {
235 return __('unknown', 'wp-serverinfo');
236 }
237 }
238 }
239
240
241 ### Function: Get PHP Short Tag
242 if(!function_exists('get_php_short_tag')) {
243 function get_php_short_tag() {
244 if(ini_get('short_open_tag')) {
245 $short_tag = __('On', 'wp-serverinfo');
246 } else {
247 $short_tag = __('Off', 'wp-serverinfo');
248 }
249 return $short_tag;
250 }
251 }
252
253
254 ### Function: Get PHP Safe Mode
255 if(!function_exists('get_php_safe_mode')) {
256 function get_php_safe_mode() {
257 if(ini_get('safe_mode')) {
258 $safe_mode = __('On', 'wp-serverinfo');
259 } else {
260 $safe_mode = __('Off', 'wp-serverinfo');
261 }
262 return $safe_mode;
263 }
264 }
265
266
267 ### Function: Get PHP Magic Quotes GPC
268 if(!function_exists('get_php_magic_quotes_gpc')) {
269 function get_php_magic_quotes_gpc() {
270 if(get_magic_quotes_gpc()) {
271 $magic_quotes_gpc = __('On', 'wp-serverinfo');
272 } else {
273 $magic_quotes_gpc = __('Off', 'wp-serverinfo');
274 }
275 return $magic_quotes_gpc;
276 }
277 }
278
279
280 ### Function: Get PHP Max Upload Size
281 if(!function_exists('get_php_upload_max')) {
282 function get_php_upload_max() {
283 if(ini_get('upload_max_filesize')) {
284 $upload_max = ini_get('upload_max_filesize');
285 } else {
286 $upload_max = __('N/A', 'wp-serverinfo');
287 }
288 return $upload_max;
289 }
290 }
291
292
293 ### Function: Get PHP Max Post Size
294 if(!function_exists('get_php_post_max')) {
295 function get_php_post_max() {
296 if(ini_get('post_max_size')) {
297 $post_max = ini_get('post_max_size');
298 } else {
299 $post_max = __('N/A', 'wp-serverinfo');
300 }
301 return $post_max;
302 }
303 }
304
305
306 ### Function: PHP Maximum Execution Time
307 if(!function_exists('get_php_max_execution')) {
308 function get_php_max_execution() {
309 if(ini_get('max_execution_time')) {
310 $max_execute = ini_get('max_execution_time');
311 } else {
312 $max_execute = __('N/A', 'wp-serverinfo');
313 }
314 return $max_execute;
315 }
316 }
317
318
319 ### Function: PHP Memory Limit
320 if(!function_exists('get_php_memory_limit')) {
321 function get_php_memory_limit() {
322 if(ini_get('memory_limit')) {
323 $memory_limit = ini_get('memory_limit');
324 } else {
325 $memory_limit = __('N/A', 'wp-serverinfo');
326 }
327 return $memory_limit;
328 }
329 }
330
331
332 ### Function: Get MYSQL Version
333 if(!function_exists('get_mysql_version')) {
334 function get_mysql_version() {
335 global $wpdb;
336 return $wpdb->get_var("SELECT VERSION() AS version");
337 }
338 }
339
340
341 ### Function: Get MYSQL Data Usage
342 if(!function_exists('get_mysql_data_usage')) {
343 function get_mysql_data_usage() {
344 global $wpdb;
345 $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
346 foreach($tablesstatus as $tablestatus) {
347 $data_usage += $tablestatus->Data_length;
348 }
349 if (!$data_usage) {
350 $data_usage = __('N/A', 'wp-serverinfo');
351 }
352 return $data_usage;
353 }
354 }
355
356
357 ### Function: Get MYSQL Index Usage
358 if(!function_exists('get_mysql_index_usage')) {
359 function get_mysql_index_usage() {
360 global $wpdb;
361 $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
362 foreach($tablesstatus as $tablestatus) {
363 $index_usage += $tablestatus->Index_length;
364 }
365 if (!$index_usage){
366 $index_usage = __('N/A', 'wp-serverinfo');
367 }
368 return $index_usage;
369 }
370 }
371
372
373 ### Function: Get MYSQL Max Allowed Packet
374 if(!function_exists('get_mysql_max_allowed_packet')) {
375 function get_mysql_max_allowed_packet() {
376 global $wpdb;
377 $packet_max_query = $wpdb->get_row("SHOW VARIABLES LIKE 'max_allowed_packet'");
378 $packet_max = $packet_max_query->Value;
379 if(!$packet_max) {
380 $packet_max = __('N/A', 'wp-serverinfo');
381 }
382 return $packet_max;
383 }
384 }
385
386
387 ### Function:Get MYSQL Max Allowed Connections
388 if(!function_exists('get_mysql_max_allowed_connections')) {
389 function get_mysql_max_allowed_connections() {
390 global $wpdb;
391 $connection_max_query = $wpdb->get_row("SHOW VARIABLES LIKE 'max_connections'");
392 $connection_max = $connection_max_query->Value;
393 if(!$connection_max) {
394 $connection_max = __('N/A', 'wp-serverinfo');
395 }
396 return $connection_max;
397 }
398 }
399
400
401 ### Function: Get GD Version
402 if(!function_exists('get_gd_version')) {
403 function get_gd_version() {
404 if (function_exists('gd_info')) {
405 $gd = gd_info();
406 $gd = $gd["GD Version"];
407 } else {
408 ob_start();
409 phpinfo(8);
410 $phpinfo = ob_get_contents();
411 ob_end_clean();
412 $phpinfo = strip_tags($phpinfo);
413 $phpinfo = stristr($phpinfo,"gd version");
414 $phpinfo = stristr($phpinfo,"version");
415 $gd = substr($phpinfo,0,strpos($phpinfo,"\n"));
416 }
417 if(empty($gd)) {
418 $gd = __('N/A', 'wp-serverinfo');
419 }
420 return $gd;
421 }
422 }
423
424
425 ### Function: Get The Server Load
426 if(!function_exists('get_serverload')) {
427 function get_serverload() {
428 if(PHP_OS != 'WINNT' && PHP_OS != 'WIN32') {
429 if(@file_exists('/proc/loadavg') ) {
430 if ($fh = @fopen( '/proc/loadavg', 'r' )) {
431 $data = @fread( $fh, 6 );
432 @fclose( $fh );
433 $load_avg = explode( " ", $data );
434 $server_load = trim($load_avg[0]);
435 }
436 } else {
437 $data = @system('uptime');
438 preg_match('/(.*):{1}(.*)/', $data, $matches);
439 $load_arr = explode(',', $matches[2]);
440 $server_load = trim($load_arr[0]);
441 }
442 }
443 if(!$server_load) {
444 $server_load = __('N/A', 'wp-serverinfo');
445 }
446 return $server_load;
447 }
448 }
449
450
451 ### Function: Register ServerInfo Dashboard Widget
452 add_action('wp_dashboard_setup', 'serverinfo_register_dashboard_widget');
453 function serverinfo_register_dashboard_widget() {
454 if(current_user_can('manage_options')) {
455 wp_register_sidebar_widget('dashboard_serverinfo', __('Server Information', 'wp-serverinfo'), 'dashboard_serverinfo', array('all_link' => 'index.php?page=wp-serverinfo/wp-serverinfo.php', 'width' => 'half', 'height' => 'single'));
456 }
457 }
458
459
460 ### Function: Add ServerInfo Dashboard Widget
461 add_filter('wp_dashboard_widgets', 'serverinfo_add_dashboard_widget');
462 function serverinfo_add_dashboard_widget($widgets) {
463 global $wp_registered_widgets;
464 if (!isset($wp_registered_widgets['dashboard_serverinfo']) || !current_user_can('manage_options')) {
465 return $widgets;
466 }
467 array_splice($widgets, 2, 0, 'dashboard_serverinfo');
468 return $widgets;
469 }
470
471
472 ### Function: Print ServerInfo Dashboard Widget
473 function dashboard_serverinfo($sidebar_args) {
474 global $wpdb;
475 extract($sidebar_args, EXTR_SKIP);
476 echo $before_widget;
477 echo $before_title;
478 echo $widget_name;
479 echo $after_title;
480 echo '<p><strong>General</strong></p>';
481 echo '<ul>';
482 echo '<li>'. __('OS', 'wp-serverinfo').': <strong>'.PHP_OS.'</strong></li>';
483 echo '<li>'. __('Server', 'wp-serverinfo').': <strong>'.$_SERVER["SERVER_SOFTWARE"].'</strong></li>';
484 echo '<li>'. __('Hostname', 'wp-serverinfo').': <strong>'.$_SERVER['SERVER_NAME'].'</strong></li>';
485 echo '<li>'. __('IP:Port', 'wp-serverinfo').': <strong>'.$_SERVER['SERVER_ADDR'].':'.$_SERVER['SERVER_PORT'].'</strong></li>';
486 echo '<li>'. __('Document Root', 'wp-serverinfo').': <strong>'.$_SERVER['DOCUMENT_ROOT'].'</strong></li>';
487 echo '</ul>';
488 echo '<p><strong>PHP</strong></p>';
489 echo '<ul>';
490 echo '<li>v<strong>'.PHP_VERSION.'</strong></li>';
491 echo '<li>GD: <strong>'.get_gd_version().'</strong></li>';
492 echo '<li>'. __('Magic Quotes GPC', 'wp-serverinfo').': <strong>'.get_php_magic_quotes_gpc().'</strong></li>';
493 echo '<li>'. __('Memory Limit', 'wp-serverinfo').': <strong>'.get_php_memory_limit().'</strong></li>';
494 echo '<li>'. __('Max Upload Size', 'wp-serverinfo').': <strong>'.get_php_upload_max().'</strong></li>';
495 echo '</ul>';
496 echo '<p><strong>MYSQL</strong></p>';
497 echo '<ul>';
498 echo '<li>v<strong>'.get_mysql_version().'</strong></li>';
499 echo '<li>'. __('Maximum No. Connections', 'wp-serverinfo').': <strong>'.number_format_i18n(get_mysql_max_allowed_connections()).'</strong></li>';
500 echo '<li>'. __('Maximum Packet Size', 'wp-serverinfo').': <strong>'.format_filesize(get_mysql_max_allowed_packet()).'</strong></li>';
501 echo '<li>'. __('Data Disk Usage', 'wp-serverinfo').': <strong>'.format_filesize(get_mysql_data_usage()).'</strong></li>';
502 echo '<li>'. __('Index Disk Usage', 'wp-serverinfo').': <strong>'.format_filesize(get_mysql_index_usage()).'</strong></li>';
503 echo '</ul>';
504 echo $after_widget;
505 }
506 ?>