Fixed: error saving BSM keys

Fixed: issue of saving Wordfence key
Fixed: issue of overwrite php error config
Fixed: issue of a big child plugin option value
Fixed: error get update info of some premium plugin
Fixed: error for logging reports update post
This commit is contained in:
thanghv 2020-02-25 19:41:28 +07:00
parent fbc6ad0fb8
commit 927b138610
4 changed files with 106 additions and 21 deletions

View file

@ -21,9 +21,11 @@ class MainWP_Child_Skeleton_Key {
$error = error_get_last();
if ( isset( $error['type'] ) && in_array($error['type'], array(1, 4, 16, 64, 256) ) && isset( $error['message'] ) ) {
MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
} else {
MainWP_Helper::write( MainWP_Child_Skeleton_Key::$information );
}
// to fix issue double <mainwp></mainwp> header in response
// else {
// MainWP_Helper::write( MainWP_Child_Skeleton_Key::$information );
// }
}
register_shutdown_function( 'mainwp_skeleton_key_handle_fatal_error' );

View file

@ -1282,53 +1282,119 @@ SQL
// if saving then validate data
if (in_array('apiKey', $saving_opts)) {
$apiKey = trim( $_POST['apiKey'] );
if ( ! $apiKey ) { //Empty API key (after trim above), then try to get one.
$apiKey = strtolower(trim($apiKey));
$existingAPIKey = wfConfig::get('apiKey', '');
$ping = false;
if ( empty( $apiKey ) && empty($existingAPIKey) ) { // then try to get one.
$api = new wfAPI( '', wfUtils::getWPVersion() );
try {
$keyData = $api->call( 'get_anon_api_key' );
if ( $keyData['ok'] && $keyData['apiKey'] ) {
wfConfig::set( 'apiKey', $keyData['apiKey'] );
wfConfig::set( 'isPaid', 0 );
$result['apiKey'] = $keyData['apiKey'];
wfConfig::set('keyType', wfAPI::KEY_TYPE_FREE);
wordfence::licenseStatusChanged();
$result['apiKey'] = $apiKey = $keyData['apiKey'];
$result['isPaid'] = 0;
$reload = 'reload';
} else {
throw new Exception( "We could not understand the Wordfence server's response because it did not contain an 'ok' and 'apiKey' element." );
throw new Exception("The Wordfence server's response did not contain the expected elements.");
}
} catch ( Exception $e ) {
$result['error'] = 'Your options have been saved, but we encountered a problem. You left your API key blank, so we tried to get you a free API key from the Wordfence servers. However we encountered a problem fetching the free key: ' . htmlentities( $e->getMessage() );
$result['error'] = 'Your options have been saved, but you left your license key blank, so we tried to get you a free license key from the Wordfence servers. There was a problem fetching the free key: ' . wp_kses( $e->getMessage(), array() );
return $result;
}
} else if ( wfConfig::get( 'apiKey' ) !== $apiKey ) {
} else if ( !empty( $apiKey ) && $existingAPIKey != $apiKey ) {
$api = new wfAPI( $apiKey, wfUtils::getWPVersion() );
try {
$res = $api->call( 'check_api_key', array(), array() );
$res = $api->call('check_api_key', array(), array('previousLicense' => $existingAPIKey));
if ( $res['ok'] && isset( $res['isPaid'] ) ) {
wfConfig::set( 'apiKey', $apiKey );
wfConfig::set( 'isPaid', $res['isPaid'] ); //res['isPaid'] is boolean coming back as JSON and turned back into PHP struct. Assuming JSON to PHP handles bools.
// wfConfig::set( 'apiKey', $apiKey );
// wfConfig::set( 'isPaid', $res['isPaid'] ); //res['isPaid'] is boolean coming back as JSON and turned back into PHP struct. Assuming JSON to PHP handles bools.
// $result['apiKey'] = $apiKey;
// $result['isPaid'] = $res['isPaid'];
// if ( $res['isPaid'] ) {
// $result['paidKeyMsg'] = true;
// }
$isPaid = wfUtils::truthyToBoolean($res['isPaid']);
wfConfig::set('apiKey', $apiKey);
wfConfig::set('isPaid', $isPaid); //res['isPaid'] is boolean coming back as JSON and turned back into PHP struct. Assuming JSON to PHP handles bools.
wordfence::licenseStatusChanged();
if (!$isPaid) {
wfConfig::set('keyType', wfAPI::KEY_TYPE_FREE);
}
$result['apiKey'] = $apiKey;
$result['isPaid'] = $res['isPaid'];
if ( $res['isPaid'] ) {
$result['isPaid'] = $isPaid;
if ( $isPaid ) {
$result['paidKeyMsg'] = true;
}
$ping = true;
$reload = 'reload';
} else {
throw new Exception( 'We could not understand the Wordfence API server reply when updating your API key.' );
}
} catch ( Exception $e ) {
$result['error'] = 'Your options have been saved. However we noticed you changed your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities( $e->getMessage() );
return $result;
}
} else {
$ping = true;
$apiKey = $existingAPIKey;
}
if ( $ping ) {
$api = new wfAPI($apiKey, wfUtils::getWPVersion());
try {
$api = new wfAPI( $apiKey, wfUtils::getWPVersion() );
$res = $api->call( 'ping_api_key', array(), array() );
} catch ( Exception $e ) {
$result['error'] = 'Your options have been saved. However we noticed you do not change your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities( $e->getMessage() );
$keyType = wfAPI::KEY_TYPE_FREE;
$keyData = $api->call('ping_api_key', array(), array('supportHash' => wfConfig::get('supportHash', ''), 'whitelistHash' => wfConfig::get('whitelistHash', '')));
if (isset($keyData['_isPaidKey'])) {
$keyType = wfConfig::get('keyType');
}
if (isset($keyData['dashboard'])) {
wfConfig::set('lastDashboardCheck', time());
wfDashboard::processDashboardResponse($keyData['dashboard']);
}
if (isset($keyData['support']) && isset($keyData['supportHash'])) {
wfConfig::set('supportContent', $keyData['support']);
wfConfig::set('supportHash', $keyData['supportHash']);
}
if (isset($keyData['_whitelist']) && isset($keyData['_whitelistHash'])) {
wfConfig::setJSON('whitelistPresets', $keyData['_whitelist']);
wfConfig::set('whitelistHash', $keyData['_whitelistHash']);
}
if (isset($keyData['scanSchedule']) && is_array($keyData['scanSchedule'])) {
wfConfig::set_ser('noc1ScanSchedule', $keyData['scanSchedule']);
if (wfScanner::shared()->schedulingMode() == wfScanner::SCAN_SCHEDULING_MODE_AUTOMATIC) {
wfScanner::shared()->scheduleScans();
}
}
wfConfig::set('keyType', $keyType);
if (!isset($result['apiKey'])) {
$isPaid = ( $keyType == wfAPI::KEY_TYPE_FREE ) ? false : true;
$result['apiKey'] = $apiKey;
$result['isPaid'] = $isPaid;
if ( $isPaid ) {
$result['paidKeyMsg'] = true;
}
}
} catch ( Exception $e ) {
$result['error'] = 'Your options have been saved. However we tried to verify your license key with the Wordfence servers and received an error: ' . wp_kses($e->getMessage(), array()) ;
return $result;
}
}

View file

@ -3,6 +3,11 @@ if ( defined( 'MAINWP_DEBUG' ) && MAINWP_DEBUG === TRUE ) {
@error_reporting( E_ALL );
@ini_set( 'display_errors', TRUE );
@ini_set( 'display_startup_errors', TRUE );
} else {
if (isset($_REQUEST['mainwpsignature'])) {
@ini_set( 'display_errors', FALSE );
@error_reporting( 0 );
}
}
define( 'MAINWP_CHILD_NR_OF_COMMENTS', 50 );
@ -750,7 +755,7 @@ class MainWP_Child {
}
self::$subPages = $sub_pages;
self::$subPagesLoaded = true;
MainWP_Helper::update_option( 'mainwp_child_subpages', self::$subPages );
//MainWP_Helper::update_option( 'mainwp_child_subpages', self::$subPages ); // to fix error for some case
}
add_action( 'mainwp-child-pageheader', array( __CLASS__, 'render_header' ) );
add_action( 'mainwp-child-pagefooter', array( __CLASS__, 'render_footer' ) );
@ -3783,10 +3788,20 @@ class MainWP_Child {
$information['plugin_updates'] = array();
}
foreach( $cached_plugins_update as $slug => $plugin_update ) {
// to fix incorrect info
if ( !property_exists( $plugin_update, 'new_version' ) || empty( $plugin_update->new_version ) ) {
if ( !property_exists( $plugin_update, 'new_version' ) || empty( $plugin_update->new_version ) ) { // may do not need to check this?
// to fix for some premiums update info
if ( property_exists( $plugin_update, 'update' ) ) {
if ( !property_exists( $plugin_update->update, 'new_version' ) || empty( $plugin_update->update->new_version ) ) {
continue;
}
} else {
continue;
}
}
if ( !isset( $information['plugin_updates'][ $slug ] ) ) {
$information['plugin_updates'][ $slug ] = $plugin_update;
}

View file

@ -563,7 +563,7 @@ class MainWP_Helper {
//Save the post to the wp
remove_filter( 'content_save_pre', 'wp_filter_post_kses' ); // to fix brake scripts or html
$post_status = $new_post['post_status'];
$new_post['post_status'] = 'auto-draft';
$new_post['post_status'] = 'auto-draft'; // child reports: to logging as created post
// update post
if ( $edit_post_id ) {
@ -572,6 +572,7 @@ class MainWP_Helper {
if ( $current_post && ( ( !isset( $new_post['post_type'] ) && $current_post->post_type == 'post' ) || ( isset( $new_post['post_type'] ) && $new_post['post_type'] == $current_post->post_type ) ) ) {
$new_post['ID'] = $edit_post_id;
}
$new_post['post_status'] = $post_status; // child reports: to logging as update post
}
$new_post_id = wp_insert_post( $new_post, $wp_error );
@ -584,6 +585,7 @@ class MainWP_Helper {
return array( 'error' => 'Empty post id');
}
if ( !$edit_post_id )
wp_update_post( array( 'ID' => $new_post_id, 'post_status' => $post_status ) );
if ( ! empty( $terms ) ) {