iQ Block Country - Version 1.2.13

Version Description

  • Change: Altered import/export function to make it more secure
    • New: Added "Reset Counters" button to reset your total number of frontend / backend blocks.
Download this release

Release Info

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

Code changes from version 1.2.12 to 1.2.13

iq-block-country.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: iQ Block Country
4
  Plugin URI: https://www.webence.nl/plugins/iq-block-country-the-wordpress-plugin-that-blocks-countries-for-you/
5
- Version: 1.2.12
6
  Author: Pascal
7
  Author URI: https://www.webence.nl/
8
  Description: Block visitors from visiting your website and backend website based on which country their IP address is from. The Maxmind GeoIP lite database is used for looking up from which country an ip address is from.
@@ -13,7 +13,7 @@ Domain Path: /lang
13
 
14
  /* This script uses GeoLite Country from MaxMind (http://www.maxmind.com) which is available under terms of GPL/LGPL */
15
 
16
- /* Copyright 2010-2021 Pascal (email: pascal@webence.nl)
17
 
18
  This program is free software; you can redistribute it and/or modify
19
  it under the terms of the GNU General Public License, version 2, as
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.
13
 
14
  /* This script uses GeoLite Country from MaxMind (http://www.maxmind.com) which is available under terms of GPL/LGPL */
15
 
16
+ /* Copyright 2010-2022 Pascal (email: pascal@webence.nl)
17
 
18
  This program is free software; you can redistribute it and/or modify
19
  it under the terms of the GNU General Public License, version 2, as
libs/blockcountry-settings.php CHANGED
@@ -489,7 +489,31 @@ function iqblockcountry_settings_tools() {
489
  <br />
490
  <br />
491
 
 
492
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
493
  <h3><?php _e('Active plugins', 'iq-block-country'); ?></h3>
494
  <?php
495
 
@@ -823,18 +847,18 @@ function iqblockcountry_settings_importexport() {
823
 
824
  $blogname = str_replace(" ", "", get_option('blogname'));
825
  $date = date("d-m-Y");
826
- $json_name = $blogname."-".$date; // Namming the filename will be generated.
 
 
827
 
828
  $optarr = iqblockcountry_get_options_arr();
829
  foreach ( $optarr as $options ) {
830
-
831
  $value = get_option($options);
832
  $need_options[$options] = $value;
833
- }
834
 
835
  $json_file = json_encode($need_options); // Encode data into json data
836
 
837
-
838
  if ( !$handle = fopen( $dir['path'] . '/' . 'iqblockcountry.ini', 'w' ) )
839
  wp_die(__("Something went wrong exporting this file", 'iq-block-country'));
840
 
@@ -843,12 +867,16 @@ function iqblockcountry_settings_importexport() {
843
 
844
  fclose( $handle );
845
 
846
- require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
847
-
848
  chdir( $dir['path'] );
849
- $zip = new PclZip( './' . $json_name . '-iqblockcountry.zip' );
850
- if ( $zip->create( './' . 'iqblockcountry.ini' ) == 0 )
851
- wp_die(__("Something went wrong exporting this file", 'iq-block-country'));
 
 
 
 
 
 
852
 
853
  $url = $dir['url'] . '/' . $json_name . '-iqblockcountry.zip';
854
  $content = "<div class='notice notice-success'><p>" . __("Exporting settings...", 'iq-block-country') . "</p></div>";
@@ -865,39 +893,40 @@ function iqblockcountry_settings_importexport() {
865
  elseif (isset($_POST['import'])) {
866
  $optarr = iqblockcountry_get_options_arr();
867
  if (isset($_FILES['import']) && check_admin_referer('iqblockimport')) {
868
- if ($_FILES['import']['error'] > 0) {
869
  wp_die(__("Something went wrong importing this file", 'iq-block-country'));
870
  }
871
- else {
872
- require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
873
- $zip = new PclZip( $_FILES['import']['tmp_name'] );
874
- $unzipped = $zip->extract( $p_path = $dir['path'] );
875
- if ( $unzipped[0]['stored_filename'] == 'iqblockcountry.ini' ) {
 
 
 
 
 
 
 
876
  $encode_options = file_get_contents($dir['path'] . '/iqblockcountry.ini');
877
  $options = json_decode($encode_options, true);
878
  foreach ($options as $key => $value) {
879
- if (in_array($key,$optarr)) {
880
- update_option($key, $value);
881
- }
882
  }
883
  unlink($dir['path'] . '/iqblockcountry.ini');
884
- // check if file exists first.
885
-
886
- echo "<div class='notice notice-success'><p>" . __("All options are restored successfully.", 'iq-block-country') . "</p></div>";
887
- }
888
- else {
889
- echo "<div class='notice notice-error'><p>" . __("Invalid file.", 'iq-block-country') ."</p></div>";
890
- }
891
- foreach ($unzipped as $zipfile)
892
- {
893
- if (file_exists($zipfile['filename']))
894
- {
895
- unlink($zipfile['filename']);
896
- }
897
- }
898
- if (file_exists($dir['path'] . $_FILES['import']['name'])) { unlink($dir['path'] . $_FILES['import']['name']); }
899
- }
900
- }
901
  }
902
  else { wp_die(__("No correct import or export option given.", 'iq-block-country')); }
903
 
@@ -1914,8 +1943,8 @@ function iqblockcountry_settings_page() {
1914
 
1915
  <p>This product uses GeoIP2 data created by MaxMind, available from <a href="http://www.maxmind.com/">http://www.maxmind.com/</a>.</p>
1916
 
1917
- <p>If you like this plugin please link back to <a href="https://www.webence.nl/">www.webence.nl</a>! :-) and support the development of the plugin.
1918
- See <a href="https://www.webence.nl/plugins/donate/">Plugin donation page</a></p>
1919
 
1920
  <?php
1921
 
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
 
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
 
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>";
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
 
1943
 
1944
  <p>This product uses GeoIP2 data created by MaxMind, available from <a href="http://www.maxmind.com/">http://www.maxmind.com/</a>.</p>
1945
 
1946
+ <p>If you like this plugin please link back to <a href="https://webence.nl/">webence.nl</a>! :-) and support the development of the plugin.
1947
+ See <a href="https://webence.nl/plugins/donate/">Plugin donation page</a></p>
1948
 
1949
  <?php
1950
 
readme.txt CHANGED
@@ -3,11 +3,11 @@ 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.7.2
7
- Stable tag: 1.2.12
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
- Requires PHP: 5.6
11
 
12
  Allow or disallow visitors from certain countries accessing (parts of) your website
13
 
@@ -241,6 +241,11 @@ be used.
241
 
242
  == Changelog ==
243
 
 
 
 
 
 
244
  = 1.2.12 =
245
 
246
  * Change: Added/Changed some services.
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
11
 
12
  Allow or disallow visitors from certain countries accessing (parts of) your website
13
 
241
 
242
  == Changelog ==
243
 
244
+ = 1.2.13 =
245
+
246
+ * Change: Altered import/export function to make it more secure
247
+ * New: Added "Reset Counters" button to reset your total number of frontend / backend blocks.
248
+
249
  = 1.2.12 =
250
 
251
  * Change: Added/Changed some services.