iQ Block Country - Version 1.4.41

Version Description

Download this release

Release Info

Developer iqpascal
Plugin Icon 128x128 iQ Block Country
Version 1.4.41
Comparing to
See all releases

Code changes from version 1.1.40 to 1.4.41

iq-block-country.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: iQ Block Country
4
  Plugin URI: https://www.webence.nl/plugins/iq-block-country-the-wordpress-plugin-that-blocks-countries-for-you/
5
- Version: 1.1.40
6
  Author: Pascal
7
  Author URI: https://www.webence.nl/
8
  Description: Block visitors from visiting your website and backend website based on which country their IP address is from. The Maxmind GeoIP lite database is used for looking up from which country an ip address is from.
@@ -13,7 +13,7 @@ Domain Path: /lang
13
 
14
  /* This script uses GeoLite Country from MaxMind (http://www.maxmind.com) which is available under terms of GPL/LGPL */
15
 
16
- /* Copyright 2010-2016 Pascal (email : pascal@webence.nl)
17
 
18
  This program is free software; you can redistribute it and/or modify
19
  it under the terms of the GNU General Public License, version 2, as
@@ -107,7 +107,7 @@ function iqblockcountry_get_countries()
107
  return $countrylist;
108
  }
109
 
110
- return $countylist;
111
  }
112
 
113
  /*
@@ -158,18 +158,18 @@ function iqblockcountry_upgrade()
158
  /* Check if update is necessary */
159
  $dbversion = get_option( 'blockcountry_version' );
160
  update_option('blockcountry_version',VERSION);
161
- if ($dbversion != "" && version_compare($dbversion, "1.1.31", '<') )
 
 
162
  {
163
- if (!get_option('blockcountry_blocktag'))
164
- {
165
- update_option('blockcountry_blocktag','on');
166
- }
167
  }
168
- elseif ($dbversion != "" && version_compare($dbversion, "1.1.21", '<') )
169
  {
170
- if (!get_option('blockcountry_geoapilocation'))
171
  {
172
- iqblockcountry_find_geoip_location();
173
  }
174
  }
175
  elseif ($dbversion != "" && version_compare($dbversion, "1.1.19", '<') )
@@ -230,13 +230,14 @@ define("IPV4DB","http://geolite.maxmind.com/download/geoip/database/GeoLiteCount
230
  define("IPV4DBFILE",$upload_dir['basedir'] . "/GeoIP.dat");
231
  define("IPV6DBFILE",$upload_dir['basedir'] . "/GeoIPv6.dat");
232
  define("TRACKINGURL","https://tracking.webence.nl/iq-block-country-tracking.php");
233
- define("BANLISTRETRIEVEURL","https://tracking.webence.nl/iq-block-country-retrieve.php");
234
  define("GEOIPAPIURL","https://eu.geoip.webence.nl/geoipapi.php");
235
  define("GEOIPAPIURLUS","https://us.geoip.webence.nl/geoipapi.php");
 
236
  define("GEOIPAPIURLASIA","https://asia.geoip.webence.nl/geoipapi.php");
237
  define("GEOIPAPICHECKURL","https://eu.geoip.webence.nl/geoipapi-keycheck.php");
238
  define("ADMINAPICHECKURL","https://tracking.webence.nl/adminapi-keycheck.php");
239
- define("VERSION","1.1.40");
240
  define("DBVERSION","122");
241
  define("PLUGINPATH",plugin_dir_path( __FILE__ ));
242
 
@@ -281,8 +282,6 @@ if (isset($_POST['action']))
281
 
282
  if (is_user_logged_in() && is_admin() && check_admin_referer( 'iqblockcountrycsv' ))
283
  {
284
- // $iqaction = filter_var($_POST['action'],FILTER_SANITIZE_STRING);
285
- // if ($iqaction == 'csvoutput') {
286
  global $wpdb;
287
  $output = "";
288
  $table_name = $wpdb->prefix . "iqblock_logging";
@@ -309,6 +308,7 @@ if (isset($_POST['action']))
309
  $country = iqblockcountry_check_ipaddress($ip_address);
310
  iqblockcountry_debug_logging($ip_address,$country,'');
311
 
 
312
  function iq_add_my_scripts() {
313
  // Scripts
314
  wp_enqueue_script( 'chosen', CHOSENJS, array( 'jquery' ), false, true );
@@ -327,7 +327,7 @@ if (($blockcountry_is_login_page || is_admin() || $blockcountry_is_xmlrpc) && ge
327
  }
328
  elseif (get_option('blockcountry_blockfrontend') == "on")
329
  {
330
- add_action ( 'wp_head', 'iqblockcountry_checkCountry', 1 );
331
  }
332
  else
333
  {
2
  /*
3
  Plugin Name: iQ Block Country
4
  Plugin URI: https://www.webence.nl/plugins/iq-block-country-the-wordpress-plugin-that-blocks-countries-for-you/
5
+ Version: 1.1.41
6
  Author: Pascal
7
  Author URI: https://www.webence.nl/
8
  Description: Block visitors from visiting your website and backend website based on which country their IP address is from. The Maxmind GeoIP lite database is used for looking up from which country an ip address is from.
13
 
14
  /* This script uses GeoLite Country from MaxMind (http://www.maxmind.com) which is available under terms of GPL/LGPL */
15
 
16
+ /* Copyright 2010-2017 Pascal (email : pascal@webence.nl)
17
 
18
  This program is free software; you can redistribute it and/or modify
19
  it under the terms of the GNU General Public License, version 2, as
107
  return $countrylist;
108
  }
109
 
110
+ return $countrylist;
111
  }
112
 
113
  /*
158
  /* Check if update is necessary */
159
  $dbversion = get_option( 'blockcountry_version' );
160
  update_option('blockcountry_version',VERSION);
161
+
162
+
163
+ if ($dbversion != "" && version_compare($dbversion, "1.1.41", '<') )
164
  {
165
+ iqblockcountry_find_geoip_location();
166
+ update_option('blockcountry_daysstatistics',30);
 
 
167
  }
168
+ elseif ($dbversion != "" && version_compare($dbversion, "1.1.31", '<') )
169
  {
170
+ if (!get_option('blockcountry_blocktag'))
171
  {
172
+ update_option('blockcountry_blocktag','on');
173
  }
174
  }
175
  elseif ($dbversion != "" && version_compare($dbversion, "1.1.19", '<') )
230
  define("IPV4DBFILE",$upload_dir['basedir'] . "/GeoIP.dat");
231
  define("IPV6DBFILE",$upload_dir['basedir'] . "/GeoIPv6.dat");
232
  define("TRACKINGURL","https://tracking.webence.nl/iq-block-country-tracking.php");
233
+ define("BANLISTRETRIEVEURL","https://eu.adminblock.webence.nl/iq-block-country-retrieve.php");
234
  define("GEOIPAPIURL","https://eu.geoip.webence.nl/geoipapi.php");
235
  define("GEOIPAPIURLUS","https://us.geoip.webence.nl/geoipapi.php");
236
+ define("GEOIPAPIURLUS2","https://us2.geoip.webence.nl/geoipapi.php");
237
  define("GEOIPAPIURLASIA","https://asia.geoip.webence.nl/geoipapi.php");
238
  define("GEOIPAPICHECKURL","https://eu.geoip.webence.nl/geoipapi-keycheck.php");
239
  define("ADMINAPICHECKURL","https://tracking.webence.nl/adminapi-keycheck.php");
240
+ define("VERSION","1.1.41");
241
  define("DBVERSION","122");
242
  define("PLUGINPATH",plugin_dir_path( __FILE__ ));
243
 
282
 
283
  if (is_user_logged_in() && is_admin() && check_admin_referer( 'iqblockcountrycsv' ))
284
  {
 
 
285
  global $wpdb;
286
  $output = "";
287
  $table_name = $wpdb->prefix . "iqblock_logging";
308
  $country = iqblockcountry_check_ipaddress($ip_address);
309
  iqblockcountry_debug_logging($ip_address,$country,'');
310
 
311
+
312
  function iq_add_my_scripts() {
313
  // Scripts
314
  wp_enqueue_script( 'chosen', CHOSENJS, array( 'jquery' ), false, true );
327
  }
328
  elseif (get_option('blockcountry_blockfrontend') == "on")
329
  {
330
+ add_action ( 'init', 'iqblockcountry_checkCountry', 1 );
331
  }
332
  else
333
  {
libs/blockcountry-checks.php CHANGED
@@ -50,11 +50,18 @@ function iqblockcountry_check_ipaddress($ip_address)
50
  */
51
  function iqblockcountry_retrieve_geoipapi($ipaddress)
52
  {
 
 
 
53
  $url = GEOIPAPIURL;
54
  if (get_option('blockcountry_geoapilocation') == "US")
55
  {
56
  $url = GEOIPAPIURLUS;
57
  }
 
 
 
 
58
  if (get_option('blockcountry_geoapilocation') == "ASIA")
59
  {
60
  $url = GEOIPAPIURLASIA;
@@ -90,6 +97,9 @@ function iqblockcountry_retrieve_geoipapi($ipaddress)
90
  update_option('blockcountry_geoapikey','');
91
  }
92
  else return "Unknown";
 
 
 
93
  }
94
 
95
 
50
  */
51
  function iqblockcountry_retrieve_geoipapi($ipaddress)
52
  {
53
+ if (iqblockcountry_is_valid_ipv4($ipaddress) || iqblockcountry_is_valid_ipv6($ipaddress))
54
+ {
55
+
56
  $url = GEOIPAPIURL;
57
  if (get_option('blockcountry_geoapilocation') == "US")
58
  {
59
  $url = GEOIPAPIURLUS;
60
  }
61
+ if (get_option('blockcountry_geoapilocation') == "US2")
62
+ {
63
+ $url = GEOIPAPIURLUS2;
64
+ }
65
  if (get_option('blockcountry_geoapilocation') == "ASIA")
66
  {
67
  $url = GEOIPAPIURLASIA;
97
  update_option('blockcountry_geoapikey','');
98
  }
99
  else return "Unknown";
100
+ }
101
+ else
102
+ { return "Invalid"; }
103
  }
104
 
105
 
libs/blockcountry-logging.php CHANGED
@@ -36,9 +36,12 @@ function iqblockcountry_uninstall_db() {
36
  function iqblockcountry_clean_db()
37
  {
38
  global $wpdb;
 
 
 
39
 
40
  $table_name = $wpdb->prefix . "iqblock_logging";
41
- $sql = "DELETE FROM " . $table_name . " WHERE DATE_SUB(CURDATE(),INTERVAL 31 DAY) >= datetime;";
42
  $wpdb->query($sql);
43
 
44
  }
36
  function iqblockcountry_clean_db()
37
  {
38
  global $wpdb;
39
+
40
+ $nrdays = get_option('blockcountry_daysstatistics');
41
+
42
 
43
  $table_name = $wpdb->prefix . "iqblock_logging";
44
+ $sql = "DELETE FROM " . $table_name . " WHERE DATE_SUB(CURDATE(),INTERVAL " . $nrdays . " DAY) >= datetime;";
45
  $wpdb->query($sql);
46
 
47
  }
libs/blockcountry-settings.php CHANGED
@@ -138,7 +138,8 @@ function iqblockcountry_register_mysettings()
138
  register_setting ( 'iqblockcountry-settings-group', 'blockcountry_buffer');
139
  register_setting ( 'iqblockcountry-settings-group', 'blockcountry_tracking');
140
  register_setting ( 'iqblockcountry-settings-group', 'blockcountry_nrstatistics');
141
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_nrstatistics');
 
142
  register_setting ( 'iqblockcountry-settings-group', 'blockcountry_geoapikey','iqblockcountry_check_geoapikey');
143
  register_setting ( 'iqblockcountry-settings-group', 'blockcountry_geoapilocation');
144
  register_setting ( 'iqblockcountry-settings-group', 'blockcountry_apikey','iqblockcountry_check_adminapikey');
@@ -181,10 +182,10 @@ function iqblockcountry_get_options_arr() {
181
  'blockcountry_backendblacklist','blockcountry_backendwhitelist','blockcountry_frontendblacklist','blockcountry_frontendwhitelist',
182
  'blockcountry_blockmessage','blockcountry_blocklogin','blockcountry_blockfrontend','blockcountry_blockbackend','blockcountry_header',
183
  'blockcountry_blockpages','blockcountry_pages','blockcountry_blockcategories','blockcountry_categories','blockcountry_tracking',
184
- 'blockcountry_blockhome','blockcountry_nrstatistics','blockcountry_geoapikey','blockcountry_geoapilocation','blockcountry_apikey',
185
- 'blockcountry_redirect','blockcountry_redirect_url','blockcountry_allowse','blockcountry_debuglogging','blockcountry_buffer',
186
- 'blockcountry_accessibility','blockcountry_logging','blockcountry_blockposttypes','blockcountry_posttypes','blockcountry_blocksearch',
187
- 'blockcountry_adminajax','blockcountry_blocktag','blockcountry_blocktags','blockcountry_tags');
188
  return apply_filters( 'iqblockcountry_options', $optarr );
189
  }
190
 
@@ -204,6 +205,7 @@ function iqblockcountry_set_defaults()
204
  if (get_option('blockcountry_frontendnrblocks') === FALSE) { update_option('blockcountry_frontendnrblocks', 0); }
205
  if (get_option('blockcountry_header') === FALSE) { update_option('blockcountry_header', 'on'); }
206
  if (get_option('blockcountry_nrstatistics') === FALSE) { update_option('blockcountry_nrstatistics',15); }
 
207
  if (get_option('blockcountry_backendwhitelist') === FALSE || (get_option('blockcountry_backendwhitelist') == "")) { update_option('blockcountry_backendwhitelist',$ip_address); }
208
  iqblockcountry_install_db();
209
  iqblockcountry_find_geoip_location();
@@ -239,6 +241,8 @@ function iqblockcountry_uninstall() //deletes all the database entries that the
239
  delete_option('blockcountry_blockhome');
240
  delete_option('blockcountry_backendbanlistip');
241
  delete_option('blockcountry_nrstastistics');
 
 
242
  delete_option('blockcountry_geoapikey');
243
  delete_option('blockcountry_geoapilocation');
244
  delete_option('blockcountry_apikey');
@@ -519,14 +523,6 @@ function iqblockcountry_settings_tools() {
519
  ?>
520
  <tbody><tr><td><?php _e( 'PHP Max Post Size', 'iq-block-country' ); ?>: <strong><?php echo $post_max; ?></strong></td></tr></tbody>
521
  <?php
522
- if ( ini_get( 'safe_mode' ) ) {
523
- $safe_mode = __( 'On', 'iq-block-country' );
524
- } else {
525
- $safe_mode = __( 'Off', 'iq-block-country' );
526
- }
527
- ?>
528
- <tbody><tr><td><?php _e( 'PHP Safe Mode', 'iq-block-country' ); ?>: <strong><?php echo $safe_mode; ?></strong></td></tr></tbody>
529
- <?php
530
  if ( ini_get( 'allow_url_fopen' ) ) {
531
  $allow_url_fopen = __( 'On', 'iq-block-country' );
532
  } else {
@@ -1381,8 +1377,8 @@ if (is_file ( IPV4DBFILE ) && (!get_option('blockcountry_geoapikey'))) {
1381
 
1382
 
1383
  <tr valign="top">
1384
- <th width="30%"><?php _e('Number of rows on statistics page:', 'iq-block-country'); ?><br />
1385
- <em><?php _e('How many rows do you want to display on each tab the statistics page.', 'iq-block-country'); ?></em></th>
1386
  <td width="70%">
1387
  <?php
1388
  $nrrows = get_option('blockcountry_nrstatistics'); ?>
@@ -1396,6 +1392,29 @@ if (is_file ( IPV4DBFILE ) && (!get_option('blockcountry_geoapikey'))) {
1396
  </select>
1397
  </td></tr>
1398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1399
  <tr valign="top">
1400
  <th width="30%"><?php _e('Allow tracking:', 'iq-block-country'); ?><br />
1401
  <em><?php _e('This sends only the IP address and the number of attempts this ip address tried to login to your backend and was blocked doing so to a central server. No other data is being send. This helps us to get a better picture of rogue countries.', 'iq-block-country'); ?></em></th>
@@ -1405,7 +1424,7 @@ if (is_file ( IPV4DBFILE ) && (!get_option('blockcountry_geoapikey'))) {
1405
 
1406
  <tr valign="top">
1407
  <th width="30%"><?php _e('GeoIP API Key:', 'iq-block-country'); ?><br />
1408
- <em><?php _e('If for some reason you cannot or do not want to download the MaxMind GeoIP databases you will need an API key for the GeoIP api.<br />You can get an API key from: ', 'iq-block-country'); ?> <a href="https://geoip.webence.nl/" target=""_blank>https://geoip.webence.nl/</a></em></th>
1409
  </th>
1410
  <td width="70%">
1411
  <input type="text" size="25" name="blockcountry_geoapikey" value="<?php echo get_option ( 'blockcountry_geoapikey' );?>">
@@ -1418,13 +1437,14 @@ if (is_file ( IPV4DBFILE ) && (!get_option('blockcountry_geoapikey'))) {
1418
  </th>
1419
  <td width="70%">
1420
 
1421
- <input type="radio" name="blockcountry_geoapilocation" value="EU" <?php checked('EU', get_option('blockcountry_geoapilocation'), true); ?>> Europe
1422
- <input type="radio" name="blockcountry_geoapilocation" value="US" <?php checked('US', get_option('blockcountry_geoapilocation'), true); ?>> United States
 
1423
  <input type="radio" name="blockcountry_geoapilocation" value="ASIA" <?php checked('ASIA', get_option('blockcountry_geoapilocation'), true); ?>> Asia-Pacific region
1424
  </td></tr>
1425
  <tr valign="top">
1426
  <th width="30%"><?php _e('Admin block API Key:', 'iq-block-country'); ?><br />
1427
- <em><?php _e('This is an experimantal feature. You do not need an API key for this plugin to work.', 'iq-block-country'); ?></em></th>
1428
  </th>
1429
  <td width="70%">
1430
  <input type="text" size="25" name="blockcountry_apikey" value="<?php echo get_option ( 'blockcountry_apikey' );?>">
@@ -1477,6 +1497,7 @@ function iqblockcountry_settings_logging()
1477
  $table_name = $wpdb->prefix . "iqblock_logging";
1478
  $format = get_option('date_format') . ' ' . get_option('time_format');
1479
  $nrrows = get_option('blockcountry_nrstatistics');
 
1480
  if ($nrrows == "") { $nrrows = 15;};
1481
  $countrylist = iqblockcountry_get_countries();
1482
  echo '<table class="widefat">';
@@ -1489,7 +1510,14 @@ function iqblockcountry_settings_logging()
1489
  echo "<tbody><tr><td>";
1490
  $datetime = strtotime($row->datetime);
1491
  $mysqldate = date($format, $datetime);
1492
- echo $mysqldate . '</td><td>' . $row->ipaddress . '</td><td>' . gethostbyaddr( $row->ipaddress ) . '</td><td>' . $row->url . '</td><td>' . $countryurl . $countrylist[$row->country] . '<td>';
 
 
 
 
 
 
 
1493
  if ($row->banned == "F") _e('Frontend', 'iq-block-country'); elseif ($row->banned == "A") { _e('Backend banlist','iq-block-country'); } elseif ($row->banned == "T") { _e('Backend & Backend banlist','iq-block-country'); } else { _e('Backend', 'iq-block-country'); }
1494
  echo "</td></tr></tbody>";
1495
  }
@@ -1516,7 +1544,17 @@ function iqblockcountry_settings_logging()
1516
 
1517
  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)
1518
  {
1519
- echo "<tbody><tr><td>" . $row->ipaddress . "</td><td>" . gethostbyaddr($row->ipaddress) . "</td><td>" . $row->count . "</td></tr></tbody>";
 
 
 
 
 
 
 
 
 
 
1520
  }
1521
  echo '</table>';
1522
 
@@ -1547,10 +1585,8 @@ function iqblockcountry_settings_logging()
1547
  $table_name = $wpdb->prefix . "iqblock_logging";
1548
  $sql = "TRUNCATE " . $table_name . ";";
1549
  $wpdb->query($sql);
1550
- echo mysql_error();
1551
  $sql = "ALTER TABLE ". $table_name . " AUTO_INCREMENT = 1;";
1552
  $wpdb->query($sql);
1553
- echo mysql_error();
1554
  echo "Cleared database";
1555
 
1556
  }
@@ -1660,7 +1696,8 @@ function iqblockcountry_settings_page() {
1660
 
1661
  <p>This product uses GeoLite data created by MaxMind, available from <a href="http://www.maxmind.com/">http://www.maxmind.com/</a>.</p>
1662
 
1663
- <p>If you like this plugin please link back to <a href="https://www.webence.nl/">www.webence.nl</a>! :-)</p>
 
1664
 
1665
  <?php
1666
 
@@ -1677,7 +1714,7 @@ function iqblockcountry_find_geoip_location()
1677
  $curl = curl_init();
1678
  curl_setopt_array($curl, array(
1679
  CURLOPT_RETURNTRANSFER => 1,
1680
- CURLOPT_URL => 'http://us.geoip.webence.nl/test',
1681
  CURLOPT_USERAGENT => 'iQ Block Country location test'
1682
  ));
1683
  $resp = curl_exec($curl);
@@ -1687,7 +1724,17 @@ function iqblockcountry_find_geoip_location()
1687
  $curl = curl_init();
1688
  curl_setopt_array($curl, array(
1689
  CURLOPT_RETURNTRANSFER => 1,
1690
- CURLOPT_URL => 'http://asia.geoip.webence.nl/test',
 
 
 
 
 
 
 
 
 
 
1691
  CURLOPT_USERAGENT => 'iQ Block Country location test'
1692
  ));
1693
  $resp = curl_exec($curl);
@@ -1696,30 +1743,30 @@ function iqblockcountry_find_geoip_location()
1696
 
1697
  $curl = curl_init();
1698
  curl_setopt_array($curl, array(
1699
- CURLOPT_URL => 'http://eu.geoip.webence.nl/test',
1700
  CURLOPT_USERAGENT => 'iQ Block Country location test'
1701
  ));
1702
  $resp = curl_exec($curl);
1703
  $infoeu = curl_getinfo($curl);
1704
  curl_close($curl);
1705
 
1706
- if ($infoasia['total_time'] < $infoeu['total_time'])
 
 
1707
  {
1708
  update_option('blockcountry_geoapilocation','ASIA');
1709
  }
1710
- elseif ($infoeu['total_time'] < $infous['total_time'])
1711
  {
1712
- update_option('blockcountry_geoapilocation','EU');
1713
  }
1714
- else
1715
  {
1716
- update_option('blockcountry_geoapilocation','US');
1717
  }
1718
- }
1719
- else
1720
- {
1721
  update_option('blockcountry_geoapilocation','EU');
 
1722
  }
1723
-
1724
-
1725
  }
138
  register_setting ( 'iqblockcountry-settings-group', 'blockcountry_buffer');
139
  register_setting ( 'iqblockcountry-settings-group', 'blockcountry_tracking');
140
  register_setting ( 'iqblockcountry-settings-group', 'blockcountry_nrstatistics');
141
+ register_setting ( 'iqblockcountry-settings-group', 'blockcountry_daysstatistics');
142
+ register_setting ( 'iqblockcountry-settings-group', 'blockcountry_lookupstatistics');
143
  register_setting ( 'iqblockcountry-settings-group', 'blockcountry_geoapikey','iqblockcountry_check_geoapikey');
144
  register_setting ( 'iqblockcountry-settings-group', 'blockcountry_geoapilocation');
145
  register_setting ( 'iqblockcountry-settings-group', 'blockcountry_apikey','iqblockcountry_check_adminapikey');
182
  'blockcountry_backendblacklist','blockcountry_backendwhitelist','blockcountry_frontendblacklist','blockcountry_frontendwhitelist',
183
  'blockcountry_blockmessage','blockcountry_blocklogin','blockcountry_blockfrontend','blockcountry_blockbackend','blockcountry_header',
184
  'blockcountry_blockpages','blockcountry_pages','blockcountry_blockcategories','blockcountry_categories','blockcountry_tracking',
185
+ 'blockcountry_blockhome','blockcountry_nrstatistics','blockcountry_daysstatistics','blockcountry_lookupstatistics','blockcountry_geoapikey',
186
+ 'blockcountry_geoapilocation','blockcountry_apikey','blockcountry_redirect','blockcountry_redirect_url','blockcountry_allowse',
187
+ 'blockcountry_debuglogging','blockcountry_buffer','blockcountry_accessibility','blockcountry_logging','blockcountry_blockposttypes',
188
+ 'blockcountry_posttypes','blockcountry_blocksearch','blockcountry_adminajax','blockcountry_blocktag','blockcountry_blocktags','blockcountry_tags');
189
  return apply_filters( 'iqblockcountry_options', $optarr );
190
  }
191
 
205
  if (get_option('blockcountry_frontendnrblocks') === FALSE) { update_option('blockcountry_frontendnrblocks', 0); }
206
  if (get_option('blockcountry_header') === FALSE) { update_option('blockcountry_header', 'on'); }
207
  if (get_option('blockcountry_nrstatistics') === FALSE) { update_option('blockcountry_nrstatistics',15); }
208
+ if (get_option('blockcountry_daysstatistics') == FALSE) { update_option('blockcountry_daysstatistics',30); }
209
  if (get_option('blockcountry_backendwhitelist') === FALSE || (get_option('blockcountry_backendwhitelist') == "")) { update_option('blockcountry_backendwhitelist',$ip_address); }
210
  iqblockcountry_install_db();
211
  iqblockcountry_find_geoip_location();
241
  delete_option('blockcountry_blockhome');
242
  delete_option('blockcountry_backendbanlistip');
243
  delete_option('blockcountry_nrstastistics');
244
+ delete_option('blockcountry_daysstatistics');
245
+ delete_option('blockcountry_lookupstatistics');
246
  delete_option('blockcountry_geoapikey');
247
  delete_option('blockcountry_geoapilocation');
248
  delete_option('blockcountry_apikey');
523
  ?>
524
  <tbody><tr><td><?php _e( 'PHP Max Post Size', 'iq-block-country' ); ?>: <strong><?php echo $post_max; ?></strong></td></tr></tbody>
525
  <?php
 
 
 
 
 
 
 
 
526
  if ( ini_get( 'allow_url_fopen' ) ) {
527
  $allow_url_fopen = __( 'On', 'iq-block-country' );
528
  } else {
1377
 
1378
 
1379
  <tr valign="top">
1380
+ <th width="30%"><?php _e('Number of rows on logging tab:', 'iq-block-country'); ?><br />
1381
+ <em><?php _e('How many rows do you want to display on each column on the logging tab.', 'iq-block-country'); ?></em></th>
1382
  <td width="70%">
1383
  <?php
1384
  $nrrows = get_option('blockcountry_nrstatistics'); ?>
1392
  </select>
1393
  </td></tr>
1394
 
1395
+ <tr valign="top">
1396
+ <th width="30%"><?php _e('Number of days to keep logging:', 'iq-block-country'); ?><br />
1397
+ <em><?php _e('How many days do you want to keep the logging used for the logging tab.', 'iq-block-country'); ?></em></th>
1398
+ <td width="70%">
1399
+ <?php
1400
+ $nrdays = get_option('blockcountry_daysstatistics'); ?>
1401
+ <select name="blockcountry_daysstatistics">
1402
+ <option <?php selected( $nrdays, 7 ); ?> value="7">7</option>
1403
+ <option <?php selected( $nrdays, 14 ); ?> value="14">14</option>
1404
+ <option <?php selected( $nrdays, 21 ); ?> value="21">21</option>
1405
+ <option <?php selected( $nrdays, 30 ); ?> value="30">30</option>
1406
+ <option <?php selected( $nrdays, 60 ); ?> value="60">60</option>
1407
+ <option <?php selected( $nrdays, 90 ); ?> value="90">90</option>
1408
+ </select>
1409
+ </td></tr>
1410
+
1411
+ <tr valign="top">
1412
+ <th width="30%"><?php _e('Do not lookup hosts on the logging tab:', 'iq-block-country'); ?><br />
1413
+ <em><?php _e('On some hosting environments looking up hosts may slow down the logging tab.', 'iq-block-country'); ?></em></th>
1414
+ <td width="70%">
1415
+ <input type="checkbox" name="blockcountry_lookupstatistics" <?php checked('on', get_option('blockcountry_lookupstatistics'), true); ?> />
1416
+ </td></tr>
1417
+
1418
  <tr valign="top">
1419
  <th width="30%"><?php _e('Allow tracking:', 'iq-block-country'); ?><br />
1420
  <em><?php _e('This sends only the IP address and the number of attempts this ip address tried to login to your backend and was blocked doing so to a central server. No other data is being send. This helps us to get a better picture of rogue countries.', 'iq-block-country'); ?></em></th>
1424
 
1425
  <tr valign="top">
1426
  <th width="30%"><?php _e('GeoIP API Key:', 'iq-block-country'); ?><br />
1427
+ <em><?php _e('If for some reason you cannot or do not want to download the MaxMind GeoIP databases you will need an API key for the GeoIP api.<br />You can get an API key from: ', 'iq-block-country'); ?> <a href="https://geoip.webence.nl/" target="_blank">https://geoip.webence.nl/</a></em></th>
1428
  </th>
1429
  <td width="70%">
1430
  <input type="text" size="25" name="blockcountry_geoapikey" value="<?php echo get_option ( 'blockcountry_geoapikey' );?>">
1437
  </th>
1438
  <td width="70%">
1439
 
1440
+ <input type="radio" name="blockcountry_geoapilocation" value="EU" <?php checked('EU', get_option('blockcountry_geoapilocation'), true); ?>> Europe<br />
1441
+ <input type="radio" name="blockcountry_geoapilocation" value="US" <?php checked('US', get_option('blockcountry_geoapilocation'), true); ?>> United States - East coast<br />
1442
+ <input type="radio" name="blockcountry_geoapilocation" value="US2" <?php checked('US2', get_option('blockcountry_geoapilocation'), true); ?>> United States - West coast<br />
1443
  <input type="radio" name="blockcountry_geoapilocation" value="ASIA" <?php checked('ASIA', get_option('blockcountry_geoapilocation'), true); ?>> Asia-Pacific region
1444
  </td></tr>
1445
  <tr valign="top">
1446
  <th width="30%"><?php _e('Admin block API Key:', 'iq-block-country'); ?><br />
1447
+ <em><?php _e('For additional security you can protect your backend from known IP addresses who have made hack attempts at other WordPress sites.<br />You can get more information and an API key from: ', 'iq-block-country'); ?> <a href="https://geoip.webence.nl/admin-block/" target="_blank">https://geoip.webence.nl/admin-block/</a></em></th>
1448
  </th>
1449
  <td width="70%">
1450
  <input type="text" size="25" name="blockcountry_apikey" value="<?php echo get_option ( 'blockcountry_apikey' );?>">
1497
  $table_name = $wpdb->prefix . "iqblock_logging";
1498
  $format = get_option('date_format') . ' ' . get_option('time_format');
1499
  $nrrows = get_option('blockcountry_nrstatistics');
1500
+ $lookupstats = get_option('blockcountry_lookupstatistics');
1501
  if ($nrrows == "") { $nrrows = 15;};
1502
  $countrylist = iqblockcountry_get_countries();
1503
  echo '<table class="widefat">';
1510
  echo "<tbody><tr><td>";
1511
  $datetime = strtotime($row->datetime);
1512
  $mysqldate = date($format, $datetime);
1513
+ if ($lookupstats)
1514
+ {
1515
+ echo $mysqldate . '</td><td>' . $row->ipaddress . '</td><td>'. $row->ipaddress . '</td><td>' . $row->url . '</td><td>' . $countryurl . $countrylist[$row->country] . '<td>';
1516
+ }
1517
+ else
1518
+ {
1519
+ echo $mysqldate . '</td><td>' . $row->ipaddress . '</td><td>' . gethostbyaddr( $row->ipaddress ) . '</td><td>' . $row->url . '</td><td>' . $countryurl . $countrylist[$row->country] . '<td>';
1520
+ }
1521
  if ($row->banned == "F") _e('Frontend', 'iq-block-country'); elseif ($row->banned == "A") { _e('Backend banlist','iq-block-country'); } elseif ($row->banned == "T") { _e('Backend & Backend banlist','iq-block-country'); } else { _e('Backend', 'iq-block-country'); }
1522
  echo "</td></tr></tbody>";
1523
  }
1544
 
1545
  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)
1546
  {
1547
+ if ($lookupstats)
1548
+ {
1549
+ echo "<tbody><tr><td>" . $row->ipaddress . "</td><td>" . $row->ipaddress . "</td><td>" . $row->count . "</td></tr></tbody>";
1550
+ }
1551
+ else
1552
+ {
1553
+ echo "<tbody><tr><td>" . $row->ipaddress . "</td><td>" . gethostbyaddr($row->ipaddress) . "</td><td>" . $row->count . "</td></tr></tbody>";
1554
+
1555
+ }
1556
+
1557
+
1558
  }
1559
  echo '</table>';
1560
 
1585
  $table_name = $wpdb->prefix . "iqblock_logging";
1586
  $sql = "TRUNCATE " . $table_name . ";";
1587
  $wpdb->query($sql);
 
1588
  $sql = "ALTER TABLE ". $table_name . " AUTO_INCREMENT = 1;";
1589
  $wpdb->query($sql);
 
1590
  echo "Cleared database";
1591
 
1592
  }
1696
 
1697
  <p>This product uses GeoLite data created by MaxMind, available from <a href="http://www.maxmind.com/">http://www.maxmind.com/</a>.</p>
1698
 
1699
+ <p>If you like this plugin please link back to <a href="https://www.webence.nl/">www.webence.nl</a>! :-) and support the development of the plugin.
1700
+ See <a href="https://www.webence.nl/plugins/donate/">Plugin donation page</a> or become a <a href="https://www.patreon.com/webence" target="_blank">Patreon</a></p>
1701
 
1702
  <?php
1703
 
1714
  $curl = curl_init();
1715
  curl_setopt_array($curl, array(
1716
  CURLOPT_RETURNTRANSFER => 1,
1717
+ CURLOPT_URL => 'https://us.geoip.webence.nl/test',
1718
  CURLOPT_USERAGENT => 'iQ Block Country location test'
1719
  ));
1720
  $resp = curl_exec($curl);
1724
  $curl = curl_init();
1725
  curl_setopt_array($curl, array(
1726
  CURLOPT_RETURNTRANSFER => 1,
1727
+ CURLOPT_URL => 'https://us2.geoip.webence.nl/test',
1728
+ CURLOPT_USERAGENT => 'iQ Block Country location test'
1729
+ ));
1730
+ $resp = curl_exec($curl);
1731
+ $infous2 = curl_getinfo($curl);
1732
+ curl_close($curl);
1733
+
1734
+ $curl = curl_init();
1735
+ curl_setopt_array($curl, array(
1736
+ CURLOPT_RETURNTRANSFER => 1,
1737
+ CURLOPT_URL => 'https://asia.geoip.webence.nl/test',
1738
  CURLOPT_USERAGENT => 'iQ Block Country location test'
1739
  ));
1740
  $resp = curl_exec($curl);
1743
 
1744
  $curl = curl_init();
1745
  curl_setopt_array($curl, array(
1746
+ CURLOPT_URL => 'https://eu.geoip.webence.nl/test',
1747
  CURLOPT_USERAGENT => 'iQ Block Country location test'
1748
  ));
1749
  $resp = curl_exec($curl);
1750
  $infoeu = curl_getinfo($curl);
1751
  curl_close($curl);
1752
 
1753
+ $fastestsite = min($infoeu['total_time'],$infous['total_time'],$infous2['total_time'],$infoasia['total_time']);
1754
+
1755
+ if ($infoasia['total_time'] == $fastestsite)
1756
  {
1757
  update_option('blockcountry_geoapilocation','ASIA');
1758
  }
1759
+ elseif ($infous['total_time'] == $fastestsite)
1760
  {
1761
+ update_option('blockcountry_geoapilocation','US');
1762
  }
1763
+ elseif ($infous2['total_time'] == $fastestsite)
1764
  {
1765
+ update_option('blockcountry_geoapilocation','US2');
1766
  }
1767
+ else
1768
+ {
 
1769
  update_option('blockcountry_geoapilocation','EU');
1770
+ }
1771
  }
 
 
1772
  }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: iqpascal
3
  Donate link: https://www.webence.nl/plugins/donate
4
  Tags: spam, block, country, comments, ban, geo, geo blocking, geo ip, block country, block countries, ban countries, ban country, blacklist, whitelist, security
5
  Requires at least: 3.5.2
6
- Tested up to: 4.7.3
7
- Stable tag: 1.1.40
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -40,7 +40,7 @@ If you cannot or do not want to download the GeoIP database from Maxmind you can
40
  If you want to use the GeoLite database from Maxmind you will have to download the GeoIP database from MaxMind directly and upload it to your site.
41
  The Wordpress license does not allow this plugin to download the MaxMind Geo database for you.
42
 
43
- Do you need help with this plugin? Please email support@webence.nl or use the WordPress forums.
44
 
45
  = Using this plugin with a caching plugin =
46
 
@@ -179,8 +179,6 @@ If you select this option each hour the plugin checks if it has new data to send
179
 
180
  This data consists of each IP address that has tried to login to your backend and how many attempts were made since the last check.
181
 
182
- Goal of this feature is to check if we can create a user-driven database of rogue IP addresses that try to login to the backend.
183
-
184
  If storing or sharing an IP address is illegal in your country do not select this feature.
185
 
186
  = The laws in my country do not allow storing IP addresses as it is personal information. =
@@ -215,6 +213,13 @@ As the basic rule is to block all and every post you have to configure this in a
215
 
216
  == Changelog ==
217
 
 
 
 
 
 
 
 
218
  = 1.1.40 =
219
 
220
  * Bugfix: Fix for bug in not blocking/allowing post types.
3
  Donate link: https://www.webence.nl/plugins/donate
4
  Tags: spam, block, country, comments, ban, geo, geo blocking, geo ip, block country, block countries, ban countries, ban country, blacklist, whitelist, security
5
  Requires at least: 3.5.2
6
+ Tested up to: 4.7.4
7
+ Stable tag: 1.1.41
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
40
  If you want to use the GeoLite database from Maxmind you will have to download the GeoIP database from MaxMind directly and upload it to your site.
41
  The Wordpress license does not allow this plugin to download the MaxMind Geo database for you.
42
 
43
+ Do you need help with this plugin? Please email support@webence.nl.
44
 
45
  = Using this plugin with a caching plugin =
46
 
179
 
180
  This data consists of each IP address that has tried to login to your backend and how many attempts were made since the last check.
181
 
 
 
182
  If storing or sharing an IP address is illegal in your country do not select this feature.
183
 
184
  = The laws in my country do not allow storing IP addresses as it is personal information. =
213
 
214
  == Changelog ==
215
 
216
+ = 1.1.41 =
217
+
218
+ * Change: Removed unnecessary code.
219
+ * New: New GeoIP API location added at the west coast of the United States
220
+ * New: Limit the number of days the logging is kept between 7 days and 90 days.
221
+ * New: Disable host lookup on the logging tab. In some circumstances this may speed up the logging tab.
222
+
223
  = 1.1.40 =
224
 
225
  * Bugfix: Fix for bug in not blocking/allowing post types.