From 1e11c93c4aad99a86618b131c42905a9937bf437 Mon Sep 17 00:00:00 2001 From: Thang Hoang Van Date: Wed, 19 Dec 2018 17:01:08 +0700 Subject: [PATCH] Merge with branch01 * Fixed: an issue with the X-Frame-Options configuration * Fixed: an issue with clearing WP Rocket cache * Fixed: an issue with saving BackWPup settings * Fixed: multiple compatibility issues for the Bulk Settings Manger extension * Fixed: an issue with submitting the Bulk Settings Manger keys on child sites protected with the HTTP Basic Authentication * Fixed: an issue with creating buckets in Backblaze remote option caused by disallowed characters * Fixed: an issue with tokens usage in the UpdraftPlus Webdav remote storage settings * Added: support for new WP Staging plugin options * Updated: update detection process in order to improve performance on some hosts * Updated: disabled site size calculation function as default state * Updated: support for the latest Wordfence version --- class/class-mainwp-child-back-up-buddy.php | 11 ++ .../class-mainwp-child-back-up-wordpress.php | 10 + class/class-mainwp-child-back-wp-up.php | 5 +- class/class-mainwp-child-branding.php | 176 ++++++++++++++++-- .../class-mainwp-child-server-information.php | 3 +- class/class-mainwp-child-skeleton-key.php | 3 + class/class-mainwp-child-staging.php | 12 ++ class/class-mainwp-child-timecapsule.php | 9 + ...lass-mainwp-child-updraft-plus-backups.php | 136 ++++++++------ class/class-mainwp-child-wordfence.php | 162 ++++++++++------ class/class-mainwp-child-wp-rocket.php | 39 ++-- class/class-mainwp-child.php | 24 ++- class/class-mainwp-client-report.php | 60 +++++- class/class-mainwp-helper.php | 16 ++ mainwp-child.php | 10 +- 15 files changed, 521 insertions(+), 155 deletions(-) diff --git a/class/class-mainwp-child-back-up-buddy.php b/class/class-mainwp-child-back-up-buddy.php index 3b4eb9d..ac2defa 100644 --- a/class/class-mainwp-child-back-up-buddy.php +++ b/class/class-mainwp-child-back-up-buddy.php @@ -32,13 +32,24 @@ class MainWP_Child_Back_Up_Buddy { add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); + add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) ); } } + function hide_update_notice( $slugs ) { + $slugs[] = 'backupbuddy/backupbuddy.php'; + return $slugs; + } + function remove_update_nag( $value ) { if ( isset( $_POST['mainwpsignature'] ) ) { return $value; } + + if (! MainWP_Helper::is_screen_with_update()) { + return $value; + } + if ( isset( $value->response['backupbuddy/backupbuddy.php'] ) ) { unset( $value->response['backupbuddy/backupbuddy.php'] ); } diff --git a/class/class-mainwp-child-back-up-wordpress.php b/class/class-mainwp-child-back-up-wordpress.php index f705534..fe2357b 100644 --- a/class/class-mainwp-child-back-up-wordpress.php +++ b/class/class-mainwp-child-back-up-wordpress.php @@ -35,13 +35,23 @@ class MainWP_Child_Back_Up_Wordpress { add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); add_action( 'admin_menu', array( $this, 'remove_menu' ) ); add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); + add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) ); } } + function hide_update_notice( $slugs ) { + $slugs[] = 'backupwordpress/backupwordpress.php'; + return $slugs; + } + function remove_update_nag( $value ) { if ( isset( $_POST['mainwpsignature'] ) ) { return $value; } + + if (! MainWP_Helper::is_screen_with_update()) { + return $value; + } if ( isset( $value->response['backupwordpress/backupwordpress.php'] ) ) { unset( $value->response['backupwordpress/backupwordpress.php'] ); } diff --git a/class/class-mainwp-child-back-wp-up.php b/class/class-mainwp-child-back-wp-up.php index 71772ad..c207693 100644 --- a/class/class-mainwp-child-back-wp-up.php +++ b/class/class-mainwp-child-back-wp-up.php @@ -1423,7 +1423,10 @@ class MainWP_Child_Back_WP_Up { update_site_option( 'backwpup_messages', array() ); - $backwpup = new BackWPup_Page_Settings(); + $settings_views = array(); + $settings_updaters = array(); + + $backwpup = new BackWPup_Page_Settings($settings_views, $settings_updaters); $backwpup->save_post_form(); if ( class_exists( 'BackWPup_Pro' ) ) { diff --git a/class/class-mainwp-child-branding.php b/class/class-mainwp-child-branding.php index d2916b0..4092ba8 100644 --- a/class/class-mainwp-child-branding.php +++ b/class/class-mainwp-child-branding.php @@ -270,6 +270,17 @@ class MainWP_Child_Branding { if ( ! is_array( $extra_setting ) ) { $extra_setting = array(); } + + // to hide updates notice + if (is_admin()) { + // back end + add_action( 'in_admin_footer', array( $this, 'in_admin_footer' ) ); + } else if (is_user_logged_in()) { + // front end + add_action( 'add_admin_bar_menus', array( $this, 'add_admin_bar_menus' )); + } + + $cancelled_branding = ( get_option( 'mainwp_child_branding_disconnected' ) === 'yes' ) && ! get_option( 'mainwp_branding_preserve_branding' ); if ( $cancelled_branding ) { return; @@ -277,9 +288,10 @@ class MainWP_Child_Branding { // enable branding in case child plugin is deactive add_filter( 'all_plugins', array( $this, 'branding_child_plugin' ) ); -// if ( self::is_branding() ) { -// add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); -// } + if ( self::is_branding() ) { + add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); + add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) ); + } if ( get_option( 'mainwp_branding_ext_enabled' ) !== 'Y' ) { return; @@ -856,6 +868,135 @@ class MainWP_Child_Branding { return 'MainWP'; } + public function add_admin_bar_menus() { + + $hide_slugs = apply_filters('mainwp_child_hide_update_notice' , array()); + + if (!is_array($hide_slugs)) + $hide_slugs = array(); + + if (count($hide_slugs) == 0) { + return; + } + + if (!function_exists('get_plugin_updates')) { + include_once( ABSPATH . '/wp-admin/includes/update.php' ); + } + + $count_hide = 0; + + $updates = get_plugin_updates(); + if (is_array($updates)) { + foreach($updates as $slug => $data) { + if (in_array($slug, $hide_slugs)) { + $count_hide++; + } + } + } + + if ( $count_hide == 0) { + return; + } + // js for front end + ?> + $data) { + if (in_array($slug, $hide_slugs)) { + $count_hide++; + } + } + } + + if ( $count_hide == 0) { + return; + } + + // to tweaks counting of update notification display + // js for admin end + ?> + response['mainwp-child/mainwp-child.php'] ) ) { -// unset( $value->response['mainwp-child/mainwp-child.php'] ); -// } -// return $value; -// } + function hide_update_notice( $slugs ) { + $slugs[] = 'mainwp-child/mainwp-child.php'; + return $slugs; + } + + + function remove_update_nag( $value ) { + if ( isset( $_POST['mainwpsignature'] ) ) { + return $value; + } + + if (! MainWP_Helper::is_screen_with_update()) { + return $value; + } + + if ( isset( $value->response['mainwp-child/mainwp-child.php'] ) ) { + unset( $value->response['mainwp-child/mainwp-child.php'] ); + } + return $value; + } public function update_child_header( $plugins, $header ) { $plugin_key = ''; diff --git a/class/class-mainwp-child-server-information.php b/class/class-mainwp-child-server-information.php index 5405979..21faf67 100644 --- a/class/class-mainwp-child-server-information.php +++ b/class/class-mainwp-child-server-information.php @@ -1250,7 +1250,8 @@ class MainWP_Child_Server_Information { } protected static function getServerGetawayInterface() { - echo esc_html( $_SERVER['GATEWAY_INTERFACE'] ); + $gate = isset($_SERVER['GATEWAY_INTERFACE']) ? $_SERVER['GATEWAY_INTERFACE'] : ''; + echo esc_html( $gate ); } public static function getServerIP() { diff --git a/class/class-mainwp-child-skeleton-key.php b/class/class-mainwp-child-skeleton-key.php index d6175c0..ee293ef 100644 --- a/class/class-mainwp-child-skeleton-key.php +++ b/class/class-mainwp-child-skeleton-key.php @@ -123,6 +123,9 @@ class MainWP_Child_Skeleton_Key { $full_url = add_query_arg( $get_args, get_site_url() . $url ); + global $mainWPChild; + add_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); + $response = wp_remote_post( $full_url, $post_args ); if ( is_wp_error( $response ) ) { diff --git a/class/class-mainwp-child-staging.php b/class/class-mainwp-child-staging.php index a1f22df..6e590bf 100644 --- a/class/class-mainwp-child-staging.php +++ b/class/class-mainwp-child-staging.php @@ -36,6 +36,7 @@ class MainWP_Child_Staging { add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); add_action( 'admin_menu', array( $this, 'remove_menu' ) ); add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); + add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) ); } } @@ -141,6 +142,7 @@ class MainWP_Child_Staging { 'fileLimit', 'batchSize', 'cpuLoad', + 'delayRequests', 'disableAdminLogin', 'querySRLimit', 'maxFileSize', @@ -393,10 +395,20 @@ class MainWP_Child_Staging { } } + function hide_update_notice( $slugs ) { + $slugs[] = 'wp-staging/wp-staging.php'; + return $slugs; + } + function remove_update_nag( $value ) { if ( isset( $_POST['mainwpsignature'] ) ) { return $value; } + + if (! MainWP_Helper::is_screen_with_update()) { + return $value; + } + if ( isset( $value->response['wp-staging/wp-staging.php'] ) ) { unset( $value->response['wp-staging/wp-staging.php'] ); } diff --git a/class/class-mainwp-child-timecapsule.php b/class/class-mainwp-child-timecapsule.php index 67e0e0c..213faec 100644 --- a/class/class-mainwp-child-timecapsule.php +++ b/class/class-mainwp-child-timecapsule.php @@ -38,6 +38,7 @@ class MainWP_Child_Timecapsule { add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); add_action( 'admin_menu', array( $this, 'remove_menu' ) ); add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); + add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) ); } } @@ -1243,10 +1244,18 @@ function get_sibling_files_callback_wptc() { } } + function hide_update_notice( $slugs ) { + $slugs[] = 'wp-time-capsule/wp-time-capsule.php'; + return $slugs; + } + function remove_update_nag( $value ) { if ( isset( $_POST['mainwpsignature'] ) ) { return $value; } + if (! MainWP_Helper::is_screen_with_update()) { + return $value; + } if ( isset( $value->response['wp-time-capsule/wp-time-capsule.php'] ) ) { unset( $value->response['wp-time-capsule/wp-time-capsule.php'] ); } diff --git a/class/class-mainwp-child-updraft-plus-backups.php b/class/class-mainwp-child-updraft-plus-backups.php index 6906589..9c884c2 100644 --- a/class/class-mainwp-child-updraft-plus-backups.php +++ b/class/class-mainwp-child-updraft-plus-backups.php @@ -421,57 +421,60 @@ class MainWP_Child_Updraft_Plus_Backups { } UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else if ( 'updraft_googledrive' === $key ) { - $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_googledrive' ); - if (!is_array($opts)) - $opts = array(); - if(is_array($opts) && isset($opts['settings'])) { - $settings_key = key($opts['settings']); -// $opts['settings'][$settings_key]['clientid'] = $settings[ $key ]['clientid']; -// $opts['settings'][$settings_key]['secret'] = $settings[ $key ]['secret']; - $opts['settings'][$settings_key]['folder'] = $this->replace_tokens($settings[ $key ]['folder']); - } else { -// $opts['clientid'] = $settings[ $key ]['clientid']; -// $opts['secret'] = $settings[ $key ]['secret']; - $opts['folder'] = $this->replace_tokens($settings[ $key ]['folder']); - } - UpdraftPlus_Options::update_updraft_option( $key, $opts ); + // do not saving from dashboard +// $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_googledrive' ); +// if (!is_array($opts)) +// $opts = array(); +// if(is_array($opts) && isset($opts['settings'])) { +// $settings_key = key($opts['settings']); +//// $opts['settings'][$settings_key]['clientid'] = $settings[ $key ]['clientid']; +//// $opts['settings'][$settings_key]['secret'] = $settings[ $key ]['secret']; +// $opts['settings'][$settings_key]['folder'] = $this->replace_tokens($settings[ $key ]['folder']); +// } else { +//// $opts['clientid'] = $settings[ $key ]['clientid']; +//// $opts['secret'] = $settings[ $key ]['secret']; +// $opts['folder'] = $this->replace_tokens($settings[ $key ]['folder']); +// } +// UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else if ( 'updraft_googlecloud' === $key ) { - $opts = UpdraftPlus_Options::get_updraft_option( $key ); - if (!is_array($opts)) - $opts = array(); - if(is_array($opts) && isset($opts['settings'])) { - $settings_key = key($opts['settings']); -// $opts['settings'][$settings_key]['clientid'] = $settings[ $key ]['clientid']; -// $opts['settings'][$settings_key]['secret'] = $settings[ $key ]['secret']; -// $opts['settings'][$settings_key]['project_id'] = $settings[ $key ]['project_id']; -// $opts['settings'][$settings_key]['bucket_path'] = $settings[ $key ]['bucket_path']; - $opts['settings'][$settings_key]['storage_class'] = $settings[ $key ]['storage_class']; - $opts['settings'][$settings_key]['bucket_location'] = $settings[ $key ]['bucket_location']; - } else { -// $opts['clientid'] = $settings[ $key ]['clientid']; -// $opts['secret'] = $settings[ $key ]['secret']; -// $opts['project_id'] = $settings[ $key ]['project_id']; -// $opts['bucket_path'] = $settings[ $key ]['bucket_path']; - $opts['storage_class'] = $settings[ $key ]['storage_class']; - $opts['bucket_location'] = $settings[ $key ]['bucket_location']; - } - UpdraftPlus_Options::update_updraft_option( $key, $opts ); + // do not saving from dashboard +// $opts = UpdraftPlus_Options::get_updraft_option( $key ); +// if (!is_array($opts)) +// $opts = array(); +// if(is_array($opts) && isset($opts['settings'])) { +// $settings_key = key($opts['settings']); +//// $opts['settings'][$settings_key]['clientid'] = $settings[ $key ]['clientid']; +//// $opts['settings'][$settings_key]['secret'] = $settings[ $key ]['secret']; +//// $opts['settings'][$settings_key]['project_id'] = $settings[ $key ]['project_id']; +//// $opts['settings'][$settings_key]['bucket_path'] = $settings[ $key ]['bucket_path']; +// $opts['settings'][$settings_key]['storage_class'] = $settings[ $key ]['storage_class']; +// $opts['settings'][$settings_key]['bucket_location'] = $settings[ $key ]['bucket_location']; +// } else { +//// $opts['clientid'] = $settings[ $key ]['clientid']; +//// $opts['secret'] = $settings[ $key ]['secret']; +//// $opts['project_id'] = $settings[ $key ]['project_id']; +//// $opts['bucket_path'] = $settings[ $key ]['bucket_path']; +// $opts['storage_class'] = $settings[ $key ]['storage_class']; +// $opts['bucket_location'] = $settings[ $key ]['bucket_location']; +// } +// UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else if ( 'updraft_onedrive' === $key ) { - $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_onedrive' ); - if (!is_array($opts)) - $opts = array(); - if(is_array($opts) && isset($opts['settings'])) { - $settings_key = key($opts['settings']); -// $opts['settings'][$settings_key]['clientid'] = $settings[ $key ]['clientid']; -// $opts['settings'][$settings_key]['secret'] = $settings[ $key ]['secret']; - $opts['settings'][$settings_key]['folder'] = $this->replace_tokens($settings[ $key ]['folder']); - } else { -// $opts['clientid'] = $settings[ $key ]['clientid']; -// $opts['secret'] = $settings[ $key ]['secret']; - $opts['folder'] = $this->replace_tokens($settings[ $key ]['folder']); - } - - UpdraftPlus_Options::update_updraft_option( $key, $opts ); + // do not saving from dashboard +// $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_onedrive' ); +// if (!is_array($opts)) +// $opts = array(); +// if(is_array($opts) && isset($opts['settings'])) { +// $settings_key = key($opts['settings']); +//// $opts['settings'][$settings_key]['clientid'] = $settings[ $key ]['clientid']; +//// $opts['settings'][$settings_key]['secret'] = $settings[ $key ]['secret']; +// $opts['settings'][$settings_key]['folder'] = $this->replace_tokens($settings[ $key ]['folder']); +// } else { +//// $opts['clientid'] = $settings[ $key ]['clientid']; +//// $opts['secret'] = $settings[ $key ]['secret']; +// $opts['folder'] = $this->replace_tokens($settings[ $key ]['folder']); +// } +// +// UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else if ( 'updraft_email' === $key ) { $value = $settings[ $key ]; // free version @@ -600,10 +603,10 @@ class MainWP_Child_Updraft_Plus_Backups { if(is_array($opts) && isset($opts['settings'])) { $settings_key = key($opts['settings']); - $opts['settings'][$settings_key]['url'] = $settings[ $key ]['url']; + $opts['settings'][$settings_key]['url'] = $this->replace_tokens( $settings[ $key ]['url'] ); UpdraftPlus_Options::update_updraft_option( 'updraft_webdav', $opts ); } - + } else if ( 'updraft_backblaze' === $key ) { $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_backblaze' ); if (!is_array($opts)) @@ -612,8 +615,14 @@ class MainWP_Child_Updraft_Plus_Backups { $settings_key = key($opts['settings']); $opts['settings'][$settings_key]['account_id'] = $settings[ $key ]['account_id']; $opts['settings'][$settings_key]['key'] = $settings[ $key ]['key']; - $opts['settings'][$settings_key]['bucket_name'] = $this->replace_tokens( $settings[ $key ]['bucket_name'] ); - $opts['settings'][$settings_key]['backup_path'] = $this->replace_tokens( $settings[ $key ]['backup_path'] ); + $bname = $this->replace_tokens( $settings[ $key ]['bucket_name'] ); + $bpath = $this->replace_tokens( $settings[ $key ]['backup_path'] ); + $bname = str_replace('.', '-', $bname); + $bpath = str_replace('.', '-', $bpath); + $bname = str_replace('_', '', $bname); // to fix strange character + $bpath = str_replace('_', '', $bpath); + $opts['settings'][$settings_key]['bucket_name'] = $bname; + $opts['settings'][$settings_key]['backup_path'] = $bpath; UpdraftPlus_Options::update_updraft_option( $key, $opts ); } } else { @@ -899,7 +908,8 @@ class MainWP_Child_Updraft_Plus_Backups { 'm' => '' . __( 'Start backup', 'updraftplus' ) . ': ' . htmlspecialchars( __( 'OK. You should soon see activity in the "Last log message" field below.', 'updraftplus' ) ), ); - $this->close_browser_connection( $msg ); + // to fix issue for some site + //$this->close_browser_connection( $msg ); $options = array( 'nocloud' => $backupnow_nocloud, 'use_nonce' => $nonce ); if ( ! empty( $_REQUEST['onlythisfileentity'] ) && is_string( $_REQUEST['onlythisfileentity'] ) ) { @@ -910,6 +920,8 @@ class MainWP_Child_Updraft_Plus_Backups { do_action( $event, apply_filters( 'updraft_backupnow_options', $options, array() ) ); + return $msg; + // not used anymore // if (wp_schedule_single_event(time()+5, $event, array($backupnow_nocloud)) === false) { // $updraftplus->log("A backup run failed to schedule"); @@ -920,9 +932,9 @@ class MainWP_Child_Updraft_Plus_Backups { // //echo htmlspecialchars(__('OK. You should soon see activity in the "Last log message" field below.','updraftplus'))."
".__('Nothing happening? Follow this link for help.','updraftplus')."
"; // $updraftplus->log("A backup run has been scheduled"); // } - $out = array( 'result' => 'OK' ); - - return $out; +// $out = array( 'result' => 'OK' ); +// +// return $out; } function activejobs_list() { @@ -3926,6 +3938,7 @@ ENDHERE; add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); add_action( 'admin_menu', array( $this, 'remove_menu' ) ); add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); + add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) ); add_action( 'wp_before_admin_bar_render', array( $this, 'wp_before_admin_bar_render' ), 99 ); add_action( 'admin_init', array( $this, 'remove_notices' ) ); } @@ -3972,10 +3985,19 @@ ENDHERE; } } + function hide_update_notice( $slugs ) { + $slugs[] = 'updraftplus/updraftplus.php'; + return $slugs; + } + function remove_update_nag( $value ) { if ( isset( $_POST['mainwpsignature'] ) ) { return $value; } + if (! MainWP_Helper::is_screen_with_update()) { + return $value; + } + if ( isset( $value->response['updraftplus/updraftplus.php'] ) ) { unset( $value->response['updraftplus/updraftplus.php'] ); } diff --git a/class/class-mainwp-child-wordfence.php b/class/class-mainwp-child-wordfence.php index badb9d7..f0df913 100644 --- a/class/class-mainwp-child-wordfence.php +++ b/class/class-mainwp-child-wordfence.php @@ -666,33 +666,35 @@ class MainWP_Child_Wordfence { $lastcheck = time() - 3600 * 24 * 10; // check 10 days ago } - $status_table = $wpdb->base_prefix . 'wfStatus'; + $table_wfStatus = wfDB::networkTable('wfStatus'); + // to fix prepare sql empty - $sql = sprintf( "SELECT * FROM {$status_table} WHERE ctime >= %d AND level = 1 AND type = 'info' AND msg LIKE ", $lastcheck ); - $sql .= " 'Scan Complete. %';"; + $sql = sprintf( "SELECT * FROM {$table_wfStatus} WHERE ctime >= %d AND level = 1 AND type = 'info' AND msg LIKE ", $lastcheck ); + $sql .= " 'Scan Complete.%';"; $rows = MainWP_Child_DB::_query( $sql, $wpdb->dbh ); + $scan_time = array(); if ( $rows ) { while ( $row = MainWP_Child_DB::fetch_array( $rows ) ) { - $message = "Wordfence scan completed"; - $scan_time = $row['ctime']; + $scan_time[$row['ctime']] = $row['msg']; + } + } - $sql = sprintf( "SELECT * FROM {$status_table} WHERE ctime > %d AND ctime < %d AND level = 10 AND type = 'info' AND msg LIKE ", $scan_time, $scan_time + 100 ); // to get nearest SUM_FINAL msg + if ($scan_time) { + $message = "Wordfence scan completed"; + foreach($scan_time as $ctime => $details) { + $sql = sprintf( "SELECT * FROM {$table_wfStatus} WHERE ctime > %d AND ctime < %d AND level = 10 AND type = 'info' AND msg LIKE ", $ctime, $ctime + 100 ); // to get nearest SUM_FINAL msg $sql .= " 'SUM_FINAL:Scan complete.%';"; + $sum_rows = MainWP_Child_DB::_query( $sql, $wpdb->dbh ); $result = ''; if ($sum_rows) { $sum_row = MainWP_Child_DB::fetch_array( $sum_rows ); if (is_array($sum_row) && isset($sum_row['msg'])) { - if ( false !== strpos( $sum_row['msg'], 'Congratulations, no problems found' ) ) { - $result = 'No issues detected'; - } else { - $result = 'Issues Detected'; - } + $result = $sum_row['msg']; } } - $details = $row['msg']; - do_action( 'mainwp_reports_wordfence_scan', $message, $scan_time, $details, $result ); + do_action( 'mainwp_reports_wordfence_scan', $message, $ctime, $details, $result ); } } @@ -830,10 +832,11 @@ class MainWP_Child_Wordfence { public function count_attacks_blocked($maxAgeDays) { global $wpdb; + $table_wfBlockedIPLog = wfDB::networkTable('wfBlockedIPLog'); $interval = 'FLOOR(UNIX_TIMESTAMP(DATE_SUB(NOW(), interval ' . $maxAgeDays . ' day)) / 86400)'; return $wpdb->get_var(<<prefix}wfBlockedIPLog +FROM {$table_wfBlockedIPLog} WHERE unixday >= {$interval} SQL ); @@ -841,10 +844,9 @@ SQL function get_lastscan() { - global $wpdb; $wfdb = new wfDB(); - $p = $wpdb->base_prefix; - $ctime = $wfdb->querySingle("SELECT MAX(ctime) FROM $p"."wfStatus WHERE msg LIKE '%SUM_PREP:Preparing a new scan.%'"); + $table_wfStatus = wfDB::networkTable('wfStatus'); + $ctime = $wfdb->querySingle("SELECT MAX(ctime) FROM {$table_wfStatus} WHERE msg LIKE '%SUM_PREP:Preparing a new scan.%'"); return $ctime; } @@ -1145,9 +1147,8 @@ SQL if (in_array('other_WFNet', $saving_opts)) { if ( ! $opts['other_WFNet'] ) { $wfdb = new wfDB(); - global $wpdb; - $p = $wpdb->base_prefix; - $wfdb->queryWrite( "delete from $p" . 'wfBlocks where wfsn=1 and permanent=0' ); + $table_wfBlocks7 = wfDB::networkTable('wfBlocks7'); + $wfdb->queryWrite( "delete from {$table_wfBlocks7} where wfsn=1 and permanent=0" ); } } @@ -1158,7 +1159,7 @@ SQL $regenerateHtaccess = true; } } - //error_log(print_r($opts, true)); + // $to_fix_boolean_values = array( // 'scansEnabled_checkGSB', // 'spamvertizeCheck', @@ -1372,9 +1373,8 @@ SQL if ( ! $opts['other_WFNet'] ) { $wfdb = new wfDB(); - global $wpdb; - $p = $wpdb->base_prefix; - $wfdb->queryWrite( "delete from $p" . 'wfBlocks where wfsn=1 and permanent=0' ); + $table_wfBlocks7 = wfDB::networkTable('wfBlocks7'); + $wfdb->queryWrite( "delete from {$table_wfBlocks7} where wfsn=1 and permanent=0" ); } $regenerateHtaccess = false; @@ -1493,51 +1493,109 @@ SQL } public function export_settings(){ - /** @var wpdb $wpdb */ - global $wpdb; + + $export = array(); + + //Basic Options $keys = wfConfig::getExportableOptionsKeys(); - $export = array(); - foreach($keys as $key){ + foreach ($keys as $key) { $export[$key] = wfConfig::get($key, ''); } - $export['scanScheduleJSON'] = json_encode(wfConfig::get_ser('scanSched', array())); - $export['schedMode'] = wfConfig::get('schedMode', ''); - // Any user supplied blocked IPs. - $export['_blockedIPs'] = $wpdb->get_results('SELECT *, HEX(IP) as IP FROM ' . $wpdb->base_prefix . 'wfBlocks WHERE wfsn = 0 AND permanent = 1'); + //Serialized Options + $export['scanSched'] = wfConfig::get_ser('scanSched', array()); - // Any advanced blocking stuff too. - $export['_advancedBlocking'] = $wpdb->get_results('SELECT * FROM ' . $wpdb->base_prefix . 'wfBlocksAdv'); + //Table-based Options + $export['blocks'] = wfBlock::exportBlocks(); + //Make the API call try { $api = new wfAPI(wfConfig::get('apiKey'), wfUtils::getWPVersion()); - $res = $api->call('export_options', array(), $export); - if($res['ok'] && $res['token']){ + $res = $api->call('export_options', array(), array('export' => json_encode($export))); + if ($res['ok'] && $res['token']) { return array( 'ok' => 1, 'token' => $res['token'], ); - } else { - throw new Exception("Invalid response: " . var_export($res, true)); } - } catch(Exception $e){ - return array('errorExport' => "An error occurred: " . $e->getMessage()); + else if ($res['err']) { + return array('errorExport' => __("An error occurred: ", 'wordfence') . $res['err']); + } + else { + throw new Exception(__("Invalid response: ", 'wordfence') . var_export($res, true)); + } + } + catch (Exception $e) { + return array('errorExport' => __("An error occurred: ", 'wordfence') . $e->getMessage()); } } public function import_settings(){ $token = $_POST['token']; - try { - $totalSet = wordfence::importSettings($token); - return array( - 'ok' => 1, - 'totalSet' => $totalSet, - 'settings' => $this->get_settings() - ); - } catch(Exception $e){ + try { + $api = new wfAPI(wfConfig::get('apiKey'), wfUtils::getWPVersion()); + $res = $api->call('import_options', array(), array('token' => $token)); + if ($res['ok'] && $res['export']) { + $totalSet = 0; + $import = @json_decode($res['export'], true); + if (!is_array($import)) { + return array('errorImport' => __("An error occurred: Invalid options format received.", 'wordfence')); + } + + //Basic Options + $keys = wfConfig::getExportableOptionsKeys(); + $toSet = array(); + foreach ($keys as $key) { + if (isset($import[$key])) { + $toSet[$key] = $import[$key]; + } + } + + if (count($toSet)) { + $validation = wfConfig::validate($toSet); + $skipped = array(); + if ($validation !== true) { + foreach ($validation as $error) { + $skipped[$error['option']] = $error['error']; + unset($toSet[$error['option']]); + } + } + + $totalSet += count($toSet); + wfConfig::save(wfConfig::clean($toSet)); + } + + //Serialized Options + if (isset($import['scanSched']) && is_array($import['scanSched'])) { + wfConfig::set_ser('scanSched', $import['scanSched']); + wfScanner::shared()->scheduleScans(); + $totalSet++; + } + + //Table-based Options + if (isset($import['blocks']) && is_array($import['blocks'])) { + wfBlock::importBlocks($import['blocks']); + $totalSet += count($import['blocks']); + } + + return array( + 'ok' => 1, + 'totalSet' => $totalSet, + 'settings' => $this->get_settings() + ); + } + else if ($res['err']) { + return array('errorImport' => "An error occurred: " . $res['err']); + } + else { + throw new Exception("Invalid response: " . var_export($res, true)); + } + } + catch (Exception $e) { return array('errorImport' => "An error occurred: " . $e->getMessage()); } + } function get_settings() { @@ -1553,15 +1611,15 @@ SQL function ticker() { $wfdb = new wfDB(); - global $wpdb; - $p = $wpdb->base_prefix; $serverTime = $wfdb->querySingle( 'select unix_timestamp()' ); + $table_wfStatus = wfDB::networkTable('wfStatus'); + $jsonData = array( 'serverTime' => $serverTime, - 'serverMicrotime' => microtime(true), - 'msg' => $wfdb->querySingle( "select msg from $p" . 'wfStatus where level < 3 order by ctime desc limit 1' ), + 'serverMicrotime' => microtime(true), + 'msg' => $wfdb->querySingle( "select msg from {$table_wfStatus} where level < 3 order by ctime desc limit 1" ), ); $events = array(); diff --git a/class/class-mainwp-child-wp-rocket.php b/class/class-mainwp-child-wp-rocket.php index 1a5632d..cfdbd6d 100644 --- a/class/class-mainwp-child-wp-rocket.php +++ b/class/class-mainwp-child-wp-rocket.php @@ -12,7 +12,7 @@ class MainWP_Child_WP_Rocket { } public function __construct() { - + } public function init() { @@ -21,25 +21,26 @@ class MainWP_Child_WP_Rocket { } add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); - + if ( get_option( 'mainwp_wprocket_hide_plugin' ) === 'hide' ) { add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); add_action( 'admin_menu', array( $this, 'remove_menu' ) ); add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); + add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) ); add_action( 'wp_before_admin_bar_render', array( $this, 'wp_before_admin_bar_render' ), 99 ); add_action( 'admin_init', array( $this, 'remove_notices' ) ); } } - + // ok - public function syncOthersData( $information, $data = array() ) { - if ( isset( $data['syncWPRocketData'] ) && ( 'yes' === $data['syncWPRocketData'] ) ) { + public function syncOthersData( $information, $data = array() ) { + if ( isset( $data['syncWPRocketData'] ) && ( 'yes' === $data['syncWPRocketData'] ) ) { try{ - $data = array( 'rocket_boxes' => get_user_meta( $GLOBALS['current_user']->ID, 'rocket_boxes', true )); - $information['syncWPRocketData'] = $data; + $data = array( 'rocket_boxes' => get_user_meta( $GLOBALS['current_user']->ID, 'rocket_boxes', true )); + $information['syncWPRocketData'] = $data; } catch(Exception $e) { } - } + } return $information; } @@ -79,10 +80,20 @@ class MainWP_Child_WP_Rocket { } } + function hide_update_notice( $slugs ) { + $slugs[] = 'wp-rocket/wp-rocket.php'; + return $slugs; + } + function remove_update_nag( $value ) { if ( isset( $_POST['mainwpsignature'] ) ) { return $value; } + + if (! MainWP_Helper::is_screen_with_update()) { + return $value; + } + if ( isset( $value->response['wp-rocket/wp-rocket.php'] ) ) { unset( $value->response['wp-rocket/wp-rocket.php'] ); } @@ -195,7 +206,7 @@ class MainWP_Child_WP_Rocket { } } - function purge_cache_all() { + function purge_cache_all() { if ( function_exists( 'rocket_clean_domain' ) || function_exists( 'rocket_clean_minify' ) || function_exists( 'create_rocket_uniqid' ) ) { set_transient( 'rocket_clear_cache', 'all', HOUR_IN_SECONDS ); // Remove all cache files @@ -208,7 +219,11 @@ class MainWP_Child_WP_Rocket { if ( function_exists( 'rocket_clean_cache_busting' )) { rocket_clean_cache_busting(); } - + + if ( !function_exists( 'rocket_dismiss_boxes' ) && defined('WP_ROCKET_ADMIN_PATH')) { + require_once WP_ROCKET_ADMIN_PATH . 'admin.php'; + } + // Generate a new random key for minify cache file $options = get_option( WP_ROCKET_SLUG ); $options['minify_css_key'] = create_rocket_uniqid(); @@ -248,7 +263,7 @@ class MainWP_Child_WP_Rocket { } } if (isset($_POST['do_database_optimization']) && !empty($_POST['do_database_optimization'])) { - $_POST['wp_rocket_settings']['submit_optimize'] = 1; // simulate POST + $_POST['wp_rocket_settings']['submit_optimize'] = 1; // simulate POST } update_option( WP_ROCKET_SLUG, $options ); @@ -328,7 +343,7 @@ class MainWP_Child_WP_Rocket { 'deferred_js_files' => array(), 'lazyload' => 0, 'lazyload_iframes' => 0, - 'lazyload_youtube' =>0, + 'lazyload_youtube' =>0, 'minify_css' => 0, // 'minify_css_key' => $minify_css_key, 'minify_concatenate_css' => 0, diff --git a/class/class-mainwp-child.php b/class/class-mainwp-child.php index 5e4f9e7..015ebfa 100644 --- a/class/class-mainwp-child.php +++ b/class/class-mainwp-child.php @@ -57,6 +57,14 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus } if ( empty( $nonce ) ) { + + // To fix verify nonce conflict #1 + // this is fake post field to fix some conflict of wp_verify_nonce() + // just return false to unverify nonce, does not exit + if ( isset($_POST[$action]) && ($_POST[$action] == 'mainwp-bsm-unverify-nonce')) { + return false; + } + // to help tracing the conflict verify nonce with other plugins @ob_start(); @debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); @@ -64,8 +72,8 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus die( '' . base64_encode( json_encode( array( 'error' => 'You dont send nonce: ' . $action . '
Trace: ' .$stackTrace) ) ) . '
' ); } - // To fix verify nonce conflict #1 - // this is fake nonce to fix some conflict of wp_verify_nonce + // To fix verify nonce conflict #2 + // this is fake nonce to fix some conflict of wp_verify_nonce() // just return false to unverify nonce, does not exit if ($nonce == 'mainwp-bsm-unverify-nonce') { return false; @@ -87,8 +95,8 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus return 2; } - // To fix verify nonce conflict #2 - // this is fake post field to fix some conflict of wp_verify_nonce + // To fix verify nonce conflict #3 + // this is fake post field to fix some conflict of wp_verify_nonce() // just return false to unverify nonce, does not exit if ( isset($_POST[$action]) && ($_POST[$action] == 'mainwp-bsm-unverify-nonce')) { return false; @@ -107,7 +115,7 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus } class MainWP_Child { - public static $version = '3.5.2'; + public static $version = '3.5.3'; private $update_version = '1.3'; private $callableFunctions = array( @@ -1344,8 +1352,8 @@ class MainWP_Child { exit(); } - remove_action( 'admin_init', 'send_frame_options_header' ); - remove_action( 'login_init', 'send_frame_options_header' ); +// remove_action( 'admin_init', 'send_frame_options_header' ); +// remove_action( 'login_init', 'send_frame_options_header' ); // Call Heatmap if ( 'yes' === get_option( 'heatMapExtensionLoaded' ) ) { @@ -3729,7 +3737,7 @@ class MainWP_Child { } $information['categories'] = $categories; $get_file_size = apply_filters('mainwp-child-get-total-size', true); - if ($get_file_size) { + if ( $get_file_size && isset( $_POST['cloneSites'] ) && ( '0' !== $_POST['cloneSites'] ) ) { $max_exe = ini_get( 'max_execution_time' ); // to fix issue of some hosts have limit of execution time if ($max_exe > 20) { $information['totalsize'] = $this->getTotalFileSize(); diff --git a/class/class-mainwp-client-report.php b/class/class-mainwp-client-report.php index 699beb5..6340943 100644 --- a/class/class-mainwp-client-report.php +++ b/class/class-mainwp-client-report.php @@ -439,6 +439,19 @@ class MainWP_Client_Report { } } + // to avoid WC order_note, action_log + if ( 'comments' === $context ) { + if ( isset( $record->meta ) ) { + if ( isset( $record->meta[ 'comment_type' ] ) && is_array($record->meta[ 'comment_type' ])) { + $cmtype = current($record->meta[ 'comment_type' ]); + if ( $cmtype == 'order_note' || $cmtype == 'action_log') { + continue; + } + } + } + } + + } $count ++; @@ -716,7 +729,20 @@ class MainWP_Client_Report { case 'details': case 'result': if ( 'wordfence' === $context || 'maintenance' === $context ) { - $token_values[ $token ] = $this->get_stream_meta_data( $record, $data ); + $meta_value = $this->get_stream_meta_data( $record, $data ); + // to fix + if ('wordfence' === $context && $data == 'result') { + // SUM_FINAL:Scan complete. You have xxx new issues to fix. See below. + // SUM_FINAL:Scan complete. Congratulations, no new problems found + if (stripos($meta_value, 'Congratulations')) { + $meta_value = 'No issues detected'; + } else if (stripos($meta_value, 'You have')) { + $meta_value = 'Issues Detected'; + } else { + $meta_value = ''; + } + } + $token_values[ $token ] = $meta_value; } break; case 'destination': // backup cases @@ -781,7 +807,7 @@ class MainWP_Client_Report { } function set_showhide() { - MainWP_Helper::update_option( 'mainwp_creport_ext_branding_enabled', 'Y', 'yes' ); +// MainWP_Helper::update_option( 'mainwp_creport_ext_branding_enabled', 'Y', 'yes' ); $hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : ''; MainWP_Helper::update_option( 'mainwp_creport_branding_stream_hide', $hide, 'yes' ); $information['result'] = 'SUCCESS'; @@ -790,21 +816,41 @@ class MainWP_Client_Report { } public function creport_init() { - if ( get_option( 'mainwp_creport_ext_branding_enabled' ) !== 'Y' ) { - return; - } +// if ( get_option( 'mainwp_creport_ext_branding_enabled' ) !== 'Y' ) { +// return; +// } + $hide_nag = false; if ( get_option( 'mainwp_creport_branding_stream_hide' ) === 'hide' ) { add_filter( 'all_plugins', array( $this, 'creport_branding_plugin' ) ); add_action( 'admin_menu', array( $this, 'creport_remove_menu' ) ); - add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); + $hide_nag = true; } + + if ( MainWP_Child_Branding::is_branding() ) { + $hide_nag = true; + } + + if ($hide_nag) { + add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); + add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) ); + } } + function hide_update_notice( $slugs ) { + $slugs[] = 'mainwp-child-reports/mainwp-child-reports.php'; + return $slugs; + } + function remove_update_nag( $value ) { - if ( isset( $_POST['mainwpsignature'] ) ) { + if ( isset( $_POST['mainwpsignature'] ) ) { return $value; } + + if (! MainWP_Helper::is_screen_with_update()) { + return $value; + } + if ( isset( $value->response['mainwp-child-reports/mainwp-child-reports.php'] ) ) { unset( $value->response['mainwp-child-reports/mainwp-child-reports.php'] ); } diff --git a/class/class-mainwp-helper.php b/class/class-mainwp-helper.php index 67de8fb..4de0a36 100644 --- a/class/class-mainwp-helper.php +++ b/class/class-mainwp-helper.php @@ -1417,6 +1417,22 @@ static function remove_filters_with_method_name( $hook_name = '', $method_name = return function_exists( 'openssl_verify' ); } + public static function is_screen_with_update() { + + if ( ( defined('DOING_AJAX') && DOING_AJAX ) || ( defined('DOING_CRON') && DOING_CRON ) ) + return false; + + if (function_exists('get_current_screen')) { + $screen = get_current_screen(); + if ( $screen ) { + if ( $screen->base == 'update-core' && $screen->parent_file == 'index.php' ) { + return true; + } + } + } + return false; + } + public static function check_files_exists( $files = array(), $return = false ) { $missing = array(); if (is_array($files)) { diff --git a/mainwp-child.php b/mainwp-child.php index b8acb92..17add8f 100644 --- a/mainwp-child.php +++ b/mainwp-child.php @@ -6,11 +6,11 @@ Author: MainWP Author URI: https://mainwp.com Text Domain: mainwp-child - Version: 3.5.2 + Version: 3.5.3 */ -if ( ( isset( $_REQUEST['heatmap'] ) && '1' === $_REQUEST['heatmap'] ) || ( isset( $_REQUEST['mainwpsignature'] ) && ( ! empty( $_REQUEST['mainwpsignature'] ) ) ) ) { - header( 'X-Frame-Options: ALLOWALL' ); -} +//if ( ( isset( $_REQUEST['heatmap'] ) && '1' === $_REQUEST['heatmap'] ) || ( isset( $_REQUEST['mainwpsignature'] ) && ( ! empty( $_REQUEST['mainwpsignature'] ) ) ) ) { +// header( 'X-Frame-Options: ALLOWALL' ); +//} //header('X-Frame-Options: GOFORIT'); include_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php' ); //Version information from wordpress @@ -35,7 +35,7 @@ function mainwp_child_autoload( $class_name ) { if ( function_exists( 'spl_autoload_register' ) ) { spl_autoload_register( 'mainwp_child_autoload' ); -} +} $mainWPChild = new MainWP_Child( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . plugin_basename( __FILE__ ) ); register_activation_hook( __FILE__, array( $mainWPChild, 'activation' ) );