Last active
May 26, 2016 13:53
-
-
Save bjornjohansen/c6598834712eb3b6cc5b18e23b186190 to your computer and use it in GitHub Desktop.
Whitelist the remote IP in CloudProxy when the user logs into WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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