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