updated plugin Jetpack Protect version 5.0.0
This commit is contained in:
@ -9,6 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
use Automattic\Jetpack\Account_Protection\Settings as Account_Protection_Settings;
|
||||
use Automattic\Jetpack\Admin_UI\Admin_Menu;
|
||||
use Automattic\Jetpack\Assets;
|
||||
use Automattic\Jetpack\Connection\Initial_State as Connection_Initial_State;
|
||||
@ -37,6 +38,8 @@ use Automattic\Jetpack\Waf\Waf_Stats;
|
||||
|
||||
/**
|
||||
* Class Jetpack_Protect
|
||||
*
|
||||
* @phan-constructor-used-for-side-effects
|
||||
*/
|
||||
class Jetpack_Protect {
|
||||
|
||||
@ -58,6 +61,7 @@ class Jetpack_Protect {
|
||||
);
|
||||
const JETPACK_WAF_MODULE_SLUG = 'waf';
|
||||
const JETPACK_BRUTE_FORCE_PROTECTION_MODULE_SLUG = 'protect';
|
||||
const JETPACK_ACCOUNT_PROTECTION_MODULE_SLUG = 'account-protection';
|
||||
const JETPACK_PROTECT_ACTIVATION_OPTION = JETPACK_PROTECT_SLUG . '_activated';
|
||||
|
||||
/**
|
||||
@ -112,6 +116,9 @@ class Jetpack_Protect {
|
||||
|
||||
// Web application firewall package.
|
||||
$config->ensure( 'waf' );
|
||||
|
||||
// Account protection package.
|
||||
$config->ensure( 'account_protection' );
|
||||
},
|
||||
1
|
||||
);
|
||||
@ -195,7 +202,7 @@ class Jetpack_Protect {
|
||||
* @return string
|
||||
*/
|
||||
public function render_initial_state() {
|
||||
return 'var jetpackProtectInitialState=JSON.parse(decodeURIComponent("' . rawurlencode( wp_json_encode( $this->initial_state() ) ) . '"));';
|
||||
return 'var jetpackProtectInitialState=' . wp_json_encode( $this->initial_state(), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -228,6 +235,7 @@ class Jetpack_Protect {
|
||||
'jetpackScan' => My_Jetpack_Products::get_product( 'scan' ),
|
||||
'hasPlan' => $has_plan,
|
||||
'onboardingProgress' => Onboarding::get_current_user_progress(),
|
||||
'accountProtection' => ( new Account_Protection_Settings() )->get(),
|
||||
'waf' => array(
|
||||
'wafSupported' => Waf_Runner::is_supported_environment(),
|
||||
'currentIp' => IP_Utils::get_ip(),
|
||||
@ -280,6 +288,7 @@ class Jetpack_Protect {
|
||||
*/
|
||||
public static function activate_modules() {
|
||||
delete_option( self::JETPACK_PROTECT_ACTIVATION_OPTION );
|
||||
( new Modules() )->activate( self::JETPACK_ACCOUNT_PROTECTION_MODULE_SLUG, false, false );
|
||||
( new Modules() )->activate( self::JETPACK_WAF_MODULE_SLUG, false, false );
|
||||
( new Modules() )->activate( self::JETPACK_BRUTE_FORCE_PROTECTION_MODULE_SLUG, false, false );
|
||||
}
|
||||
@ -339,7 +348,7 @@ class Jetpack_Protect {
|
||||
* @return array
|
||||
*/
|
||||
public function protect_filter_available_modules( $modules ) {
|
||||
return array_merge( array( self::JETPACK_WAF_MODULE_SLUG, self::JETPACK_BRUTE_FORCE_PROTECTION_MODULE_SLUG ), $modules );
|
||||
return array_merge( array( self::JETPACK_ACCOUNT_PROTECTION_MODULE_SLUG, self::JETPACK_WAF_MODULE_SLUG, self::JETPACK_BRUTE_FORCE_PROTECTION_MODULE_SLUG ), $modules );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
|
||||
namespace Automattic\Jetpack\Protect;
|
||||
|
||||
use Automattic\Jetpack\Account_Protection\Account_Protection;
|
||||
use Automattic\Jetpack\Account_Protection\Settings as Account_Protection_Settings;
|
||||
use Automattic\Jetpack\Connection\Rest_Authentication as Connection_Rest_Authentication;
|
||||
use Automattic\Jetpack\IP\Utils as IP_Utils;
|
||||
use Automattic\Jetpack\Protect_Status\REST_Controller as Protect_Status_REST_Controller;
|
||||
@ -117,6 +119,30 @@ class REST_Controller {
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'jetpack-protect/v1',
|
||||
'toggle-account-protection',
|
||||
array(
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => __CLASS__ . '::api_toggle_account_protection',
|
||||
'permission_callback' => function () {
|
||||
return current_user_can( 'manage_options' );
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'jetpack-protect/v1',
|
||||
'account-protection',
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => __CLASS__ . '::api_get_account_protection',
|
||||
'permission_callback' => function () {
|
||||
return current_user_can( 'manage_options' );
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'jetpack-protect/v1',
|
||||
'toggle-waf',
|
||||
@ -316,6 +342,47 @@ class REST_Controller {
|
||||
return new WP_REST_Response( 'Scan enqueued.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the Account Protection module on or off for the API endpoint
|
||||
*
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public static function api_toggle_account_protection() {
|
||||
$account_protection = Account_Protection::instance();
|
||||
if ( $account_protection->is_enabled() ) {
|
||||
$disabled = $account_protection->disable();
|
||||
if ( ! $disabled ) {
|
||||
return new WP_Error(
|
||||
'account_protection_disable_failed',
|
||||
__( 'An error occurred disabling account protection.', 'jetpack-protect' ),
|
||||
array( 'status' => 500 )
|
||||
);
|
||||
}
|
||||
|
||||
return rest_ensure_response( true );
|
||||
}
|
||||
|
||||
$enabled = $account_protection->enable();
|
||||
if ( ! $enabled ) {
|
||||
return new WP_Error(
|
||||
'account_protection_enable_failed',
|
||||
__( 'An error occurred enabling account protection.', 'jetpack-protect' ),
|
||||
array( 'status' => 500 )
|
||||
);
|
||||
}
|
||||
|
||||
return rest_ensure_response( true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Account Protection data for the API endpoint
|
||||
*
|
||||
* @return WP_Rest_Response
|
||||
*/
|
||||
public static function api_get_account_protection() {
|
||||
return new WP_REST_Response( ( new Account_Protection_Settings() )->get() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the WAF module on or off for the API endpoint
|
||||
*
|
||||
|
||||
@ -53,7 +53,7 @@ class Threats {
|
||||
"$api_base/$threat_id",
|
||||
'2',
|
||||
array( 'method' => 'POST' ),
|
||||
wp_json_encode( $updates ),
|
||||
wp_json_encode( $updates, JSON_UNESCAPED_SLASHES ),
|
||||
'wpcom'
|
||||
);
|
||||
|
||||
@ -112,7 +112,8 @@ class Threats {
|
||||
wp_json_encode(
|
||||
array(
|
||||
'threat_ids' => $threat_ids,
|
||||
)
|
||||
),
|
||||
JSON_UNESCAPED_SLASHES
|
||||
),
|
||||
'wpcom'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user