Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Whitelist the remote IP in CloudProxy when the user logs into WordPress
<?php
/**
* Whitelist the remote IP in CloudProxy when the user logs into WordPress
*
* @param string $user_login The provided $user->user_login
* @param WP_User $user The WP_User object
*/
function whitelist_ip_in_cloudproxy( $user_login, $user ) {
/**
* A capability the user has to have to be whitelisted.
*
* Please remember that whitelisting circumvents most security features in CloudProxy.
*
* @param string $capability The capability needed to be whitelisted.
*/
$capability = apply_filters( 'CloudProxy/Whitelist_IP/Capability', 'unfiltered_html' );
if ( ! user_can( $user, $capability ) ) {
return;
}
if ( ! class_exists( 'SucuriScanAPI' ) ) {
// Not exactly useful to continue now, is it? :-/
return;
}
$ip = SucuriScan::get_remote_addr();
if ( ! SucuriScan::is_valid_ip( $ip ) ) {
return;
}
$api_key = SucuriScanAPI::getCloudproxyKey();
if ( ! $api_key ) {
return;
}
$postdata = array(
'a' => 'whitelist_ip',
'ip' => $ip,
'k' =>$api_key['k'],
's' =>$api_key['s'],
);
// Put on fancypants to create the URL https://waf.sucuri.net/api?v2
$url = add_query_arg( 'v2', '1', SUCURISCAN_CLOUDPROXY_API );
$args = array(
'timeout' => 60,
'blocking' => false, // Fire and forget. We don’t want this to slow down login just to create a log nobody will have interest in.
'body' => $postdata,
);
wp_remote_post( $url, $args );
}
add_action( 'wp_login', 'whitelist_ip_in_cloudproxy', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.