/**
 * Returns an array of IP objects that will never be blocked by the Protect module
 *
 * The array is segmented into a local whitelist which applies only to the current site
 * and a global whitelist which, for multisite installs, applies to the entire networko
 *
 * @return array
 */
function jetpack_protect_format_whitelist()
{
    $local_whitelist = jetpack_protect_get_local_whitelist();
    $formatted = array('local' => array());
    foreach ($local_whitelist as $item) {
        if ($item->range) {
            $formatted['local'][] = $item->range_low . ' - ' . $item->range_high;
        } else {
            $formatted['local'][] = $item->ip_address;
        }
    }
    if (is_multisite() && current_user_can('manage_network')) {
        $formatted['global'] = array();
        $global_whitelist = jetpack_protect_get_global_whitelist();
        if (false === $global_whitelist) {
            // if the global whitelist has never been set, check for a legacy option set prior to 3.6
            $global_whitelist = get_site_option('jetpack_protect_whitelist', array());
        }
        foreach ($global_whitelist as $item) {
            if ($item->range) {
                $formatted['global'][] = $item->range_low . ' - ' . $item->range_high;
            } else {
                $formatted['global'][] = $item->ip_address;
            }
        }
    }
    return $formatted;
}
Example #2
0
 function ip_is_whitelisted($ip)
 {
     // If we found an exact match in wp-config
     if (defined('JETPACK_IP_ADDRESS_OK') && JETPACK_IP_ADDRESS_OK == $ip) {
         return true;
     }
     $whitelist = jetpack_protect_get_local_whitelist();
     if (is_multisite()) {
         $whitelist = array_merge($whitelist, get_site_option('jetpack_protect_global_whitelist', array()));
     }
     if (!empty($whitelist)) {
         foreach ($whitelist as $item) {
             // If the IPs are an exact match
             if (!$item->range && isset($item->ip_address) && $item->ip_address == $ip) {
                 return true;
             }
             if ($item->range && isset($item->range_low) && isset($item->range_high)) {
                 if (jetpack_protect_ip_address_is_in_range($ip, $item->range_low, $item->range_high)) {
                     return true;
                 }
             }
         }
     }
     return false;
 }