Refactoring

This commit is contained in:
thanghv 2020-05-30 01:13:29 +07:00
parent d76f9a4186
commit 24d898716c
10 changed files with 47 additions and 1103 deletions

View file

@ -1,6 +1,6 @@
<?php
/**
* MainWP Child Skeleton Key
* MainWP Child Bulk Settings Manager
*
* This file handles connecting to the child site as a browser
* in order performs an HTTP request using the POST method and returns its response.
@ -9,11 +9,11 @@
namespace MainWP\Child;
/**
* Class MainWP_Child_Skeleton_Key
* Class MainWP_Child_Bulk_Settings_Manager
*
* @package MainWP\Child
*/
class MainWP_Child_Skeleton_Key {
class MainWP_Child_Bulk_Settings_Manager {
/**
* @static
@ -33,9 +33,9 @@ class MainWP_Child_Skeleton_Key {
public $plugin_translate = 'mainwp-child';
/**
* Create public static instance for MainWP_Child_Skeleton_Key.
* Create public static instance for MainWP_Child_Bulk_Settings_Manager.
*
* @return MainWP_Child_Skeleton_Key|null
* @return MainWP_Child_Bulk_Settings_Manager|null
*/
public static function instance() {
if ( null === self::$instance ) {
@ -51,19 +51,22 @@ class MainWP_Child_Skeleton_Key {
public function action() {
/**
* MainWP skeleton key fatal error handler.
* MainWP bulk settings manager fatal error handler.
*/
function mainwp_skeleton_key_handle_fatal_error() {
function mainwp_bulk_settings_manager_handle_fatal_error() {
$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'] ) );
}
}
register_shutdown_function( 'MainWP\Child\MainWP_Child_Skeleton_Key\mainwp_skeleton_key_handle_fatal_error' );
register_shutdown_function( 'MainWP\Child\mainwp_bulk_settings_manager_handle_fatal_error' );
switch ( $_POST['action'] ) {
case 'skeleton_key_visit_site_as_browser':
case 'skeleton_key_visit_site_as_browser': // deprecated.
$information = $this->visit_site_as_browser();
break;
case 'bulk_settings_manager_visit_site_as_browser':
$information = $this->visit_site_as_browser();
break;
case 'save_settings':
@ -143,8 +146,8 @@ class MainWP_Child_Skeleton_Key {
$get_args = array();
}
$get_args['skeleton_keyuse_nonce_key'] = intval( time() );
$get_args['skeleton_keyuse_nonce_hmac'] = hash_hmac( 'sha256', $get_args['skeleton_keyuse_nonce_key'], NONCE_KEY );
$get_args['bulk_settings_manageruse_nonce_key'] = intval( time() );
$get_args['bulk_settings_manageruse_nonce_hmac'] = hash_hmac( 'sha256', $get_args['bulk_settings_manageruse_nonce_key'], NONCE_KEY );
$good_nonce = null;
if ( isset( $args['nonce'] ) && ! empty( $args['nonce'] ) ) {
@ -205,8 +208,8 @@ class MainWP_Child_Skeleton_Key {
}
}
}
unset( $get_args['skeleton_keyuse_nonce_key'] );
unset( $get_args['skeleton_keyuse_nonce_hmac'] );
unset( $get_args['bulk_settings_manageruse_nonce_key'] );
unset( $get_args['bulk_settings_manageruse_nonce_hmac'] );
return array(
'success' => 1,

View file

@ -38,7 +38,6 @@ class MainWP_Child_Callable {
'user_action' => 'user_action',
'search_users' => 'search_users',
'maintenance_site' => 'maintenance_site',
'keyword_links_action' => 'keyword_links_action',
'branding_child_plugin' => 'branding_child_plugin',
'code_snippet' => 'code_snippet',
'uploader_action' => 'uploader_action',
@ -57,7 +56,8 @@ class MainWP_Child_Callable {
'backwpup' => 'backwpup',
'wp_rocket' => 'wp_rocket',
'settings_tools' => 'settings_tools',
'skeleton_key' => 'skeleton_key',
'skeleton_key' => 'bulk_settings_manager', // deprecated.
'bulk_settings_manager' => 'bulk_settings_manager',
'custom_post_type' => 'custom_post_type',
'backup_buddy' => 'backup_buddy',
'get_site_icon' => 'get_site_icon',
@ -294,8 +294,8 @@ class MainWP_Child_Callable {
MainWP_Child_Misc::get_instance()->do_security_un_fix();
}
public function skeleton_key() {
MainWP_Child_Skeleton_Key::instance()->action();
public function bulk_settings_manager() {
MainWP_Child_Bulk_Settings_Manager::instance()->action();
}
public function custom_post_type() {
@ -404,10 +404,6 @@ class MainWP_Child_Callable {
MainWP_Helper::write( array( 'result' => 'ok' ) );
}
public function keyword_links_action() {
MainWP_Keyword_Links::instance()->action();
}
public function branding_child_plugin() {
MainWP_Child_Branding::instance()->action();
}

View file

@ -922,6 +922,7 @@ class MainWP_Child_Posts {
'_bulkpost_do_not_del',
'_mainwp_spin_me',
'_mainwp_boilerplate_sites_posts',
'_mainwp_boilerplate',
'_mainwp_post_plus',
'_saved_as_draft',
'_saved_draft_categories',

View file

@ -69,7 +69,6 @@ class MainWP_Child {
$this->update();
$this->load_all_options();
$this->plugin_dir = dirname( $plugin_file );
$this->plugin_slug = plugin_basename( $plugin_file );
add_action( 'template_redirect', array( $this, 'template_redirect' ) );
@ -138,18 +137,12 @@ class MainWP_Child {
$suppress = $wpdb->suppress_errors();
$options = array(
'mainwp_child_auth',
'mainwp_child_reports_db',
'mainwp_child_fix_htaccess',
'mainwp_child_reports_db',
'mainwp_child_pluginDir',
'mainwp_updraftplus_hide_plugin',
'mainwp_backwpup_ext_enabled',
'mainwpKeywordLinks',
'mainwp_backwpup_ext_enabled',
'mainwp_child_server',
'mainwp_kwl_options',
'mainwp_kwl_keyword_links',
'mainwp_keyword_links_htaccess_set',
'mainwp_pagespeed_hide_plugin',
'mainwp_kwl_enable_statistic',
'mainwp_pagespeed_hide_plugin',
'mainwp_child_clone_permalink',
'mainwp_child_restore_permalink',
'mainwp_ext_snippets_enabled',
@ -243,30 +236,10 @@ class MainWP_Child {
}
}
global $wp_rewrite;
$snPluginDir = basename( $this->plugin_dir );
if ( isset( $wp_rewrite->non_wp_rules[ 'wp-content/plugins/' . $snPluginDir . '/([^js\/]*)$' ] ) ) {
unset( $wp_rewrite->non_wp_rules[ 'wp-content/plugins/' . $snPluginDir . '/([^js\/]*)$' ] );
}
if ( isset( $wp_rewrite->non_wp_rules[ 'wp-content/plugins/' . $snPluginDir . '/(.*)$' ] ) ) {
unset( $wp_rewrite->non_wp_rules[ 'wp-content/plugins/' . $snPluginDir . '/(.*)$' ] );
}
if ( get_option( 'mainwp_child_fix_htaccess' ) === false ) {
include_once ABSPATH . '/wp-admin/includes/misc.php';
$wp_rewrite->flush_rules();
MainWP_Helper::update_option( 'mainwp_child_fix_htaccess', 'yes', 'yes' );
}
// if login required.
if ( isset( $_REQUEST['login_required'] ) && ( '1' === $_REQUEST['login_required'] ) && isset( $_REQUEST['user'] ) ) {
$valid_login_required = MainWP_Connect::instance()->parse_login_required();
// return parse init if login required are not valid.
// return if login required are not valid, if login is valid will redirect to admin side.
if ( ! $valid_login_required ) {
return;
}
@ -300,8 +273,6 @@ class MainWP_Child {
// execute callable functions here.
MainWP_Child_Callable::get_instance()->init_call_functions( $auth );
MainWP_Keyword_Links::instance()->parse_init_keyword_links();
}
/**

View file

@ -237,10 +237,10 @@ class MainWP_Connect {
$serverNoSsl = ( isset( $nossl ) && 1 === (int) $nossl );
if ( ( 1 === (int) $nossl ) || $serverNoSsl ) {
$nossl_key = get_option( 'mainwp_child_nossl_key' );
$auth = hash_equals( md5( $func . $nonce . $nossl_key ), base64_decode( $signature ) ); // // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
} else {
$auth = openssl_verify( $func . $nonce, base64_decode( $signature ), base64_decode( get_option( 'mainwp_child_pubkey' ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
if ( 1 !== $auth ) {
$auth = hash_equals( md5( $func . $nonce . $nossl_key ), base64_decode( $signature ) ); // // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible.
} else {
$auth = openssl_verify( $func . $nonce, base64_decode( $signature ), base64_decode( get_option( 'mainwp_child_pubkey' ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible.
if ( 1 !== $auth ) {
$auth = false;
}
}
@ -269,8 +269,7 @@ class MainWP_Connect {
}
}
if ( is_user_logged_in() ) {
global $current_user;
if ( is_user_logged_in() ) {
if ( 10 !== $current_user->wp_user_level && ( ! isset( $current_user->user_level ) || 10 !== $current_user->user_level ) && ! current_user_can( 'level_10' ) ) {
do_action( 'wp_logout' );
}
@ -280,18 +279,17 @@ class MainWP_Connect {
$file = $this->get_request_files();
$auth = self::instance()->auth( $signature, rawurldecode( ( isset( $_REQUEST['where'] ) ? $_REQUEST['where'] : $file ) ), isset( $_REQUEST['nonce'] ) ? $_REQUEST['nonce'] : '', isset( $_REQUEST['nossl'] ) ? $_REQUEST['nossl'] : 0 );
$auth = $this->auth( $signature, rawurldecode( ( isset( $_REQUEST['where'] ) ? $_REQUEST['where'] : $file ) ), isset( $_REQUEST['nonce'] ) ? $_REQUEST['nonce'] : '', isset( $_REQUEST['nossl'] ) ? $_REQUEST['nossl'] : 0 );
if ( ! $auth ) {
return;
return false;
}
if ( ! is_user_logged_in() || $username !== $current_user->user_login ) {
if ( ! $this->login( $username ) ) {
return;
return false;
}
global $current_user;
if ( 10 !== $current_user->wp_user_level && ( ! isset( $current_user->user_level ) || 10 !== $current_user->user_level ) && ! current_user_can( 'level_10' ) ) {
// if is not alternative admin login.
// it is connected admin login.
@ -299,11 +297,12 @@ class MainWP_Connect {
// log out if connected admin is not admin level 10.
do_action( 'wp_logout' );
return;
return false;
}
}
}
$this->check_redirects();
return true;
}
/**
@ -335,15 +334,15 @@ class MainWP_Connect {
private function check_redirects() {
if ( isset( $_REQUEST['fdl'] ) ) {
if ( stristr( $_REQUEST['fdl'], '..' ) ) {
return;
return false;
}
MainWP_Utility::instance()->upload_file( $_REQUEST['fdl'], isset( $_REQUEST['foffset'] ) ? $_REQUEST['foffset'] : 0 );
exit;
}
// support for custom wp-admin slug.
if ( isset( $_REQUEST['open_location'] ) ) {
$open_location = base64_decode( $_REQUEST['open_location'] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
$this->open_location_redirect( $open_location );
if ( isset( $_REQUEST['open_location'] ) && ! empty( $_REQUEST['open_location'] ) ) {
$open_location = base64_decode( $_REQUEST['open_location'] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible.
$this->open_location_redirect( $open_location );
}
$this->where_redirect();
}
@ -421,7 +420,7 @@ class MainWP_Connect {
$_SESSION['file'] = $file;
$_SESSION['size'] = $_POST['size'];
}
wp_safe_redirect( admin_url( $where ) );
wp_redirect( admin_url( $where ) );
exit();
}

View file

@ -64,7 +64,7 @@ class MainWP_Custom_Post_Type {
die( '<mainwp>' . base64_encode( $data ) . '</mainwp>' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatibility.
}
register_shutdown_function( 'MainWP\Child\MainWP_Custom_Post_Type\mainwp_custom_post_type_handle_fatal_error' );
register_shutdown_function( 'MainWP\Child\mainwp_custom_post_type_handle_fatal_error' );
/** @var $information @deprecated Unused local variable 'information'. The value of the variable is overwritten immediately. */
$information = array();

File diff suppressed because it is too large Load diff

View file

@ -5,14 +5,14 @@
* @package MainWP/Child
*/
if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyuse_nonce_hmac'] ) ) {
$skeleton_keyuse_nonce_key = intval( $_GET['skeleton_keyuse_nonce_key'] );
$skeleton_keyuse_nonce_hmac = $_GET['skeleton_keyuse_nonce_hmac'];
$skeleton_keycurrent_time = intval( time() );
if ( isset( $_GET['bulk_settings_manageruse_nonce_key'] ) && isset( $_GET['bulk_settings_manageruse_nonce_hmac'] ) ) {
$bulk_settings_manageruse_nonce_key = intval( $_GET['bulk_settings_manageruse_nonce_key'] );
$bulk_settings_manageruse_nonce_hmac = $_GET['bulk_settings_manageruse_nonce_hmac'];
$bulk_settings_managercurrent_time = intval( time() );
if ( $skeleton_keycurrent_time >= $skeleton_keyuse_nonce_key && $skeleton_keycurrent_time <= ( $skeleton_keyuse_nonce_key + 30 ) ) {
if ( $bulk_settings_managercurrent_time >= $bulk_settings_manageruse_nonce_key && $bulk_settings_managercurrent_time <= ( $bulk_settings_manageruse_nonce_key + 30 ) ) {
if ( strcmp( $skeleton_keyuse_nonce_hmac, hash_hmac( 'sha256', $skeleton_keyuse_nonce_key, NONCE_KEY ) ) === 0 ) {
if ( strcmp( $bulk_settings_manageruse_nonce_hmac, hash_hmac( 'sha256', $bulk_settings_manageruse_nonce_key, NONCE_KEY ) ) === 0 ) {
if ( ! function_exists( 'wp_verify_nonce' ) ) :

View file

View file

@ -1,22 +0,0 @@
/**
* Mouse click tracking
*/
jQuery(document).ready(function($){
$('.kwl-regular-link').click(function(){
var link_id = $(this).attr('link-id');
if (link_id) {
$.ajax({
data : {
link_id: link_id,
ip: kwlIp,
referer: kwlReferer,
action: 'keywordLinksSaveClick',
nonce: kwlNonce
},
type: 'POST',
url: kwlAjaxUrl
});
}
});
});