PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.6.0.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.6.0.1
6.2.3 6.2.2 6.2.1 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 All 156 releases
mainwp / pages / page-mainwp-server-information-handler.php

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

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