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'); } }
function iqblockcountry_settings_logging() { ?> <h3><?php _e('Last blocked visits', 'iqblockcountry'); ?> </h3> <?php if (!get_option('blockcountry_logging')) { global $wpdb; $table_name = $wpdb->prefix . "iqblock_logging"; $format = get_option('date_format') . ' ' . get_option('time_format'); $nrrows = get_option('blockcountry_nrstatistics'); if ($nrrows == "") { $nrrows = 15; } $countrylist = iqblockcountry_get_countries(); echo '<table class="widefat">'; echo '<thead><tr><th>' . __('Date / Time', 'iqblockcountry') . '</th><th>' . __('IP Address', 'iqblockcountry') . '</th><th>' . __('Hostname', 'iqblockcountry') . '</th><th>' . __('URL', 'iqblockcountry') . '</th><th>' . __('Country', 'iqblockcountry') . '</th><th>' . __('Frontend/Backend', 'iqblockcountry') . '</th></tr></thead>'; foreach ($wpdb->get_results("SELECT * FROM {$table_name} ORDER BY datetime DESC LIMIT {$nrrows}") as $row) { $countryimage = "icons/" . strtolower($row->country) . ".png"; $countryurl = '<img src="' . plugins_url($countryimage, dirname(__FILE__)) . '" > '; echo "<tbody><tr><td>"; $datetime = strtotime($row->datetime); $mysqldate = date($format, $datetime); echo $mysqldate . '</td><td>' . $row->ipaddress . '</td><td>' . gethostbyaddr($row->ipaddress) . '</td><td>' . $row->url . '</td><td>' . $countryurl . $countrylist[$row->country] . '<td>'; if ($row->banned == "F") { _e('Frontend', 'iqblockcountry'); } elseif ($row->banned == "A") { _e('Backend banlist', 'iqblockcountry'); } elseif ($row->banned == "T") { _e('Backend & Backend banlist', 'iqblockcountry'); } else { _e('Backend', 'iqblockcountry'); } echo "</td></tr></tbody>"; } echo '</table>'; echo '<hr>'; echo '<h3>' . __('Top countries that are blocked', 'iqblockcountry') . '</h3>'; echo '<table class="widefat">'; echo '<thead><tr><th>' . __('Country', 'iqblockcountry') . '</th><th>' . __('# of blocked attempts', 'iqblockcountry') . '</th></tr></thead>'; foreach ($wpdb->get_results("SELECT count(country) AS count,country FROM {$table_name} GROUP BY country ORDER BY count(country) DESC LIMIT {$nrrows}") as $row) { $countryimage = "icons/" . strtolower($row->country) . ".png"; $countryurl = '<img src="' . plugins_url($countryimage, dirname(__FILE__)) . '" > '; echo "<tbody><tr><td>" . $countryurl . $countrylist[$row->country] . "</td><td>" . $row->count . "</td></tr></tbody>"; } echo '</table>'; echo '<hr>'; echo '<h3>' . __('Top hosts that are blocked', 'iqblockcountry') . '</h3>'; echo '<table class="widefat">'; echo '<thead><tr><th>' . __('IP Address', 'iqblockcountry') . '</th><th>' . __('Hostname', 'iqblockcountry') . '</th><th>' . __('# of blocked attempts', 'iqblockcountry') . '</th></tr></thead>'; foreach ($wpdb->get_results("SELECT count(ipaddress) AS count,ipaddress FROM {$table_name} GROUP BY ipaddress ORDER BY count(ipaddress) DESC LIMIT {$nrrows}") as $row) { echo "<tbody><tr><td>" . $row->ipaddress . "</td><td>" . gethostbyaddr($row->ipaddress) . "</td><td>" . $row->count . "</td></tr></tbody>"; } echo '</table>'; echo '<hr>'; echo '<h3>' . __('Top URLs that are blocked', 'iqblockcountry') . '</h3>'; echo '<table class="widefat">'; echo '<thead><tr><th>' . __('URL', 'iqblockcountry') . '</th><th>' . __('# of blocked attempts', 'iqblockcountry') . '</th></tr></thead>'; foreach ($wpdb->get_results("SELECT count(url) AS count,url FROM {$table_name} GROUP BY url ORDER BY count(url) DESC LIMIT {$nrrows}") as $row) { echo "<tbody><tr><td>" . $row->url . "</td><td>" . $row->count . "</td></tr></tbody>"; } echo '</table>'; ?> <form name="cleardatabase" action="#cleardatabase" method="post"> <input type="hidden" name="action" value="cleardatabase" /> <?php echo '<div class="submit"><input type="submit" name="test" value="' . __('Clear database', 'iqblockcountry') . '" /></div>'; wp_nonce_field('iqblockcountry'); if (isset($_POST['action']) && $_POST['action'] == 'cleardatabase') { global $wpdb; $table_name = $wpdb->prefix . "iqblock_logging"; $sql = "TRUNCATE " . $table_name . ";"; $wpdb->query($sql); echo mysql_error(); echo "Cleared database"; } } else { echo "<hr><h3>"; _e('You are not logging any information. Please uncheck the option \'Do not log IP addresses\' if this is not what you want.', 'iqblockcountry'); echo "<hr></h3>"; } }