PHP Class Jetpack_Protect_Module, jetpack

Mostra file Open project: automattic/jetpack Class Usage Examples

Public Properties

Property Type Description
$api_key
$api_key_error
$last_request
$last_response
$last_response_raw
$whitelist
$whitelist_error
$whitelist_saved

Public Methods

Method Description
admin_banner_styles ( )
admin_jetpack_manage_notice ( )
block_with_math ( )
check_api_key ( )
check_login_ability ( boolean $preauth = false ) : boolean Checks the status for a given IP. API results are cached as transients
check_preauth ( string $user = 'Not Used By Protect', string $username = 'Not Used By Protect', string $password = 'Not Used By Protect' ) : string Checks for loginability BEFORE authentication so that bots don't get to go around the log in form.
check_use_math ( ) * Checks if the protect API call has failed, and if so initiates the math captcha fallback.
configuration_head ( )
configuration_load ( ) Get or delete API key
configuration_screen ( ) Prints the configuration screen
delete_transient ( string $transient ) : boolean Wrapper for WordPress delete_transient function, our version deletes the transient on the main site in the network if this is a multisite network
get_api_host ( )
get_headers ( ) : string Get all IP headers so that we can process on our server.
get_local_host ( )
get_main_blog_id ( ) : integer If we're in a multisite network, return the blog ID of the primary blog
get_main_blog_jetpack_id ( ) : integer Get jetpack blog id, or the jetpack blog id of the main blog in the main network
get_protect_key ( ) : boolean | string Request an api key from wordpress.com
get_transient ( string $transient ) : mixed Wrapper for WordPress get_transient function, our version gets the transient on the main site in the network if this is a multisite network
instance ( ) : object Singleton implementation
ip_is_whitelisted ( $ip ) * Checks if the IP address has been whitelisted
kill_login ( ) * Kill a login attempt
log_failed_attempt ( ) : void Called via WP action wp_login_failed to log failed attempt with the api
log_successful_login ( $user_login, $user ) Logs a successful login back to our servers, this allows us to make sure we're not blocking a busy IP that has a lot of good logins along with some forgotten passwords. Also saves current user's ip to the ip address whitelist
maybe_display_security_warning ( )
maybe_get_protect_key ( )
maybe_update_headers ( $force = false ) Sends a "check_key" API call once a day. This call allows us to track IP-related headers for this server via the Protect API, in order to better identify the source IP for login attempts
modules_loaded ( ) Set up the Protect configuration page
on_activation ( ) On module activation, try to get an api key
on_deactivation ( ) On module deactivation, unset protect_active
prepare_jetpack_protect_multisite_notice ( )
protect_call ( string $action = 'check_ip', array $request = [] ) : array Calls over to the api using wp_remote_post
set_transient ( string $transient, mixed $value, integer $expiration ) : boolean Wrapper for WordPress set_transient function, our version sets the transient on the main site in the network if this is a multisite network

Private Methods

Method Description
__construct ( ) Registers actions

Method Details

admin_banner_styles() public method

public admin_banner_styles ( )

admin_jetpack_manage_notice() public method

block_with_math() public method

public block_with_math ( )

check_api_key() public method

public check_api_key ( )

check_login_ability() public method

Checks the status for a given IP. API results are cached as transients
public check_login_ability ( boolean $preauth = false ) : boolean
$preauth boolean Whether or not we are checking prior to authorization
return boolean Either returns true, fires $this->kill_login, or includes a math fallback and returns false

check_preauth() public method

If we are using our math fallback, authenticate via math-fallback.php
public check_preauth ( string $user = 'Not Used By Protect', string $username = 'Not Used By Protect', string $password = 'Not Used By Protect' ) : string
$user string
$username string
$password string
return string $user

check_use_math() public method

* Checks if the protect API call has failed, and if so initiates the math captcha fallback.
public check_use_math ( )

configuration_head() public method

public configuration_head ( )

configuration_load() public method

Get or delete API key
public configuration_load ( )

configuration_screen() public method

Prints the configuration screen

delete_transient() public method

Wrapper for WordPress delete_transient function, our version deletes the transient on the main site in the network if this is a multisite network
public delete_transient ( string $transient ) : boolean
$transient string Transient name. Expected to not be SQL-escaped.
return boolean true if successful, false otherwise

get_api_host() public method

public get_api_host ( )

get_headers() public method

..
public get_headers ( ) : string
return string

get_local_host() public method

public get_local_host ( )

get_main_blog_id() public method

If we're in a multisite network, return the blog ID of the primary blog
public get_main_blog_id ( ) : integer
return integer

get_main_blog_jetpack_id() public method

Get jetpack blog id, or the jetpack blog id of the main blog in the main network

get_protect_key() public method

Request an api key from wordpress.com
public get_protect_key ( ) : boolean | string
return boolean | string | string

get_transient() public method

Wrapper for WordPress get_transient function, our version gets the transient on the main site in the network if this is a multisite network
public get_transient ( string $transient ) : mixed
$transient string Transient name. Expected to not be SQL-escaped.
return mixed Value of transient.

instance() public static method

Singleton implementation
public static instance ( ) : object
return object

ip_is_whitelisted() public method

* Checks if the IP address has been whitelisted
public ip_is_whitelisted ( $ip )
$ip

kill_login() public method

* Kill a login attempt
public kill_login ( )

log_failed_attempt() public method

Fires custom, plugable action jpp_log_failed_attempt with the IP
public log_failed_attempt ( ) : void
return void

log_successful_login() public method

Logs a successful login back to our servers, this allows us to make sure we're not blocking a busy IP that has a lot of good logins along with some forgotten passwords. Also saves current user's ip to the ip address whitelist
public log_successful_login ( $user_login, $user )

maybe_display_security_warning() public method

maybe_get_protect_key() public method

maybe_update_headers() public method

Sends a "check_key" API call once a day. This call allows us to track IP-related headers for this server via the Protect API, in order to better identify the source IP for login attempts
public maybe_update_headers ( $force = false )

modules_loaded() public method

Set up the Protect configuration page
public modules_loaded ( )

on_activation() public method

On module activation, try to get an api key
public on_activation ( )

on_deactivation() public method

On module deactivation, unset protect_active
public on_deactivation ( )

prepare_jetpack_protect_multisite_notice() public method

protect_call() public method

Calls over to the api using wp_remote_post
public protect_call ( string $action = 'check_ip', array $request = [] ) : array
$action string 'check_ip', 'check_key', or 'failed_attempt'
$request array Any custom data to post to the api
return array

set_transient() public method

We do it this way (instead of set_site_transient) because of an issue where sitewide transients are always autoloaded https://core.trac.wordpress.org/ticket/22846
public set_transient ( string $transient, mixed $value, integer $expiration ) : boolean
$transient string Transient name. Expected to not be SQL-escaped. Must be 45 characters or fewer in length.
$value mixed Transient value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
$expiration integer Optional. Time until expiration in seconds. Default 0.
return boolean False if value was not set and true if value was set.

Property Details

$api_key public_oe property

public $api_key

$api_key_error public_oe property

public $api_key_error

$last_request public_oe property

public $last_request

$last_response public_oe property

public $last_response

$last_response_raw public_oe property

public $last_response_raw

$whitelist public_oe property

public $whitelist

$whitelist_error public_oe property

public $whitelist_error

$whitelist_saved public_oe property

public $whitelist_saved