updated plugin Jetpack Protect
version 1.2.0
This commit is contained in:
@ -27,12 +27,15 @@ use Automattic\Jetpack\Protect\Threats;
|
||||
use Automattic\Jetpack\Status as Jetpack_Status;
|
||||
use Automattic\Jetpack\Sync\Functions as Sync_Functions;
|
||||
use Automattic\Jetpack\Sync\Sender;
|
||||
use Automattic\Jetpack\Waf\Waf_Runner;
|
||||
|
||||
/**
|
||||
* Class Jetpack_Protect
|
||||
*/
|
||||
class Jetpack_Protect {
|
||||
|
||||
const JETPACK_WAF_MODULE_SLUG = 'waf';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
@ -79,9 +82,14 @@ class Jetpack_Protect {
|
||||
|
||||
// Identity crisis package.
|
||||
$config->ensure( 'identity_crisis' );
|
||||
|
||||
// Web application firewall package.
|
||||
$config->ensure( 'waf' );
|
||||
},
|
||||
1
|
||||
);
|
||||
|
||||
add_filter( 'jetpack_get_available_standalone_modules', array( $this, 'protect_filter_available_modules' ), 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -186,8 +194,14 @@ class Jetpack_Protect {
|
||||
'adminUrl' => 'admin.php?page=jetpack-protect',
|
||||
'siteSuffix' => ( new Jetpack_Status() )->get_site_suffix(),
|
||||
'jetpackScan' => My_Jetpack_Products::get_product( 'scan' ),
|
||||
'productData' => My_Jetpack_Products::get_product( 'protect' ),
|
||||
'hasRequiredPlan' => Plan::has_required_plan(),
|
||||
'waf' => array(
|
||||
'isSupported' => Waf_Runner::is_supported_environment(),
|
||||
'isSeen' => self::get_waf_seen_status(),
|
||||
'isEnabled' => Waf_Runner::is_enabled(),
|
||||
'isLoading' => false,
|
||||
'config' => Waf_Runner::get_config(),
|
||||
),
|
||||
);
|
||||
|
||||
$initial_state['jetpackScan']['pricingForUi'] = Plan::get_product( 'jetpack_scan' );
|
||||
@ -249,6 +263,16 @@ class Jetpack_Protect {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds module to the list of available modules
|
||||
*
|
||||
* @param array $modules The available modules.
|
||||
* @return array
|
||||
*/
|
||||
public function protect_filter_available_modules( $modules ) {
|
||||
return array_merge( array( self::JETPACK_WAF_MODULE_SLUG ), $modules );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the REST API routes.
|
||||
*
|
||||
@ -350,6 +374,54 @@ class Jetpack_Protect {
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'jetpack-protect/v1',
|
||||
'toggle-waf',
|
||||
array(
|
||||
'methods' => \WP_REST_SERVER::EDITABLE,
|
||||
'callback' => __CLASS__ . '::api_toggle_waf',
|
||||
'permission_callback' => function () {
|
||||
return current_user_can( 'manage_options' );
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'jetpack-protect/v1',
|
||||
'waf',
|
||||
array(
|
||||
'methods' => \WP_REST_SERVER::READABLE,
|
||||
'callback' => __CLASS__ . '::api_get_waf',
|
||||
'permission_callback' => function () {
|
||||
return current_user_can( 'manage_options' );
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'jetpack-protect/v1',
|
||||
'waf-seen',
|
||||
array(
|
||||
'methods' => \WP_REST_SERVER::READABLE,
|
||||
'callback' => __CLASS__ . '::get_waf_seen_status',
|
||||
'permission_callback' => function () {
|
||||
return current_user_can( 'manage_options' );
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'jetpack-protect/v1',
|
||||
'waf-seen',
|
||||
array(
|
||||
'methods' => \WP_REST_SERVER::EDITABLE,
|
||||
'callback' => __CLASS__ . '::set_waf_seen_status',
|
||||
'permission_callback' => function () {
|
||||
return current_user_can( 'manage_options' );
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -482,4 +554,52 @@ class Jetpack_Protect {
|
||||
|
||||
return new WP_REST_Response( 'Scan enqueued.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the WAF module on or off for the API endpoint
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function api_toggle_waf() {
|
||||
if ( Waf_Runner::is_enabled() ) {
|
||||
Waf_Runner::disable();
|
||||
return rest_ensure_response( true, 200 );
|
||||
}
|
||||
|
||||
Waf_Runner::enable();
|
||||
return rest_ensure_response( true, 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get WAF data for the API endpoint
|
||||
*
|
||||
* @return WP_Rest_Response
|
||||
*/
|
||||
public static function api_get_waf() {
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'is_seen' => self::get_waf_seen_status(),
|
||||
'is_enabled' => Waf_Runner::is_enabled(),
|
||||
'config' => Waf_Runner::get_config(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get WAF "Seen" Status
|
||||
*
|
||||
* @return bool Whether the current user has viewed the WAF screen.
|
||||
*/
|
||||
public static function get_waf_seen_status() {
|
||||
return (bool) get_user_meta( get_current_user_id(), 'jetpack_protect_waf_seen', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set WAF "Seen" Status
|
||||
*
|
||||
* @return bool True if seen status updated to true, false on failure.
|
||||
*/
|
||||
public static function set_waf_seen_status() {
|
||||
return (bool) update_user_meta( get_current_user_id(), 'jetpack_protect_waf_seen', true );
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user