| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Server Information Page Handler |
| 4 |
* |
| 5 |
* @package MainWP/Dashboard |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace MainWP\Dashboard; |
| 9 |
|
| 10 |
/** |
| 11 |
* Class MainWP Server_Information_Handler |
| 12 |
*/ |
| 13 |
class MainWP_Server_Information_Handler { |
| 14 |
|
| 15 |
// phpcs:disable WordPress.WP.AlternativeFunctions -- use system functions. |
| 16 |
|
| 17 |
/** |
| 18 |
* Gets Class Name. |
| 19 |
* |
| 20 |
* @return string __CLASS__ |
| 21 |
*/ |
| 22 |
public static function get_class_name() { |
| 23 |
return __CLASS__; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Gets current MainWP Plugin version. |
| 28 |
* |
| 29 |
* @return mixed $currentVersion verion number/ |
| 30 |
*/ |
| 31 |
public static function get_current_version() { |
| 32 |
$currentVersion = get_option( 'mainwp_plugin_version' ); |
| 33 |
return $currentVersion; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Gets current MainWP Dashboard version. |
| 38 |
* |
| 39 |
* @return mixed false|version |
| 40 |
*/ |
| 41 |
public static function get_mainwp_version() { |
| 42 |
|
| 43 |
if ( isset( $_SESSION['cachedVersion'] ) && isset( $_SESSION['cachedTime'] ) && ( null !== $_SESSION['cachedVersion'] ) && ( ( $_SESSION['cachedTime'] + ( 60 * 30 ) ) > time() ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.NonceVerification.Recommended |
| 44 |
return $_SESSION['cachedVersion']; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.NonceVerification.Recommended |
| 45 |
} |
| 46 |
include_once ABSPATH . '/wp-admin/includes/plugin-install.php'; |
| 47 |
$api = MainWP_System_Utility::get_plugin_theme_info( |
| 48 |
'plugin', |
| 49 |
array( |
| 50 |
'slug' => 'mainwp', |
| 51 |
'fields' => array( 'sections' => false ), |
| 52 |
'timeout' => 60, |
| 53 |
) |
| 54 |
); |
| 55 |
if ( is_object( $api ) && isset( $api->version ) ) { |
| 56 |
$_SESSION['cachedTime'] = time(); |
| 57 |
$_SESSION['cachedVersion'] = $api->version; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.NonceVerification.Recommended |
| 58 |
return $_SESSION['cachedVersion']; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.NonceVerification.Recommended |
| 59 |
} |
| 60 |
return false; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Checks if WP environment is Mutisilte or not. |
| 65 |
* |
| 66 |
* @return bool true|false. |
| 67 |
*/ |
| 68 |
public static function check_if_multisite() { |
| 69 |
$isMultisite = ! is_multisite() ? true : false; |
| 70 |
return $isMultisite; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Compares filesize. |
| 75 |
* |
| 76 |
* @param mixed $value1 First file size. |
| 77 |
* @param mixed $value2 Second file size. |
| 78 |
* @param null $operator Comparison operator. |
| 79 |
* |
| 80 |
* @return mixed version_compare() value. |
| 81 |
*/ |
| 82 |
public static function filesize_compare( $value1, $value2, $operator = null ) { |
| 83 |
if ( false !== strpos( $value1, 'G' ) ) { |
| 84 |
$value1 = preg_replace( '/[A-Za-z]/', '', $value1 ); |
| 85 |
$value1 = intval( $value1 ) * 1024; |
| 86 |
} else { |
| 87 |
$value1 = preg_replace( '/[A-Za-z]/', '', $value1 ); |
| 88 |
} |
| 89 |
|
| 90 |
if ( false !== strpos( $value2, 'G' ) ) { |
| 91 |
$value2 = preg_replace( '/[A-Za-z]/', '', $value2 ); |
| 92 |
$value2 = intval( $value2 ) * 1024; |
| 93 |
} else { |
| 94 |
$value2 = preg_replace( '/[A-Za-z]/', '', $value2 ); |
| 95 |
} |
| 96 |
|
| 97 |
return version_compare( $value1, $value2, $operator ); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Compares cURL SSL Version. |
| 102 |
* |
| 103 |
* @param mixed $version CURL SSL version number. |
| 104 |
* @param null $operator Comparison operator. |
| 105 |
* |
| 106 |
* @return mixed false|version |
| 107 |
*/ |
| 108 |
public static function curlssl_compare( $version, $operator ) { |
| 109 |
if ( function_exists( 'curl_version' ) ) { |
| 110 |
$ver = self::get_curl_ssl_version(); |
| 111 |
return version_compare( $ver, $version, $operator ); |
| 112 |
} |
| 113 |
return false; |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Gets file system method. |
| 118 |
* |
| 119 |
* @return string $fs File System Method. |
| 120 |
*/ |
| 121 |
public static function get_file_system_method() { |
| 122 |
$fs = get_filesystem_method(); |
| 123 |
|
| 124 |
return $fs; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Gets loaded PHP Extensions. |
| 129 |
*/ |
| 130 |
public static function get_loaded_php_extensions() { |
| 131 |
$extensions = get_loaded_extensions(); |
| 132 |
sort( $extensions ); |
| 133 |
echo esc_html( implode( ', ', $extensions ) ); |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Gets the WP_MEMORY_LIMIT value. |
| 138 |
* |
| 139 |
* @return mixed WP_MEMORY_LIMIT WordPress Memmory Limit. |
| 140 |
*/ |
| 141 |
public static function get_wordpress_memory_limit() { |
| 142 |
return WP_MEMORY_LIMIT; |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Method get_curl_version() |
| 147 |
* |
| 148 |
* Get current cURL Version. |
| 149 |
* |
| 150 |
* @return mixed $curlversion['version'] Currently installed cURL Version. |
| 151 |
*/ |
| 152 |
public static function get_curl_version() { |
| 153 |
$curlversion = curl_version(); |
| 154 |
|
| 155 |
return $curlversion['version']; |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* Method get_curl_ssl_version() |
| 160 |
* |
| 161 |
* Get current SSL Version installed. |
| 162 |
* |
| 163 |
* @return mixed $curlversion['ssl_version'] Currently installed SSL version. |
| 164 |
*/ |
| 165 |
public static function get_curl_ssl_version() { |
| 166 |
$curlversion = curl_version(); |
| 167 |
|
| 168 |
return $curlversion['ssl_version']; |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Method get_wordpress_version() |
| 173 |
* |
| 174 |
* Get current WordPress Version |
| 175 |
* |
| 176 |
* @return mixed $wp_version Current installed WordPress version |
| 177 |
*/ |
| 178 |
public static function get_wordpress_version() { |
| 179 |
|
| 180 |
/** |
| 181 |
* WordPress version. |
| 182 |
* |
| 183 |
* @global string |
| 184 |
*/ |
| 185 |
global $wp_version; |
| 186 |
|
| 187 |
return $wp_version; |
| 188 |
} |
| 189 |
|
| 190 |
/** |
| 191 |
* Method get_ssl_support() |
| 192 |
* |
| 193 |
* Get SSL Support. |
| 194 |
* |
| 195 |
* @return mixed Open SSL Extentions loaded. |
| 196 |
*/ |
| 197 |
public static function get_ssl_support() { |
| 198 |
return extension_loaded( 'openssl' ); |
| 199 |
} |
| 200 |
|
| 201 |
/** |
| 202 |
* Method get_ssl_warning() |
| 203 |
* |
| 204 |
* Get any SSL Warning Messages. |
| 205 |
* |
| 206 |
* @return string SSL Error message. |
| 207 |
* |
| 208 |
* @uses \MainWP\Dashboard\MainWP_System_Utility::get_openssl_conf() |
| 209 |
*/ |
| 210 |
public static function get_ssl_warning() { |
| 211 |
$conf = array( 'private_key_bits' => 2048 ); |
| 212 |
$conf_loc = MainWP_System_Utility::get_openssl_conf(); |
| 213 |
if ( ! empty( $conf_loc ) ) { |
| 214 |
$conf['config'] = $conf_loc; |
| 215 |
} |
| 216 |
$errors = array(); |
| 217 |
|
| 218 |
$general_verify_con = (int) get_option( 'mainwp_verify_connection_method', 0 ); |
| 219 |
|
| 220 |
if ( 2 !== $general_verify_con ) { |
| 221 |
if ( function_exists( 'openssl_pkey_new' ) ) { |
| 222 |
$res = openssl_pkey_new( $conf ); |
| 223 |
openssl_pkey_export( $res, $privkey, null, $conf ); |
| 224 |
|
| 225 |
$error = ''; |
| 226 |
while ( ( $errorRow = openssl_error_string() ) !== false ) { |
| 227 |
$error = $errorRow . "\n" . $error; |
| 228 |
} |
| 229 |
if ( ! empty( $error ) ) { |
| 230 |
$errors[] = $error; |
| 231 |
} |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
return empty( $errors ) ? '' : implode( ' - ', $errors ); |
| 236 |
} |
| 237 |
|
| 238 |
/** |
| 239 |
* To verify openssl working. |
| 240 |
* |
| 241 |
* @return bool Working status. |
| 242 |
*/ |
| 243 |
public static function get_openssl_working_status() { |
| 244 |
|
| 245 |
$ok = false; |
| 246 |
$general_verify_con = (int) get_option( 'mainwp_verify_connection_method', 0 ); |
| 247 |
if ( 2 === $general_verify_con ) { |
| 248 |
$ok = 1; |
| 249 |
} elseif ( function_exists( 'openssl_verify' ) && function_exists( 'openssl_pkey_new' ) ) { |
| 250 |
|
| 251 |
$conf = array( |
| 252 |
'private_key_bits' => 2048, |
| 253 |
); |
| 254 |
|
| 255 |
$conf_loc = MainWP_System_Utility::get_openssl_conf(); |
| 256 |
if ( ! empty( $conf_loc ) ) { |
| 257 |
$conf['config'] = $conf_loc; |
| 258 |
} |
| 259 |
|
| 260 |
$res = openssl_pkey_new( $conf ); |
| 261 |
|
| 262 |
@openssl_pkey_export( $res, $privkey, null, $conf ); // phpcs:ignore -- prevent warning. |
| 263 |
$details = openssl_pkey_get_details( $res ); |
| 264 |
|
| 265 |
if ( is_array( $details ) && isset( $details['key'] ) ) { |
| 266 |
$publicKey = $details['key']; |
| 267 |
$data = 'working status'; |
| 268 |
openssl_sign( $data, $signature, $privkey ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. |
| 269 |
if ( ! empty( $signature ) ) { |
| 270 |
$ok = openssl_verify( $data, $signature, $publicKey ); |
| 271 |
} |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
return 1 === $ok; |
| 276 |
} |
| 277 |
|
| 278 |
/** |
| 279 |
* Method is_openssl_config_warning() |
| 280 |
* |
| 281 |
* Check if open ssl is configured correctly. |
| 282 |
* |
| 283 |
* @return boolean true|false. |
| 284 |
*/ |
| 285 |
public static function is_openssl_config_warning() { |
| 286 |
$ssl_warning = self::get_ssl_warning(); |
| 287 |
if ( '' !== $ssl_warning ) { |
| 288 |
if ( false !== stristr( $ssl_warning, 'No such file or directory found', 'mainwp' ) || false !== stristr( $ssl_warning, 'No such process', 'mainwp' ) || false !== stristr( $ssl_warning, 'no such file', 'mainwp' ) ) { |
| 289 |
return true; |
| 290 |
} |
| 291 |
} |
| 292 |
return false; |
| 293 |
} |
| 294 |
|
| 295 |
/** |
| 296 |
* Method get_curl_support() |
| 297 |
* |
| 298 |
* Get cURL Version. |
| 299 |
* |
| 300 |
* @return string cURL Version. |
| 301 |
*/ |
| 302 |
public static function get_curl_support() { |
| 303 |
return function_exists( 'curl_version' ); |
| 304 |
} |
| 305 |
|
| 306 |
/** |
| 307 |
* Method get_curl_timeout() |
| 308 |
* |
| 309 |
* Get cURL_Timeout value. |
| 310 |
* |
| 311 |
* @return string cURL_Timeout value. |
| 312 |
*/ |
| 313 |
public static function get_curl_timeout() { |
| 314 |
return ini_get( 'default_socket_timeout' ); |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* Method get_php_version() |
| 319 |
* |
| 320 |
* Get PHP Version. |
| 321 |
* |
| 322 |
* @return string phpversion(). |
| 323 |
*/ |
| 324 |
public static function get_php_version() { |
| 325 |
return phpversion(); |
| 326 |
} |
| 327 |
|
| 328 |
/** |
| 329 |
* Method get_max_execution_time() |
| 330 |
* |
| 331 |
* Get MAX_EXECUTION_TIME. |
| 332 |
* |
| 333 |
* @return string MAX_EXECUTION_TIME. |
| 334 |
*/ |
| 335 |
public static function get_max_execution_time() { |
| 336 |
return ini_get( 'max_execution_time' ); |
| 337 |
} |
| 338 |
|
| 339 |
/** |
| 340 |
* Method get_max_execution_time() |
| 341 |
* |
| 342 |
* Get MAX_INPUT_TIME. |
| 343 |
* |
| 344 |
* @return string MAX_EXECUTION_TIME. |
| 345 |
*/ |
| 346 |
public static function get_max_input_time() { |
| 347 |
return ini_get( 'max_input_time' ); |
| 348 |
} |
| 349 |
|
| 350 |
/** |
| 351 |
* Method get_max_execution_time() |
| 352 |
* |
| 353 |
* Get MAX_UPLOAD_FILESIZE. |
| 354 |
* |
| 355 |
* @return string MAX_UPLOAD_FILESIZE. |
| 356 |
*/ |
| 357 |
public static function get_upload_max_filesize() { |
| 358 |
return ini_get( 'upload_max_filesize' ); |
| 359 |
} |
| 360 |
|
| 361 |
/** |
| 362 |
* Method get_max_execution_time() |
| 363 |
* |
| 364 |
* Get MAX_POST_SIZE. |
| 365 |
* |
| 366 |
* @return string MAX_POST_SIZE. |
| 367 |
*/ |
| 368 |
public static function get_post_max_size() { |
| 369 |
return ini_get( 'post_max_size' ); |
| 370 |
} |
| 371 |
|
| 372 |
/** |
| 373 |
* Method get_mysql_version() |
| 374 |
* |
| 375 |
* Get MySql Version. |
| 376 |
* |
| 377 |
* @return string MySQL Version. |
| 378 |
* |
| 379 |
* @uses \MainWP\Dashboard\MainWP_DB::get_my_sql_version() |
| 380 |
*/ |
| 381 |
public static function get_mysql_version() { |
| 382 |
return MainWP_DB::instance()->get_my_sql_version(); |
| 383 |
} |
| 384 |
|
| 385 |
/** |
| 386 |
* Method get_php_memory_limit() |
| 387 |
* |
| 388 |
* Get PHP_MEMORY_LIMIT. |
| 389 |
* |
| 390 |
* @return string PHP_MEMORY_LIMIT. |
| 391 |
*/ |
| 392 |
public static function get_php_memory_limit() { |
| 393 |
return ini_get( 'memory_limit' ); |
| 394 |
} |
| 395 |
|
| 396 |
/** |
| 397 |
* Method get_os() |
| 398 |
* |
| 399 |
* Get Host OS. |
| 400 |
* |
| 401 |
* @param bool $return_value = false. |
| 402 |
* |
| 403 |
* @return mixed PHP_OS. |
| 404 |
*/ |
| 405 |
public static function get_os( $return_value = false ) { |
| 406 |
if ( $return_value ) { |
| 407 |
return PHP_OS; |
| 408 |
} else { |
| 409 |
echo esc_html( PHP_OS ); |
| 410 |
} |
| 411 |
} |
| 412 |
|
| 413 |
/** |
| 414 |
* Method get_architecture() |
| 415 |
* |
| 416 |
* Get PHP_INT_SIZE * 8bit. |
| 417 |
*/ |
| 418 |
public static function get_architecture() { |
| 419 |
echo( esc_html( PHP_INT_SIZE * 8 ) ) |
| 420 |
?> |
| 421 |
bit |
| 422 |
<?php |
| 423 |
} |
| 424 |
|
| 425 |
/** |
| 426 |
* Method memory_usage() |
| 427 |
* |
| 428 |
* Get currently used memory. |
| 429 |
*/ |
| 430 |
public static function memory_usage() { |
| 431 |
if ( function_exists( 'memory_get_usage' ) ) { |
| 432 |
$memory_usage = round( memory_get_usage() / 1024 / 1024, 2 ) . ' MB'; |
| 433 |
} else { |
| 434 |
$memory_usage = 'N/A'; |
| 435 |
} |
| 436 |
echo esc_html( $memory_usage ); |
| 437 |
} |
| 438 |
|
| 439 |
/** |
| 440 |
* Method get_output_buffer_size() |
| 441 |
* |
| 442 |
* Get putput buffer size. |
| 443 |
* |
| 444 |
* @return string Current output buffer Size. |
| 445 |
*/ |
| 446 |
public static function get_output_buffer_size() { |
| 447 |
return ini_get( 'pcre.backtrack_limit' ); |
| 448 |
} |
| 449 |
|
| 450 |
/** |
| 451 |
* Method get_php_safe_mode() |
| 452 |
* |
| 453 |
* Get PHP Safe Mode. |
| 454 |
* |
| 455 |
* @return bool true|false. |
| 456 |
*/ |
| 457 |
public static function get_php_safe_mode() { |
| 458 |
if ( version_compare( self::get_php_version(), '5.3.0' ) >= 0 ) { |
| 459 |
return true; |
| 460 |
} |
| 461 |
|
| 462 |
if ( ini_get( 'safe_mode' ) ) { |
| 463 |
return false; |
| 464 |
} |
| 465 |
|
| 466 |
return true; |
| 467 |
} |
| 468 |
|
| 469 |
/** |
| 470 |
* Method get_sql_mode() |
| 471 |
* |
| 472 |
* Get SQL Mode. |
| 473 |
*/ |
| 474 |
public static function get_sql_mode() { |
| 475 |
|
| 476 |
/** |
| 477 |
* WordPress database instance. |
| 478 |
* |
| 479 |
* @global object |
| 480 |
*/ |
| 481 |
global $wpdb; |
| 482 |
|
| 483 |
$sql_mode = ''; |
| 484 |
$mysqlinfo = $wpdb->get_results( "SHOW VARIABLES LIKE 'sql_mode'" ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- ok. |
| 485 |
if ( is_array( $mysqlinfo ) ) { |
| 486 |
$sql_mode = $mysqlinfo[0]->Value; |
| 487 |
} |
| 488 |
if ( empty( $sql_mode ) ) { |
| 489 |
$sql_mode = esc_html__( 'NOT SET', 'mainwp' ); |
| 490 |
} |
| 491 |
echo esc_html( $sql_mode ); |
| 492 |
} |
| 493 |
|
| 494 |
/** |
| 495 |
* Checks if PHP url fopen is allowed. |
| 496 |
*/ |
| 497 |
public static function get_php_allow_url_fopen() { |
| 498 |
$allow = ini_get( 'allow_url_fopen' ); |
| 499 |
if ( is_numeric( $allow ) ) { |
| 500 |
$allow = intval( $allow ); |
| 501 |
if ( $allow ) { |
| 502 |
esc_html_e( 'YES', 'mainwp' ); |
| 503 |
} else { |
| 504 |
esc_html_e( 'NO', 'mainwp' ); |
| 505 |
} |
| 506 |
} elseif ( is_string( $allow ) ) { |
| 507 |
echo esc_html( $allow ); |
| 508 |
} |
| 509 |
} |
| 510 |
|
| 511 |
/** |
| 512 |
* Method get_php_exif() |
| 513 |
* |
| 514 |
* Check if PHP Exif is enabled. |
| 515 |
*/ |
| 516 |
public static function get_php_exif() { |
| 517 |
if ( is_callable( 'exif_read_data' ) ) { |
| 518 |
esc_html_e( 'YES', 'mainwp' ) . ' ( V' . esc_html( substr( phpversion( 'exif' ), 0, 4 ) ) . ')'; |
| 519 |
} else { |
| 520 |
esc_html_e( 'NO', 'mainwp' ); |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
/** |
| 525 |
* Method get_php_iptc() |
| 526 |
* |
| 527 |
* Check if iptcparse is enabled. |
| 528 |
*/ |
| 529 |
public static function get_php_iptc() { |
| 530 |
if ( is_callable( 'iptcparse' ) ) { |
| 531 |
esc_html_e( 'YES', 'mainwp' ); |
| 532 |
} else { |
| 533 |
esc_html_e( 'NO', 'mainwp' ); |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
/** |
| 538 |
* Method get_php_xml() |
| 539 |
* |
| 540 |
* Check if PHP XML Parser is enabled. |
| 541 |
*/ |
| 542 |
public static function get_php_xml() { |
| 543 |
if ( is_callable( 'xml_parser_create' ) ) { |
| 544 |
esc_html_e( 'YES', 'mainwp' ); |
| 545 |
} else { |
| 546 |
esc_html_e( 'NO', 'mainwp' ); |
| 547 |
} |
| 548 |
} |
| 549 |
|
| 550 |
/** |
| 551 |
* Method get_server_gateway_interface() |
| 552 |
* |
| 553 |
* Get server gateway interface. |
| 554 |
*/ |
| 555 |
public static function get_server_gateway_interface() { |
| 556 |
echo isset( $_SERVER['GATEWAY_INTERFACE'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['GATEWAY_INTERFACE'] ) ) ) : ''; |
| 557 |
} |
| 558 |
|
| 559 |
/** |
| 560 |
* Method get_server_ip() |
| 561 |
* |
| 562 |
* Get server IP address. |
| 563 |
*/ |
| 564 |
public static function get_server_ip() { |
| 565 |
echo isset( $_SERVER['SERVER_ADDR'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) ) : ''; |
| 566 |
} |
| 567 |
|
| 568 |
/** |
| 569 |
* Method get_server_name() |
| 570 |
* |
| 571 |
* Get server name. |
| 572 |
* |
| 573 |
* @param bool $return_value Return or not. |
| 574 |
* |
| 575 |
* @return string $_SERVER['SERVER_NAME']. |
| 576 |
*/ |
| 577 |
public static function get_server_name( $return_value = false ) { |
| 578 |
if ( $return_value ) { |
| 579 |
return isset( $_SERVER['SERVER_NAME'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) ) : ''; |
| 580 |
} else { |
| 581 |
echo isset( $_SERVER['SERVER_NAME'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) ) : ''; |
| 582 |
} |
| 583 |
} |
| 584 |
|
| 585 |
/** |
| 586 |
* Method get_server_software() |
| 587 |
* |
| 588 |
* Get server software. |
| 589 |
* |
| 590 |
* @param bool $return_value Return or not. |
| 591 |
* |
| 592 |
* @return string $_SERVER['SERVER_SOFTWARE']. |
| 593 |
*/ |
| 594 |
public static function get_server_software( $return_value = false ) { |
| 595 |
if ( $return_value ) { |
| 596 |
return isset( $_SERVER['SERVER_SOFTWARE'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) ) : ''; |
| 597 |
} else { |
| 598 |
echo isset( $_SERVER['SERVER_SOFTWARE'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) ) : ''; |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
/** |
| 603 |
* Method is_apache_server_software() |
| 604 |
* |
| 605 |
* Check if server software is apache. |
| 606 |
* |
| 607 |
* @return bool True|false. |
| 608 |
*/ |
| 609 |
public static function is_apache_server_software() { |
| 610 |
$server = self::get_server_software( true ); |
| 611 |
return ( false !== stripos( $server, 'apache' ) ) ? true : false; |
| 612 |
} |
| 613 |
|
| 614 |
/** |
| 615 |
* Gets server protocol. |
| 616 |
*/ |
| 617 |
public static function get_server_protocol() { |
| 618 |
echo isset( $_SERVER['SERVER_PROTOCOL'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_PROTOCOL'] ) ) ) : ''; |
| 619 |
} |
| 620 |
|
| 621 |
/** |
| 622 |
* Gets server request time. |
| 623 |
*/ |
| 624 |
public static function get_server_request_time() { |
| 625 |
echo isset( $_SERVER['REQUEST_TIME'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_TIME'] ) ) ) : ''; |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
/** |
| 630 |
* Gets server HTTP accept. |
| 631 |
*/ |
| 632 |
public static function get_server_http_accept() { |
| 633 |
echo isset( $_SERVER['HTTP_ACCEPT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_ACCEPT'] ) ) ) : ''; |
| 634 |
} |
| 635 |
|
| 636 |
/** |
| 637 |
* Gets server accepted character set. |
| 638 |
*/ |
| 639 |
public static function get_server_accept_charset() { |
| 640 |
// phpcs:disable WordPress.Security.EscapeOutput |
| 641 |
echo ( ! isset( $_SERVER['HTTP_ACCEPT_CHARSET'] ) || empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) ? esc_html__( 'N/A', 'mainwp' ) : esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) ); |
| 642 |
// phpcs:enable |
| 643 |
} |
| 644 |
|
| 645 |
/** |
| 646 |
* Gets HTTP host. |
| 647 |
*/ |
| 648 |
public static function get_http_host() { |
| 649 |
echo isset( $_SERVER['HTTP_HOST'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : ''; |
| 650 |
} |
| 651 |
|
| 652 |
/** |
| 653 |
* Gets complete URL. |
| 654 |
*/ |
| 655 |
public static function get_complete_url() { |
| 656 |
echo isset( $_SERVER['HTTP_REFERER'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) ) : ''; |
| 657 |
} |
| 658 |
|
| 659 |
/** |
| 660 |
* Gets user agent. |
| 661 |
*/ |
| 662 |
public static function get_user_agent() { |
| 663 |
echo isset( $_SERVER['HTTP_USER_AGENT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) ) : ''; |
| 664 |
} |
| 665 |
|
| 666 |
/** |
| 667 |
* Checks if HTTPS is enabled. |
| 668 |
*/ |
| 669 |
public static function get_https() { |
| 670 |
if ( isset( $_SERVER['HTTPS'] ) && '' !== $_SERVER['HTTPS'] ) { |
| 671 |
esc_html_e( 'ON', 'mainwp' ) . ' - ' . esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) ) ); |
| 672 |
} else { |
| 673 |
esc_html_e( 'OFF', 'mainwp' ); |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
/** |
| 678 |
* Method server_self_connect() |
| 679 |
* |
| 680 |
* Check if server self-connect is possible. |
| 681 |
*/ |
| 682 |
public static function server_self_connect() { |
| 683 |
$url = site_url( 'wp-cron.php' ); |
| 684 |
$query_args = array( 'mainwp_run' => 'test' ); |
| 685 |
$url = esc_url_raw( add_query_arg( $query_args, $url ) ); |
| 686 |
|
| 687 |
/** |
| 688 |
* Filter: https_local_ssl_verify |
| 689 |
* |
| 690 |
* Filters whether the server-self check shoul verify SSL Cert. |
| 691 |
* |
| 692 |
* @since Unknown |
| 693 |
*/ |
| 694 |
$args = array( |
| 695 |
'blocking' => true, |
| 696 |
'sslverify' => apply_filters( 'https_local_ssl_verify', true ), |
| 697 |
'timeout' => 15, |
| 698 |
); |
| 699 |
$response = wp_remote_post( $url, $args ); |
| 700 |
$test_result = ''; |
| 701 |
if ( is_wp_error( $response ) ) { |
| 702 |
$test_result .= sprintf( esc_html__( 'The HTTP response test get an error "%s"', 'mainwp' ), $response->get_error_message() ); |
| 703 |
} |
| 704 |
$response_code = wp_remote_retrieve_response_code( $response ); |
| 705 |
if ( 200 > $response_code && 204 < $response_code ) { |
| 706 |
$test_result .= sprintf( esc_html__( 'The HTTP response test get a false http status (%s)', 'mainwp' ), wp_remote_retrieve_response_code( $response ) ); |
| 707 |
} else { |
| 708 |
$response_body = wp_remote_retrieve_body( $response ); |
| 709 |
if ( false === strstr( $response_body, 'MainWP Test' ) ) { |
| 710 |
$test_result .= sprintf( esc_html__( 'Not expected HTTP response body: %s', 'mainwp' ), esc_attr( wp_strip_all_tags( $response_body ) ) ); |
| 711 |
} |
| 712 |
} |
| 713 |
if ( empty( $test_result ) ) { |
| 714 |
esc_html_e( 'Response Test O.K.', 'mainwp' ); |
| 715 |
} else { |
| 716 |
echo esc_html( $test_result ); |
| 717 |
} |
| 718 |
} |
| 719 |
|
| 720 |
/** |
| 721 |
* Gets server remote address. |
| 722 |
*/ |
| 723 |
public static function get_remote_address() { |
| 724 |
echo isset( $_SERVER['REMOTE_ADDR'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) : ''; |
| 725 |
} |
| 726 |
|
| 727 |
/** |
| 728 |
* Gets server remote host. |
| 729 |
*/ |
| 730 |
public static function get_remote_host() { |
| 731 |
if ( ! isset( $_SERVER['REMOTE_HOST'] ) || ( '' === $_SERVER['REMOTE_HOST'] ) ) { |
| 732 |
esc_html_e( 'N/A', 'mainwp' ); |
| 733 |
} else { |
| 734 |
echo isset( $_SERVER['REMOTE_HOST'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_HOST'] ) ) ) : ''; |
| 735 |
} |
| 736 |
} |
| 737 |
|
| 738 |
/** |
| 739 |
* Gets server remote port. |
| 740 |
*/ |
| 741 |
public static function get_remote_port() { |
| 742 |
echo isset( $_SERVER['REMOTE_PORT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_PORT'] ) ) ) : ''; |
| 743 |
} |
| 744 |
|
| 745 |
/** |
| 746 |
* Gets server script filename. |
| 747 |
*/ |
| 748 |
public static function get_script_file_name() { |
| 749 |
echo isset( $_SERVER['SCRIPT_FILENAME'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_FILENAME'] ) ) ) : ''; |
| 750 |
} |
| 751 |
|
| 752 |
/** |
| 753 |
* Method get_server_port() |
| 754 |
* |
| 755 |
* Get server port. |
| 756 |
*/ |
| 757 |
public static function get_server_port() { |
| 758 |
echo isset( $_SERVER['SERVER_PORT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_PORT'] ) ) ) : ''; |
| 759 |
} |
| 760 |
|
| 761 |
/** |
| 762 |
* Method get_current_page_uri() |
| 763 |
* |
| 764 |
* Get current page URI. |
| 765 |
*/ |
| 766 |
public static function get_current_page_uri() { |
| 767 |
echo isset( $_SERVER['REQUEST_URI'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) : ''; |
| 768 |
} |
| 769 |
|
| 770 |
/** |
| 771 |
* Method get_wp_root() |
| 772 |
* |
| 773 |
* Get WP Root Path. |
| 774 |
*/ |
| 775 |
public static function get_wp_root() { |
| 776 |
echo esc_html( ABSPATH ); |
| 777 |
} |
| 778 |
|
| 779 |
/** |
| 780 |
* Compares time. |
| 781 |
* |
| 782 |
* @param mixed $a first time to compare. |
| 783 |
* @param mixed $b second time to compare. |
| 784 |
*/ |
| 785 |
public static function time_compare( $a, $b ) { |
| 786 |
|
| 787 |
if ( $a === $b ) { |
| 788 |
return 0; |
| 789 |
} |
| 790 |
|
| 791 |
return ( strtotime( $a['time'] ) > strtotime( $b['time'] ) ) ? - 1 : 1; |
| 792 |
} |
| 793 |
|
| 794 |
/** |
| 795 |
* Gets line count. |
| 796 |
* |
| 797 |
* @param mixed $path the error log file location. |
| 798 |
* @param int $line_count number of lines in the error log. |
| 799 |
* @param int $block_size block size. |
| 800 |
* |
| 801 |
* @return string Line Count. |
| 802 |
*/ |
| 803 |
public static function last_lines( $path, $line_count, $block_size = 512 ) { |
| 804 |
//phpcs:disable WordPress.WP.AlternativeFunctions |
| 805 |
$lines = array(); |
| 806 |
$leftover = ''; |
| 807 |
$fh = fopen( $path, 'r' ); |
| 808 |
|
| 809 |
fseek( $fh, 0, SEEK_END ); |
| 810 |
|
| 811 |
do { |
| 812 |
$can_read = $block_size; |
| 813 |
|
| 814 |
if ( ftell( $fh ) <= $block_size ) { |
| 815 |
$can_read = ftell( $fh ); |
| 816 |
} |
| 817 |
|
| 818 |
if ( empty( $can_read ) ) { |
| 819 |
break; |
| 820 |
} |
| 821 |
|
| 822 |
fseek( $fh, - $can_read, SEEK_CUR ); |
| 823 |
$data = fread( $fh, $can_read ); |
| 824 |
$data .= $leftover; |
| 825 |
fseek( $fh, - $can_read, SEEK_CUR ); |
| 826 |
|
| 827 |
$split_data = array_reverse( explode( "\n", $data ) ); |
| 828 |
$new_lines = array_slice( $split_data, 0, - 1 ); |
| 829 |
$lines = array_merge( $lines, $new_lines ); |
| 830 |
$leftover = $split_data[ count( $split_data ) - 1 ]; |
| 831 |
$count = count( $lines ); |
| 832 |
} while ( $count < $line_count && ! empty( ftell( $fh ) ) ); |
| 833 |
|
| 834 |
if ( empty( ftell( $fh ) ) ) { |
| 835 |
$lines[] = $leftover; |
| 836 |
} |
| 837 |
|
| 838 |
fclose( $fh ); |
| 839 |
//phpcs:enable |
| 840 |
|
| 841 |
return array_slice( $lines, 0, $line_count ); |
| 842 |
} |
| 843 |
|
| 844 |
/** |
| 845 |
* Gets MainWP Set Options. |
| 846 |
* |
| 847 |
* @return array $options_value MainWP Options array. |
| 848 |
* |
| 849 |
* @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() |
| 850 |
* @uses \MainWP\Dashboard\MainWP_DB::get_websites_count() |
| 851 |
*/ |
| 852 |
public static function mainwp_options() { // phpcs:ignore -- current complexity required to achieve desired results. Pull request solutions appreaciated. |
| 853 |
$mainwp_options = array( |
| 854 |
'mainwp_number_of_child_sites' => esc_html__( 'Number of connected sites', 'mainwp' ), |
| 855 |
'mainwp_wp_cron' => esc_html__( 'Use WP Cron', 'mainwp' ), |
| 856 |
'mainwp_optimize' => esc_html__( 'Optimize data loading', 'mainwp' ), |
| 857 |
'mainwp_automaticDailyUpdate' => esc_html__( 'WP Core advanced automatic updates enabled', 'mainwp' ), |
| 858 |
'mainwp_pluginAutomaticDailyUpdate' => esc_html__( 'Plugin advanced automatic updates enabled', 'mainwp' ), |
| 859 |
'mainwp_themeAutomaticDailyUpdate' => esc_html__( 'Theme advanced automatic updates enabled', 'mainwp' ), |
| 860 |
'mainwp_numberdays_Outdate_Plugin_Theme' => esc_html__( 'Abandoned plugins/themes tolerance', 'mainwp' ), |
| 861 |
'mainwp_maximumPosts' => esc_html__( 'Maximum number of posts to return', 'mainwp' ), |
| 862 |
'mainwp_maximumPages' => esc_html__( 'Maximum number of pages to return', 'mainwp' ), |
| 863 |
'mainwp_maximumComments' => esc_html__( 'Maximum number of comments', 'mainwp' ), |
| 864 |
'mainwp_enableLegacyBackupFeature' => esc_html__( 'MainWP legacy backups enabled', 'mainwp' ), |
| 865 |
'mainwp_primaryBackup' => esc_html__( 'Primary backup system', 'mainwp' ), |
| 866 |
'mainwp_disableSitesChecking' => esc_html__( 'Basic uptime monitoring enabled', 'mainwp' ), |
| 867 |
'mainwp_disableSitesHealthMonitoring' => esc_html__( 'Site health monitoring enabled', 'mainwp' ), |
| 868 |
'mainwp_maximumRequests' => esc_html__( 'Maximum simultaneous requests', 'mainwp' ), |
| 869 |
'mainwp_minimumDelay' => esc_html__( 'Minimum delay between requests', 'mainwp' ), |
| 870 |
'mainwp_maximumIPRequests' => esc_html__( 'Maximum simultaneous requests per ip', 'mainwp' ), |
| 871 |
'mainwp_minimumIPDelay' => esc_html__( 'Minimum delay between requests to the same ip', 'mainwp' ), |
| 872 |
'mainwp_maximumSyncRequests' => esc_html__( 'Maximum simultaneous sync requests', 'mainwp' ), |
| 873 |
'mainwp_maximumInstallUpdateRequests' => esc_html__( 'Maximum simultaneous install and update requests', 'mainwp' ), |
| 874 |
'mainwp_auto_purge_cache' => esc_html__( 'Cache control enabled', 'mainwp' ), |
| 875 |
); |
| 876 |
|
| 877 |
if ( ! is_plugin_active( 'mainwp-comments-extension/mainwp-comments-extension.php' ) ) { |
| 878 |
unset( $mainwp_options['mainwp_maximumComments'] ); |
| 879 |
} |
| 880 |
|
| 881 |
$options_value = array(); |
| 882 |
$userExtension = MainWP_DB_Common::instance()->get_user_extension(); |
| 883 |
foreach ( $mainwp_options as $opt => $label ) { |
| 884 |
$value = get_option( $opt, false ); |
| 885 |
switch ( $opt ) { |
| 886 |
case 'mainwp_number_of_child_sites': |
| 887 |
$value = MainWP_DB::instance()->get_websites_count(); |
| 888 |
break; |
| 889 |
case 'mainwp_primaryBackup': |
| 890 |
$value = esc_html__( 'MainWP Legacy Backups', 'mainwp' ); |
| 891 |
break; |
| 892 |
case 'mainwp_numberdays_Outdate_Plugin_Theme': |
| 893 |
case 'mainwp_maximumPosts': |
| 894 |
case 'mainwp_maximumPages': |
| 895 |
case 'mainwp_maximumComments': |
| 896 |
case 'mainwp_maximumSyncRequests': |
| 897 |
case 'mainwp_maximumInstallUpdateRequests': |
| 898 |
break; |
| 899 |
case 'mainwp_maximumRequests': |
| 900 |
$value = ( false === $value ) ? 4 : $value; |
| 901 |
break; |
| 902 |
case 'mainwp_maximumIPRequests': |
| 903 |
$value = ( false === $value ) ? 1 : $value; |
| 904 |
break; |
| 905 |
case 'mainwp_minimumIPDelay': |
| 906 |
$value = ( false === $value ) ? 1000 : $value; |
| 907 |
break; |
| 908 |
case 'mainwp_minimumDelay': |
| 909 |
$value = ( false === $value ) ? 200 : $value; |
| 910 |
break; |
| 911 |
case 'mainwp_maximumSyncRequests': |
| 912 |
$value = ( false === $value ) ? 8 : $value; |
| 913 |
break; |
| 914 |
case 'mainwp_maximumInstallUpdateRequests': |
| 915 |
$value = ( false === $value ) ? 3 : $value; |
| 916 |
break; |
| 917 |
case 'mainwp_disableSitesChecking': |
| 918 |
$value = empty( $value ) ? esc_html__( 'Yes', 'mainwp' ) : esc_html__( 'No', 'mainwp' ); |
| 919 |
break; |
| 920 |
case 'mainwp_disableSitesHealthMonitoring': |
| 921 |
$value = empty( $value ) ? esc_html__( 'Yes', 'mainwp' ) : esc_html__( 'No', 'mainwp' ); |
| 922 |
break; |
| 923 |
default: |
| 924 |
$value = empty( $value ) ? esc_html__( 'No', 'mainwp' ) : esc_html__( 'Yes', 'mainwp' ); |
| 925 |
break; |
| 926 |
} |
| 927 |
$options_value[ $opt ] = array( |
| 928 |
'label' => $label, |
| 929 |
'value' => $value, |
| 930 |
); |
| 931 |
} |
| 932 |
|
| 933 |
$options_value[ $opt ] = array( |
| 934 |
'label' => esc_html__( 'REST API enabled', 'mainwp' ), |
| 935 |
'value' => Rest_Api::instance()->is_rest_api_enabled() ? esc_html__( 'Yes', 'mainwp' ) : esc_html__( 'No', 'mainwp' ), |
| 936 |
); |
| 937 |
|
| 938 |
/** |
| 939 |
* Filter: mainwp_getprimarybackup_methods |
| 940 |
* |
| 941 |
* Filters the primary backup options for the select menu in Settings. |
| 942 |
* |
| 943 |
* @since 4.0 |
| 944 |
*/ |
| 945 |
$primaryBackup = get_option( 'mainwp_primaryBackup' ); |
| 946 |
$primary_methods = array(); |
| 947 |
$primary_methods = apply_filters_deprecated( 'mainwp-getprimarybackup-methods', array( $primary_methods ), '4.0.7.2', 'mainwp_getprimarybackup_methods' ); // @deprecated Use 'mainwp_getprimarybackup_methods' instead. |
| 948 |
$primaryBackupMethods = apply_filters( 'mainwp_getprimarybackup_methods', $primary_methods ); |
| 949 |
|
| 950 |
if ( ! is_array( $primaryBackupMethods ) ) { |
| 951 |
$primaryBackupMethods = array(); |
| 952 |
} |
| 953 |
|
| 954 |
if ( 0 < count( $primaryBackupMethods ) ) { |
| 955 |
$chk = false; |
| 956 |
foreach ( $primaryBackupMethods as $method ) { |
| 957 |
if ( $primaryBackup === $method['value'] ) { |
| 958 |
$value = $method['title']; |
| 959 |
$chk = true; |
| 960 |
break; |
| 961 |
} |
| 962 |
} |
| 963 |
if ( $chk ) { |
| 964 |
$options_value['mainwp_primaryBackup'] = array( |
| 965 |
'label' => esc_html__( 'Primary Backup System', 'mainwp' ), |
| 966 |
'value' => $value, |
| 967 |
); |
| 968 |
} |
| 969 |
} |
| 970 |
return $options_value; |
| 971 |
} |
| 972 |
} |
| 973 |
|