Fixed: backwpup save settings error

Fixed: jetpack get status error
Updated: connection settings
Added: cli command for setting
This commit is contained in:
thanghv 2024-11-20 00:38:32 +07:00
parent 34f0be0766
commit 288b919df4
19 changed files with 836 additions and 279 deletions

View file

@ -1111,6 +1111,16 @@ class MainWP_Child_Back_WP_Up { //phpcs:ignore -- NOSONAR - multi methods.
return $result;
}
/**
* MainWP BackWPup WP Die ajax handler.
*
* @param string $message Error message container.
* @return string Error message.
*/
public static function mainwp_backwpup_wp_die_ajax_handler() {
return '__return_true';
}
/**
* BackWPup Ajax Working.
*
@ -1131,16 +1141,6 @@ class MainWP_Child_Back_WP_Up { //phpcs:ignore -- NOSONAR - multi methods.
$this->wp_list_table_dependency();
/**
* MainWP BackWPup WP Die ajax handler.
*
* @param string $message Error message container.
* @return string Error message.
*/
function mainwp_backwpup_wp_die_ajax_handler() {
return 'mainwp_backwpup_wp_die_ajax_handler';
}
// We do this in order to not die when using wp_die.
if ( ! defined( 'DOING_AJAX' ) ) {
@ -1153,7 +1153,7 @@ class MainWP_Child_Back_WP_Up { //phpcs:ignore -- NOSONAR - multi methods.
define( 'DOING_AJAX', true );
}
add_filter( 'wp_die_ajax_handler', 'mainwp_backwpup_wp_die_ajax_handler' );
add_filter( 'wp_die_ajax_handler', array( __CLASS__ , 'mainwp_backwpup_wp_die_ajax_handler' ) );
remove_filter( 'wp_die_ajax_handler', '_ajax_wp_die_handler' );
ob_start();
@ -1792,6 +1792,7 @@ class MainWP_Child_Back_WP_Up { //phpcs:ignore -- NOSONAR - multi methods.
}
}
// this assign not work with filter_input - INPUT_POST.
foreach ( $settings['value'] as $key => $val ) {
$_POST[ $key ] = $val;
}

View file

@ -1059,7 +1059,8 @@ class MainWP_Child_Callable { //phpcs:ignore -- NOSONAR - multi methods.
*/
global $mainWPChild;
$mainWPChild->deactivation( false );
$mainWPChild->delete_connection_data();
MainWP_Helper::write( array( 'result' => 'success' ) );
}
@ -1087,6 +1088,15 @@ class MainWP_Child_Callable { //phpcs:ignore -- NOSONAR - multi methods.
if ( is_plugin_active( $mainWPChild->plugin_slug ) ) {
MainWP_Helper::instance()->error( 'Plugin still active' );
}
/**
* MainWP Child instance.
*
* @global object
*/
global $mainWPChild;
$mainWPChild->delete_connection_data();
$information['deactivated'] = true;
MainWP_Helper::write( $information );
}

View file

@ -117,15 +117,19 @@ class MainWP_Child_IThemes_Security { //phpcs:ignore -- NOSONAR - multi methods.
$response = rest_do_request( $request );
$scans = rest_get_server()->response_to_data( $response, true );
if ( is_array( $scans ) && count( $scans ) > 0 ) {
$scan = current( $scans );
$information['syncIThemeData']['scan_info'] = array(
'time' => $scan['time'],
'description' => $scan['description'],
'status' => $scan['status'],
);
if( is_array($scan ) && isset( $scan['time'] ) ){ // to fix error: "you cannot view site scans".
$information['syncIThemeData']['scan_info'] = array(
'time' => $scan['time'],
'description' => $scan['description'],
'status' => $scan['status'],
);
}
}
if ( class_exists( '\iThemesSecurity\Ban_Users\Database_Repository' ) ) {
try{
$repository = \ITSEC_Modules::get_container()->get( \iThemesSecurity\Ban_Users\Database_Repository::class );

View file

@ -258,11 +258,25 @@ class MainWP_Child_Jetpack_Protect {
* @return array $return scan result.
*/
public function get_scan_status() {
MainWP_Helper::instance()->check_classes_exists( '\Automattic\Jetpack\Protect\Status' );
MainWP_Helper::instance()->check_methods( '\Automattic\Jetpack\Protect\Status', 'get_status' );
return array(
'status' => \Automattic\Jetpack\Protect\Status::get_status(),
);
$version_error = false;
try {
MainWP_Helper::instance()->check_classes_exists( '\Automattic\Jetpack\Protect\Status' );
MainWP_Helper::instance()->check_methods( '\Automattic\Jetpack\Protect\Status', 'get_status' );
return array(
'status' => \Automattic\Jetpack\Protect\Status::get_status(),
);
} catch ( MainWP_Exception $e ) {
$version_error = true;
}
if ( $version_error ) {
MainWP_Helper::instance()->check_classes_exists( '\Automattic\Jetpack\Protect_Status\Status' );
MainWP_Helper::instance()->check_methods( '\Automattic\Jetpack\Protect_Status\Status', 'get_status' );
return array(
'status' => \Automattic\Jetpack\Protect_Status\Status::get_status(),
);
}
return array();
}
/**

View file

@ -1278,28 +1278,24 @@ class MainWP_Child_Server_Information extends MainWP_Child_Server_Information_Ba
);
// phpcs:disable WordPress.Security.EscapeOutput
?>
<div class="postbox" id="connection_detail">
<h3 class="mainwp_box_title"><span><?php esc_html_e( 'Connection details', 'mainwp-child' ); ?></span></h3>
<div class="inside">
<div class="mainwp-postbox-actions-top mainwp-padding-5">
<?php printf( esc_html__( 'If you are trying to connect this child site to your %s Dashboard, you can use following details to do that. Please note that these are only suggested values.', 'mainwp-child' ), esc_html( stripslashes( $branding_title ) ) ); ?>
</div>
<table id="mainwp-table" class="wp-list-table widefat" style="border: 0;border-spacing:0;">
<tbody>
<?php
foreach ( $details as $row ) {
?>
<tr>
<th style="width: 20%"><strong><?php echo esc_html( $row['title'] ); ?></strong></th>
<td style="width: 20%"><strong><?php echo esc_html( $row['value'] ); ?></strong></td>
<td><?php echo esc_html( $row['desc'] ); ?></td>
</tr>
<?php
}
<div class="connection-detail-info" id="connection_detail">
<h3><?php esc_html_e( 'Connection details', 'mainwp-child' ); ?></h3>
<p><?php printf( esc_html__( 'If you are trying to connect this child site to your %s Dashboard, you can use following details to do that. Please note that these are only suggested values.', 'mainwp-child' ), esc_html( stripslashes( $branding_title ) ) ); ?></p>
<table class="wp-list-table widefat" style="border: 0;border-spacing:0;">
<tbody>
<?php
foreach ( $details as $row ) {
?>
</tbody>
</table>
</div>
<tr>
<th style="width: 20%"><strong><?php echo esc_html( $row['title'] ); ?></strong></th>
<td style="width: 20%"><strong><?php echo esc_html( $row['value'] ); ?></strong></td>
<td><?php echo esc_html( $row['desc'] ); ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<?php
// phpcs:enable

View file

@ -320,6 +320,12 @@ class MainWP_Child_Stats { //phpcs:ignore -- NOSONAR - multi methods.
}
}
// still generate if regverify the connect user disabled pw auth.
if ( ! empty( $_POST['sync_regverify'] ) ) {
$information['regverify_info'] = MainWP_Connect::instance()->validate_register( false, 'generate' );
}
if ( $exit_done ) {
MainWP_Helper::write( $information );
}

View file

@ -0,0 +1,86 @@
<?php
/**
* MainWP-Child-CLI
*
* This file extends the WP-CLI and provides a set of SubCommands to Control your
* Child Sites that are added to the MainWP Child.
*
* @package MainWP/Child
*/
namespace MainWP\Child;
// Exit if access directly.
if ( ! defined( 'WP_CLI' ) ) {
return; // Nconstant_name: OSONAR - jump to avoid CLI.
}
/**
* Class MainWP_Child_WP_CLI_Command
*
* @package MainWP\Child
*/
class MainWP_Child_WP_CLI_Command extends \WP_CLI_Command { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
/**
* Method init()
*
* Initiate the MainWP CLI after all Plugins have loaded.
*/
public static function init() {
add_action( 'plugins_loaded', array( static::class, 'init_wpcli_commands' ), 99999 );
}
/**
* Method init_wpcli_commands
*
* Adds the MainWP WP CLI Commands via WP_CLI::add_command
*/
public static function init_wpcli_commands() {
\WP_CLI::add_command( 'mainwp-child', static::class );
}
/**
* Settings.
*
* ## OPTIONS
*
* [--disable-pwd-auth]
* : Disable connect passwd authentication
*
*
* ## EXAMPLES
*
* wp mainwp-child settings --disable-pwd-auth [<username>] [<disabled>].
*
* ## Synopsis [--disable-pwd-auth] [<username>] [<disabled>].
*
* @param array $args Function arguments.
* @param array $assoc_args Function associate arguments.
*/
public function settings( $args, $assoc_args ) {
if ( isset( $assoc_args['disable-pwd-auth'] ) ) {
if ( empty( $args ) || empty( $args[0] ) ) {
\WP_CLI::error( 'Please enter the username to apply this setting. A valid username is required to proceed.' );
return true;
} else {
$user_name = $args[0];
$user = get_user_by( 'login', $user_name );
if ( ! $user || empty( $user->ID ) ) {
\WP_CLI::error( 'The username you entered does not match any account. Please verify the username and try again.' );
return true;
}
$disabled = ! isset( $args[1] ) || '1' === $args[1] ? true : false;
update_user_option( $user->ID, 'mainwp_child_user_enable_passwd_auth_connect', $disabled ? 0 : 1 );
\WP_CLI::success( 'Your changes have been saved successfully!' );
return true;
}
}
\WP_CLI::error( 'Invalid arguments. Please try again, or contact support if the issue persists.' );
}
}

View file

@ -30,7 +30,7 @@ class MainWP_Child {
*
* @var string MainWP Child plugin version.
*/
public static $version = '5.2'; // NOSONAR - not IP.
public static $version = '5.3-RC1'; // NOSONAR - not IP.
/**
* Private variable containing the latest MainWP Child update version.
@ -72,6 +72,7 @@ class MainWP_Child {
$this->plugin_slug = plugin_basename( $plugin_file );
add_action( 'template_redirect', array( $this, 'template_redirect' ) );
add_action( 'activated_plugin', array( $this, 'hook_activated_plugin' ) );
add_action( 'init', array( &$this, 'init_check_login' ), 1 );
add_action( 'init', array( &$this, 'parse_init' ), 9999 );
add_action( 'init', array( &$this, 'localization' ), 33 );
@ -104,6 +105,10 @@ class MainWP_Child {
MainWP_Child_Themes_Check::instance();
MainWP_Utility::instance()->run_saved_snippets();
if ( defined( 'WP_CLI' ) && WP_CLI ) {
MainWP_Child_WP_CLI_Command::init();
}
/**
* Initiate Branding Options.
*/
@ -255,6 +260,22 @@ class MainWP_Child {
MainWP_Utility::instance()->send_maintenance_alert();
}
/**
* Method hook_activated_plugin()
*
* @param mixed $plugin
* @return void
*/
public function hook_activated_plugin( $plugin ) {
if ( $plugin === plugin_basename( MAINWP_CHILD_FILE ) && ( ! defined( 'DOING_CRON' ) || ! DOING_CRON ) ) {
$branding = MainWP_Child_Branding::instance()->is_branding();
if ( ! $branding ) {
wp_safe_redirect( 'options-general.php?page=mainwp_child_tab' );
exit();
}
}
}
/**
* Method parse_init()
*
@ -352,6 +373,20 @@ class MainWP_Child {
MainWP_Clone::instance()->init_ajax();
}
MainWP_Child_Actions::get_instance()->init_hooks();
if ( empty( get_option( 'mainwp_child_pubkey' ) ) ) {
$ttl_pubkey = (int) get_option( 'mainwp_child_ttl_active_unconnected_site', 20 );
if ( ! empty( $ttl_pubkey ) ) {
$lasttime_active = get_option( 'mainwp_child_lasttime_not_connected' );
if ( empty( $lasttime_active ) ) {
MainWP_Helper::update_option( 'mainwp_child_lasttime_not_connected', time() );
} elseif ( $lasttime_active < time() - $ttl_pubkey * MINUTE_IN_SECONDS ) {
include_once ABSPATH . '/wp-admin/includes/plugin.php'; // NOSONAR -- WP compatible.
delete_option( 'mainwp_child_lasttime_not_connected' );
deactivate_plugins( $this->plugin_slug, true );
}
}
}
}
/**
@ -395,20 +430,55 @@ class MainWP_Child {
MainWP_Custom_Post_Type::instance();
}
/**
* Method activation()
*
* Activate the MainWP Child plugin and delete unwanted data.
*
* @uses \MainWP\Child\MainWP_Helper::update_option()
*/
public function activation() {
delete_option( 'mainwp_child_lasttime_not_connected' ); // delete if existed.
}
/**
* Method deactivation()
*
* Deactivate the MainWP Child plugin and delete unwanted data.
* Deactivate the MainWP Child plugin.
*
* @param bool $deact Whether or not to deactivate pugin. Default: true.
*/
public function deactivation( $deact = true ) {
delete_option( 'mainwp_child_lasttime_not_connected' ); // delete if existed.
$mu_plugin_enabled = apply_filters( 'mainwp_child_mu_plugin_enabled', false );
if ( $mu_plugin_enabled ) {
return;
}
if ( $deact ) {
do_action( 'mainwp_child_deactivation' );
}
}
/**
* Method delete_connection_data()
*
* Delete connection data.
*
* @param bool $check_must_use Check must use before delete data.
*/
public function delete_connection_data( $check_must_use = true ) {
if ( $check_must_use ) {
$mu_plugin_enabled = apply_filters( 'mainwp_child_mu_plugin_enabled', false );
if ( $mu_plugin_enabled ) {
return;
}
}
$to_delete = array(
'mainwp_child_pubkey',
'mainwp_child_nonce',
@ -426,43 +496,6 @@ class MainWP_Child {
wp_cache_delete( $delete, 'options' );
}
}
if ( $deact ) {
do_action( 'mainwp_child_deactivation' );
}
}
/**
* Method activation()
*
* Activate the MainWP Child plugin and delete unwanted data.
*
* @uses \MainWP\Child\MainWP_Helper::update_option()
*/
public function activation() {
$mu_plugin_enabled = apply_filters( 'mainwp_child_mu_plugin_enabled', false );
if ( $mu_plugin_enabled ) {
return;
}
$to_delete = array(
'mainwp_child_pubkey',
'mainwp_child_nonce',
'mainwp_child_connected_admin',
'mainwp_child_openssl_sign_algo',
);
foreach ( $to_delete as $delete ) {
if ( get_option( $delete ) ) {
delete_option( $delete );
}
}
MainWP_Helper::update_option( 'mainwp_child_activated_once', true );
$to_delete = array( 'mainwp_ext_snippets_enabled', 'mainwp_ext_code_snippets' );
foreach ( $to_delete as $delete ) {
delete_option( $delete );
}
}
/**

View file

@ -23,6 +23,8 @@ class MainWP_Connect { //phpcs:ignore -- NOSONAR - multi methods.
*/
public static $instance = null;
private $connect_user = null;
/**
* Private variable to hold the max history value.
*
@ -110,6 +112,14 @@ class MainWP_Connect { //phpcs:ignore -- NOSONAR - multi methods.
MainWP_Helper::instance()->error( esc_html__( 'cURL Extension not enabled on the child site server. Please contact your host support and have them enabled it for you.', 'mainwp-child' ) );
}
if ( ! empty( $_POST['user'] ) && ! $this->is_verified_register( wp_unslash( $_POST['user'] ) ) ) {
if ( isset( $_POST['regverify'] ) ) {
MainWP_Helper::instance()->error( esc_html__( 'Failed to reconnect to the site. Please remove the site and add it again.', 'mainwp-child' ), 'reconnect_failed' );
} else {
MainWP_Helper::instance()->error( esc_html__( 'Unable to connect to the site. Please verify that your Admin Username and Password are correct and try again.', 'mainwp-child' ) );
}
}
// Check if the user exists and if yes, check if it's Administartor user.
if ( empty( $_POST['user'] ) || ! $this->login( wp_unslash( $_POST['user'] ) ) ) {
MainWP_Helper::instance()->error( esc_html__( 'Unexisting administrator user. Please verify that it is an existing administrator.', 'mainwp-child' ) );
@ -129,14 +139,239 @@ class MainWP_Connect { //phpcs:ignore -- NOSONAR - multi methods.
MainWP_Helper::update_option( 'mainwp_child_connected_admin', $current_user->user_login, 'yes' );
// register success.
$new_verify = $this->may_be_generate_register_verify();
if ( ! empty( $new_verify ) ) {
$information['regverify'] = $new_verify; // get reg verify value.
}
$information['register'] = 'OK';
$information['uniqueId'] = MainWP_Helper::get_site_unique_id();
$information['user'] = isset( $_POST['user'] ) ? sanitize_text_field( wp_unslash( $_POST['user'] ) ) : '';
// phpcs:enable
// phpcs:enable WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
MainWP_Child_Stats::get_instance()->get_site_stats( $information ); // get stats and exit.
}
/**
* Method validate_register().
*
* @param string $key_value Key & value.
* @param string $act Action.
* @param string $user_name.
*
* @return mixed
*/
public function validate_register( $key_value, $act = 'verify', $user_name = false ) { // phpcs:ignore -- NOSONAR - Current complexity is the only way to achieve desired results, pull request solutions appreciated.
$user_id = 0;
if ( ! empty( $user_name ) ) {
$user = get_user_by( 'login', $user_name );
$user_id = $user ? $user->ID : false;
} else {
$user = $this->get_connected_user();
$user_id = $user ? $user->ID : false;
}
if ( empty( $user_id ) ) {
return false;
}
$_values = get_user_option( 'mainwp_child_user_verified_registers', $user_id );
$saved_values = ! empty( $_values ) ? json_decode( $_values, true ) : array();
if ( ! is_array( $saved_values ) ) {
$saved_values = array();
}
$verify_key = '';
$verify_secrect = '';
if ( ! empty( $key_value ) && false !== strpos( $key_value, '-' ) ) {
list( $verify_key, $verify_secrect ) = explode( '-', $key_value );
}
$gen_verify = '';
if ( 'verify' === $act ) {
$found_secure = '';
$hash_key = hash_hmac( 'sha256', $verify_key, 'register-verify' );
foreach ( $saved_values as $info ) {
if ( is_array( $info ) && ! empty( $info['hash_key'] ) && $hash_key === $info['hash_key'] ) {
$found_secure = $info['secure'];
break;
}
}
return ! empty( $found_secure ) && hash_equals( $found_secure, $verify_secrect );
} elseif ( 'generate' === $act ) {
$gen_values = $this->generate_verify_hash();
$saved_values[] = array(
'hash_key' => $gen_values['hash_key'],
'secure' => $gen_values['secure'],
'date' => gmdate( 'Y-m-d H:i:s' ),
);
$gen_verify = $gen_values['key'] . '-' . $gen_values['secure'];
} elseif ( 'remove' === $act ) {
if ( ! empty( $saved_values ) ) {
array_pop( $saved_values );
}
} else {
return false;
}
if ( 5 < count( $saved_values ) ) {
array_shift( $saved_values );
}
update_user_option( $user_id, 'mainwp_child_user_verified_registers', wp_json_encode( $saved_values ) );
if ( ! empty( $gen_verify ) ) {
return $gen_verify;
}
}
/**
* Method is_verified_register().
*
* @param string $user_name User name.
*
* @return bool
*/
public function is_verified_register( $user_name ) { // phpcs:ignore -- NOSONAR - Current complexity is the only way to achieve desired results, pull request solutions appreciated.
if ( ! $this->is_enabled_user_passwd_auth( $user_name ) ) {
return true; // not enable passwd auth, then return true.
}
$user_pwd = isset( $_POST['userpwd'] ) ? trim( rawurldecode( $_POST['userpwd'] ) ) : ''; //phpcs:ignore -- NOSONAR - ok.
$reg_verify = isset( $_POST['regverify'] ) ? sanitize_text_field(wp_unslash( $_POST['regverify'] )) : ''; //phpcs:ignore -- NOSONAR - ok.
$is_valid_pwd = -1;
if ( ! empty( $user_pwd ) ) {
$is_valid_pwd = $this->is_valid_user_pwd( $user_name, $user_pwd );
return $is_valid_pwd ? true : false;
}
$is_dash_version_older_than_ver53 = empty( $_POST['mainwpver'] ) || version_compare( $_POST['mainwpver'], '5.3', '<' ) ? true : false;
if ( empty( $reg_verify ) && $this->is_never_verify_register( $user_name ) && $is_dash_version_older_than_ver53 ) {
// set it is valid one time.
return true;
}
$is_valid_regis = $this->validate_register( $reg_verify, 'verify', $user_name );
return $is_valid_regis ? true : false;
}
/**
* Method is_enabled_user_passwd_auth().
*
* @param string $user_name User name.
*
* @return bool
*/
public function is_enabled_user_passwd_auth( $user_name ) {
$user = get_user_by( 'login', $user_name );
if ( ! $user ) {
return true;
}
$enable_pwd_auth_connect = get_user_option( 'mainwp_child_user_enable_passwd_auth_connect', $user->ID );
if ( false === $enable_pwd_auth_connect || '1' === $enable_pwd_auth_connect ) {
return true;
}
return false;
}
/**
* Method may_be_generate_register_verify().
*
* @return string
*/
private function may_be_generate_register_verify() { // phpcs:ignore -- NOSONAR - Current complexity is the only way to achieve desired results, pull request solutions appreciated.
$is_dash_version_older_than_ver53 = empty( $_POST['mainwpver'] ) || version_compare( $_POST['mainwpver'], '5.3', '<' ) ? true : false;
if ( $is_dash_version_older_than_ver53 ) {
return false; // not genereate verify registers for dashboard version before 5.2.
}
$reg_verify = isset( $_POST['regverify'] ) ? sanitize_text_field(wp_unslash( $_POST['regverify'] )) : ''; //phpcs:ignore -- NOSONAR - ok.
if ( empty( $reg_verify ) ) {
return $this->validate_register( false, 'generate' );
}
$is_valid_regis = $this->validate_register( $reg_verify );
if ( $is_valid_regis ) { // do not need to generate.
return false;
}
// generate a new one, in case connection was validated.
return $this->validate_register( $reg_verify, 'generate' );
}
/**
* Method is_valid_user_pwd()
*
* Parse inistial authentication.
*
* @param string $username Admin login name.
* @param string $pwd Admin password.
*
* @return bool ture|false.
*/
public function is_valid_user_pwd( $username, $pwd ) { // phpcs:ignore -- NOSONAR - Current complexity is the only way to achieve desired results, pull request solutions appreciated.
$user = get_user_by( 'login', $username );
if ( $user && ! empty( $user->user_pass ) ) {
return wp_check_password( $pwd, $user->user_pass, $user->ID );
}
return false;
}
/**
* Method generate_verify_hash()
*
* Generates a random hash to be used when generating the key and secret.
*
* @return array Returns.
*/
private function generate_verify_hash() {
$key = MainWP_Helper::rand_str_key();
return array(
'key' => $key,
'secure' => MainWP_Helper::rand_str_key(),
'hash_key' => hash_hmac( 'sha256', $key, 'register-verify' ),
);
}
/**
* Method is_never_verify_register()
*
* @param string $username Admin login name.
*
* @return bool ture|false.
*/
public function is_never_verify_register( $user_name ) { // phpcs:ignore -- NOSONAR - Current complexity is the only way to achieve desired results, pull request solutions appreciated.
$user = get_user_by( 'login', $user_name );
if ( $user && ! empty( $user->ID ) ) {
$_values = get_user_option( 'mainwp_child_user_verified_registers', $user->ID );
$saved_values = ! empty( $_values ) ? json_decode( $_values, true ) : array();
if ( ! is_array( $saved_values ) ) {
$saved_values = array();
}
return empty( $saved_values ) ? true : false;
}
return false;
}
/**
* Method parse_init_auth()
*
@ -827,12 +1062,22 @@ class MainWP_Connect { //phpcs:ignore -- NOSONAR - multi methods.
$this->check_compatible_connect_info();
}
$this->connect_user = $user;
return $logged_in;
}
return false;
}
/**
* Method get_connected_user()
*/
public function get_connected_user() {
return $this->connect_user;
}
/**
* Method check_other_auth()
*
@ -906,12 +1151,12 @@ class MainWP_Connect { //phpcs:ignore -- NOSONAR - multi methods.
*/
public function check_compatible_connect_info() {
global $current_user;
$connect_user = isset( $_POST['user'] ) ? wp_unslash( $_POST['user'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput,InputNotSanitized,WordPress.Security.NonceVerification
if ( ! empty( $connect_user ) && $current_user->user_login === $connect_user ) {
$con_username = isset( $_POST['user'] ) ? wp_unslash( $_POST['user'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput,InputNotSanitized,WordPress.Security.NonceVerification
if ( ! empty( $con_username ) && $current_user->user_login === $con_username ) {
$connected_admin = get_option( 'mainwp_child_connected_admin', '' );
if ( empty( $connected_admin ) ) {
// to comparable.
MainWP_Helper::update_option( 'mainwp_child_connected_admin', $connect_user, 'yes' );
MainWP_Helper::update_option( 'mainwp_child_connected_admin', $con_username, 'yes' );
}
}
}

View file

@ -537,6 +537,22 @@ class MainWP_Helper { //phpcs:ignore -- NOSONAR - multi methods.
return \wp_generate_password( $length, false );
}
/**
* Method rand_str_key()
*
* Generates a random string to be used when generating the consumer key and secret.
*
* @return string Returns.
*/
public static function rand_str_key() {
if ( ! function_exists( 'openssl_random_pseudo_bytes' ) ) {
return sha1( wp_rand() ); // NOSONAR - safe for keys.
}
return bin2hex( openssl_random_pseudo_bytes( 20 ) ); // @codingStandardsIgnoreLine
}
/**
* Method return_bytes()
*

View file

@ -82,8 +82,8 @@ class MainWP_Pages {
* Initiate actions and filters.
*/
public function init() {
add_action( 'admin_init', array( &$this, 'admin_init' ) );
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
add_action( 'admin_head', array( &$this, 'admin_head' ) );
add_action( 'admin_notices', array( &$this, 'admin_notice' ) );
add_filter( 'plugin_row_meta', array( &$this, 'plugin_row_meta' ), 10, 2 );
}
@ -104,19 +104,72 @@ class MainWP_Pages {
$child_name = ( '' === $branding_opts['branding_preserve_title'] ) ? 'MainWP Child' : $branding_opts['branding_preserve_title'];
$dashboard_name = ( '' === $branding_opts['branding_preserve_title'] ) ? 'MainWP Dashboard' : $branding_opts['branding_preserve_title'] . ' Dashboard';
$msg = '<div style="margin:50px 20px 20px 0;background:#fff;border:1px solid #c3c4c7;border-top-color:#d63638;border-top-width:5px;padding:20px;">';
$msg .= '<h3 style="margin-top:0;color:#d63638;font-weight:900;">' . esc_html__( 'Attention! ', 'mainwp-child' ) . $child_name . esc_html__( ' plugin is activated but not connected.', 'mainwp-child' ) . '</h3>';
$msg .= '<p style="font-size:15px">' . esc_html__( 'Please add this site to your ', 'mainwp-child' ) . $dashboard_name . ' ' . esc_html__( 'NOW or deactivate the ', 'mainwp-child' ) . $child_name . esc_html__( ' plugin until you are ready to connect this site to your Dashboard in order to avoid unexpected security issues. ', 'mainwp-child' );
$msg .= sprintf( esc_html__( 'If you are not sure how to do it, please review this %1$shelp document%2$s.', 'mainwp-child' ), '<a href="https://kb.mainwp.com/docs/add-site-to-your-dashboard/" target="_blank">', '</a>' ) . '</p>';
$msg = '<div style="background:#ffffff;padding:20px;margin:20px 20px 20px 2px;border:1px solid #f4f4f4;">';
if ( ! MainWP_Child_Branding::instance()->is_branding() ) {
$msg .= '<p style="font-size:15px">' . esc_html__( 'You can also turn on the unique security ID option in ', 'mainwp-child' ) . $child_name . sprintf( esc_html__( ' %1$ssettings%2$s if you would like extra security and additional time to add this site to your Dashboard. ', 'maiwnip-child' ), '<a href="admin.php?page=mainwp_child_tab">', '</a>' );
$msg .= sprintf( esc_html__( 'Find out more in this %1$shelp document%2$s how to do it.', 'mainwp-child' ), '<a href="https://kb.mainwp.com/docs/set-unique-security-id/" target="_blank">', '</a>' ) . '</p>';
$msg .= '<div style="width:105px;float:left;margin-right:20px">';
$msg .= '<img alt="MainWP Icon" style="max-width:105px" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyNi4zLjEsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHZpZXdCb3g9IjAgMCAxNzAgMTcwIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAxNzAgMTcwOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPg0KCS5zdDB7ZmlsbDojN0ZCMTAwO30NCgkuc3Qxe2ZpbGw6I0ZGRkZGRjt9DQo8L3N0eWxlPg0KPGc+DQoJPGNpcmNsZSBjbGFzcz0ic3QwIiBjeD0iODUiIGN5PSI4NSIgcj0iNzguNjciLz4NCgk8Zz4NCgkJPGNpcmNsZSBjbGFzcz0ic3QxIiBjeD0iODUiIGN5PSIzNy44IiByPSIxNS43MyIvPg0KCQk8cG9seWdvbiBjbGFzcz0ic3QxIiBwb2ludHM9IjExMS43NSwxMzIuMiA4NSwxNDcuOTQgNTguMjUsMTMyLjIgODUsMjIuMDYgCQkiLz4NCgk8L2c+DQo8L2c+DQo8L3N2Zz4NCg==" />';
$msg .= '</div>';
}
$msg .= '<div style="font-size:1.5em;font-weight:bolder;margin-bottom:16px;">' . esc_html( $child_name ) . esc_html__( ' Plugin is Actived', 'mainwp-child' ) . '</div>';
$msg .= '<div style="font-size:1.2em;margin-bottom:8px">' . esc_html__( 'This site is now ready for connection. Please proceed with the connection process from your ', 'mainwp-child' ) . esc_html( $dashboard_name ) . ' ' . esc_html__( 'to start managing the site. ', 'mainwp-child' ) . '</div>';
$msg .= '<div style="font-size:1.2em;margin-bottom:8px">' . sprintf( esc_html__( 'If you need assistance, refer to our %1$sdocumentation%2$s.', 'mainwp-child' ), '<a href="https://kb.mainwp.com/docs/add-site-to-your-dashboard/" target="_blank">', '</a>' ) . '</div>';
if ( ! MainWP_Child_Branding::instance()->is_branding() ) {
$msg .= '<div style="font-size:1.2em;">' . esc_html__( 'For additional security options, visit the ', 'mainwp-child' ) . esc_html( $child_name ) . sprintf( esc_html__( ' %1$splugin settings%2$s. ', 'maiwnip-child' ), '<a href="admin.php?page=mainwp_child_tab">', '</a>' ) . '</div>';
$msg .= '<div style="clear:both"></div>';
}
$msg .= '</div>';
echo wp_kses_post( $msg );
echo $msg; //phpcs:ignore -- NOSONAR - ok
}
if ( isset( $_GET['page'] ) && 'mainwp_child_tab' === $_GET['page'] && isset( $_GET['message'] ) ) {
$message = '';
if ( '1' === wp_unslash( $_GET['message'] ) ) {
$message = __( 'Disconnected the Site from Dashboard.', 'mainwp-child' );
} elseif ( '2' === wp_unslash( $_GET['message'] ) ) {
$message = __( 'Settings have been saved successfully.', 'mainwp-child' );
}
if ( ! empty( $message ) ) {
?>
<div>
<div class="notice notice-success settings-error is-dismissible">
<p><?php echo esc_html( $message ); ?></p><button type="button" class="notice-dismiss">
<span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice.', 'mainwp-child' ); ?></span></button>
</div>
<?php
}
}
}
/**
* Method admin_init().
*/
public function admin_init() { //phpcs:ignore -- NOSONAR - complex method.
if ( isset( $_POST['nonce-disconnect'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce-disconnect'] ) ), 'child-settings-disconnect' ) ) {
global $mainWPChild;
$mainWPChild->delete_connection_data( false );
delete_option( 'mainwp_child_lasttime_not_connected' ); // reset.
wp_safe_redirect( 'options-general.php?page=mainwp_child_tab&message=1' );
}
// phpcs:disable WordPress.Security.NonceVerification
if ( isset( $_POST['submit'] ) && isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'child-settings' ) ) {
if ( isset( $_POST['requireUniqueSecurityId'] ) ) {
MainWP_Helper::update_option( 'mainwp_child_uniqueId', MainWP_Helper::rand_string( 12 ) );
} else {
MainWP_Helper::update_option( 'mainwp_child_uniqueId', '' );
}
MainWP_Helper::update_option( 'mainwp_child_ttl_active_unconnected_site', ! empty( $_POST['mainwp_child_active_time_for_unconnected_site'] ) ? intval( $_POST['mainwp_child_active_time_for_unconnected_site'] ) : 0 );
update_user_option( get_current_user_id(), 'mainwp_child_user_enable_passwd_auth_connect', ! empty( $_POST['mainwp_child_user_enable_pwd_auth_connect'] ) ? 1 : 0 );
wp_safe_redirect( 'options-general.php?page=mainwp_child_tab&message=2' );
}
// phpcs:enable
}
/**
* Add and remove Admin Menu Items dependant upon Branding settings.
*
@ -256,7 +309,7 @@ class MainWP_Pages {
*/
global $mainWPChild;
if ( $mainWPChild->plugin_slug !== $plugin_file ) {
if ( ! $mainWPChild || $mainWPChild->plugin_slug !== $plugin_file ) {
return $plugin_meta;
}
return apply_filters( 'mainwp_child_plugin_row_meta', $plugin_meta, $plugin_file, $mainWPChild->plugin_slug );
@ -385,118 +438,172 @@ class MainWP_Pages {
?>
<style type="text/css">
.mainwp-tabs
{
margin-top: 2em;
border-bottom: 1px solid #e5e5e5;
.settings_page_mainwp_child_tab #wpwrap,
.settings_page_mainwp-reports-settings #wpwrap {
}
#mainwp-tabs {
clear: both ;
}
#mainwp-tabs .nav-tab-active {
background: #fafafa ;
border-top: 1px solid #7fb100 !important;
border-left: 1px solid #e5e5e5;
border-right: 1px solid #e5e5e5;
border-bottom: 1px solid #fafafa !important ;
color: #7fb100;
#mainwp-child-settings-page-content {
margin: 20px 20px 0 0;
background: #FFFFFF;
border: 1px solid #E7EEF6;
}
#mainwp-tabs .nav-tab {
border-top: 1px solid #e5e5e5;
border-left: 1px solid #e5e5e5;
border-right: 1px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
padding: 10px 16px;
font-size: 14px;
text-transform: uppercase;
#mainwp-child-settings-page-content p {
font-size: 15px;
}
#mainwp-child-settings-page-content h4 {
font-size: 1.2em;
}
#mainwp_wrap-inside {
min-height: 80vh;
height: 100% ;
margin-top: 0em ;
padding: 10px ;
background: #fafafa ;
border-top: none ;
border-bottom: 1px solid #e5e5e5;
border-left: 1px solid #e5e5e5;
border-right: 1px solid #e5e5e5;
box-shadow: 0 1px 1px rgba(0,0,0,.04);
position: relative;
#mainwp-child-settings-page-navigation {
background: #2D3B44;
}
#mainwp_wrap-inside h2.hndle {
font-size: 14px;
padding: 8px 12px;
#mainwp-child-settings-page-tabs {
padding: 20px;
}
#mainwp-child-settings-page-navigation .nav-tab {
background: #2D3B44;
color: #FFFFFF;
border: none;
margin: 0;
line-height: 1.4;
padding: 1em;
}
#mainwp-child-settings-page-navigation .nav-tab:hover {
background: #3a4c58;
}
#mainwp-child-settings-page-navigation .nav-tab-active {
background: #4682b4;
}
.mainwp-hidden {
display: none;
}
/* The switch - the box around the slider */
.mainwp-toggle {
position: relative;
display: inline-block;
width: 49px;
height: 21px;
margin-right: 1em;
}
/* Hide default HTML checkbox */
.mainwp-toggle input {
opacity: 0;
width: 0;
height: 0;
}
/* The slider */
.mainwp-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.05);
-webkit-transition: .4s;
transition: .4s;
border-radius: 11px;
}
.mainwp-slider:before {
position: absolute;
content: "";
height: 21px;
width: 21px;
background: #fff linear-gradient(transparent, rgba(0, 0, 0, 0.05));
box-shadow: 0 1px 2px 0 rgba(34, 36, 38, 0.15), 0 0 0 1px rgba(34, 36, 38, 0.15) inset;
-webkit-transition: .4s;
transition: .4s;
border-radius: 11px;
}
.mainwp-toggle input:checked + .mainwp-slider {
background: #7fb100;
}
.mainwp-toggle input:checked + .mainwp-slider:before {
-webkit-transform: translateX(28px);
-ms-transform: translateX(28px);
transform: translateX(28px);
}
.mainwp-button {
background-color: #7fb100;
border: none;
color: #ffffff !important;
border-radius: 15px;
padding: 0.78571429em 1.5em 0.78571429em;
cursor: pointer;
font-weight: bolder;
font-size:1em;
}
.mainwp-basic-button {
background-color: #4682b4;
border: none;
color: #ffffff !important;
border-radius: 15px;
padding: 0.78571429em 1.5em 0.78571429em;
cursor: pointer;
font-weight: bolder;
font-size:1em;
}
.mainwp-basic-button:disabled {
background-color: #4682b4;
opacity: 0.45;
}
.mainwp-number-field {
margin: 0;
outline: none;
-webkit-appearance: none;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
line-height: 1.21428571em !important;
padding: 0.67857143em 1em !important;
font-size: 1em !important;
background: #fff;
border: 1px solid rgba(34, 36, 38, 0.15) !important;
color: rgba(0, 0, 0, 0.87);
border-radius: 0.28571429rem !important;
}
</style>
<div class="wrap">
<h2><i class="fa fa-file"></i> <?php echo esc_html( null === static::$brandingTitle ? 'MainWP Child' : static::$brandingTitle ); ?></h2>
<div style="clear: both;"></div><br/>
<div class="mainwp-tabs" id="mainwp-tabs">
<?php if ( ! $hide_settings ) { ?>
<a class="nav-tab pos-nav-tab
<?php
if ( 'settings' === $shownPage ) {
echo 'nav-tab-active';
}
?>
" tab-slug="settings" href="<?php echo $subpage ? 'options-general.php?page=mainwp_child_tab&tab=settings' : '#'; ?>" style="margin-left: 0 !important;"><?php esc_html_e( 'Settings', 'mainwp-child' ); ?></a>
<?php } ?>
<?php if ( ! $hide_restore && $show_clone_funcs ) { ?>
<a class="nav-tab pos-nav-tab
<?php
if ( 'restore-clone' === $shownPage ) {
echo 'nav-tab-active';
}
?>
" tab-slug="restore-clone" href="<?php echo esc_url( $subpage ? 'options-general.php?page=mainwp_child_tab&tab=restore-clone' : '#' ); ?>"><?php echo esc_html__( 0 !== (int) $sitesToClone ? 'Restore / Clone' : 'Restore', 'mainwp-child' ); ?></a>
<?php } ?>
<?php if ( ! $hide_server_info ) { ?>
<a class="nav-tab pos-nav-tab
<?php
if ( 'server-info' === $shownPage ) {
echo 'nav-tab-active';
}
?>
" tab-slug="server-info" href="<?php echo $subpage ? 'options-general.php?page=mainwp_child_tab&tab=server-info' : '#'; ?>"><?php esc_html_e( 'Server information', 'mainwp-child' ); ?></a>
<?php } ?>
<?php if ( ! $hide_connection_detail ) { ?>
<a class="nav-tab pos-nav-tab
<?php
if ( 'connection-detail' === $shownPage ) {
echo 'nav-tab-active';
}
?>
" tab-slug="connection-detail" href="<?php echo $subpage ? 'options-general.php?page=mainwp_child_tab&tab=connection-detail' : '#'; ?>"><?php esc_html_e( 'Connection Details', 'mainwp-child' ); ?></a>
<?php } ?>
<?php
if ( isset( static::$subPages ) && is_array( static::$subPages ) ) {
foreach ( static::$subPages as $subPage ) {
?>
<a class="nav-tab pos-nav-tab
<?php
if ( $shownPage === $subPage['slug'] ) {
echo 'nav-tab-active';
}
?>
" tab-slug="<?php echo esc_attr( $subPage['slug'] ); ?>" href="options-general.php?page=<?php echo esc_html( rawurlencode( $subPage['page'] ) ); ?>"><?php echo esc_html( $subPage['title'] ); ?></a>
<?php
}
}
?>
<div style="clear:both;"></div>
</div>
<div style="clear:both;"></div>
<div class="" id="mainwp-child-settings-page">
<h1><?php echo esc_html( null === static::$brandingTitle ? 'MainWP Child' : static::$brandingTitle ); ?></h1>
<div class="" id="mainwp-child-settings-page-content">
<div class="" id="mainwp-child-settings-page-navigation">
<?php if ( ! $hide_settings ) : ?>
<a class="nav-tab pos-nav-tab <?php echo ( 'settings' === $shownPage ) ? 'nav-tab-active' : ''; ?>" tab-slug="settings" href="<?php echo $subpage ? 'options-general.php?page=mainwp_child_tab&tab=settings' : '#'; ?>"><?php esc_html_e( 'Settings', 'mainwp-child' ); ?></a>
<?php endif; ?>
<?php if ( ! $hide_restore && $show_clone_funcs ) : ?>
<a class="nav-tab pos-nav-tab <?php echo ( 'restore-clone' === $shownPage ) ? 'nav-tab-active' : ''; ?>" tab-slug="restore-clone" href="<?php echo $subpage ? 'options-general.php?page=mainwp_child_tab&tab=restore-clone' : '#'; ?>"><?php echo esc_html__( 0 !== (int) $sitesToClone ? 'Restore / Clone' : 'Restore', 'mainwp-child' ); ?></a>
<?php endif; ?>
<?php if ( ! $hide_server_info ) : ?>
<a class="nav-tab pos-nav-tab <?php echo ( 'server-info' === $shownPage ) ? 'nav-tab-active' : ''; ?>" tab-slug="server-info" href="<?php echo $subpage ? 'options-general.php?page=mainwp_child_tab&tab=server-info' : '#'; ?>"><?php esc_html_e( 'Server Information', 'mainwp-child' ); ?></a>
<?php endif; ?>
<?php if ( ! $hide_connection_detail ) : ?>
<a class="nav-tab pos-nav-tab <?php echo ( 'connection-detail' === $shownPage ) ? 'nav-tab-active' : ''; ?>" tab-slug="connection-detail" href="<?php echo $subpage ? 'options-general.php?page=mainwp_child_tab&tab=connection-detail' : '#'; ?>"><?php esc_html_e( 'Connection Details', 'mainwp-child' ); ?></a>
<?php endif; ?>
<?php if ( isset( static::$subPages ) && is_array( static::$subPages ) ) : ?>
<?php foreach ( static::$subPages as $subPage ) : ?>
<a class="nav-tab pos-nav-tab <?php echo ( $shownPage === $subPage['slug'] ) ? 'nav-tab-active' : ''; ?>" tab-slug="<?php echo esc_attr( $subPage['slug'] ); ?>" href="options-general.php?page=<?php echo esc_html( rawurlencode( $subPage['page'] ) ); ?>"><?php echo esc_html( $subPage['title'] ); ?></a>
<?php endforeach; ?>
<?php endif; ?>
<div style="clear:both"></div>
</div>
<div style="clear:both"></div>
<div class="" id="mainwp-child-settings-page-tabs">
<script type="text/javascript">
jQuery( document ).ready( function () {
$hideMenu = jQuery( '#menu-settings li a .mainwp-hidden' );
@ -504,13 +611,13 @@ class MainWP_Pages {
jQuery( this ).closest( 'li' ).hide();
} );
var $tabs = jQuery( '.mainwp-tabs' );
var $tabs = jQuery( '#mainwp-child-settings-page-navigation' );
$tabs.on( 'click', 'a', function () {
if ( jQuery( this ).attr( 'href' ) !=='#' )
return true;
jQuery( '.mainwp-tabs > a' ).removeClass( 'nav-tab-active' );
jQuery( '#mainwp-child-settings-page-navigation > a' ).removeClass( 'nav-tab-active' );
jQuery( this ).addClass( 'nav-tab-active' );
jQuery( '.mainwp-child-setting-tab' ).hide();
var _tab = jQuery( this ).attr( 'tab-slug' );
@ -520,8 +627,6 @@ class MainWP_Pages {
} );
</script>
<div id="mainwp_wrap-inside">
<?php
}
@ -530,89 +635,141 @@ class MainWP_Pages {
*/
public static function render_footer() {
?>
</div>
</div>
</div>
</div>
<?php
}
/**
* Render admin header.
*/
public function admin_head() {
if ( isset( $_GET['page'] ) && 'mainwp_child_tab' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification
?>
<style type="text/css">
.mainwp-postbox-actions-top {
padding: 10px;
clear: both;
border-bottom: 1px solid #ddd;
background: #f5f5f5;
}
h3.mainwp_box_title {
font-family: "Open Sans",sans-serif;
font-size: 14px;
font-weight: 600;
line-height: 1.4;
margin: 0;
padding: 8px 12px;
border-bottom: 1px solid #eee;
}
.mainwp-child-setting-tab.connection-detail .postbox .inside{
margin: 0;
padding: 0;
}
</style>
<?php
}
}
/**
* Render connection settings sub page.
*
* @uses \MainWP\Child\MainWP_Helper::update_option()
*/
public function render_settings() {
// phpcs:disable WordPress.Security.NonceVerification
if ( isset( $_POST['submit'] ) && isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'child-settings' ) ) {
if ( isset( $_POST['requireUniqueSecurityId'] ) ) {
MainWP_Helper::update_option( 'mainwp_child_uniqueId', MainWP_Helper::rand_string( 12 ) );
} else {
MainWP_Helper::update_option( 'mainwp_child_uniqueId', '' );
}
$branding_title = MainWP_Child_Branding::instance()->get_branding_title();
if ( '' === $branding_title ) {
$branding_title = 'MainWP';
} else {
$branding_title = stripslashes( $branding_title );
}
// phpcs:enable
?>
<div class="postbox">
<h2 class="hndle"><span><?php esc_html_e( 'Connection settings', 'mainwp-child' ); ?></span></h2>
<div class="inside">
<form method="post" action="options-general.php?page=mainwp_child_tab">
<div class="howto"><?php esc_html_e( 'The unique security ID adds additional protection between the child plugin and your Dashboard. The unique security ID will need to match when being added to the Dashboard. This is additional security and should not be needed in most situations.', 'mainwp-child' ); ?></div>
<div style="margin: 1em 0 4em 0;">
<input name="requireUniqueSecurityId" type="checkbox" id="requireUniqueSecurityId"
<?php
$uniqueId = MainWP_Helper::get_site_unique_id();
if ( ! empty( $uniqueId ) ) {
echo 'checked';
}
?>
/>
<label for="requireUniqueSecurityId" style="font-size: 15px;"><?php esc_html_e( 'Require unique security ID', 'mainwp-child' ); ?></label>
</div>
<div>
<?php
if ( ! empty( $uniqueId ) ) {
echo '<span style="border: 1px dashed #e5e5e5; background: #fafafa; font-size: 24px; padding: 1em 2em;">' . esc_html__( 'Your unique security ID is:', 'mainwp-child' ) . ' <span style="font-weight: bold; color: #7fb100;">' . esc_html( get_option( 'mainwp_child_uniqueId' ) ) . '</span></span>';
}
?>
</div>
<p class="submit" style="margin-top: 4em;">
<input type="submit" name="submit" id="submit" class="button button-primary button-hero" value="<?php esc_attr_e( 'Save changes', 'mainwp-child' ); ?>">
</p>
<input type="hidden" name="nonce" value="<?php echo esc_attr( wp_create_nonce( 'child-settings' ) ); ?>">
</form>
</div>
</div>
$uniqueId = MainWP_Helper::get_site_unique_id();
$time_limit = get_option( 'mainwp_child_ttl_active_unconnected_site', 20 );
$enable_pwd_auth_connect = get_user_option( 'mainwp_child_user_enable_passwd_auth_connect' );
if ( false === $enable_pwd_auth_connect ) {
$enable_pwd_auth_connect = 1;
update_user_option( get_current_user_id(), 'mainwp_child_user_enable_passwd_auth_connect', 1 );
}
?>
<h2 style="font-size:1.5em"><?php esc_html_e( 'Connection Security Settings', 'mainwp-child' ); ?></h2>
<p><?php esc_html_e( 'Configure the plugin to best suit your security and connection needs.', 'mainwp-child' ); ?></p>
<br/>
<form method="post" action="options-general.php?page=mainwp_child_tab">
<header class="section-header">
<h3><?php esc_html_e( 'Password Authentication - Initial Connection Security', 'mainwp-child' ); ?></h3>
<hr/>
</header>
<p><?php esc_html_e( $branding_title . ' requests that you connect using an admin account and password for the initial setup. Rest assured, your password is never stored by your Dashboard and never sent to ' . $branding_title . '.com. Once this initial connection is complete, your ' . $branding_title . ' Dashboard generates a secure Public and Private key pair (2048 bits) using OpenSSL, allowing future connections without needing your password again. For added security, you can even change this admin password once connected just be sure not to delete the admin account, as this would disrupt the connection.', 'mainwp-child' ); ?></p>
<h4><strong><?php esc_html_e( 'Dedicated ' . $branding_title . ' Admin Account', 'mainwp-child' ); ?></strong></h4>
<p><?php esc_html_e( 'For further security, we recommend creating a dedicated admin account specifically for ' . $branding_title . '. This \'' . $branding_title . ' Admin\' account can be used exclusively by ' . $branding_title . ', allowing you to easily track any actions performed by the plugin. To set this up, go to Users to create the account, then return to your Dashboard to connect it.', 'mainwp-child' ); ?></p>
<h4><strong><?php esc_html_e( 'Disabling Password Security', 'mainwp-child' ); ?></strong></h4>
<p><?php esc_html_e( 'If you prefer not to use password security, you can disable it by unchecking the box below. Make sure this child site is ready to connect before turning off this feature.', 'mainwp-child' ); ?></p>
<p>
<?php
if ( MainWP_Child_Branding::instance()->is_branding() ) {
esc_html_e( 'If you have additional questions, please refer to this Knowledge Base article or contact ' . $branding_title . ' Support.', 'mainwp-child' );
} else {
printf( esc_html__( 'If you have additional questions, please %srefer to this Knowledge Base article%s or %scontact MainWP Support%s.', 'mainwp-child' ), '<a href="https://kb.mainwp.com/docs/mainwp-connection-security/#password-authentication" target="_blank">', '</a>', '<a href="https://mainwp.com/mainwp-support/" target="_blank">', '</a>' );
}
?>
</p>
<table class="form-table">
<tbody>
<tr>
<th scope="row" style="width:300px"><?php esc_html_e( 'Require Password Authentication', 'mainwp-child' ); ?></th>
<td>
<label for="mainwp_child_user_enable_pwd_auth_connect" class="mainwp-toggle">
<input type="checkbox" name="mainwp_child_user_enable_pwd_auth_connect" id="mainwp_child_user_enable_pwd_auth_connect" value="1" <?php echo $enable_pwd_auth_connect ? 'checked' : ''; ?> />
<span class="mainwp-slider"></span>
</label><?php esc_html_e( 'Enable this option to require password authentication on initial site connection.', 'mainwp-child' ); ?>
</td>
<tr>
</tbody>
</table>
<header class="section-header">
<h3><?php esc_html_e( 'Unique Security ID', 'mainwp-child' ); ?></h3>
<hr/>
</header>
<p><?php printf( esc_html__( 'Add an extra layer of security for connecting this site to your %s Dashboard.', 'mainwp-child' ), esc_html( stripslashes( $branding_title ) ) ); ?></p>
<table class="form-table">
<tbody>
<tr>
<th scope="row" style="width:300px"><?php esc_html_e( 'Require Unique Secuirty ID', 'mainwp-child' ); ?></th>
<td>
<label for="requireUniqueSecurityId" class="mainwp-toggle">
<input name="requireUniqueSecurityId" type="checkbox" id="requireUniqueSecurityId" <?php echo ( ! empty( $uniqueId ) ) ? 'checked' : ''; ?> />
<span class="mainwp-slider"></span>
</label><?php esc_html_e( 'Enable this option for an added layer of protection when connecting this site.', 'mainwp-child' ); ?>
</td>
<tr>
</tbody>
</table>
<div>
<?php if ( ! empty( $uniqueId ) ) : ?>
<table class="form-table">
<tbody>
<tr>
<th scope="row" style="width:300px"><?php esc_html_e( 'Your unique security ID is:', 'mainwp-child' ); ?></th>
<td><?php echo '<code>' . esc_html( get_option( 'mainwp_child_uniqueId' ) ) . '</code>'; ?></td>
<tr>
</tbody>
</table>
<?php endif; ?>
</div>
<header class="section-header">
<h3><?php esc_html_e( 'Connection Timeout', 'mainwp-child' ); ?></h3>
<hr/>
</header>
<p><?php esc_html_e( 'Define how long the plugin will remain active if no connection is established. After this period, the plugin will automatically deactivate for security.', 'mainwp-child' ); ?></p>
<table class="form-table">
<tbody>
<tr>
<th scope="row" style="width:300px"><?php esc_html_e( 'Set Connection Timeout', 'mainwp-child' ); ?></th>
<td>
<input type="number" name="mainwp_child_active_time_for_unconnected_site" id="mainwp_child_active_time_for_unconnected_site" class="mainwp-number-field" placeholder="" min="0" max="999" step="1" value="<?php echo intval( $time_limit ); ?>">
<label for="mainwp_child_active_time_for_unconnected_site"><?php esc_html_e( 'Specify how long the plugin should stay active if a connection isn\'t established. Enter a value in minutes.', 'mainwp-child' ); ?></label>
</td>
<tr>
</tbody>
</table>
<div>
</div>
<p class="submit">
<input type="submit" name="submit" id="submit" class="mainwp-button" value="<?php esc_attr_e( 'Save Settings', 'mainwp-child' ); ?>">
</p>
<input type="hidden" name="nonce" value="<?php echo esc_attr( wp_create_nonce( 'child-settings' ) ); ?>">
</form>
<br/>
<header class="section-header">
<h3><?php esc_html_e( 'Site Connection Management', 'mainwp-child' ); ?></h3>
<hr/>
</header>
<form method="post" onsubmit="return confirm('<?php echo esc_js( __( 'Are you sure you want to Disconnect Site from your ' . $branding_title . ' Dashboard?', 'mainwp-child' ) ); ?>');" action="options-general.php?page=mainwp_child_tab">
<p><?php printf( esc_html__( 'Click this button to disconnect this site from your %s Dashboard.', 'mainwp-child' ), esc_html( stripslashes( $branding_title ) ) ); ?></p>
<p class="submit">
<input <?php echo empty( get_option( 'mainwp_child_pubkey' ) ) ? ' disabled="disabled" ' : ''; ?> type="submit" name="submit" id="submit" class="mainwp-basic-button" value="<?php esc_attr_e( 'Clear Connection Data', 'mainwp-child' ); ?>">
</p>
<input type="hidden" name="nonce-disconnect" value="<?php echo esc_attr( wp_create_nonce( 'child-settings-disconnect' ) ); ?>">
</form>
<?php
}
}

View file

@ -71,17 +71,6 @@ class MainWP_WordPress_SEO {
*/
global $wpdb;
$this->import_error = __( 'Settings could not be imported.', 'mainwp-child' );
add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) );
}
/**
* Empty options upon MainWP Child plugin deactivation.
*/
public function child_deactivation() {
$dell_all = array();
foreach ( $dell_all as $opt ) {
delete_option( $opt );
}
}
/**

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

Before After
Before After

BIN
images/mainwp-logo-alt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
images/mainwp-logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -12,7 +12,7 @@
* Author: MainWP
* Author URI: https://mainwp.com
* Text Domain: mainwp-child
* Version: 5.2
* Version: 5.3-RC1
* Requires at least: 5.4
* Requires PHP: 7.4
*/

View file

@ -7,7 +7,7 @@ Plugin URI: https://mainwp.com
Requires at least: 6.2
Tested up to: 6.6.1
Requires PHP: 7.4
Stable tag: 5.2
Stable tag: 5.3-RC1
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html