PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.2.2
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / pages / page-mainwp-server-information-handler.php

page-mainwp-server-information-handler.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.2.2, at pages/page-mainwp-server-information-handler.php

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