PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.2.26
Adminify – White Label, Admin Menu Editor, Login Customizer v4.2.26
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Modules / ServerInformation / ServerInformation.php

ServerInformation.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.2.26, at Inc/Modules/ServerInformation/ServerInformation.php

501 lines 15.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PXLBSAdminify\Inc\Modules\ServerInformation;
4
5 use PXLBSAdminify\Inc\Utils;
6 use PXLBSAdminify\Inc\Modules\ServerInformation\ServerInfo_WP_Details;
7 use PXLBSAdminify\Inc\Modules\ServerInformation\ServerInfo_Server_Details;
8 use PXLBSAdminify\Inc\Modules\ServerInformation\ServerInfo_PHP_INI_Details;
9 use PXLBSAdminify\Inc\Modules\ServerInformation\ServerInfo_Htaccess_Details;
10 use PXLBSAdminify\Inc\Modules\ServerInformation\ServerInfo_Robots_Details;
11 use PXLBSAdminify\Inc\Modules\ServerInformation\ServerInfo_Error_Logs_Details;
12
13 // no direct access allowed
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 /**
19 * PXLBSAdminify
20 *
21 * @package Server Information
22 *
23 * @author WP Adminify <support@wpadminify.com>
24 */
25
26 class ServerInformation {
27
28 private $url;
29 public $prefix = 'pxlbsadminify_server_info';
30
31 public function __construct() {
32 // if ( is_multisite() && ! is_network_admin() ) {
33 // return; // only display to network admin if multisite is enbaled
34 // }
35
36 $this->url = PXLBSADMINIFY_URL . 'Inc/Modules/ServerInformation';
37 add_action( 'adminify_loaded', [ $this, 'server_info_menu' ] );
38
39 if ( is_admin() ) {
40 add_action( 'admin_enqueue_scripts', [ $this, 'server_info_styles' ], 99999 );
41
42 // Refresh Debug Log
43 add_action( 'wp_ajax_pxlbsadminify_error_log_content_refresh', [ $this, 'pxlbsadminify_error_log_content_refresh' ] );
44
45 // Clear Debug Log
46 add_action( 'wp_ajax_pxlbsadminify_error_log_content_clear', [ $this, 'pxlbsadminify_error_log_content_clear' ] );
47 }
48 }
49
50
51
52 /**
53 * Server Information Script/Styles
54 *
55 * @return void
56 */
57 public function server_info_styles() {
58 global $pagenow;
59
60 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check, no state change.
61 $current_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
62 if ( ( 'admin.php' === $pagenow ) && ( 'adminify-server-info' === $current_page ) ) {
63 echo '<style>.wp-adminify_page_adminify-server-info .adminify-header-inner{padding:0;}.wp-adminify_page_adminify-server-info .adminify-field-subheading{font-size:20px; padding-left:0;}.wp-adminify_page_adminify-server-info .adminify-nav,.wp-adminify_page_adminify-server-info .adminify-search,.wp-adminify_page_adminify-server-info .adminify-footer,.wp-adminify_page_adminify-server-info .adminify-reset-all,.wp-adminify_page_adminify-server-info .adminify-expand-all,.wp-adminify_page_adminify-server-info .adminify-header-left,.wp-adminify_page_adminify-server-info .adminify-reset-section,.wp-adminify_page_adminify-server-info .adminify-nav-background{display: none !important;}.wp-adminify_page_adminify-server-info .adminify-nav-normal + .adminify-content{margin-left: 0;}
64
65 /* If needed for white top-bar */
66 .wp-adminify_page_adminify-server-info .adminify-header-inner {
67 background-color: #fafafa !important;
68 border-bottom: 1px solid #f5f5f5;
69 }
70 .wp-adminify .adminify-server-info .adminify-buttons{
71 display: none !important;
72 }
73 </style>';
74
75 wp_enqueue_script( 'adminify-error-logs', $this->url . '/error-logs.js', [ 'jquery' ], PXLBSADMINIFY_VER, true );
76 wp_localize_script( 'adminify-error-logs', 'PXLBSADMINIFY_ERROR_LOGS', $this->adminify_error_logs_object() );
77
78 wp_enqueue_style( 'adminify', \ADMINIFY_Setup::include_plugin_url( 'assets/css/style.min.css' ), [], PXLBSADMINIFY_VER, 'all' );
79 wp_enqueue_script( 'adminify', \ADMINIFY_Setup::include_plugin_url( 'assets/js/main.min.js' ), [ 'jquery' ], PXLBSADMINIFY_VER, true );
80 }
81 }
82
83
84
85 /**
86 * JS Object
87 *
88 * @return void
89 */
90 public function adminify_error_logs_object() {
91 return [
92 'ajax_url' => admin_url( 'admin-ajax.php' ),
93 'security_nonce' => wp_create_nonce( 'pxlbsadminify-error-logs-security-nonce' ),
94 'label_update' => esc_html__( 'Will be updated...', 'adminify' ),
95 'label_clear' => esc_html__( 'Will be cleared...', 'adminify' ),
96 'label_done' => esc_html__( 'Done!', 'adminify' ),
97 ];
98 }
99
100 public function server_info_menu() {
101 if ( ! class_exists( 'ADMINIFY' ) ) {
102 return;
103 }
104
105 // WP Adminify Server Infos Settings
106 \ADMINIFY::createOptions(
107 $this->prefix,
108 [
109
110 // Framework Title
111 'framework_title' => __( 'Adminify Server Info <small>by Jewel Theme</small>', 'adminify' ),
112 'framework_class' => 'adminify-server-info',
113
114 // menu settings
115 'menu_title' => 'Server Info',
116 'menu_slug' => 'adminify-server-info',
117 'menu_type' => 'submenu', // menu, submenu, options, theme, etc.
118 'menu_capability' => 'manage_options',
119 'menu_icon' => '',
120 'menu_position' => 59,
121 'menu_hidden' => false,
122 'menu_parent' => 'wp-adminify-settings',
123
124 // Footer Credits
125 'footer_text' => ' ',
126 'footer_after' => ' ',
127 'footer_credit' => ' ',
128
129 // menu extras
130 'show_bar_menu' => false,
131 'show_sub_menu' => false,
132 'show_in_network' => true,
133 'show_in_customizer' => false,
134
135 'show_search' => false,
136 'show_reset_all' => false,
137 'show_reset_section' => false,
138 'show_footer' => false,
139 'show_all_options' => false,
140 'show_form_warning' => false,
141 'sticky_header' => false,
142 'save_defaults' => false,
143 'ajax_save' => false,
144
145 // admin bar menu settings
146 'admin_bar_menu_icon' => '',
147 'admin_bar_menu_priority' => 45,
148
149 // database model
150 'database' => 'network', // options, transient, theme_mod, network(multisite support)
151 'transient_time' => 0,
152
153 // typography options
154 'enqueue_webfont' => false,
155 'async_webfont' => false,
156
157 // others
158 'output_css' => false,
159
160 // theme and wrapper classname
161 'nav' => 'normal',
162 'theme' => 'dark',
163 'class' => 'wp-adminify_page_adminify-server-info',
164 ]
165 );
166
167 // Server Info Section
168 \ADMINIFY::createSection(
169 $this->prefix,
170 [
171 'title' => 'Server Info',
172 'icon' => 'fas fa-rocket',
173 'fields' => [
174
175 [
176 'id' => 'server-info-tab',
177 'type' => 'tabbed',
178 'title' => '',
179 'tabs' => [
180
181 [
182 'title' => __( 'WordPress', 'adminify' ),
183 'icon' => 'fab fa-wordpress',
184 'fields' => [
185 [
186 'id' => 'wordpress',
187 'type' => 'callback',
188 'class' => 'adminify-one-col',
189 'function' => 'PXLBSAdminify\Inc\Modules\ServerInformation\ServerInformation::pxlbsadminify_wordpress_details',
190 ],
191 ],
192 ],
193 [
194 'title' => __( 'Server', 'adminify' ),
195 'icon' => 'fa fa-gear',
196 'fields' => [
197 [
198 'id' => 'server',
199 'type' => 'callback',
200 'class' => 'adminify-one-col',
201 'function' => 'PXLBSAdminify\Inc\Modules\ServerInformation\ServerInformation::pxlbsadminify_server_details',
202 ],
203 ],
204 ],
205 [
206 'title' => __( 'PHP Info', 'adminify' ),
207 'icon' => 'fa fa-gear',
208 'fields' => [
209 [
210 'id' => 'php_info',
211 'type' => 'callback',
212 'class' => 'adminify-one-col',
213 'function' => 'PXLBSAdminify\Inc\Modules\ServerInformation\ServerInformation::pxlbsadminify_get_phpinfo',
214 ],
215 ],
216 ],
217 [
218 'title' => __( 'MySQL', 'adminify' ),
219 'icon' => 'fa fa-gear',
220 'fields' => [
221 [
222 'id' => 'mysql_info',
223 'type' => 'callback',
224 'function' => 'PXLBSAdminify\Inc\Modules\ServerInformation\ServerInformation::pxlbsadminify_get_mysqlinfo',
225 ],
226 ],
227 ],
228 [
229 'title' => __( 'Constants', 'adminify' ),
230 'icon' => 'fa fa-gear',
231 'fields' => [
232 [
233 'id' => 'constants',
234 'type' => 'callback',
235 'class' => 'adminify-one-col',
236 'function' => 'PXLBSAdminify\Inc\Modules\ServerInformation\ServerInformation::pxlbsadminify_constant_details',
237 ],
238 ],
239 ],
240 [
241 'title' => __( '.htaccess File', 'adminify' ),
242 'icon' => 'fa fa-gear',
243 'fields' => [
244 [
245 'id' => 'htaccess',
246 'type' => 'callback',
247 'class' => 'adminify-one-col',
248 'function' => 'PXLBSAdminify\Inc\Modules\ServerInformation\ServerInformation::pxlbsadminify_htacces_details',
249 ],
250 ],
251 ],
252 [
253 'title' => __( 'php.ini File', 'adminify' ),
254 'icon' => 'fa fa-gear',
255 'fields' => [
256 [
257 'id' => 'php_ini',
258 'type' => 'callback',
259 'class' => 'adminify-one-col',
260 'function' => 'PXLBSAdminify\Inc\Modules\ServerInformation\ServerInformation::pxlbsadminify_php_ini_details',
261 ],
262 ],
263 ],
264 [
265 'title' => __( 'Robots.txt File', 'adminify' ),
266 'icon' => 'fa fa-gear',
267 'fields' => [
268 [
269 'id' => 'robots_txt',
270 'type' => 'callback',
271 'class' => 'adminify-one-col',
272 'function' => 'PXLBSAdminify\Inc\Modules\ServerInformation\ServerInformation::pxlbsadminify_robots_details',
273 ],
274 ],
275 ],
276 [
277 'title' => __( 'Error Logs', 'adminify' ),
278 'icon' => 'fa fa-gear',
279 'fields' => [
280 [
281 'id' => 'error_logs',
282 'type' => 'callback',
283 'class' => 'adminify-one-col',
284 'function' => '\PXLBSAdminify\Inc\Modules\ServerInformation\ServerInformation::pxlbsadminify_error_log_details',
285 ],
286 ],
287 ],
288
289 ],
290 ],
291
292 ],
293 ]
294 );
295 }
296
297
298 /**
299 * Server Details
300 */
301 public static function pxlbsadminify_server_details() {
302 new ServerInfo_Server_Details();
303 }
304
305
306 /**
307 * WordPress Details
308 */
309 public static function pxlbsadminify_wordpress_details() {
310 new ServerInfo_WP_Details();
311 }
312
313
314 /**
315 * Constant Details
316 */
317 public static function pxlbsadminify_constant_details() {
318 new ServerInfo_Constant_Details();
319 }
320
321 /**
322 * .htaccess file Details
323 */
324 public static function pxlbsadminify_htacces_details() {
325 new ServerInfo_Htaccess_Details();
326 }
327
328 /**
329 * php.ini file Details
330 */
331 public static function pxlbsadminify_php_ini_details() {
332 new ServerInfo_PHP_INI_Details();
333 }
334
335 /**
336 * Robots file Details
337 */
338 public static function pxlbsadminify_robots_details() {
339 new ServerInfo_Robots_Details();
340 }
341
342 /**
343 * Error Logs Details
344 */
345 public static function pxlbsadminify_error_log_details() {
346 new ServerInfo_Error_Logs_Details();
347 }
348
349 /**
350 * Error Logs Details
351 */
352 public static function pxlbsadminify_get_phpinfo() {
353 if ( ! class_exists( 'DOMDocument' ) ) {
354 echo '<div class="wrap" id="PHPinfo">';
355 echo '<h2>' . esc_html__( 'PHP', 'adminify' ) . ' ' . esc_html( phpversion() ) . '</h2>';
356 echo 'You need <a href="' . esc_url( 'http://php.net/manual/en/class.domdocument.php' ) . '" target="_blank">' . esc_html__('DOMDocument extension' , 'adminify') . '</a> to be enabled.';
357 echo '</div>';
358 } else {
359 ob_start();
360 phpinfo(); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_phpinfo -- intentional server-info display on a capability-gated admin screen.
361 $phpinfo = ob_get_contents();
362 ob_end_clean();
363
364 // Use DOMDocument to parse phpinfo()
365 $html = new \DOMDocument( '1.0', 'UTF-8' );
366 $internal_errors = libxml_use_internal_errors( true );
367 $html->loadHTML( $phpinfo );
368 libxml_use_internal_errors( $internal_errors );
369
370 // Style process
371 $tables = $html->getElementsByTagName( 'table' );
372 foreach ( $tables as $table ) {
373 $table->setAttribute( 'class', 'widefat' );
374 }
375
376 // We only need the <body>
377 $xpath = new \DOMXPath( $html );
378 $body = $xpath->query( '/html/body' );
379
380 // Save HTML fragment
381 $phpinfo_html = $html->saveXml( $body->item( 0 ) );
382
383 echo '<div class="wrap" id="PHPinfo">';
384 echo '<h2>' . esc_html__( 'PHP', 'adminify' ) . ' ' . esc_html( phpversion() ) . '</h2>';
385 echo wp_kses_post( Utils::kses_custom( $phpinfo_html ) );
386 echo '</div>';
387 }
388 }
389
390
391 /**
392 * Get MYSQL Information
393 *
394 * @return void
395 */
396 public static function pxlbsadminify_get_mysqlinfo() {
397 global $wpdb;
398 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query required for live server-info display; not cached intentionally.
399 $sqlversion = $wpdb->get_var( 'SELECT VERSION() AS version' );
400 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query required for live server-info display; not cached intentionally.
401 $mysqlinfo = $wpdb->get_results( 'SHOW VARIABLES' );
402
403 if ( is_rtl() ) { ?>
404 <style type="text/css">
405 #MYSQLinfo,
406 #MYSQLinfo table,
407 #MYSQLinfo th,
408 #MYSQLinfo td {
409 direction: ltr;
410 text-align: left;
411 }
412
413 #MYSQLinfo h2 {
414 padding: 0.5em 0 0;
415 }
416 </style>
417 <?php
418 }
419 echo '<div class="wrap" id="MYSQLinfo" >' . "\n";
420 echo '<h2>' . esc_html__( 'MYSQL', 'adminify' ) . ' ' . esc_html( $sqlversion ) . '</h2>';
421
422 if ( $mysqlinfo ) {
423 echo '<br class="clear" />' . "\n";
424 echo '<table class="widefat" dir="ltr">' . "\n";
425 echo '<thead><tr><th>' . esc_html__( 'Variable Name', 'adminify' ) . '</th><th>' . esc_html__( 'Value', 'adminify' ) . '</th></tr></thead><tbody>' . "\n";
426 foreach ( $mysqlinfo as $info ) {
427 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>' . esc_html( $info->Variable_name ) . '</td><td>' . esc_html( htmlspecialchars( $info->Value ) ) . '</td></tr>' . "\n";
428 }
429 echo '</tbody></table>' . "\n";
430 }
431 echo '</div>' . "\n";
432 }
433
434
435 // Refresh Button Ajax
436 public function pxlbsadminify_error_log_content_refresh() {
437 if ( defined( 'DOING_AJAX' ) && DOING_AJAX && check_ajax_referer( 'pxlbsadminify-error-logs-security-nonce', 'security' ) > 0 ) {
438 // Security check - only administrators can access error logs
439 if ( ! current_user_can( 'manage_options' ) ) {
440 wp_send_json_error( array( 'message' => __( 'You do not have permission to perform this action.', 'adminify' ) ) );
441 }
442
443 if ( ! empty( $_POST['command'] ) ) {
444 $action = sanitize_key( $_POST['command'] );
445
446 $file_content = '';
447
448 // Check for user refreshing request
449 if ( $action == 'refresh_error_log' ) {
450
451 // Get the wp "debug.log" file
452 $file = ServerInfo_Error_Logs_Details::custom_error_log();
453
454 // Get the wp "debug.log" file content
455 $file_content = ServerInfo_Error_Logs_Details::custom_error_log_content( $file );
456 }
457
458 wp_send_json( [ 'file_content' => $file_content ] );
459 }
460 }
461
462 die();
463 }
464
465
466
467 public function pxlbsadminify_error_log_content_clear() {
468 if ( defined( 'DOING_AJAX' ) && DOING_AJAX && check_ajax_referer( 'pxlbsadminify-error-logs-security-nonce', 'security' ) > 0 ) {
469 // Security check - only administrators can clear error logs
470 if ( ! current_user_can( 'manage_options' ) ) {
471 wp_send_json_error( array( 'message' => __( 'You do not have permission to perform this action.', 'adminify' ) ) );
472 }
473
474 if ( ! empty( $_POST['command'] ) ) {
475 $file_content = '';
476 $action = sanitize_key( $_POST['command'] );
477 // Check for user clearing request
478 if ( $action == 'clear_error_log' ) {
479
480 // Call wp file system
481 global $wp_filesystem;
482 WP_Filesystem();
483
484 // Get the wp "debug.log" file
485 $file = ServerInfo_Error_Logs_Details::custom_error_log();
486
487 // Save no content to "debug.log" file the clear the file content
488 $wp_filesystem->put_contents( $file, '', 0644 );
489
490 // Get the wp "debug.log" file content
491 $file_content = ServerInfo_Error_Logs_Details::custom_error_log_content( $file );
492 }
493
494 return wp_send_json( [ 'file_content' => $file_content ] );
495 }
496 }
497
498 die();
499 }
500 }
501