-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiserver.php
599 lines (532 loc) · 28.7 KB
/
iserver.php
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
<?php
/*
Plugin Name: iServer
Plugin URI: https://iserver.infernal.site/
Description: Display Information About Your Tech Stack on Your WordPress Dashboard.
Version: 1.66
Author: iNfernalSoft
Author URI: https://infernalsoft.co.uk/
Text Domain: iserver
*/
/*
Copyright 2023 iNfernalSoft LTD.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the
Free Software Foundation Europe e.V.
Schönhauser Allee 6/7
Stairway 2, 5. floor
10119 Berlin
Germany
Phone: +49-30-27595290
*/
### Create Text Domain For Translations
add_action('init', 'iserver_textdomain');
function iserver_textdomain() {
load_plugin_textdomain( 'iserver' );
}
### Function: iServer Menu
add_action('admin_menu', 'iserver_menu');
function iserver_menu() {
if (function_exists('add_submenu_page')) {
add_submenu_page('index.php', __('iServer', 'iserver'), __('iServer', 'iserver'), 'add_users', 'iserver/iserver.php', 'display_iserver');
}
}
### Function: Enqueue ServerInfo JavaScripts In WP-Admin
add_action('admin_enqueue_scripts', 'iserver_scripts_admin');
function iserver_scripts_admin($hook_suffix) {
$iserver_admin_pages = array('dashboard_page_iserver/iserver');
if(in_array($hook_suffix, $iserver_admin_pages)) {
wp_enqueue_script('iserver', plugins_url('iserver/iserver-js.js'), array('jquery'), '1.60', true);
}
}
### Display iServer Admin Page
function display_iserver() {
get_generalinfo();
get_phpinfo();
get_mysqlinfo();
get_memcachedinfo();
}
### Get General Information
function get_generalinfo() {
global $is_IIS;
if( is_rtl() ) : ?>
<style type="text/css">
#GeneralOverview table,
#GeneralOverview th,
#GeneralOverview td {
direction: ltr;
text-align: left;
}
#GeneralOverview h2 {
padding: 0.5em 0 0;
}
</style>
<?php endif;
?>
<div class="wrap" id="GeneralOverview">
<h2><?php _e('General Overview','iserver'); ?></h2>
<?php iserver_subnavi(); ?>
<br class="clear" />
<table class="widefat">
<thead>
<tr>
<th><?php _e('Variable Name', 'iserver'); ?></th>
<th><?php _e('Value', 'iserver'); ?></th>
<th><?php _e('Variable Name', 'iserver'); ?></th>
<th><?php _e('Value', 'iserver'); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td><?php _e('OS', 'iserver'); ?></td>
<td><?php echo PHP_OS; ?></td>
<td><?php _e('Database Data Disk Usage', 'iserver'); ?></td>
<td><?php echo format_filesize(get_mysql_data_usage()); ?></td>
</tr>
<tr class="alternate">
<td><?php _e('Server', 'iserver'); ?></td>
<td><?php echo $_SERVER["SERVER_SOFTWARE"]; ?></td>
<td><?php _e('Database Index Disk Usage', 'iserver'); ?></td>
<td><?php echo format_filesize(get_mysql_index_usage()); ?></td>
</tr>
<tr>
<td>PHP</td>
<td>v<?php echo PHP_VERSION; ?></td>
<td><?php _e('MYSQL Maximum Packet Size', 'iserver'); ?></td>
<td><?php echo format_filesize(get_mysql_max_allowed_packet()); ?></td>
</tr>
<tr class="alternate">
<td>MYSQL</td>
<td>v<?php echo get_mysql_version(); ?></td>
<td><?php _e('MYSQL Maximum No. Connection', 'iserver'); ?></td>
<td><?php echo number_format_i18n(get_mysql_max_allowed_connections()); ?></td>
</tr>
<tr>
<td>GD</td>
<td><?php echo get_gd_version(); ?></td>
<td><?php _e( 'MYSQL Query Cache Size', 'iserver' ); ?></td>
<td><?php echo format_filesize( get_mysql_query_cache_size() ); ?></td>
</tr>
<tr class="alternate">
<td><?php _e('Server Hostname', 'iserver'); ?></td>
<td><?php echo $_SERVER['SERVER_NAME']; ?></td>
<td><?php _e('PHP Short Tag', 'iserver'); ?></td>
<td><?php echo get_php_short_tag(); ?></td>
</tr>
<tr>
<td><?php _e('Server IP:Port','iserver'); ?></td>
<td><?php echo ($is_IIS ? $_SERVER['LOCAL_ADDR'] : $_SERVER['SERVER_ADDR']); ?>:<?php echo $_SERVER['SERVER_PORT']; ?></td>
<td><?php _e('PHP Max Script Execute Time', 'iserver'); ?></td>
<td><?php echo get_php_max_execution(); ?>s</td>
</tr>
<tr class="alternate">
<td><?php _e('Server Document Root','iserver'); ?></td>
<td><?php echo $_SERVER['DOCUMENT_ROOT']; ?></td>
<td><?php _e('PHP Memory Limit', 'iserver'); ?></td>
<td><?php echo format_php_size(get_php_memory_limit()); ?></td>
</tr>
<tr>
<td><?php _e('Server Date/Time', 'iserver'); ?></td>
<td><?php echo mysql2date(sprintf(__('%s @ %s', 'wp-postratings'), get_option('date_format'), get_option('time_format')), current_time('mysql')); ?></td>
<td><?php _e('PHP Max Upload Size', 'iserver'); ?></td>
<td><?php echo format_php_size(get_php_upload_max()); ?></td>
</tr>
<tr class="alternate">
<td><?php _e('Server Load', 'iserver'); ?></td>
<td><?php echo get_serverLoad(); ?></td>
<td><?php _e('PHP Max Post Size', 'iserver'); ?></td>
<td><?php echo format_php_size(get_php_post_max()); ?></td>
</tr>
</tbody>
</table>
</div>
<?php
}
### Get PHP Information
function get_phpinfo() {
if( ! class_exists( 'DOMDocument' ) ) {
echo '<div class="wrap" id="PHPinfo" style="display: none;">';
echo '<h2>PHP ' . phpversion() . '</h2>';
iserver_subnavi();
echo 'You need <a href="http://php.net/manual/en/class.domdocument.php" target="_blank">DOMDocument extension</a> to be enabled.';
echo '</div>';
} else {
ob_start();
phpinfo();
$phpinfo = ob_get_contents();
ob_end_clean();
// Use DOMDocument to parse phpinfo()
$html = new DOMDocument( '1.0', 'UTF-8' );
$html->loadHTML( $phpinfo );
// Style process
$tables = $html->getElementsByTagName( 'table' );
foreach( $tables as $table ) {
$table->setAttribute( 'class', 'widefat' );
}
// We only need the <body>
$xpath = new DOMXPath($html);
$body = $xpath->query('/html/body');
// Save HTML fragment
$phpinfo_html = $html->saveXml( $body->item( 0 ) );
echo '<div class="wrap" id="PHPinfo" style="display: none;">';
echo '<h2>PHP ' . phpversion() . '</h2>';
iserver_subnavi();
echo $phpinfo_html;
echo '</div>';
}
}
### Get MYSQL Information
function get_mysqlinfo() {
global $wpdb;
$sqlversion = $wpdb->get_var("SELECT VERSION() AS version");
$mysqlinfo = $wpdb->get_results("SHOW VARIABLES");
if( is_rtl() ) : ?>
<style type="text/css">
#MYSQLinfo,
#MYSQLinfo table,
#MYSQLinfo th,
#MYSQLinfo td {
direction: ltr;
text-align: left;
}
#MYSQLinfo h2 {
padding: 0.5em 0 0;
}
</style>
<?php endif;
echo '<div class="wrap" id="MYSQLinfo" style="display: none;">'."\n";
echo "<h2>MYSQL $sqlversion</h2>\n";
iserver_subnavi();
if($mysqlinfo) {
echo '<br class="clear" />'."\n";
echo '<table class="widefat" dir="ltr">'."\n";
echo '<thead><tr><th>'.__('Variable Name', 'iserver').'</th><th>'.__('Value', 'iserver').'</th></tr></thead><tbody>'."\n";
foreach($mysqlinfo as $info) {
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>'.$info->Variable_name.'</td><td>'.htmlspecialchars($info->Value).'</td></tr>'."\n";
}
echo '</tbody></table>'."\n";
}
echo '</div>'."\n";
}
### Get memcached Information (Description from https://boxpanel.blueboxgrp.com/public/the_vault/index.php/memcached_Tips)
function get_memcachedinfo() {
echo '<div class="wrap" id="memcachedinfo" style="display: none;">'."\n";
if(class_exists('Memcache')) {
$memcached_obj = new Memcache;
$memcached_obj->addServer('localhost', 11211);
$memcachedinfo = $memcached_obj->getStats();
if( is_rtl() ) : ?>
<style type="text/css">
#memcachedinfo,
#memcachedinfo table,
#memcachedinfo th,
#memcachedinfo td {
direction: ltr;
text-align: left;
}
#memcachedinfo h2 {
padding: 0.5em 0 0;
}
</style>
<?php endif;
echo "<h2>memcached {$memcachedinfo['version']}</h2>\n";
iserver_subnavi();
if($memcachedinfo) {
$cache_hit= ( $memcachedinfo['cmd_get'] > 0 ? ( ( $memcachedinfo['get_hits'] / $memcachedinfo['cmd_get'] ) * 100 ) : 0 );
$cache_hit = round($cache_hit, 2);
$cache_miss = 100 - $cache_hit;
$usage = round((($memcachedinfo['bytes']/$memcachedinfo['limit_maxbytes']) * 100), 2);
$uptime = number_format_i18n(($memcachedinfo['uptime']/60/60/24));
echo '<br class="clear" />'."\n";
echo '<table class="widefat" dir="ltr">'."\n";
echo '<thead><tr><th>'.__('Variable Name', 'iserver').'</th><th>'.__('Value', 'iserver').'</th><th>'.__('Description', 'iserver').'</th></tr></thead><tbody>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>pid</td><td>'.$memcachedinfo['pid'].'</td><td>'.__('Process ID', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>uptime</td><td>'.$uptime.'</td><td>'.__('Number of days since the process was started', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>version</td><td>'.$memcachedinfo['version'].'</td><td>'.__('memcached version', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>rusage_user</td><td>'.$memcachedinfo['rusage_user'].'</td><td>'.__('Seconds the cpu has devoted to the process as the user', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>rusage_system</td><td>'.$memcachedinfo['rusage_system'].'</td><td>'.__('Seconds the cpu has devoted to the process as the system', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>curr_items</td><td>'.number_format_i18n($memcachedinfo['curr_items']).'</td><td>'.__('Total number of items currently in memcached', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>total_items</td><td>'.number_format_i18n($memcachedinfo['total_items']).'</td><td>'.__('Total number of items that have passed through memcached', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>bytes</td><td>'.format_filesize($memcachedinfo['bytes']).' ('.$usage.'%)</td><td>'.__('Memory size currently used by curr_items', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>limit_maxbytes</td><td>'.format_filesize($memcachedinfo['limit_maxbytes']).'</td><td>'.__('Maximum memory size allocated to memcached', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>curr_connections</td><td>'.number_format_i18n($memcachedinfo['curr_connections']).'</td><td>'.__('Total number of open connections to memcached', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>total_connections</td><td>'.number_format_i18n($memcachedinfo['total_connections']).'</td><td>'.__('Total number of connections opened since memcached started running', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>connection_structures</td><td>'.number_format_i18n($memcachedinfo['connection_structures']).'</td><td>'.__('Number of connection structures allocated by the server', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>cmd_get</td><td>'.number_format_i18n($memcachedinfo['cmd_get']).'</td><td>'.__('Total GET commands issued to the server', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>cmd_set</td><td>'.number_format_i18n($memcachedinfo['cmd_set']).'</td><td>'.__('Total SET commands issued to the server', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>cmd_flush</td><td>'.number_format_i18n($memcachedinfo['cmd_flush']).'</td><td>'.__('Total FLUSH commands issued to the server', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>get_hits</td><td>'.number_format_i18n($memcachedinfo['get_hits']).' ('.$cache_hit.'%)</td><td>'.__('Total number of times a GET command was able to retrieve and return data', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>get_misses</td><td>'.number_format_i18n($memcachedinfo['get_misses']).' ('.$cache_miss.'%)</td><td>'.__('Total number of times a GET command was unable to retrieve and return data', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>delete_hits</td><td>'.number_format_i18n($memcachedinfo['delete_hits']).'</td><td>'.__('Total number of times a DELETE command was able to delete data', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>delete_misses</td><td>'.number_format_i18n($memcachedinfo['delete_misses']).'</td><td>'.__('Total number of times a DELETE command was unable to delete data', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>incr_hits</td><td>'.number_format_i18n($memcachedinfo['incr_hits']).'</td><td>'.__('Total number of times a INCR command was able to increment a value', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>incr_misses</td><td>'.number_format_i18n($memcachedinfo['incr_misses']).'</td><td>'.__('Total number of times a INCR command was unable to increment a value', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>decr_hits</td><td>'.number_format_i18n($memcachedinfo['decr_hits']).'</td><td>'.__('Total number of times a DECR command was able to decrement a value', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>decr_misses</td><td>'.number_format_i18n($memcachedinfo['decr_misses']).'</td><td>'.__('Total number of times a DECR command was unable to decrement a value', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>cas_hits</td><td>'.number_format_i18n($memcachedinfo['cas_hits']).'</td><td>'.__('Total number of times a CAS command was able to compare and swap data', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>cas_misses</td><td>'.number_format_i18n($memcachedinfo['cas_misses']).'</td><td>'.__('Total number of times a CAS command was unable to compare and swap data', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>cas_badval</td><td>'.number_format_i18n($memcachedinfo['cas_badval']).'</td><td>'.__('N/A', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>bytes_read</td><td>'.format_filesize($memcachedinfo['bytes_read']).'</td><td>'.__('Total number of bytes input into the server', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>bytes_written</td><td>'.format_filesize($memcachedinfo['bytes_written']).'</td><td>'.__('Total number of bytes written by the server', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>evictions</td><td>'.number_format_i18n($memcachedinfo['evictions']).'</td><td>'.__('Number of valid items removed from cache to free memory for new items', 'iserver').'</td></tr>'."\n";
echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>reclaimed</td><td>'.number_format_i18n($memcachedinfo['reclaimed']).'</td><td>'.__('Number of items reclaimed', 'iserver').'</td></tr>'."\n";
echo '</tbody></table>'."\n";
}
}
echo '</div>'."\n";
}
### WP-Server Sub Navigation
function iserver_subnavi($display = true) {
$output = '<p style="text-align: center">';
$output .= '<a href="#DisplayGeneral" onclick="toggle_general(); return false;">'.__('Display General Overview', 'iserver').'</a>';
$output .= ' - <a href="#DisplayPHP" onclick="toggle_php(); return false;">'.__('Display PHP Information', 'iserver').'</a>';
$output .= ' - <a href="#DisplayMYSQL" onclick="toggle_mysql(); return false;">'.__('Display MYSQL Information', 'iserver').'</a>';
if(class_exists('Memcache')) {
$output .= ' - <a href="#Displaymemcached" onclick="toggle_memcached(); return false;">'.__('Display memcached Information', 'iserver').'</a>';
}
$output .= '</p>';
if($display) {
echo $output;
} else {
return $output;
}
}
### Function: Format Bytes Into TiB/GiB/MiB/KiB/Bytes
if(!function_exists('format_filesize')) {
function format_filesize($rawSize) {
if($rawSize / 1099511627776 > 1) {
return number_format_i18n($rawSize/1099511627776, 1).' '.__('TiB', 'iserver');
} elseif($rawSize / 1073741824 > 1) {
return number_format_i18n($rawSize/1073741824, 1).' '.__('GiB', 'iserver');
} elseif($rawSize / 1048576 > 1) {
return number_format_i18n($rawSize/1048576, 1).' '.__('MiB', 'iserver');
} elseif($rawSize / 1024 > 1) {
return number_format_i18n($rawSize/1024, 1).' '.__('KiB', 'iserver');
} elseif($rawSize > 1) {
return number_format_i18n($rawSize, 0).' '.__('bytes', 'iserver');
} else {
return __('unknown', 'iserver');
}
}
}
### Function: Convert PHP Size Format to Localized
function format_php_size($size) {
if (!is_numeric($size)) {
if (strpos($size, 'M') !== false) {
$size = intval($size)*1024*1024;
} elseif (strpos($size, 'K') !== false) {
$size = intval($size)*1024;
} elseif (strpos($size, 'G') !== false) {
$size = intval($size)*1024*1024*1024;
}
}
return is_numeric($size) ? format_filesize($size) : $size;
}
### Function: Get PHP Short Tag
if(!function_exists('get_php_short_tag')) {
function get_php_short_tag() {
if(ini_get('short_open_tag')) {
$short_tag = __('On', 'iserver');
} else {
$short_tag = __('Off', 'iserver');
}
return $short_tag;
}
}
### Function: Get PHP Max Upload Size
if(!function_exists('get_php_upload_max')) {
function get_php_upload_max() {
if(ini_get('upload_max_filesize')) {
$upload_max = ini_get('upload_max_filesize');
} else {
$upload_max = __('N/A', 'iserver');
}
return $upload_max;
}
}
### Function: Get PHP Max Post Size
if(!function_exists('get_php_post_max')) {
function get_php_post_max() {
if(ini_get('post_max_size')) {
$post_max = ini_get('post_max_size');
} else {
$post_max = __('N/A', 'iserver');
}
return $post_max;
}
}
### Function: PHP Maximum Execution Time
if(!function_exists('get_php_max_execution')) {
function get_php_max_execution() {
if(ini_get('max_execution_time')) {
$max_execute = ini_get('max_execution_time');
} else {
$max_execute = __('N/A', 'iserver');
}
return $max_execute;
}
}
### Function: PHP Memory Limit
if(!function_exists('get_php_memory_limit')) {
function get_php_memory_limit() {
if(ini_get('memory_limit')) {
$memory_limit = ini_get('memory_limit');
} else {
$memory_limit = __('N/A', 'iserver');
}
return $memory_limit;
}
}
### Function: Get MYSQL Version
if(!function_exists('get_mysql_version')) {
function get_mysql_version() {
global $wpdb;
return $wpdb->get_var("SELECT VERSION() AS version");
}
}
### Function: Get MYSQL Data Usage
if(!function_exists('get_mysql_data_usage')) {
function get_mysql_data_usage() {
global $wpdb;
$data_usage = 0;
$tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
foreach($tablesstatus as $tablestatus) {
$data_usage += $tablestatus->Data_length;
}
return $data_usage;
}
}
### Function: Get MYSQL Index Usage
if(!function_exists('get_mysql_index_usage')) {
function get_mysql_index_usage() {
global $wpdb;
$index_usage = 0;
$tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
foreach($tablesstatus as $tablestatus) {
$index_usage += $tablestatus->Index_length;
}
return $index_usage;
}
}
### Function: Get MYSQL Max Allowed Packet
if(!function_exists('get_mysql_max_allowed_packet')) {
function get_mysql_max_allowed_packet() {
global $wpdb;
$packet_max_query = $wpdb->get_row("SHOW VARIABLES LIKE 'max_allowed_packet'");
return $packet_max_query->Value;
}
}
### Function:Get MYSQL Max Allowed Connections
if(!function_exists('get_mysql_max_allowed_connections')) {
function get_mysql_max_allowed_connections() {
global $wpdb;
$connection_max_query = $wpdb->get_row("SHOW VARIABLES LIKE 'max_connections'");
return $connection_max_query->Value;
}
}
### Function:Get MYSQL Query Cache Size
if(!function_exists('get_mysql_query_cache_size')) {
function get_mysql_query_cache_size() {
global $wpdb;
$query_cache_size_query = $wpdb->get_row( "SHOW VARIABLES LIKE 'query_cache_size'" );
return $query_cache_size_query->Value;
}
}
### Function: Get GD Version
if(!function_exists('get_gd_version')) {
function get_gd_version() {
if (function_exists('gd_info')) {
$gd = gd_info();
$gd = $gd["GD Version"];
} else {
ob_start();
phpinfo(8);
$phpinfo = ob_get_contents();
ob_end_clean();
$phpinfo = strip_tags($phpinfo);
$phpinfo = stristr($phpinfo,"gd version");
$phpinfo = stristr($phpinfo,"version");
$gd = substr($phpinfo,0,strpos($phpinfo,"\n"));
}
if(empty($gd)) {
$gd = __('N/A', 'iserver');
}
return $gd;
}
}
### Function: Get The Server Load
if(!function_exists('get_serverload')) {
function get_serverload() {
$server_load = '';
if(PHP_OS != 'WINNT' && PHP_OS != 'WIN32') {
if(@file_exists('/proc/loadavg') ) {
if ($fh = @fopen( '/proc/loadavg', 'r' )) {
$data = @fread( $fh, 6 );
@fclose( $fh );
$load_avg = explode( " ", $data );
$server_load = trim($load_avg[0]);
}
} else {
$data = @system('uptime');
preg_match('/(.*):{1}(.*)/', $data, $matches);
$load_arr = explode(',', $matches[2]);
$server_load = trim($load_arr[0]);
}
}
if(empty($server_load)) {
$server_load = __('N/A', 'iserver');
}
return $server_load;
}
}
### Function: Register ServerInfo Dashboard Widget
add_action('wp_dashboard_setup', 'iserver_register_dashboard_widget');
function iserver_register_dashboard_widget() {
if(current_user_can('manage_options')) {
wp_add_dashboard_widget('dashboard_iserver', __('Server Information', 'iserver'), 'wp_dashboard_iserver');
}
}
### Function: Print ServerInfo Dashboard Widget
function wp_dashboard_iserver() {
if( is_rtl() ) {
echo '<style type="text/css"> #iserver ul { padding-left: 15px !important; } </style>';
echo '<div id="iserver" style="direction: ltr; text-align: left;">';
} else {
echo '<div id="iserver">';
}
echo '<p><strong>'.__('General', 'iserver').'</strong></p>';
echo '<ul>';
echo '<li>'. __('OS', 'iserver').': <strong>'.PHP_OS.'</strong></li>';
echo '<li>'. __('Server', 'iserver').': <strong>'.$_SERVER["SERVER_SOFTWARE"].'</strong></li>';
echo '<li>'. __('Hostname', 'iserver').': <strong>'.$_SERVER['SERVER_NAME'].'</strong></li>';
echo '<li>'. __('IP:Port', 'iserver').': <strong>'.$_SERVER['SERVER_ADDR'].':'.$_SERVER['SERVER_PORT'].'</strong></li>';
echo '<li>'. __('Document Root', 'iserver').': <strong>'.$_SERVER['DOCUMENT_ROOT'].'</strong></li>';
echo '</ul>';
echo '<p><strong>PHP</strong></p>';
echo '<ul>';
echo '<li>v<strong>'.PHP_VERSION.'</strong></li>';
echo '<li>GD: <strong>'.get_gd_version().'</strong></li>';
echo '<li>'. __('Memory Limit', 'iserver').': <strong>'.format_php_size(get_php_memory_limit()).'</strong></li>';
echo '<li>'. __('Max Script Execute Time', 'iserver').': <strong>'.get_php_max_execution().'s</strong></li>';
echo '<li>'. __('Max Post Size', 'iserver').': <strong>'. format_php_size(get_php_post_max()).'</strong></li>';
echo '<li>'. __('Max Upload Size', 'iserver').': <strong>'.format_php_size(get_php_upload_max()).'</strong></li>';
echo '</ul>';
echo '<p><strong>MYSQL</strong></p>';
echo '<ul>';
echo '<li>v<strong>'.get_mysql_version().'</strong></li>';
echo '<li>'. __('Maximum No. Connections', 'iserver').': <strong>'.number_format_i18n(get_mysql_max_allowed_connections(), 0).'</strong></li>';
echo '<li>'. __('Maximum Packet Size', 'iserver').': <strong>'.format_filesize(get_mysql_max_allowed_packet()).'</strong></li>';
echo '<li>'. __('Data Disk Usage', 'iserver').': <strong>'.format_filesize(get_mysql_data_usage()).'</strong></li>';
echo '<li>'. __('Index Disk Usage', 'iserver').': <strong>'.format_filesize(get_mysql_index_usage()).'</strong></li>';
echo '</ul>';
echo '<p class="textright"><a href="'.admin_url('index.php?page=iserver/iserver.php').'" class="button">'.__('View all', 'iserver').'</a></p>';
echo '</div>';
}