iQ Block Country - Version 1.2.14

Version Description

  • Change: A lot of internal code changes to make it more in line of WordPress Best Practices
Download this release

Release Info

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

Code changes from version 1.2.13 to 1.2.14

iq-block-country.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
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.2.13
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.
9
  License: GPL2
10
  Text Domain: iq-block-country
@@ -29,270 +29,202 @@ Domain Path: /lang
29
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
  */
31
 
32
- /*
33
- *
34
  * This software is dedicated to my one true love.
35
  * Luvya :)
36
- *
37
- */
38
 
39
- /*
40
  * Try to make this plugin the first plugin that is loaded.
41
  * Because we output header info we don't want other plugins to send output first.
42
- */
43
  function iqblockcountry_this_plugin_first()
44
  {
45
- $wp_path_to_this_file = preg_replace('/(.*)plugins\/(.*)$/', WP_PLUGIN_DIR."/$2", __FILE__);
46
- $this_plugin = plugin_basename(trim($wp_path_to_this_file));
47
- $active_plugins = get_option('active_plugins');
48
- $this_plugin_key = array_search($this_plugin, $active_plugins);
49
- if ($this_plugin_key) { // if it's 0 it's the first plugin already, no need to continue
50
- array_splice($active_plugins, $this_plugin_key, 1);
51
- array_unshift($active_plugins, $this_plugin);
52
- update_option('active_plugins', $active_plugins);
53
- }
54
  }
55
 
56
 
57
- /*
58
  * Attempt on output buffering to protect against headers already send mistakes
59
- */
60
- function iqblockcountry_buffer() {
61
- ob_start();
 
62
  }
63
 
64
- /*
65
  * Attempt on output buffering to protect against headers already send mistakes
66
- */
67
- function iqblockcountry_buffer_flush() {
68
- if (ob_get_contents()) ob_end_flush();
 
 
69
  }
70
 
71
 
72
- /*
73
  * Localization
74
- */
75
  function iqblockcountry_localization()
76
  {
77
- load_plugin_textdomain( 'iq-block-country', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
78
  }
79
 
80
  /*
81
  * Retrieves the IP address from the HTTP Headers
82
  */
83
- function iqblockcountry_get_ipaddress() {
84
- global $ip_address;
85
-
86
- $server_address = "";
87
- if(isset($_SERVER['SERVER_ADDR']))
88
- $server_address = $_SERVER['SERVER_ADDR'];
89
- elseif(array_key_exists('LOCAL_ADDR', $_SERVER))
90
- $server_address = $_SERVER['LOCAL_ADDR'];
 
 
91
 
92
- if ( isset($_SERVER['HTTP_CF_CONNECTING_IP']) && !empty($_SERVER['HTTP_CF_CONNECTING_IP']) ) {
93
- $ip_address = $_SERVER['HTTP_CF_CONNECTING_IP'];
94
  }
95
- elseif ( isset($_SERVER['HTTP_X_REAL_IP']) && !empty($_SERVER['HTTP_X_REAL_IP']) ) {
96
- $ip_address = $_SERVER['HTTP_X_REAL_IP'];
97
  }
98
- elseif ( isset($_SERVER['HTTP_X_SUCURI_CLIENTIP']) && !empty($_SERVER['HTTP_X_SUCURI_CLIENTIP']) ) {
99
- $ip_address = $_SERVER['HTTP_X_SUCURI_CLIENTIP'];
100
  }
101
- elseif ( isset($_SERVER['HTTP_INCAP_CLIENT_IP']) && !empty($_SERVER['HTTP_INCAP_CLIENT_IP']) ) {
102
- $ip_address = $_SERVER['HTTP_INCAP_CLIENT_IP'];
103
  }
104
- elseif ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
105
- $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
106
  }
107
- elseif ( isset($_SERVER['HTTP_X_FORWARDED']) && !empty($_SERVER['HTTP_X_FORWARDED']) ) {
108
- $ip_address = $_SERVER['HTTP_X_FORWARDED'];
109
  }
110
- elseif ( isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP']) ) {
111
- $ip_address = $_SERVER['HTTP_CLIENT_IP'];
112
  }
113
- elseif ( isset($_SERVER['HTTP_FORWARDED']) && !empty($_SERVER['HTTP_FORWARDED']) ) {
114
- $ip_address = $_SERVER['HTTP_FORWARDED'];
115
  }
116
- elseif ( isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['REMOTE_ADDR']) ) {
117
- $ip_address = $_SERVER['REMOTE_ADDR'];
118
  }
119
 
120
- $ipoverride = get_option('blockcountry_ipoverride');
121
- if (isset($ipoverride) && (!empty($ipoverride) && ($ipoverride != "NONE") ))
122
- {
123
- if ( isset($_SERVER[$ipoverride]) && !empty($_SERVER[$ipoverride]))
124
- {
125
- if (iqblockcountry_is_valid_ipv4($_SERVER[$ipoverride]) || iqblockcountry_is_valid_ipv6($_SERVER[$ipoverride]))
126
- {
127
- $ip_address = $_SERVER[$ipoverride];
128
  }
129
  }
130
  }
131
 
132
  // Get first ip if ip_address contains multiple addresses
133
- $ips = explode(',', $ip_address);
134
 
135
- if (iqblockcountry_is_valid_ipv4(trim($ips[0])) || iqblockcountry_is_valid_ipv6(trim($ips[0])))
136
- {
137
- $ip_address = trim($ips[0]);
138
  }
139
- if ($ip_address == $server_address)
140
- {
141
- if ( isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['REMOTE_ADDR']) ) {
142
- $ip_address = $_SERVER['REMOTE_ADDR'];
143
  }
144
  else
145
  {
146
- $ip_address = "0.0.0.0";
147
  }
148
 
149
  }
150
- return $ip_address;
151
  }
152
 
153
 
154
  function iqblockcountry_upgrade()
155
  {
156
  /* Check if update is necessary */
157
- $dbversion = get_option( 'blockcountry_version' );
158
- update_option('blockcountry_version',VERSION);
159
 
160
- if ($dbversion != "" && version_compare($dbversion, "1.2.10", '<') )
161
- {
162
  iqblockcountry_find_geoip_location();
163
- $server_addr = array_key_exists( 'SERVER_ADDR', $_SERVER ) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR'];
164
- if (get_option('blockcountry_backendwhitelist') === FALSE || (get_option('blockcountry_backendwhitelist') == ""))
165
- { update_option('blockcountry_backendwhitelist',$server_addr . ";"); }
 
 
 
 
 
 
166
  else
167
  {
168
- $tmpbackendallowlist = get_option('blockcountry_backendwhitelist');
169
- $ippos = strpos($tmpbackendallowlist,$server_addr);
170
- if ($ippos === false)
171
- {
172
- $tmpbackendallowlist .= $server_addr . ";";
173
- update_option('blockcountry_backendwhitelist',$tmpbackendallowlist);
174
  }
175
  }
176
 
177
  }
178
- elseif ($dbversion != "" && version_compare($dbversion, "1.2.5", '<') )
179
- {
180
- update_option('blockcountry_blockfeed' , 'on');
181
- }
182
- elseif ($dbversion != "" && version_compare($dbversion, "1.2.3", '<') )
183
- {
184
- update_option('blockcountry_ipoverride' , 'NONE');
185
- }
186
- elseif ($dbversion != "" && version_compare($dbversion, "1.1.44", '<') )
187
- {
188
- $server_addr = array_key_exists( 'SERVER_ADDR', $_SERVER ) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR'];
189
- if (get_option('blockcountry_frontendwhitelist') === FALSE || (get_option('blockcountry_frontendwhitelist') == "")) { update_option('blockcountry_frontendwhitelist',$server_addr); } iqblockcountry_install_db();
190
-
191
- }
192
- elseif ($dbversion != "" && version_compare($dbversion, "1.1.41", '<') )
193
- {
194
- update_option('blockcountry_daysstatistics',30);
195
- }
196
- elseif ($dbversion != "" && version_compare($dbversion, "1.1.31", '<') )
197
- {
198
- if (!get_option('blockcountry_blocktag'))
199
- {
200
- update_option('blockcountry_blocktag','on');
201
- }
202
- }
203
- elseif ($dbversion != "" && version_compare($dbversion, "1.1.19", '<') )
204
- {
205
- update_option('blockcountry_blocksearch','on');
206
- }
207
- if ($dbversion != "" && version_compare($dbversion, "1.1.17", '<') )
208
- {
209
- delete_option('blockcountry_automaticupdate');
210
- delete_option('blockcountry_lastupdate');
211
- }
212
- elseif ($dbversion != "" && version_compare($dbversion, "1.1.11", '<') )
213
- {
214
- update_option('blockcountry_nrstatistics', 15);
215
- }
216
- elseif ($dbversion != "" && version_compare($dbversion, "1.0.10", '<') )
217
- {
218
- $frontendbanlist = get_option('blockcountry_banlist');
219
- update_option('blockcountry_backendbanlist',$frontendbanlist);
220
- update_option('blockcountry_backendnrblocks', 0);
221
- update_option('blockcountry_frontendnrblocks', 0);
222
- update_option('blockcountry_header', 'on');
223
- }
224
- elseif ($dbversion != "" && version_compare($dbversion, "1.0.10", '=') )
225
- {
226
- iqblockcountry_install_db();
227
- update_option('blockcountry_backendnrblocks', 0);
228
- update_option('blockcountry_frontendnrblocks', 0);
229
- update_option('blockcountry_header', 'on');
230
- }
231
- elseif ($dbversion == "")
232
- {
233
- iqblockcountry_install_db();
234
- add_option( "blockcountry_dbversion", DBVERSION );
235
- update_option('blockcountry_blockfrontend' , 'on');
236
- update_option('blockcountry_version',VERSION);
237
- update_option('blockcountry_backendnrblocks', 0);
238
- update_option('blockcountry_frontendnrblocks', 0);
239
- update_option('blockcountry_header', 'on');
240
- $frontendbanlist = get_option('blockcountry_banlist');
241
- update_option('blockcountry_backendbanlist',$frontendbanlist);
242
- }
243
-
244
  iqblockcountry_update_db_check();
245
 
246
  }
247
 
248
 
249
- /*
250
  * Main plugin works.
251
- */
252
- $upload_dir = wp_upload_dir();
253
  define("CHOSENJS", plugins_url('/js/chosen.jquery.js', __FILE__));
254
  define("CHOSENCSS", plugins_url('/chosen.css', __FILE__));
255
- define("CHOSENCUSTOM",plugins_url('/js/chosen.custom.js', __FILE__));
256
- define("GEOIP2DB","http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz"); // Used to display download location.
257
- define("MAXMINDURL","https://dev.maxmind.com/geoip/geoip2/geolite2/");
258
- define("IPV4DBFILE",$upload_dir['basedir'] . "/GeoIP.dat");
259
- define("IPV6DBFILE",$upload_dir['basedir'] . "/GeoIPv6.dat");
260
- define("GEOIP2DBFILE",$upload_dir['basedir'] . "/GeoLite2-Country.mmdb");
261
- define("TRACKINGURL","https://tracking.webence.nl/iq-block-country-tracking.php");
262
- define("BANLISTRETRIEVEURL","https://eu.adminblock.webence.nl/iq-block-country-retrieve.php");
263
- define("GEOIPAPIURL","https://eu.geoip.webence.nl/geoipapi.php");
264
- define("GEOIPAPIURLEU2","https://eu2.geoip.webence.nl/geoipapi.php");
265
- define("GEOIPAPIURLEU3","https://eu3.geoip.webence.nl/geoipapi.php");
266
- define("GEOIPAPIURLEU4","https://eu4.geoip.webence.nl/geoipapi.php");
267
- define("GEOIPAPIURLUS","https://us.geoip.webence.nl/geoipapi.php");
268
- define("GEOIPAPIURLUS2","https://us2.geoip.webence.nl/geoipapi.php");
269
- define("GEOIPAPIURLUS3","https://us3.geoip.webence.nl/geoipapi.php");
270
- define("GEOIPAPIURLASIA","https://asia.geoip.webence.nl/geoipapi.php");
271
- define("GEOIPAPICHECKURL","https://eu.geoip.webence.nl/geoipapi-keycheck.php");
272
- define("GEOIPAPICHECKUSAGEURL","https://eu.geoip.webence.nl/geoipapi-usage.php");
273
- define("ADMINAPICHECKURL","https://tracking.webence.nl/adminapi-keycheck.php");
274
- define("IPLOOKUPURL",'https://geoip.webence.nl/iplookup/iplookup.php');
275
- define("VERSION","1.2.10");
276
- define("DBVERSION","122");
277
- define("PLUGINPATH",plugin_dir_path( __FILE__ ));
278
 
279
 
280
 
281
  /*
282
  * Include libraries
283
  */
284
- require_once('libs/blockcountry-geoip.php');
285
- require_once('libs/blockcountry-checks.php');
286
- require_once('libs/blockcountry-settings.php');
287
- require_once('libs/blockcountry-validation.php');
288
- require_once('libs/blockcountry-logging.php');
289
- require_once('libs/blockcountry-tracking.php');
290
- require_once('libs/blockcountry-search-engines.php');
291
- require_once('vendor/autoload.php');
292
-
293
- global $apiblocklist;
294
- $apiblocklist = FALSE;
295
- $backendblocklistcheck = FALSE;
296
 
297
  $blockcountry_is_login_page = iqblockcountry_is_login_page();
298
  $blockcountry_is_xmlrpc = iqblockcountry_is_xmlrpc();
@@ -305,94 +237,91 @@ register_uninstall_hook(__file__, 'iqblockcountry_uninstall');
305
  iqblockcountry_upgrade();
306
 
307
  /* Clean logging database */
308
- iqblockcountry_clean_db();
309
  iqblockcountry_get_blockallowlist();
310
 
311
- if (isset($_POST['action']))
312
- {
313
 
314
- $iqaction = filter_var($_POST['action'],FILTER_SANITIZE_STRING);
315
- if ($iqaction == 'csvoutput') {
316
  if(!function_exists('is_user_logged_in')) {
317
- include(ABSPATH . "wp-includes/pluggable.php");
318
  }
319
 
320
- if (is_user_logged_in() && is_admin() && check_admin_referer( 'iqblockcountrycsv' ))
321
- {
322
- global $wpdb;
323
- $output = "";
324
- $table_name = $wpdb->prefix . "iqblock_logging";
325
- $format = get_option('date_format') . ' ' . get_option('time_format');
326
- foreach ($wpdb->get_results( "SELECT * FROM $table_name ORDER BY datetime ASC" ) as $row)
327
- {
328
- $datetime = strtotime($row->datetime);
329
- $mysqldate = date($format, $datetime);
330
- $output .= '"' . $mysqldate . '"' . ';"' . $row->ipaddress . '";"' . $row->url . '"'. "\n";
 
 
 
 
 
 
 
 
 
 
331
  }
332
- $iqtempvalue = preg_replace("/[^A-Za-z0-9]/", "", get_bloginfo());
333
- $filename = $iqtempvalue . "-iqblockcountry-logging-export.csv";
334
- header("Content-type: text/csv");
335
- header("Content-Disposition: attachment; filename=$filename");
336
- header("Pragma: no-cache");
337
- header("Expires: 0");
338
- echo $output;
339
- exit();
340
- }
341
  }
342
  }
343
 
344
- $ip_address = iqblockcountry_get_ipaddress();
345
- $country = iqblockcountry_check_ipaddress($ip_address);
346
- iqblockcountry_debug_logging($ip_address,$country,'');
347
 
348
 
349
- function iq_add_my_scripts() {
350
- $iqscreen = get_current_screen();
351
- if ( $iqscreen->id == 'settings_page_iq-block-country/libs/blockcountry-settings' ) {
 
352
  // Scripts
353
- wp_enqueue_script( 'chosen', CHOSENJS, array( 'jquery' ), false, true );
354
- wp_enqueue_script( 'custom', CHOSENCUSTOM, array( 'jquery', 'chosen' ), false, true );
 
355
  }
356
  }
357
 
358
- add_action( 'admin_enqueue_scripts', 'iq_add_my_scripts' );
359
 
360
 
361
  /*
362
  * Check first if users want to block the backend.
363
  */
364
- if (($blockcountry_is_login_page || is_admin() || $blockcountry_is_xmlrpc) && get_option('blockcountry_blockbackend') == 'on')
365
- {
366
- add_action ( 'init', 'iqblockcountry_checkCountryBackEnd', 1 );
367
- }
368
- elseif ((!$blockcountry_is_login_page && !is_admin() && !$blockcountry_is_xmlrpc) && get_option('blockcountry_blockfrontend') == 'on')
369
- {
370
- add_action ( 'wp', 'iqblockcountry_checkCountryFrontEnd', 1 );
371
  }
372
- else
373
- {
374
- $ip_address = iqblockcountry_get_ipaddress();
375
- $country = iqblockcountry_check_ipaddress($ip_address);
376
- iqblockcountry_debug_logging($ip_address,$country,'NH');
 
377
 
378
  }
379
 
380
- add_action ( 'admin_init', 'iqblockcountry_localization');
381
- add_action ( 'admin_menu', 'iqblockcountry_create_menu' );
382
- add_filter ( 'update_option_blockcountry_tracking', 'iqblockcountry_schedule_tracking', 10, 2);
383
- add_filter ( 'add_option_blockcountry_tracking', 'iqblockcountry_schedule_tracking', 10, 2);
384
- add_filter ( 'update_option_blockcountry_apikey', 'iqblockcountry_schedule_retrieving', 10, 2);
385
- add_filter ( 'add_option_blockcountry_apikey', 'iqblockcountry_schedule_retrieving', 10, 2);
386
-
387
- add_filter ( 'update_option_blockcountry_debuglogging', 'iqblockcountry_blockcountry_debuglogging', 10, 2);
388
- add_filter ( 'add_option_blockcountry_debuglogging', 'iqblockcountry_blockcountry_debuglogging', 10, 2);
389
- add_action ( 'blockcountry_tracking', 'iqblockcountry_tracking' );
390
- add_action ( 'blockcountry_retrievebanlist', 'iqblockcountry_tracking_retrieve_xml');
391
- if (get_option('blockcountry_buffer') == "on")
392
- {
393
- add_action ( 'init', 'iqblockcountry_buffer',1);
394
- add_action ( 'shutdown', 'iqblockcountry_buffer_flush');
395
  }
396
 
397
 
398
- ?>
1
  <?php
2
  /*
3
  Plugin Name: iQ Block Country
4
+ Plugin URI: https://webence.nl/plugins/iq-block-country-the-wordpress-plugin-that-blocks-countries-for-you/
5
+ Version: 1.2.14
6
  Author: Pascal
7
+ Author URI: https://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.
9
  License: GPL2
10
  Text Domain: iq-block-country
29
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
  */
31
 
32
+ /**
 
33
  * This software is dedicated to my one true love.
34
  * Luvya :)
35
+ **/
 
36
 
37
+ /**
38
  * Try to make this plugin the first plugin that is loaded.
39
  * Because we output header info we don't want other plugins to send output first.
40
+ **/
41
  function iqblockcountry_this_plugin_first()
42
  {
43
+ $iqbc_wp_path_to_this_file = preg_replace('/(.*)plugins\/(.*)$/', WP_PLUGIN_DIR."/$2", __FILE__);
44
+ $iqbc_this_plugin = plugin_basename(trim($iqbc_wp_path_to_this_file));
45
+ $iqbc_active_plugins = get_option('active_plugins');
46
+ $iqbc_this_plugin_key = array_search($iqbc_this_plugin, $iqbc_active_plugins);
47
+ if ($iqbc_this_plugin_key) { // if it's 0 it's the first plugin already, no need to continue
48
+ array_splice($iqbc_active_plugins, $iqbc_this_plugin_key, 1);
49
+ array_unshift($iqbc_active_plugins, $iqbc_this_plugin);
50
+ update_option('active_plugins', $iqbc_active_plugins);
51
+ }
52
  }
53
 
54
 
55
+ /**
56
  * Attempt on output buffering to protect against headers already send mistakes
57
+ **/
58
+ function iqblockcountry_buffer()
59
+ {
60
+ ob_start();
61
  }
62
 
63
+ /**
64
  * Attempt on output buffering to protect against headers already send mistakes
65
+ **/
66
+ function iqblockcountry_buffer_flush()
67
+ {
68
+ if (ob_get_contents()) { ob_end_flush();
69
+ }
70
  }
71
 
72
 
73
+ /**
74
  * Localization
75
+ **/
76
  function iqblockcountry_localization()
77
  {
78
+ load_plugin_textdomain('iq-block-country', false, dirname(plugin_basename(__FILE__)) . '/lang');
79
  }
80
 
81
  /*
82
  * Retrieves the IP address from the HTTP Headers
83
  */
84
+ function iqblockcountry_get_ipaddress()
85
+ {
86
+ global $iqbc_ip_address;
87
+
88
+ $iqbc_server_address = "";
89
+ if(isset($_SERVER['SERVER_ADDR']) && (filter_var($_SERVER['SERVER_ADDR'],FILTER_VALIDATE_IP))) {
90
+ $iqbc_server_address = $_SERVER['SERVER_ADDR'];
91
+ } elseif(array_key_exists('LOCAL_ADDR', $_SERVER) && (filter_var($_SERVER['LOCAL_ADDR'],FILTER_VALIDATE_IP))) {
92
+ $iqbc_server_address = $_SERVER['LOCAL_ADDR'];
93
+ }
94
 
95
+ if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && filter_var($_SERVER['HTTP_CF_CONNECTING_IP'],FILTER_VALIDATE_IP) ) {
96
+ $iqbc_ip_address = $_SERVER['HTTP_CF_CONNECTING_IP'];
97
  }
98
+ elseif (isset($_SERVER['HTTP_X_REAL_IP']) && filter_var($_SERVER['HTTP_X_REAL_IP'],FILTER_VALIDATE_IP) ) {
99
+ $iqbc_ip_address = $_SERVER['HTTP_X_REAL_IP'];
100
  }
101
+ elseif (isset($_SERVER['HTTP_X_SUCURI_CLIENTIP']) && filter_var($_SERVER['HTTP_X_SUCURI_CLIENTIP'],FILTER_VALIDATE_IP) ) {
102
+ $iqbc_ip_address = $_SERVER['HTTP_X_SUCURI_CLIENTIP'];
103
  }
104
+ elseif (isset($_SERVER['HTTP_INCAP_CLIENT_IP']) && filter_var($_SERVER['HTTP_INCAP_CLIENT_IP'],FILTER_VALIDATE_IP) ) {
105
+ $iqbc_ip_address = $_SERVER['HTTP_INCAP_CLIENT_IP'];
106
  }
107
+ elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && filter_var($_SERVER['HTTP_X_FORWARDED_FOR'],FILTER_VALIDATE_IP)) {
108
+ $iqbc_ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
109
  }
110
+ elseif (isset($_SERVER['HTTP_X_FORWARDED']) && filter_var($_SERVER['HTTP_X_FORWARDED'],FILTER_VALIDATE_IP)) {
111
+ $iqbc_ip_address = $_SERVER['HTTP_X_FORWARDED'];
112
  }
113
+ elseif (isset($_SERVER['HTTP_CLIENT_IP']) && filter_var($_SERVER['HTTP_CLIENT_IP'],FILTER_VALIDATE_IP) ) {
114
+ $iqbc_ip_address = $_SERVER['HTTP_CLIENT_IP'];
115
  }
116
+ elseif (isset($_SERVER['HTTP_FORWARDED']) && filter_var($_SERVER['HTTP_FORWARDED'],FILTER_VALIDATE_IP)) {
117
+ $iqbc_ip_address = $_SERVER['HTTP_FORWARDED'];
118
  }
119
+ elseif (isset($_SERVER['REMOTE_ADDR']) && filter_var($_SERVER['REMOTE_ADDR'],FILTER_VALIDATE_IP) ) {
120
+ $iqbc_ip_address = $_SERVER['REMOTE_ADDR'];
121
  }
122
 
123
+ $iqbc_ipoverride = get_option('blockcountry_ipoverride');
124
+ if (isset($iqbc_ipoverride) && (!empty($iqbc_ipoverride) && ($iqbc_ipoverride != "NONE") )) {
125
+ if (isset($_SERVER[$iqbc_ipoverride]) && !empty($_SERVER[$iqbc_ipoverride])) {
126
+ if (iqblockcountry_is_valid_ipv4($_SERVER[$iqbc_ipoverride]) || iqblockcountry_is_valid_ipv6($_SERVER[$iqbc_ipoverride])) {
127
+ $iqbc_ip_address = $_SERVER[$iqbc_ipoverride];
 
 
 
128
  }
129
  }
130
  }
131
 
132
  // Get first ip if ip_address contains multiple addresses
133
+ $iqbc_ips = explode(',', $iqbc_ip_address);
134
 
135
+ if (iqblockcountry_is_valid_ipv4(trim($iqbc_ips[0])) || iqblockcountry_is_valid_ipv6(trim($iqbc_ips[0]))) {
136
+ $iqbc_ip_address = trim($iqbc_ips[0]);
 
137
  }
138
+ if ($iqbc_ip_address == $iqbc_server_address) {
139
+ if (isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['REMOTE_ADDR']) && filter_var($_SERVER['REMOTE_ADDR'],FILTER_VALIDATE_IP) ) {
140
+ $iqbc_ip_address = $_SERVER['REMOTE_ADDR'];
 
141
  }
142
  else
143
  {
144
+ $iqbc_ip_address = "0.0.0.0";
145
  }
146
 
147
  }
148
+ return $iqbc_ip_address;
149
  }
150
 
151
 
152
  function iqblockcountry_upgrade()
153
  {
154
  /* Check if update is necessary */
155
+ $iqbc_dbversion = get_option('blockcountry_version');
156
+ update_option('blockcountry_version', IQDBVERSION);
157
 
158
+ if ($iqbc_dbversion != "" && version_compare($iqbc_dbversion, "1.2.10", '<') ) {
 
159
  iqblockcountry_find_geoip_location();
160
+ $iqbc_server_addr = "";
161
+ if(isset($_SERVER['SERVER_ADDR']) && (filter_var($_SERVER['SERVER_ADDR'],FILTER_VALIDATE_IP))) {
162
+ $iqbc_server_addr = $_SERVER['SERVER_ADDR'];
163
+ } elseif(array_key_exists('LOCAL_ADDR', $_SERVER) && (filter_var($_SERVER['LOCAL_ADDR'],FILTER_VALIDATE_IP))) {
164
+ $iqbc_server_addr = $_SERVER['LOCAL_ADDR'];
165
+ }
166
+
167
+ if (get_option('blockcountry_backendwhitelist') === false || (get_option('blockcountry_backendwhitelist') == "")) { update_option('blockcountry_backendwhitelist', $iqbc_server_addr . ";");
168
+ }
169
  else
170
  {
171
+ $iqbc_tmpbackendallowlist = get_option('blockcountry_backendwhitelist');
172
+ $iqbc_ippos = strpos($iqbc_tmpbackendallowlist, $iqbc_server_addr);
173
+ if ($iqbc_ippos === false) {
174
+ $iqbc_tmpbackendallowlist .= $iqbc_server_addr . ";";
175
+ update_option('blockcountry_backendwhitelist', $iqbc_tmpbackendallowlist);
 
176
  }
177
  }
178
 
179
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  iqblockcountry_update_db_check();
181
 
182
  }
183
 
184
 
185
+ /**
186
  * Main plugin works.
187
+ **/
188
+ $iqbc_upload_dir = wp_upload_dir();
189
  define("CHOSENJS", plugins_url('/js/chosen.jquery.js', __FILE__));
190
  define("CHOSENCSS", plugins_url('/chosen.css', __FILE__));
191
+ define("CHOSENCUSTOM", plugins_url('/js/chosen.custom.js', __FILE__));
192
+ define("IQBCMAXMINDURL", "https://dev.maxmind.com/geoip/geoip2/geolite2/");
193
+ define("IQBCGEOIP2DBFILE", $iqbc_upload_dir['basedir'] . "/GeoLite2-Country.mmdb");
194
+ define("IQBCTRACKINGURL", "https://tracking.webence.nl/iq-block-country-tracking.php");
195
+ define("IQBCBANLISTRETRIEVEURL", "https://eu.adminblock.webence.nl/iq-block-country-retrieve.php");
196
+ define("GEOIPAPIURL", "https://eu.geoip.webence.nl/geoipapi.php");
197
+ define("GEOIPAPIURLEU2", "https://eu2.geoip.webence.nl/geoipapi.php");
198
+ define("GEOIPAPIURLEU3", "https://eu3.geoip.webence.nl/geoipapi.php");
199
+ define("GEOIPAPIURLEU4", "https://eu4.geoip.webence.nl/geoipapi.php");
200
+ define("GEOIPAPIURLUS", "https://us.geoip.webence.nl/geoipapi.php");
201
+ define("GEOIPAPIURLUS2", "https://us2.geoip.webence.nl/geoipapi.php");
202
+ define("GEOIPAPIURLUS3", "https://us3.geoip.webence.nl/geoipapi.php");
203
+ define("GEOIPAPIURLASIA", "https://asia.geoip.webence.nl/geoipapi.php");
204
+ define("GEOIPAPICHECKURL", "https://eu.geoip.webence.nl/geoipapi-keycheck.php");
205
+ define("GEOIPAPICHECKUSAGEURL", "https://eu.geoip.webence.nl/geoipapi-usage.php");
206
+ define("ADMINAPICHECKURL", "https://tracking.webence.nl/adminapi-keycheck.php");
207
+ define("IQDBVERSION", "1.2.15");
208
+ define("IQDBDBVERSION", "122");
209
+ define("IQBCPLUGINPATH", plugin_dir_path(__FILE__));
 
 
 
 
210
 
211
 
212
 
213
  /*
214
  * Include libraries
215
  */
216
+ require_once 'libs/blockcountry-geoip.php';
217
+ require_once 'libs/blockcountry-checks.php';
218
+ require_once 'libs/blockcountry-settings.php';
219
+ require_once 'libs/blockcountry-validation.php';
220
+ require_once 'libs/blockcountry-logging.php';
221
+ require_once 'libs/blockcountry-tracking.php';
222
+ require_once 'libs/blockcountry-search-engines.php';
223
+ require_once dirname(__FILE__) . '/vendor/autoload.php';
224
+
225
+ global $iqbc_apiblocklist;
226
+ $iqbc_apiblocklist = false;
227
+ $iqbc_backendblocklistcheck = false;
228
 
229
  $blockcountry_is_login_page = iqblockcountry_is_login_page();
230
  $blockcountry_is_xmlrpc = iqblockcountry_is_xmlrpc();
237
  iqblockcountry_upgrade();
238
 
239
  /* Clean logging database */
240
+ iqblockcountry_clean_db();
241
  iqblockcountry_get_blockallowlist();
242
 
243
+ if (isset($_POST['iqbc_action'])) {
 
244
 
245
+ $iqbc_iqaction = filter_var($_POST['iqbc_action'], FILTER_SANITIZE_STRING);
246
+ if ($iqbc_iqaction == 'iqbc_csvoutput') {
247
  if(!function_exists('is_user_logged_in')) {
248
+ include ABSPATH . "wp-includes/pluggable.php";
249
  }
250
 
251
+ if (is_user_logged_in() && is_admin() && check_admin_referer('iqbc_iqblockcountrycsv')) {
252
+ global $wpdb;
253
+ $iqbc_output = "";
254
+ $iqbc_table_name = $wpdb->prefix . "iqblock_logging";
255
+ $iqbc_format = get_option('date_format') . ' ' . get_option('time_format');
256
+ $iqbc_sql = "DELETE FROM " . $iqbc_table_name . " WHERE `datetime` < DATE_SUB(NOW(), INTERVAL 14 DAY);";
257
+
258
+ foreach ($wpdb->get_results("SELECT * FROM $iqbc_table_name ORDER BY datetime ASC") as $iqbc_row)
259
+ {
260
+ $iqbc_datetime = strtotime($iqbc_row->datetime);
261
+ $iqbc_mysqldate = date($iqbc_format, $iqbc_datetime);
262
+ $iqbc_output .= '"' . $iqbc_mysqldate . '"' . ';"' . $iqbc_row->ipaddress . '";"' . $iqbc_row->url . '"'. "\n";
263
+ }
264
+ $iqbc_iqtempvalue = preg_replace("/[^A-Za-z0-9]/", "", get_bloginfo());
265
+ $iqbc_filename = $iqbc_iqtempvalue . "-iqblockcountry-logging-export.csv";
266
+ header("Content-type: text/csv");
267
+ header("Content-Disposition: attachment; filename=$iqbc_filename");
268
+ header("Pragma: no-cache");
269
+ header("Expires: 0");
270
+ echo $iqbc_output;
271
+ exit();
272
  }
 
 
 
 
 
 
 
 
 
273
  }
274
  }
275
 
276
+ $iqbc_ip_address = iqblockcountry_get_ipaddress();
277
+ $iqbc_country = iqblockcountry_check_ipaddress($iqbc_ip_address);
278
+ iqblockcountry_debug_logging($iqbc_ip_address, $iqbc_country, '');
279
 
280
 
281
+ function iqbc_add_my_scripts()
282
+ {
283
+ $iqbc_iqscreen = get_current_screen();
284
+ if ($iqbc_iqscreen->id == 'settings_page_iq-block-country/libs/blockcountry-settings' ) {
285
  // Scripts
286
+ wp_enqueue_script('chosen', CHOSENJS, array( 'jquery' ), false, true);
287
+ wp_enqueue_script('custom', CHOSENCUSTOM, array( 'jquery', 'chosen' ), false, true);
288
+ wp_enqueue_style( 'chosenstylecss', CHOSENCSS );
289
  }
290
  }
291
 
292
+ add_action('admin_enqueue_scripts', 'iqbc_add_my_scripts');
293
 
294
 
295
  /*
296
  * Check first if users want to block the backend.
297
  */
298
+ if (($blockcountry_is_login_page || is_admin() || $blockcountry_is_xmlrpc) && get_option('blockcountry_blockbackend') == 'on') {
299
+ add_action('init', 'iqblockcountry_checkCountryBackEnd', 1);
 
 
 
 
 
300
  }
301
+ elseif ((!$blockcountry_is_login_page && !is_admin() && !$blockcountry_is_xmlrpc) && get_option('blockcountry_blockfrontend') == 'on') {
302
+ add_action('wp', 'iqblockcountry_checkCountryFrontEnd', 1);
303
+ } else {
304
+ $iqbc_ip_address = iqblockcountry_get_ipaddress();
305
+ $iqbc_country = iqblockcountry_check_ipaddress($iqbc_ip_address);
306
+ iqblockcountry_debug_logging($iqbc_ip_address, $iqbc_country, 'NH');
307
 
308
  }
309
 
310
+ add_action('admin_init', 'iqblockcountry_localization');
311
+ add_action('admin_menu', 'iqblockcountry_create_menu');
312
+ add_filter('update_option_blockcountry_tracking', 'iqblockcountry_schedule_tracking', 10, 2);
313
+ add_filter('add_option_blockcountry_tracking', 'iqblockcountry_schedule_tracking', 10, 2);
314
+ add_filter('update_option_blockcountry_apikey', 'iqblockcountry_schedule_retrieving', 10, 2);
315
+ add_filter('add_option_blockcountry_apikey', 'iqblockcountry_schedule_retrieving', 10, 2);
316
+
317
+ add_filter('update_option_blockcountry_debuglogging', 'iqblockcountry_blockcountry_debuglogging', 10, 2);
318
+ add_filter('add_option_blockcountry_debuglogging', 'iqblockcountry_blockcountry_debuglogging', 10, 2);
319
+ add_action('blockcountry_tracking', 'iqblockcountry_tracking');
320
+ add_action('blockcountry_retrievebanlist', 'iqblockcountry_tracking_retrieve_xml');
321
+ if (get_option('blockcountry_buffer') == "on") {
322
+ add_action('init', 'iqblockcountry_buffer', 1);
323
+ add_action('shutdown', 'iqblockcountry_buffer_flush');
 
324
  }
325
 
326
 
327
+ ?>
libs/blockcountry-checks.php CHANGED
@@ -1,378 +1,328 @@
1
  <?php
2
 
3
 
4
- function iqblockcountry_check_ipaddress($ip_address)
5
  {
6
- if (!class_exists('GeoIP'))
7
- {
8
- include_once("geoip.inc");
9
  }
10
 
11
- if (get_option('blockcountry_geoapikey'))
12
- {
13
- $country = iqblockcountry_retrieve_geoipapi($ip_address);
14
- }
15
- elseif ((is_file ( GEOIP2DBFILE)))
16
- {
17
- if (iqblockcountry_is_valid_ipv4($ip_address) || iqblockcountry_is_valid_ipv6($ip_address))
18
- {
19
- if (class_exists('GeoIp2\\Database\\Reader'))
20
- {
21
- try {
22
- $blockreader = new GeoIp2\Database\Reader( GEOIP2DBFILE );
23
- $blockrecord = $blockreader->country($ip_address);
24
- $country = $blockrecord->country->isoCode;
25
- }
26
- catch(Exception $e) {
27
- $country = "FALSE";
28
- }
29
  }
30
  }
31
 
32
  }
33
- elseif ((is_file ( IPV4DBFILE )) && function_exists('geoip_open'))
34
- {
35
-
36
- $ipv4 = FALSE;
37
- $ipv6 = FALSE;
38
- if (iqblockcountry_is_valid_ipv4($ip_address)) { $ipv4 = TRUE; }
39
- if (iqblockcountry_is_valid_ipv6($ip_address)) { $ipv6 = TRUE; }
40
-
41
- if ($ipv4)
42
- {
43
- $gi = geoip_open ( IPV4DBFILE, GEOIP_STANDARD );
44
- $country = geoip_country_code_by_addr ( $gi, $ip_address );
45
- geoip_close ( $gi );
46
- }
47
- elseif ($ipv6)
48
- {
49
- if (is_file ( IPV6DBFILE )) {
50
- $gi = geoip_open(IPV6DBFILE,GEOIP_STANDARD);
51
- $country = geoip_country_code_by_addr_v6 ( $gi, $ip_address );
52
- geoip_close($gi);
53
- }
54
- else {
55
- $country = 'ipv6';
56
- }
57
- }
58
- else { $country = "Unknown"; }
59
- }
60
- else { $country = "Unknown"; }
61
 
62
- if (empty($country) || $country == null )
63
- {
64
- $country = "Unknown";
65
  }
66
 
67
- return $country;
68
  }
69
 
70
  /*
71
  * iQ Block Retrieve XML file for API blocking
72
  */
73
- function iqblockcountry_retrieve_geoipapi($ipaddress)
74
  {
75
- if (iqblockcountry_is_valid_ipv4($ipaddress) || iqblockcountry_is_valid_ipv6($ipaddress))
76
- {
77
 
78
- $url = GEOIPAPIURL;
79
- if (get_option('blockcountry_geoapilocation') == "US")
80
- {
81
- $url = GEOIPAPIURLUS;
82
- }
83
- if (get_option('blockcountry_geoapilocation') == "US2")
84
- {
85
- $url = GEOIPAPIURLUS2;
86
- }
87
- if (get_option('blockcountry_geoapilocation') == "US3")
88
- {
89
- $url = GEOIPAPIURLUS3;
90
- }
91
- if (get_option('blockcountry_geoapilocation') == "EU2")
92
- {
93
- $url = GEOIPAPIURLEU2;
94
- }
95
- if (get_option('blockcountry_geoapilocation') == "EU3")
96
- {
97
- $url = GEOIPAPIURLEU3;
98
- }
99
- if (get_option('blockcountry_geoapilocation') == "EU4")
100
- {
101
- $url = GEOIPAPIURLEU4;
102
- }
103
- if (get_option('blockcountry_geoapilocation') == "ASIA")
104
- {
105
- $url = GEOIPAPIURLASIA;
106
- }
107
 
108
- $result = wp_remote_post(
109
- $url,
110
  array(
111
  'body' => array(
112
  'api-key' => get_option('blockcountry_geoapikey'),
113
- 'ipaddress' => $ipaddress
114
 
115
  )
116
  )
117
  );
118
- if ( is_wp_error( $result ) ) {
119
- return "Unknown";
120
- }
121
- elseif ( 200 == $result['response']['code'] ) {
122
- $body = $result['body'];
123
- $xml = new SimpleXmlElement($body);
124
- if (isset($xml->country)) { return (string) $xml->country; }
125
- elseif (isset($xml->error))
126
- {
127
- if (strpos($xml->error, 'License expired on ') !== false) {
128
- update_option('blockcountry_geoapikey','');
129
- return "Expired";
130
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  }
132
- else { return "Unknown"; }
133
  }
134
- elseif ( 403 == $result['response']['code'] ) {
135
- update_option('blockcountry_geoapikey','');
136
  }
137
- else return "Unknown";
138
- }
139
- else
140
- { return "Invalid"; }
141
  }
142
 
143
 
144
 
145
- /*
146
  * Check country against bad countries, allow list and block list
147
- */
148
- function iqblockcountry_check($country,$badcountries,$ip_address)
149
  {
150
  /* Set default blocked status and get all options */
151
- $blocked = FALSE;
152
- $blockedpage = get_option('blockcountry_blockpages');
153
- //$blockedpages = get_option('blockcountry_pages');
154
- $pagesbanlist = get_option( 'blockcountry_pages' );
155
- if (!is_array($pagesbanlist)) { $pagesbanlist = array(); }
156
- if (get_option( 'blockcountry_blockpages_inverse' ) == 'on') {
157
- $pages = get_pages();
158
- $all_pages = array();
159
- foreach ( $pages as $page ) {
160
- $all_pages[$page->ID] = $page->ID;
161
- }
162
- $blockedpages = array_diff($all_pages, $pagesbanlist);
163
- } else {
164
- $blockedpages = $pagesbanlist;
165
  }
 
 
 
 
166
 
167
- $blockedcategory = get_option('blockcountry_blockcategories');
168
- $blocktags = get_option('blockcountry_blocktags');
169
- $blockedposttypes = get_option('blockcountry_blockposttypes');
170
- $blockedtag = get_option('blockcountry_blocktag');
171
- $blockedfeed = get_option('blockcountry_blockfeed');
172
- $postid = get_the_ID();
173
 
174
- global $feblocklistip,$feblocklistiprange4,$feblocklistiprange6,$feallowlistip,$feallowlistiprange4,$feallowlistiprange6;
175
- global $beblocklistip,$beblocklistiprange4,$beblocklistiprange6,$beallowlistip,$beallowlistiprange4,$beallowlistiprange6;
176
 
177
- $backendbanlistip = unserialize(get_option('blockcountry_backendbanlistip'));
178
- $blockredirect = get_option ( 'blockcountry_redirect');
179
 
180
  /* Block if user is in a bad country from frontend or backend. Unblock may happen later */
181
- if (is_array ( $badcountries ) && in_array ( $country, $badcountries )) {
182
- $blocked = TRUE;
183
- global $backendblocklistcheck;
184
- $backendblocklistcheck = TRUE;
185
  }
186
 
187
  global $blockcountry_is_login_page,$blockcountry_is_xmlrpc;
188
 
189
 
190
  /* Check if requested url is not login page. Else check against frontend allow list / block list. */
191
- if (!($blockcountry_is_login_page) && !(is_admin()) && !($blockcountry_is_xmlrpc))
192
- {
193
- if (iqblockcountry_validate_ip_in_list($ip_address,$feblocklistiprange4,$feblocklistiprange6,$feblocklistip))
194
- {
195
- $blocked = TRUE;
196
- }
197
- if (iqblockcountry_validate_ip_in_list($ip_address,$feallowlistiprange4,$feallowlistiprange6,$feallowlistip))
198
- {
199
- $blocked = FALSE;
200
- }
201
  }
202
 
203
 
204
- if ($blockcountry_is_login_page || is_admin() || $blockcountry_is_xmlrpc)
205
- {
206
- if (is_array($backendbanlistip) && in_array($ip_address,$backendbanlistip))
207
- {
208
- $blocked = TRUE;
209
- global $apiblocklist;
210
- $apiblocklist = TRUE;
211
  }
212
- if (iqblockcountry_validate_ip_in_list($ip_address,$beblocklistiprange4,$beblocklistiprange6,$beblocklistip)) {
213
- $blocked = TRUE;
214
- }
215
- if (iqblockcountry_validate_ip_in_list($ip_address,$beallowlistiprange4,$beallowlistiprange6,$beallowlistip)) {
216
- $blocked = FALSE;
217
- }
218
- if (iqblockcountry_is_adminajax() && get_option('blockcountry_adminajax'))
219
- {
220
- $blocked = FALSE;
221
  }
222
  }
223
 
224
- if ($blockedposttypes == "on")
225
- {
226
- $blockedposttypes = get_option('blockcountry_posttypes');
227
- if (is_array($blockedposttypes) && in_array(get_post_type( $postid ), $blockedposttypes) && ((is_array ( $badcountries ) && in_array ( $country, $badcountries ) || (iqblockcountry_validate_ip_in_list($ip_address,$feblocklistiprange4,$feblocklistiprange6,$feblocklistip)))))
228
- {
229
- $blocked = TRUE;
230
- if (iqblockcountry_validate_ip_in_list($ip_address,$feallowlistiprange4,$feallowlistiprange6,$feallowlistip)) {
231
- $blocked = FALSE;
232
  }
233
  }
234
  else
235
  {
236
- $blocked = FALSE;
237
  }
238
  }
239
 
240
- if (is_page() && $blockedpage == "on")
241
- {
242
- $post = get_post();
243
- if (is_page($blockedpages) && !empty($blockedpages) && ((is_array ( $badcountries ) && in_array ( $country, $badcountries ) || (iqblockcountry_validate_ip_in_list($ip_address,$feblocklistiprange4,$feblocklistiprange6,$feblocklistip)))))
244
- {
245
- $blocked = TRUE;
246
- if (iqblockcountry_validate_ip_in_list($ip_address,$feallowlistiprange4,$feallowlistiprange6,$feallowlistip)) {
247
- $blocked = FALSE;
248
  }
249
  }
250
  else
251
  {
252
- $blocked = FALSE;
253
  }
254
  }
255
- if (is_single() && $blockedcategory == "on")
256
- {
257
- $blockedcategories = get_option('blockcountry_categories');
258
- if (!is_array($blockedcategories)) { $blockedcategories = array(); }
259
- $post_categories = wp_get_post_categories( $postid );
260
- $flagged = FALSE;
261
- foreach ($post_categories as $key => $value)
262
  {
263
- if (in_array($value,$blockedcategories))
264
- {
265
- if (is_single() && ((is_array ( $badcountries ) && in_array ( $country, $badcountries ) || (iqblockcountry_validate_ip_in_list($ip_address,$feblocklistiprange4,$feblocklistiprange6,$feblocklistip)))))
266
- {
267
- $flagged = TRUE;
268
- if (iqblockcountry_validate_ip_in_list($ip_address,$feallowlistiprange4,$feallowlistiprange6,$feallowlistip)) {
269
- $flagged = FALSE;
270
  }
271
  }
272
  }
273
  }
274
- if ($flagged) { $blocked = TRUE; } else { $blocked = FALSE; }
 
 
275
  }
276
 
277
- if (is_single() && $blocktags == "on")
278
- {
279
- $previousblock = $blocked;
280
- $blockedtags = get_option('blockcountry_tags');
281
- if (!is_array($blockedtags)) { $blockedtags = array(); }
282
- $post_tags = get_the_tags($postid);
283
- if (empty($post_tags)) { $post_tags = array();}
284
- $flagged = FALSE;
285
- foreach ($post_tags as $tag)
 
286
  {
287
- if (in_array($tag->term_id,$blockedtags))
288
- {
289
- if (is_single() && ((is_array ( $badcountries ) && in_array ( $country, $badcountries ) || (iqblockcountry_validate_ip_in_list($ip_address,$feblocklistiprange4,$feblocklistiprange6,$feblocklistip)))))
290
- {
291
- $flagged = TRUE;
292
- if (iqblockcountry_validate_ip_in_list($ip_address,$feallowlistiprange4,$feallowlistiprange6,$feallowlistip)) {
293
 
294
- $flagged = FALSE;
295
  }
296
  }
297
  }
298
  }
299
- if ($flagged || $previousblock == TRUE) { $blocked = TRUE; } else { $blocked = FALSE; }
 
 
300
  }
301
 
302
 
303
- if (is_category() && $blockedcategory == "on")
304
- {
305
- $flagged = FALSE;
306
- $blockedcategories = get_option('blockcountry_categories');
307
- if (is_category($blockedcategories) && ((is_array ( $badcountries ) && in_array ( $country, $badcountries ) || (iqblockcountry_validate_ip_in_list($ip_address,$feblocklistiprange4,$feblocklistiprange6,$feblocklistip)))))
308
- {
309
- $flagged = TRUE;
310
  }
311
- if (iqblockcountry_validate_ip_in_list($ip_address,$feallowlistiprange4,$feallowlistiprange6,$feallowlistip)) {
312
 
313
- $flagged = FALSE;
 
 
 
314
  }
315
- if ($flagged) { $blocked = TRUE; } else { $blocked = FALSE; }
316
  }
317
 
318
 
319
- if (is_tag() && $blockedtag == "on")
320
- {
321
- $flagged = FALSE;
322
- if ((is_array ( $badcountries ) && in_array ( $country, $badcountries ) || (iqblockcountry_validate_ip_in_list($ip_address,$feblocklistiprange4,$feblocklistiprange6,$feblocklistip))))
323
- {
324
- $flagged = TRUE;
325
  }
326
- if (iqblockcountry_validate_ip_in_list($ip_address,$feallowlistiprange4,$feallowlistiprange6,$feallowlistip)) {
327
 
328
- $flagged = FALSE;
 
 
 
329
  }
330
- if ($flagged) { $blocked = TRUE; } else { $blocked = FALSE; }
331
  }
332
- elseif (is_tag() && $blockedtag == FALSE)
333
- {
334
- $blocked = FALSE;
335
  }
336
 
337
- if (is_feed() && $blockedfeed == "on")
338
- {
339
- $flagged = FALSE;
340
- if ((is_array ( $badcountries ) && in_array ( $country, $badcountries ) || (iqblockcountry_validate_ip_in_list($ip_address,$feblocklistiprange4,$feblocklistiprange6,$feblocklistip))))
341
- {
342
- $flagged = TRUE;
343
  }
344
- if (iqblockcountry_validate_ip_in_list($ip_address,$feallowlistiprange4,$feallowlistiprange6,$feallowlistip)) {
345
 
346
- $flagged = FALSE;
 
 
 
347
  }
348
- if ($flagged) { $blocked = TRUE; } else { $blocked = FALSE; }
349
  }
350
- elseif (is_feed() && $blockedfeed == FALSE)
351
- {
352
- $blocked = FALSE;
353
  }
354
 
355
- if (is_home() && (get_option('blockcountry_blockhome')) == FALSE && $blockedcategory == "on")
356
- {
357
- $blocked = FALSE;
358
  }
359
- if (is_page($blockredirect) && ($blockredirect != 0) && !(empty($blockredirect)))
360
- {
361
- $blocked = FALSE;
362
  }
363
 
364
- $allowse = get_option('blockcountry_allowse');
365
- if (!$blockcountry_is_login_page && isset ($_SERVER['HTTP_USER_AGENT']) && iqblockcountry_check_searchengine($_SERVER['HTTP_USER_AGENT'], $allowse))
366
- {
367
- $blocked = FALSE;
368
  }
369
 
370
- if (is_search() && (get_option('blockcountry_blocksearch')) == FALSE)
371
- {
372
- $blocked = FALSE;
373
  }
374
 
375
- return $blocked;
376
  }
377
 
378
  /*
@@ -380,105 +330,99 @@ function iqblockcountry_check($country,$badcountries,$ip_address)
380
  * Does the real check of visitor IP against MaxMind database or the GeoAPI
381
  *
382
  */
383
- function iqblockcountry_CheckCountryBackEnd() {
384
- $ip_address = iqblockcountry_get_ipaddress();
385
- $country = iqblockcountry_check_ipaddress($ip_address);
 
386
  global $blockcountry_is_login_page,$blockcountry_is_xmlrpc;
387
- if (($blockcountry_is_login_page || is_admin() || $blockcountry_is_xmlrpc) && get_option('blockcountry_blockbackend') == 'on')
388
- {
389
- $banlist = get_option( 'blockcountry_backendbanlist' );
390
- if (!is_array($banlist)) { $banlist = array(); }
391
- if (get_option( 'blockcountry_backendbanlist_inverse' ) == 'on') {
392
- $all_countries = array_keys(iqblockcountry_get_isocountries());
393
- $badcountries = array_diff($all_countries, $banlist);
394
  } else {
395
- $badcountries = $banlist;
396
  }
397
  }
398
 
399
- $blocklogin = get_option ( 'blockcountry_blocklogin' );
400
- if ( ((is_user_logged_in()) && ($blocklogin != "on")) || (!(is_user_logged_in())) ) {
401
 
402
  /* Check ip address against banlist, allow list and block list */
403
- if (iqblockcountry_check($country,$badcountries,$ip_address))
404
- {
405
- if (($blockcountry_is_login_page || is_admin() || $blockcountry_is_xmlrpc) && get_option('blockcountry_blockbackend') == 'on')
406
- {
407
- $blocked = get_option('blockcountry_backendnrblocks');
408
- if (empty($blocked)) { $blocked = 0; }
409
- $blocked++;
410
- update_option('blockcountry_backendnrblocks', $blocked);
411
- global $apiblocklist,$backendblocklistcheck,$debughandled;
412
- if (!get_option('blockcountry_logging'))
 
 
 
 
 
 
 
 
413
  {
414
- if (!$apiblocklist)
415
- {
416
- iqblockcountry_logging($ip_address, $country, "B");
417
- iqblockcountry_debug_logging($ip_address,$country,'BB');
418
- }
419
- elseif ($backendblocklistcheck && $apiblocklist)
420
- {
421
- iqblockcountry_logging($ip_address, $country, "T");
422
- iqblockcountry_debug_logging($ip_address,$country,'TB');
423
- }
424
- else
425
- {
426
- iqblockcountry_logging($ip_address, $country, "A");
427
- iqblockcountry_debug_logging($ip_address,$country,'AB');
428
- }
429
  }
430
  }
431
- else
 
432
  {
433
- $blocked = get_option('blockcountry_frontendnrblocks');
434
- if (empty($blocked)) { $blocked = 0; }
435
- $blocked++;
436
- update_option('blockcountry_frontendnrblocks', $blocked);
437
- if (!get_option('blockcountry_logging'))
438
- {
439
- iqblockcountry_logging($ip_address, $country, "F");
440
- iqblockcountry_debug_logging($ip_address,$country,'FB');
441
- }
442
  }
 
443
 
444
 
445
- $blockmessage = get_option ( 'blockcountry_blockmessage' );
446
- $blockredirect = get_option ( 'blockcountry_redirect');
447
- $blockredirect_url = get_option ( 'blockcountry_redirect_url');
448
- $header = get_option('blockcountry_header');
449
- if (!empty($header) && ($header))
450
- {
451
- // Prevent as much as possible that this error message is cached:
452
- header("Cache-Control: no-store, no-cache, must-revalidate");
453
- header("Cache-Control: post-check=0, pre-check=0", false);
454
- header("Pragma: no-cache");
455
- header("Expires: Sat, 26 Jul 2012 05:00:00 GMT");
456
 
457
- header ( 'HTTP/1.1 403 Forbidden' );
458
- }
459
- if (!empty($blockredirect_url))
460
- {
461
- header("Location: $blockredirect_url");
462
- }
463
- elseif (!empty($blockredirect) && $blockredirect != 0)
464
- {
465
- $redirecturl = get_permalink($blockredirect);
466
- header("Location: $redirecturl");
467
- }
468
  // Display block message
469
- print "$blockmessage";
470
 
471
 
472
- exit ();
473
- }
474
  else
475
  {
476
- iqblockcountry_debug_logging($ip_address,$country,'NB');
477
  }
478
  }
479
  else
480
  {
481
- iqblockcountry_debug_logging($ip_address,$country,'NB');
482
  }
483
  }
484
 
@@ -487,177 +431,188 @@ function iqblockcountry_CheckCountryBackEnd() {
487
  * Does the real check of visitor IP against MaxMind database or the GeoAPI FrontEnd
488
  *
489
  */
490
- function iqblockcountry_CheckCountryFrontEnd() {
491
- $ip_address = iqblockcountry_get_ipaddress();
492
- $country = iqblockcountry_check_ipaddress($ip_address);
493
- $banlist = get_option( 'blockcountry_banlist' );
494
- if (!is_array($banlist)) { $banlist = array(); }
495
- if (get_option( 'blockcountry_banlist_inverse' ) == 'on') {
496
- $all_countries = array_keys(iqblockcountry_get_isocountries());
497
- $badcountries = array_diff($all_countries, $banlist);
498
- } else {
499
- $badcountries = $banlist;
500
- }
 
 
501
 
502
- $blocklogin = get_option ( 'blockcountry_blocklogin' );
503
- if ( ((is_user_logged_in()) && ($blocklogin != "on")) || (!(is_user_logged_in())) ) {
504
 
505
  /* Check ip address against banlist, allow list and block list */
506
- if (iqblockcountry_check($country,$badcountries,$ip_address))
507
- {
508
- $blocked = get_option('blockcountry_frontendnrblocks');
509
- if (empty($blocked)) { $blocked = 0; }
510
- $blocked++;
511
- update_option('blockcountry_frontendnrblocks', $blocked);
512
- if (!get_option('blockcountry_logging'))
513
- {
514
- iqblockcountry_logging($ip_address, $country, "F");
515
- iqblockcountry_debug_logging($ip_address,$country,'FB');
516
- }
517
 
518
 
519
- $blockmessage = get_option ( 'blockcountry_blockmessage' );
520
- $blockredirect = get_option ( 'blockcountry_redirect');
521
- $blockredirect_url = get_option ( 'blockcountry_redirect_url');
522
- $header = get_option('blockcountry_header');
523
- if (!empty($header) && ($header))
524
- {
525
- // Prevent as much as possible that this error message is cached:
526
- header("Cache-Control: no-store, no-cache, must-revalidate");
527
- header("Cache-Control: post-check=0, pre-check=0", false);
528
- header("Pragma: no-cache");
529
- header("Expires: Sat, 26 Jul 2012 05:00:00 GMT");
530
 
531
- header ( 'HTTP/1.1 403 Forbidden' );
532
- }
533
- if (!empty($blockredirect_url))
534
- {
535
- header("Location: $blockredirect_url");
536
- }
537
- elseif (!empty($blockredirect) && $blockredirect != 0)
538
- {
539
- $redirecturl = get_permalink($blockredirect);
540
- header("Location: $redirecturl");
541
- }
542
  // Display block message
543
- print "$blockmessage";
544
-
545
 
546
- exit ();
547
- }
548
  else
549
  {
550
- iqblockcountry_debug_logging($ip_address,$country,'NB');
551
  }
552
  }
553
  else
554
  {
555
- iqblockcountry_debug_logging($ip_address,$country,'NB');
556
  }
557
  }
558
 
559
 
560
  /**
561
  * Check if xmlrpc.php is hit.
 
562
  * @return bool
563
  */
564
- function iqblockcountry_is_xmlrpc() {
 
565
  return defined('XMLRPC_REQUEST') && XMLRPC_REQUEST;
566
  }
567
 
568
  /*
569
  * Check for active caching plugins
570
  */
571
- function iqblockcountry_is_caching_active() {
572
- $found = FALSE;
 
573
 
574
 
575
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
576
- if ( is_plugin_active( 'w3-total-cache/w3-total-cache.php' ) ) {
577
- $found = TRUE;
578
  }
579
- if ( is_plugin_active( 'hyper-cache/plugin.php' ) ) {
580
- $found = TRUE;
581
  }
582
 
583
- if (get_option('blockcountry_blockfrontend') == FALSE)
584
- {
585
- $found = FALSE;
586
  }
587
 
588
- return $found;
589
  }
590
 
591
  /*
592
  * Check if page is the login page
593
  */
594
- function iqblockcountry_is_login_page() {
595
- $found = FALSE;
596
- $pos2 = FALSE;
 
597
 
598
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
599
- if ( is_plugin_active( 'all-in-one-wp-security-and-firewall/wp-security.php' ) ) {
600
- $aio = get_option('aio_wp_security_configs');
601
- if (!empty($aio) && !(empty($aio['aiowps_login_page_slug']))) {
602
- $pos2 = strpos( $_SERVER['REQUEST_URI'], $aio['aiowps_login_page_slug'] ); }
 
603
  }
604
 
605
- if ( is_plugin_active( 'lockdown-wp-admin/lockdown-wp-admin.php' ) ) {
606
- $ld = get_option('ld_login_base');
607
- if (!empty($ld)) {
608
- $pos2 = strpos( $_SERVER['REQUEST_URI'], $ld); }
 
609
  }
610
 
611
- if ( is_plugin_active( 'wp-simple-firewall/icwp-wpsf.php' ) ) {
612
- $wpsf = get_option('icwp_wpsf_loginprotect_options');
613
- if (!empty($wpsf['rename_wplogin_path'])) {
614
- $pos2 = strpos( $_SERVER['REQUEST_URI'], $wpsf['rename_wplogin_path'] ); }
 
615
  }
616
 
617
- if ( is_plugin_active( 'rename-wp-login/rename-wp-login.php' ) ) {
618
- $rwpl = get_option('rwl_page');
619
- if (!empty($rwpl)) {
620
- $pos2 = strpos( $_SERVER['REQUEST_URI'], $rwpl ); }
 
621
  }
622
 
623
- if ( is_plugin_active( 'wps-hide-login/wps-hide-login.php' ) ) {
624
- $whlpage = get_option('whl_page');
625
- if (!empty($whlpage)) {
626
- $pos2 = strpos( $_SERVER['REQUEST_URI'], $whlpage ); }
 
627
  }
628
 
629
 
630
 
631
- $pos = strpos( $_SERVER['REQUEST_URI'], 'wp-login' );
632
- if ($pos !== false) { $found = TRUE; }
633
- elseif ($pos2 !== false) { $found = TRUE; }
 
 
634
 
635
- return $found;
636
  }
637
 
638
 
639
  /*
640
  * Check if page is within wp-admin page
641
  */
642
- function iqblockcountry_is_admin() {
643
- $found = FALSE;
 
644
 
645
 
646
- $pos = strpos( $_SERVER['REQUEST_URI'], '/wp-admin/' );
647
- if ($pos !== false) { $found = TRUE; }
 
648
 
649
- return $found;
650
  }
651
 
652
  /*
653
  * Check if page is within admin-ajax url.
654
  */
655
- function iqblockcountry_is_adminajax() {
656
- $found = FALSE;
 
657
 
658
 
659
- $pos = strpos( $_SERVER['REQUEST_URI'], '/wp-admin/admin-ajax.php' );
660
- if ($pos !== false) { $found = TRUE; }
 
661
 
662
- return $found;
663
  }
1
  <?php
2
 
3
 
4
+ function iqblockcountry_check_ipaddress($iqbc_ip_address)
5
  {
6
+ if (!class_exists('GeoIP')) {
7
+ include_once "geoip.inc";
 
8
  }
9
 
10
+ if (get_option('blockcountry_geoapikey')) {
11
+ $iqbc_country = iqblockcountry_retrieve_geoipapi($iqbc_ip_address);
12
+ }
13
+ elseif ((is_file(IQBCGEOIP2DBFILE))) {
14
+ if (iqblockcountry_is_valid_ipv4($iqbc_ip_address) || iqblockcountry_is_valid_ipv6($iqbc_ip_address)) {
15
+ if (class_exists('GeoIp2\\Database\\Reader')) {
16
+ try {
17
+ $iqbc_blockreader = new GeoIp2\Database\Reader(IQBCGEOIP2DBFILE);
18
+ $iqbc_blockrecord = $iqbc_blockreader->country($iqbc_ip_address);
19
+ $iqbc_country = filter_var($iqbc_blockrecord->country->isoCode, FILTER_SANITIZE_STRING);
20
+ }
21
+ catch(Exception $iqbc_e) {
22
+ $iqbc_country = "FALSE";
23
+ }
 
 
 
 
24
  }
25
  }
26
 
27
  }
28
+ else { $iqbc_country = "Unknown";
29
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
+ if (empty($iqbc_country) || $iqbc_country == null ) {
32
+ $iqbc_country = "Unknown";
 
33
  }
34
 
35
+ return $iqbc_country;
36
  }
37
 
38
  /*
39
  * iQ Block Retrieve XML file for API blocking
40
  */
41
+ function iqblockcountry_retrieve_geoipapi($iqbc_ipaddress)
42
  {
43
+ if (iqblockcountry_is_valid_ipv4($iqbc_ipaddress) || iqblockcountry_is_valid_ipv6($iqbc_ipaddress)) {
 
44
 
45
+ $iqbc_url = GEOIPAPIURL;
46
+ if (get_option('blockcountry_geoapilocation') == "US") {
47
+ $iqbc_url = GEOIPAPIURLUS;
48
+ }
49
+ if (get_option('blockcountry_geoapilocation') == "US2") {
50
+ $iqbc_url = GEOIPAPIURLUS2;
51
+ }
52
+ if (get_option('blockcountry_geoapilocation') == "US3") {
53
+ $iqbc_url = GEOIPAPIURLUS3;
54
+ }
55
+ if (get_option('blockcountry_geoapilocation') == "EU2") {
56
+ $iqbc_url = GEOIPAPIURLEU2;
57
+ }
58
+ if (get_option('blockcountry_geoapilocation') == "EU3") {
59
+ $iqbc_url = GEOIPAPIURLEU3;
60
+ }
61
+ if (get_option('blockcountry_geoapilocation') == "EU4") {
62
+ $iqbc_url = GEOIPAPIURLEU4;
63
+ }
64
+ if (get_option('blockcountry_geoapilocation') == "ASIA") {
65
+ $iqbc_url = GEOIPAPIURLASIA;
66
+ }
 
 
 
 
 
 
 
67
 
68
+ $iqbc_result = wp_remote_post(
69
+ $iqbc_url,
70
  array(
71
  'body' => array(
72
  'api-key' => get_option('blockcountry_geoapikey'),
73
+ 'ipaddress' => $iqbc_ipaddress
74
 
75
  )
76
  )
77
  );
78
+ if (is_wp_error($iqbc_result) ) {
79
+ return "Unknown";
80
+ }
81
+ elseif (200 == $iqbc_result['response']['code'] ) {
82
+ $iqbc_body = $iqbc_result['body'];
83
+ $iqbc_xml = new SimpleXmlElement($iqbc_body);
84
+ // FIX: Check against countries
85
+ if (isset($iqbc_xml->country)) { return (string) $iqbc_xml->country;
 
 
 
 
86
  }
87
+ elseif (isset($iqbc_xml->error)) {
88
+ if (strpos($iqbc_xml->error, 'License expired on ') !== false) {
89
+ update_option('blockcountry_geoapikey', '');
90
+ return "Expired";
91
+ }
92
+ }
93
+ else { return "Unknown";
94
+ }
95
+ }
96
+ elseif (403 == $iqbc_result['response']['code'] ) {
97
+ update_option('blockcountry_geoapikey', '');
98
+ }
99
+ else { return "Unknown";
100
  }
 
101
  }
102
+ else
103
+ { return "Invalid";
104
  }
 
 
 
 
105
  }
106
 
107
 
108
 
109
+ /**
110
  * Check country against bad countries, allow list and block list
111
+ **/
112
+ function iqblockcountry_check($iqbc_country,$iqbc_badcountries,$iqbc_ip_address)
113
  {
114
  /* Set default blocked status and get all options */
115
+ $iqbc_blocked = false;
116
+ $iqbc_blockedpage = get_option('blockcountry_blockpages');
117
+ //$iqbc_blockedpages = get_option('blockcountry_pages');
118
+ $iqbc_pagesbanlist = get_option('blockcountry_pages');
119
+ if (!is_array($iqbc_pagesbanlist)) { $iqbc_pagesbanlist = array();
120
+ }
121
+ if (get_option('blockcountry_blockpages_inverse') == 'on') {
122
+ $iqbc_pages = get_pages();
123
+ $iqbc_all_pages = array();
124
+ foreach ( $iqbc_pages as $iqbc_page ) {
125
+ $iqbc_all_pages[$iqbc_page->ID] = $iqbc_page->ID;
 
 
 
126
  }
127
+ $iqbc_blockedpages = array_diff($iqbc_all_pages, $iqbc_pagesbanlist);
128
+ } else {
129
+ $iqbc_blockedpages = $iqbc_pagesbanlist;
130
+ }
131
 
132
+ $iqbc_blockedcategory = get_option('blockcountry_blockcategories');
133
+ $iqbc_blocktags = get_option('blockcountry_blocktags');
134
+ $iqbc_blockedposttypes = get_option('blockcountry_blockposttypes');
135
+ $iqbc_blockedtag = get_option('blockcountry_blocktag');
136
+ $iqbc_blockedfeed = get_option('blockcountry_blockfeed');
137
+ $iqbc_postid = get_the_ID();
138
 
139
+ global $iqbc_feblocklistip,$iqbc_feblocklistiprange4,$iqbc_feblocklistiprange6,$iqbc_feallowlistip,$iqbc_feallowlistiprange4,$iqbc_feallowlistiprange6;
140
+ global $iqbc_beblocklistip,$iqbc_beblocklistiprange4,$iqbc_beblocklistiprange6,$iqbc_beallowlistip,$iqbc_beallowlistiprange4,$iqbc_beallowlistiprange6;
141
 
142
+ $iqbc_backendbanlistip = unserialize(get_option('blockcountry_backendbanlistip'));
143
+ $iqbc_blockredirect = get_option('blockcountry_redirect');
144
 
145
  /* Block if user is in a bad country from frontend or backend. Unblock may happen later */
146
+ if (is_array($iqbc_badcountries) && in_array($iqbc_country, $iqbc_badcountries)) {
147
+ $iqbc_blocked = true;
148
+ global $iqbc_backendblocklistcheck;
149
+ $iqbc_backendblocklistcheck = true;
150
  }
151
 
152
  global $blockcountry_is_login_page,$blockcountry_is_xmlrpc;
153
 
154
 
155
  /* Check if requested url is not login page. Else check against frontend allow list / block list. */
156
+ if (!($blockcountry_is_login_page) && !(is_admin()) && !($blockcountry_is_xmlrpc)) {
157
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feblocklistiprange4, $iqbc_feblocklistiprange6, $iqbc_feblocklistip)) {
158
+ $iqbc_blocked = true;
159
+ }
160
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feallowlistiprange4, $iqbc_feallowlistiprange6, $iqbc_feallowlistip)) {
161
+ $iqbc_blocked = false;
162
+ }
 
 
 
163
  }
164
 
165
 
166
+ if ($blockcountry_is_login_page || is_admin() || $blockcountry_is_xmlrpc) {
167
+ if (is_array($iqbc_backendbanlistip) && in_array($iqbc_ip_address, $iqbc_backendbanlistip)) {
168
+ $iqbc_blocked = true;
169
+ global $iqbc_apiblocklist;
170
+ $iqbc_apiblocklist = true;
 
 
171
  }
172
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_beblocklistiprange4, $iqbc_beblocklistiprange6, $iqbc_beblocklistip)) {
173
+ $iqbc_blocked = true;
174
+ }
175
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_beallowlistiprange4, $iqbc_beallowlistiprange6, $iqbc_beallowlistip)) {
176
+ $iqbc_blocked = false;
177
+ }
178
+ if (iqblockcountry_is_adminajax() && get_option('blockcountry_adminajax')) {
179
+ $iqbc_blocked = false;
 
180
  }
181
  }
182
 
183
+ if ($iqbc_blockedposttypes == "on") {
184
+ $iqbc_blockedposttypes = get_option('blockcountry_posttypes');
185
+ if (is_array($iqbc_blockedposttypes) && in_array(get_post_type($iqbc_postid), $iqbc_blockedposttypes) && ((is_array($iqbc_badcountries) && in_array($iqbc_country, $iqbc_badcountries) || (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feblocklistiprange4, $iqbc_feblocklistiprange6, $iqbc_feblocklistip))))) {
186
+ $iqbc_blocked = true;
187
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feallowlistiprange4, $iqbc_feallowlistiprange6, $iqbc_feallowlistip)) {
188
+ $iqbc_blocked = false;
 
 
189
  }
190
  }
191
  else
192
  {
193
+ $iqbc_blocked = false;
194
  }
195
  }
196
 
197
+ if (is_page() && $iqbc_blockedpage == "on") {
198
+ $iqbc_post = get_post();
199
+ if (is_page($iqbc_blockedpages) && !empty($iqbc_blockedpages) && ((is_array($iqbc_badcountries) && in_array($iqbc_country, $iqbc_badcountries) || (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feblocklistiprange4, $iqbc_feblocklistiprange6, $iqbc_feblocklistip))))) {
200
+ $iqbc_blocked = true;
201
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feallowlistiprange4, $iqbc_feallowlistiprange6, $iqbc_feallowlistip)) {
202
+ $iqbc_blocked = false;
 
 
203
  }
204
  }
205
  else
206
  {
207
+ $iqbc_blocked = false;
208
  }
209
  }
210
+ if (is_single() && $iqbc_blockedcategory == "on") {
211
+ $iqbc_blockedcategories = get_option('blockcountry_categories');
212
+ if (!is_array($iqbc_blockedcategories)) { $iqbc_blockedcategories = array();
213
+ }
214
+ $iqbc_post_categories = wp_get_post_categories($iqbc_postid);
215
+ $iqbc_flagged = false;
216
+ foreach ($iqbc_post_categories as $iqbc_key => $iqbc_value)
217
  {
218
+ if (in_array($iqbc_value, $iqbc_blockedcategories)) {
219
+ if (is_single() && ((is_array($iqbc_badcountries) && in_array($iqbc_country, $iqbc_badcountries) || (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feblocklistiprange4, $iqbc_feblocklistiprange6, $iqbc_feblocklistip))))) {
220
+ $iqbc_flagged = true;
221
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feallowlistiprange4, $iqbc_feallowlistiprange6, $iqbc_feallowlistip)) {
222
+ $iqbc_flagged = false;
 
 
223
  }
224
  }
225
  }
226
  }
227
+ if ($iqbc_flagged) { $iqbc_blocked = true;
228
+ } else { $iqbc_blocked = false;
229
+ }
230
  }
231
 
232
+ if (is_single() && $iqbc_blocktags == "on") {
233
+ $iqbc_previousblock = $iqbc_blocked;
234
+ $iqbc_blockedtags = get_option('blockcountry_tags');
235
+ if (!is_array($iqbc_blockedtags)) { $iqbc_blockedtags = array();
236
+ }
237
+ $iqbc_post_tags = get_the_tags($iqbc_postid);
238
+ if (empty($iqbc_post_tags)) { $iqbc_post_tags = array();
239
+ }
240
+ $iqbc_flagged = false;
241
+ foreach ($iqbc_post_tags as $iqbc_tag)
242
  {
243
+ if (in_array($iqbc_tag->term_id, $iqbc_blockedtags)) {
244
+ if (is_single() && ((is_array($iqbc_badcountries) && in_array($iqbc_country, $iqbc_badcountries) || (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feblocklistiprange4, $iqbc_feblocklistiprange6, $iqbc_feblocklistip))))) {
245
+ $iqbc_flagged = true;
246
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feallowlistiprange4, $iqbc_feallowlistiprange6, $iqbc_feallowlistip)) {
 
 
247
 
248
+ $iqbc_flagged = false;
249
  }
250
  }
251
  }
252
  }
253
+ if ($iqbc_flagged || $iqbc_previousblock == true) { $iqbc_blocked = true;
254
+ } else { $iqbc_blocked = false;
255
+ }
256
  }
257
 
258
 
259
+ if (is_category() && $iqbc_blockedcategory == "on") {
260
+ $iqbc_flagged = false;
261
+ $iqbc_blockedcategories = get_option('blockcountry_categories');
262
+ if (is_category($iqbc_blockedcategories) && ((is_array($iqbc_badcountries) && in_array($iqbc_country, $iqbc_badcountries) || (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feblocklistiprange4, $iqbc_feblocklistiprange6, $iqbc_feblocklistip))))) {
263
+ $iqbc_flagged = true;
 
 
264
  }
265
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feallowlistiprange4, $iqbc_feallowlistiprange6, $iqbc_feallowlistip)) {
266
 
267
+ $iqbc_flagged = false;
268
+ }
269
+ if ($iqbc_flagged) { $iqbc_blocked = true;
270
+ } else { $iqbc_blocked = false;
271
  }
 
272
  }
273
 
274
 
275
+ if (is_tag() && $iqbc_blockedtag == "on") {
276
+ $iqbc_flagged = false;
277
+ if ((is_array($iqbc_badcountries) && in_array($iqbc_country, $iqbc_badcountries) || (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feblocklistiprange4, $iqbc_feblocklistiprange6, $iqbc_feblocklistip)))) {
278
+ $iqbc_flagged = true;
 
 
279
  }
280
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feallowlistiprange4, $iqbc_feallowlistiprange6, $iqbc_feallowlistip)) {
281
 
282
+ $iqbc_flagged = false;
283
+ }
284
+ if ($iqbc_flagged) { $iqbc_blocked = true;
285
+ } else { $iqbc_blocked = false;
286
  }
 
287
  }
288
+ elseif (is_tag() && $iqbc_blockedtag == false) {
289
+ $iqbc_blocked = false;
 
290
  }
291
 
292
+ if (is_feed() && $iqbc_blockedfeed == "on") {
293
+ $iqbc_flagged = false;
294
+ if ((is_array($iqbc_badcountries) && in_array($iqbc_country, $iqbc_badcountries) || (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feblocklistiprange4, $iqbc_feblocklistiprange6, $iqbc_feblocklistip)))) {
295
+ $iqbc_flagged = true;
 
 
296
  }
297
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feallowlistiprange4, $iqbc_feallowlistiprange6, $iqbc_feallowlistip)) {
298
 
299
+ $iqbc_flagged = false;
300
+ }
301
+ if ($iqbc_flagged) { $iqbc_blocked = true;
302
+ } else { $iqbc_blocked = false;
303
  }
 
304
  }
305
+ elseif (is_feed() && $iqbc_blockedfeed == false) {
306
+ $iqbc_blocked = false;
 
307
  }
308
 
309
+ if (is_home() && (get_option('blockcountry_blockhome')) == false && $iqbc_blockedcategory == "on") {
310
+ $iqbc_blocked = false;
 
311
  }
312
+ if (is_page($iqbc_blockredirect) && ($iqbc_blockredirect != 0) && !(empty($iqbc_blockredirect))) {
313
+ $iqbc_blocked = false;
 
314
  }
315
 
316
+ $iqbc_allowse = get_option('blockcountry_allowse');
317
+ if (!$blockcountry_is_login_page && isset($_SERVER['HTTP_USER_AGENT']) && iqblockcountry_check_searchengine($_SERVER['HTTP_USER_AGENT'], $iqbc_allowse)) {
318
+ $iqbc_blocked = false;
 
319
  }
320
 
321
+ if (is_search() && (get_option('blockcountry_blocksearch')) == false) {
322
+ $iqbc_blocked = false;
 
323
  }
324
 
325
+ return $iqbc_blocked;
326
  }
327
 
328
  /*
330
  * Does the real check of visitor IP against MaxMind database or the GeoAPI
331
  *
332
  */
333
+ function iqblockcountry_CheckCountryBackEnd()
334
+ {
335
+ $iqbc_ip_address = iqblockcountry_get_ipaddress();
336
+ $iqbc_country = iqblockcountry_check_ipaddress($iqbc_ip_address);
337
  global $blockcountry_is_login_page,$blockcountry_is_xmlrpc;
338
+ if (($blockcountry_is_login_page || is_admin() || $blockcountry_is_xmlrpc) && get_option('blockcountry_blockbackend') == 'on') {
339
+ $iqbc_banlist = get_option('blockcountry_backendbanlist');
340
+ if (!is_array($iqbc_banlist)) { $iqbc_banlist = array();
341
+ }
342
+ if (get_option('blockcountry_backendbanlist_inverse') == 'on') {
343
+ $iqbc_all_countries = array_keys(iqblockcountry_get_isocountries());
344
+ $iqbc_badcountries = array_diff($iqbc_all_countries, $iqbc_banlist);
345
  } else {
346
+ $iqbc_badcountries = $iqbc_banlist;
347
  }
348
  }
349
 
350
+ $iqbc_blocklogin = get_option('blockcountry_blocklogin');
351
+ if (((is_user_logged_in()) && ($iqbc_blocklogin != "on")) || (!(is_user_logged_in())) ) {
352
 
353
  /* Check ip address against banlist, allow list and block list */
354
+ if (iqblockcountry_check($iqbc_country, $iqbc_badcountries, $iqbc_ip_address)) {
355
+ if (($blockcountry_is_login_page || is_admin() || $blockcountry_is_xmlrpc) && get_option('blockcountry_blockbackend') == 'on') {
356
+ $iqbc_blocked = get_option('blockcountry_backendnrblocks');
357
+ if (empty($iqbc_blocked)) { $iqbc_blocked = 0;
358
+ }
359
+ $iqbc_blocked++;
360
+ update_option('blockcountry_backendnrblocks', $iqbc_blocked);
361
+ global $iqbc_apiblocklist,$iqbc_backendblocklistcheck,$iqbc_debughandled;
362
+ if (!get_option('blockcountry_logging')) {
363
+ if (!$iqbc_apiblocklist) {
364
+ iqblockcountry_logging($iqbc_ip_address, $iqbc_country, "B");
365
+ iqblockcountry_debug_logging($iqbc_ip_address, $iqbc_country, 'BB');
366
+ }
367
+ elseif ($iqbc_backendblocklistcheck && $iqbc_apiblocklist) {
368
+ iqblockcountry_logging($iqbc_ip_address, $iqbc_country, "T");
369
+ iqblockcountry_debug_logging($iqbc_ip_address, $iqbc_country, 'TB');
370
+ }
371
+ else
372
  {
373
+ iqblockcountry_logging($iqbc_ip_address, $iqbc_country, "A");
374
+ iqblockcountry_debug_logging($iqbc_ip_address, $iqbc_country, 'AB');
 
 
 
 
 
 
 
 
 
 
 
 
 
375
  }
376
  }
377
+ }
378
+ else
379
  {
380
+ $iqbc_blocked = get_option('blockcountry_frontendnrblocks');
381
+ if (empty($iqbc_blocked)) { $iqbc_blocked = 0;
382
+ }
383
+ $iqbc_blocked++;
384
+ update_option('blockcountry_frontendnrblocks', $iqbc_blocked);
385
+ if (!get_option('blockcountry_logging')) {
386
+ iqblockcountry_logging($iqbc_ip_address, $iqbc_country, "F");
387
+ iqblockcountry_debug_logging($iqbc_ip_address, $iqbc_country, 'FB');
 
388
  }
389
+ }
390
 
391
 
392
+ $iqbc_blockmessage = get_option('blockcountry_blockmessage');
393
+ $iqbc_blockredirect = get_option('blockcountry_redirect');
394
+ $iqbc_blockredirect_url = get_option('blockcountry_redirect_url');
395
+ $iqbc_header = get_option('blockcountry_header');
396
+ if (!empty($iqbc_header) && ($iqbc_header)) {
397
+ // Prevent as much as possible that this error message is cached:
398
+ header("Cache-Control: no-store, no-cache, must-revalidate");
399
+ header("Cache-Control: post-check=0, pre-check=0", false);
400
+ header("Pragma: no-cache");
401
+ header("Expires: Sat, 26 Jul 2021 05:00:00 GMT");
 
402
 
403
+ header('HTTP/1.1 403 Forbidden');
404
+ }
405
+ if (!empty($iqbc_blockredirect_url)) {
406
+ header("Location: $iqbc_blockredirect_url");
407
+ }
408
+ elseif (!empty($iqbc_blockredirect) && $iqbc_blockredirect != 0) {
409
+ $iqbc_redirecturl = get_permalink($iqbc_blockredirect);
410
+ header("Location: $iqbc_redirecturl");
411
+ }
 
 
412
  // Display block message
413
+ print "$iqbc_blockmessage";
414
 
415
 
416
+ exit();
417
+ }
418
  else
419
  {
420
+ iqblockcountry_debug_logging($iqbc_ip_address, $iqbc_country, 'NB');
421
  }
422
  }
423
  else
424
  {
425
+ iqblockcountry_debug_logging($iqbc_ip_address, $iqbc_country, 'NB');
426
  }
427
  }
428
 
431
  * Does the real check of visitor IP against MaxMind database or the GeoAPI FrontEnd
432
  *
433
  */
434
+ function iqblockcountry_CheckCountryFrontEnd()
435
+ {
436
+ $iqbc_ip_address = iqblockcountry_get_ipaddress();
437
+ $iqbc_country = iqblockcountry_check_ipaddress($iqbc_ip_address);
438
+ $iqbc_banlist = get_option('blockcountry_banlist');
439
+ if (!is_array($iqbc_banlist)) { $iqbc_banlist = array();
440
+ }
441
+ if (get_option('blockcountry_banlist_inverse') == 'on') {
442
+ $iqbc_all_countries = array_keys(iqblockcountry_get_isocountries());
443
+ $iqbc_badcountries = array_diff($iqbc_all_countries, $iqbc_banlist);
444
+ } else {
445
+ $iqbc_badcountries = $iqbc_banlist;
446
+ }
447
 
448
+ $iqbc_blocklogin = get_option('blockcountry_blocklogin');
449
+ if (((is_user_logged_in()) && ($iqbc_blocklogin != "on")) || (!(is_user_logged_in())) ) {
450
 
451
  /* Check ip address against banlist, allow list and block list */
452
+ if (iqblockcountry_check($iqbc_country, $iqbc_badcountries, $iqbc_ip_address)) {
453
+ $iqbc_blocked = get_option('blockcountry_frontendnrblocks');
454
+ if (empty($iqbc_blocked)) { $iqbc_blocked = 0;
455
+ }
456
+ $iqbc_blocked++;
457
+ update_option('blockcountry_frontendnrblocks', $iqbc_blocked);
458
+ if (!get_option('blockcountry_logging')) {
459
+ iqblockcountry_logging($iqbc_ip_address, $iqbc_country, "F");
460
+ iqblockcountry_debug_logging($iqbc_ip_address, $iqbc_country, 'FB');
461
+ }
 
462
 
463
 
464
+ $iqbc_blockmessage = get_option('blockcountry_blockmessage');
465
+ $iqbc_blockredirect = get_option('blockcountry_redirect');
466
+ $iqbc_blockredirect_url = get_option('blockcountry_redirect_url');
467
+ $iqbc_header = get_option('blockcountry_header');
468
+ if (!empty($iqbc_header) && ($iqbc_header)) {
469
+ // Prevent as much as possible that this error message is cached:
470
+ header("Cache-Control: no-store, no-cache, must-revalidate");
471
+ header("Cache-Control: post-check=0, pre-check=0", false);
472
+ header("Pragma: no-cache");
473
+ header("Expires: Sat, 26 Jul 2012 05:00:00 GMT");
 
474
 
475
+ header('HTTP/1.1 403 Forbidden');
476
+ }
477
+ if (!empty($iqbc_blockredirect_url)) {
478
+ header("Location: $iqbc_blockredirect_url");
479
+ }
480
+ elseif (!empty($iqbc_blockredirect) && $iqbc_blockredirect != 0) {
481
+ $iqbc_redirecturl = get_permalink($iqbc_blockredirect);
482
+ header("Location: $iqbc_redirecturl");
483
+ }
 
 
484
  // Display block message
485
+ print "$iqbc_blockmessage";
 
486
 
487
+ exit();
488
+ }
489
  else
490
  {
491
+ iqblockcountry_debug_logging($iqbc_ip_address, $iqbc_country, 'NB');
492
  }
493
  }
494
  else
495
  {
496
+ iqblockcountry_debug_logging($iqbc_ip_address, $iqbc_country, 'NB');
497
  }
498
  }
499
 
500
 
501
  /**
502
  * Check if xmlrpc.php is hit.
503
+ *
504
  * @return bool
505
  */
506
+ function iqblockcountry_is_xmlrpc()
507
+ {
508
  return defined('XMLRPC_REQUEST') && XMLRPC_REQUEST;
509
  }
510
 
511
  /*
512
  * Check for active caching plugins
513
  */
514
+ function iqblockcountry_is_caching_active()
515
+ {
516
+ $iqbc_found = false;
517
 
518
 
519
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
520
+ if (is_plugin_active('w3-total-cache/w3-total-cache.php') ) {
521
+ $iqbc_found = true;
522
  }
523
+ if (is_plugin_active('hyper-cache/plugin.php') ) {
524
+ $iqbc_found = true;
525
  }
526
 
527
+ if (get_option('blockcountry_blockfrontend') == false) {
528
+ $iqbc_found = false;
 
529
  }
530
 
531
+ return $iqbc_found;
532
  }
533
 
534
  /*
535
  * Check if page is the login page
536
  */
537
+ function iqblockcountry_is_login_page()
538
+ {
539
+ $iqbc_found = false;
540
+ $iqbc_pos2 = false;
541
 
542
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
543
+ if (is_plugin_active('all-in-one-wp-security-and-firewall/wp-security.php') ) {
544
+ $iqbc_aio = get_option('aio_wp_security_configs');
545
+ if (!empty($iqbc_aio) && !(empty($iqbc_aio['aiowps_login_page_slug']))) {
546
+ $iqbc_pos2 = strpos($_SERVER['REQUEST_URI'], $iqbc_aio['aiowps_login_page_slug']);
547
+ }
548
  }
549
 
550
+ if (is_plugin_active('lockdown-wp-admin/lockdown-wp-admin.php') ) {
551
+ $iqbc_ld = get_option('ld_login_base');
552
+ if (!empty($iqbc_ld)) {
553
+ $iqbc_pos2 = strpos($_SERVER['REQUEST_URI'], $iqbc_ld);
554
+ }
555
  }
556
 
557
+ if (is_plugin_active('wp-simple-firewall/icwp-wpsf.php') ) {
558
+ $iqbc_wpsf = get_option('icwp_wpsf_loginprotect_options');
559
+ if (!empty($iqbc_wpsf['rename_wplogin_path'])) {
560
+ $iqbc_pos2 = strpos($_SERVER['REQUEST_URI'], $iqbc_wpsf['rename_wplogin_path']);
561
+ }
562
  }
563
 
564
+ if (is_plugin_active('rename-wp-login/rename-wp-login.php') ) {
565
+ $iqbc_rwpl = get_option('rwl_page');
566
+ if (!empty($iqbc_rwpl)) {
567
+ $iqbc_pos2 = strpos($_SERVER['REQUEST_URI'], $iqbc_rwpl);
568
+ }
569
  }
570
 
571
+ if (is_plugin_active('wps-hide-login/wps-hide-login.php') ) {
572
+ $iqbc_whlpage = get_option('whl_page');
573
+ if (!empty($iqbc_whlpage)) {
574
+ $iqbc_pos2 = strpos($_SERVER['REQUEST_URI'], $iqbc_whlpage);
575
+ }
576
  }
577
 
578
 
579
 
580
+ $iqbc_pos = strpos($_SERVER['REQUEST_URI'], 'wp-login');
581
+ if ($iqbc_pos !== false) { $iqbc_found = true;
582
+ }
583
+ elseif ($iqbc_pos2 !== false) { $iqbc_found = true;
584
+ }
585
 
586
+ return $iqbc_found;
587
  }
588
 
589
 
590
  /*
591
  * Check if page is within wp-admin page
592
  */
593
+ function iqblockcountry_is_admin()
594
+ {
595
+ $iqbc_found = false;
596
 
597
 
598
+ $iqbc_pos = strpos($_SERVER['REQUEST_URI'], '/wp-admin/');
599
+ if ($iqbc_pos !== false) { $iqbc_found = true;
600
+ }
601
 
602
+ return $iqbc_found;
603
  }
604
 
605
  /*
606
  * Check if page is within admin-ajax url.
607
  */
608
+ function iqblockcountry_is_adminajax()
609
+ {
610
+ $iqbc_found = false;
611
 
612
 
613
+ $iqbc_pos = strpos($_SERVER['REQUEST_URI'], '/wp-admin/admin-ajax.php');
614
+ if ($iqbc_pos !== false) { $iqbc_found = true;
615
+ }
616
 
617
+ return $iqbc_found;
618
  }
libs/blockcountry-geoip.php CHANGED
@@ -1,9 +1,13 @@
1
  <?php
2
 
 
 
 
 
3
  function iqblockcountry_get_isocountries()
4
  {
5
 
6
- $iqcountrylist = array(
7
  'A1' => "Anonymous Proxy",
8
  'A2' => "Satellite Provider",
9
  'AF' => 'Afghanistan',
@@ -256,9 +260,9 @@ $iqcountrylist = array(
256
  'YE' => 'Yemen',
257
  'ZM' => 'Zambia',
258
  'ZW' => 'Zimbabwe',
259
- );
260
 
261
- return $iqcountrylist;
262
  }
263
 
264
  ?>
1
  <?php
2
 
3
+ /**
4
+ *
5
+ *
6
+ */
7
  function iqblockcountry_get_isocountries()
8
  {
9
 
10
+ $iqbc_countrylist = array(
11
  'A1' => "Anonymous Proxy",
12
  'A2' => "Satellite Provider",
13
  'AF' => 'Afghanistan',
260
  'YE' => 'Yemen',
261
  'ZM' => 'Zambia',
262
  'ZW' => 'Zimbabwe',
263
+ );
264
 
265
+ return $iqbc_countrylist;
266
  }
267
 
268
  ?>
libs/blockcountry-logging.php CHANGED
@@ -1,11 +1,12 @@
1
  <?php
2
 
3
- function iqblockcountry_install_db() {
4
- global $wpdb;
 
5
 
6
- $table_name = $wpdb->prefix . "iqblock_logging";
7
 
8
- $sql = "CREATE TABLE $table_name (
9
  id bigint(20) NOT NULL AUTO_INCREMENT,
10
  datetime datetime NOT NULL,
11
  ipaddress tinytext NOT NULL,
@@ -16,51 +17,55 @@ function iqblockcountry_install_db() {
16
  KEY `datetime` (`datetime`)
17
  );";
18
 
19
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
20
- dbDelta( $sql );
21
  }
22
 
23
 
24
- function iqblockcountry_uninstall_db() {
25
- global $wpdb;
 
26
 
27
- $table_name = $wpdb->prefix . "iqblock_logging";
28
 
29
- $sql = "DROP TABLE IF EXISTS `$table_name`;";
30
 
31
- $wpdb->query($sql);
32
 
33
- delete_option( "blockcountry_dbversion");
34
  }
35
 
36
  function iqblockcountry_clean_db()
37
  {
38
- global $wpdb;
39
 
40
- $nrdays = get_option('blockcountry_daysstatistics');
41
- if (empty($nrdays)) { $nrdays = 30; }
 
42
 
43
- $table_name = $wpdb->prefix . "iqblock_logging";
44
- $sql = "DELETE FROM " . $table_name . " WHERE `datetime` < DATE_SUB(NOW(), INTERVAL " . $nrdays . " DAY);";
45
 
46
- $wpdb->query($sql);
47
 
48
  }
49
 
50
 
51
- function iqblockcountry_update_db_check() {
52
- if (get_site_option( 'blockcountry_dbversion' ) != DBVERSION) {
 
53
  iqblockcountry_install_db();
54
- update_option( "blockcountry_dbversion", DBVERSION );
55
  }
56
  }
57
 
58
- function iqblockcountry_install_loggingdb() {
59
- global $wpdb;
 
60
 
61
- $table_name = $wpdb->prefix . "iqblock_debug_logging";
62
 
63
- $sql = "CREATE TABLE $table_name (
64
  id bigint(20) NOT NULL AUTO_INCREMENT,
65
  datetime datetime NOT NULL,
66
  ipaddress tinytext NOT NULL,
@@ -71,71 +76,68 @@ function iqblockcountry_install_loggingdb() {
71
  PRIMARY KEY id (id)
72
  );";
73
 
74
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
75
- dbDelta( $sql );
76
  }
77
 
78
- function iqblockcountry_uninstall_loggingdb() {
79
- global $wpdb;
 
80
 
81
- $table_name = $wpdb->prefix . "iqblock_debug_logging";
82
 
83
- $sql = "DROP TABLE IF EXISTS `$table_name`;";
84
 
85
- $wpdb->query($sql);
86
 
87
- delete_option( "blockcountry_dbversion2");
88
  }
89
 
90
  function iqblockcountry_clean_loggingdb()
91
  {
92
- global $wpdb;
93
 
94
- $table_name = $wpdb->prefix . "iqblock_debug_logging";
95
- $sql = "DELETE FROM " . $table_name . " WHERE `datetime` < DATE_SUB(NOW(), INTERVAL 14 DAY);";
96
- // $sql = "DELETE FROM " . $table_name . " WHERE DATE_SUB(CURDATE(),INTERVAL 14 DAY) >= datetime;";
97
- $wpdb->query($sql);
98
  }
99
 
100
  /*
101
  * Schedule debug logging if this option was set in the admin panel
102
  */
103
- function iqblockcountry_blockcountry_debuglogging($old_value, $new_value)
104
  {
105
- if ($old_value !== $new_value)
106
- {
107
- if ($new_value == '')
108
- {
109
  iqblockcountry_uninstall_loggingdb();
110
  }
111
- elseif (!empty($new_value))
112
- {
113
  iqblockcountry_install_loggingdb();
114
  }
115
  }
116
  }
117
 
118
 
119
- function iqblockcountry_logging($ipaddress,$country,$banend)
120
  {
121
  global $wpdb;
122
 
123
- $urlRequested = (isset($_SERVER["REQUEST_URI"]) ? htmlspecialchars($_SERVER["REQUEST_URI"]) : '/' );
124
 
125
- $table_name = $wpdb->prefix . "iqblock_logging";
126
- $wpdb->insert($table_name,array ('datetime' => current_time('mysql'), 'ipaddress' => $ipaddress, 'country' => $country, 'banned' => $banend,'url' => $urlRequested));
127
  }
128
 
129
- function iqblockcountry_debug_logging($ipaddress,$country,$banend)
130
  {
131
- if (get_option('blockcountry_debuglogging'))
132
- {
133
  global $wpdb;
134
 
135
- $urlRequested = (isset($_SERVER["REQUEST_URI"]) ? htmlspecialchars($_SERVER["REQUEST_URI"]) : '/' );
136
- $type = htmlspecialchars($_SERVER['REQUEST_METHOD']);
137
 
138
- $table_name = $wpdb->prefix . "iqblock_debug_logging";
139
- $wpdb->insert($table_name,array ('datetime' => current_time('mysql'), 'ipaddress' => $ipaddress, 'type' => $type, 'country' => $country, 'banned' => $banend,'url' => $urlRequested));
140
  }
141
  }
1
  <?php
2
 
3
+ function iqblockcountry_install_db()
4
+ {
5
+ global $wpdb;
6
 
7
+ $iqbc_table_name = $wpdb->prefix . "iqblock_logging";
8
 
9
+ $iqbc_sql = "CREATE TABLE $iqbc_table_name (
10
  id bigint(20) NOT NULL AUTO_INCREMENT,
11
  datetime datetime NOT NULL,
12
  ipaddress tinytext NOT NULL,
17
  KEY `datetime` (`datetime`)
18
  );";
19
 
20
+ include_once ABSPATH . 'wp-admin/includes/upgrade.php';
21
+ dbDelta($iqbc_sql);
22
  }
23
 
24
 
25
+ function iqblockcountry_uninstall_db()
26
+ {
27
+ global $wpdb;
28
 
29
+ $iqbc_table_name = $wpdb->prefix . "iqblock_logging";
30
 
31
+ $iqbc_sql = "DROP TABLE IF EXISTS `$iqbc_table_name`;";
32
 
33
+ $wpdb->query($iqbc_sql);
34
 
35
+ delete_option("blockcountry_dbversion");
36
  }
37
 
38
  function iqblockcountry_clean_db()
39
  {
40
+ global $wpdb;
41
 
42
+ $iqbc_nrdays = get_option('blockcountry_daysstatistics');
43
+ if (empty($iqbc_nrdays)) { $iqbc_nrdays = 30;
44
+ }
45
 
46
+ $iqbc_table_name = $wpdb->prefix . "iqblock_logging";
47
+ $iqbc_sql = $wpdb->prepare("DELETE FROM " . $iqbc_table_name . " WHERE `datetime` < DATE_SUB(NOW(), INTERVAL %d DAY);",$iqbc_nrdays);
48
 
49
+ $wpdb->query($iqbc_sql);
50
 
51
  }
52
 
53
 
54
+ function iqblockcountry_update_db_check()
55
+ {
56
+ if (get_site_option('blockcountry_dbversion') != DBVERSION) {
57
  iqblockcountry_install_db();
58
+ update_option("blockcountry_dbversion", DBVERSION);
59
  }
60
  }
61
 
62
+ function iqblockcountry_install_loggingdb()
63
+ {
64
+ global $wpdb;
65
 
66
+ $iqbc_table_name = $wpdb->prefix . "iqblock_debug_logging";
67
 
68
+ $iqbc_sql = "CREATE TABLE $iqbc_table_name (
69
  id bigint(20) NOT NULL AUTO_INCREMENT,
70
  datetime datetime NOT NULL,
71
  ipaddress tinytext NOT NULL,
76
  PRIMARY KEY id (id)
77
  );";
78
 
79
+ include_once ABSPATH . 'wp-admin/includes/upgrade.php';
80
+ dbDelta($iqbc_sql);
81
  }
82
 
83
+ function iqblockcountry_uninstall_loggingdb()
84
+ {
85
+ global $wpdb;
86
 
87
+ $iqbc_table_name = $wpdb->prefix . "iqblock_debug_logging";
88
 
89
+ $iqbc_sql = "DROP TABLE IF EXISTS `$iqbc_table_name`;";
90
 
91
+ $wpdb->query($iqbc_sql);
92
 
93
+ delete_option("blockcountry_dbversion2");
94
  }
95
 
96
  function iqblockcountry_clean_loggingdb()
97
  {
98
+ global $wpdb;
99
 
100
+ $iqbc_table_name = $wpdb->prefix . "iqblock_debug_logging";
101
+ $iqbc_sql = "DELETE FROM " . $iqbc_table_name . " WHERE `datetime` < DATE_SUB(NOW(), INTERVAL 14 DAY);";
102
+ // $iqbc_sql = "DELETE FROM " . $iqbc_table_name . " WHERE DATE_SUB(CURDATE(),INTERVAL 14 DAY) >= datetime;";
103
+ $wpdb->query($iqbc_sql);
104
  }
105
 
106
  /*
107
  * Schedule debug logging if this option was set in the admin panel
108
  */
109
+ function iqblockcountry_blockcountry_debuglogging($iqbc_old_value, $iqbc_new_value)
110
  {
111
+ if ($iqbc_old_value !== $iqbc_new_value) {
112
+ if ($iqbc_new_value == '') {
 
 
113
  iqblockcountry_uninstall_loggingdb();
114
  }
115
+ elseif (!empty($iqbc_new_value)) {
 
116
  iqblockcountry_install_loggingdb();
117
  }
118
  }
119
  }
120
 
121
 
122
+ function iqblockcountry_logging($iqbc_ipaddress,$iqbc_country,$iqbc_banned)
123
  {
124
  global $wpdb;
125
 
126
+ $iqbc_urlRequested = (isset($_SERVER["REQUEST_URI"]) ? htmlspecialchars($_SERVER["REQUEST_URI"]) : '/' );
127
 
128
+ $iqbc_table_name = $wpdb->prefix . "iqblock_logging";
129
+ $wpdb->insert($iqbc_table_name, array ('datetime' => current_time('mysql'), 'ipaddress' => $iqbc_ipaddress, 'country' => $iqbc_country, 'banned' => $iqbc_banned,'url' => $iqbc_urlRequested));
130
  }
131
 
132
+ function iqblockcountry_debug_logging($iqbc_ipaddress,$iqbc_country,$iqbc_banned)
133
  {
134
+ if (get_option('blockcountry_debuglogging')) {
 
135
  global $wpdb;
136
 
137
+ $iqbc_urlRequested = (isset($_SERVER["REQUEST_URI"]) ? htmlspecialchars($_SERVER["REQUEST_URI"]) : '/' );
138
+ $iqbc_type = htmlspecialchars($_SERVER['REQUEST_METHOD']);
139
 
140
+ $iqbc_table_name = $wpdb->prefix . "iqblock_debug_logging";
141
+ $wpdb->insert($iqbc_table_name, array ('datetime' => current_time('mysql'), 'ipaddress' => $iqbc_ipaddress, 'type' => $iqbc_type, 'country' => $iqbc_country, 'banned' => $iqbc_banned,'url' => $iqbc_urlRequested));
142
  }
143
  }
libs/blockcountry-search-engines.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
- global $searchengines;
4
- $searchengines = array(
5
  "Alexa" => "ia_archiver",
6
  "AppleBot" => "Applebot",
7
  "Ask" => "ask jeeves",
@@ -42,20 +42,18 @@ $searchengines = array(
42
  "Yandex" => "yandexbot"
43
  );
44
 
45
- function iqblockcountry_check_searchengine($user_agent,$allowse)
46
  {
47
- global $searchengines;
48
- $issearchengine = FALSE;
49
- foreach ( $searchengines AS $se => $seua ) {
50
- if (is_array($allowse) && in_array($se,$allowse))
51
- {
52
- if(stripos($user_agent, $seua) !== false)
53
- {
54
- $issearchengine = TRUE;
55
  }
56
  }
57
  }
58
- return $issearchengine;
59
  }
60
 
61
  ?>
1
  <?php
2
 
3
+ global $iqbc_searchengines;
4
+ $iqbc_searchengines = array(
5
  "Alexa" => "ia_archiver",
6
  "AppleBot" => "Applebot",
7
  "Ask" => "ask jeeves",
42
  "Yandex" => "yandexbot"
43
  );
44
 
45
+ function iqblockcountry_check_searchengine($iqbc_user_agent,$iqbc_allowse)
46
  {
47
+ global $iqbc_searchengines;
48
+ $iqbc_issearchengine = false;
49
+ foreach ( $iqbc_searchengines AS $iqbc_se => $iqbc_seua ) {
50
+ if (is_array($iqbc_allowse) && in_array($iqbc_se, $iqbc_allowse)) {
51
+ if(stripos($iqbc_user_agent, $iqbc_seua) !== false) {
52
+ $iqbc_issearchengine = true;
 
 
53
  }
54
  }
55
  }
56
+ return $iqbc_issearchengine;
57
  }
58
 
59
  ?>
libs/blockcountry-settings.php CHANGED
@@ -1,106 +1,38 @@
1
  <?php
2
 
3
  /* Check if the Geo Database exists or if GeoIP API key is entered otherwise display notification */
4
- if (!is_file ( GEOIP2DBFILE ) && (!get_option('blockcountry_geoapikey'))) {
5
- add_action( 'admin_notices', 'iq_missing_db_notice' );
6
- }
7
-
8
- /* Check if the Geo Database exists or if GeoIP API key is entered otherwise display notification */
9
- if ((is_file(IPV4DBFILE) && !is_file ( GEOIP2DBFILE )) && (!get_option('blockcountry_geoapikey'))) {
10
- add_action( 'admin_notices', 'iq_missing_dbgeoip2_notice' );
11
  }
12
 
13
  /* check if caching plugins are active, if so display notice */
14
-
15
- if (iqblockcountry_is_caching_active())
16
- {
17
- add_action( 'admin_notices', 'iq_cachingisactive_notice' );
18
- }
19
-
20
-
21
- /*
22
- * Unzip the MaxMind IPv4 database if somebody uploaded it in GZIP format
23
- */
24
- if (is_file(IPV4DBFILE . ".gz"))
25
- {
26
- $zd = gzopen ( IPV4DBFILE . ".gz", "r" );
27
- $buffer = gzread ( $zd, 2000000 );
28
- gzclose ( $zd );
29
- if (is_file ( IPV4DBFILE . ".gz" )) { unlink ( IPV4DBFILE . ".gz" ); }
30
-
31
- /* Write this file to the GeoIP database file */
32
- if (is_file ( IPV4DBFILE )) { unlink ( IPV4DBFILE ); }
33
- $fp = fopen ( IPV4DBFILE, "w" );
34
- fwrite ( $fp, "$buffer" );
35
- fclose ( $fp );
36
- }
37
-
38
- /*
39
- * Unzip the MaxMind IPv6 database if somebody uploaded it in GZIP format
40
- */
41
- if (is_file(IPV6DBFILE . ".gz"))
42
- {
43
- $zd = gzopen ( IPV6DBFILE . ".gz", "r" );
44
- $buffer = gzread ( $zd, 2000000 );
45
- gzclose ( $zd );
46
- if (is_file ( IPV6DBFILE . ".gz" )) { unlink ( IPV6DBFILE . ".gz" ); }
47
-
48
- /* Write this file to the GeoIP database file */
49
- if (is_file ( IPV6DBFILE )) { unlink ( IPV6DBFILE ); }
50
- $fp = fopen ( IPV6DBFILE, "w" );
51
- fwrite ( $fp, "$buffer" );
52
- fclose ( $fp );
53
  }
54
 
55
-
56
- /*
57
  * Display missing database notification.
58
- */
59
  function iq_missing_db_notice()
60
  {
61
- if (!is_file(GEOIP2DBFILE) && !is_file(IPV4DBFILE))
62
- {
63
  ?>
64
  <div class="notice notice-error">
65
  <h3>iQ Block Country</h3>
66
- <p><?php _e('The MaxMind GeoIP2 database does not exist. Please download this file manually or if you wish to use the GeoIP API get an API key from: ', 'iq-block-country'); ?> <a href="https://webence.nl/geoip-api/" target="_blank">https://webence.nl/geoip-api/</a></p>
67
- <p><?php _e("Please download the database (GeoLite2-Country.tar.gz) from: " , 'iq-block-country'); ?>
68
- <?php _e("If you do not have an account at Maxmind yet for the Geolite2 database sign up for a free account at:", 'iq-block-country'); ?>
69
- <?php echo "<a href=\"" . MAXMINDURL . "\" target=\"_blank\">" . MAXMINDURL . "</a> "; ?>
70
- <?php _e("unzip the file and afterwards upload the GeoLite2-Country.mmdb file to the following location: " , 'iq-block-country'); ?>
71
- <b><?php echo GEOIP2DBFILE; ?></b></p>
72
 
73
- <p><?php _e('For more detailed instructions take a look at the documentation..', 'iq-block-country'); ?></p>
74
 
75
  </div>
76
- <?php
77
- }
78
  }
79
 
80
- /*
81
- * Display missing GeoIP2 database notification.
82
- */
83
- function iq_missing_dbgeoip2_notice()
84
- {
85
- if (is_file(IPV4DBFILE) && !(is_file(GEOIP2DBFILE)))
86
- {
87
- ?>
88
- <div class="notice notice-error">
89
- <h3>iQ Block Country</h3>
90
- <p><?php _e('Please upgrade your old GeoIP database. This database is no longer maintained by MaxMind and everyone should upgrade to the GeoIP2 database.<br />', 'iq-block-country');
91
- _e( 'The MaxMind GeoIP2 database does not exist yet . Please download this file manually or if you wish to use the GeoIP API get an API key from: ', 'iq-block-country'); ?> <a href="https://webence.nl/geoip-api/" target="_blank">https://webence.nl/geoip-api/</a></p>
92
- <p><?php _e("Please download the database (GeoLite2-Country.tar.gz) from: " , 'iq-block-country'); ?>
93
- <?php _e("If you do not have an account at Maxmind yet for the Geolite2 database sign up for a free account at:", 'iq-block-country'); ?>
94
- <?php echo "<a href=\"" . MAXMINDURL . "\" target=\"_blank\">" . MAXMINDURL . "</a> "; ?>
95
- <?php _e("unzip the file and afterwards upload the GeoLite2-Country.mmdb file to the following location: " , 'iq-block-country'); ?>
96
- <b><?php echo GEOIP2DBFILE; ?></b></p>
97
-
98
- <p><?php _e('For more detailed instructions take a look at the documentation..', 'iq-block-country'); ?></p>
99
-
100
- </div>
101
- <?php
102
- }
103
- }
104
 
105
 
106
  /*
@@ -111,11 +43,11 @@ function iq_cachingisactive_notice()
111
  ?>
112
  <div class="notice notice-warning is-dismissible">
113
  <h3>iQ Block Country</h3>
114
- <p><?php _e('A caching plugin appears to be active on your WordPress installation.', 'iq-block-country'); ?></p>
115
- <p><?php _e('Caching plugins do not always cooperate nicely together with the iQ Block Country plugin which may lead to non blocked visitors getting a cached banned message or page.', 'iq-block-country'); ?></p>
116
- <p><?php _e('For more information visit the following page:','iq-block-country'); ?> <a target="_blank"href="https://www.webence.nl/questions/iq-block-country-and-caching-plugins/">https://www.webence.nl/questions/iq-block-country-and-caching-plugins/</a></p>
117
  </div>
118
- <?php
119
  }
120
 
121
 
@@ -128,17 +60,17 @@ function iq_old_db_notice()
128
  ?>
129
  <div class="notice notice-warning">
130
  <h3>iQ Block Country</h3>
131
- <p><?php _e('The MaxMind GeoIP database is older than 3 months. Please update this file manually or if you wish to use the GeoIP API get an API key from: ', 'iq-block-country'); ?><a href="https://webence.nl/geoip-api/" target="_blank">https://webence.nl/geoip-api/</a></p>
132
- <p><?php _e("Please download the database (GeoLite2-Country.tar.gz) from MaxMind. " , 'iq-block-country'); ?>
133
- <?php _e("If you do not have an account at Maxmind yet for the Geolite2 database sign up for a free account at:", 'iq-block-country'); ?>
134
- <?php echo "<a href=\"" . MAXMINDURL . "\" target=\"_blank\">" . MAXMINDURL . "</a> "; ?>
135
- <?php _e("unzip the file and afterwards upload it to the following location: " , 'iq-block-country'); ?>
136
- <b><?php echo GEOIP2DBFILE; ?></b></p>
137
 
138
- <p><?php _e('For more detailed instructions take a look at the documentation..', 'iq-block-country'); ?></p>
139
 
140
  </div>
141
- <?php
142
  }
143
 
144
 
@@ -147,10 +79,10 @@ function iq_old_db_notice()
147
  */
148
  function iqblockcountry_create_menu()
149
  {
150
- //create new menu option in the settings department
151
- add_submenu_page ( 'options-general.php', 'iQ Block Country', 'iQ Block Country', 'administrator', __FILE__, 'iqblockcountry_settings_page' );
152
- //call register settings function
153
- add_action ( 'admin_init', 'iqblockcountry_register_mysettings' );
154
  }
155
 
156
  /*
@@ -158,49 +90,49 @@ function iqblockcountry_create_menu()
158
  */
159
  function iqblockcountry_register_mysettings()
160
  {
161
- //register our settings
162
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_blockmessage' );
163
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_redirect');
164
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_redirect_url','iqblockcountry_is_valid_url');
165
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_header');
166
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_buffer');
167
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_tracking');
168
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_nrstatistics');
169
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_daysstatistics');
170
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_lookupstatistics');
171
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_geoapikey','iqblockcountry_check_geoapikey');
172
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_geoapilocation');
173
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_apikey','iqblockcountry_check_adminapikey');
174
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_debuglogging');
175
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_accessibility');
176
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_ipoverride');
177
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_logging');
178
- register_setting ( 'iqblockcountry-settings-group', 'blockcountry_adminajax');
179
- register_setting ( 'iqblockcountry-settings-group-backend', 'blockcountry_blockbackend' );
180
- register_setting ( 'iqblockcountry-settings-group-backend', 'blockcountry_backendbanlist' );
181
- register_setting ( 'iqblockcountry-settings-group-backend', 'blockcountry_backendbanlist_inverse' );
182
- register_setting ( 'iqblockcountry-settings-group-backend', 'blockcountry_backendblacklist','iqblockcountry_validate_ip');
183
- register_setting ( 'iqblockcountry-settings-group-backend', 'blockcountry_backendwhitelist','iqblockcountry_validate_ip');
184
- register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_banlist' );
185
- register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_banlist_inverse' );
186
- register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_frontendblacklist','iqblockcountry_validate_ip');
187
- register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_frontendwhitelist','iqblockcountry_validate_ip');
188
- register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_blocklogin' );
189
- register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_blocksearch' );
190
- register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_blockfrontend' );
191
- register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_blocktag' );
192
- register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_blockfeed' );
193
- register_setting ( 'iqblockcountry-settings-group-pages', 'blockcountry_blockpages');
194
- register_setting ( 'iqblockcountry-settings-group-pages', 'blockcountry_blockpages_inverse');
195
- register_setting ( 'iqblockcountry-settings-group-pages', 'blockcountry_pages');
196
- register_setting ( 'iqblockcountry-settings-group-posttypes', 'blockcountry_blockposttypes');
197
- register_setting ( 'iqblockcountry-settings-group-posttypes', 'blockcountry_posttypes');
198
- register_setting ( 'iqblockcountry-settings-group-cat', 'blockcountry_blockcategories');
199
- register_setting ( 'iqblockcountry-settings-group-cat', 'blockcountry_categories');
200
- register_setting ( 'iqblockcountry-settings-group-cat', 'blockcountry_blockhome');
201
- register_setting ( 'iqblockcountry-settings-group-tags', 'blockcountry_blocktags');
202
- register_setting ( 'iqblockcountry-settings-group-tags', 'blockcountry_tags');
203
- register_setting ( 'iqblockcountry-settings-group-se', 'blockcountry_allowse');
204
  }
205
 
206
  /**
@@ -208,8 +140,9 @@ function iqblockcountry_register_mysettings()
208
  *
209
  * @return array of options.
210
  */
211
- function iqblockcountry_get_options_arr() {
212
- $optarr = array( 'blockcountry_banlist','blockcountry_banlist_inverse', 'blockcountry_backendbanlist','blockcountry_backendbanlist_inverse',
 
213
  'blockcountry_backendblacklist','blockcountry_backendwhitelist','blockcountry_frontendblacklist','blockcountry_frontendwhitelist',
214
  'blockcountry_blockmessage','blockcountry_blocklogin','blockcountry_blockfrontend','blockcountry_blockbackend','blockcountry_header',
215
  'blockcountry_blockpages','blockcountry_blockpages_inverse','blockcountry_pages','blockcountry_blockcategories','blockcountry_categories','blockcountry_tracking',
@@ -217,7 +150,7 @@ function iqblockcountry_get_options_arr() {
217
  'blockcountry_geoapilocation','blockcountry_apikey','blockcountry_redirect','blockcountry_redirect_url','blockcountry_allowse',
218
  'blockcountry_debuglogging','blockcountry_buffer','blockcountry_accessibility','blockcountry_ipoverride','blockcountry_logging','blockcountry_blockposttypes',
219
  'blockcountry_posttypes','blockcountry_blocksearch','blockcountry_adminajax','blockcountry_blocktag','blockcountry_blockfeed','blockcountry_blocktags','blockcountry_tags');
220
- return apply_filters( 'iqblockcountry_options', $optarr );
221
  }
222
 
223
 
@@ -226,33 +159,48 @@ function iqblockcountry_get_options_arr() {
226
  */
227
  function iqblockcountry_set_defaults()
228
  {
229
- update_option('blockcountry_version',VERSION);
230
- $countrylist = iqblockcountry_get_isocountries();
231
- $ip_address = iqblockcountry_get_ipaddress();
232
- $usercountry = iqblockcountry_check_ipaddress($ip_address);
233
- $server_addr = array_key_exists( 'SERVER_ADDR', $_SERVER ) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR'];
234
-
235
-
236
- if (get_option('blockcountry_blockfrontend') === FALSE) { update_option('blockcountry_blockfrontend' , 'on'); }
237
- if (get_option('blockcountry_blockfeed') === FALSE) { update_option('blockcountry_blockfeed' , 'on'); }
238
- if (get_option('blockcountry_backendnrblocks') === FALSE) { update_option('blockcountry_backendnrblocks', 0); }
239
- if (get_option('blockcountry_frontendnrblocks') === FALSE) { update_option('blockcountry_frontendnrblocks', 0); }
240
- if (get_option('blockcountry_header') === FALSE) { update_option('blockcountry_header', 'on'); }
241
- if (get_option('blockcountry_nrstatistics') === FALSE) { update_option('blockcountry_nrstatistics',15); }
242
- if ( NULL === get_option('blockcountry_daysstatistics', NULL ) ) { update_option('blockcountry_daysstatistics',30); }
243
- if (get_option('blockcountry_backendwhitelist') === FALSE || (get_option('blockcountry_backendwhitelist') == "")) { update_option('blockcountry_backendwhitelist',$ip_address . ";"); }
244
- $tmpbackendallowlist = get_option('blockcountry_backendwhitelist');
245
- $ippos = strpos($tmpbackendallowlist,$server_addr);
246
- if ($ippos === false)
247
- {
248
- $tmpbackendallowlist .= $server_addr . ";";
249
- update_option('blockcountry_backendwhitelist',$tmpbackendallowlist);
250
  }
251
- if (get_option('blockcountry_frontendwhitelist') === FALSE || (get_option('blockcountry_frontendwhitelist') == "")) { update_option('blockcountry_frontendwhitelist',$server_addr . ";"); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  iqblockcountry_install_db();
253
- if (get_option('blockcountry_banlist_inverse') === FALSE) { update_option('blockcountry_banlist_inverse' , 'off'); }
254
- if (get_option('blockcountry_backendbanlist_inverse') === FALSE) { update_option('blockcountry_backendbanlist_inverse' , 'off'); }
255
- if (get_option('blockcountry_ipoverride') === FALSE) { update_option('blockcountry_ipoverride' , 'NONE'); }
 
 
 
256
  iqblockcountry_find_geoip_location();
257
  }
258
 
@@ -261,20 +209,20 @@ function iqblockcountry_uninstall() //deletes all the database entries that the
261
  {
262
  iqblockcountry_uninstall_db();
263
  iqblockcountry_uninstall_loggingdb();
264
- delete_option('blockcountry_banlist' );
265
- delete_option('blockcountry_banlist_inverse' );
266
- delete_option('blockcountry_backendbanlist' );
267
  delete_option('blockcountry_backendbanlist_inverse');
268
- delete_option('blockcountry_backendblacklist' );
269
- delete_option('blockcountry_backendwhitelist' );
270
- delete_option('blockcountry_frontendblacklist' );
271
- delete_option('blockcountry_frontendwhitelist' );
272
- delete_option('blockcountry_blockmessage' );
273
- delete_option('blockcountry_backendnrblocks' );
274
- delete_option('blockcountry_frontendnrblocks' );
275
- delete_option('blockcountry_blocklogin' );
276
- delete_option('blockcountry_blockfrontend' );
277
- delete_option('blockcountry_blockbackend' );
278
  delete_option('blockcountry_version');
279
  delete_option('blockcountry_header');
280
  delete_option('blockcountry_blockpages');
@@ -312,832 +260,800 @@ function iqblockcountry_uninstall() //deletes all the database entries that the
312
 
313
 
314
 
315
- function iqblockcountry_settings_tools() {
 
316
  ?>
317
- <h3><?php _e('Check which country belongs to an IP Address according to the current database.', 'iq-block-country'); ?></h3>
318
 
319
- <form name="ipcheck" action="#ipcheck" method="post">
320
- <input type="hidden" name="action" value="ipcheck" />
321
- <input name="ipcheck_nonce" type="hidden" value="<?php echo wp_create_nonce('ipcheck_nonce'); ?>" />
322
- <?php _e('IP Address to check:', 'iq-block-country'); ?> <input type="text" name="ipaddress" lenth="50" />
323
- <?php
324
- global $feblocklistip,$feblocklistiprange4,$feblocklistiprange6,$feallowlistip,$feallowlistiprange4,$feallowlistiprange6;
325
- global $beblocklistip,$beblocklistiprange4,$beblocklistiprange6,$beallowlistip,$beallowlistiprange4,$beallowlistiprange6;
326
-
327
-
328
- if ( isset($_POST['action']) && $_POST[ 'action' ] == 'ipcheck') {
329
- if (!isset($_POST['ipcheck_nonce'])) die("Failed security check.");
330
- if (!wp_verify_nonce($_POST['ipcheck_nonce'],'ipcheck_nonce')) die("Is this a CSRF attempts?");
331
- if (isset($_POST['ipaddress']) && !empty($_POST['ipaddress']))
332
- {
333
- if (iqblockcountry_is_valid_ipv4($_POST['ipaddress']) || iqblockcountry_is_valid_ipv6($_POST['ipaddress']))
334
- {
335
- if (filter_var($_POST['ipaddress'], FILTER_VALIDATE_IP))
336
- { $ip_address = $_POST['ipaddress']; }
337
- $country = iqblockcountry_check_ipaddress($ip_address);
338
- $countrylist = iqblockcountry_get_isocountries();
339
- if ($country == "Unknown" || $country == "ipv6" || $country == "" || $country == "FALSE")
340
- {
341
- echo "<p>" . __('No country for', 'iq-block-country') . ' ' . $ip_address . ' ' . __('could be found. Or', 'iq-block-country') . ' ' . $ip_address . ' ' . __('is not a valid IPv4 or IPv6 IP address', 'iq-block-country');
342
- echo "</p>";
343
- }
344
- else {
345
- $displaycountry = $countrylist[$country];
346
- echo "<p>" . __('IP Adress', 'iq-block-country') . ' ' . $ip_address . ' ' . __('belongs to', 'iq-block-country') . ' ' . $displaycountry . ".</p>";
347
- $haystack = get_option('blockcountry_banlist');
348
- if (!is_array($haystack)) { $haystack = array(); }
349
- $inverse = get_option( 'blockcountry_banlist_inverse');
350
- if ($inverse == "on") {
351
- if (is_array($haystack) && !in_array ($country, $haystack )) {
352
- _e('This country is not permitted to visit the frontend of this website.', 'iq-block-country');
353
- echo "<br />";
354
- }
355
- } else {
356
- if (is_array($haystack) && in_array ( $country, $haystack )) {
357
- _e('This country is not permitted to visit the frontend of this website.', 'iq-block-country');
358
- echo "<br />";
359
- }
360
- }
361
- $inverse = get_option( 'blockcountry_backendbanlist_inverse');
362
- $haystack = get_option('blockcountry_backendbanlist');
363
- if (!is_array($haystack)) { $haystack = array(); }
364
- if ($inverse == "on") {
365
- if (is_array($haystack) && !in_array ( $country, $haystack )) {
366
- _e('This country is not permitted to visit the backend of this website.', 'iq-block-country');
367
- echo "<br />";
368
- }
369
- }
370
- else
371
- {
372
- if (is_array($haystack) && in_array ( $country, $haystack )) {
373
- _e('This country is not permitted to visit the backend of this website.', 'iq-block-country');
374
- echo "<br />";
375
- }
376
- }
377
- $backendbanlistip = unserialize(get_option('blockcountry_backendbanlistip'));
378
- if (is_array($backendbanlistip) && in_array($ip_address,$backendbanlistip)) {
379
- _e('This IP address is present in the block list.', 'iq-block-country');
380
- }
381
 
382
- }
383
- if (iqblockcountry_validate_ip_in_list($ip_address,$feblocklistiprange4,$feblocklistiprange6,$feblocklistip))
384
- {
385
- _e('This IP address is present in the frontend block list.', 'iq-block-country');
386
- echo "<br />";
387
- }
388
- if (iqblockcountry_validate_ip_in_list($ip_address,$feallowlistiprange4,$feallowlistiprange6,$feallowlistip))
389
- {
390
- _e('This IP address is present in the frontend allow list.', 'iq-block-country');
391
- echo "<br />";
392
- }
393
- if (iqblockcountry_validate_ip_in_list($ip_address,$beblocklistiprange4,$beblocklistiprange6,$beblocklistip))
394
- {
395
- _e('This IP address is present in the backend block list.', 'iq-block-country');
396
- echo "<br />";
397
- }
398
- if (iqblockcountry_validate_ip_in_list($ip_address,$beallowlistiprange4,$beallowlistiprange6,$beblocklistip))
399
- {
400
- _e('This IP address is present in the backend allow list.', 'iq-block-country');
401
- echo "<br />";
402
- }
403
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  }
405
- }
406
- }
407
- echo '<div class="submit"><input type="submit" name="test" value="' . __( 'Check IP address', 'iq-block-country' ) . '" /></div>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
408
  wp_nonce_field('iqblockcountry');
409
 
410
- ?>
411
  </form>
412
 
413
  <hr />
414
 
415
- <h3><?php _e('Database information', 'iq-block-country'); ?></h3>
416
  <?php
417
 
418
- $format = get_option('date_format') . ' ' . get_option('time_format');
419
- if (!get_option('blockcountry_geoapikey'))
420
- {
421
- if (!is_file ( GEOIP2DBFILE ))
422
- {
423
- /* Check if the Geo Database exists */
424
- if (is_file ( IPV4DBFILE )) {
425
-
426
- _e("IPv4 database exists. File date: ", 'iq-block-country');
427
- $iqfiledate = filemtime(IPV4DBFILE);
428
- echo date ($format,$iqfiledate);
429
- echo " ";
430
- $iq3months = time() - 3 * 31 * 86400;
431
- if ($iqfiledate < $iq3months)
432
- {
433
- _e("Database is older than 3 months... Please update...", 'iq-block-country');
434
- }
435
- }
436
- else
437
- {
438
- _e("IPv4 database does not exist.", 'iq-block-country');
439
- }
440
- echo "<br />";
441
-
442
- if (is_file ( IPV6DBFILE )) {
443
 
444
- _e("IPv6 database exists. File date: ", 'iq-block-country');
445
- $iqfiledate = filemtime(IPV6DBFILE);
446
- echo date ($format,$iqfiledate);
447
  echo " ";
448
- $iq3months = time() - 3 * 31 * 86400;
449
- if ($iqfiledate < $iq3months)
450
- {
451
- _e("Database is older than 3 months... Please update...", 'iq-block-country');
452
  }
453
  }
454
  else
455
  {
456
- _e("IPv6 database does not exist.", 'iq-block-country');
457
- }
458
  echo "<br />";
459
  }
460
- if (is_file ( GEOIP2DBFILE )) {
461
-
462
- _e("GeoIP2 database exists. File date: ", 'iq-block-country');
463
- $iqfiledate = filemtime(GEOIP2DBFILE);
464
- echo date ($format,$iqfiledate);
465
- echo " ";
466
- $iq3months = time() - 3 * 31 * 86400;
467
- if ($iqfiledate < $iq3months)
468
- {
469
- _e("Database is older than 3 months... Please update...", 'iq-block-country');
470
- }
471
- }
472
- else
473
- {
474
- _e("GeoIP2 database does not exist.", 'iq-block-country');
475
- }
476
- echo "<br />";
477
- }
478
- if (get_option('blockcountry_geoapikey'))
479
- {
480
- $licensedate = strtotime(iqblockcountry_get_licensedate_geoapikey(get_option('blockcountry_geoapikey')));
481
- _e("Your GeoIP API key is valid till: ", 'iq-block-country');
482
- echo date($format,$licensedate);
483
  echo "<br />";
484
- $usagerequests = iqblockcountry_get_usage_geoapikey(get_option('blockcountry_geoapikey'));
485
- _e("Your GeoIP API usage this month: ", 'iq-block-country');
486
- echo $usagerequests;
487
  }
488
  ?>
489
  <br />
490
  <br />
491
 
492
- <h3><?php _e('Reset Counters', 'iq-block-country'); ?></h3>
493
 
494
  <div class="wrap">
495
  <div id="icon-tools" class="icon32"><br /></div>
496
- <p><?php _e('When you click on the <tt>Reset Counter</tt> button the counters of total Frontend & Backend blocks will be set to 0.', 'iq-block-country'); ?></p>
497
 
498
- <?php $blocked = get_option('blockcountry_backendnrblocks'); ?>
499
- <p><?php echo number_format($blocked); ?> <?php _e('visitors blocked from the backend.', 'iq-block-country'); ?></p>
500
- <?php $blocked = get_option('blockcountry_frontendnrblocks'); ?>
501
- <p><?php echo number_format($blocked); ?> <?php _e('visitors blocked from the frontend.', 'iq-block-country'); ?></p>
502
 
503
  <form method='post'>
504
  <p class="submit">
505
  <?php wp_nonce_field('iqblockresetcounter'); ?>
506
- <input type='submit' name='resetcounter' value='<?php _e('Reset Counter', 'iq-block-country'); ?>'/>
507
  </p>
508
  </form>
509
  </div>
510
  <?php
511
- if ((isset($_POST['resetcounter'])) && (check_admin_referer('iqblockresetcounter'))) {
512
- update_option('blockcountry_backendnrblocks',0);
513
- update_option('blockcountry_frontendnrblocks',0);
514
- _e("Counters reset", 'iq-block-country');
515
  }
516
  ?>
517
- <h3><?php _e('Active plugins', 'iq-block-country'); ?></h3>
518
  <?php
519
 
520
- $plugins = get_plugins();
521
- $plugins_string = '';
522
 
523
  echo '<table class="widefat">';
524
- echo '<thead><tr><th>' . __('Plugin name', 'iq-block-country') . '</th><th>' . __('Version', 'iq-block-country') . '</th><th>' . __('URL', 'iq-block-country') . '</th></tr></thead>';
525
 
526
- foreach( array_keys($plugins) as $key ) {
527
- if ( is_plugin_active( $key ) ) {
528
- $plugin =& $plugins[$key];
529
- echo "<tbody><tr>";
530
- echo '<td>' . $plugin['Name'] . '</td>';
531
- echo '<td>' . $plugin['Version'] . '</td>';
532
- echo '<td>' . $plugin['PluginURI'] . '</td>';
533
  echo "</tr></tbody>";
534
  }
535
  }
536
  echo '</table>';
537
- echo $plugins_string;
538
  global $wpdb;
539
 
540
- $disabled_functions = @ini_get( 'disable_functions' );
541
 
542
- if ( $disabled_functions == '' || $disabled_functions === false ) {
543
- $disabled_functions = '<i>(' . __( 'none', 'iq-block-country' ) . ')</i>';
544
  }
545
 
546
- $disabled_functions = str_replace( ', ', ',', $disabled_functions ); // Normalize spaces or lack of spaces between disabled functions.
547
- $disabled_functions_array = explode( ',', $disabled_functions );
548
 
549
- $php_uid = __( 'unavailable', 'iq-block-country' );
550
- $php_user = __( 'unavailable', 'iq-block-country' );
551
 
552
 
553
  ?>
554
- <h3><?php _e('File System Information', 'iq-block-country'); ?></h3>
555
 
556
  <table class="widefat">
557
- <tbody><tr><td><?php _e( 'Website Root Folder', 'iq-block-country' ); ?>: <strong><?php echo get_site_url(); ?></strong></td></tr></tbody>
558
- <tbody><tr><td><?php _e( 'Document Root Path', 'iq-block-country' ); ?>: <strong><?php echo filter_var( $_SERVER['DOCUMENT_ROOT'], FILTER_SANITIZE_STRING ); ?></strong></td></tr></tbody>
559
  </table>
560
 
561
 
562
- <h3><?php _e('Database Information', 'iq-block-country'); ?></h3>
563
  <table class="widefat">
564
- <tbody><tr><td><?php _e( 'MySQL Database Version', 'iq-block-country' ); ?>: <?php $sqlversion = $wpdb->get_var( "SELECT VERSION() AS version" ); ?><strong><?php echo $sqlversion; ?></strong></td></tr></tbody>
565
- <tbody><tr><td><?php _e( 'MySQL Client Version', 'iq-block-country' ); ?>: <strong><?php echo $wpdb->db_version(); ?></strong></td></tr></tbody>
566
- <tbody><tr><td><?php _e( 'Database Host', 'iq-block-country' ); ?>: <strong><?php echo DB_HOST; ?></strong></td></tr></tbody>
567
- <?php $mysqlinfo = $wpdb->get_results( "SHOW VARIABLES LIKE 'sql_mode'" );
568
- if ( is_array( $mysqlinfo ) ) {
569
- $sql_mode = $mysqlinfo[0]->Value;
570
- }
571
- if ( empty( $sql_mode ) ) {
572
- $sql_mode = __( 'Not Set', 'iq-block-country' );
573
- } else {
574
- $sql_mode = __( 'Off', 'iq-block-country' );
575
- }
576
- ?>
577
- <tbody><tr><td><?php _e( 'SQL Mode', 'iq-block-country' ); ?>: <strong><?php echo $sql_mode; ?></strong></td></tr></tbody>
578
  </table>
579
 
580
 
581
- <h3><?php _e('Server Information', 'iq-block-country'); ?></h3>
582
 
583
  <table class="widefat">
584
 
585
- <?php $server_addr = array_key_exists( 'SERVER_ADDR', $_SERVER ) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']; ?>
586
- <tbody><tr><td><?php _e( 'Server IP Address', 'iq-block-country' ); ?>: <strong><?php echo $server_addr; ?></strong></td></tr></tbody>
587
-
588
- <tbody><tr><td><?php _e( 'Server Type', 'iq-block-country' ); ?>: <strong><?php echo filter_var( filter_var( $_SERVER['SERVER_SOFTWARE'], FILTER_SANITIZE_STRING ), FILTER_SANITIZE_STRING ); ?></strong></td></tr></tbody>
589
- <tbody><tr><td><?php _e( 'Operating System', 'iq-block-country' ); ?>: <strong><?php echo PHP_OS; ?></strong></td></tr></tbody>
590
- <tbody><tr><td><?php _e( 'Browser Compression Supported', 'iq-block-country' ); ?>:
591
- <strong><?php echo filter_var( $_SERVER['HTTP_ACCEPT_ENCODING'], FILTER_SANITIZE_STRING ); ?></strong></td></tr></tbody>
592
  <?php
593
 
594
- if ( is_callable( 'posix_geteuid' ) && ( false === in_array( 'posix_geteuid', $disabled_functions_array ) ) ) {
595
 
596
- $php_uid = @posix_geteuid();
597
 
598
- if ( is_callable( 'posix_getpwuid' ) && ( false === in_array( 'posix_getpwuid', $disabled_functions_array ) ) ) {
599
 
600
- $php_user = @posix_getpwuid( $php_uid );
601
- $php_user = $php_user['name'];
602
 
603
- }
604
  }
605
 
606
- $php_gid = __( 'undefined', 'iq-block-country' );
607
 
608
- if ( is_callable( 'posix_getegid' ) && ( false === in_array( 'posix_getegid', $disabled_functions_array ) ) ) {
609
- $php_gid = @posix_getegid();
610
  }
611
 
612
  ?>
613
- <tbody><tr><td><?php _e( 'PHP Process User (UID:GID)', 'iq-block-country' ); ?>:
614
- <strong><?php echo $php_user . ' (' . $php_uid . ':' . $php_gid . ')'; ?></strong></td></tr></tbody>
615
  </table>
616
 
617
 
618
- <h3><?php _e('PHP Information', 'iq-block-country'); ?></h3>
619
 
620
  <table class="widefat">
621
 
622
 
623
- <tbody><tr><td><?php _e( 'PHP Version', 'iq-block-country' ); ?>: <strong><?php echo PHP_VERSION; ?></strong></td></tr></tbody>
624
- <tbody><tr><td><?php _e( 'PHP Memory Usage', 'iq-block-country' ); ?>: <strong><?php echo round( memory_get_usage() / 1024 / 1024, 2 ) . __( ' MB', 'iq-block-country' ); ?></strong></td></tr></tbody>
625
 
626
  <?php
627
- if ( ini_get( 'memory_limit' ) ) {
628
- $memory_limit = filter_var( ini_get( 'memory_limit' ), FILTER_SANITIZE_STRING );
629
  } else {
630
- $memory_limit = __( 'N/A', 'iq-block-country' );
631
  }
632
  ?>
633
- <tbody><tr><td><?php _e( 'PHP Memory Limit', 'iq-block-country' ); ?>: <strong><?php echo $memory_limit; ?></strong></td></tr></tbody>
634
  <?php
635
- if ( ini_get( 'upload_max_filesize' ) ) {
636
- $upload_max = filter_var( ini_get( 'upload_max_filesize' ), FILTER_SANITIZE_STRING );
637
  } else {
638
- $upload_max = __( 'N/A', 'iq-block-country' );
639
  }
640
  ?>
641
- <tbody><tr><td><?php _e( 'PHP Max Upload Size', 'iq-block-country' ); ?>: <strong><?php echo $upload_max; ?></strong></td></tr></tbody>
642
  <?php
643
- if ( ini_get( 'post_max_size' ) ) {
644
- $post_max = filter_var( ini_get( 'post_max_size' ), FILTER_SANITIZE_STRING );
645
  } else {
646
- $post_max = __( 'N/A', 'iq-block-country' );
647
  }
648
  ?>
649
- <tbody><tr><td><?php _e( 'PHP Max Post Size', 'iq-block-country' ); ?>: <strong><?php echo $post_max; ?></strong></td></tr></tbody>
650
  <?php
651
- if ( ini_get( 'allow_url_fopen' ) ) {
652
- $allow_url_fopen = __( 'On', 'iq-block-country' );
653
  } else {
654
- $allow_url_fopen = __( 'Off', 'iq-block-country' );
655
  }
656
  ?>
657
- <tbody><tr><td><?php _e( 'PHP Allow URL fopen', 'iq-block-country' ); ?>: <strong><?php echo $allow_url_fopen; ?></strong></td></tr></tbody>
658
  <?php
659
- if ( ini_get( 'allow_url_include' ) ) {
660
- $allow_url_include = __( 'On', 'iq-block-country' );
661
  } else {
662
- $allow_url_include = __( 'Off', 'iq-block-country' );
663
  }
664
  ?>
665
- <tbody><tr><td><?php _e( 'PHP Allow URL Include' ); ?>: <strong><?php echo $allow_url_include; ?></strong></td></tr></tbody>
666
  <?php
667
- if ( ini_get( 'display_errors' ) ) {
668
- $display_errors = __( 'On', 'iq-block-country' );
669
  } else {
670
- $display_errors = __( 'Off', 'iq-block-country' );
671
  }
672
  ?>
673
- <tbody><tr><td><?php _e( 'PHP Display Errors', 'iq-block-country' ); ?>: <strong><?php echo $display_errors; ?></strong></td></tr></tbody>
674
  <?php
675
- if ( ini_get( 'display_startup_errors' ) ) {
676
- $display_startup_errors = __( 'On', 'iq-block-country' );
677
  } else {
678
- $display_startup_errors = __( 'Off', 'iq-block-country' );
679
  }
680
  ?>
681
- <tbody><tr><td><?php _e( 'PHP Display Startup Errors', 'iq-block-country' ); ?>:
682
- <strong><?php echo $display_startup_errors; ?></strong></td></tr></tbody>
683
  <?php
684
- if ( ini_get( 'expose_php' ) ) {
685
- $expose_php = __( 'On', 'iq-block-country' );
686
  } else {
687
- $expose_php = __( 'Off', 'iq-block-country' );
688
  }
689
  ?>
690
- <tbody><tr><td><?php _e( 'PHP Expose PHP', 'iq-block-country' ); ?>: <strong><?php echo $expose_php; ?></strong></td></tr></tbody>
691
  <?php
692
- if ( ini_get( 'max_execution_time' ) ) {
693
- $max_execute = filter_var( ini_get( 'max_execution_time' ) );
694
  } else {
695
- $max_execute = __( 'N/A', 'iq-block-country' );
696
  }
697
  ?>
698
- <tbody><tr><td><?php _e( 'PHP Max Script Execution Time' ); ?>:
699
- <strong><?php echo $max_execute; ?> <?php _e( 'Seconds' ); ?></strong></td></tr></tbody>
700
  <?php
701
- if ( ini_get( 'open_basedir' ) ) {
702
- $open_basedir = __( 'On', 'iq-block-country' );
703
  } else {
704
- $open_basedir = __( 'Off', 'iq-block-country' );
705
  }
706
  ?>
707
- <tbody><tr><td><?php _e( 'PHP open_basedir', 'iq-block-country' ); ?>: <strong><?php echo $open_basedir; ?></strong></td></tr></tbody>
708
  <?php
709
- if ( is_callable( 'xml_parser_create' ) ) {
710
- $xml = __( 'Yes', 'iq-block-country' );
711
  } else {
712
- $xml = __( 'No', 'iq-block-country' );
713
  }
714
  ?>
715
- <tbody><tr><td><?php _e( 'PHP XML Support', 'iq-block-country' ); ?>: <strong><?php echo $xml; ?></strong></td></tr></tbody>
716
  <?php
717
- if ( is_callable( 'iptcparse' ) ) {
718
- $iptc = __( 'Yes', 'iq-block-country' );
719
  } else {
720
- $iptc = __( 'No', 'iq-block-country' );
721
  }
722
  ?>
723
- <tbody><tr><td><?php _e( 'PHP IPTC Support', 'iq-block-country' ); ?>: <strong><?php echo $iptc; ?></strong></td></tr></tbody>
724
- <?php $disabled_functions = str_replace( ',', ', ', $disabled_functions ); // Normalize spaces or lack of spaces between disabled functions. ?>
725
- <tbody><tr><td><?php _e( 'Disabled PHP Functions', 'iq-block-country' ); ?>: <strong><?php echo $disabled_functions; ?></strong></td></tr></tbody>
726
 
727
 
728
  </table>
729
 
730
 
731
 
732
- <h3><?php _e('Wordpress info', 'iq-block-country'); ?></h3>
733
 
734
  <table class="widefat">
735
  <?php
736
- if ( is_multisite() ) {
737
- $multSite = __( 'is enabled', 'iq-block-country' );
738
  } else {
739
- $multSite = __( 'is disabled', 'iq-block-country' );
740
  }
741
  ?>
742
- <tbody><tr><td><?php _e( ' Multisite', 'iq-block-country' ); ?> <strong><?php echo $multSite; ?></strong></td></tr></tbody>
743
  <?php
744
- if ( get_option( 'permalink_structure' ) != '' ) {
745
- $permalink_structure = __( 'are enabled', 'iq-block-country' );
746
  } else {
747
- $permalink_structure = __( 'are disabled', 'iq-block-country' );
748
  }
749
  ?>
750
- <tbody><tr><td><?php _e( 'Permalinks', 'iq-block-country' ); ?>
751
- <strong> <?php echo $permalink_structure; ?></strong></td></tr></tbody>
752
- <tbody><tr><td><?php _e( 'Document Root Path', 'iq-block-country' ); ?>: <strong><?php echo WP_CONTENT_DIR ?></strong></td></tr></tbody>
753
  </table>
754
 
755
  <br />
756
  <br />
757
- <h3><?php _e('IP Address information', 'iq-block-country'); ?></h3>
758
 
759
  <?php
760
  echo "<br />HTTP_CF_CONNECTING_IP: ";
761
- if ( isset($_SERVER['HTTP_CF_CONNECTING_IP']) && !empty($_SERVER['HTTP_CF_CONNECTING_IP']) ) {
762
- echo $_SERVER['HTTP_CF_CONNECTING_IP'];
 
 
763
  }
764
- else { _e('Not set', 'iq-block-country'); }
765
  echo "<br />HTTP_X_SUCURI_CLIENTIP: ";
766
- if ( isset($_SERVER['HTTP_X_SUCURI_CLIENTIP']) && !empty($_SERVER['HTTP_X_SUCURI_CLIENTIP']) ) {
767
- echo $_SERVER['HTTP_X_SUCURI_CLIENTIP'];
 
 
768
  }
769
- else { _e('Not set', 'iq-block-country'); }
770
  echo "<br />HTTP_INCAP_CLIENT_IP: ";
771
- if ( isset($_SERVER['HTTP_INCAP_CLIENT_IP']) && !empty($_SERVER['HTTP_INCAP_CLIENT_IP']) ) {
772
- echo $_SERVER['HTTP_INCAP_CLIENT_IP'];
 
 
773
  }
774
- else { _e('Not set', 'iq-block-country'); }
775
  echo "<br />HTTP_X_FORWARDED_FOR: ";
776
- if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
777
- echo $_SERVER['HTTP_X_FORWARDED_FOR'];
778
  }
779
- else { _e('Not set', 'iq-block-country'); }
 
780
  echo "<br />HTTP_X_FORWARDED: ";
781
- if ( isset($_SERVER['HTTP_X_FORWARDED']) && !empty($_SERVER['HTTP_X_FORWARDED']) ) {
782
- echo $_SERVER['HTTP_X_FORWARDED'];
 
 
783
  }
784
- else { _e('Not set', 'iq-block-country'); }
785
  echo "<br />HTTP_CLIENT_IP: ";
786
- if ( isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP']) ) {
787
- echo $_SERVER['HTTP_CLIENT_IP'];
 
 
788
  }
789
- else { _e('Not set', 'iq-block-country'); }
790
  echo "<br />HTTP_X_REAL_IP: ";
791
- if ( isset($_SERVER['HTTP_X_REAL_IP']) && !empty($_SERVER['HTTP_X_REAL_IP']) ) {
792
- echo $_SERVER['HTTP_X_REAL_IP'];
793
  }
794
- else { _e('Not set', 'iq-block-country'); }
 
795
  echo "<br />HTTP_FORWARDED: ";
796
- if ( isset($_SERVER['HTTP_FORWARDED']) && !empty($_SERVER['HTTP_FORWARDED']) ) {
797
- echo $_SERVER['HTTP_FORWARDED'];
 
 
798
  }
799
- else { _e('Not set', 'iq-block-country'); }
800
  echo "<br />REMOTE_ADDR: ";
801
- if ( isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['REMOTE_ADDR']) ) {
802
- echo $_SERVER['REMOTE_ADDR'];
 
 
803
  }
804
- else { _e('Not set', 'iq-block-country'); }
805
 
806
  ?>
807
 
808
- <?php
809
  }
810
 
811
  /*
812
  * Function: Import/Export settings
813
  */
814
- function iqblockcountry_settings_importexport() {
815
- $dir = wp_upload_dir();
816
- if (!isset($_POST['export']) && !isset($_POST['import'])) {
 
817
  ?>
818
  <div class="wrap">
819
  <div id="icon-tools" class="icon32"><br /></div>
820
- <h2><?php _e('Export', 'iq-block-country'); ?></h2>
821
- <p><?php _e('When you click on <tt>Backup all settings</tt> button a backup of the iQ Block Country configuration will be created.', 'iq-block-country'); ?></p>
822
- <p><?php _e('After exporting, you can either use the backup file to restore your settings on this site again or copy the settings to another WordPress site.', 'iq-block-country'); ?></p>
823
  <form method='post'>
824
  <p class="submit">
825
  <?php wp_nonce_field('iqblockexport'); ?>
826
- <input type='submit' name='export' value='<?php _e('Backup all settings', 'iq-block-country'); ?>'/>
827
  </p>
828
  </form>
829
  </div>
830
 
831
  <div class="wrap">
832
  <div id="icon-tools" class="icon32"><br /></div>
833
- <h2><?php _e('Import', 'iq-block-country'); ?></h2>
834
- <p><?php _e('Click the browse button and choose a zip file that you exported before.', 'iq-block-country'); ?></p>
835
- <p><?php _e('Press Restore settings button, and let WordPress do the magic for you.', 'iq-block-country'); ?></p>
836
  <form method='post' enctype='multipart/form-data'>
837
  <p class="submit">
838
  <?php wp_nonce_field('iqblockimport'); ?>
839
- <input type='file' name='import' />
840
- <input type='submit' name='import' value='<?php _e('Restore settings', 'iq-block-country'); ?>'/>
841
  </p>
842
  </form>
843
  </div>
844
  <?php
845
  }
846
- elseif (isset($_POST['export'])) {
847
 
848
- $blogname = str_replace(" ", "", get_option('blogname'));
849
- $date = date("d-m-Y");
850
- $randstr=rand();
851
- $resultrand = sha1($randstr);
852
- $json_name = $blogname."-".$date . "-" . $resultrand; // Filename will be generated with random string.
853
 
854
- $optarr = iqblockcountry_get_options_arr();
855
- foreach ( $optarr as $options ) {
856
- $value = get_option($options);
857
- $need_options[$options] = $value;
858
  }
859
 
860
- $json_file = json_encode($need_options); // Encode data into json data
861
 
862
- if ( !$handle = fopen( $dir['path'] . '/' . 'iqblockcountry.ini', 'w' ) )
863
- wp_die(__("Something went wrong exporting this file", 'iq-block-country'));
 
864
 
865
- if ( !fwrite( $handle, $json_file ) )
866
- wp_die(__("Something went wrong exporting this file", 'iq-block-country'));
 
867
 
868
- fclose( $handle );
869
 
870
- chdir( $dir['path'] );
871
- $zipfiles = array('iqblockcountry.ini');
872
- $zipfilename = $dir['path'] . '/' . $json_name . '-iqblockcountry.zip';
873
- $zip = new ZipArchive;
874
- $zip->open($zipfilename, ZipArchive::CREATE);
875
- foreach ($zipfiles as $file) {
876
- $zip->addFile($file);
877
  }
878
- $zip->close();
879
- unlink($dir['path'] . '/iqblockcountry.ini');
880
 
881
- $url = $dir['url'] . '/' . $json_name . '-iqblockcountry.zip';
882
- $content = "<div class='notice notice-success'><p>" . __("Exporting settings...", 'iq-block-country') . "</p></div>";
883
 
884
- if ( $url ) {
885
- $content .= '<script type="text/javascript">
886
- document.location = \'' . $url . '\';
887
  </script>';
888
  } else {
889
- $content .= 'Error: ' . $url;
890
  }
891
- echo $content;
892
  }
893
- elseif (isset($_POST['import'])) {
894
- $optarr = iqblockcountry_get_options_arr();
895
- if (isset($_FILES['import']) && check_admin_referer('iqblockimport')) {
896
- if (($_FILES['import']['error'] > 0) && ($_FILES['type'] == "application/x-zip-compressed")) {
897
- wp_die(__("Something went wrong importing this file", 'iq-block-country'));
898
  }
899
  else
900
  {
901
- $zip = new ZipArchive;
902
- $res = $zip->open($_FILES['import']['tmp_name']);
903
- if ($res === TRUE) {
904
- $zip->extractTo($dir['path'], 'iqblockcountry.ini');
905
- $zip->close();
906
- } else {
907
- wp_die(__("Something went wrong importing this file", 'iq-block-country'));
908
- }
909
- if (file_exists($dir['path'] . '/iqblockcountry.ini'))
910
- {
911
- $encode_options = file_get_contents($dir['path'] . '/iqblockcountry.ini');
912
- $options = json_decode($encode_options, true);
913
- foreach ($options as $key => $value) {
914
- if (in_array($key,$optarr)) {
915
- update_option($key, $value);
916
- }
917
  }
918
- unlink($dir['path'] . '/iqblockcountry.ini');
919
-
920
- echo "<div class='notice notice-success'><p>" . __("All options are restored successfully.", 'iq-block-country') . "</p></div>";
921
  }
922
- else {
923
- wp_die(__("ZIP File did not contain any settings", 'iq-block-country'));
924
- }
 
 
 
 
925
  }
926
  }
927
  else {
928
- wp_die(__("Something went wrong importing this file", 'iq-block-country'));
929
  }
930
  }
931
- else { wp_die(__("No correct import or export option given.", 'iq-block-country')); }
 
932
 
933
  }
934
 
935
  /*
936
  * Function: Page settings
937
  */
938
- function iqblockcountry_settings_pages() {
 
939
  ?>
940
- <h3><?php _e('Select which pages are blocked.', 'iq-block-country'); ?></h3>
941
  <form method="post" action="options.php">
942
- <?php
943
- settings_fields ( 'iqblockcountry-settings-group-pages' );
944
- ?>
945
- <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
946
  <tr valign="top">
947
- <th width="30%"><?php _e('Do you want to block individual pages:', 'iq-block-country'); ?><br />
948
- <?php _e('If you do not select this option all pages will be blocked.', 'iq-block-country'); ?></th>
949
  <td width="70%">
950
- <input type="checkbox" name="blockcountry_blockpages" value="on" <?php checked('on', get_option('blockcountry_blockpages'), true); ?> />
951
  </td></tr>
952
 
953
 
954
  <tr valign="top">
955
- <th width="30%"><?php _e('Block pages selected below:', 'iq-block-country'); ?><br />
956
- <?php _e('Block all pages except those selected below', 'iq-block-country'); ?></th>
957
  <td width="70%">
958
- <input type="radio" name="blockcountry_blockpages_inverse" value="off" <?php checked('off', get_option('blockcountry_blockpages_inverse'), true); ?> <?php checked(FALSE, get_option('blockcountry_blockpages_inverse'), true); ?> /><br />
959
  <input type="radio" name="blockcountry_blockpages_inverse" value="on" <?php checked('on', get_option('blockcountry_blockpages_inverse'), true); ?> />
960
  </td></tr>
961
 
962
  <tr valign="top">
963
- <th width="30%"><?php _e('Select pages you want to block:', 'iq-block-country'); ?></th>
964
  <td width="70%">
965
 
966
- <ul>
967
  <?php
968
- $selectedpages = get_option('blockcountry_pages');
969
- $pages = get_pages();
970
- $selected = "";
971
- foreach ( $pages as $page ) {
972
- if (is_array($selectedpages)) {
973
- if ( in_array( $page->ID,$selectedpages) ) {
974
- $selected = " checked=\"checked\"";
975
- } else {
976
- $selected = "";
977
- }
978
- }
979
- echo "<li><input type=\"checkbox\" " . $selected . " name=\"blockcountry_pages[]\" value=\"" . $page->ID . "\" id=\"" . $page->post_title . "\" /> <label for=\"" . $page->post_title . "\">" . $page->post_title . "</label></li>";
980
- }
981
- ?>
982
  </td></tr>
983
  <tr><td></td><td>
984
- <p class="submit"><input type="submit" class="button-primary"
985
- value="<?php _e ( 'Save Changes', 'iq-block-country' )?>" /></p>
986
- </td></tr>
987
- </table>
988
  </form>
989
 
990
- <?php
991
  }
992
 
993
  /*
994
  * Function: Categories settings
995
  */
996
- function iqblockcountry_settings_categories() {
 
997
  ?>
998
- <h3><?php _e('Select which categories are blocked.', 'iq-block-country'); ?></h3>
999
  <form method="post" action="options.php">
1000
- <?php
1001
- settings_fields ( 'iqblockcountry-settings-group-cat' );
1002
- ?>
1003
- <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
1004
  <tr valign="top">
1005
- <th width="30%"><?php _e('Do you want to block individual categories:', 'iq-block-country'); ?><br />
1006
- <?php _e('If you do not select this option all blog articles will be blocked.', 'iq-block-country'); ?></th>
1007
  <td width="70%">
1008
- <input type="checkbox" name="blockcountry_blockcategories" value="on" <?php checked('on', get_option('blockcountry_blockcategories'), true); ?> />
1009
  </td></tr>
1010
  <tr valign="top">
1011
- <th width="30%"><?php _e('Do you want to block the homepage:', 'iq-block-country'); ?><br />
1012
- <?php _e('If you do not select this option visitors will not be blocked from your homepage regardless of the categories you select.', 'iq-block-country'); ?></th>
1013
  <td width="70%">
1014
- <input type="checkbox" name="blockcountry_blockhome" value="on" <?php checked('on', get_option('blockcountry_blockhome'), true); ?> />
1015
  </td></tr>
1016
  <tr valign="top">
1017
- <th width="30%"><?php _e('Select categories you want to block:', 'iq-block-country'); ?></th>
1018
  <td width="70%">
1019
 
1020
- <ul>
1021
  <?php
1022
- $selectedcategories = get_option('blockcountry_categories');
1023
- $categories = get_categories(array("hide_empty"=>0));
1024
- $selected = "";
1025
- foreach ( $categories as $category ) {
1026
- if (is_array($selectedcategories)) {
1027
- if ( in_array( $category->term_id,$selectedcategories) ) {
1028
- $selected = " checked=\"checked\"";
1029
- } else {
1030
- $selected = "";
1031
- }
1032
- }
1033
- echo "<li><input type=\"checkbox\" " . $selected . " name=\"blockcountry_categories[]\" value=\"" . $category->term_id . "\" id=\"" . $category->name . "\" /> <label for=\"" . $category->name . "\">" . $category->name . "</label></li>";
1034
- }
1035
- ?>
1036
  </td></tr>
1037
  <tr><td></td><td>
1038
- <p class="submit"><input type="submit" class="button-primary"
1039
- value="<?php _e ( 'Save Changes', 'iq-block-country' )?>" /></p>
1040
- </td></tr>
1041
- </table>
1042
  </form>
1043
 
1044
- <?php
1045
  }
1046
 
1047
  /*
1048
  * Function: Categories settings
1049
  */
1050
- function iqblockcountry_settings_tags() {
 
1051
  ?>
1052
- <h3><?php _e('Select which tags are blocked.', 'iq-block-country'); ?></h3>
1053
  <form method="post" action="options.php">
1054
- <?php
1055
- settings_fields ( 'iqblockcountry-settings-group-tags' );
1056
- ?>
1057
- <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
1058
  <tr valign="top">
1059
- <th width="30%"><?php _e('Do you want to block individual tags:', 'iq-block-country'); ?><br />
1060
- <?php _e('If you do not select this option all blog articles will be blocked.', 'iq-block-country'); ?></th>
1061
  <td width="70%">
1062
- <input type="checkbox" name="blockcountry_blocktags" value="on" <?php checked('on', get_option('blockcountry_blocktags'), true); ?> />
1063
  </td></tr>
1064
  <tr valign="top">
1065
- <th width="30%"><?php _e('Select tags you want to block:', 'iq-block-country'); ?></th>
1066
  <td width="70%">
1067
 
1068
- <ul>
1069
  <?php
1070
- $selectedtags = get_option('blockcountry_tags');
1071
- $tags = get_tags(array("hide_empty"=>0));
1072
- $selected = "";
1073
- foreach ( $tags as $tag ) {
1074
- if (is_array($selectedtags)) {
1075
- if ( in_array( $tag->term_id,$selectedtags) ) {
1076
- $selected = " checked=\"checked\"";
1077
- } else {
1078
- $selected = "";
1079
- }
1080
- }
1081
- echo "<li><input type=\"checkbox\" " . $selected . " name=\"blockcountry_tags[]\" value=\"" . $tag->term_id . "\" id=\"" . $tag->name . "\" /> <label for=\"" . $tag->name . "\">" . $tag->name . "</label></li>";
1082
- }
1083
- ?>
1084
  </td></tr>
1085
  <tr><td></td><td>
1086
- <p class="submit"><input type="submit" class="button-primary"
1087
- value="<?php _e ( 'Save Changes', 'iq-block-country' )?>" /></p>
1088
- </td></tr>
1089
- </table>
1090
  </form>
1091
 
1092
- <?php
1093
  }
1094
 
1095
 
1096
  /*
1097
  * Function: Custom post type settings
1098
  */
1099
- function iqblockcountry_settings_posttypes() {
 
1100
  ?>
1101
- <h3><?php _e('Select which post types are blocked.', 'iq-block-country'); ?></h3>
1102
  <form method="post" action="options.php">
1103
- <?php
1104
- settings_fields ( 'iqblockcountry-settings-group-posttypes' );
1105
- ?>
1106
- <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
1107
  <tr valign="top">
1108
- <th width="30%"><?php _e('Do you want to block individual post types:', 'iq-block-country'); ?><br />
1109
  <td width="70%">
1110
- <input type="checkbox" name="blockcountry_blockposttypes" value="on" <?php checked('on', get_option('blockcountry_blockposttypes'), true); ?> />
1111
  </td></tr>
1112
  <tr valign="top">
1113
- <th width="30%"><?php _e('Select post types you want to block:', 'iq-block-country'); ?></th>
1114
  <td width="70%">
1115
 
1116
- <ul>
1117
  <?php
1118
- $post_types = get_post_types( '', 'names' );
1119
- $selectedposttypes = get_option('blockcountry_posttypes');
1120
- $selected = "";
1121
- foreach ( $post_types as $post_type ) {
1122
- if (is_array($selectedposttypes)) {
1123
- if ( in_array( $post_type,$selectedposttypes) ) {
1124
- $selected = " checked=\"checked\"";
1125
- } else {
1126
- $selected = "";
1127
- }
1128
- }
1129
- echo "<li><input type=\"checkbox\" " . $selected . " name=\"blockcountry_posttypes[]\" value=\"" . $post_type . "\" id=\"" . $post_type . "\" /> <label for=\"" . $post_type . "\">" . $post_type . "</label></li>";
1130
- }
1131
- ?>
1132
  </td></tr>
1133
  <tr><td></td><td>
1134
- <p class="submit"><input type="submit" class="button-primary"
1135
- value="<?php _e ( 'Save Changes', 'iq-block-country' )?>" /></p>
1136
- </td></tr>
1137
- </table>
1138
  </form>
1139
 
1140
- <?php
1141
  }
1142
 
1143
 
@@ -1145,46 +1061,47 @@ function iqblockcountry_settings_posttypes() {
1145
  /*
1146
  * Function: Services settings
1147
  */
1148
- function iqblockcountry_settings_services() {
 
1149
  ?>
1150
- <h3><?php _e('Select which services are allowed.', 'iq-block-country'); ?></h3>
1151
  <form method="post" action="options.php">
1152
- <?php
1153
- settings_fields ( 'iqblockcountry-settings-group-se' );
1154
- ?>
1155
- <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
1156
  <tr valign="top">
1157
- <th width="30%"><?php _e('Select which services you want to allow:', 'iq-block-country'); ?><br />
1158
- <?php _e('This will allow a service like for instance a search engine to your site despite if you blocked the country.', 'iq-block-country'); ?><br />
1159
- <?php _e('Please note the "Search Engine Visibility" should not be selected in ', 'iq-block-country'); ?><a href="/wp-admin/options-reading.php"><?php _e('reading settings.', 'iq-block-country'); ?></a>
1160
  </th>
1161
  <td width="70%">
1162
 
1163
- <ul>
1164
  <?php
1165
- global $searchengines;
1166
- $selectedse = get_option('blockcountry_allowse');
1167
- $selected = "";
1168
- foreach ( $searchengines AS $se => $seua ) {
1169
- if (is_array($selectedse)) {
1170
- if ( in_array( $se,$selectedse) ) {
1171
- $selected = " checked=\"checked\"";
1172
- } else {
1173
- $selected = "";
1174
- }
1175
- }
1176
- echo "<li><input type=\"checkbox\" " . $selected . " name=\"blockcountry_allowse[]\" value=\"" . $se . "\" id=\"" . $se . "\" /> <label for=\"" . $se . "\">" . $se . "</label></li>";
1177
- }
1178
- ?>
1179
  </td></tr>
1180
  <tr><td></td><td>
1181
- <p class="submit"><input type="submit" class="button-primary"
1182
- value="<?php _e ( 'Save Changes', 'iq-block-country' )?>" /></p>
1183
- </td></tr>
1184
- </table>
1185
  </form>
1186
 
1187
- <?php
1188
  }
1189
 
1190
 
@@ -1193,112 +1110,109 @@ function iqblockcountry_settings_services() {
1193
  */
1194
  function iqblockcountry_settings_frontend()
1195
  {
1196
- ?>
1197
- <h3><?php _e('Frontend options', 'iq-block-country'); ?></h3>
1198
 
1199
  <form method="post" action="options.php">
1200
  <?php
1201
- settings_fields ( 'iqblockcountry-settings-group-frontend' );
1202
- if (!class_exists('GeoIP'))
1203
- {
1204
- include_once("geoip.inc");
1205
- }
1206
- if (class_exists('GeoIP'))
1207
- {
1208
- $countrylist = iqblockcountry_get_isocountries();
1209
-
1210
- $ip_address = iqblockcountry_get_ipaddress();
1211
- $country = iqblockcountry_check_ipaddress($ip_address);
1212
- if ($country == "Unknown" || $country == "ipv6" || $country == "" || $country == "FALSE")
1213
- { $displaycountry = "Unknown"; }
1214
- else { $displaycountry = $countrylist[$country]; }
1215
 
1216
- ?>
1217
 
1218
- <link rel="stylesheet" href=<?php echo "\"" . CHOSENCSS . "\""?> type="text/css" />
1219
 
1220
 
1221
- <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
1222
 
1223
  <tr valign="top">
1224
- <th width="30%"><?php _e('Block visitors from visiting the frontend of your website:', 'iq-block-country'); ?></th>
1225
  <td width="70%">
1226
- <input type="checkbox" name="blockcountry_blockfrontend" <?php checked('on', get_option('blockcountry_blockfrontend'), true); ?> />
1227
  </td></tr>
1228
 
1229
- <tr valign="top">
1230
- <th width="30%"><?php _e('Do not block visitors that are logged in from visiting frontend website:', 'iq-block-country'); ?></th>
1231
- <td width="70%">
1232
- <input type="checkbox" name="blockcountry_blocklogin" <?php checked('on', get_option('blockcountry_blocklogin'), true); ?> />
1233
- </td></tr>
1234
 
1235
  <tr valign="top">
1236
- <th width="30%"><?php _e('Block visitors from using the search function of your website:', 'iq-block-country'); ?></th>
1237
  <td width="70%">
1238
- <input type="checkbox" name="blockcountry_blocksearch" <?php checked('on', get_option('blockcountry_blocksearch'), true); ?> />
1239
  </td></tr>
1240
 
1241
  <tr valign="top">
1242
- <th width="30%"><?php _e('Block countries selected below:', 'iq-block-country'); ?><br />
1243
- <?php _e('Block all countries except those selected below', 'iq-block-country'); ?></th>
1244
  <td width="70%">
1245
- <input type="radio" name="blockcountry_banlist_inverse" value="off" <?php checked('off', get_option('blockcountry_banlist_inverse'), true); ?> <?php checked(FALSE, get_option('blockcountry_banlist_inverse'), true); ?> /><br />
1246
  <input type="radio" name="blockcountry_banlist_inverse" value="on" <?php checked('on', get_option('blockcountry_banlist_inverse'), true); ?> />
1247
  </td></tr>
1248
 
1249
  <tr valign="top">
1250
- <th scope="row" width="30%"><?php _e('Select the countries:', 'iq-block-country'); ?><br />
1251
- <?php _e('Use the CTRL key to select multiple countries', 'iq-block-country'); ?></th>
1252
- <td width="70%">
1253
 
1254
  <?php
1255
- $selected = "";
1256
- $haystack = get_option('blockcountry_banlist');
1257
 
1258
- if (get_option('blockcountry_accessibility'))
1259
- {
1260
  echo "<ul>";
1261
- foreach ( $countrylist as $key => $value ) {
1262
- if (is_array($haystack) && in_array ( $key, $haystack )) {
1263
- $selected = " checked=\"checked\"";
1264
- } else {
1265
- $selected = "";
1266
- }
1267
- echo "<li><input type=\"checkbox\" " . $selected . " name=\"blockcountry_banlist[]\" value=\"" . $key . "\" \"/> <label for=\"" . $value . "\">" . $value . "</label></li>";
1268
  }
1269
  echo "</ul>";
1270
  }
1271
  else
1272
  {
1273
- ?>
1274
 
1275
 
1276
  <select data-placeholder="Choose a country..." class="chosen" name="blockcountry_banlist[]" multiple="true" style="width:600px;">
1277
  <optgroup label="(de)select all countries">
1278
  <?php
1279
- foreach ( $countrylist as $key => $value ) {
1280
- print "<option value=\"$key\"";
1281
- if (is_array($haystack) && in_array ( $key, $haystack )) {
1282
- print " selected=\"selected\" ";
1283
- }
1284
- print ">$value</option>\n";
1285
- }
1286
  echo "</optgroup>";
1287
  echo " </select>";
1288
  }
1289
 
1290
- ?>
1291
  </td></tr>
1292
  <tr valign="top">
1293
- <th width="30%"><?php _e('Block tag pages:', 'iq-block-country'); ?><br />
1294
- <?php _e('If you select this option tag pages will be blocked.', 'iq-block-country')?></th>
1295
  <td width="70%">
1296
  <input type="checkbox" name="blockcountry_blocktag" <?php checked('on', get_option('blockcountry_blocktag'), true); ?> />
1297
  </td></tr>
1298
 
1299
  <tr valign="top">
1300
- <th width="30%"><?php _e('Block feed:', 'iq-block-country'); ?><br />
1301
- <?php _e('If you select this option feed pages will be blocked.', 'iq-block-country')?></th>
1302
  <td width="70%">
1303
  <input type="checkbox" name="blockcountry_blockfeed" <?php checked('on', get_option('blockcountry_blockfeed'), true); ?> />
1304
  </td></tr>
@@ -1306,33 +1220,33 @@ function iqblockcountry_settings_frontend()
1306
 
1307
 
1308
  <tr valign="top">
1309
- <th width="30%"><?php _e('Frontend allow list IPv4 and/or IPv6 addresses:', 'iq-block-country'); ?><br /><?php _e('Use a semicolon (;) to separate IP addresses', 'iq-block-country'); ?><br /><?php _e('This field accepts single IP addresses as well as ranges in CIDR format.', 'iq-block-country'); ?></th>
1310
- <td width="70%">
1311
- <?php
1312
- $frontendallowlist = get_option ( 'blockcountry_frontendwhitelist' );
1313
- ?>
1314
- <textarea cols="70" rows="5" name="blockcountry_frontendwhitelist"><?php echo htmlspecialchars($frontendallowlist); ?></textarea>
1315
- </td></tr>
1316
  <tr valign="top">
1317
- <th width="30%"><?php _e('Frontend block list IPv4 and/or IPv6 addresses:', 'iq-block-country'); ?><br /><?php _e('Use a semicolon (;) to separate IP addresses', 'iq-block-country'); ?><br /><?php _e('This field accepts single IP addresses as well as ranges in CIDR format.', 'iq-block-country'); ?></th>
1318
- <td width="70%">
1319
- <?php
1320
- $frontendblocklist = get_option ( 'blockcountry_frontendblacklist' );
1321
- ?>
1322
- <textarea cols="70" rows="5" name="blockcountry_frontendblacklist"><?php echo htmlspecialchars($frontendblocklist); ?></textarea>
1323
- </td></tr>
1324
- <tr><td></td><td>
1325
- <p class="submit"><input type="submit" class="button-primary"
1326
- value="<?php _e ( 'Save Changes', 'iq-block-country' )?>" /></p>
1327
- </td></tr>
1328
- </table>
1329
  </form>
1330
- <?php
1331
- }
1332
- else
1333
  {
1334
- print "<p>You are missing the GeoIP class. Perhaps geoip.inc is missing?</p>";
1335
- }
1336
 
1337
  }
1338
 
@@ -1342,127 +1256,122 @@ function iqblockcountry_settings_frontend()
1342
  */
1343
  function iqblockcountry_settings_backend()
1344
  {
1345
- ?>
1346
- <h3><?php _e('Backend Options', 'iq-block-country'); ?></h3>
1347
 
1348
  <form method="post" action="options.php">
1349
  <?php
1350
- settings_fields ( 'iqblockcountry-settings-group-backend' );
1351
- if (!class_exists('GeoIP'))
1352
- {
1353
- include_once("geoip.inc");
1354
- }
1355
- if (class_exists('GeoIP'))
1356
- {
1357
-
1358
- $countrylist = iqblockcountry_get_isocountries();
1359
-
1360
- $ip_address = iqblockcountry_get_ipaddress();
1361
- $country = iqblockcountry_check_ipaddress($ip_address);
1362
- if ($country == "Unknown" || $country == "ipv6" || $country == "" || $country == "FALSE")
1363
- { $displaycountry = "Unknown"; }
1364
- else { $displaycountry = $countrylist[$country]; }
1365
 
1366
 
1367
- ?>
1368
-
1369
- <link rel="stylesheet" href=<?php echo "\"" . CHOSENCSS . "\""?> type="text/css" />
1370
-
1371
 
1372
- <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
1373
- <tr valign="top">
1374
- <th width="30%"><?php _e('Block visitors from visiting the backend (administrator) of your website:', 'iq-block-country'); ?></th>
1375
- <td width="70%">
1376
- <input type="checkbox" name="blockcountry_blockbackend" <?php checked('on', get_option('blockcountry_blockbackend'), true); ?> />
1377
  </td></tr>
1378
 
1379
  <tr>
1380
  <th width="30%"></th>
1381
  <th width="70%">
1382
- <?php _e('Your IP address is', 'iq-block-country'); ?> <i><?php echo $ip_address ?></i>. <?php _e('The country that is listed for this IP address is', 'iq-block-country'); ?> <em><?php echo $displaycountry ?></em>.<br />
1383
- <?php _e('Do <strong>NOT</strong> set the \'Block visitors from visiting the backend (administrator) of your website\' and also select', 'iq-block-country'); ?> <?php echo $displaycountry ?> <?php _e('below.', 'iq-block-country'); ?><br />
1384
- <?php echo "<strong>" . __('You will NOT be able to login the next time if you DO block your own country from visiting the backend.', 'iq-block-country') . "</strong>"; ?>
1385
  </th>
1386
  </tr>
1387
- </td></tr>
1388
  <tr valign="top">
1389
- <th width="30%"><?php _e('Block countries selected below:', 'iq-block-country'); ?><br />
1390
- <?php _e('Block all countries except those selected below', 'iq-block-country'); ?></th>
1391
  <td width="70%">
1392
- <input type="radio" name="blockcountry_backendbanlist_inverse" value="off" <?php checked('off', get_option('blockcountry_backendbanlist_inverse'), true); ?> <?php checked(FALSE, get_option('blockcountry_backendbanlist_inverse'), true); ?> /><br />
1393
  <input type="radio" name="blockcountry_backendbanlist_inverse" value="on" <?php checked('on', get_option('blockcountry_backendbanlist_inverse'), true); ?> />
1394
  </td></tr>
1395
 
1396
  <tr valign="top">
1397
- <th scope="row" width="30%"><?php _e('Select the countries:', 'iq-block-country'); ?><br />
1398
- <?php _e('Use the CTRL key to select multiple countries', 'iq-block-country'); ?></th>
1399
- <td width="70%">
1400
 
1401
  <?php
1402
- $selected = "";
1403
- $haystack = get_option ( 'blockcountry_backendbanlist' );
1404
-
1405
- if (get_option('blockcountry_accessibility'))
1406
- {
1407
- echo "<ul>";
1408
- foreach ( $countrylist as $key => $value ) {
1409
- if (is_array($haystack) && in_array ( $key, $haystack )) {
1410
- $selected = " checked=\"checked\"";
1411
- } else {
1412
- $selected = "";
1413
- }
1414
- echo "<li><input type=\"checkbox\" " . $selected . " name=\"blockcountry_backendbanlist[]\" value=\"" . $key . "\" \"/> <label for=\"" . $value . "\">" . $value . "</label></li>";
1415
- }
1416
- echo "</ul>";
1417
- }
1418
- else
1419
- {
1420
- ?> <select class="chosen" data-placeholder="Choose a country..." name="blockcountry_backendbanlist[]" multiple="true" style="width:600px;">
1421
  <optgroup label="(de)select all countries">
1422
 
1423
- <?php
1424
- foreach ( $countrylist as $key => $value ) {
1425
- print "<option value=\"$key\"";
1426
- if (is_array($haystack) && in_array ( $key, $haystack )) {
1427
- print " selected=\"selected\" ";
1428
- }
1429
- print ">$value</option>\n";
1430
  }
1431
  echo "</optgroup>";
1432
  echo " </select>";
1433
- }
1434
- ?>
1435
 
1436
  </td></tr>
1437
 
1438
  <tr valign="top">
1439
- <th width="30%"><?php _e('Backend allow list IPv4 and/or IPv6 addresses:', 'iq-block-country'); ?><br /><?php _e('Use a semicolon (;) to separate IP addresses', 'iq-block-country'); ?><br /><?php _e('This field accepts single IP addresses as well as ranges in CIDR format.', 'iq-block-country'); ?></th>
1440
- <td width="70%">
1441
- <?php
1442
- $backendallowlist = get_option ( 'blockcountry_backendwhitelist' );
1443
- ?>
1444
- <textarea cols="70" rows="5" name="blockcountry_backendwhitelist"><?php echo htmlspecialchars($backendallowlist); ?></textarea>
1445
- </td></tr>
1446
  <tr valign="top">
1447
- <th width="30%"><?php _e('Backend block list IPv4 and/or IPv6 addresses:', 'iq-block-country'); ?><br /><?php _e('Use a semicolon (;) to separate IP addresses', 'iq-block-country'); ?><br /><?php _e('This field accepts single IP addresses as well as ranges in CIDR format.', 'iq-block-country'); ?></th>
1448
- <td width="70%">
1449
- <?php
1450
- $backendblocklist = get_option ( 'blockcountry_backendblacklist' );
1451
- ?>
1452
- <textarea cols="70" rows="5" name="blockcountry_backendblacklist"><?php echo htmlspecialchars($backendblocklist); ?></textarea>
1453
- </td></tr>
1454
- <tr><td></td><td>
1455
- <p class="submit"><input type="submit" class="button-primary"
1456
- value="<?php _e ( 'Save Changes', 'iq-block-country' )?>" /></p>
1457
- </td></tr>
1458
- </table>
1459
  </form>
1460
- <?php
1461
- }
1462
- else
1463
  {
1464
- print "<p>You are missing the GeoIP class. Perhaps geoip.inc is missing?</p>";
1465
- }
1466
 
1467
  }
1468
 
@@ -1474,246 +1383,243 @@ function iqblockcountry_settings_backend()
1474
  function iqblockcountry_settings_home()
1475
  {
1476
 
1477
- /* Check if the Geo Database exists or if GeoIP API key is entered otherwise display notification */
1478
- if (is_file ( GEOIP2DBFILE ) && (!get_option('blockcountry_geoapikey'))) {
1479
- $iqfiledate = filemtime(GEOIP2DBFILE);
1480
- $iq3months = time() - 3 * 31 * 86400;
1481
- if ($iqfiledate < $iq3months)
1482
- {
1483
- iq_old_db_notice();
1484
- }
1485
- }
1486
 
1487
 
1488
- ?>
1489
- <h3><?php _e('Overall statistics since start', 'iq-block-country'); ?></h3>
1490
 
1491
- <?php $blocked = get_option('blockcountry_backendnrblocks'); ?>
1492
- <p><?php echo number_format($blocked); ?> <?php _e('visitors blocked from the backend.', 'iq-block-country'); ?></p>
1493
- <?php $blocked = get_option('blockcountry_frontendnrblocks'); ?>
1494
- <p><?php echo number_format($blocked); ?> <?php _e('visitors blocked from the frontend.', 'iq-block-country'); ?></p>
1495
 
1496
  <form method="post" action="options.php">
1497
  <?php
1498
- settings_fields ( 'iqblockcountry-settings-group' );
1499
- if (!class_exists('GeoIP'))
1500
- {
1501
- include_once("geoip.inc");
1502
- }
1503
- if (class_exists('GeoIP'))
1504
- {
1505
- $countrylist = iqblockcountry_get_isocountries();
1506
- ?>
1507
-
1508
- <link rel="stylesheet" href=<?php echo "\"" . CHOSENCSS . "\""?> type="text/css" />
1509
 
1510
  <hr>
1511
- <h3><?php _e('Block type', 'iq-block-country'); ?></h3>
1512
  <em>
1513
- <?php _e('You should choose one of the 3 block options below. This wil either show a block message, redirect to an internal page or redirect to an external page.', 'iq-block-country'); ?>
1514
  </em>
1515
- <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
1516
 
1517
  <tr valign="top">
1518
- <th width="30%"><?php _e('Message to display when people are blocked:', 'iq-block-country'); ?></th>
1519
- <td width="70%">
1520
- <?php
1521
- $blockmessage = get_option ( 'blockcountry_blockmessage' );
1522
- if (empty($blockmessage)) { $blockmessage = "Forbidden - Visitors from your country are not permitted to browse this site."; }
1523
- ?>
1524
- <textarea cols="100" rows="3" name="blockcountry_blockmessage"><?php echo $blockmessage; ?></textarea>
1525
- </td></tr>
 
1526
 
1527
 
1528
  <tr valign="top">
1529
- <th width="30%"><?php _e('Page to redirect to:', 'iq-block-country'); ?><br />
1530
- <em><?php _e('If you select a page here blocked visitors will be redirected to this page instead of displaying above block message.', 'iq-block-country'); ?></em></th>
1531
  </th>
1532
- <td width="70%">
1533
  <select class="chosen" name="blockcountry_redirect" style="width:400px;">
1534
  <?php
1535
- $haystack = get_option ( 'blockcountry_redirect' );
1536
- echo "<option value=\"0\">". __("Choose a page...", 'iq-block-country') . "</option>";
1537
- $pages = get_pages();
1538
- foreach ( $pages as $page ) {
1539
- print "<option value=\"$page->ID\"";
1540
- if ($page->ID == $haystack) {
1541
-
1542
- print " selected=\"selected\" ";
1543
- }
1544
- print ">$page->post_title</option>\n";
1545
- }
1546
- ?>
1547
  </select>
1548
  </td></tr>
1549
 
1550
  <tr valign="top">
1551
- <th width="30%"><?php _e('URL to redirect to:', 'iq-block-country'); ?><br />
1552
- <em><?php _e('If you enter a URL here blocked visitors will be redirected to this URL instead of displaying above block message or redirected to a local page.', 'iq-block-country'); ?></em>
1553
  </th>
1554
  <td width="70%">
1555
- <input type="text" style="width:100%" name="blockcountry_redirect_url" value="<?php echo get_option ( 'blockcountry_redirect_url' );?>">
1556
  </td></tr>
1557
  </table>
1558
  <hr>
1559
- <h3><?php _e('General settings', 'iq-block-country'); ?></h3>
1560
 
1561
- <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
1562
  <tr valign="top">
1563
- <th width="30%"><?php _e('Send headers when user is blocked:', 'iq-block-country'); ?><br />
1564
- <em><?php _e('Under normal circumstances you should keep this selected! Only if you have "Cannot modify header information - headers already sent" errors or if you know what you are doing uncheck this.', 'iq-block-country'); ?></em></th>
1565
- <td width="70%">
1566
- <input type="checkbox" name="blockcountry_header" <?php checked('on', get_option('blockcountry_header'), true); ?> />
1567
- </td></tr>
1568
 
1569
  <tr valign="top">
1570
- <th width="30%"><?php _e('Buffer output?:', 'iq-block-country'); ?><br />
1571
- <em><?php _e('You can use this option to buffer all output. This can be helpful in case you have "headers already sent" issues.', 'iq-block-country'); ?></em></th>
1572
- <td width="70%">
1573
- <input type="checkbox" name="blockcountry_buffer" <?php checked('on', get_option('blockcountry_buffer'), true); ?> />
1574
- </td></tr>
1575
 
1576
- <tr valign="top">
1577
- <th width="30%"><?php _e('Do not log IP addresses:', 'iq-block-country'); ?><br />
1578
- <em><?php _e('Check this box if the laws in your country do not permit you to log IP addresses or if you do not want to log the ip addresses.', 'iq-block-country'); ?></em></th>
1579
- <td width="70%">
1580
- <input type="checkbox" name="blockcountry_logging" <?php checked('on', get_option('blockcountry_logging'), true); ?> />
1581
- </td></tr>
1582
-
1583
- <tr valign="top">
1584
- <th width="30%"><?php _e('Do not block admin-ajax.php:', 'iq-block-country'); ?><br />
1585
- <em><?php _e('Check this box if you use a plugin that uses admin-ajax.php.', 'iq-block-country'); ?></em></th>
1586
- <td width="70%">
1587
- <input type="checkbox" name="blockcountry_adminajax" <?php checked('on', get_option('blockcountry_adminajax'), true); ?> />
1588
- </td></tr>
1589
 
1590
 
1591
 
1592
 
1593
  <tr valign="top">
1594
- <th width="30%"><?php _e('Number of rows on logging tab:', 'iq-block-country'); ?><br />
1595
- <em><?php _e('How many rows do you want to display on each column on the logging tab.', 'iq-block-country'); ?></em></th>
1596
- <td width="70%">
1597
- <?php
1598
- $nrrows = get_option('blockcountry_nrstatistics'); ?>
1599
  <select name="blockcountry_nrstatistics">
1600
- <option <?php selected( $nrrows, 10 ); ?> value="10">10</option>
1601
- <option <?php selected( $nrrows, 15 ); ?> value="15">15</option>
1602
- <option <?php selected( $nrrows, 20 ); ?> value="20">20</option>
1603
- <option <?php selected( $nrrows, 25 ); ?> value="25">25</option>
1604
- <option <?php selected( $nrrows, 30 ); ?> value="30">30</option>
1605
- <option <?php selected( $nrrows, 45 ); ?> value="45">45</option>
1606
  </select>
1607
- </td></tr>
1608
 
1609
  <tr valign="top">
1610
- <th width="30%"><?php _e('Number of days to keep logging:', 'iq-block-country'); ?><br />
1611
- <em><?php _e('How many days do you want to keep the logging used for the logging tab.', 'iq-block-country'); ?></em></th>
1612
- <td width="70%">
1613
- <?php
1614
- $nrdays = get_option('blockcountry_daysstatistics'); ?>
1615
  <select name="blockcountry_daysstatistics">
1616
- <option <?php selected( $nrdays, 7 ); ?> value="7">7</option>
1617
- <option <?php selected( $nrdays, 14 ); ?> value="14">14</option>
1618
- <option <?php selected( $nrdays, 21 ); ?> value="21">21</option>
1619
- <option <?php selected( $nrdays, 30 ); ?> value="30">30</option>
1620
- <option <?php selected( $nrdays, 60 ); ?> value="60">60</option>
1621
- <option <?php selected( $nrdays, 90 ); ?> value="90">90</option>
1622
  </select>
1623
- </td></tr>
1624
-
1625
- <tr valign="top">
1626
- <th width="30%"><?php _e('Do not lookup hosts on the logging tab:', 'iq-block-country'); ?><br />
1627
- <em><?php _e('On some hosting environments looking up hosts may slow down the logging tab.', 'iq-block-country'); ?></em></th>
1628
- <td width="70%">
1629
- <input type="checkbox" name="blockcountry_lookupstatistics" <?php checked('on', get_option('blockcountry_lookupstatistics'), true); ?> />
1630
- </td></tr>
1631
 
1632
- <tr valign="top">
1633
- <th width="30%"><?php _e('Allow tracking:', 'iq-block-country'); ?><br />
1634
- <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>
1635
- <td width="70%">
1636
- <input type="checkbox" name="blockcountry_tracking" <?php checked('on', get_option('blockcountry_tracking'), true); ?> />
1637
- </td></tr>
1638
 
1639
  <tr valign="top">
1640
- <th width="30%"><?php _e('GeoIP API Key:', 'iq-block-country'); ?><br />
1641
- <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://webence.nl/geoip-api/" target="_blank">https://webence.nl/geoip-api/</a></em></th>
1642
  </th>
1643
  <td width="70%">
1644
- <input type="text" size="25" name="blockcountry_geoapikey" value="<?php echo get_option ( 'blockcountry_geoapikey' );?>">
1645
  </td></tr>
1646
 
1647
 
1648
  <tr valign="top">
1649
- <th width="30%"><?php _e('GeoIP API Key Server Location:', 'iq-block-country'); ?><br />
1650
- <em><?php _e('Choose a location closest to your own location.', 'iq-block-country'); ?>
1651
  </th>
1652
- <td width="70%">
1653
 
1654
  <input type="radio" name="blockcountry_geoapilocation" value="EU" <?php checked('EU', get_option('blockcountry_geoapilocation'), true); ?>> Europe (Netherlands)<br />
1655
- <input type="radio" name="blockcountry_geoapilocation" value="EU3" <?php checked('EU3', get_option('blockcountry_geoapilocation'), true); ?>> Europe (Germany)<br />
1656
  <input type="radio" name="blockcountry_geoapilocation" value="US" <?php checked('US', get_option('blockcountry_geoapilocation'), true); ?>> United States - New York<br />
1657
  <input type="radio" name="blockcountry_geoapilocation" value="US2" <?php checked('US2', get_option('blockcountry_geoapilocation'), true); ?>> United States - San Francisco<br />
1658
  <input type="radio" name="blockcountry_geoapilocation" value="US3" <?php checked('US3', get_option('blockcountry_geoapilocation'), true); ?>> United States - Miami<br />
1659
 
1660
- </td></tr>
1661
  <tr valign="top">
1662
- <th width="30%"><?php _e('Admin block API Key:', 'iq-block-country'); ?><br />
1663
- <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://webence.nl/admin-block-api/" target="_blank">https://webence.nl/admin-block-api/</a></em></th>
1664
  </th>
1665
- <td width="70%">
1666
- <input type="text" size="25" name="blockcountry_apikey" value="<?php echo get_option ( 'blockcountry_apikey' );?>">
1667
- </td></tr>
1668
 
1669
 
1670
- <tr valign="top">
1671
- <th width="30%"><?php _e('Accessibility options:', 'iq-block-country'); ?><br />
1672
- <em><?php _e('Set this option if you cannot use the default country selection box.', 'iq-block-country'); ?></em></th>
1673
- <td width="70%">
1674
- <input type="checkbox" name="blockcountry_accessibility" <?php checked('on', get_option('blockcountry_accessibility'), true); ?> />
1675
- </td></tr>
1676
 
1677
  <tr valign="top">
1678
- <th width="30%"><?php _e('Override IP information:', 'iq-block-country'); ?><br />
1679
- <em><?php _e('This option allows you to override how iQ Block Country gets the real IP of your visitors.', 'iq-block-country'); ?></em></th>
1680
- <td width="70%">
1681
- <?php
1682
- $ipoverride = get_option('blockcountry_ipoverride'); ?>
1683
  <select name="blockcountry_ipoverride">
1684
- <option <?php selected( $ipoverride, "NONE" ); ?> value="NONE">No override</option>
1685
- <option <?php selected( $ipoverride, "REMOTE_ADDR" ); ?> value="REMOTE_ADDR">REMOTE_ADDR</option>
1686
- <option <?php selected( $ipoverride, "HTTP_FORWARDED" ); ?> value="HTTP_FORWARDED">HTTP_FORWARDED</option>
1687
- <option <?php selected( $ipoverride, "HTTP_X_REAL_IP" ); ?> value="HTTP_X_REAL_IP">HTTP_X_REAL_IP</option>
1688
- <option <?php selected( $ipoverride, "HTTP_CLIENT_IP" ); ?> value="HTTP_CLIENT_IP">HTTP_CLIENT_IP</option>
1689
- <option <?php selected( $ipoverride, "HTTP_X_FORWARDED" ); ?> value="HTTP_X_FORWARDED">HTTP_X_FORWARDED</option>
1690
- <option <?php selected( $ipoverride, "HTTP_X_FORWARDED_FOR" ); ?> value="HTTP_X_FORWARDED_FOR">HTTP_X_FORWARDED_FOR</option>
1691
- <option <?php selected( $ipoverride, "HTTP_INCAP_CLIENT_IP" ); ?> value="HTTP_INCAP_CLIENT_IP">HTTP_X_FORWARDED</option>
1692
- <option <?php selected( $ipoverride, "HTTP_X_SUCURI_CLIENTIP" ); ?> value="HTTP_X_SUCURI_CLIENTIP">HTTP_X_SUCURI_CLIENTIP</option>
1693
- <option <?php selected( $ipoverride, "HTTP_CF_CONNECTING_IP" ); ?> value="HTTP_CF_CONNECTING_IP">HTTP_CF_CONNECTING_IP</option>
1694
  </select>
1695
- </td></tr>
1696
 
1697
  <tr valign="top">
1698
- <th width="30%"><?php _e('Log all visits:', 'iq-block-country'); ?><br />
1699
- <em><?php _e('This logs all visits despite if they are blocked or not. This is only for debugging purposes.', 'iq-block-country'); ?></em></th>
1700
- <td width="70%">
1701
- <input type="checkbox" name="blockcountry_debuglogging" <?php checked('on', get_option('blockcountry_debuglogging'), true); ?> />
1702
- </td></tr>
1703
 
1704
 
1705
  <tr><td></td><td>
1706
- <p class="submit"><input type="submit" class="button-primary"
1707
- value="<?php _e ( 'Save Changes', 'iq-block-country' )?>" /></p>
1708
- </td></tr>
1709
- </table>
1710
  </form>
1711
- <?php
1712
- }
1713
- else
1714
  {
1715
- print "<p>You are missing the GeoIP class. Perhaps geoip.inc is missing?</p>";
1716
- }
1717
  }
1718
 
1719
  /*
@@ -1722,118 +1628,126 @@ if (is_file ( GEOIP2DBFILE ) && (!get_option('blockcountry_geoapikey'))) {
1722
  function iqblockcountry_settings_logging()
1723
  {
1724
  ?>
1725
- <h3><?php _e('Last blocked visits', 'iq-block-country'); ?></h3>
1726
- <?php
1727
- if (!get_option('blockcountry_logging'))
1728
- {
1729
 
1730
 
1731
- global $wpdb;
1732
-
1733
- $table_name = $wpdb->prefix . "iqblock_logging";
1734
- $format = get_option('date_format') . ' ' . get_option('time_format');
1735
- $nrrows = get_option('blockcountry_nrstatistics');
1736
- $lookupstats = get_option('blockcountry_lookupstatistics');
1737
- if ($nrrows == "") { $nrrows = 15;};
1738
- $countrylist = iqblockcountry_get_isocountries();
1739
- echo '<table class="widefat">';
1740
- echo '<thead><tr><th>' . __('Date / Time', 'iq-block-country') . '</th><th>' . __('IP Address', 'iq-block-country') . '</th><th>' . __('Hostname', 'iq-block-country') . '</th><th>' . __('URL', 'iq-block-country') . '</th><th>' . __('Country', 'iq-block-country') . '</th><th>' . __('Frontend/Backend', 'iq-block-country') . '</th></tr></thead>';
1741
- foreach ($wpdb->get_results( "SELECT * FROM $table_name ORDER BY datetime DESC LIMIT $nrrows" ) as $row)
1742
- {
1743
- $countryimage = "icons/" . strtolower($row->country) . ".png";
1744
- $countryurl = '<img src="' . plugins_url( $countryimage , dirname(__FILE__) ) . '" > ';
1745
- echo "<tbody><tr><td>";
1746
- $datetime = strtotime($row->datetime);
1747
- $mysqldate = date($format, $datetime);
1748
- if ($lookupstats)
1749
- {
1750
- if (extension_loaded('mbstring')) {
1751
- echo $mysqldate . '</td><td>' . $row->ipaddress . '</td><td>' . $row->ipaddress . 'S</td><td>' . mb_strimwidth($row->url,0,75,'...') . '</td><td>' . $countryurl . $countrylist[$row->country] . '<td>';
1752
- }
1753
- else
1754
- {
1755
- echo $mysqldate . '</td><td>' . $row->ipaddress . '</td><td>' . $row->ipaddress . 'S</td><td>' . $row->url . '</td><td>' . $countryurl . $countrylist[$row->country] . '<td>';
 
1756
 
1757
- }
1758
- }
1759
- else
1760
- {
1761
- if (extension_loaded('mbstring')) {
1762
- echo $mysqldate . '</td><td>' . $row->ipaddress . '</td><td>' . htmlspecialchars(gethostbyaddr( $row->ipaddress )) . '</td><td>' . mb_strimwidth($row->url,0,75,'...') . '</td><td>' . $countryurl . $countrylist[$row->country] . '<td>';
1763
- }
1764
- else {
1765
- echo $mysqldate . '</td><td>' . $row->ipaddress . '</td><td>' . htmlspecialchars(gethostbyaddr( $row->ipaddress )) . '</td><td>' . $row->url . '</td><td>' . $countryurl . $countrylist[$row->country] . '<td>';
1766
- }
1767
- }
1768
- 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'); }
1769
- echo "</td></tr></tbody>";
1770
- }
1771
- echo '</table>';
 
 
 
 
1772
 
1773
 
1774
- echo '<hr>';
1775
- echo '<h3>' . __('Top countries that are blocked', 'iq-block-country') . '</h3>';
1776
- echo '<table class="widefat">';
1777
- echo '<thead><tr><th>' . __('Country', 'iq-block-country') . '</th><th>' . __('# of blocked attempts', 'iq-block-country') . '</th></tr></thead>';
1778
-
1779
- 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)
1780
- {
1781
- $countryimage = "icons/" . strtolower($row->country) . ".png";
1782
- $countryurl = '<img src="' . plugins_url( $countryimage , dirname(__FILE__) ) . '" > ';
1783
- echo "<tbody><tr><td>" . $countryurl . $countrylist[$row->country] . "</td><td>" . $row->count . "</td></tr></tbody>";
1784
- }
1785
- echo '</table>';
 
1786
 
1787
- echo '<hr>';
1788
- echo '<h3>' . __('Top hosts that are blocked', 'iq-block-country') . '</h3>';
1789
- echo '<table class="widefat">';
1790
- echo '<thead><tr><th>' . __('IP Address', 'iq-block-country') . '</th><th>' . __('Hostname', 'iq-block-country') . '</th><th>' . __('# of blocked attempts', 'iq-block-country') . '</th></tr></thead>';
1791
-
1792
- 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)
1793
- {
1794
- if ($lookupstats)
1795
- {
1796
- echo "<tbody><tr><td>" . $row->ipaddress . "</td><td>" . $row->ipaddress . "</td><td>" . $row->count . "</td></tr></tbody>";
1797
- }
1798
- else
1799
- {
1800
- echo "<tbody><tr><td>" . $row->ipaddress . "</td><td>" . htmlspecialchars(gethostbyaddr($row->ipaddress)) . "</td><td>" . $row->count . "</td></tr></tbody>";
1801
 
1802
- }
1803
 
1804
 
1805
- }
1806
- echo '</table>';
1807
-
1808
- echo '<hr>';
1809
- echo '<h3>' . __('Top URLs that are blocked', 'iq-block-country') . '</h3>';
1810
- echo '<table class="widefat">';
1811
- echo '<thead><tr><th>' . __('URL', 'iq-block-country') . '</th><th>' . __('# of blocked attempts', 'iq-block-country') . '</th></tr></thead>';
1812
-
1813
- 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)
1814
- {
1815
- echo "<tbody><tr><td>" . $row->url . "</td><td>" . $row->count . "</td></tr></tbody>";
1816
- }
1817
- echo '</table>';
 
1818
 
1819
- ?>
1820
  <form name="cleardatabase" action="#" method="post">
1821
- <input type="hidden" name="action" value="cleardatabase" />
1822
- <input name="cleardatabase_nonce" type="hidden" value="<?php echo wp_create_nonce('cleardatabase_nonce'); ?>" />
1823
 
1824
- <?php
1825
- echo '<div class="submit"><input type="submit" name="test" value="' . __( 'Clear database', 'iq-block-country' ) . '" /></div>';
1826
  wp_nonce_field('iqblockcountry');
1827
 
1828
- if ( isset($_POST['action']) && $_POST[ 'action' ] == 'cleardatabase') {
1829
- if (!isset($_POST['cleardatabase_nonce'])) die("Failed security check.");
1830
- if (!wp_verify_nonce($_POST['cleardatabase_nonce'],'cleardatabase_nonce')) die("Is this a CSRF attempt?");
 
 
1831
  global $wpdb;
1832
- $table_name = $wpdb->prefix . "iqblock_logging";
1833
- $sql = "TRUNCATE " . $table_name . ";";
1834
- $wpdb->query($sql);
1835
- $sql = "ALTER TABLE ". $table_name . " AUTO_INCREMENT = 1;";
1836
- $wpdb->query($sql);
1837
  echo "Cleared database";
1838
 
1839
  }
@@ -1841,49 +1755,51 @@ function iqblockcountry_settings_logging()
1841
  ?>
1842
  </form>
1843
 
1844
- <form name="csvoutput" action="#" method="post">
1845
- <input type="hidden" name="action" value="csvoutput" />
1846
- <input name="csv_nonce" type="hidden" value="<?php echo wp_create_nonce('csv_nonce'); ?>" />
1847
  <?php
1848
- echo '<div class="submit"><input type="submit" name="submit" value="' . __( 'Download as CSV file', 'iq-block-country' ) . '" /></div>';
1849
- wp_nonce_field('iqblockcountrycsv');
1850
  echo '</form>';
1851
- }
1852
- else
1853
- {
1854
- echo "<hr><h3>";
1855
- _e('You are not logging any information. Please uncheck the option \'Do not log IP addresses\' if this is not what you want.', 'iq-block-country');
1856
- echo "<hr></h3>";
1857
- }
1858
  }
1859
 
1860
 
1861
  /*
1862
  * Create the settings page.
1863
  */
1864
- function iqblockcountry_settings_page() {
 
1865
 
1866
 
1867
- if( isset( $_GET[ 'tab' ] ) ) {
1868
- $active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'home';
1869
- }
1870
- else
1871
  {
1872
- $active_tab = 'home';
1873
- }
1874
- ?>
1875
 
1876
  <h2 class="nav-tab-wrapper">
1877
- <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=home" class="nav-tab <?php echo $active_tab == 'home' ? 'nav-tab-active' : ''; ?>"><?php _e('Home', 'iq-block-country'); ?></a>
1878
- <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=frontend" class="nav-tab <?php echo $active_tab == 'frontend' ? 'nav-tab-active' : ''; ?>"><?php _e('Frontend', 'iq-block-country'); ?></a>
1879
- <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=backend" class="nav-tab <?php echo $active_tab == 'backend' ? 'nav-tab-active' : ''; ?>"><?php _e('Backend', 'iq-block-country'); ?></a>
1880
- <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=pages" class="nav-tab <?php echo $active_tab == 'pages' ? 'nav-tab-active' : ''; ?>"><?php _e('Pages', 'iq-block-country'); ?></a>
1881
- <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=categories" class="nav-tab <?php echo $active_tab == 'categories' ? 'nav-tab-active' : ''; ?>"><?php _e('Categories', 'iq-block-country'); ?></a>
1882
- <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=tags" class="nav-tab <?php echo $active_tab == 'tags' ? 'nav-tab-active' : ''; ?>"><?php _e('Tags', 'iq-block-country'); ?></a> <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=posttypes" class="nav-tab <?php echo $active_tab == 'posttypes' ? 'nav-tab-active' : ''; ?>"><?php _e('Post types', 'iq-block-country'); ?></a>
1883
- <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=services" class="nav-tab <?php echo $active_tab == 'services' ? 'nav-tab-active' : ''; ?>"><?php _e('Services', 'iq-block-country'); ?></a>
1884
- <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=tools" class="nav-tab <?php echo $active_tab == 'tools' ? 'nav-tab-active' : ''; ?>"><?php _e('Tools', 'iq-block-country'); ?></a>
1885
- <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=logging" class="nav-tab <?php echo $active_tab == 'logging' ? 'nav-tab-active' : ''; ?>"><?php _e('Logging', 'iq-block-country'); ?></a>
1886
- <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=export" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Import/Export', 'iq-block-country'); ?></a>
 
1887
  </h2>
1888
 
1889
 
@@ -1892,44 +1808,34 @@ function iqblockcountry_settings_page() {
1892
 
1893
  <hr />
1894
  <?php
1895
- if ($active_tab == "frontend")
1896
- {
1897
  iqblockcountry_settings_frontend();
1898
  }
1899
- elseif ($active_tab == "backend")
1900
- {
1901
  iqblockcountry_settings_backend();
1902
  }
1903
- elseif ($active_tab == "tools")
1904
- {
1905
  iqblockcountry_settings_tools();
1906
  }
1907
- elseif ($active_tab == "logging")
1908
- {
1909
  iqblockcountry_settings_logging();
1910
  }
1911
- elseif ($active_tab == "pages")
1912
- {
1913
  iqblockcountry_settings_pages();
1914
  }
1915
- elseif ($active_tab == "categories")
1916
- {
1917
  iqblockcountry_settings_categories();
1918
  }
1919
- elseif ($active_tab == "tags")
1920
- {
1921
  iqblockcountry_settings_tags();
1922
  }
1923
- elseif ($active_tab == "posttypes")
1924
- {
1925
  iqblockcountry_settings_posttypes();
1926
  }
1927
- elseif ($active_tab == "services")
1928
- {
1929
  iqblockcountry_settings_services();
1930
  }
1931
- elseif ($active_tab == "export")
1932
- {
1933
  iqblockcountry_settings_importexport();
1934
  }
1935
  else
@@ -1947,7 +1853,7 @@ function iqblockcountry_settings_page() {
1947
  See <a href="https://webence.nl/plugins/donate/">Plugin donation page</a></p>
1948
 
1949
  <?php
1950
-
1951
  }
1952
 
1953
 
@@ -1956,94 +1862,99 @@ function iqblockcountry_settings_page() {
1956
  */
1957
  function iqblockcountry_find_geoip_location()
1958
  {
1959
- if (function_exists('curl_init'))
1960
- {
1961
- $curl = curl_init();
1962
- curl_setopt_array($curl, array(
1963
- CURLOPT_RETURNTRANSFER => 1,
1964
- CURLOPT_URL => 'https://us.geoip.webence.nl/test',
1965
- CURLOPT_USERAGENT => 'iQ Block Country US location test/' . get_bloginfo('wpurl')
1966
- ));
1967
- $resp = curl_exec($curl);
1968
- $infous = curl_getinfo($curl);
1969
- curl_close($curl);
1970
-
1971
- $curl = curl_init();
1972
- curl_setopt_array($curl, array(
1973
- CURLOPT_RETURNTRANSFER => 1,
1974
- CURLOPT_URL => 'https://us2.geoip.webence.nl/test',
1975
- CURLOPT_USERAGENT => 'iQ Block Country US2 location test/' . get_bloginfo('wpurl')
1976
- ));
1977
- $resp = curl_exec($curl);
1978
- $infous2 = curl_getinfo($curl);
1979
- curl_close($curl);
1980
-
1981
- $curl = curl_init();
1982
- curl_setopt_array($curl, array(
1983
- CURLOPT_RETURNTRANSFER => 1,
1984
- CURLOPT_URL => 'https://us3.geoip.webence.nl/test',
1985
- CURLOPT_USERAGENT => 'iQ Block Country US3 location test/' . get_bloginfo('wpurl')
1986
- ));
1987
- $resp = curl_exec($curl);
1988
- $infous3 = curl_getinfo($curl);
1989
- curl_close($curl);
1990
-
1991
- // $curl = curl_init();
1992
- // curl_setopt_array($curl, array(
1993
- // CURLOPT_RETURNTRANSFER => 1,
1994
- // CURLOPT_URL => 'https://asia.geoip.webence.nl/test',
1995
- // CURLOPT_USERAGENT => 'iQ Block Country Asia location test/' . get_bloginfo('wpurl')
1996
- // ));
1997
- // $resp = curl_exec($curl);
1998
- // $infoasia = curl_getinfo($curl);
1999
- // curl_close($curl);
 
 
 
 
 
2000
 
2001
- $curl = curl_init();
2002
- curl_setopt_array($curl, array(
2003
- CURLOPT_URL => 'https://eu.geoip.webence.nl/test',
2004
- CURLOPT_USERAGENT => 'iQ Block Country EU location test/' . get_bloginfo('wpurl')
2005
- ));
2006
- $resp = curl_exec($curl);
2007
- $infoeu = curl_getinfo($curl);
2008
- curl_close($curl);
2009
-
2010
- $curl = curl_init();
2011
- curl_setopt_array($curl, array(
2012
- CURLOPT_URL => 'https://eu3.geoip.webence.nl/test',
2013
- CURLOPT_USERAGENT => 'iQ Block Country EU3 location test/' . get_bloginfo('wpurl')
2014
- ));
2015
- $resp = curl_exec($curl);
2016
- $infoeu3 = curl_getinfo($curl);
2017
- curl_close($curl);
 
 
 
 
2018
 
2019
 
2020
- $fastestsite = min($infoeu['total_time'],$infoeu3['total_time'],$infous['total_time'],$infous2['total_time'],$infous3['total_time']);
2021
 
2022
- if ($infous['total_time'] == $fastestsite)
2023
- {
2024
- update_option('blockcountry_geoapilocation','US');
2025
- }
2026
- elseif ($infous2['total_time'] == $fastestsite)
2027
- {
2028
- update_option('blockcountry_geoapilocation','US2');
2029
- }
2030
- elseif ($infous3['total_time'] == $fastestsite)
2031
- {
2032
- update_option('blockcountry_geoapilocation','US3');
2033
- }
2034
- // elseif ($infoasia['total_time'] == $fastestsite)
2035
- // {
2036
- // update_option('blockcountry_geoapilocation','ASIA');
2037
- // }
2038
- elseif ($infoeu3['total_time'] == $fastestsite)
2039
- {
2040
- update_option('blockcountry_geoapilocation','EU3');
2041
- }
2042
- else
2043
- {
2044
- update_option('blockcountry_geoapilocation','EU');
2045
  }
2046
- }
2047
  }
2048
 
2049
  /*
@@ -2051,67 +1962,75 @@ function iqblockcountry_find_geoip_location()
2051
  */
2052
  function iqblockcountry_get_blockallowlist()
2053
  {
2054
- $frontendblocklistip = array(); $frontendblocklist = get_option ( 'blockcountry_frontendblacklist' );
2055
- $frontendallowlistip = array(); $frontendallowlist = get_option ( 'blockcountry_frontendwhitelist' );
2056
- $backendblocklistip = array(); $backendblocklist = get_option ( 'blockcountry_backendblacklist' );
2057
- $backendallowlistip = array(); $backendallowlist = get_option ( 'blockcountry_backendwhitelist' );
2058
 
2059
 
2060
- $feblocklistip = array();
2061
- $feblocklistiprange4 = array();
2062
- $feblocklistiprange6 = array();
2063
- $feallowlistip = array();
2064
- $feallowlistiprange4 = array();
2065
- $feallowlistiprange6 = array();
2066
- global $feblocklistip,$feblocklistiprange4,$feblocklistiprange6,$feallowlistip,$feallowlistiprange4,$feallowlistiprange6;
2067
 
2068
- $beblocklistip = array();
2069
- $beblocklistiprange4 = array();
2070
- $beblocklistiprange6 = array();
2071
- $beallowlistip = array();
2072
- $beallowlistiprange4 = array();
2073
- $beallowlistiprange6 = array();
2074
- global $beblocklistip,$beblocklistiprange4,$beblocklistiprange6,$beallowlistip,$beallowlistiprange4,$beallowlistiprange6;
2075
 
2076
 
2077
- if (preg_match('/;/',$frontendblocklist))
2078
- {
2079
- $frontendblocklistip = explode(";", $frontendblocklist);
2080
- foreach ($frontendblocklistip AS $ip)
2081
  {
2082
- if (iqblockcountry_is_valid_ipv4($ip) || iqblockcountry_is_valid_ipv6($ip)) { $feblocklistip[] = $ip; }
2083
- elseif (iqblockcountry_is_valid_ipv4_cidr($ip)) { $feblocklistiprange4[] = $ip; }
2084
- elseif (iqblockcountry_is_valid_ipv6_cidr($ip)) { $feblocklistiprange6[] = $ip; }
 
 
 
2085
  }
2086
  }
2087
- if (preg_match('/;/',$frontendallowlist))
2088
- {
2089
- $frontendallowlistip = explode(";", $frontendallowlist);
2090
- foreach ($frontendallowlistip AS $ip)
2091
  {
2092
- if (iqblockcountry_is_valid_ipv4($ip) || iqblockcountry_is_valid_ipv6($ip)) { $feallowlistip[] = $ip; }
2093
- elseif (iqblockcountry_is_valid_ipv4_cidr($ip)) { $feallowlistiprange4[] = $ip; }
2094
- elseif (iqblockcountry_is_valid_ipv6_cidr($ip)) { $feallowlistiprange6[] = $ip; }
 
 
 
2095
  }
2096
  }
2097
- if (preg_match('/;/',$backendblocklist))
2098
- {
2099
- $backendblocklistip = explode(";", $backendblocklist);
2100
- foreach ($backendblocklistip AS $ip)
2101
  {
2102
- if (iqblockcountry_is_valid_ipv4($ip) || iqblockcountry_is_valid_ipv6($ip)) { $beblocklistip[] = $ip; }
2103
- elseif (iqblockcountry_is_valid_ipv4_cidr($ip)) { $beblocklistiprange4[] = $ip; }
2104
- elseif (iqblockcountry_is_valid_ipv6_cidr($ip)) { $beblocklistiprange6[] = $ip; }
 
 
 
2105
  }
2106
  }
2107
- if (preg_match('/;/',$backendallowlist))
2108
- {
2109
- $backendallowlistip = explode(";", $backendallowlist);
2110
- foreach ($backendallowlistip AS $ip)
2111
  {
2112
- if (iqblockcountry_is_valid_ipv4($ip) || iqblockcountry_is_valid_ipv6($ip)) { $beallowlistip[] = $ip; }
2113
- elseif (iqblockcountry_is_valid_ipv4_cidr($ip)) { $beallowlistiprange4[] = $ip; }
2114
- elseif (iqblockcountry_is_valid_ipv6_cidr($ip)) { $beallowlistiprange6[] = $ip; }
 
 
 
2115
  }
2116
  }
2117
 
1
  <?php
2
 
3
  /* Check if the Geo Database exists or if GeoIP API key is entered otherwise display notification */
4
+ if (!is_file(IQBCGEOIP2DBFILE) && (!get_option('blockcountry_geoapikey'))) {
5
+ add_action('admin_notices', 'iq_missing_db_notice');
 
 
 
 
 
6
  }
7
 
8
  /* check if caching plugins are active, if so display notice */
9
+ if (iqblockcountry_is_caching_active()) {
10
+ add_action('admin_notices', 'iq_cachingisactive_notice');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  }
12
 
13
+ /**
 
14
  * Display missing database notification.
15
+ **/
16
  function iq_missing_db_notice()
17
  {
18
+ if (!is_file(IQBCGEOIP2DBFILE) ) {
 
19
  ?>
20
  <div class="notice notice-error">
21
  <h3>iQ Block Country</h3>
22
+ <p><?php esc_html_e('The MaxMind GeoIP2 database does not exist. Please download this file manually or if you wish to use the GeoIP API get an API key from: ', 'iq-block-country'); ?> <a href="https://webence.nl/geoip-api/" target="_blank">https://webence.nl/geoip-api/</a></p>
23
+ <p><?php esc_html_e("Please download the database (GeoLite2-Country.tar.gz) from: ", 'iq-block-country'); ?>
24
+ <?php esc_html_e("If you do not have an account at Maxmind yet for the Geolite2 database sign up for a free account at:", 'iq-block-country'); ?>
25
+ <?php esc_html_e("<a href=\"" . IQBCMAXMINDURL . "\" target=\"_blank\">" . IQBCMAXMINDURL . "</a> "); ?>
26
+ <?php esc_html_e("unzip the file and afterwards upload the GeoLite2-Country.mmdb file to the following location: ", 'iq-block-country'); ?>
27
+ <b><?php esc_html_e(IQBCGEOIP2DBFILE); ?></b></p>
28
 
29
+ <p><?php esc_html_e('For more detailed instructions take a look at the documentation..', 'iq-block-country'); ?></p>
30
 
31
  </div>
32
+ <?php
33
+ }
34
  }
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
 
38
  /*
43
  ?>
44
  <div class="notice notice-warning is-dismissible">
45
  <h3>iQ Block Country</h3>
46
+ <p><?php esc_html_e('A caching plugin appears to be active on your WordPress installation.', 'iq-block-country'); ?></p>
47
+ <p><?php esc_html_e('Caching plugins do not always cooperate nicely together with the iQ Block Country plugin which may lead to non blocked visitors getting a cached banned message or page.', 'iq-block-country'); ?></p>
48
+ <p><?php esc_html_e('For more information visit the following page:', 'iq-block-country'); ?> <a target="_blank"href="https://www.webence.nl/questions/iq-block-country-and-caching-plugins/">https://www.webence.nl/questions/iq-block-country-and-caching-plugins/</a></p>
49
  </div>
50
+ <?php
51
  }
52
 
53
 
60
  ?>
61
  <div class="notice notice-warning">
62
  <h3>iQ Block Country</h3>
63
+ <p><?php esc_html_e('The MaxMind GeoIP database is older than 3 months. Please update this file manually or if you wish to use the GeoIP API get an API key from: ', 'iq-block-country'); ?><a href="https://webence.nl/geoip-api/" target="_blank">https://webence.nl/geoip-api/</a></p>
64
+ <p><?php esc_html_e("Please download the database (GeoLite2-Country.tar.gz) from MaxMind. ", 'iq-block-country'); ?>
65
+ <?php esc_html_e("If you do not have an account at Maxmind yet for the Geolite2 database sign up for a free account at:", 'iq-block-country'); ?>
66
+ <?php esc_html_e("<a href=\"" . IQBCMAXMINDURL . "\" target=\"_blank\">" . IQBCMAXMINDURL . "</a> "); ?>
67
+ <?php esc_html_e("unzip the file and afterwards upload it to the following location: ", 'iq-block-country'); ?>
68
+ <b><?php esc_html_e(IQBCGEOIP2DBFILE); ?></b></p>
69
 
70
+ <p><?php esc_html_e('For more detailed instructions take a look at the documentation..', 'iq-block-country'); ?></p>
71
 
72
  </div>
73
+ <?php
74
  }
75
 
76
 
79
  */
80
  function iqblockcountry_create_menu()
81
  {
82
+ //create new menu option in the settings department
83
+ add_submenu_page('options-general.php', 'iQ Block Country', 'iQ Block Country', 'administrator', __FILE__, 'iqblockcountry_settings_page');
84
+ //call register settings function
85
+ add_action('admin_init', 'iqblockcountry_register_mysettings');
86
  }
87
 
88
  /*
90
  */
91
  function iqblockcountry_register_mysettings()
92
  {
93
+ //register our settings
94
+ register_setting('iqblockcountry-settings-group', 'blockcountry_blockmessage');
95
+ register_setting('iqblockcountry-settings-group', 'blockcountry_redirect');
96
+ register_setting('iqblockcountry-settings-group', 'blockcountry_redirect_url', 'iqblockcountry_is_valid_url');
97
+ register_setting('iqblockcountry-settings-group', 'blockcountry_header');
98
+ register_setting('iqblockcountry-settings-group', 'blockcountry_buffer');
99
+ register_setting('iqblockcountry-settings-group', 'blockcountry_tracking');
100
+ register_setting('iqblockcountry-settings-group', 'blockcountry_nrstatistics');
101
+ register_setting('iqblockcountry-settings-group', 'blockcountry_daysstatistics');
102
+ register_setting('iqblockcountry-settings-group', 'blockcountry_lookupstatistics');
103
+ register_setting('iqblockcountry-settings-group', 'blockcountry_geoapikey', 'iqblockcountry_check_geoapikey');
104
+ register_setting('iqblockcountry-settings-group', 'blockcountry_geoapilocation');
105
+ register_setting('iqblockcountry-settings-group', 'blockcountry_apikey', 'iqblockcountry_check_adminapikey');
106
+ register_setting('iqblockcountry-settings-group', 'blockcountry_debuglogging');
107
+ register_setting('iqblockcountry-settings-group', 'blockcountry_accessibility');
108
+ register_setting('iqblockcountry-settings-group', 'blockcountry_ipoverride');
109
+ register_setting('iqblockcountry-settings-group', 'blockcountry_logging');
110
+ register_setting('iqblockcountry-settings-group', 'blockcountry_adminajax');
111
+ register_setting('iqblockcountry-settings-group-backend', 'blockcountry_blockbackend');
112
+ register_setting('iqblockcountry-settings-group-backend', 'blockcountry_backendbanlist');
113
+ register_setting('iqblockcountry-settings-group-backend', 'blockcountry_backendbanlist_inverse');
114
+ register_setting('iqblockcountry-settings-group-backend', 'blockcountry_backendblacklist', 'iqblockcountry_validate_ip');
115
+ register_setting('iqblockcountry-settings-group-backend', 'blockcountry_backendwhitelist', 'iqblockcountry_validate_ip');
116
+ register_setting('iqblockcountry-settings-group-frontend', 'blockcountry_banlist');
117
+ register_setting('iqblockcountry-settings-group-frontend', 'blockcountry_banlist_inverse');
118
+ register_setting('iqblockcountry-settings-group-frontend', 'blockcountry_frontendblacklist', 'iqblockcountry_validate_ip');
119
+ register_setting('iqblockcountry-settings-group-frontend', 'blockcountry_frontendwhitelist', 'iqblockcountry_validate_ip');
120
+ register_setting('iqblockcountry-settings-group-frontend', 'blockcountry_blocklogin');
121
+ register_setting('iqblockcountry-settings-group-frontend', 'blockcountry_blocksearch');
122
+ register_setting('iqblockcountry-settings-group-frontend', 'blockcountry_blockfrontend');
123
+ register_setting('iqblockcountry-settings-group-frontend', 'blockcountry_blocktag');
124
+ register_setting('iqblockcountry-settings-group-frontend', 'blockcountry_blockfeed');
125
+ register_setting('iqblockcountry-settings-group-pages', 'blockcountry_blockpages');
126
+ register_setting('iqblockcountry-settings-group-pages', 'blockcountry_blockpages_inverse');
127
+ register_setting('iqblockcountry-settings-group-pages', 'blockcountry_pages');
128
+ register_setting('iqblockcountry-settings-group-posttypes', 'blockcountry_blockposttypes');
129
+ register_setting('iqblockcountry-settings-group-posttypes', 'blockcountry_posttypes');
130
+ register_setting('iqblockcountry-settings-group-cat', 'blockcountry_blockcategories');
131
+ register_setting('iqblockcountry-settings-group-cat', 'blockcountry_categories');
132
+ register_setting('iqblockcountry-settings-group-cat', 'blockcountry_blockhome');
133
+ register_setting('iqblockcountry-settings-group-tags', 'blockcountry_blocktags');
134
+ register_setting('iqblockcountry-settings-group-tags', 'blockcountry_tags');
135
+ register_setting('iqblockcountry-settings-group-se', 'blockcountry_allowse');
136
  }
137
 
138
  /**
140
  *
141
  * @return array of options.
142
  */
143
+ function iqblockcountry_get_options_arr()
144
+ {
145
+ $iqbc_optarr = array( 'blockcountry_banlist','blockcountry_banlist_inverse', 'blockcountry_backendbanlist','blockcountry_backendbanlist_inverse',
146
  'blockcountry_backendblacklist','blockcountry_backendwhitelist','blockcountry_frontendblacklist','blockcountry_frontendwhitelist',
147
  'blockcountry_blockmessage','blockcountry_blocklogin','blockcountry_blockfrontend','blockcountry_blockbackend','blockcountry_header',
148
  'blockcountry_blockpages','blockcountry_blockpages_inverse','blockcountry_pages','blockcountry_blockcategories','blockcountry_categories','blockcountry_tracking',
150
  'blockcountry_geoapilocation','blockcountry_apikey','blockcountry_redirect','blockcountry_redirect_url','blockcountry_allowse',
151
  'blockcountry_debuglogging','blockcountry_buffer','blockcountry_accessibility','blockcountry_ipoverride','blockcountry_logging','blockcountry_blockposttypes',
152
  'blockcountry_posttypes','blockcountry_blocksearch','blockcountry_adminajax','blockcountry_blocktag','blockcountry_blockfeed','blockcountry_blocktags','blockcountry_tags');
153
+ return apply_filters('iqblockcountry_options', $iqbc_optarr);
154
  }
155
 
156
 
159
  */
160
  function iqblockcountry_set_defaults()
161
  {
162
+ update_option('blockcountry_version', VERSION);
163
+ $iqbc_countrylist = iqblockcountry_get_isocountries();
164
+ $iqbc_ip_address = iqblockcountry_get_ipaddress();
165
+ $usercountry = iqblockcountry_check_ipaddress($iqbc_ip_address);
166
+ $iqbc_server_addr = "";
167
+ if(isset($_SERVER['SERVER_ADDR']) && (filter_var($_SERVER['SERVER_ADDR'],FILTER_VALIDATE_IP))) {
168
+ $iqbc_server_addr = $_SERVER['SERVER_ADDR'];
169
+ } elseif(array_key_exists('LOCAL_ADDR', $_SERVER) && (filter_var($_SERVER['LOCAL_ADDR'],FILTER_VALIDATE_IP))) {
170
+ $iqbc_server_addr = $_SERVER['LOCAL_ADDR'];
 
 
 
 
 
 
 
 
 
 
 
 
171
  }
172
+
173
+ if (get_option('blockcountry_blockfrontend') === false) { update_option('blockcountry_blockfrontend', 'on');
174
+ }
175
+ if (get_option('blockcountry_blockfeed') === false) { update_option('blockcountry_blockfeed', 'on');
176
+ }
177
+ if (get_option('blockcountry_backendnrblocks') === false) { update_option('blockcountry_backendnrblocks', 0);
178
+ }
179
+ if (get_option('blockcountry_frontendnrblocks') === false) { update_option('blockcountry_frontendnrblocks', 0);
180
+ }
181
+ if (get_option('blockcountry_header') === false) { update_option('blockcountry_header', 'on');
182
+ }
183
+ if (get_option('blockcountry_nrstatistics') === false) { update_option('blockcountry_nrstatistics', 15);
184
+ }
185
+ if (null === get_option('blockcountry_daysstatistics', null) ) { update_option('blockcountry_daysstatistics', 30);
186
+ }
187
+ if (get_option('blockcountry_backendwhitelist') === false || (get_option('blockcountry_backendwhitelist') == "")) { update_option('blockcountry_backendwhitelist', $iqbc_ip_address . ";");
188
+ }
189
+ $iqbc_tmpbackendallowlist = get_option('blockcountry_backendwhitelist');
190
+ $iqbc_ippos = strpos($iqbc_tmpbackendallowlist, $iqbc_server_addr);
191
+ if ($iqbc_ippos === false) {
192
+ $iqbc_tmpbackendallowlist .= $iqbc_server_addr . ";";
193
+ update_option('blockcountry_backendwhitelist', $iqbc_tmpbackendallowlist);
194
+ }
195
+ if (get_option('blockcountry_frontendwhitelist') === false || (get_option('blockcountry_frontendwhitelist') == "")) { update_option('blockcountry_frontendwhitelist', $iqbc_server_addr . ";");
196
+ }
197
  iqblockcountry_install_db();
198
+ if (get_option('blockcountry_banlist_inverse') === false) { update_option('blockcountry_banlist_inverse', 'off');
199
+ }
200
+ if (get_option('blockcountry_backendbanlist_inverse') === false) { update_option('blockcountry_backendbanlist_inverse', 'off');
201
+ }
202
+ if (get_option('blockcountry_ipoverride') === false) { update_option('blockcountry_ipoverride', 'NONE');
203
+ }
204
  iqblockcountry_find_geoip_location();
205
  }
206
 
209
  {
210
  iqblockcountry_uninstall_db();
211
  iqblockcountry_uninstall_loggingdb();
212
+ delete_option('blockcountry_banlist');
213
+ delete_option('blockcountry_banlist_inverse');
214
+ delete_option('blockcountry_backendbanlist');
215
  delete_option('blockcountry_backendbanlist_inverse');
216
+ delete_option('blockcountry_backendblacklist');
217
+ delete_option('blockcountry_backendwhitelist');
218
+ delete_option('blockcountry_frontendblacklist');
219
+ delete_option('blockcountry_frontendwhitelist');
220
+ delete_option('blockcountry_blockmessage');
221
+ delete_option('blockcountry_backendnrblocks');
222
+ delete_option('blockcountry_frontendnrblocks');
223
+ delete_option('blockcountry_blocklogin');
224
+ delete_option('blockcountry_blockfrontend');
225
+ delete_option('blockcountry_blockbackend');
226
  delete_option('blockcountry_version');
227
  delete_option('blockcountry_header');
228
  delete_option('blockcountry_blockpages');
260
 
261
 
262
 
263
+ function iqblockcountry_settings_tools()
264
+ {
265
  ?>
266
+ <h3><?php esc_html_e('Check which country belongs to an IP Address according to the current database.', 'iq-block-country'); ?></h3>
267
 
268
+ <form name="ipcheck" action="#ipcheck" method="post">
269
+ <input type="hidden" name="action" value="iqbc_ipcheck" />
270
+ <input name="iqbc_ipcheck_nonce" type="hidden" value="<?php echo wp_create_nonce('iqbc_ipcheck_nonce'); ?>" />
271
+ <?php esc_html_e('IP Address to check:', 'iq-block-country'); ?> <input type="text" name="iqbc_ipaddress" lenth="50" />
272
+ <?php
273
+ global $iqbc_feblocklistip,$iqbc_feblocklistiprange4,$iqbc_feblocklistiprange6,$iqbc_feallowlistip,$iqbc_feallowlistiprange4,$iqbc_feallowlistiprange6;
274
+ global $iqbc_beblocklistip,$iqbc_beblocklistiprange4,$iqbc_beblocklistiprange6,$iqbc_beallowlistip,$iqbc_beallowlistiprange4,$iqbc_beallowlistiprange6;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
 
277
+ if (isset($_POST['iqbc_action']) && $_POST[ 'iqbc_action' ] == 'iqbc_ipcheck') {
278
+ if (!isset($_POST['iqbc_ipcheck_nonce'])) { die("Failed security check.");
279
+ }
280
+ if (!wp_verify_nonce($_POST['iqbc_ipcheck_nonce'], 'iqbc_ipcheck_nonce')) { die("Is this a CSRF attempts?");
281
+ }
282
+ if (isset($_POST['iqbc_ipaddress']) && !empty($_POST['iqbc_ipaddress'])) {
283
+ if (iqblockcountry_is_valid_ipv4($_POST['iqbc_ipaddress']) || iqblockcountry_is_valid_ipv6($_POST['iqbc_ipaddress'])) {
284
+ if (filter_var($_POST['iqbc_ipaddress'], FILTER_VALIDATE_IP)) { $iqbc_ip_address = $_POST['iqbc_ipaddress'];
285
+ }
286
+ $iqbc_country = iqblockcountry_check_ipaddress($iqbc_ip_address);
287
+ $iqbc_countrylist = iqblockcountry_get_isocountries();
288
+ if ($iqbc_country == "Unknown" || $iqbc_country == "ipv6" || $iqbc_country == "" || $iqbc_country == "FALSE") {
289
+ echo "<p>" . esc_html('No country for', 'iq-block-country') . ' ' . esc_html($iqbc_ip_address) . ' ' . esc_html('could be found. Or', 'iq-block-country') . ' ' . esc_html($iqbc_ip_address) . ' ' . esc_html('is not a valid IPv4 or IPv6 IP address', 'iq-block-country');
290
+ echo "</p>";
291
+ }
292
+ else {
293
+ $iqbc_displaycountry = $iqbc_countrylist[$iqbc_country];
294
+ echo "<p>" . esc_html('IP Adress', 'iq-block-country') . ' ' . esc_html($iqbc_ip_address) . ' ' . esc_html('belongs to', 'iq-block-country') . ' ' . esc_html($iqbc_displaycountry) . ".</p>";
295
+ $iqbc_haystack = get_option('blockcountry_banlist');
296
+ if (!is_array($iqbc_haystack)) { $iqbc_haystack = array();
297
+ }
298
+ $iqbc_inverse = get_option('blockcountry_banlist_inverse');
299
+ if ($iqbc_inverse == "on") {
300
+ if (is_array($iqbc_haystack) && !in_array($iqbc_country, $iqbc_haystack)) {
301
+ esc_html_e('This country is not permitted to visit the frontend of this website.', 'iq-block-country');
302
+ echo "<br />";
303
+ }
304
+ } else {
305
+ if (is_array($iqbc_haystack) && in_array($iqbc_country, $iqbc_haystack)) {
306
+ esc_html_e('This country is not permitted to visit the frontend of this website.', 'iq-block-country');
307
+ echo "<br />";
308
+ }
309
+ }
310
+ $iqbc_inverse = get_option('blockcountry_backendbanlist_inverse');
311
+ $iqbc_haystack = get_option('blockcountry_backendbanlist');
312
+ if (!is_array($iqbc_haystack)) { $iqbc_haystack = array();
313
+ }
314
+ if ($iqbc_inverse == "on") {
315
+ if (is_array($iqbc_haystack) && !in_array($iqbc_country, $iqbc_haystack)) {
316
+ esc_html_e('This country is not permitted to visit the backend of this website.', 'iq-block-country');
317
+ echo "<br />";
318
+ }
319
+ }
320
+ else
321
+ {
322
+ if (is_array($iqbc_haystack) && in_array($iqbc_country, $iqbc_haystack)) {
323
+ esc_html_e('This country is not permitted to visit the backend of this website.', 'iq-block-country');
324
+ echo "<br />";
325
  }
326
+ }
327
+ $iqbc_backendbanlistip = unserialize(get_option('blockcountry_backendbanlistip'));
328
+ if (is_array($iqbc_backendbanlistip) && in_array($iqbc_ip_address, $iqbc_backendbanlistip)) {
329
+ esc_html_e('This IP address is present in the block list.', 'iq-block-country');
330
+ }
331
+
332
+ }
333
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feblocklistiprange4, $iqbc_feblocklistiprange6, $iqbc_feblocklistip)) {
334
+ esc_html_e('This IP address is present in the frontend block list.', 'iq-block-country');
335
+ echo "<br />";
336
+ }
337
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_feallowlistiprange4, $iqbc_feallowlistiprange6, $iqbc_feallowlistip)) {
338
+ esc_html_e('This IP address is present in the frontend allow list.', 'iq-block-country');
339
+ echo "<br />";
340
+ }
341
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_beblocklistiprange4, $iqbc_beblocklistiprange6, $iqbc_beblocklistip)) {
342
+ esc_html_e('This IP address is present in the backend block list.', 'iq-block-country');
343
+ echo "<br />";
344
+ }
345
+ if (iqblockcountry_validate_ip_in_list($iqbc_ip_address, $iqbc_beallowlistiprange4, $iqbc_beallowlistiprange6, $iqbc_beblocklistip)) {
346
+ esc_html_e('This IP address is present in the backend allow list.', 'iq-block-country');
347
+ echo "<br />";
348
+ }
349
+
350
+ }
351
+ }
352
+ }
353
+ echo '<div class="submit"><input type="submit" name="test" value="' . esc_html('Check IP address', 'iq-block-country') . '" /></div>';
354
  wp_nonce_field('iqblockcountry');
355
 
356
+ ?>
357
  </form>
358
 
359
  <hr />
360
 
361
+ <h3><?php esc_html_e('Database information', 'iq-block-country'); ?></h3>
362
  <?php
363
 
364
+ $iqbc_format = get_option('date_format') . ' ' . get_option('time_format');
365
+ if (!get_option('blockcountry_geoapikey')) {
366
+ if (is_file(IQBCGEOIP2DBFILE)) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
367
 
368
+ esc_html_e("GeoIP2 database exists. File date: ", 'iq-block-country');
369
+ $iqbc_filedate = filemtime(IQBCGEOIP2DBFILE);
370
+ echo esc_html(date($iqbc_format, $iqbc_filedate));
371
  echo " ";
372
+ $iqbc_3months = time() - 3 * 31 * 86400;
373
+ if ($iqbc_filedate < $iqbc_3months) {
374
+ esc_html_e("Database is older than 3 months... Please update...", 'iq-block-country');
 
375
  }
376
  }
377
  else
378
  {
379
+ esc_html_e("GeoIP2 database does not exist.", 'iq-block-country');
380
+ }
381
  echo "<br />";
382
  }
383
+ if (get_option('blockcountry_geoapikey')) {
384
+ $iqbc_licensedate = strtotime(iqblockcountry_get_licensedate_geoapikey(get_option('blockcountry_geoapikey')));
385
+ esc_html_e("Your GeoIP API key is valid till: ", 'iq-block-country');
386
+ esc_html_e(date($iqbc_format, $iqbc_licensedate));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  echo "<br />";
388
+ $iqbc_usagerequests = iqblockcountry_get_usage_geoapikey(get_option('blockcountry_geoapikey'));
389
+ esc_html_e("Your GeoIP API usage this month: ", 'iq-block-country');
390
+ esc_html_e($iqbc_usagerequests);
391
  }
392
  ?>
393
  <br />
394
  <br />
395
 
396
+ <h3><?php esc_html_e('Reset Counters', 'iq-block-country'); ?></h3>
397
 
398
  <div class="wrap">
399
  <div id="icon-tools" class="icon32"><br /></div>
400
+ <p><?php esc_html_e('When you click on the Reset Counter button the counters of total Frontend & Backend blocks will be set to 0.', 'iq-block-country'); ?></p>
401
 
402
+ <?php $iqbc_blocked = get_option('blockcountry_backendnrblocks'); ?>
403
+ <p><?php esc_html_e(number_format($iqbc_blocked)); ?> <?php esc_html_e('visitors blocked from the backend.', 'iq-block-country'); ?></p>
404
+ <?php $iqbc_blocked = get_option('blockcountry_frontendnrblocks'); ?>
405
+ <p><?php esc_html_e(number_format($iqbc_blocked)); ?> <?php esc_html_e('visitors blocked from the frontend.', 'iq-block-country'); ?></p>
406
 
407
  <form method='post'>
408
  <p class="submit">
409
  <?php wp_nonce_field('iqblockresetcounter'); ?>
410
+ <input type='submit' name='iqbc_resetcounter' value='<?php esc_html_e('Reset Counter', 'iq-block-country'); ?>'/>
411
  </p>
412
  </form>
413
  </div>
414
  <?php
415
+ if ((isset($_POST['iqbc_resetcounter'])) && (check_admin_referer('iqblockresetcounter'))) {
416
+ update_option('blockcountry_backendnrblocks', 0);
417
+ update_option('blockcountry_frontendnrblocks', 0);
418
+ esc_html_e("Counters reset", 'iq-block-country');
419
  }
420
  ?>
421
+ <h3><?php esc_html_e('Active plugins', 'iq-block-country'); ?></h3>
422
  <?php
423
 
424
+ $iqbc_plugins = get_plugins();
425
+ $iqbc_plugins_string = '';
426
 
427
  echo '<table class="widefat">';
428
+ echo '<thead><tr><th>' . esc_html('Plugin name', 'iq-block-country') . '</th><th>' . esc_html('Version', 'iq-block-country') . '</th><th>' . esc_html('URL', 'iq-block-country') . '</th></tr></thead>';
429
 
430
+ foreach( array_keys($iqbc_plugins) as $iqbc_key ) {
431
+ if (is_plugin_active($iqbc_key) ) {
432
+ $iqbc_plugin =& $iqbc_plugins[$iqbc_key];
433
+ echo "<tbody><tr>";
434
+ echo '<td>' . esc_html($iqbc_plugin['Name']) . '</td>';
435
+ echo '<td>' . esc_html($iqbc_plugin['Version']) . '</td>';
436
+ echo '<td>' . esc_url($iqbc_plugin['PluginURI']) . '</td>';
437
  echo "</tr></tbody>";
438
  }
439
  }
440
  echo '</table>';
441
+ //echo $iqbc_plugins_string;
442
  global $wpdb;
443
 
444
+ $iqbc_disabled_functions = @ini_get('disable_functions');
445
 
446
+ if ($iqbc_disabled_functions == '' || $iqbc_disabled_functions === false ) {
447
+ $iqbc_disabled_functions = '<i>(' . esc_html('none', 'iq-block-country') . ')</i>';
448
  }
449
 
450
+ $iqbc_disabled_functions = str_replace(', ', ',', $iqbc_disabled_functions); // Normalize spaces or lack of spaces between disabled functions.
451
+ $iqbc_disabled_functions_array = explode(',', $iqbc_disabled_functions);
452
 
453
+ $iqbc_php_uid = esc_html('unavailable', 'iq-block-country');
454
+ $iqbc_php_user = esc_html('unavailable', 'iq-block-country');
455
 
456
 
457
  ?>
458
+ <h3><?php esc_html_e('File System Information', 'iq-block-country'); ?></h3>
459
 
460
  <table class="widefat">
461
+ <tbody><tr><td><?php esc_html_e('Website url', 'iq-block-country'); ?>: <strong><?php echo esc_url(get_site_url()); ?></strong></td></tr></tbody>
462
+ <tbody><tr><td><?php esc_html_e('Document Root Path', 'iq-block-country'); ?>: <strong><?php echo esc_html(filter_var($_SERVER['DOCUMENT_ROOT'], FILTER_SANITIZE_STRING)); ?></strong></td></tr></tbody>
463
  </table>
464
 
465
 
466
+ <h3><?php esc_html_e('Database Information', 'iq-block-country'); ?></h3>
467
  <table class="widefat">
468
+ <tbody><tr><td><?php esc_html_e('MySQL Database Version', 'iq-block-country'); ?>: <?php $iqbc_sqlversion = $wpdb->get_var("SELECT VERSION() AS version"); ?><strong><?php echo esc_html($iqbc_sqlversion); ?></strong></td></tr></tbody>
469
+ <tbody><tr><td><?php esc_html_e('MySQL Client Version', 'iq-block-country'); ?>: <strong><?php echo esc_html($wpdb->db_version()); ?></strong></td></tr></tbody>
470
+ <tbody><tr><td><?php esc_html_e('Database Host', 'iq-block-country'); ?>: <strong><?php echo esc_html(DB_HOST); ?></strong></td></tr></tbody>
471
+ <?php $iqbc_mysqlinfo = $wpdb->get_results("SHOW VARIABLES LIKE 'sql_mode'");
472
+ if (is_array($iqbc_mysqlinfo) ) {
473
+ $iqbc_sql_mode = $iqbc_mysqlinfo[0]->Value;
474
+ }
475
+ if (empty($iqbc_sql_mode) ) {
476
+ $iqbc_sql_mode = esc_html('Not Set', 'iq-block-country');
477
+ } else {
478
+ $iqbc_sql_mode = esc_html('Off', 'iq-block-country');
479
+ }
480
+ ?>
481
+ <tbody><tr><td><?php esc_html_e('SQL Mode', 'iq-block-country'); ?>: <strong><?php echo esc_html($iqbc_sql_mode); ?></strong></td></tr></tbody>
482
  </table>
483
 
484
 
485
+ <h3><?php esc_html_e('Server Information', 'iq-block-country'); ?></h3>
486
 
487
  <table class="widefat">
488
 
489
+ <tbody><tr><td><?php esc_html_e('Server Type', 'iq-block-country'); ?>: <strong><?php echo esc_html(filter_var(filter_var($_SERVER['SERVER_SOFTWARE'], FILTER_SANITIZE_STRING))); ?></strong></td></tr></tbody>
490
+ <tbody><tr><td><?php esc_html_e('Operating System', 'iq-block-country'); ?>: <strong><?php echo esc_html(PHP_OS); ?></strong></td></tr></tbody>
491
+ <tbody><tr><td><?php esc_html_e('Browser Compression Supported', 'iq-block-country'); ?>:
492
+ <strong><?php echo esc_html(filter_var($_SERVER['HTTP_ACCEPT_ENCODING'], FILTER_SANITIZE_STRING)); ?></strong></td></tr></tbody>
 
 
 
493
  <?php
494
 
495
+ if (is_callable('posix_geteuid') && ( false === in_array('posix_geteuid', $iqbc_disabled_functions_array) ) ) {
496
 
497
+ $iqbc_php_uid = @posix_geteuid();
498
 
499
+ if (is_callable('posix_getpwuid') && ( false === in_array('posix_getpwuid', $iqbc_disabled_functions_array) ) ) {
500
 
501
+ $iqbc_php_user = @posix_getpwuid($iqbc_php_uid);
502
+ $iqbc_php_user = $iqbc_php_user['name'];
503
 
504
+ }
505
  }
506
 
507
+ $iqbc_php_gid = esc_html('undefined', 'iq-block-country');
508
 
509
+ if (is_callable('posix_getegid') && ( false === in_array('posix_getegid', $iqbc_disabled_functions_array) ) ) {
510
+ $iqbc_php_gid = @posix_getegid();
511
  }
512
 
513
  ?>
514
+ <tbody><tr><td><?php esc_html_e('PHP Process User (UID:GID)', 'iq-block-country'); ?>:
515
+ <strong><?php echo esc_html($iqbc_php_user) . ' (' . esc_html($iqbc_php_uid) . ':' . esc_html($iqbc_php_gid) . ')'; ?></strong></td></tr></tbody>
516
  </table>
517
 
518
 
519
+ <h3><?php esc_html_e('PHP Information', 'iq-block-country'); ?></h3>
520
 
521
  <table class="widefat">
522
 
523
 
524
+ <tbody><tr><td><?php esc_html_e('PHP Version', 'iq-block-country'); ?>: <strong><?php echo esc_html(PHP_VERSION); ?></strong></td></tr></tbody>
525
+ <tbody><tr><td><?php esc_html_e('PHP Memory Usage', 'iq-block-country'); ?>: <strong><?php echo esc_html(round(memory_get_usage() / 1024 / 1024, 2)) . esc_html(' MB', 'iq-block-country'); ?></strong></td></tr></tbody>
526
 
527
  <?php
528
+ if (ini_get('memory_limit') ) {
529
+ $iqbc_memory_limit = filter_var(ini_get('memory_limit'), FILTER_SANITIZE_STRING);
530
  } else {
531
+ $iqbc_memory_limit = esc_html('N/A', 'iq-block-country');
532
  }
533
  ?>
534
+ <tbody><tr><td><?php esc_html_e('PHP Memory Limit', 'iq-block-country'); ?>: <strong><?php echo esc_html($iqbc_memory_limit); ?></strong></td></tr></tbody>
535
  <?php
536
+ if (ini_get('upload_max_filesize') ) {
537
+ $iqbc_upload_max = filter_var(ini_get('upload_max_filesize'), FILTER_SANITIZE_STRING);
538
  } else {
539
+ $iqbc_upload_max = esc_html('N/A', 'iq-block-country');
540
  }
541
  ?>
542
+ <tbody><tr><td><?php esc_html_e('PHP Max Upload Size', 'iq-block-country'); ?>: <strong><?php echo esc_html($iqbc_upload_max); ?></strong></td></tr></tbody>
543
  <?php
544
+ if (ini_get('post_max_size') ) {
545
+ $iqbc_post_max = filter_var(ini_get('post_max_size'), FILTER_SANITIZE_STRING);
546
  } else {
547
+ $iqbc_post_max = esc_html('N/A', 'iq-block-country');
548
  }
549
  ?>
550
+ <tbody><tr><td><?php esc_html_e('PHP Max Post Size', 'iq-block-country'); ?>: <strong><?php echo esc_html($iqbc_post_max); ?></strong></td></tr></tbody>
551
  <?php
552
+ if (ini_get('allow_url_fopen') ) {
553
+ $iqbc_allow_url_fopen = esc_html('On', 'iq-block-country');
554
  } else {
555
+ $iqbc_allow_url_fopen = esc_html('Off', 'iq-block-country');
556
  }
557
  ?>
558
+ <tbody><tr><td><?php esc_html_e('PHP Allow URL fopen', 'iq-block-country'); ?>: <strong><?php echo esc_html($iqbc_allow_url_fopen); ?></strong></td></tr></tbody>
559
  <?php
560
+ if (ini_get('allow_url_include') ) {
561
+ $iqbc_allow_url_include = esc_html('On', 'iq-block-country');
562
  } else {
563
+ $iqbc_allow_url_include = esc_html('Off', 'iq-block-country');
564
  }
565
  ?>
566
+ <tbody><tr><td><?php esc_html_e('PHP Allow URL Include'); ?>: <strong><?php echo esc_html($iqbc_allow_url_include); ?></strong></td></tr></tbody>
567
  <?php
568
+ if (ini_get('display_errors') ) {
569
+ $iqbc_display_errors = esc_html('On', 'iq-block-country');
570
  } else {
571
+ $iqbc_display_errors = esc_html('Off', 'iq-block-country');
572
  }
573
  ?>
574
+ <tbody><tr><td><?php esc_html_e('PHP Display Errors', 'iq-block-country'); ?>: <strong><?php echo esc_html($iqbc_display_errors); ?></strong></td></tr></tbody>
575
  <?php
576
+ if (ini_get('display_startup_errors') ) {
577
+ $iqbc_display_startup_errors = esc_html('On', 'iq-block-country');
578
  } else {
579
+ $iqbc_display_startup_errors = esc_html('Off', 'iq-block-country');
580
  }
581
  ?>
582
+ <tbody><tr><td><?php esc_html_e('PHP Display Startup Errors', 'iq-block-country'); ?>:
583
+ <strong><?php echo esc_html($iqbc_display_startup_errors); ?></strong></td></tr></tbody>
584
  <?php
585
+ if (ini_get('expose_php') ) {
586
+ $iqbc_expose_php = esc_html('On', 'iq-block-country');
587
  } else {
588
+ $iqbc_expose_php = esc_html('Off', 'iq-block-country');
589
  }
590
  ?>
591
+ <tbody><tr><td><?php esc_html_e('PHP Expose PHP', 'iq-block-country'); ?>: <strong><?php echo esc_html($iqbc_expose_php); ?></strong></td></tr></tbody>
592
  <?php
593
+ if (ini_get('max_execution_time') ) {
594
+ $iqbc_max_execute = filter_var(ini_get('max_execution_time'));
595
  } else {
596
+ $iqbc_max_execute = esc_html('N/A', 'iq-block-country');
597
  }
598
  ?>
599
+ <tbody><tr><td><?php esc_html_e('PHP Max Script Execution Time'); ?>:
600
+ <strong><?php echo esc_html($iqbc_max_execute); ?> <?php esc_html_e('Seconds'); ?></strong></td></tr></tbody>
601
  <?php
602
+ if (ini_get('open_basedir') ) {
603
+ $iqbc_open_basedir = esc_html('On', 'iq-block-country');
604
  } else {
605
+ $iqbc_open_basedir = esc_html('Off', 'iq-block-country');
606
  }
607
  ?>
608
+ <tbody><tr><td><?php esc_html_e('PHP open_basedir', 'iq-block-country'); ?>: <strong><?php echo esc_html($iqbc_open_basedir); ?></strong></td></tr></tbody>
609
  <?php
610
+ if (is_callable('xml_parser_create') ) {
611
+ $iqbc_xml = esc_html('Yes', 'iq-block-country');
612
  } else {
613
+ $iqbc_xml = esc_html('No', 'iq-block-country');
614
  }
615
  ?>
616
+ <tbody><tr><td><?php esc_html_e('PHP XML Support', 'iq-block-country'); ?>: <strong><?php echo esc_html($iqbc_xml); ?></strong></td></tr></tbody>
617
  <?php
618
+ if (is_callable('iptcparse') ) {
619
+ $iqbc_iptc = esc_html('Yes', 'iq-block-country');
620
  } else {
621
+ $iqbc_iptc = esc_html('No', 'iq-block-country');
622
  }
623
  ?>
624
+ <tbody><tr><td><?php esc_html_e('PHP IPTC Support', 'iq-block-country'); ?>: <strong><?php echo esc_html($iqbc_iptc); ?></strong></td></tr></tbody>
625
+ <?php $iqbc_disabled_functions = str_replace(',', ', ', $iqbc_disabled_functions); // Normalize spaces or lack of spaces between disabled functions. ?>
626
+ <tbody><tr><td><?php esc_html_e('Disabled PHP Functions', 'iq-block-country'); ?>: <strong><?php echo esc_html($iqbc_disabled_functions); ?></strong></td></tr></tbody>
627
 
628
 
629
  </table>
630
 
631
 
632
 
633
+ <h3><?php esc_html_e('Wordpress info', 'iq-block-country'); ?></h3>
634
 
635
  <table class="widefat">
636
  <?php
637
+ if (is_multisite() ) {
638
+ $iqbc_multSite = esc_html('is enabled', 'iq-block-country');
639
  } else {
640
+ $iqbc_multSite = esc_html('is disabled', 'iq-block-country');
641
  }
642
  ?>
643
+ <tbody><tr><td><?php esc_html_e(' Multisite', 'iq-block-country'); ?> <strong><?php echo esc_html($iqbc_multSite); ?></strong></td></tr></tbody>
644
  <?php
645
+ if (get_option('permalink_structure') != '' ) {
646
+ $iqbc_permalink_structure = esc_html('are enabled', 'iq-block-country');
647
  } else {
648
+ $iqbc_permalink_structure = esc_html('are disabled', 'iq-block-country');
649
  }
650
  ?>
651
+ <tbody><tr><td><?php esc_html_e('Permalinks', 'iq-block-country'); ?>
652
+ <strong> <?php echo esc_html($iqbc_permalink_structure); ?></strong></td></tr></tbody>
653
+ <tbody><tr><td><?php esc_html_e('Document Root Path', 'iq-block-country'); ?>: <strong><?php echo esc_html(WP_CONTENT_DIR) ?></strong></td></tr></tbody>
654
  </table>
655
 
656
  <br />
657
  <br />
658
+ <h3><?php esc_html_e('IP Address information', 'iq-block-country'); ?></h3>
659
 
660
  <?php
661
  echo "<br />HTTP_CF_CONNECTING_IP: ";
662
+ if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && !empty($_SERVER['HTTP_CF_CONNECTING_IP']) ) {
663
+ echo esc_html($_SERVER['HTTP_CF_CONNECTING_IP']);
664
+ }
665
+ else { esc_html_e('Not set', 'iq-block-country');
666
  }
 
667
  echo "<br />HTTP_X_SUCURI_CLIENTIP: ";
668
+ if (isset($_SERVER['HTTP_X_SUCURI_CLIENTIP']) && !empty($_SERVER['HTTP_X_SUCURI_CLIENTIP']) ) {
669
+ echo esc_html($_SERVER['HTTP_X_SUCURI_CLIENTIP']);
670
+ }
671
+ else { esc_html_e('Not set', 'iq-block-country');
672
  }
 
673
  echo "<br />HTTP_INCAP_CLIENT_IP: ";
674
+ if (isset($_SERVER['HTTP_INCAP_CLIENT_IP']) && !empty($_SERVER['HTTP_INCAP_CLIENT_IP']) ) {
675
+ echo esc_html($_SERVER['HTTP_INCAP_CLIENT_IP']);
676
+ }
677
+ else { esc_html_e('Not set', 'iq-block-country');
678
  }
 
679
  echo "<br />HTTP_X_FORWARDED_FOR: ";
680
+ if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
681
+ echo esc_html($_SERVER['HTTP_X_FORWARDED_FOR']);
682
  }
683
+ else { esc_html_e('Not set', 'iq-block-country');
684
+ }
685
  echo "<br />HTTP_X_FORWARDED: ";
686
+ if (isset($_SERVER['HTTP_X_FORWARDED']) && !empty($_SERVER['HTTP_X_FORWARDED']) ) {
687
+ echo esc_html($_SERVER['HTTP_X_FORWARDED']);
688
+ }
689
+ else { esc_html_e('Not set', 'iq-block-country');
690
  }
 
691
  echo "<br />HTTP_CLIENT_IP: ";
692
+ if (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP']) ) {
693
+ echo esc_html($_SERVER['HTTP_CLIENT_IP']);
694
+ }
695
+ else { esc_html_e('Not set', 'iq-block-country');
696
  }
 
697
  echo "<br />HTTP_X_REAL_IP: ";
698
+ if (isset($_SERVER['HTTP_X_REAL_IP']) && !empty($_SERVER['HTTP_X_REAL_IP']) ) {
699
+ echo esc_html($_SERVER['HTTP_X_REAL_IP']);
700
  }
701
+ else { esc_html_e('Not set', 'iq-block-country');
702
+ }
703
  echo "<br />HTTP_FORWARDED: ";
704
+ if (isset($_SERVER['HTTP_FORWARDED']) && !empty($_SERVER['HTTP_FORWARDED']) ) {
705
+ echo esc_html($_SERVER['HTTP_FORWARDED']);
706
+ }
707
+ else { esc_html_e('Not set', 'iq-block-country');
708
  }
 
709
  echo "<br />REMOTE_ADDR: ";
710
+ if (isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['REMOTE_ADDR']) ) {
711
+ echo esc_html($_SERVER['REMOTE_ADDR']);
712
+ }
713
+ else { esc_html_e('Not set', 'iq-block-country');
714
  }
 
715
 
716
  ?>
717
 
718
+ <?php
719
  }
720
 
721
  /*
722
  * Function: Import/Export settings
723
  */
724
+ function iqblockcountry_settings_importexport()
725
+ {
726
+ $iqbc_dir = wp_upload_dir();
727
+ if (!isset($_POST['iqbc_export']) && !isset($_POST['iqbc_import'])) {
728
  ?>
729
  <div class="wrap">
730
  <div id="icon-tools" class="icon32"><br /></div>
731
+ <h2><?php esc_html_e('Export', 'iq-block-country'); ?></h2>
732
+ <p><?php esc_html_e('When you click on Backup all settings button a backup of the iQ Block Country configuration will be created.', 'iq-block-country'); ?></p>
733
+ <p><?php esc_html_e('After exporting, you can either use the backup file to restore your settings on this site again or copy the settings to another WordPress site.', 'iq-block-country'); ?></p>
734
  <form method='post'>
735
  <p class="submit">
736
  <?php wp_nonce_field('iqblockexport'); ?>
737
+ <input type='submit' name='iqbc_export' value='<?php esc_html_e('Backup all settings', 'iq-block-country'); ?>'/>
738
  </p>
739
  </form>
740
  </div>
741
 
742
  <div class="wrap">
743
  <div id="icon-tools" class="icon32"><br /></div>
744
+ <h2><?php esc_html_e('Import', 'iq-block-country'); ?></h2>
745
+ <p><?php esc_html_e('Click the browse button and choose a zip file that you exported before.', 'iq-block-country'); ?></p>
746
+ <p><?php esc_html_e('Press Restore settings button, and let WordPress do the magic for you.', 'iq-block-country'); ?></p>
747
  <form method='post' enctype='multipart/form-data'>
748
  <p class="submit">
749
  <?php wp_nonce_field('iqblockimport'); ?>
750
+ <input type='file' name='iqbc_import' />
751
+ <input type='submit' name='iqbc_import' value='<?php esc_html_e('Restore settings', 'iq-block-country'); ?>'/>
752
  </p>
753
  </form>
754
  </div>
755
  <?php
756
  }
757
+ elseif (isset($_POST['iqbc_export'])) {
758
 
759
+ $iqbc_date = date("d-m-Y");
760
+ $iqbc_randstr=rand();
761
+ $iqbc_resultrand = sha1($iqbc_randstr);
762
+ $iqbc_json_name = "iqblockcountry-".$iqbc_date . "-" . $iqbc_resultrand; // Filename will be generated with random string.
 
763
 
764
+ $iqbc_optarr = iqblockcountry_get_options_arr();
765
+ foreach ( $iqbc_optarr as $iqbc_options ) {
766
+ $iqbc_value = get_option($iqbc_options);
767
+ $need_options[$iqbc_options] = $iqbc_value;
768
  }
769
 
770
+ $iqbc_json_file = json_encode($need_options); // Encode data into json data
771
 
772
+ if (!$iqbc_handle = fopen($iqbc_dir['path'] . '/' . 'iqblockcountry.ini', 'w') ) {
773
+ wp_die( esc_html("Something went wrong exporting this file", 'iq-block-country'));
774
+ }
775
 
776
+ if (!fwrite($iqbc_handle, $iqbc_json_file) ) {
777
+ wp_die( esc_html("Something went wrong exporting this file", 'iq-block-country'));
778
+ }
779
 
780
+ fclose($iqbc_handle);
781
 
782
+ chdir($iqbc_dir['path']);
783
+ $iqbc_zipfiles = array('iqblockcountry.ini');
784
+ $iqbc_zipfilename = $iqbc_dir['path'] . '/' . $iqbc_json_name . '-iqblockcountry.zip';
785
+ $iqbc_zip = new ZipArchive;
786
+ $iqbc_zip->open($iqbc_zipfilename, ZipArchive::CREATE);
787
+ foreach ($iqbc_zipfiles as $iqbc_file) {
788
+ $iqbc_zip->addFile($iqbc_file);
789
  }
790
+ $iqbc_zip->close();
791
+ unlink($iqbc_dir['path'] . '/iqblockcountry.ini');
792
 
793
+ $iqbc_url = $iqbc_dir['url'] . '/' . $iqbc_json_name . '-iqblockcountry.zip';
794
+ $iqbc_content = "<div class='notice notice-success'><p>" . esc_html("Exporting settings...", 'iq-block-country') . "</p></div>";
795
 
796
+ if ($iqbc_url ) {
797
+ $iqbc_content .= '<script type="text/javascript">
798
+ document.location = \'' . $iqbc_url . '\';
799
  </script>';
800
  } else {
801
+ $iqbc_content .= 'Error: ' . $iqbc_url;
802
  }
803
+ echo $iqbc_content;
804
  }
805
+ elseif (isset($_POST['iqbc_import'])) {
806
+ $iqbc_optarr = iqblockcountry_get_options_arr();
807
+ if (isset($_FILES['iqbc_import']) && check_admin_referer('iqblockimport')) {
808
+ if (($_FILES['iqbc_import']['error'] > 0) && ($_FILES['type'] == "application/x-zip-compressed")) {
809
+ wp_die( esc_html("Something went wrong importing this file", 'iq-block-country'));
810
  }
811
  else
812
  {
813
+ $iqbc_zip = new ZipArchive;
814
+ $iqbc_res = $iqbc_zip->open($_FILES['iqbc_import']['tmp_name']);
815
+ if ($iqbc_res === true) {
816
+ $iqbc_zip->extractTo($iqbc_dir['path'], 'iqblockcountry.ini');
817
+ $iqbc_zip->close();
818
+ } else {
819
+ wp_die( esc_html("Something went wrong importing this file", 'iq-block-country'));
820
+ }
821
+ if (file_exists($iqbc_dir['path'] . '/iqblockcountry.ini')) {
822
+ $encode_options = file_get_contents($iqbc_dir['path'] . '/iqblockcountry.ini');
823
+ $iqbc_options = json_decode($encode_options, true);
824
+ foreach ($iqbc_options as $iqbc_key => $iqbc_value) {
825
+ if (in_array($iqbc_key, $iqbc_optarr)) {
826
+ update_option($iqbc_key, $iqbc_value);
 
 
827
  }
 
 
 
828
  }
829
+ unlink($iqbc_dir['path'] . '/iqblockcountry.ini');
830
+
831
+ echo "<div class='notice notice-success'><p>" . esc_html("All options are restored successfully.", 'iq-block-country') . "</p></div>";
832
+ }
833
+ else {
834
+ wp_die( esc_html("ZIP File did not contain any settings", 'iq-block-country'));
835
+ }
836
  }
837
  }
838
  else {
839
+ wp_die( esc_html("Something went wrong importing this file", 'iq-block-country'));
840
  }
841
  }
842
+ else { wp_die( esc_html("No correct import or export option given.", 'iq-block-country'));
843
+ }
844
 
845
  }
846
 
847
  /*
848
  * Function: Page settings
849
  */
850
+ function iqblockcountry_settings_pages()
851
+ {
852
  ?>
853
+ <h3><?php esc_html_e('Select which pages are blocked.', 'iq-block-country'); ?></h3>
854
  <form method="post" action="options.php">
855
+ <?php
856
+ settings_fields('iqblockcountry-settings-group-pages');
857
+ ?>
858
+ <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
859
  <tr valign="top">
860
+ <th width="30%"><?php esc_html_e('Do you want to block individual pages:', 'iq-block-country'); ?><br />
861
+ <?php esc_html_e('If you do not select this option all pages will be blocked.', 'iq-block-country'); ?></th>
862
  <td width="70%">
863
+ <input type="checkbox" name="blockcountry_blockpages" value="on" <?php checked('on', get_option('blockcountry_blockpages'), true); ?> />
864
  </td></tr>
865
 
866
 
867
  <tr valign="top">
868
+ <th width="30%"><?php esc_html_e('Block pages selected below:', 'iq-block-country'); ?><br />
869
+ <?php esc_html_e('Block all pages except those selected below', 'iq-block-country'); ?></th>
870
  <td width="70%">
871
+ <input type="radio" name="blockcountry_blockpages_inverse" value="off" <?php checked('off', get_option('blockcountry_blockpages_inverse'), true); ?> <?php checked(false, get_option('blockcountry_blockpages_inverse'), true); ?> /><br />
872
  <input type="radio" name="blockcountry_blockpages_inverse" value="on" <?php checked('on', get_option('blockcountry_blockpages_inverse'), true); ?> />
873
  </td></tr>
874
 
875
  <tr valign="top">
876
+ <th width="30%"><?php esc_html_e('Select pages you want to block:', 'iq-block-country'); ?></th>
877
  <td width="70%">
878
 
879
+ <ul>
880
  <?php
881
+ $iqbc_selectedpages = get_option('blockcountry_pages');
882
+ $iqbc_pages = get_pages();
883
+ $iqbc_selected = "";
884
+ foreach ( $iqbc_pages as $iqbc_page ) {
885
+ if (is_array($iqbc_selectedpages)) {
886
+ if (in_array($iqbc_page->ID, $iqbc_selectedpages) ) {
887
+ $iqbc_selected = " checked=\"checked\"";
888
+ } else {
889
+ $iqbc_selected = "";
890
+ }
891
+ }
892
+ echo "<li><input type=\"checkbox\" " . $iqbc_selected . " name=\"blockcountry_pages[]\" value=\"" . $iqbc_page->ID . "\" id=\"" . $iqbc_page->post_title . "\" /> <label for=\"" . $iqbc_page->post_title . "\">" . $iqbc_page->post_title . "</label></li>";
893
+ }
894
+ ?>
895
  </td></tr>
896
  <tr><td></td><td>
897
+ <p class="submit"><input type="submit" class="button-primary"
898
+ value="<?php esc_html_e('Save Changes', 'iq-block-country')?>" /></p>
899
+ </td></tr>
900
+ </table>
901
  </form>
902
 
903
+ <?php
904
  }
905
 
906
  /*
907
  * Function: Categories settings
908
  */
909
+ function iqblockcountry_settings_categories()
910
+ {
911
  ?>
912
+ <h3><?php esc_html_e('Select which categories are blocked.', 'iq-block-country'); ?></h3>
913
  <form method="post" action="options.php">
914
+ <?php
915
+ settings_fields('iqblockcountry-settings-group-cat');
916
+ ?>
917
+ <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
918
  <tr valign="top">
919
+ <th width="30%"><?php esc_html_e('Do you want to block individual categories:', 'iq-block-country'); ?><br />
920
+ <?php esc_html_e('If you do not select this option all blog articles will be blocked.', 'iq-block-country'); ?></th>
921
  <td width="70%">
922
+ <input type="checkbox" name="blockcountry_blockcategories" value="on" <?php checked('on', get_option('blockcountry_blockcategories'), true); ?> />
923
  </td></tr>
924
  <tr valign="top">
925
+ <th width="30%"><?php esc_html_e('Do you want to block the homepage:', 'iq-block-country'); ?><br />
926
+ <?php esc_html_e('If you do not select this option visitors will not be blocked from your homepage regardless of the categories you select.', 'iq-block-country'); ?></th>
927
  <td width="70%">
928
+ <input type="checkbox" name="blockcountry_blockhome" value="on" <?php checked('on', get_option('blockcountry_blockhome'), true); ?> />
929
  </td></tr>
930
  <tr valign="top">
931
+ <th width="30%"><?php esc_html_e('Select categories you want to block:', 'iq-block-country'); ?></th>
932
  <td width="70%">
933
 
934
+ <ul>
935
  <?php
936
+ $iqbc_selectedcategories = get_option('blockcountry_categories');
937
+ $iqbc_categories = get_categories(array("hide_empty"=>0));
938
+ $iqbc_selected = "";
939
+ foreach ( $iqbc_categories as $iqbc_category ) {
940
+ if (is_array($iqbc_selectedcategories)) {
941
+ if (in_array($iqbc_category->term_id, $iqbc_selectedcategories) ) {
942
+ $iqbc_selected = " checked=\"checked\"";
943
+ } else {
944
+ $iqbc_selected = "";
945
+ }
946
+ }
947
+ echo "<li><input type=\"checkbox\" " . $iqbc_selected . " name=\"blockcountry_categories[]\" value=\"" . $iqbc_category->term_id . "\" id=\"" . $iqbc_category->name . "\" /> <label for=\"" . $iqbc_category->name . "\">" . $iqbc_category->name . "</label></li>";
948
+ }
949
+ ?>
950
  </td></tr>
951
  <tr><td></td><td>
952
+ <p class="submit"><input type="submit" class="button-primary"
953
+ value="<?php esc_html_e('Save Changes', 'iq-block-country')?>" /></p>
954
+ </td></tr>
955
+ </table>
956
  </form>
957
 
958
+ <?php
959
  }
960
 
961
  /*
962
  * Function: Categories settings
963
  */
964
+ function iqblockcountry_settings_tags()
965
+ {
966
  ?>
967
+ <h3><?php esc_html_e('Select which tags are blocked.', 'iq-block-country'); ?></h3>
968
  <form method="post" action="options.php">
969
+ <?php
970
+ settings_fields('iqblockcountry-settings-group-tags');
971
+ ?>
972
+ <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
973
  <tr valign="top">
974
+ <th width="30%"><?php esc_html_e('Do you want to block individual tags:', 'iq-block-country'); ?><br />
975
+ <?php esc_html_e('If you do not select this option all blog articles will be blocked.', 'iq-block-country'); ?></th>
976
  <td width="70%">
977
+ <input type="checkbox" name="blockcountry_blocktags" value="on" <?php checked('on', get_option('blockcountry_blocktags'), true); ?> />
978
  </td></tr>
979
  <tr valign="top">
980
+ <th width="30%"><?php esc_html_e('Select tags you want to block:', 'iq-block-country'); ?></th>
981
  <td width="70%">
982
 
983
+ <ul>
984
  <?php
985
+ $iqbc_selectedtags = get_option('blockcountry_tags');
986
+ $iqbc_tags = get_tags(array("hide_empty"=>0));
987
+ $iqbc_selected = "";
988
+ foreach ( $iqbc_tags as $iqbc_tag ) {
989
+ if (is_array($iqbc_selectedtags)) {
990
+ if (in_array($iqbc_tag->term_id, $iqbc_selectedtags) ) {
991
+ $iqbc_selected = " checked=\"checked\"";
992
+ } else {
993
+ $iqbc_selected = "";
994
+ }
995
+ }
996
+ echo "<li><input type=\"checkbox\" " . $iqbc_selected . " name=\"blockcountry_tags[]\" value=\"" . $iqbc_tag->term_id . "\" id=\"" . $iqbc_tag->name . "\" /> <label for=\"" . $iqbc_tag->name . "\">" . $iqbc_tag->name . "</label></li>";
997
+ }
998
+ ?>
999
  </td></tr>
1000
  <tr><td></td><td>
1001
+ <p class="submit"><input type="submit" class="button-primary"
1002
+ value="<?php esc_html_e('Save Changes', 'iq-block-country')?>" /></p>
1003
+ </td></tr>
1004
+ </table>
1005
  </form>
1006
 
1007
+ <?php
1008
  }
1009
 
1010
 
1011
  /*
1012
  * Function: Custom post type settings
1013
  */
1014
+ function iqblockcountry_settings_posttypes()
1015
+ {
1016
  ?>
1017
+ <h3><?php esc_html_e('Select which post types are blocked.', 'iq-block-country'); ?></h3>
1018
  <form method="post" action="options.php">
1019
+ <?php
1020
+ settings_fields('iqblockcountry-settings-group-posttypes');
1021
+ ?>
1022
+ <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
1023
  <tr valign="top">
1024
+ <th width="30%"><?php esc_html_e('Do you want to block individual post types:', 'iq-block-country'); ?><br />
1025
  <td width="70%">
1026
+ <input type="checkbox" name="blockcountry_blockposttypes" value="on" <?php checked('on', get_option('blockcountry_blockposttypes'), true); ?> />
1027
  </td></tr>
1028
  <tr valign="top">
1029
+ <th width="30%"><?php esc_html_e('Select post types you want to block:', 'iq-block-country'); ?></th>
1030
  <td width="70%">
1031
 
1032
+ <ul>
1033
  <?php
1034
+ $iqbc_post_types = get_post_types('', 'names');
1035
+ $iqbc_selectedposttypes = get_option('blockcountry_posttypes');
1036
+ $iqbc_selected = "";
1037
+ foreach ( $iqbc_post_types as $iqbc_post_type ) {
1038
+ if (is_array($iqbc_selectedposttypes)) {
1039
+ if (in_array($iqbc_post_type, $iqbc_selectedposttypes) ) {
1040
+ $iqbc_selected = " checked=\"checked\"";
1041
+ } else {
1042
+ $iqbc_selected = "";
1043
+ }
1044
+ }
1045
+ echo "<li><input type=\"checkbox\" " . $iqbc_selected . " name=\"blockcountry_posttypes[]\" value=\"" . $iqbc_post_type . "\" id=\"" . $iqbc_post_type . "\" /> <label for=\"" . $iqbc_post_type . "\">" . $iqbc_post_type . "</label></li>";
1046
+ }
1047
+ ?>
1048
  </td></tr>
1049
  <tr><td></td><td>
1050
+ <p class="submit"><input type="submit" class="button-primary"
1051
+ value="<?php esc_html_e('Save Changes', 'iq-block-country')?>" /></p>
1052
+ </td></tr>
1053
+ </table>
1054
  </form>
1055
 
1056
+ <?php
1057
  }
1058
 
1059
 
1061
  /*
1062
  * Function: Services settings
1063
  */
1064
+ function iqblockcountry_settings_services()
1065
+ {
1066
  ?>
1067
+ <h3><?php esc_html_e('Select which services are allowed.', 'iq-block-country'); ?></h3>
1068
  <form method="post" action="options.php">
1069
+ <?php
1070
+ settings_fields('iqblockcountry-settings-group-se');
1071
+ ?>
1072
+ <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
1073
  <tr valign="top">
1074
+ <th width="30%"><?php esc_html_e('Select which services you want to allow:', 'iq-block-country'); ?><br />
1075
+ <?php esc_html_e('This will allow a service like for instance a search engine to your site despite if you blocked the country.', 'iq-block-country'); ?><br />
1076
+ <?php esc_html_e('Please note the "Search Engine Visibility" should not be selected in ', 'iq-block-country'); ?><a href="/wp-admin/options-reading.php"><?php esc_html_e('reading settings.', 'iq-block-country'); ?></a>
1077
  </th>
1078
  <td width="70%">
1079
 
1080
+ <ul>
1081
  <?php
1082
+ global $iqbc_searchengines;
1083
+ $iqbc_selectedse = get_option('blockcountry_allowse');
1084
+ $iqbc_selected = "";
1085
+ foreach ( $iqbc_searchengines AS $iqbc_se => $iqbc_seua ) {
1086
+ if (is_array($iqbc_selectedse)) {
1087
+ if (in_array($iqbc_se, $iqbc_selectedse) ) {
1088
+ $iqbc_selected = " checked=\"checked\"";
1089
+ } else {
1090
+ $iqbc_selected = "";
1091
+ }
1092
+ }
1093
+ echo "<li><input type=\"checkbox\" " . $iqbc_selected . " name=\"blockcountry_allowse[]\" value=\"" . $iqbc_se . "\" id=\"" . $iqbc_se . "\" /> <label for=\"" . $iqbc_se . "\">" . $iqbc_se . "</label></li>";
1094
+ }
1095
+ ?>
1096
  </td></tr>
1097
  <tr><td></td><td>
1098
+ <p class="submit"><input type="submit" class="button-primary"
1099
+ value="<?php esc_html_e('Save Changes', 'iq-block-country')?>" /></p>
1100
+ </td></tr>
1101
+ </table>
1102
  </form>
1103
 
1104
+ <?php
1105
  }
1106
 
1107
 
1110
  */
1111
  function iqblockcountry_settings_frontend()
1112
  {
1113
+ ?>
1114
+ <h3><?php esc_html_e('Frontend options', 'iq-block-country'); ?></h3>
1115
 
1116
  <form method="post" action="options.php">
1117
  <?php
1118
+ settings_fields('iqblockcountry-settings-group-frontend');
1119
+ if (!class_exists('GeoIP')) {
1120
+ include_once "geoip.inc";
1121
+ }
1122
+ if (class_exists('GeoIP')) {
1123
+ $iqbc_countrylist = iqblockcountry_get_isocountries();
1124
+
1125
+ $iqbc_ip_address = iqblockcountry_get_ipaddress();
1126
+ $iqbc_country = iqblockcountry_check_ipaddress($iqbc_ip_address);
1127
+ if ($iqbc_country == "Unknown" || $iqbc_country == "ipv6" || $iqbc_country == "" || $iqbc_country == "FALSE") { $iqbc_displaycountry = "Unknown";
1128
+ }
1129
+ else { $iqbc_displaycountry = $iqbc_countrylist[$iqbc_country];
1130
+ }
 
1131
 
1132
+ ?>
1133
 
 
1134
 
1135
 
1136
+ <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
1137
 
1138
  <tr valign="top">
1139
+ <th width="30%"><?php esc_html_e('Block visitors from visiting the frontend of your website:', 'iq-block-country'); ?></th>
1140
  <td width="70%">
1141
+ <input type="checkbox" name="blockcountry_blockfrontend" <?php checked('on', get_option('blockcountry_blockfrontend'), true); ?> />
1142
  </td></tr>
1143
 
1144
+ <tr valign="top">
1145
+ <th width="30%"><?php esc_html_e('Do not block visitors that are logged in from visiting frontend website:', 'iq-block-country'); ?></th>
1146
+ <td width="70%">
1147
+ <input type="checkbox" name="blockcountry_blocklogin" <?php checked('on', get_option('blockcountry_blocklogin'), true); ?> />
1148
+ </td></tr>
1149
 
1150
  <tr valign="top">
1151
+ <th width="30%"><?php esc_html_e('Block visitors from using the search function of your website:', 'iq-block-country'); ?></th>
1152
  <td width="70%">
1153
+ <input type="checkbox" name="blockcountry_blocksearch" <?php checked('on', get_option('blockcountry_blocksearch'), true); ?> />
1154
  </td></tr>
1155
 
1156
  <tr valign="top">
1157
+ <th width="30%"><?php esc_html_e('Block countries selected below:', 'iq-block-country'); ?><br />
1158
+ <?php esc_html_e('Block all countries except those selected below', 'iq-block-country'); ?></th>
1159
  <td width="70%">
1160
+ <input type="radio" name="blockcountry_banlist_inverse" value="off" <?php checked('off', get_option('blockcountry_banlist_inverse'), true); ?> <?php checked(false, get_option('blockcountry_banlist_inverse'), true); ?> /><br />
1161
  <input type="radio" name="blockcountry_banlist_inverse" value="on" <?php checked('on', get_option('blockcountry_banlist_inverse'), true); ?> />
1162
  </td></tr>
1163
 
1164
  <tr valign="top">
1165
+ <th scope="row" width="30%"><?php esc_html_e('Select the countries:', 'iq-block-country'); ?><br />
1166
+ <?php esc_html_e('Use the CTRL key to select multiple countries', 'iq-block-country'); ?></th>
1167
+ <td width="70%">
1168
 
1169
  <?php
1170
+ $iqbc_selected = "";
1171
+ $iqbc_haystack = get_option('blockcountry_banlist');
1172
 
1173
+ if (get_option('blockcountry_accessibility')) {
 
1174
  echo "<ul>";
1175
+ foreach ( $iqbc_countrylist as $iqbc_key => $iqbc_value ) {
1176
+ if (is_array($iqbc_haystack) && in_array($iqbc_key, $iqbc_haystack)) {
1177
+ $iqbc_selected = " checked=\"checked\"";
1178
+ } else {
1179
+ $iqbc_selected = "";
1180
+ }
1181
+ echo "<li><input type=\"checkbox\" " . $iqbc_selected . " name=\"blockcountry_banlist[]\" value=\"" . esc_html($iqbc_key) . "\" \"/> <label for=\"" . esc_html($iqbc_value) . "\">" . esc_html($iqbc_value) . "</label></li>";
1182
  }
1183
  echo "</ul>";
1184
  }
1185
  else
1186
  {
1187
+ ?>
1188
 
1189
 
1190
  <select data-placeholder="Choose a country..." class="chosen" name="blockcountry_banlist[]" multiple="true" style="width:600px;">
1191
  <optgroup label="(de)select all countries">
1192
  <?php
1193
+ foreach ( $iqbc_countrylist as $iqbc_key => $iqbc_value ) {
1194
+ print "<option value=\"". esc_html($iqbc_key) ."\"";
1195
+ if (is_array($iqbc_haystack) && in_array($iqbc_key, $iqbc_haystack)) {
1196
+ print " selected=\"selected\" ";
1197
+ }
1198
+ print ">". esc_html($iqbc_value) ."</option>\n";
1199
+ }
1200
  echo "</optgroup>";
1201
  echo " </select>";
1202
  }
1203
 
1204
+ ?>
1205
  </td></tr>
1206
  <tr valign="top">
1207
+ <th width="30%"><?php esc_html_e('Block tag pages:', 'iq-block-country'); ?><br />
1208
+ <?php esc_html_e('If you select this option tag pages will be blocked.', 'iq-block-country')?></th>
1209
  <td width="70%">
1210
  <input type="checkbox" name="blockcountry_blocktag" <?php checked('on', get_option('blockcountry_blocktag'), true); ?> />
1211
  </td></tr>
1212
 
1213
  <tr valign="top">
1214
+ <th width="30%"><?php esc_html_e('Block feed:', 'iq-block-country'); ?><br />
1215
+ <?php esc_html_e('If you select this option feed pages will be blocked.', 'iq-block-country')?></th>
1216
  <td width="70%">
1217
  <input type="checkbox" name="blockcountry_blockfeed" <?php checked('on', get_option('blockcountry_blockfeed'), true); ?> />
1218
  </td></tr>
1220
 
1221
 
1222
  <tr valign="top">
1223
+ <th width="30%"><?php esc_html_e('Frontend allow list IPv4 and/or IPv6 addresses:', 'iq-block-country'); ?><br /><?php esc_html_e('Use a semicolon (;) to separate IP addresses', 'iq-block-country'); ?><br /><?php esc_html_e('This field accepts single IP addresses as well as ranges in CIDR format.', 'iq-block-country'); ?></th>
1224
+ <td width="70%">
1225
+ <?php
1226
+ $iqbc_frontendallowlist = get_option('blockcountry_frontendwhitelist');
1227
+ ?>
1228
+ <textarea cols="70" rows="5" name="blockcountry_frontendwhitelist"><?php echo esc_html($iqbc_frontendallowlist); ?></textarea>
1229
+ </td></tr>
1230
  <tr valign="top">
1231
+ <th width="30%"><?php esc_html_e('Frontend block list IPv4 and/or IPv6 addresses:', 'iq-block-country'); ?><br /><?php esc_html_e('Use a semicolon (;) to separate IP addresses', 'iq-block-country'); ?><br /><?php esc_html_e('This field accepts single IP addresses as well as ranges in CIDR format.', 'iq-block-country'); ?></th>
1232
+ <td width="70%">
1233
+ <?php
1234
+ $iqbc_frontendblocklist = get_option('blockcountry_frontendblacklist');
1235
+ ?>
1236
+ <textarea cols="70" rows="5" name="blockcountry_frontendblacklist"><?php echo esc_html($iqbc_frontendblocklist); ?></textarea>
1237
+ </td></tr>
1238
+ <tr><td></td><td>
1239
+ <p class="submit"><input type="submit" class="button-primary"
1240
+ value="<?php esc_html_e('Save Changes', 'iq-block-country')?>" /></p>
1241
+ </td></tr>
1242
+ </table>
1243
  </form>
1244
+ <?php
1245
+ }
1246
+ else
1247
  {
1248
+ print "<p>You are missing the GeoIP class. Perhaps geoip.inc is missing?</p>";
1249
+ }
1250
 
1251
  }
1252
 
1256
  */
1257
  function iqblockcountry_settings_backend()
1258
  {
1259
+ ?>
1260
+ <h3><?php esc_html_e('Backend Options', 'iq-block-country'); ?></h3>
1261
 
1262
  <form method="post" action="options.php">
1263
  <?php
1264
+ settings_fields('iqblockcountry-settings-group-backend');
1265
+ if (!class_exists('GeoIP')) {
1266
+ include_once "geoip.inc";
1267
+ }
1268
+ if (class_exists('GeoIP')) {
1269
+
1270
+ $iqbc_countrylist = iqblockcountry_get_isocountries();
1271
+
1272
+ $iqbc_ip_address = iqblockcountry_get_ipaddress();
1273
+ $iqbc_country = iqblockcountry_check_ipaddress($iqbc_ip_address);
1274
+ if ($iqbc_country == "Unknown" || $iqbc_country == "ipv6" || $iqbc_country == "" || $iqbc_country == "FALSE") { $iqbc_displaycountry = "Unknown";
1275
+ }
1276
+ else { $iqbc_displaycountry = $iqbc_countrylist[$iqbc_country];
1277
+ }
 
1278
 
1279
 
1280
+ ?>
 
 
 
1281
 
1282
+ <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
1283
+ <tr valign="top">
1284
+ <th width="30%"><?php esc_html_e('Block visitors from visiting the backend (administrator) of your website:', 'iq-block-country'); ?></th>
1285
+ <td width="70%">
1286
+ <input type="checkbox" name="blockcountry_blockbackend" <?php checked('on', get_option('blockcountry_blockbackend'), true); ?> />
1287
  </td></tr>
1288
 
1289
  <tr>
1290
  <th width="30%"></th>
1291
  <th width="70%">
1292
+ <?php esc_html_e('Your IP address is', 'iq-block-country'); ?> <i><?php echo $iqbc_ip_address ?></i>. <?php esc_html_e('The country that is listed for this IP address is', 'iq-block-country'); ?> <em><?php echo $iqbc_displaycountry ?></em>.<br />
1293
+ <?php esc_html_e('Do NOT set the \'Block visitors from visiting the backend (administrator) of your website\' and also select', 'iq-block-country'); ?> <?php echo $iqbc_displaycountry ?> <?php esc_html_e('below.', 'iq-block-country'); ?><br />
1294
+ <?php echo "<strong>" . esc_html_e('You will NOT be able to login the next time if you DO block your own country from visiting the backend.', 'iq-block-country') . "</strong>"; ?>
1295
  </th>
1296
  </tr>
1297
+ </td></tr>
1298
  <tr valign="top">
1299
+ <th width="30%"><?php esc_html_e('Block countries selected below:', 'iq-block-country'); ?><br />
1300
+ <?php esc_html_e('Block all countries except those selected below', 'iq-block-country'); ?></th>
1301
  <td width="70%">
1302
+ <input type="radio" name="blockcountry_backendbanlist_inverse" value="off" <?php checked('off', get_option('blockcountry_backendbanlist_inverse'), true); ?> <?php checked(false, get_option('blockcountry_backendbanlist_inverse'), true); ?> /><br />
1303
  <input type="radio" name="blockcountry_backendbanlist_inverse" value="on" <?php checked('on', get_option('blockcountry_backendbanlist_inverse'), true); ?> />
1304
  </td></tr>
1305
 
1306
  <tr valign="top">
1307
+ <th scope="row" width="30%"><?php esc_html_e('Select the countries:', 'iq-block-country'); ?><br />
1308
+ <?php esc_html_e('Use the CTRL key to select multiple countries', 'iq-block-country'); ?></th>
1309
+ <td width="70%">
1310
 
1311
  <?php
1312
+ $iqbc_selected = "";
1313
+ $iqbc_haystack = get_option('blockcountry_backendbanlist');
1314
+
1315
+ if (get_option('blockcountry_accessibility')) {
1316
+ echo "<ul>";
1317
+ foreach ( $iqbc_countrylist as $iqbc_key => $iqbc_value ) {
1318
+ if (is_array($iqbc_haystack) && in_array($iqbc_key, $iqbc_haystack)) {
1319
+ $iqbc_selected = " checked=\"checked\"";
1320
+ } else {
1321
+ $iqbc_selected = "";
1322
+ }
1323
+ echo "<li><input type=\"checkbox\" " . $iqbc_selected . " name=\"blockcountry_backendbanlist[]\" value=\"" . esc_html($iqbc_key) . "\" \"/> <label for=\"" . esc_html($iqbc_value) . "\">" . esc_html($iqbc_value) . "</label></li>";
1324
+ }
1325
+ echo "</ul>";
1326
+ }
1327
+ else
1328
+ {
1329
+ ?> <select class="chosen" data-placeholder="Choose a country..." name="blockcountry_backendbanlist[]" multiple="true" style="width:600px;">
 
1330
  <optgroup label="(de)select all countries">
1331
 
1332
+ <?php
1333
+ foreach ( $iqbc_countrylist as $iqbc_key => $iqbc_value ) {
1334
+ print "<option value=\"". esc_html($iqbc_key) . "\"";
1335
+ if (is_array($iqbc_haystack) && in_array($iqbc_key, $iqbc_haystack)) {
1336
+ print " selected=\"selected\" ";
1337
+ }
1338
+ print ">". esc_html($iqbc_value) . "</option>\n";
1339
  }
1340
  echo "</optgroup>";
1341
  echo " </select>";
1342
+ }
1343
+ ?>
1344
 
1345
  </td></tr>
1346
 
1347
  <tr valign="top">
1348
+ <th width="30%"><?php esc_html_e('Backend allow list IPv4 and/or IPv6 addresses:', 'iq-block-country'); ?><br /><?php esc_html_e('Use a semicolon (;) to separate IP addresses', 'iq-block-country'); ?><br /><?php esc_html_e('This field accepts single IP addresses as well as ranges in CIDR format.', 'iq-block-country'); ?></th>
1349
+ <td width="70%">
1350
+ <?php
1351
+ $iqbc_backendallowlist = get_option('blockcountry_backendwhitelist');
1352
+ ?>
1353
+ <textarea cols="70" rows="5" name="blockcountry_backendwhitelist"><?php echo esc_html($iqbc_backendallowlist); ?></textarea>
1354
+ </td></tr>
1355
  <tr valign="top">
1356
+ <th width="30%"><?php esc_html_e('Backend block list IPv4 and/or IPv6 addresses:', 'iq-block-country'); ?><br /><?php esc_html_e('Use a semicolon (;) to separate IP addresses', 'iq-block-country'); ?><br /><?php esc_html_e('This field accepts single IP addresses as well as ranges in CIDR format.', 'iq-block-country'); ?></th>
1357
+ <td width="70%">
1358
+ <?php
1359
+ $iqbc_backendblocklist = get_option('blockcountry_backendblacklist');
1360
+ ?>
1361
+ <textarea cols="70" rows="5" name="blockcountry_backendblacklist"><?php echo esc_html($iqbc_backendblocklist); ?></textarea>
1362
+ </td></tr>
1363
+ <tr><td></td><td>
1364
+ <p class="submit"><input type="submit" class="button-primary"
1365
+ value="<?php esc_html_e('Save Changes', 'iq-block-country')?>" /></p>
1366
+ </td></tr>
1367
+ </table>
1368
  </form>
1369
+ <?php
1370
+ }
1371
+ else
1372
  {
1373
+ print "<p>You are missing the GeoIP class. Perhaps geoip.inc is missing?</p>";
1374
+ }
1375
 
1376
  }
1377
 
1383
  function iqblockcountry_settings_home()
1384
  {
1385
 
1386
+ /* Check if the Geo Database exists or if GeoIP API key is entered otherwise display notification */
1387
+ if (is_file(IQBCGEOIP2DBFILE) && (!get_option('blockcountry_geoapikey'))) {
1388
+ $iqbc_filedate = filemtime(IQBCGEOIP2DBFILE);
1389
+ $iqbc_3months = time() - 3 * 31 * 86400;
1390
+ if ($iqbc_filedate < $iqbc_3months) {
1391
+ iq_old_db_notice();
1392
+ }
1393
+ }
 
1394
 
1395
 
1396
+ ?>
1397
+ <h3><?php esc_html_e('Overall statistics since start', 'iq-block-country'); ?></h3>
1398
 
1399
+ <?php $iqbc_blocked = get_option('blockcountry_backendnrblocks'); ?>
1400
+ <p><?php echo esc_html(number_format($iqbc_blocked)); ?> <?php esc_html_e('visitors blocked from the backend.', 'iq-block-country'); ?></p>
1401
+ <?php $iqbc_blocked = get_option('blockcountry_frontendnrblocks'); ?>
1402
+ <p><?php echo esc_html(number_format($iqbc_blocked)); ?> <?php esc_html_e('visitors blocked from the frontend.', 'iq-block-country'); ?></p>
1403
 
1404
  <form method="post" action="options.php">
1405
  <?php
1406
+ settings_fields('iqblockcountry-settings-group');
1407
+ if (!class_exists('GeoIP')) {
1408
+ include_once "geoip.inc";
1409
+ }
1410
+ if (class_exists('GeoIP')) {
1411
+ $iqbc_countrylist = iqblockcountry_get_isocountries();
1412
+ ?>
1413
+
 
 
 
1414
 
1415
  <hr>
1416
+ <h3><?php esc_html_e('Block type', 'iq-block-country'); ?></h3>
1417
  <em>
1418
+ <?php esc_html_e('You should choose one of the 3 block options below. This wil either show a block message, redirect to an internal page or redirect to an external page.', 'iq-block-country'); ?>
1419
  </em>
1420
+ <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
1421
 
1422
  <tr valign="top">
1423
+ <th width="30%"><?php esc_html_e('Message to display when people are blocked:', 'iq-block-country'); ?></th>
1424
+ <td width="70%">
1425
+ <?php
1426
+ $iqbc_blockmessage = get_option('blockcountry_blockmessage');
1427
+ if (empty($iqbc_blockmessage)) { $iqbc_blockmessage = "Forbidden - Visitors from your country are not permitted to browse this site.";
1428
+ }
1429
+ ?>
1430
+ <textarea cols="100" rows="3" name="blockcountry_blockmessage"><?php echo esc_html($iqbc_blockmessage); ?></textarea>
1431
+ </td></tr>
1432
 
1433
 
1434
  <tr valign="top">
1435
+ <th width="30%"><?php esc_html_e('Page to redirect to:', 'iq-block-country'); ?><br />
1436
+ <em><?php esc_html_e('If you select a page here blocked visitors will be redirected to this page instead of displaying above block message.', 'iq-block-country'); ?></em></th>
1437
  </th>
1438
+ <td width="70%">
1439
  <select class="chosen" name="blockcountry_redirect" style="width:400px;">
1440
  <?php
1441
+ $iqbc_haystack = get_option('blockcountry_redirect');
1442
+ echo "<option value=\"0\">". esc_html("Choose a page...", 'iq-block-country') . "</option>";
1443
+ $iqbc_pages = get_pages();
1444
+ foreach ( $iqbc_pages as $iqbc_page ) {
1445
+ print "<option value=\"$iqbc_page->ID\"";
1446
+ if ($iqbc_page->ID == $iqbc_haystack) {
1447
+
1448
+ print " selected=\"selected\" ";
1449
+ }
1450
+ print ">" . esc_html($iqbc_page->post_title) . "</option>\n";
1451
+ }
1452
+ ?>
1453
  </select>
1454
  </td></tr>
1455
 
1456
  <tr valign="top">
1457
+ <th width="30%"><?php esc_html_e('URL to redirect to:', 'iq-block-country'); ?><br />
1458
+ <em><?php esc_html_e('If you enter a URL here blocked visitors will be redirected to this URL instead of displaying above block message or redirected to a local page.', 'iq-block-country'); ?></em>
1459
  </th>
1460
  <td width="70%">
1461
+ <input type="text" style="width:100%" name="blockcountry_redirect_url" value="<?php echo get_option('blockcountry_redirect_url');?>">
1462
  </td></tr>
1463
  </table>
1464
  <hr>
1465
+ <h3><?php esc_html_e('General settings', 'iq-block-country'); ?></h3>
1466
 
1467
+ <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
1468
  <tr valign="top">
1469
+ <th width="30%"><?php esc_html_e('Send headers when user is blocked:', 'iq-block-country'); ?><br />
1470
+ <em><?php esc_html_e('Under normal circumstances you should keep this selected! Only if you have "Cannot modify header information - headers already sent" errors or if you know what you are doing uncheck this.', 'iq-block-country'); ?></em></th>
1471
+ <td width="70%">
1472
+ <input type="checkbox" name="blockcountry_header" <?php checked('on', get_option('blockcountry_header'), true); ?> />
1473
+ </td></tr>
1474
 
1475
  <tr valign="top">
1476
+ <th width="30%"><?php esc_html_e('Buffer output?:', 'iq-block-country'); ?><br />
1477
+ <em><?php esc_html_e('You can use this option to buffer all output. This can be helpful in case you have "headers already sent" issues.', 'iq-block-country'); ?></em></th>
1478
+ <td width="70%">
1479
+ <input type="checkbox" name="blockcountry_buffer" <?php checked('on', get_option('blockcountry_buffer'), true); ?> />
1480
+ </td></tr>
1481
 
1482
+ <tr valign="top">
1483
+ <th width="30%"><?php esc_html_e('Do not log IP addresses:', 'iq-block-country'); ?><br />
1484
+ <em><?php esc_html_e('Check this box if the laws in your country do not permit you to log IP addresses or if you do not want to log the ip addresses.', 'iq-block-country'); ?></em></th>
1485
+ <td width="70%">
1486
+ <input type="checkbox" name="blockcountry_logging" <?php checked('on', get_option('blockcountry_logging'), true); ?> />
1487
+ </td></tr>
1488
+
1489
+ <tr valign="top">
1490
+ <th width="30%"><?php esc_html_e('Do not block admin-ajax.php:', 'iq-block-country'); ?><br />
1491
+ <em><?php esc_html_e('Check this box if you use a plugin that uses admin-ajax.php.', 'iq-block-country'); ?></em></th>
1492
+ <td width="70%">
1493
+ <input type="checkbox" name="blockcountry_adminajax" <?php checked('on', get_option('blockcountry_adminajax'), true); ?> />
1494
+ </td></tr>
1495
 
1496
 
1497
 
1498
 
1499
  <tr valign="top">
1500
+ <th width="30%"><?php esc_html_e('Number of rows on logging tab:', 'iq-block-country'); ?><br />
1501
+ <em><?php esc_html_e('How many rows do you want to display on each column on the logging tab.', 'iq-block-country'); ?></em></th>
1502
+ <td width="70%">
1503
+ <?php
1504
+ $iqbc_nrrows = get_option('blockcountry_nrstatistics'); ?>
1505
  <select name="blockcountry_nrstatistics">
1506
+ <option <?php selected($iqbc_nrrows, 10); ?> value="10">10</option>
1507
+ <option <?php selected($iqbc_nrrows, 15); ?> value="15">15</option>
1508
+ <option <?php selected($iqbc_nrrows, 20); ?> value="20">20</option>
1509
+ <option <?php selected($iqbc_nrrows, 25); ?> value="25">25</option>
1510
+ <option <?php selected($iqbc_nrrows, 30); ?> value="30">30</option>
1511
+ <option <?php selected($iqbc_nrrows, 45); ?> value="45">45</option>
1512
  </select>
1513
+ </td></tr>
1514
 
1515
  <tr valign="top">
1516
+ <th width="30%"><?php esc_html_e('Number of days to keep logging:', 'iq-block-country'); ?><br />
1517
+ <em><?php esc_html_e('How many days do you want to keep the logging used for the logging tab.', 'iq-block-country'); ?></em></th>
1518
+ <td width="70%">
1519
+ <?php
1520
+ $iqbc_nrdays = get_option('blockcountry_daysstatistics'); ?>
1521
  <select name="blockcountry_daysstatistics">
1522
+ <option <?php selected($iqbc_nrdays, 7); ?> value="7">7</option>
1523
+ <option <?php selected($iqbc_nrdays, 14); ?> value="14">14</option>
1524
+ <option <?php selected($iqbc_nrdays, 21); ?> value="21">21</option>
1525
+ <option <?php selected($iqbc_nrdays, 30); ?> value="30">30</option>
1526
+ <option <?php selected($iqbc_nrdays, 60); ?> value="60">60</option>
1527
+ <option <?php selected($iqbc_nrdays, 90); ?> value="90">90</option>
1528
  </select>
1529
+ </td></tr>
1530
+
1531
+ <tr valign="top">
1532
+ <th width="30%"><?php esc_html_e('Do not lookup hosts on the logging tab:', 'iq-block-country'); ?><br />
1533
+ <em><?php esc_html_e('On some hosting environments looking up hosts may slow down the logging tab.', 'iq-block-country'); ?></em></th>
1534
+ <td width="70%">
1535
+ <input type="checkbox" name="blockcountry_lookupstatistics" <?php checked('on', get_option('blockcountry_lookupstatistics'), true); ?> />
1536
+ </td></tr>
1537
 
1538
+ <tr valign="top">
1539
+ <th width="30%"><?php esc_html_e('Allow tracking:', 'iq-block-country'); ?><br />
1540
+ <em><?php esc_html_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>
1541
+ <td width="70%">
1542
+ <input type="checkbox" name="blockcountry_tracking" <?php checked('on', get_option('blockcountry_tracking'), true); ?> />
1543
+ </td></tr>
1544
 
1545
  <tr valign="top">
1546
+ <th width="30%"><?php esc_html_e('GeoIP API Key:', 'iq-block-country'); ?><br />
1547
+ <em><?php esc_html_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://webence.nl/geoip-api/" target="_blank">https://webence.nl/geoip-api/</a></em></th>
1548
  </th>
1549
  <td width="70%">
1550
+ <input type="text" size="25" name="blockcountry_geoapikey" value="<?php echo get_option('blockcountry_geoapikey');?>">
1551
  </td></tr>
1552
 
1553
 
1554
  <tr valign="top">
1555
+ <th width="30%"><?php esc_html_e('GeoIP API Key Server Location:', 'iq-block-country'); ?><br />
1556
+ <em><?php esc_html_e('Choose a location closest to your own location.', 'iq-block-country'); ?>
1557
  </th>
1558
+ <td width="70%">
1559
 
1560
  <input type="radio" name="blockcountry_geoapilocation" value="EU" <?php checked('EU', get_option('blockcountry_geoapilocation'), true); ?>> Europe (Netherlands)<br />
1561
+ <input type="radio" name="blockcountry_geoapilocation" value="EU3" <?php checked('EU3', get_option('blockcountry_geoapilocation'), true); ?>> Europe (Netherlands)<br />
1562
  <input type="radio" name="blockcountry_geoapilocation" value="US" <?php checked('US', get_option('blockcountry_geoapilocation'), true); ?>> United States - New York<br />
1563
  <input type="radio" name="blockcountry_geoapilocation" value="US2" <?php checked('US2', get_option('blockcountry_geoapilocation'), true); ?>> United States - San Francisco<br />
1564
  <input type="radio" name="blockcountry_geoapilocation" value="US3" <?php checked('US3', get_option('blockcountry_geoapilocation'), true); ?>> United States - Miami<br />
1565
 
1566
+ </td></tr>
1567
  <tr valign="top">
1568
+ <th width="30%"><?php esc_html_e('Admin block API Key:', 'iq-block-country'); ?><br />
1569
+ <em><?php esc_html_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://webence.nl/admin-block-api/" target="_blank">https://webence.nl/admin-block-api/</a></em></th>
1570
  </th>
1571
+ <td width="70%">
1572
+ <input type="text" size="25" name="blockcountry_apikey" value="<?php echo get_option('blockcountry_apikey');?>">
1573
+ </td></tr>
1574
 
1575
 
1576
+ <tr valign="top">
1577
+ <th width="30%"><?php esc_html_e('Accessibility options:', 'iq-block-country'); ?><br />
1578
+ <em><?php esc_html_e('Set this option if you cannot use the default country selection box.', 'iq-block-country'); ?></em></th>
1579
+ <td width="70%">
1580
+ <input type="checkbox" name="blockcountry_accessibility" <?php checked('on', get_option('blockcountry_accessibility'), true); ?> />
1581
+ </td></tr>
1582
 
1583
  <tr valign="top">
1584
+ <th width="30%"><?php esc_html_e('Override IP information:', 'iq-block-country'); ?><br />
1585
+ <em><?php esc_html_e('This option allows you to override how iQ Block Country gets the real IP of your visitors.', 'iq-block-country'); ?></em></th>
1586
+ <td width="70%">
1587
+ <?php
1588
+ $iqbc_ipoverride = get_option('blockcountry_ipoverride'); ?>
1589
  <select name="blockcountry_ipoverride">
1590
+ <option <?php selected($iqbc_ipoverride, "NONE"); ?> value="NONE">No override</option>
1591
+ <option <?php selected($iqbc_ipoverride, "REMOTE_ADDR"); ?> value="REMOTE_ADDR">REMOTE_ADDR</option>
1592
+ <option <?php selected($iqbc_ipoverride, "HTTP_FORWARDED"); ?> value="HTTP_FORWARDED">HTTP_FORWARDED</option>
1593
+ <option <?php selected($iqbc_ipoverride, "HTTP_X_REAL_IP"); ?> value="HTTP_X_REAL_IP">HTTP_X_REAL_IP</option>
1594
+ <option <?php selected($iqbc_ipoverride, "HTTP_CLIENT_IP"); ?> value="HTTP_CLIENT_IP">HTTP_CLIENT_IP</option>
1595
+ <option <?php selected($iqbc_ipoverride, "HTTP_X_FORWARDED"); ?> value="HTTP_X_FORWARDED">HTTP_X_FORWARDED</option>
1596
+ <option <?php selected($iqbc_ipoverride, "HTTP_X_FORWARDED_FOR"); ?> value="HTTP_X_FORWARDED_FOR">HTTP_X_FORWARDED_FOR</option>
1597
+ <option <?php selected($iqbc_ipoverride, "HTTP_INCAP_CLIENT_IP"); ?> value="HTTP_INCAP_CLIENT_IP">HTTP_X_FORWARDED</option>
1598
+ <option <?php selected($iqbc_ipoverride, "HTTP_X_SUCURI_CLIENTIP"); ?> value="HTTP_X_SUCURI_CLIENTIP">HTTP_X_SUCURI_CLIENTIP</option>
1599
+ <option <?php selected($iqbc_ipoverride, "HTTP_CF_CONNECTING_IP"); ?> value="HTTP_CF_CONNECTING_IP">HTTP_CF_CONNECTING_IP</option>
1600
  </select>
1601
+ </td></tr>
1602
 
1603
  <tr valign="top">
1604
+ <th width="30%"><?php esc_html_e('Log all visits:', 'iq-block-country'); ?><br />
1605
+ <em><?php esc_html_e('This logs all visits despite if they are blocked or not. This is only for debugging purposes.', 'iq-block-country'); ?></em></th>
1606
+ <td width="70%">
1607
+ <input type="checkbox" name="blockcountry_debuglogging" <?php checked('on', get_option('blockcountry_debuglogging'), true); ?> />
1608
+ </td></tr>
1609
 
1610
 
1611
  <tr><td></td><td>
1612
+ <p class="submit"><input type="submit" class="button-primary"
1613
+ value="<?php esc_html_e('Save Changes', 'iq-block-country')?>" /></p>
1614
+ </td></tr>
1615
+ </table>
1616
  </form>
1617
+ <?php
1618
+ }
1619
+ else
1620
  {
1621
+ print "<p>You are missing the GeoIP class. Perhaps geoip.inc is missing?</p>";
1622
+ }
1623
  }
1624
 
1625
  /*
1628
  function iqblockcountry_settings_logging()
1629
  {
1630
  ?>
1631
+ <h3><?php esc_html_e('Last blocked visits', 'iq-block-country'); ?></h3>
1632
+ <?php
1633
+ if (!get_option('blockcountry_logging')) {
 
1634
 
1635
 
1636
+ global $wpdb;
1637
+
1638
+ $iqbc_table_name = $wpdb->prefix . "iqblock_logging";
1639
+ $iqbc_format = get_option('date_format') . ' ' . get_option('time_format');
1640
+ $iqbc_nrrows = get_option('blockcountry_nrstatistics');
1641
+ $iqbc_lookupstats = get_option('blockcountry_lookupstatistics');
1642
+ if ($iqbc_nrrows == "") { $iqbc_nrrows = 15;
1643
+ };
1644
+ $iqbc_countrylist = iqblockcountry_get_isocountries();
1645
+ echo '<table class="widefat">';
1646
+ echo '<thead><tr><th>' . esc_html('Date / Time', 'iq-block-country') . '</th><th>' . esc_html('IP Address', 'iq-block-country') . '</th><th>' . esc_html('Hostname', 'iq-block-country') . '</th><th>' . esc_html('URL', 'iq-block-country') . '</th><th>' . esc_html('Country', 'iq-block-country') . '</th><th>' . esc_html('Frontend/Backend', 'iq-block-country') . '</th></tr></thead>';
1647
+ $iqbcsql = $wpdb->prepare("SELECT * FROM $iqbc_table_name ORDER BY datetime DESC LIMIT %d",$iqbc_nrrows);
1648
+ foreach ($wpdb->get_results("$iqbcsql") as $iqbc_row)
1649
+ {
1650
+ $iqbc_countryimage = "icons/" . strtolower($iqbc_row->country) . ".png";
1651
+ $iqbc_countryurl = '<img src="' . plugins_url($iqbc_countryimage, dirname(__FILE__)) . '" > ';
1652
+ echo "<tbody><tr><td>";
1653
+ $iqbc_datetime = strtotime($iqbc_row->datetime);
1654
+ $iqbc_mysqldate = date($iqbc_format, $iqbc_datetime);
1655
+ if ($iqbc_lookupstats) {
1656
+ if (extension_loaded('mbstring')) {
1657
+ echo $iqbc_mysqldate . '</td><td>' . esc_html($iqbc_row->ipaddress) . '</td><td>' . esc_html($iqbc_row->ipaddress) . 'S</td><td>' . esc_url(mb_strimwidth($iqbc_row->url, 0, 75, '...')) . '</td><td>' . $iqbc_countryurl . esc_html($iqbc_countrylist[$iqbc_row->country]) . '<td>';
1658
+ }
1659
+ else
1660
+ {
1661
+ echo $iqbc_mysqldate . '</td><td>' . esc_html($iqbc_row->ipaddress) . '</td><td>' . esc_html($iqbc_row->ipaddress) . 'S</td><td>' . esc_url($iqbc_row->url) . '</td><td>' . $iqbc_countryurl . esc_html($iqbc_countrylist[$iqbc_row->country]) . '<td>';
1662
 
1663
+ }
1664
+ }
1665
+ else
1666
+ {
1667
+ if (extension_loaded('mbstring')) {
1668
+ echo $iqbc_mysqldate . '</td><td>' . esc_html($iqbc_row->ipaddress) . '</td><td>' . esc_html($iqbc_row->ipaddress) . '</td><td>' . esc_url(mb_strimwidth($iqbc_row->url, 0, 75, '...')) . '</td><td>' . $iqbc_countryurl . $iqbc_countrylist[$iqbc_row->country] . '<td>';
1669
+ }
1670
+ else {
1671
+ echo $iqbc_mysqldate . '</td><td>' . esc_html($iqbc_row->ipaddress) . '</td><td>' . esc_html(gethostbyaddr($iqbc_row->ipaddress)) . '</td><td>' . esc_url($iqbc_row->url) . '</td><td>' . $iqbc_countryurl . $iqbc_countrylist[$iqbc_row->country] . '<td>';
1672
+ }
1673
+ }
1674
+ if ($iqbc_row->banned == "F") { esc_html_e('Frontend', 'iq-block-country');
1675
+ } elseif ($iqbc_row->banned == "A") { esc_html_e('Backend banlist', 'iq-block-country');
1676
+ } elseif ($iqbc_row->banned == "T") { esc_html_e('Backend & Backend banlist', 'iq-block-country');
1677
+ } else { esc_html_e('Backend', 'iq-block-country');
1678
+ }
1679
+ echo "</td></tr></tbody>";
1680
+ }
1681
+ echo '</table>';
1682
 
1683
 
1684
+ echo '<hr>';
1685
+ echo '<h3>' . esc_html('Top countries that are blocked', 'iq-block-country') . '</h3>';
1686
+ echo '<table class="widefat">';
1687
+ echo '<thead><tr><th>' . esc_html('Country', 'iq-block-country') . '</th><th>' . esc_html('# of blocked attempts', 'iq-block-country') . '</th></tr></thead>';
1688
+
1689
+ $iqbcsql = $wpdb->prepare("SELECT count(country) AS count,country FROM $iqbc_table_name GROUP BY country ORDER BY count(country) DESC LIMIT %d",$iqbc_nrrows);
1690
+ foreach ($wpdb->get_results("$iqbcsql") as $iqbc_row)
1691
+ {
1692
+ $iqbc_countryimage = "icons/" . strtolower($iqbc_row->country) . ".png";
1693
+ $iqbc_countryurl = '<img src="' . plugins_url($iqbc_countryimage, dirname(__FILE__)) . '" > ';
1694
+ echo "<tbody><tr><td>" . $iqbc_countryurl . esc_html($iqbc_countrylist[$iqbc_row->country]) . "</td><td>" . esc_html($iqbc_row->count) . "</td></tr></tbody>";
1695
+ }
1696
+ echo '</table>';
1697
 
1698
+ echo '<hr>';
1699
+ echo '<h3>' . esc_html('Top hosts that are blocked', 'iq-block-country') . '</h3>';
1700
+ echo '<table class="widefat">';
1701
+ echo '<thead><tr><th>' . esc_html('IP Address', 'iq-block-country') . '</th><th>' . esc_html('Hostname', 'iq-block-country') . '</th><th>' . esc_html('# of blocked attempts', 'iq-block-country') . '</th></tr></thead>';
1702
+
1703
+ $iqbcsql = $wpdb->prepare("SELECT count(ipaddress) AS count,ipaddress FROM $iqbc_table_name GROUP BY ipaddress ORDER BY count(ipaddress) DESC LIMIT %d",$iqbc_nrrows);
1704
+ foreach ($wpdb->get_results("$iqbcsql") as $iqbc_row)
1705
+ {
1706
+ if ($iqbc_lookupstats) {
1707
+ echo "<tbody><tr><td>" . esc_html($iqbc_row->ipaddress) . "</td><td>" . esc_html($iqbc_row->ipaddress) . "</td><td>" . esc_html($iqbc_row->count) . "</td></tr></tbody>";
1708
+ }
1709
+ else
1710
+ {
1711
+ echo "<tbody><tr><td>" . esc_html($iqbc_row->ipaddress) . "</td><td>" . esc_html(gethostbyaddr($iqbc_row->ipaddress)) . "</td><td>" . esc_html($iqbc_row->count) . "</td></tr></tbody>";
1712
 
1713
+ }
1714
 
1715
 
1716
+ }
1717
+ echo '</table>';
1718
+
1719
+ echo '<hr>';
1720
+ echo '<h3>' . esc_html('Top URLs that are blocked', 'iq-block-country') . '</h3>';
1721
+ echo '<table class="widefat">';
1722
+ echo '<thead><tr><th>' . esc_html('URL', 'iq-block-country') . '</th><th>' . esc_html('# of blocked attempts', 'iq-block-country') . '</th></tr></thead>';
1723
+
1724
+ $iqbcsql = $wpdb->prepare("SELECT count(url) AS count,url FROM $iqbc_table_name GROUP BY url ORDER BY count(url) DESC LIMIT %d",$iqbc_nrrows);
1725
+ foreach ($wpdb->get_results($iqbcsql) as $iqbc_row)
1726
+ {
1727
+ echo "<tbody><tr><td>" . esc_url($iqbc_row->url) . "</td><td>" . esc_html($iqbc_row->count) . "</td></tr></tbody>";
1728
+ }
1729
+ echo '</table>';
1730
 
1731
+ ?>
1732
  <form name="cleardatabase" action="#" method="post">
1733
+ <input type="hidden" name="iqbc_action" value="iqbc_cleardatabase" />
1734
+ <input name="iqbc_cleardatabase_nonce" type="hidden" value="<?php echo wp_create_nonce('iqbc_cleardatabase_nonce'); ?>" />
1735
 
1736
+ <?php
1737
+ echo '<div class="submit"><input type="submit" name="test" value="' . esc_html('Clear database', 'iq-block-country') . '" /></div>';
1738
  wp_nonce_field('iqblockcountry');
1739
 
1740
+ if (isset($_POST['iqbc_action']) && $_POST[ 'iqbc_action' ] == 'iqbc_cleardatabase') {
1741
+ if (!isset($_POST['iqbc_cleardatabase_nonce'])) { die("Failed security check.");
1742
+ }
1743
+ if (!wp_verify_nonce($_POST['iqbc_cleardatabase_nonce'], 'iqbc_cleardatabase_nonce')) { die("Is this a CSRF attempt?");
1744
+ }
1745
  global $wpdb;
1746
+ $iqbc_table_name = $wpdb->prefix . "iqblock_logging";
1747
+ $iqbc_sql = "TRUNCATE " . $iqbc_table_name . ";";
1748
+ $wpdb->query($iqbc_sql);
1749
+ $iqbc_sql = "ALTER TABLE ". $iqbc_table_name . " AUTO_INCREMENT = 1;";
1750
+ $wpdb->query($iqbc_sql);
1751
  echo "Cleared database";
1752
 
1753
  }
1755
  ?>
1756
  </form>
1757
 
1758
+ <form name="csvoutput" action="#" method="post">
1759
+ <input type="hidden" name="iqbc_action" value="iqbc_csvoutput" />
1760
+ <input name="iqbc_csv_nonce" type="hidden" value="<?php echo wp_create_nonce('iqbc_csv_nonce'); ?>" />
1761
  <?php
1762
+ echo '<div class="submit"><input type="submit" name="submit" value="' . esc_html('Download as CSV file', 'iq-block-country') . '" /></div>';
1763
+ wp_nonce_field('iqbc_iqblockcountrycsv');
1764
  echo '</form>';
1765
+ }
1766
+ else
1767
+ {
1768
+ echo "<hr><h3>";
1769
+ esc_html_e('You are not logging any information. Please uncheck the option \'Do not log IP addresses\' if this is not what you want.', 'iq-block-country');
1770
+ echo "<hr></h3>";
1771
+ }
1772
  }
1773
 
1774
 
1775
  /*
1776
  * Create the settings page.
1777
  */
1778
+ function iqblockcountry_settings_page()
1779
+ {
1780
 
1781
 
1782
+ if(isset($_GET[ 'tab' ]) ) {
1783
+ $iqbc_active_tab = filter_var($_GET[ 'tab' ], FILTER_SANITIZE_STRING);
1784
+ }
1785
+ else
1786
  {
1787
+ $iqbc_active_tab = 'home';
1788
+ }
1789
+ ?>
1790
 
1791
  <h2 class="nav-tab-wrapper">
1792
+ <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=home" class="nav-tab <?php echo $iqbc_active_tab == 'home' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e('Home', 'iq-block-country'); ?></a>
1793
+ <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=frontend" class="nav-tab <?php echo $iqbc_active_tab == 'frontend' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e('Frontend', 'iq-block-country'); ?></a>
1794
+ <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=backend" class="nav-tab <?php echo $iqbc_active_tab == 'backend' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e('Backend', 'iq-block-country'); ?></a>
1795
+ <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=pages" class="nav-tab <?php echo $iqbc_active_tab == 'pages' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e('Pages', 'iq-block-country'); ?></a>
1796
+ <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=categories" class="nav-tab <?php echo $iqbc_active_tab == 'categories' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e('Categories', 'iq-block-country'); ?></a>
1797
+ <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=tags" class="nav-tab <?php echo $iqbc_active_tab == 'tags' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e('Tags', 'iq-block-country'); ?></a>
1798
+ <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=posttypes" class="nav-tab <?php echo $iqbc_active_tab == 'posttypes' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e('Post types', 'iq-block-country'); ?></a>
1799
+ <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=services" class="nav-tab <?php echo $iqbc_active_tab == 'services' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e('Services', 'iq-block-country'); ?></a>
1800
+ <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=tools" class="nav-tab <?php echo $iqbc_active_tab == 'tools' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e('Tools', 'iq-block-country'); ?></a>
1801
+ <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=logging" class="nav-tab <?php echo $iqbc_active_tab == 'logging' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e('Logging', 'iq-block-country'); ?></a>
1802
+ <a href="?page=iq-block-country/libs/blockcountry-settings.php&tab=export" class="nav-tab <?php echo $iqbc_active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e('Import/Export', 'iq-block-country'); ?></a>
1803
  </h2>
1804
 
1805
 
1808
 
1809
  <hr />
1810
  <?php
1811
+ if ($iqbc_active_tab == "frontend") {
 
1812
  iqblockcountry_settings_frontend();
1813
  }
1814
+ elseif ($iqbc_active_tab == "backend") {
 
1815
  iqblockcountry_settings_backend();
1816
  }
1817
+ elseif ($iqbc_active_tab == "tools") {
 
1818
  iqblockcountry_settings_tools();
1819
  }
1820
+ elseif ($iqbc_active_tab == "logging") {
 
1821
  iqblockcountry_settings_logging();
1822
  }
1823
+ elseif ($iqbc_active_tab == "pages") {
 
1824
  iqblockcountry_settings_pages();
1825
  }
1826
+ elseif ($iqbc_active_tab == "categories") {
 
1827
  iqblockcountry_settings_categories();
1828
  }
1829
+ elseif ($iqbc_active_tab == "tags") {
 
1830
  iqblockcountry_settings_tags();
1831
  }
1832
+ elseif ($iqbc_active_tab == "posttypes") {
 
1833
  iqblockcountry_settings_posttypes();
1834
  }
1835
+ elseif ($iqbc_active_tab == "services") {
 
1836
  iqblockcountry_settings_services();
1837
  }
1838
+ elseif ($iqbc_active_tab == "export") {
 
1839
  iqblockcountry_settings_importexport();
1840
  }
1841
  else
1853
  See <a href="https://webence.nl/plugins/donate/">Plugin donation page</a></p>
1854
 
1855
  <?php
1856
+
1857
  }
1858
 
1859
 
1862
  */
1863
  function iqblockcountry_find_geoip_location()
1864
  {
1865
+ if (function_exists('curl_init')) {
1866
+ $iqbc_curl = curl_init();
1867
+ curl_setopt_array(
1868
+ $iqbc_curl, array(
1869
+ CURLOPT_RETURNTRANSFER => 1,
1870
+ CURLOPT_URL => 'https://us.geoip.webence.nl/test',
1871
+ CURLOPT_USERAGENT => 'iQ Block Country US location test/' . get_bloginfo('wpurl')
1872
+ )
1873
+ );
1874
+ $iqbc_resp = curl_exec($iqbc_curl);
1875
+ $iqbc_infous = curl_getinfo($iqbc_curl);
1876
+ curl_close($iqbc_curl);
1877
+
1878
+ $iqbc_curl = curl_init();
1879
+ curl_setopt_array(
1880
+ $iqbc_curl, array(
1881
+ CURLOPT_RETURNTRANSFER => 1,
1882
+ CURLOPT_URL => 'https://us2.geoip.webence.nl/test',
1883
+ CURLOPT_USERAGENT => 'iQ Block Country US2 location test/' . get_bloginfo('wpurl')
1884
+ )
1885
+ );
1886
+ $iqbc_resp = curl_exec($iqbc_curl);
1887
+ $iqbc_infous2 = curl_getinfo($iqbc_curl);
1888
+ curl_close($iqbc_curl);
1889
+
1890
+ $iqbc_curl = curl_init();
1891
+ curl_setopt_array(
1892
+ $iqbc_curl, array(
1893
+ CURLOPT_RETURNTRANSFER => 1,
1894
+ CURLOPT_URL => 'https://us3.geoip.webence.nl/test',
1895
+ CURLOPT_USERAGENT => 'iQ Block Country US3 location test/' . get_bloginfo('wpurl')
1896
+ )
1897
+ );
1898
+ $iqbc_resp = curl_exec($iqbc_curl);
1899
+ $iqbc_infous3 = curl_getinfo($iqbc_curl);
1900
+ curl_close($iqbc_curl);
1901
+
1902
+ // $iqbc_curl = curl_init();
1903
+ // curl_setopt_array($iqbc_curl, array(
1904
+ // CURLOPT_RETURNTRANSFER => 1,
1905
+ // CURLOPT_URL => 'https://asia.geoip.webence.nl/test',
1906
+ // CURLOPT_USERAGENT => 'iQ Block Country Asia location test/' . get_bloginfo('wpurl')
1907
+ // ));
1908
+ // $iqbc_resp = curl_exec($iqbc_curl);
1909
+ // $infoasia = curl_getinfo($iqbc_curl);
1910
+ // curl_close($iqbc_curl);
1911
 
1912
+ $iqbc_curl = curl_init();
1913
+ curl_setopt_array(
1914
+ $iqbc_curl, array(
1915
+ CURLOPT_URL => 'https://eu.geoip.webence.nl/test',
1916
+ CURLOPT_USERAGENT => 'iQ Block Country EU location test/' . get_bloginfo('wpurl')
1917
+ )
1918
+ );
1919
+ $iqbc_resp = curl_exec($iqbc_curl);
1920
+ $iqbc_infoeu = curl_getinfo($iqbc_curl);
1921
+ curl_close($iqbc_curl);
1922
+
1923
+ $iqbc_curl = curl_init();
1924
+ curl_setopt_array(
1925
+ $iqbc_curl, array(
1926
+ CURLOPT_URL => 'https://eu3.geoip.webence.nl/test',
1927
+ CURLOPT_USERAGENT => 'iQ Block Country EU3 location test/' . get_bloginfo('wpurl')
1928
+ )
1929
+ );
1930
+ $iqbc_resp = curl_exec($iqbc_curl);
1931
+ $iqbc_infoeu3 = curl_getinfo($iqbc_curl);
1932
+ curl_close($iqbc_curl);
1933
 
1934
 
1935
+ $iqbc_fastestsite = min($iqbc_infoeu['total_time'], $iqbc_infoeu3['total_time'], $iqbc_infous['total_time'], $iqbc_infous2['total_time'], $iqbc_infous3['total_time']);
1936
 
1937
+ if ($iqbc_infous['total_time'] == $iqbc_fastestsite) {
1938
+ update_option('blockcountry_geoapilocation', 'US');
1939
+ }
1940
+ elseif ($iqbc_infous2['total_time'] == $iqbc_fastestsite) {
1941
+ update_option('blockcountry_geoapilocation', 'US2');
1942
+ }
1943
+ elseif ($iqbc_infous3['total_time'] == $iqbc_fastestsite) {
1944
+ update_option('blockcountry_geoapilocation', 'US3');
1945
+ }
1946
+ // elseif ($infoasia['total_time'] == $iqbc_fastestsite)
1947
+ // {
1948
+ // update_option('blockcountry_geoapilocation','ASIA');
1949
+ // }
1950
+ elseif ($iqbc_infoeu3['total_time'] == $iqbc_fastestsite) {
1951
+ update_option('blockcountry_geoapilocation', 'EU3');
1952
+ }
1953
+ else
1954
+ {
1955
+ update_option('blockcountry_geoapilocation', 'EU');
1956
+ }
 
 
 
1957
  }
 
1958
  }
1959
 
1960
  /*
1962
  */
1963
  function iqblockcountry_get_blockallowlist()
1964
  {
1965
+ $iqbc_frontendblocklistip = array(); $iqbc_frontendblocklist = get_option('blockcountry_frontendblacklist');
1966
+ $iqbc_frontendallowlistip = array(); $iqbc_frontendallowlist = get_option('blockcountry_frontendwhitelist');
1967
+ $iqbc_backendblocklistip = array(); $iqbc_backendblocklist = get_option('blockcountry_backendblacklist');
1968
+ $iqbc_backendallowlistip = array(); $iqbc_backendallowlist = get_option('blockcountry_backendwhitelist');
1969
 
1970
 
1971
+ $iqbc_feblocklistip = array();
1972
+ $iqbc_feblocklistiprange4 = array();
1973
+ $iqbc_feblocklistiprange6 = array();
1974
+ $iqbc_feallowlistip = array();
1975
+ $iqbc_feallowlistiprange4 = array();
1976
+ $iqbc_feallowlistiprange6 = array();
1977
+ global $iqbc_feblocklistip,$iqbc_feblocklistiprange4,$iqbc_feblocklistiprange6,$iqbc_feallowlistip,$iqbc_feallowlistiprange4,$iqbc_feallowlistiprange6;
1978
 
1979
+ $iqbc_beblocklistip = array();
1980
+ $iqbc_beblocklistiprange4 = array();
1981
+ $iqbc_beblocklistiprange6 = array();
1982
+ $iqbc_beallowlistip = array();
1983
+ $iqbc_beallowlistiprange4 = array();
1984
+ $iqbc_beallowlistiprange6 = array();
1985
+ global $iqbc_beblocklistip,$iqbc_beblocklistiprange4,$iqbc_beblocklistiprange6,$iqbc_beallowlistip,$iqbc_beallowlistiprange4,$iqbc_beallowlistiprange6;
1986
 
1987
 
1988
+ if (preg_match('/;/', $iqbc_frontendblocklist)) {
1989
+ $iqbc_frontendblocklistip = explode(";", $iqbc_frontendblocklist);
1990
+ foreach ($iqbc_frontendblocklistip AS $iqbc_ip)
 
1991
  {
1992
+ if (iqblockcountry_is_valid_ipv4($iqbc_ip) || iqblockcountry_is_valid_ipv6($iqbc_ip)) { $iqbc_feblocklistip[] = $iqbc_ip;
1993
+ }
1994
+ elseif (iqblockcountry_is_valid_ipv4_cidr($iqbc_ip)) { $iqbc_feblocklistiprange4[] = $iqbc_ip;
1995
+ }
1996
+ elseif (iqblockcountry_is_valid_ipv6_cidr($iqbc_ip)) { $iqbc_feblocklistiprange6[] = $iqbc_ip;
1997
+ }
1998
  }
1999
  }
2000
+ if (preg_match('/;/', $iqbc_frontendallowlist)) {
2001
+ $iqbc_frontendallowlistip = explode(";", $iqbc_frontendallowlist);
2002
+ foreach ($iqbc_frontendallowlistip AS $iqbc_ip)
 
2003
  {
2004
+ if (iqblockcountry_is_valid_ipv4($iqbc_ip) || iqblockcountry_is_valid_ipv6($iqbc_ip)) { $iqbc_feallowlistip[] = $iqbc_ip;
2005
+ }
2006
+ elseif (iqblockcountry_is_valid_ipv4_cidr($iqbc_ip)) { $iqbc_feallowlistiprange4[] = $iqbc_ip;
2007
+ }
2008
+ elseif (iqblockcountry_is_valid_ipv6_cidr($iqbc_ip)) { $iqbc_feallowlistiprange6[] = $iqbc_ip;
2009
+ }
2010
  }
2011
  }
2012
+ if (preg_match('/;/', $iqbc_backendblocklist)) {
2013
+ $iqbc_backendblocklistip = explode(";", $iqbc_backendblocklist);
2014
+ foreach ($iqbc_backendblocklistip AS $iqbc_ip)
 
2015
  {
2016
+ if (iqblockcountry_is_valid_ipv4($iqbc_ip) || iqblockcountry_is_valid_ipv6($iqbc_ip)) { $iqbc_beblocklistip[] = $iqbc_ip;
2017
+ }
2018
+ elseif (iqblockcountry_is_valid_ipv4_cidr($iqbc_ip)) { $iqbc_beblocklistiprange4[] = $iqbc_ip;
2019
+ }
2020
+ elseif (iqblockcountry_is_valid_ipv6_cidr($iqbc_ip)) { $iqbc_beblocklistiprange6[] = $iqbc_ip;
2021
+ }
2022
  }
2023
  }
2024
+ if (preg_match('/;/', $iqbc_backendallowlist)) {
2025
+ $iqbc_backendallowlistip = explode(";", $iqbc_backendallowlist);
2026
+ foreach ($iqbc_backendallowlistip AS $iqbc_ip)
 
2027
  {
2028
+ if (iqblockcountry_is_valid_ipv4($iqbc_ip) || iqblockcountry_is_valid_ipv6($iqbc_ip)) { $iqbc_beallowlistip[] = $iqbc_ip;
2029
+ }
2030
+ elseif (iqblockcountry_is_valid_ipv4_cidr($iqbc_ip)) { $iqbc_beallowlistiprange4[] = $iqbc_ip;
2031
+ }
2032
+ elseif (iqblockcountry_is_valid_ipv6_cidr($iqbc_ip)) { $iqbc_beallowlistiprange6[] = $iqbc_ip;
2033
+ }
2034
  }
2035
  }
2036
 
libs/blockcountry-tracking.php CHANGED
@@ -3,18 +3,15 @@
3
  /*
4
  * Schedule tracking if this option was set in the admin panel
5
  */
6
- function iqblockcountry_schedule_tracking($old_value, $new_value)
7
  {
8
- $current_schedule = wp_next_scheduled( 'blockcountry_tracking' );
9
- if ($old_value !== $new_value)
10
- {
11
- if ($new_value == '')
12
- {
13
- wp_clear_scheduled_hook( 'blockcountry_tracking' );
14
  }
15
- elseif ($new_value == 'on' && $current_schedule == FALSE)
16
- {
17
- wp_schedule_event( time(), 'hourly', 'blockcountry_tracking' );
18
  }
19
  }
20
  }
@@ -25,38 +22,36 @@ function iqblockcountry_schedule_tracking($old_value, $new_value)
25
  */
26
  function iqblockcountry_tracking()
27
  {
28
- if (get_option("blockcountry_tracking") == "on")
29
- {
30
- $lasttracked = get_option("blockcountry_lasttrack");
31
  global $wpdb;
32
 
33
- $table_name = $wpdb->prefix . "iqblock_logging";
34
-
35
- $content = array();
36
- if (!empty($lasttracked))
37
- {
38
- $query = "SELECT id,ipaddress,count(ipaddress) as countip FROM $table_name WHERE banned=\"B\" and id > $lasttracked GROUP BY ipaddress ORDER BY id";
39
  }
40
  else
41
  {
42
- $query = "SELECT id,ipaddress,count(ipaddress) as countip FROM $table_name WHERE banned=\"B\" GROUP BY ipaddress ORDER BY id";
43
  }
44
- foreach ($wpdb->get_results( $query ) as $row)
45
  {
46
- $newcontent = array('ipaddress' => $row->ipaddress,'count' => $row->countip);
47
- array_push($content,$newcontent);
48
- $id = $row->id;
49
  }
50
 
51
- if (!empty($content))
52
- {
53
- $response = wp_remote_post(TRACKINGURL,
54
  array(
55
- 'body' => $content
56
  )
57
- );
58
 
59
- if (isset($id)) { update_option('blockcountry_lasttrack',$id); }
 
60
  }
61
  }
62
  }
@@ -68,32 +63,35 @@ function iqblockcountry_tracking()
68
  */
69
  function iqblockcountry_tracking_retrieve_xml()
70
  {
71
- $url = BANLISTRETRIEVEURL;
72
 
73
- $result = wp_remote_post(
74
- $url,
75
- array(
76
  'body' => array(
77
  'api-key' => get_option('blockcountry_apikey')
78
 
79
  )
80
  )
81
- );
82
 
83
- if ( is_wp_error( $result ) ) {
84
- return FALSE;
85
  }
86
- elseif ( 200 == $result['response']['code'] ) {
87
- $body = $result['body'];
88
- $xml = new SimpleXmlElement($body);
89
- $banlist = array();
90
- $i=0;
91
- foreach ($xml->banlist->ipaddress AS $ip)
92
  {
93
- array_push($banlist,sprintf('%s',$ip));
94
- $i++;
 
 
 
95
  }
96
- update_option('blockcountry_backendbanlistip', serialize($banlist));
97
  }
98
 
99
 
@@ -102,18 +100,15 @@ function iqblockcountry_tracking_retrieve_xml()
102
  /*
103
  * Schedule retrieving banlist.
104
  */
105
- function iqblockcountry_schedule_retrieving($old_value, $new_value)
106
  {
107
- $current_schedule = wp_next_scheduled( 'blockcountry_retrievebanlist' );
108
- if ($old_value !== $new_value)
109
- {
110
- if ($new_value == '')
111
- {
112
- wp_clear_scheduled_hook( 'blockcountry_retrievebanlist' );
113
  }
114
- elseif (!empty($new_value) && $current_schedule == FALSE)
115
- {
116
- wp_schedule_event( time(), 'twicedaily', 'blockcountry_retrievebanlist' );
117
  }
118
  }
119
  }
3
  /*
4
  * Schedule tracking if this option was set in the admin panel
5
  */
6
+ function iqblockcountry_schedule_tracking($iqbc_old_value, $iqbc_new_value)
7
  {
8
+ $iqbc_current_schedule = wp_next_scheduled('blockcountry_tracking');
9
+ if ($iqbc_old_value !== $iqbc_new_value) {
10
+ if ($iqbc_new_value == '') {
11
+ wp_clear_scheduled_hook('blockcountry_tracking');
 
 
12
  }
13
+ elseif ($iqbc_new_value == 'on' && $iqbc_current_schedule == false) {
14
+ wp_schedule_event(time(), 'hourly', 'blockcountry_tracking');
 
15
  }
16
  }
17
  }
22
  */
23
  function iqblockcountry_tracking()
24
  {
25
+ if (get_option("blockcountry_tracking") == "on") {
26
+ $iqbc_lasttracked = get_option("blockcountry_lasttrack");
 
27
  global $wpdb;
28
 
29
+ $iqbc_table_name = $wpdb->prefix . "iqblock_logging";
30
+ $iqbc_content = array();
31
+ if (!empty($iqbc_lasttracked)) {
32
+ $iqbc_query = $wpdb->prepare("SELECT id,ipaddress,count(ipaddress) as countip FROM $iqbc_table_name WHERE banned=\"B\" and id > %d GROUP BY ipaddress ORDER BY id",$iqbc_lasttracked);
 
 
33
  }
34
  else
35
  {
36
+ $iqbc_query = "SELECT id,ipaddress,count(ipaddress) as countip FROM $iqbc_table_name WHERE banned=\"B\" GROUP BY ipaddress ORDER BY id";
37
  }
38
+ foreach ($wpdb->get_results($iqbc_query) as $iqbc_row)
39
  {
40
+ $iqbc_newcontent = array('ipaddress' => $iqbc_row->ipaddress,'count' => $iqbc_row->countip);
41
+ array_push($iqbc_content, $iqbc_newcontent);
42
+ $iqbc_id = $iqbc_row->id;
43
  }
44
 
45
+ if (!empty($iqbc_content)) {
46
+ $iqbc_response = wp_remote_post(
47
+ IQBCTRACKINGURL,
48
  array(
49
+ 'body' => $iqbc_content
50
  )
51
+ );
52
 
53
+ if (isset($iqbc_id)) { update_option('blockcountry_lasttrack', $iqbc_id);
54
+ }
55
  }
56
  }
57
  }
63
  */
64
  function iqblockcountry_tracking_retrieve_xml()
65
  {
66
+ $iqbc_url = IQBCBANLISTRETRIEVEURL;
67
 
68
+ $iqbc_result = wp_remote_post(
69
+ $iqbc_url,
70
+ array(
71
  'body' => array(
72
  'api-key' => get_option('blockcountry_apikey')
73
 
74
  )
75
  )
76
+ );
77
 
78
+ if (is_wp_error($iqbc_result) ) {
79
+ return false;
80
  }
81
+ elseif (200 == $iqbc_result['response']['code'] ) {
82
+ $iqbc_body = $iqbc_result['body'];
83
+ $iqbc_xml = new SimpleXmlElement($iqbc_body);
84
+ $iqbc_banlist = array();
85
+ $iqbc_i=0;
86
+ foreach ($iqbc_xml->banlist->ipaddress AS $iqbc_ip)
87
  {
88
+ if (filter_var($iqbc_ip,FILTER_VALIDATE_IP))
89
+ {
90
+ array_push($iqbc_banlist, sprintf('%s', $iqbc_ip));
91
+ $iqbc_i++;
92
+ }
93
  }
94
+ update_option('blockcountry_backendbanlistip', serialize($iqbc_banlist));
95
  }
96
 
97
 
100
  /*
101
  * Schedule retrieving banlist.
102
  */
103
+ function iqblockcountry_schedule_retrieving($iqbc_old_value, $iqbc_new_value)
104
  {
105
+ $iqbc_current_schedule = wp_next_scheduled('blockcountry_retrievebanlist');
106
+ if ($iqbc_old_value !== $iqbc_new_value) {
107
+ if ($iqbc_new_value == '') {
108
+ wp_clear_scheduled_hook('blockcountry_retrievebanlist');
 
 
109
  }
110
+ elseif (!empty($iqbc_new_value) && $iqbc_current_schedule == false) {
111
+ wp_schedule_event(time(), 'twicedaily', 'blockcountry_retrievebanlist');
 
112
  }
113
  }
114
  }
libs/blockcountry-validation.php CHANGED
@@ -3,9 +3,9 @@
3
  /*
4
  * Check of an IP address is a valid IPv4 address
5
  */
6
- function iqblockcountry_is_valid_ipv4($ipv4)
7
  {
8
- if(filter_var($ipv4, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === FALSE) {
9
  return false;
10
  }
11
 
@@ -15,19 +15,18 @@ function iqblockcountry_is_valid_ipv4($ipv4)
15
  /*
16
  * Check of an IP address is a valid IPv6 address
17
  */
18
- function iqblockcountry_is_valid_ipv6($ipv6)
19
  {
20
- if(filter_var($ipv6, FILTER_VALIDATE_IP,FILTER_FLAG_IPV6) === FALSE) {
21
- return false;
22
  }
23
 
24
  return true;
25
  }
26
 
27
- function iqblockcountry_is_valid_ipv4_cidr($ip)
28
  {
29
- if (preg_match('/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$/',$ip))
30
- {
31
  return true;
32
  }
33
  else
@@ -36,10 +35,9 @@ function iqblockcountry_is_valid_ipv4_cidr($ip)
36
  }
37
  }
38
 
39
- function iqblockcountry_is_valid_ipv6_cidr($ip)
40
  {
41
- if (preg_match('/^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*(\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8]))?$/',$ip))
42
- {
43
  return true;
44
  }
45
  else
@@ -52,15 +50,15 @@ function iqblockcountry_is_valid_ipv6_cidr($ip)
52
  /*
53
  * Check of given url is a valid url
54
  */
55
- function iqblockcountry_is_valid_url($input)
56
  {
57
- if(filter_var($input,FILTER_VALIDATE_URL) === FALSE) {
58
- return "";
 
 
 
 
59
  }
60
- else
61
- {
62
- return $input;
63
- }
64
 
65
  }
66
 
@@ -68,78 +66,73 @@ else
68
  /*
69
  * Sanitize callback. Check if supplied IP address list is valid IPv4 or IPv6
70
  */
71
- function iqblockcountry_validate_ip($input)
72
  {
73
- $validips = "";
74
- if (preg_match('/;/',$input))
75
- {
76
- $arr = explode(";", $input);
77
- foreach ($arr as $value) {
78
- if (iqblockcountry_is_valid_ipv4($value) || iqblockcountry_is_valid_ipv6($value) || iqblockcountry_is_valid_ipv4_cidr($value) || iqblockcountry_is_valid_ipv6_cidr($value))
79
- {
80
- $validips .= $value . ";";
81
  }
82
 
83
  }
84
  }
85
  else
86
  {
87
- if (iqblockcountry_is_valid_ipv4($input) || iqblockcountry_is_valid_ipv6($input) || iqblockcountry_is_valid_ipv4_cidr($input) || iqblockcountry_is_valid_ipv6_cidr($input))
88
- {
89
- $validips = $input . ";";
90
  }
91
  }
92
- return $validips;
93
 
94
  }
95
 
96
  /*
97
  * Check if GeoIP API key is correct.
98
  */
99
- function iqblockcountry_check_geoapikey($input)
100
  {
101
 
102
  // Check first if API key is empty....
103
- if (!empty($input))
104
- {
105
 
106
- $url = GEOIPAPICHECKURL;
107
 
108
- $result = wp_remote_post(
109
- $url,
110
  array(
111
  'body' => array(
112
- 'api-key' => $input
113
  )
114
  )
115
  );
116
- $message = "";
117
- $type = "updated";
118
- if ( is_wp_error( $result ) ) {
119
- return FALSE;
120
  }
121
 
122
- elseif ( 200 == $result['response']['code'] ) {
123
- $body = $result['body'];
124
- $xml = new SimpleXmlElement($body);
125
- if ($xml->check != "Ok")
126
- {
127
- $message = __( 'The GeoIP API key is incorrect. Please update the key.', 'iq-block-country' );
128
- $type = "error";
129
- $input = FALSE;
130
  }
131
  else
132
  {
133
- $message = __( 'Setting saved.', 'iq-block-country' );
134
- $type = "updated";
135
  }
136
  }
137
  else
138
  {
139
- $input = FALSE;
140
  }
141
- add_settings_error('iqblockcountry_geoipapi_error',esc_attr( 'settings_updated' ),$message,$type);
142
- return $input;
143
  }
144
  return "";
145
  }
@@ -147,49 +140,47 @@ function iqblockcountry_check_geoapikey($input)
147
  /*
148
  * Check if GeoIP API key is correct.
149
  */
150
- function iqblockcountry_check_adminapikey($input)
151
  {
152
 
153
  // Check first if API key is empty....
154
- if (!empty($input))
155
- {
156
 
157
- $url = ADMINAPICHECKURL;
158
 
159
- $result = wp_remote_post(
160
- $url,
161
  array(
162
  'body' => array(
163
- 'api-key' => $input
164
  )
165
  )
166
  );
167
- $message = "";
168
- $type = "updated";
169
- if ( is_wp_error( $result ) ) {
170
- return FALSE;
171
  }
172
- elseif ( 200 == $result['response']['code'] ) {
173
- $body = $result['body'];
174
- $xml = new SimpleXmlElement($body);
175
- if ($xml->check != "Ok")
176
- {
177
- $message = __( 'The Admin Block API key is incorrect. Please update the key.', 'iq-block-country' );
178
- $type = "error";
179
- $input = FALSE;
180
  }
181
  else
182
  {
183
- $message = __( 'Setting saved.', 'iq-block-country' );
184
- $type = "updated";
185
  }
186
  }
187
  else
188
  {
189
- $input = FALSE;
190
  }
191
- add_settings_error('iqblockcountry_adminapi_error',esc_attr( 'settings_updated' ),$message,$type);
192
- return $input;
193
  }
194
  return "";
195
  }
@@ -198,32 +189,30 @@ function iqblockcountry_check_adminapikey($input)
198
  /*
199
  * Check if GeoIP API key is correct.
200
  */
201
- function iqblockcountry_get_licensedate_geoapikey($apikey)
202
  {
203
 
204
  // Check first if API key is empty....
205
- if (!empty($apikey))
206
- {
207
 
208
- $url = GEOIPAPICHECKURL;
209
 
210
- $result = wp_remote_post(
211
- $url,
212
  array(
213
  'body' => array(
214
- 'api-key' => $apikey
215
  )
216
  )
217
  );
218
- if ( is_wp_error( $result ) ) {
219
  return "";
220
  }
221
- elseif ( 200 == $result['response']['code'] ) {
222
- $body = $result['body'];
223
- $xml = new SimpleXmlElement($body);
224
- if ($xml->check == "Ok")
225
- {
226
- return $xml->LicenseDate;
227
  }
228
  }
229
  else
@@ -237,32 +226,30 @@ function iqblockcountry_get_licensedate_geoapikey($apikey)
237
  /*
238
  * Check usage of GeoIP API
239
  */
240
- function iqblockcountry_get_usage_geoapikey($apikey)
241
  {
242
 
243
  // Check first if API key is empty....
244
- if (!empty($apikey))
245
- {
246
 
247
- $url = GEOIPAPICHECKUSAGEURL;
248
 
249
- $result = wp_remote_post(
250
- $url,
251
  array(
252
  'body' => array(
253
- 'api-key' => $apikey
254
  )
255
  )
256
  );
257
- if ( is_wp_error( $result ) ) {
258
  return "";
259
  }
260
- elseif ( 200 == $result['response']['code'] ) {
261
- $body = $result['body'];
262
- $xml = new SimpleXmlElement($body);
263
- if ($xml->check == "Ok")
264
- {
265
- return $xml->requests;
266
  }
267
  }
268
  else
@@ -276,155 +263,152 @@ function iqblockcountry_get_usage_geoapikey($apikey)
276
 
277
  /**
278
  * Check if a given ip is in a network
279
- * @param string $ip IP to check in IPV4 format eg. 127.0.0.1
280
- * @param string $range IP/CIDR netmask eg. 127.0.0.0/24, also 127.0.0.1 is accepted and /32 assumed
 
281
  * @return boolean true if the ip is in this range / false if not.
282
  */
283
- function iqblockcountry_ip_in_ipv4_range( $ip, $range ) {
284
- if ( strpos( $range, '/' ) == false ) {
285
- $range .= '/32';
286
- }
287
- // $range is in IP/CIDR format eg 127.0.0.1/24
288
- list( $range, $netmask ) = explode( '/', $range, 2 );
289
- $range_decimal = ip2long( $range );
290
- $ip_decimal = ip2long( $ip );
291
- $wildcard_decimal = pow( 2, ( 32 - $netmask ) ) - 1;
292
- $netmask_decimal = ~ $wildcard_decimal;
293
- return ( ( $ip_decimal & $netmask_decimal ) == ( $range_decimal & $netmask_decimal ) );
 
294
  }
295
 
296
- function iqblockcountry_ip2long6($ip) {
297
- if (substr_count($ip, '::')) {
298
- $ip = str_replace('::', str_repeat(':0000', 8 - substr_count($ip, ':')) . ':', $ip);
 
299
  }
300
 
301
- $ip = explode(':', $ip);
302
- $r_ip = '';
303
- foreach ($ip as $v) {
304
- $r_ip .= str_pad(base_convert($v, 16, 2), 16, 0, STR_PAD_LEFT);
305
  }
306
 
307
- return base_convert($r_ip, 2, 10);
308
  }
309
  // Get the ipv6 full format and return it as a decimal value.
310
- function iqblockcountry_get_ipv6_full($ip)
311
  {
312
- $pieces = explode ("/", $ip, 2);
313
- $left_piece = $pieces[0];
314
- $right_piece = $pieces[1];
315
  // Extract out the main IP pieces
316
- $ip_pieces = explode("::", $left_piece, 2);
317
- $main_ip_piece = $ip_pieces[0];
318
- $last_ip_piece = $ip_pieces[1];
319
  // Pad out the shorthand entries.
320
- $main_ip_pieces = explode(":", $main_ip_piece);
321
- foreach($main_ip_pieces as $key=>$val) {
322
- $main_ip_pieces[$key] = str_pad($main_ip_pieces[$key], 4, "0", STR_PAD_LEFT);
323
  }
324
  // Check to see if the last IP block (part after ::) is set
325
- $last_piece = "";
326
- $size = count($main_ip_pieces);
327
- if (trim($last_ip_piece) != "") {
328
- $last_piece = str_pad($last_ip_piece, 4, "0", STR_PAD_LEFT);
329
 
330
  // Build the full form of the IPV6 address considering the last IP block set
331
- for ($i = $size; $i < 7; $i++) {
332
- $main_ip_pieces[$i] = "0000";
333
  }
334
- $main_ip_pieces[7] = $last_piece;
335
  }
336
  else {
337
  // Build the full form of the IPV6 address
338
- for ($i = $size; $i < 8; $i++) {
339
- $main_ip_pieces[$i] = "0000";
340
  }
341
  }
342
 
343
  // Rebuild the final long form IPV6 address
344
- $final_ip = implode(":", $main_ip_pieces);
345
- return iqblockcountry_ip2long6($final_ip);
346
  }
347
  // Determine whether the IPV6 address is within range.
348
- // $ip is the IPV6 address in decimal format to check if its within the IP range created by the cloudflare IPV6 address, $range_ip.
349
- // $ip and $range_ip are converted to full IPV6 format.
350
- // Returns true if the IPV6 address, $ip, is within the range from $range_ip. False otherwise.
351
- function iqblockcountry_ipv6_in_range($ip, $range_ip)
352
  {
353
- $pieces = explode ("/", $range_ip, 2);
354
- $left_piece = $pieces[0];
355
- $right_piece = $pieces[1];
356
  // Extract out the main IP pieces
357
- $ip_pieces = explode("::", $left_piece, 2);
358
- $main_ip_piece = $ip_pieces[0];
359
- $last_ip_piece = $ip_pieces[1];
360
  // Pad out the shorthand entries.
361
- $main_ip_pieces = explode(":", $main_ip_piece);
362
- foreach($main_ip_pieces as $key=>$val) {
363
- $main_ip_pieces[$key] = str_pad($main_ip_pieces[$key], 4, "0", STR_PAD_LEFT);
364
  }
365
  // Create the first and last pieces that will denote the IPV6 range.
366
- $first = $main_ip_pieces;
367
- $last = $main_ip_pieces;
368
  // Check to see if the last IP block (part after ::) is set
369
- $last_piece = "";
370
- $size = count($main_ip_pieces);
371
- if (trim($last_ip_piece) != "") {
372
- $last_piece = str_pad($last_ip_piece, 4, "0", STR_PAD_LEFT);
373
 
374
  // Build the full form of the IPV6 address considering the last IP block set
375
- for ($i = $size; $i < 7; $i++) {
376
- $first[$i] = "0000";
377
- $last[$i] = "ffff";
378
  }
379
- $main_ip_pieces[7] = $last_piece;
380
  }
381
  else {
382
  // Build the full form of the IPV6 address
383
- for ($i = $size; $i < 8; $i++) {
384
- $first[$i] = "0000";
385
- $last[$i] = "ffff";
386
  }
387
  }
388
  // Rebuild the final long form IPV6 address
389
- $first = iqblockcountry_ip2long6(implode(":", $first));
390
- $last = iqblockcountry_ip2long6(implode(":", $last));
391
- $in_range = ($ip >= $first && $ip <= $last);
392
- return $in_range;
393
  }
394
 
395
 
396
- function iqblockcountry_validate_ip_in_list($ipaddress,$ipv4list,$ipv6list,$iplist)
397
  {
398
 
399
- $match = FALSE;
400
- if (iqblockcountry_is_valid_ipv4($ipaddress) && is_array($ipv4list))
401
- {
402
- foreach ($ipv4list AS $iprange)
403
  {
404
- if (iqblockcountry_ip_in_ipv4_range($ipaddress,$iprange))
405
- {
406
- $match = TRUE;
407
  }
408
  }
409
  }
410
- elseif (iqblockcountry_is_valid_ipv6($ipaddress) && is_array($ipv6list))
411
- {
412
- foreach ($ipv6list AS $iprange)
413
  {
414
- $ipaddress6 = iqblockcountry_get_ipv6_full($ipaddress);
415
- if (iqblockcountry_ipv6_in_range($ipaddress6,$iprange))
416
- {
417
- $match = TRUE;
418
  }
419
  }
420
 
421
  }
422
- if ((iqblockcountry_is_valid_ipv4($ipaddress) || iqblockcountry_is_valid_ipv6($ipaddress)) && is_array($iplist))
423
- {
424
- if (in_array($ipaddress,$iplist))
425
- {
426
- $match = TRUE;
427
  }
428
  }
429
- return $match;
430
  }
3
  /*
4
  * Check of an IP address is a valid IPv4 address
5
  */
6
+ function iqblockcountry_is_valid_ipv4($iqbc_ipv4)
7
  {
8
+ if(filter_var($iqbc_ipv4, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) {
9
  return false;
10
  }
11
 
15
  /*
16
  * Check of an IP address is a valid IPv6 address
17
  */
18
+ function iqblockcountry_is_valid_ipv6($iqbc_ipv6)
19
  {
20
+ if(filter_var($iqbc_ipv6, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
21
+ return false;
22
  }
23
 
24
  return true;
25
  }
26
 
27
+ function iqblockcountry_is_valid_ipv4_cidr($iqbc_ip)
28
  {
29
+ if (preg_match('/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$/', $iqbc_ip)) {
 
30
  return true;
31
  }
32
  else
35
  }
36
  }
37
 
38
+ function iqblockcountry_is_valid_ipv6_cidr($iqbc_ip)
39
  {
40
+ if (preg_match('/^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*(\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8]))?$/', $iqbc_ip)) {
 
41
  return true;
42
  }
43
  else
50
  /*
51
  * Check of given url is a valid url
52
  */
53
+ function iqblockcountry_is_valid_url($iqbc_input)
54
  {
55
+ if(filter_var($iqbc_input, FILTER_VALIDATE_URL) === false) {
56
+ return "";
57
+ }
58
+ else
59
+ {
60
+ return $iqbc_input;
61
  }
 
 
 
 
62
 
63
  }
64
 
66
  /*
67
  * Sanitize callback. Check if supplied IP address list is valid IPv4 or IPv6
68
  */
69
+ function iqblockcountry_validate_ip($iqbc_input)
70
  {
71
+ $iqbc_validips = "";
72
+ if (preg_match('/;/', $iqbc_input)) {
73
+ $iqbc_arr = explode(";", $iqbc_input);
74
+ foreach ($iqbc_arr as $iqbc_value) {
75
+ if (iqblockcountry_is_valid_ipv4($iqbc_value) || iqblockcountry_is_valid_ipv6($iqbc_value) || iqblockcountry_is_valid_ipv4_cidr($iqbc_value) || iqblockcountry_is_valid_ipv6_cidr($iqbc_value)) {
76
+ $iqbc_validips .= $iqbc_value . ";";
 
 
77
  }
78
 
79
  }
80
  }
81
  else
82
  {
83
+ if (iqblockcountry_is_valid_ipv4($iqbc_input) || iqblockcountry_is_valid_ipv6($iqbc_input) || iqblockcountry_is_valid_ipv4_cidr($iqbc_input) || iqblockcountry_is_valid_ipv6_cidr($iqbc_input)) {
84
+ $iqbc_validips = $iqbc_input . ";";
 
85
  }
86
  }
87
+ return $iqbc_validips;
88
 
89
  }
90
 
91
  /*
92
  * Check if GeoIP API key is correct.
93
  */
94
+ function iqblockcountry_check_geoapikey($iqbc_input)
95
  {
96
 
97
  // Check first if API key is empty....
98
+ if (!empty($iqbc_input)) {
 
99
 
100
+ $iqbc_url = GEOIPAPICHECKURL;
101
 
102
+ $iqbc_result = wp_remote_post(
103
+ $iqbc_url,
104
  array(
105
  'body' => array(
106
+ 'api-key' => $iqbc_input
107
  )
108
  )
109
  );
110
+ $iqbc_message = "";
111
+ $iqbc_type = "updated";
112
+ if (is_wp_error($iqbc_result) ) {
113
+ return false;
114
  }
115
 
116
+ elseif (200 == $iqbc_result['response']['code'] ) {
117
+ $iqbc_body = $iqbc_result['body'];
118
+ $iqbc_xml = new SimpleXmlElement($iqbc_body);
119
+ if ($iqbc_xml->check != "Ok") {
120
+ $iqbc_message = esc_html('The GeoIP API key is incorrect. Please update the key.', 'iq-block-country');
121
+ $iqbc_type = "error";
122
+ $iqbc_input = false;
 
123
  }
124
  else
125
  {
126
+ $iqbc_message = esc_html('Setting saved.', 'iq-block-country');
127
+ $iqbc_type = "updated";
128
  }
129
  }
130
  else
131
  {
132
+ $iqbc_input = false;
133
  }
134
+ add_settings_error('iqblockcountry_geoipapi_error', esc_attr('settings_updated'), $iqbc_message, $iqbc_type);
135
+ return $iqbc_input;
136
  }
137
  return "";
138
  }
140
  /*
141
  * Check if GeoIP API key is correct.
142
  */
143
+ function iqblockcountry_check_adminapikey($iqbc_input)
144
  {
145
 
146
  // Check first if API key is empty....
147
+ if (!empty($iqbc_input)) {
 
148
 
149
+ $iqbc_url = ADMINAPICHECKURL;
150
 
151
+ $iqbc_result = wp_remote_post(
152
+ $iqbc_url,
153
  array(
154
  'body' => array(
155
+ 'api-key' => $iqbc_input
156
  )
157
  )
158
  );
159
+ $iqbc_message = "";
160
+ $iqbc_type = "updated";
161
+ if (is_wp_error($iqbc_result) ) {
162
+ return false;
163
  }
164
+ elseif (200 == $iqbc_result['response']['code'] ) {
165
+ $iqbc_body = $iqbc_result['body'];
166
+ $iqbc_xml = new SimpleXmlElement($iqbc_body);
167
+ if ($iqbc_xml->check != "Ok") {
168
+ $iqbc_message = esc_html('The Admin Block API key is incorrect. Please update the key.', 'iq-block-country');
169
+ $iqbc_type = "error";
170
+ $iqbc_input = false;
 
171
  }
172
  else
173
  {
174
+ $iqbc_message = esc_html('Setting saved.', 'iq-block-country');
175
+ $iqbc_type = "updated";
176
  }
177
  }
178
  else
179
  {
180
+ $iqbc_input = false;
181
  }
182
+ add_settings_error('iqblockcountry_adminapi_error', esc_attr('settings_updated'), $iqbc_message, $iqbc_type);
183
+ return $iqbc_input;
184
  }
185
  return "";
186
  }
189
  /*
190
  * Check if GeoIP API key is correct.
191
  */
192
+ function iqblockcountry_get_licensedate_geoapikey($iqbc_apikey)
193
  {
194
 
195
  // Check first if API key is empty....
196
+ if (!empty($iqbc_apikey)) {
 
197
 
198
+ $iqbc_url = GEOIPAPICHECKURL;
199
 
200
+ $iqbc_result = wp_remote_post(
201
+ $iqbc_url,
202
  array(
203
  'body' => array(
204
+ 'api-key' => $iqbc_apikey
205
  )
206
  )
207
  );
208
+ if (is_wp_error($iqbc_result) ) {
209
  return "";
210
  }
211
+ elseif (200 == $iqbc_result['response']['code'] ) {
212
+ $iqbc_body = $iqbc_result['body'];
213
+ $iqbc_xml = new SimpleXmlElement($iqbc_body);
214
+ if ($iqbc_xml->check == "Ok") {
215
+ return $iqbc_xml->LicenseDate;
 
216
  }
217
  }
218
  else
226
  /*
227
  * Check usage of GeoIP API
228
  */
229
+ function iqblockcountry_get_usage_geoapikey($iqbc_apikey)
230
  {
231
 
232
  // Check first if API key is empty....
233
+ if (!empty($iqbc_apikey)) {
 
234
 
235
+ $iqbc_url = GEOIPAPICHECKUSAGEURL;
236
 
237
+ $iqbc_result = wp_remote_post(
238
+ $iqbc_url,
239
  array(
240
  'body' => array(
241
+ 'api-key' => $iqbc_apikey
242
  )
243
  )
244
  );
245
+ if (is_wp_error($iqbc_result) ) {
246
  return "";
247
  }
248
+ elseif (200 == $iqbc_result['response']['code'] ) {
249
+ $iqbc_body = $iqbc_result['body'];
250
+ $iqbc_xml = new SimpleXmlElement($iqbc_body);
251
+ if ($iqbc_xml->check == "Ok") {
252
+ return $iqbc_xml->requests;
 
253
  }
254
  }
255
  else
263
 
264
  /**
265
  * Check if a given ip is in a network
266
+ *
267
+ * @param string $iqbc_ip IP to check in IPV4 format eg. 127.0.0.1
268
+ * @param string $range IP/CIDR netmask eg. 127.0.0.0/24, also 127.0.0.1 is accepted and /32 assumed
269
  * @return boolean true if the ip is in this range / false if not.
270
  */
271
+ function iqblockcountry_ip_in_ipv4_range( $iqbc_ip, $iqbc_range )
272
+ {
273
+ if (strpos($iqbc_range, '/') == false ) {
274
+ $iqbc_range .= '/32';
275
+ }
276
+ // $iqbc_range is in IP/CIDR format eg 127.0.0.1/24
277
+ list( $iqbc_range, $iqbc_netmask ) = explode('/', $iqbc_range, 2);
278
+ $iqbc_range_decimal = ip2long($iqbc_range);
279
+ $iqbc_ip_decimal = ip2long($iqbc_ip);
280
+ $iqbc_wildcard_decimal = pow(2, ( 32 - $iqbc_netmask )) - 1;
281
+ $iqbc_netmask_decimal = ~ $iqbc_wildcard_decimal;
282
+ return ( ( $iqbc_ip_decimal & $netmask_decimal ) == ( $iqbc_range_decimal & $iqbc_netmask_decimal ) );
283
  }
284
 
285
+ function iqblockcountry_ip2long6($iqbc_ip)
286
+ {
287
+ if (substr_count($iqbc_ip, '::')) {
288
+ $iqbc_ip = str_replace('::', str_repeat(':0000', 8 - substr_count($iqbc_ip, ':')) . ':', $iqbc_ip);
289
  }
290
 
291
+ $iqbc_ip = explode(':', $iqbc_ip);
292
+ $iqbc_r_ip = '';
293
+ foreach ($iqbc_ip as $iqbc_v) {
294
+ $iqbc_r_ip .= str_pad(base_convert($iqbc_v, 16, 2), 16, 0, STR_PAD_LEFT);
295
  }
296
 
297
+ return base_convert($iqbc_r_ip, 2, 10);
298
  }
299
  // Get the ipv6 full format and return it as a decimal value.
300
+ function iqblockcountry_get_ipv6_full($iqbc_ip)
301
  {
302
+ $iqbc_pieces = explode("/", $iqbc_ip, 2);
303
+ $iqbc_left_piece = $iqbc_pieces[0];
304
+ $iqbc_right_piece = $iqbc_pieces[1];
305
  // Extract out the main IP pieces
306
+ $iqbc_ip_pieces = explode("::", $iqbc_left_piece, 2);
307
+ $iqbc_main_ip_piece = $iqbc_ip_pieces[0];
308
+ $iqbc_last_ip_piece = $iqbc_ip_pieces[1];
309
  // Pad out the shorthand entries.
310
+ $iqbc_main_ip_pieces = explode(":", $iqbc_main_ip_piece);
311
+ foreach($iqbc_main_ip_pieces as $iqbc_key=>$iqbc_val) {
312
+ $iqbc_main_ip_pieces[$iqbc_key] = str_pad($iqbc_main_ip_pieces[$iqbc_key], 4, "0", STR_PAD_LEFT);
313
  }
314
  // Check to see if the last IP block (part after ::) is set
315
+ $iqbc_last_piece = "";
316
+ $iqbc_size = count($iqbc_main_ip_pieces);
317
+ if (trim($iqbc_last_ip_piece) != "") {
318
+ $iqbc_last_piece = str_pad($iqbc_last_ip_piece, 4, "0", STR_PAD_LEFT);
319
 
320
  // Build the full form of the IPV6 address considering the last IP block set
321
+ for ($iqbc_i = $iqbc_size; $iqbc_i < 7; $iqbc_i++) {
322
+ $iqbc_main_ip_pieces[$iqbc_i] = "0000";
323
  }
324
+ $iqbc_main_ip_pieces[7] = $iqbc_last_piece;
325
  }
326
  else {
327
  // Build the full form of the IPV6 address
328
+ for ($iqbc_i = $iqbc_size; $iqbc_i < 8; $iqbc_i++) {
329
+ $iqbc_main_ip_pieces[$iqbc_i] = "0000";
330
  }
331
  }
332
 
333
  // Rebuild the final long form IPV6 address
334
+ $iqbc_final_ip = implode(":", $iqbc_main_ip_pieces);
335
+ return iqblockcountry_ip2long6($iqbc_final_ip);
336
  }
337
  // Determine whether the IPV6 address is within range.
338
+ // $iqbc_ip is the IPV6 address in decimal format to check if its within the IP range created by the cloudflare IPV6 address, $range_ip.
339
+ // $iqbc_ip and $range_ip are converted to full IPV6 format.
340
+ // Returns true if the IPV6 address, $iqbc_ip, is within the range from $range_ip. False otherwise.
341
+ function iqblockcountry_ipv6_in_range($iqbc_ip, $range_ip)
342
  {
343
+ $iqbc_pieces = explode("/", $range_ip, 2);
344
+ $iqbc_left_piece = $iqbc_pieces[0];
345
+ $iqbc_right_piece = $iqbc_pieces[1];
346
  // Extract out the main IP pieces
347
+ $iqbc_ip_pieces = explode("::", $iqbc_left_piece, 2);
348
+ $iqbc_main_ip_piece = $iqbc_ip_pieces[0];
349
+ $iqbc_last_ip_piece = $iqbc_ip_pieces[1];
350
  // Pad out the shorthand entries.
351
+ $iqbc_main_ip_pieces = explode(":", $iqbc_main_ip_piece);
352
+ foreach($iqbc_main_ip_pieces as $iqbc_key=>$iqbc_val) {
353
+ $iqbc_main_ip_pieces[$iqbc_key] = str_pad($iqbc_main_ip_pieces[$iqbc_key], 4, "0", STR_PAD_LEFT);
354
  }
355
  // Create the first and last pieces that will denote the IPV6 range.
356
+ $iqbc_first = $iqbc_main_ip_pieces;
357
+ $iqbc_last = $iqbc_main_ip_pieces;
358
  // Check to see if the last IP block (part after ::) is set
359
+ $iqbc_last_piece = "";
360
+ $iqbc_size = count($iqbc_main_ip_pieces);
361
+ if (trim($iqbc_last_ip_piece) != "") {
362
+ $iqbc_last_piece = str_pad($iqbc_last_ip_piece, 4, "0", STR_PAD_LEFT);
363
 
364
  // Build the full form of the IPV6 address considering the last IP block set
365
+ for ($iqbc_i = $iqbc_size; $iqbc_i < 7; $iqbc_i++) {
366
+ $iqbc_first[$iqbc_i] = "0000";
367
+ $iqbc_last[$iqbc_i] = "ffff";
368
  }
369
+ $iqbc_main_ip_pieces[7] = $iqbc_last_piece;
370
  }
371
  else {
372
  // Build the full form of the IPV6 address
373
+ for ($iqbc_i = $iqbc_size; $iqbc_i < 8; $iqbc_i++) {
374
+ $iqbc_first[$iqbc_i] = "0000";
375
+ $iqbc_last[$iqbc_i] = "ffff";
376
  }
377
  }
378
  // Rebuild the final long form IPV6 address
379
+ $iqbc_first = iqblockcountry_ip2long6(implode(":", $iqbc_first));
380
+ $iqbc_last = iqblockcountry_ip2long6(implode(":", $iqbc_last));
381
+ $iqbc_in_range = ($iqbc_ip >= $iqbc_first && $iqbc_ip <= $iqbc_last);
382
+ return $iqbc_in_range;
383
  }
384
 
385
 
386
+ function iqblockcountry_validate_ip_in_list($iqbc_ipaddress,$iqbc_ipv4list,$iqbc_ipv6list,$iqbc_iplist)
387
  {
388
 
389
+ $iqbc_match = false;
390
+ if (iqblockcountry_is_valid_ipv4($iqbc_ipaddress) && is_array($iqbc_ipv4list)) {
391
+ foreach ($iqbc_ipv4list AS $iqbc_iprange)
 
392
  {
393
+ if (iqblockcountry_ip_in_ipv4_range($iqbc_ipaddress, $iqbc_iprange)) {
394
+ $iqbc_match = true;
 
395
  }
396
  }
397
  }
398
+ elseif (iqblockcountry_is_valid_ipv6($iqbc_ipaddress) && is_array($iqbc_ipv6list)) {
399
+ foreach ($iqbc_ipv6list AS $iqbc_iprange)
 
400
  {
401
+ $iqbc_ipaddress6 = iqblockcountry_get_ipv6_full($iqbc_ipaddress);
402
+ if (iqblockcountry_ipv6_in_range($iqbc_ipaddress6, $iqbc_iprange)) {
403
+ $iqbc_match = true;
 
404
  }
405
  }
406
 
407
  }
408
+ if ((iqblockcountry_is_valid_ipv4($iqbc_ipaddress) || iqblockcountry_is_valid_ipv6($iqbc_ipaddress)) && is_array($iqbc_iplist)) {
409
+ if (in_array($iqbc_ipaddress, $iqbc_iplist)) {
410
+ $iqbc_match = true;
 
 
411
  }
412
  }
413
+ return $iqbc_match;
414
  }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: iqpascal
3
  Donate link: https://webence.nl/plugins/donate
4
  Tags: spam, block, country, comments, ban, geo, geo blocking, geo ip, block country, block countries, ban countries, ban country, allow list, block list, security
5
  Requires at least: 3.5.2
6
- Tested up to: 5.9.2
7
- Stable tag: 1.2.13
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  Requires PHP: 7.0
@@ -241,6 +241,9 @@ be used.
241
 
242
  == Changelog ==
243
 
 
 
 
244
  = 1.2.13 =
245
 
246
  * Change: Altered import/export function to make it more secure
3
  Donate link: https://webence.nl/plugins/donate
4
  Tags: spam, block, country, comments, ban, geo, geo blocking, geo ip, block country, block countries, ban countries, ban country, allow list, block list, security
5
  Requires at least: 3.5.2
6
+ Tested up to: 6.0
7
+ Stable tag: 1.2.14
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  Requires PHP: 7.0
241
 
242
  == Changelog ==
243
 
244
+ = 1.2.14 =
245
+ * Change: A lot of internal code changes to make it more in line of WordPress Best Practices
246
+
247
  = 1.2.13 =
248
 
249
  * Change: Altered import/export function to make it more secure