Example #1
0
require_once 'libs/blockcountry-tracking.php';
require_once 'libs/blockcountry-search-engines.php';
global $apiblacklist;
$apiblacklist = FALSE;
$backendblacklistcheck = FALSE;
register_activation_hook(__FILE__, 'iqblockcountry_this_plugin_first');
register_activation_hook(__FILE__, 'iqblockcountry_set_defaults');
register_uninstall_hook(__FILE__, 'iqblockcountry_uninstall');
// Check if upgrade is necessary
iqblockcountry_upgrade();
/* Clean logging database */
iqblockcountry_clean_db();
/*
 * Check first if users want to block the backend.
 */
if ((iqblockcountry_is_login_page() || is_admin()) && get_option('blockcountry_blockbackend')) {
    add_action('login_head', 'iqblockcountry_checkCountry', 1);
}
/*
 * Check first if users want to block the frontend.
 */
if (get_option('blockcountry_blockfrontend') == "on") {
    add_action('wp_head', 'iqblockcountry_checkCountry', 1);
}
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_backendlogging', 'iqblockcountry_blockcountry_backendlogging', 10, 2);
Example #2
0
define("VERSION", "1.1.22");
define("DBVERSION", "121");
define("PLUGINPATH", plugin_dir_path(__FILE__));
/*
 * Include libraries
 */
require_once 'libs/blockcountry-checks.php';
require_once 'libs/blockcountry-settings.php';
require_once 'libs/blockcountry-validation.php';
require_once 'libs/blockcountry-logging.php';
require_once 'libs/blockcountry-tracking.php';
require_once 'libs/blockcountry-search-engines.php';
global $apiblacklist;
$apiblacklist = FALSE;
$backendblacklistcheck = FALSE;
$blockcountry_is_login_page = iqblockcountry_is_login_page();
register_activation_hook(__FILE__, 'iqblockcountry_this_plugin_first');
register_activation_hook(__FILE__, 'iqblockcountry_set_defaults');
register_uninstall_hook(__FILE__, 'iqblockcountry_uninstall');
// Check if upgrade is necessary
iqblockcountry_upgrade();
/* Clean logging database */
iqblockcountry_clean_db();
if (isset($_POST['action'])) {
    $iqaction = filter_var($_POST['action'], FILTER_SANITIZE_STRING);
    if ($iqaction == 'csvoutput') {
        global $wpdb;
        $output = "";
        $table_name = $wpdb->prefix . "iqblock_logging";
        $format = get_option('date_format') . ' ' . get_option('time_format');
        foreach ($wpdb->get_results("SELECT * FROM {$table_name} ORDER BY datetime ASC") as $row) {
function iqblockcountry_CheckCountry()
{
    $ip_address = iqblockcountry_get_ipaddress();
    $country = iqblockcountry_check_ipaddress($ip_address);
    if ((iqblockcountry_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)) {
            $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}";
            if ((iqblockcountry_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;
                if (!get_option('blockcountry_logging')) {
                    if (!$apiblacklist) {
                        iqblockcountry_logging($ip_address, $country, "B");
                    } elseif ($backendblacklistcheck && $apiblacklist) {
                        iqblockcountry_logging($ip_address, $country, "T");
                    } else {
                        iqblockcountry_logging($ip_address, $country, "A");
                    }
                }
            } 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");
                }
            }
            exit;
        }
    }
}