Example #1
0
    }
}
$ip_address = iqblockcountry_get_ipaddress();
$country = iqblockcountry_check_ipaddress($ip_address);
iqblockcountry_debug_logging($ip_address, $country, '');
/*
 * Check first if users want to block the backend.
 */
if (($blockcountry_is_login_page || is_admin()) && get_option('blockcountry_blockbackend') == 'on') {
    add_action('init', 'iqblockcountry_checkCountry', 1);
} elseif (get_option('blockcountry_blockfrontend') == "on") {
    add_action('wp_head', 'iqblockcountry_checkCountry', 1);
} else {
    $ip_address = iqblockcountry_get_ipaddress();
    $country = iqblockcountry_check_ipaddress($ip_address);
    iqblockcountry_debug_logging($ip_address, $country, 'NH');
}
add_action('admin_init', 'iqblockcountry_localization');
add_action('admin_menu', 'iqblockcountry_create_menu');
add_filter('update_option_blockcountry_tracking', 'iqblockcountry_schedule_tracking', 10, 2);
add_filter('add_option_blockcountry_tracking', 'iqblockcountry_schedule_tracking', 10, 2);
add_filter('update_option_blockcountry_apikey', 'iqblockcountry_schedule_retrieving', 10, 2);
add_filter('add_option_blockcountry_apikey', 'iqblockcountry_schedule_retrieving', 10, 2);
add_filter('update_option_blockcountry_debuglogging', 'iqblockcountry_blockcountry_debuglogging', 10, 2);
add_filter('add_option_blockcountry_debuglogging', 'iqblockcountry_blockcountry_debuglogging', 10, 2);
add_action('blockcountry_tracking', 'iqblockcountry_tracking');
add_action('blockcountry_retrievebanlist', 'iqblockcountry_tracking_retrieve_xml');
if (get_option('blockcountry_buffer') == "on") {
    add_action('init', 'iqblockcountry_buffer', 1);
    add_action('wp_footer', 'iqblockcountry_buffer_flush');
}
Example #2
0
function iqblockcountry_CheckCountry()
{
    $ip_address = iqblockcountry_get_ipaddress();
    $country = iqblockcountry_check_ipaddress($ip_address);
    global $blockcountry_is_login_page;
    if (($blockcountry_is_login_page || is_admin()) && get_option('blockcountry_blockbackend')) {
        $banlist = get_option('blockcountry_backendbanlist');
        if (!is_array($banlist)) {
            $banlist = array();
        }
        if (get_option('blockcountry_backendbanlist_inverse') == 'on') {
            $all_countries = array_keys(iqblockcountry_get_countries());
            $badcountries = array_diff($all_countries, $banlist);
        } else {
            $badcountries = $banlist;
        }
    } else {
        $banlist = get_option('blockcountry_banlist');
        if (!is_array($banlist)) {
            $banlist = array();
        }
        if (get_option('blockcountry_banlist_inverse') == 'on') {
            $all_countries = array_keys(iqblockcountry_get_countries());
            $badcountries = array_diff($all_countries, $banlist);
        } else {
            $badcountries = $banlist;
        }
    }
    $blocklogin = get_option('blockcountry_blocklogin');
    if (is_user_logged_in() && $blocklogin != "on" || !is_user_logged_in()) {
        /* Check ip address against banlist, whitelist and blacklist */
        if (iqblockcountry_check($country, $badcountries, $ip_address)) {
            if (($blockcountry_is_login_page || is_admin()) && get_option('blockcountry_blockbackend')) {
                $blocked = get_option('blockcountry_backendnrblocks');
                if (empty($blocked)) {
                    $blocked = 0;
                }
                $blocked++;
                update_option('blockcountry_backendnrblocks', $blocked);
                global $apiblacklist, $backendblacklistcheck, $debughandled;
                if (!get_option('blockcountry_logging')) {
                    if (!$apiblacklist) {
                        iqblockcountry_logging($ip_address, $country, "B");
                        iqblockcountry_debug_logging($ip_address, $country, 'BB');
                    } elseif ($backendblacklistcheck && $apiblacklist) {
                        iqblockcountry_logging($ip_address, $country, "T");
                        iqblockcountry_debug_logging($ip_address, $country, 'TB');
                    } else {
                        iqblockcountry_logging($ip_address, $country, "A");
                        iqblockcountry_debug_logging($ip_address, $country, 'AB');
                    }
                }
            } else {
                $blocked = get_option('blockcountry_frontendnrblocks');
                if (empty($blocked)) {
                    $blocked = 0;
                }
                $blocked++;
                update_option('blockcountry_frontendnrblocks', $blocked);
                if (!get_option('blockcountry_logging')) {
                    iqblockcountry_logging($ip_address, $country, "F");
                    iqblockcountry_debug_logging($ip_address, $country, 'FB');
                }
            }
            $blockmessage = get_option('blockcountry_blockmessage');
            $blockredirect = get_option('blockcountry_redirect');
            $blockredirect_url = get_option('blockcountry_redirect_url');
            $header = get_option('blockcountry_header');
            if (!empty($header) && $header) {
                // Prevent as much as possible that this error message is cached:
                header("Cache-Control: no-store, no-cache, must-revalidate");
                header("Cache-Control: post-check=0, pre-check=0", false);
                header("Pragma: no-cache");
                header("Expires: Sat, 26 Jul 2012 05:00:00 GMT");
                header('HTTP/1.1 403 Forbidden');
            }
            if (!empty($blockredirect_url)) {
                header("Location: {$blockredirect_url}");
            } elseif (!empty($blockredirect) && $blockredirect != 0) {
                $redirecturl = get_permalink($blockredirect);
                header("Location: {$redirecturl}");
            }
            // Display block message
            print "{$blockmessage}";
            exit;
        } else {
            iqblockcountry_debug_logging($ip_address, $country, 'NB');
        }
    } else {
        iqblockcountry_debug_logging($ip_address, $country, 'NB');
    }
}