Version Description
- Added Google Ads to search engines
- Added Redirect URL (Basic code supplied by Stefan)
- Added inverse selection on frontend. (Basic code supplied by Stefan)
- Added inverse selection on backend.
- Validated input on the tools tab.
Download this release
Release Info
Developer | iqpascal |
Plugin | iQ Block Country |
Version | 1.1.20 |
Comparing to | |
See all releases |
Code changes from version 1.1.19 to 1.1.20
- iq-block-country.php +7 -3
- libs/blockcountry-checks.php +44 -17
- libs/blockcountry-search-engines.php +2 -0
- libs/blockcountry-settings.php +78 -10
- libs/blockcountry-validation.php +62 -0
- readme.txt +10 -2
iq-block-country.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/*
|
3 |
Plugin Name: iQ Block Country
|
4 |
Plugin URI: http://www.redeo.nl/2013/12/iq-block-country-wordpress-plugin-blocks-countries/
|
5 |
-
Version: 1.1.
|
6 |
Author: Pascal
|
7 |
Author URI: http://www.redeo.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.
|
@@ -127,6 +127,7 @@ function iqblockcountry_get_ipaddress() {
|
|
127 |
} elseif ( isset($_SERVER['HTTP_X_TM_REMOTE_ADDR']) && !empty($_SERVER['HTTP_X_TM_REMOTE_ADDR']) ) {
|
128 |
$ip_address = $_SERVER['HTTP_X_TM_REMOTE_ADDR'];
|
129 |
}
|
|
|
130 |
return $ip_address;
|
131 |
}
|
132 |
|
@@ -182,6 +183,7 @@ function iqblockcountry_upgrade()
|
|
182 |
|
183 |
}
|
184 |
|
|
|
185 |
/*
|
186 |
* Main plugin works.
|
187 |
*/
|
@@ -195,8 +197,10 @@ define("IPV6DBFILE",$upload_dir['basedir'] . "/GeoIPv6.dat");
|
|
195 |
define("TRACKINGURL","http://tracking.webence.nl/iq-block-country-tracking.php");
|
196 |
define("BANLISTRETRIEVEURL","http://tracking.webence.nl/iq-block-country-retrieve.php");
|
197 |
define("GEOIPAPIURL","http://geoip.webence.nl/geoipapi.php");
|
|
|
198 |
define("GEOIPAPICHECKURL","http://geoip.webence.nl/geoipapi-keycheck.php");
|
199 |
-
define("
|
|
|
200 |
define("DBVERSION","121");
|
201 |
define("PLUGINPATH",plugin_dir_path( __FILE__ ));
|
202 |
|
@@ -259,4 +263,4 @@ if (get_option('blockcountry_buffer') == "on")
|
|
259 |
|
260 |
|
261 |
|
262 |
-
?>
|
2 |
/*
|
3 |
Plugin Name: iQ Block Country
|
4 |
Plugin URI: http://www.redeo.nl/2013/12/iq-block-country-wordpress-plugin-blocks-countries/
|
5 |
+
Version: 1.1.20
|
6 |
Author: Pascal
|
7 |
Author URI: http://www.redeo.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.
|
127 |
} elseif ( isset($_SERVER['HTTP_X_TM_REMOTE_ADDR']) && !empty($_SERVER['HTTP_X_TM_REMOTE_ADDR']) ) {
|
128 |
$ip_address = $_SERVER['HTTP_X_TM_REMOTE_ADDR'];
|
129 |
}
|
130 |
+
|
131 |
return $ip_address;
|
132 |
}
|
133 |
|
183 |
|
184 |
}
|
185 |
|
186 |
+
|
187 |
/*
|
188 |
* Main plugin works.
|
189 |
*/
|
197 |
define("TRACKINGURL","http://tracking.webence.nl/iq-block-country-tracking.php");
|
198 |
define("BANLISTRETRIEVEURL","http://tracking.webence.nl/iq-block-country-retrieve.php");
|
199 |
define("GEOIPAPIURL","http://geoip.webence.nl/geoipapi.php");
|
200 |
+
define("GEOIPAPIURLUS","http://us.geoip.webence.nl/geoipapi.php");
|
201 |
define("GEOIPAPICHECKURL","http://geoip.webence.nl/geoipapi-keycheck.php");
|
202 |
+
define("ADMINAPICHECKURL","http://tracking.webence.nl/adminapi-keycheck.php");
|
203 |
+
define("VERSION","1.1.20b");
|
204 |
define("DBVERSION","121");
|
205 |
define("PLUGINPATH",plugin_dir_path( __FILE__ ));
|
206 |
|
263 |
|
264 |
|
265 |
|
266 |
+
?>
|
libs/blockcountry-checks.php
CHANGED
@@ -40,6 +40,7 @@ function iqblockcountry_check_ipaddress($ip_address)
|
|
40 |
}
|
41 |
else { $country = "Unknown"; }
|
42 |
|
|
|
43 |
return $country;
|
44 |
}
|
45 |
|
@@ -49,7 +50,11 @@ function iqblockcountry_check_ipaddress($ip_address)
|
|
49 |
function iqblockcountry_retrieve_geoipapi($ipaddress)
|
50 |
{
|
51 |
$url = GEOIPAPIURL;
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
$result = wp_remote_post(
|
54 |
$url,
|
55 |
array(
|
@@ -247,11 +252,26 @@ function iqblockcountry_CheckCountry() {
|
|
247 |
|
248 |
if ((iqblockcountry_is_login_page() || is_admin()) && get_option('blockcountry_blockbackend'))
|
249 |
{
|
250 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
}
|
252 |
else
|
253 |
{
|
254 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
}
|
256 |
$blocklogin = get_option ( 'blockcountry_blocklogin' );
|
257 |
if ( ((is_user_logged_in()) && ($blocklogin != "on")) || (!(is_user_logged_in())) ) {
|
@@ -259,8 +279,11 @@ function iqblockcountry_CheckCountry() {
|
|
259 |
/* Check ip address against banlist, whitelist and blacklist */
|
260 |
if (iqblockcountry_check($country,$badcountries,$ip_address))
|
261 |
{
|
|
|
|
|
262 |
$blockmessage = get_option ( 'blockcountry_blockmessage' );
|
263 |
$blockredirect = get_option ( 'blockcountry_redirect');
|
|
|
264 |
$header = get_option('blockcountry_header');
|
265 |
if (!empty($header) && ($header))
|
266 |
{
|
@@ -272,7 +295,11 @@ function iqblockcountry_CheckCountry() {
|
|
272 |
|
273 |
header ( 'HTTP/1.1 403 Forbidden' );
|
274 |
}
|
275 |
-
if (!empty($
|
|
|
|
|
|
|
|
|
276 |
{
|
277 |
$redirecturl = get_permalink($blockredirect);
|
278 |
header("Location: $redirecturl");
|
@@ -289,20 +316,20 @@ function iqblockcountry_CheckCountry() {
|
|
289 |
global $apiblacklist,$backendblacklistcheck;
|
290 |
if (!get_option('blockcountry_logging'))
|
291 |
{
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
}
|
305 |
-
|
306 |
}
|
307 |
else
|
308 |
{
|
40 |
}
|
41 |
else { $country = "Unknown"; }
|
42 |
|
43 |
+
|
44 |
return $country;
|
45 |
}
|
46 |
|
50 |
function iqblockcountry_retrieve_geoipapi($ipaddress)
|
51 |
{
|
52 |
$url = GEOIPAPIURL;
|
53 |
+
if (get_option('blockcountry_geoapilocation') == "US")
|
54 |
+
{
|
55 |
+
$url = GEOIPAPIURLUS;
|
56 |
+
}
|
57 |
+
|
58 |
$result = wp_remote_post(
|
59 |
$url,
|
60 |
array(
|
252 |
|
253 |
if ((iqblockcountry_is_login_page() || is_admin()) && get_option('blockcountry_blockbackend'))
|
254 |
{
|
255 |
+
$banlist = get_option( 'blockcountry_backendbanlist' );
|
256 |
+
if (!is_array($banlist)) { $banlist = array(); }
|
257 |
+
if (get_option( 'blockcountry_backendbanlist_inverse' ) == 'on') {
|
258 |
+
$all_countries = array_keys(iqblockcountry_get_countries());
|
259 |
+
$badcountries = array_diff($all_countries, $banlist);
|
260 |
+
} else {
|
261 |
+
$badcountries = $banlist;
|
262 |
+
}
|
263 |
}
|
264 |
else
|
265 |
{
|
266 |
+
$banlist = get_option( 'blockcountry_banlist' );
|
267 |
+
if (!is_array($banlist)) { $banlist = array(); }
|
268 |
+
if (get_option( 'blockcountry_banlist_inverse' ) == 'on') {
|
269 |
+
$all_countries = array_keys(iqblockcountry_get_countries());
|
270 |
+
$badcountries = array_diff($all_countries, $banlist);
|
271 |
+
} else {
|
272 |
+
$badcountries = $banlist;
|
273 |
+
}
|
274 |
+
|
275 |
}
|
276 |
$blocklogin = get_option ( 'blockcountry_blocklogin' );
|
277 |
if ( ((is_user_logged_in()) && ($blocklogin != "on")) || (!(is_user_logged_in())) ) {
|
279 |
/* Check ip address against banlist, whitelist and blacklist */
|
280 |
if (iqblockcountry_check($country,$badcountries,$ip_address))
|
281 |
{
|
282 |
+
|
283 |
+
|
284 |
$blockmessage = get_option ( 'blockcountry_blockmessage' );
|
285 |
$blockredirect = get_option ( 'blockcountry_redirect');
|
286 |
+
$blockredirect_url = get_option ( 'blockcountry_redirect_url');
|
287 |
$header = get_option('blockcountry_header');
|
288 |
if (!empty($header) && ($header))
|
289 |
{
|
295 |
|
296 |
header ( 'HTTP/1.1 403 Forbidden' );
|
297 |
}
|
298 |
+
if (!empty($blockredirect_url))
|
299 |
+
{
|
300 |
+
header("Location: $blockredirect_url");
|
301 |
+
}
|
302 |
+
elseif (!empty($blockredirect) && $blockredirect != 0)
|
303 |
{
|
304 |
$redirecturl = get_permalink($blockredirect);
|
305 |
header("Location: $redirecturl");
|
316 |
global $apiblacklist,$backendblacklistcheck;
|
317 |
if (!get_option('blockcountry_logging'))
|
318 |
{
|
319 |
+
if (!$apiblacklist)
|
320 |
+
{
|
321 |
+
iqblockcountry_logging($ip_address, $country, "B");
|
322 |
+
}
|
323 |
+
elseif ($backendblacklistcheck && $apiblacklist)
|
324 |
+
{
|
325 |
+
iqblockcountry_logging($ip_address, $country, "T");
|
326 |
+
}
|
327 |
+
else
|
328 |
+
{
|
329 |
+
iqblockcountry_logging($ip_address, $country, "A");
|
330 |
+
}
|
331 |
}
|
332 |
+
|
333 |
}
|
334 |
else
|
335 |
{
|
libs/blockcountry-search-engines.php
CHANGED
@@ -9,6 +9,8 @@ $searchengines = array(
|
|
9 |
"Duck Duck Go" => "duckduckbot",
|
10 |
"Facebook" => "facebookexternalhit",
|
11 |
"Google" => "googlebot",
|
|
|
|
|
12 |
"MSN" => "msnbot",
|
13 |
"TinEye" => "tineye-bot",
|
14 |
"Twitter" => "twitterbot",
|
9 |
"Duck Duck Go" => "duckduckbot",
|
10 |
"Facebook" => "facebookexternalhit",
|
11 |
"Google" => "googlebot",
|
12 |
+
"Google Ads" => "AdsBot-Google",
|
13 |
+
"Google Page Speed Insight" => "Google Page Speed Insight",
|
14 |
"MSN" => "msnbot",
|
15 |
"TinEye" => "tineye-bot",
|
16 |
"Twitter" => "twitterbot",
|
libs/blockcountry-settings.php
CHANGED
@@ -84,21 +84,25 @@ function iqblockcountry_register_mysettings()
|
|
84 |
//register our settings
|
85 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_blockmessage' );
|
86 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_redirect');
|
|
|
87 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_header');
|
88 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_buffer');
|
89 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_tracking');
|
90 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_nrstatistics');
|
91 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_nrstatistics');
|
92 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_geoapikey','iqblockcountry_check_geoapikey');
|
93 |
-
register_setting ( 'iqblockcountry-settings-group', '
|
|
|
94 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_backendlogging');
|
95 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_accessibility');
|
96 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_logging');
|
97 |
register_setting ( 'iqblockcountry-settings-group-backend', 'blockcountry_blockbackend' );
|
98 |
register_setting ( 'iqblockcountry-settings-group-backend', 'blockcountry_backendbanlist' );
|
|
|
99 |
register_setting ( 'iqblockcountry-settings-group-backend', 'blockcountry_backendblacklist','iqblockcountry_validate_ip');
|
100 |
register_setting ( 'iqblockcountry-settings-group-backend', 'blockcountry_backendwhitelist','iqblockcountry_validate_ip');
|
101 |
register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_banlist' );
|
|
|
102 |
register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_frontendblacklist','iqblockcountry_validate_ip');
|
103 |
register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_frontendwhitelist','iqblockcountry_validate_ip');
|
104 |
register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_blocklogin' );
|
@@ -120,12 +124,13 @@ function iqblockcountry_register_mysettings()
|
|
120 |
* @return array of options.
|
121 |
*/
|
122 |
function iqblockcountry_get_options_arr() {
|
123 |
-
$optarr = array( 'blockcountry_banlist',
|
124 |
-
'
|
125 |
-
'
|
126 |
-
'
|
127 |
-
'
|
128 |
-
'
|
|
|
129 |
return apply_filters( 'iqblockcountry_options', $optarr );
|
130 |
}
|
131 |
|
@@ -155,7 +160,9 @@ function iqblockcountry_uninstall() //deletes all the database entries that the
|
|
155 |
iqblockcountry_uninstall_db();
|
156 |
iqblockcountry_uninstall_loggingdb();
|
157 |
delete_option('blockcountry_banlist' );
|
|
|
158 |
delete_option('blockcountry_backendbanlist' );
|
|
|
159 |
delete_option('blockcountry_backendblacklist' );
|
160 |
delete_option('blockcountry_backendwhitelist' );
|
161 |
delete_option('blockcountry_frontendblacklist' );
|
@@ -178,8 +185,10 @@ function iqblockcountry_uninstall() //deletes all the database entries that the
|
|
178 |
delete_option('blockcountry_backendbanlistip');
|
179 |
delete_option('blockcountry_nrstastistics');
|
180 |
delete_option('blockcountry_geoapikey');
|
|
|
181 |
delete_option('blockcountry_apikey');
|
182 |
delete_option('blockcountry_redirect');
|
|
|
183 |
delete_option('blockcountry_allowse');
|
184 |
delete_option('blockcountry_backendlogging');
|
185 |
delete_option('blockcountry_buffer');
|
@@ -198,12 +207,19 @@ function iqblockcountry_settings_tools() {
|
|
198 |
|
199 |
<form name="ipcheck" action="#ipcheck" method="post">
|
200 |
<input type="hidden" name="action" value="ipcheck" />
|
|
|
201 |
<?php _e('IP Address to check:', 'iqblockcountry'); ?> <input type="text" name="ipaddress" lenth="50" />
|
202 |
<?php
|
|
|
|
|
203 |
if ( isset($_POST['action']) && $_POST[ 'action' ] == 'ipcheck') {
|
|
|
|
|
204 |
if (isset($_POST['ipaddress']) && !empty($_POST['ipaddress']))
|
205 |
{
|
206 |
$ip_address = $_POST['ipaddress'];
|
|
|
|
|
207 |
$country = iqblockcountry_check_ipaddress($ip_address);
|
208 |
$countrylist = iqblockcountry_get_countries();
|
209 |
if ($country == "Unknown" || $country == "ipv6" || $country == "" || $country == "FALSE")
|
@@ -215,20 +231,38 @@ function iqblockcountry_settings_tools() {
|
|
215 |
$displaycountry = $countrylist[$country];
|
216 |
echo "<p>" . __('IP Adress', 'iqblockcountry') . ' ' . $ip_address . ' ' . __('belongs to', 'iqblockcountry') . ' ' . $displaycountry . ".</p>";
|
217 |
$haystack = get_option('blockcountry_banlist');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
if (is_array($haystack) && in_array ( $country, $haystack )) {
|
219 |
_e('This country is not permitted to visit the frontend of this website.', 'iqblockcountry');
|
220 |
echo "<br />";
|
221 |
}
|
222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
if (is_array($haystack) && in_array ( $country, $haystack )) {
|
224 |
_e('This country is not permitted to visit the backend of this website.', 'iqblockcountry');
|
225 |
echo "<br />";
|
226 |
}
|
|
|
227 |
$backendbanlistip = unserialize(get_option('blockcountry_backendbanlistip'));
|
228 |
if (is_array($backendbanlistip) && in_array($ip_address,$backendbanlistip)) {
|
229 |
_e('This ip is present in the blacklist.', 'iqblockcountry');
|
230 |
}
|
231 |
}
|
|
|
232 |
}
|
233 |
}
|
234 |
echo '<div class="submit"><input type="submit" name="test" value="' . __( 'Check IP address', 'iqblockcountry' ) . '" /></div>';
|
@@ -662,6 +696,12 @@ function iqblockcountry_settings_frontend()
|
|
662 |
|
663 |
?>
|
664 |
</td></tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
665 |
<tr valign="top">
|
666 |
<th width="30%"><?php _e('Frontend whitelist IPv4 and/or IPv6 addresses:', 'iqblockcountry'); ?><br /><?php _e('Use a semicolon (;) to separate IP addresses', 'iqblockcountry'); ?></th>
|
667 |
<td width="70%">
|
@@ -786,6 +826,14 @@ function iqblockcountry_settings_backend()
|
|
786 |
?>
|
787 |
|
788 |
</td></tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
789 |
<tr valign="top">
|
790 |
<th width="30%"><?php _e('Backend whitelist IPv4 and/or IPv6 addresses:', 'iqblockcountry'); ?><br /><?php _e('Use a semicolon (;) to separate IP addresses', 'iqblockcountry'); ?></th>
|
791 |
<td width="70%">
|
@@ -877,7 +925,8 @@ function iqblockcountry_settings_home()
|
|
877 |
?>
|
878 |
<textarea cols="100" rows="3" name="blockcountry_blockmessage"><?php echo $blockmessage; ?></textarea>
|
879 |
</td></tr>
|
880 |
-
|
|
|
881 |
<tr valign="top">
|
882 |
<th width="30%"><?php _e('Page to redirect to:', 'iqblockcountry'); ?><br />
|
883 |
<em><?php _e('If you select a page here blocked visitors will be redirected to this page instead of displaying above block message.', 'iqblockcountry'); ?></em></th>
|
@@ -900,6 +949,14 @@ function iqblockcountry_settings_home()
|
|
900 |
</select>
|
901 |
</td></tr>
|
902 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
903 |
<tr valign="top">
|
904 |
<th width="30%"><?php _e('Send headers when user is blocked:', 'iqblockcountry'); ?><br />
|
905 |
<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.', 'iqblockcountry'); ?></em></th>
|
@@ -949,8 +1006,19 @@ function iqblockcountry_settings_home()
|
|
949 |
<th width="30%"><?php _e('GeoIP API Key:', 'iqblockcountry'); ?><br />
|
950 |
<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: ', 'iqblockcountry'); ?> <a href="http://geoip.webence.nl/" target=""_blank>http://geoip.webence.nl/</a></em></th>
|
951 |
</th>
|
952 |
-
|
953 |
<input type="text" size="25" name="blockcountry_geoapikey" value="<?php echo get_option ( 'blockcountry_geoapikey' );?>">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
954 |
</td></tr>
|
955 |
<tr valign="top">
|
956 |
<th width="30%"><?php _e('Admin block API Key:', 'iqblockcountry'); ?><br />
|
84 |
//register our settings
|
85 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_blockmessage' );
|
86 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_redirect');
|
87 |
+
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_redirect_url','iqblockcountry_is_valid_url');
|
88 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_header');
|
89 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_buffer');
|
90 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_tracking');
|
91 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_nrstatistics');
|
92 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_nrstatistics');
|
93 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_geoapikey','iqblockcountry_check_geoapikey');
|
94 |
+
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_geoapilocation');
|
95 |
+
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_apikey','iqblockcountry_check_adminapikey');
|
96 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_backendlogging');
|
97 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_accessibility');
|
98 |
register_setting ( 'iqblockcountry-settings-group', 'blockcountry_logging');
|
99 |
register_setting ( 'iqblockcountry-settings-group-backend', 'blockcountry_blockbackend' );
|
100 |
register_setting ( 'iqblockcountry-settings-group-backend', 'blockcountry_backendbanlist' );
|
101 |
+
register_setting ( 'iqblockcountry-settings-group-backend', 'blockcountry_backendbanlist_inverse' );
|
102 |
register_setting ( 'iqblockcountry-settings-group-backend', 'blockcountry_backendblacklist','iqblockcountry_validate_ip');
|
103 |
register_setting ( 'iqblockcountry-settings-group-backend', 'blockcountry_backendwhitelist','iqblockcountry_validate_ip');
|
104 |
register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_banlist' );
|
105 |
+
register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_banlist_inverse' );
|
106 |
register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_frontendblacklist','iqblockcountry_validate_ip');
|
107 |
register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_frontendwhitelist','iqblockcountry_validate_ip');
|
108 |
register_setting ( 'iqblockcountry-settings-group-frontend', 'blockcountry_blocklogin' );
|
124 |
* @return array of options.
|
125 |
*/
|
126 |
function iqblockcountry_get_options_arr() {
|
127 |
+
$optarr = array( 'blockcountry_banlist','blockcountry_banlist_inverse', 'blockcountry_backendbanlist','blockcountry_backendbanlist_inverse',
|
128 |
+
'blockcountry_backendblacklist','blockcountry_backendwhitelist','blockcountry_frontendblacklist','blockcountry_frontendwhitelist',
|
129 |
+
'blockcountry_blockmessage','blockcountry_blocklogin','blockcountry_blockfrontend','blockcountry_blockbackend','blockcountry_header',
|
130 |
+
'blockcountry_blockpages','blockcountry_pages','blockcountry_blockcategories','blockcountry_categories','blockcountry_tracking',
|
131 |
+
'blockcountry_blockhome','blockcountry_nrstatistics','blockcountry_geoapikey','blockcountry_geoapilocation','blockcountry_apikey',
|
132 |
+
'blockcountry_redirect','blockcountry_redirect_url','blockcountry_allowse','blockcountry_backendlogging','blockcountry_buffer',
|
133 |
+
'blockcountry_accessibility','blockcountry_logging','blockcountry_blockposttypes','blockcountry_posttypes','blockcountry_blocksearch');
|
134 |
return apply_filters( 'iqblockcountry_options', $optarr );
|
135 |
}
|
136 |
|
160 |
iqblockcountry_uninstall_db();
|
161 |
iqblockcountry_uninstall_loggingdb();
|
162 |
delete_option('blockcountry_banlist' );
|
163 |
+
delete_option('blockcountry_banlist_inverse' );
|
164 |
delete_option('blockcountry_backendbanlist' );
|
165 |
+
delete_option('blockcountry_backendbanlist_inverse');
|
166 |
delete_option('blockcountry_backendblacklist' );
|
167 |
delete_option('blockcountry_backendwhitelist' );
|
168 |
delete_option('blockcountry_frontendblacklist' );
|
185 |
delete_option('blockcountry_backendbanlistip');
|
186 |
delete_option('blockcountry_nrstastistics');
|
187 |
delete_option('blockcountry_geoapikey');
|
188 |
+
delete_option('blockcountry_geoapilocation');
|
189 |
delete_option('blockcountry_apikey');
|
190 |
delete_option('blockcountry_redirect');
|
191 |
+
delete_option('blockcountry_redirect_url');
|
192 |
delete_option('blockcountry_allowse');
|
193 |
delete_option('blockcountry_backendlogging');
|
194 |
delete_option('blockcountry_buffer');
|
207 |
|
208 |
<form name="ipcheck" action="#ipcheck" method="post">
|
209 |
<input type="hidden" name="action" value="ipcheck" />
|
210 |
+
<input name="ipcheck_nonce" type="hidden" value="<?php echo wp_create_nonce('ipcheck_nonce'); ?>" />
|
211 |
<?php _e('IP Address to check:', 'iqblockcountry'); ?> <input type="text" name="ipaddress" lenth="50" />
|
212 |
<?php
|
213 |
+
|
214 |
+
|
215 |
if ( isset($_POST['action']) && $_POST[ 'action' ] == 'ipcheck') {
|
216 |
+
if (!isset($_POST['ipcheck_nonce'])) die("Failed security check.");
|
217 |
+
if (!wp_verify_nonce($_POST['ipcheck_nonce'],'ipcheck_nonce')) die("Is this a CSRF attempts?");
|
218 |
if (isset($_POST['ipaddress']) && !empty($_POST['ipaddress']))
|
219 |
{
|
220 |
$ip_address = $_POST['ipaddress'];
|
221 |
+
if (iqblockcountry_is_valid_ipv4($ip_address) || iqblockcountry_is_valid_ipv6($ip_address))
|
222 |
+
{
|
223 |
$country = iqblockcountry_check_ipaddress($ip_address);
|
224 |
$countrylist = iqblockcountry_get_countries();
|
225 |
if ($country == "Unknown" || $country == "ipv6" || $country == "" || $country == "FALSE")
|
231 |
$displaycountry = $countrylist[$country];
|
232 |
echo "<p>" . __('IP Adress', 'iqblockcountry') . ' ' . $ip_address . ' ' . __('belongs to', 'iqblockcountry') . ' ' . $displaycountry . ".</p>";
|
233 |
$haystack = get_option('blockcountry_banlist');
|
234 |
+
$inverse = get_option( 'blockcountry_banlist_inverse');
|
235 |
+
if ($inverse) {
|
236 |
+
if (is_array($haystack) && !in_array ($country, $haystack )) {
|
237 |
+
_e('This country is not permitted to visit the frontend of this website.', 'iqblockcountry');
|
238 |
+
echo "<br />";
|
239 |
+
}
|
240 |
+
} else {
|
241 |
if (is_array($haystack) && in_array ( $country, $haystack )) {
|
242 |
_e('This country is not permitted to visit the frontend of this website.', 'iqblockcountry');
|
243 |
echo "<br />";
|
244 |
}
|
245 |
+
}
|
246 |
+
$inverse = get_option( 'blockcountry_backendbanlist_inverse');
|
247 |
+
if ($inverse) {
|
248 |
+
if (is_array($haystack) && !in_array ( $country, $haystack )) {
|
249 |
+
_e('This country is not permitted to visit the backend of this website.', 'iqblockcountry');
|
250 |
+
echo "<br />";
|
251 |
+
}
|
252 |
+
}
|
253 |
+
else
|
254 |
+
{
|
255 |
if (is_array($haystack) && in_array ( $country, $haystack )) {
|
256 |
_e('This country is not permitted to visit the backend of this website.', 'iqblockcountry');
|
257 |
echo "<br />";
|
258 |
}
|
259 |
+
}
|
260 |
$backendbanlistip = unserialize(get_option('blockcountry_backendbanlistip'));
|
261 |
if (is_array($backendbanlistip) && in_array($ip_address,$backendbanlistip)) {
|
262 |
_e('This ip is present in the blacklist.', 'iqblockcountry');
|
263 |
}
|
264 |
}
|
265 |
+
}
|
266 |
}
|
267 |
}
|
268 |
echo '<div class="submit"><input type="submit" name="test" value="' . __( 'Check IP address', 'iqblockcountry' ) . '" /></div>';
|
696 |
|
697 |
?>
|
698 |
</td></tr>
|
699 |
+
<tr valign="top">
|
700 |
+
<th width="30%"><?php _e('Inverse the selection above:', 'iqblockcountry'); ?><br />
|
701 |
+
<?php _e('If you select this option only the countries that are selected are <em>allowed</em>.', 'iqblockcountry')?></th>
|
702 |
+
<td width="70%">
|
703 |
+
<input type="checkbox" name="blockcountry_banlist_inverse" <?php checked('on', get_option('blockcountry_banlist_inverse'), true); ?> />
|
704 |
+
</td></tr>
|
705 |
<tr valign="top">
|
706 |
<th width="30%"><?php _e('Frontend whitelist IPv4 and/or IPv6 addresses:', 'iqblockcountry'); ?><br /><?php _e('Use a semicolon (;) to separate IP addresses', 'iqblockcountry'); ?></th>
|
707 |
<td width="70%">
|
826 |
?>
|
827 |
|
828 |
</td></tr>
|
829 |
+
|
830 |
+
<tr valign="top">
|
831 |
+
<th width="30%"><?php _e('Inverse the selection above:', 'iqblockcountry'); ?><br />
|
832 |
+
<?php _e('If you select this option only the countries that are selected are <em>allowed</em>.', 'iqblockcountry')?></th>
|
833 |
+
<td width="70%">
|
834 |
+
<input type="checkbox" name="blockcountry_backendbanlist_inverse" <?php checked('on', get_option('blockcountry_backendbanlist_inverse'), true); ?> />
|
835 |
+
</td></tr>
|
836 |
+
|
837 |
<tr valign="top">
|
838 |
<th width="30%"><?php _e('Backend whitelist IPv4 and/or IPv6 addresses:', 'iqblockcountry'); ?><br /><?php _e('Use a semicolon (;) to separate IP addresses', 'iqblockcountry'); ?></th>
|
839 |
<td width="70%">
|
925 |
?>
|
926 |
<textarea cols="100" rows="3" name="blockcountry_blockmessage"><?php echo $blockmessage; ?></textarea>
|
927 |
</td></tr>
|
928 |
+
|
929 |
+
|
930 |
<tr valign="top">
|
931 |
<th width="30%"><?php _e('Page to redirect to:', 'iqblockcountry'); ?><br />
|
932 |
<em><?php _e('If you select a page here blocked visitors will be redirected to this page instead of displaying above block message.', 'iqblockcountry'); ?></em></th>
|
949 |
</select>
|
950 |
</td></tr>
|
951 |
|
952 |
+
<tr valign="top">
|
953 |
+
<th width="30%"><?php _e('URL to redirect to:', 'iqblockcountry'); ?><br />
|
954 |
+
<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.', 'iqblockcountry'); ?></em>
|
955 |
+
</th>
|
956 |
+
<td width="70%">
|
957 |
+
<input type="text" style="width:100%" name="blockcountry_redirect_url" value="<?php echo get_option ( 'blockcountry_redirect_url' );?>">
|
958 |
+
</td></tr>
|
959 |
+
|
960 |
<tr valign="top">
|
961 |
<th width="30%"><?php _e('Send headers when user is blocked:', 'iqblockcountry'); ?><br />
|
962 |
<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.', 'iqblockcountry'); ?></em></th>
|
1006 |
<th width="30%"><?php _e('GeoIP API Key:', 'iqblockcountry'); ?><br />
|
1007 |
<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: ', 'iqblockcountry'); ?> <a href="http://geoip.webence.nl/" target=""_blank>http://geoip.webence.nl/</a></em></th>
|
1008 |
</th>
|
1009 |
+
<td width="70%">
|
1010 |
<input type="text" size="25" name="blockcountry_geoapikey" value="<?php echo get_option ( 'blockcountry_geoapikey' );?>">
|
1011 |
+
</td></tr>
|
1012 |
+
|
1013 |
+
|
1014 |
+
<tr valign="top">
|
1015 |
+
<th width="30%"><?php _e('GeoIP API Key Server Location:', 'iqblockcountry'); ?><br />
|
1016 |
+
<em><?php _e('Choose a location closest to your own location.', 'iqblockcountry'); ?>
|
1017 |
+
</th>
|
1018 |
+
<td width="70%">
|
1019 |
+
|
1020 |
+
<input type="radio" name="blockcountry_geoapilocation" value="EU" <?php checked('EU', get_option('blockcountry_geoapilocation'), true); ?>> Europe
|
1021 |
+
<input type="radio" name="blockcountry_geoapilocation" value="US" <?php checked('US', get_option('blockcountry_geoapilocation'), true); ?>> United States
|
1022 |
</td></tr>
|
1023 |
<tr valign="top">
|
1024 |
<th width="30%"><?php _e('Admin block API Key:', 'iqblockcountry'); ?><br />
|
libs/blockcountry-validation.php
CHANGED
@@ -24,6 +24,21 @@ function iqblockcountry_is_valid_ipv6($ipv6)
|
|
24 |
return true;
|
25 |
}
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
/*
|
29 |
* Sanitize callback. Check if supplied IP address list is valid IPv4 or IPv6
|
@@ -99,3 +114,50 @@ function iqblockcountry_check_geoapikey($input)
|
|
99 |
}
|
100 |
return "";
|
101 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
return true;
|
25 |
}
|
26 |
|
27 |
+
/*
|
28 |
+
* Check of an IP address is a valid IPv6 address
|
29 |
+
*/
|
30 |
+
function iqblockcountry_is_valid_url($input)
|
31 |
+
{
|
32 |
+
if(filter_var($input,FILTER_VALIDATE_URL) === FALSE) {
|
33 |
+
return "";
|
34 |
+
}
|
35 |
+
else
|
36 |
+
{
|
37 |
+
return $input;
|
38 |
+
}
|
39 |
+
|
40 |
+
}
|
41 |
+
|
42 |
|
43 |
/*
|
44 |
* Sanitize callback. Check if supplied IP address list is valid IPv4 or IPv6
|
114 |
}
|
115 |
return "";
|
116 |
}
|
117 |
+
|
118 |
+
/*
|
119 |
+
* Check if GeoIP API key is correct.
|
120 |
+
*/
|
121 |
+
function iqblockcountry_check_adminapikey($input)
|
122 |
+
{
|
123 |
+
|
124 |
+
// Check first if API key is empty....
|
125 |
+
if (!empty($input))
|
126 |
+
{
|
127 |
+
|
128 |
+
$url = ADMINAPICHECKURL;
|
129 |
+
|
130 |
+
$result = wp_remote_post(
|
131 |
+
$url,
|
132 |
+
array(
|
133 |
+
'body' => array(
|
134 |
+
'api-key' => $input
|
135 |
+
)
|
136 |
+
)
|
137 |
+
);
|
138 |
+
$message = "";
|
139 |
+
$type = "updated";
|
140 |
+
if ( 200 == $result['response']['code'] ) {
|
141 |
+
$body = $result['body'];
|
142 |
+
$xml = new SimpleXmlElement($body);
|
143 |
+
if ($xml->check != "Ok")
|
144 |
+
{
|
145 |
+
$message = __( 'The Admin Block API key is incorrect. Please update the key.', 'iqblockcountry' );
|
146 |
+
$type = "error";
|
147 |
+
$input = FALSE;
|
148 |
+
}
|
149 |
+
else
|
150 |
+
{
|
151 |
+
$message = __( 'Setting saved.', 'iqblockcountry' );
|
152 |
+
$type = "updated";
|
153 |
+
}
|
154 |
+
}
|
155 |
+
else
|
156 |
+
{
|
157 |
+
$input = FALSE;
|
158 |
+
}
|
159 |
+
add_settings_error('iqblockcountry_adminapi_error',esc_attr( 'settings_updated' ),$message,$type);
|
160 |
+
return $input;
|
161 |
+
}
|
162 |
+
return "";
|
163 |
+
}
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: iqpascal
|
|
3 |
Donate link: http://www.redeo.nl/plugins/donate
|
4 |
Tags: spam, block, countries, country, comments, ban, geo, geo blocking, geo ip, block country, block countries, ban countries, ban country, blacklist, whitelist
|
5 |
Requires at least: 3.5.2
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 1.1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -159,6 +159,14 @@ You can select the option on the home tab "Do not log IP addresses" to stop iQ B
|
|
159 |
|
160 |
== Changelog ==
|
161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
= 1.1.19 =
|
163 |
|
164 |
* Bugfix: Check if MaxMind databases actually exist.
|
3 |
Donate link: http://www.redeo.nl/plugins/donate
|
4 |
Tags: spam, block, countries, country, comments, ban, geo, geo blocking, geo ip, block country, block countries, ban countries, ban country, blacklist, whitelist
|
5 |
Requires at least: 3.5.2
|
6 |
+
Tested up to: 4.3
|
7 |
+
Stable tag: 1.1.20
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
159 |
|
160 |
== Changelog ==
|
161 |
|
162 |
+
= 1.1.20 =
|
163 |
+
|
164 |
+
* Added Google Ads to search engines
|
165 |
+
* Added Redirect URL (Basic code supplied by Stefan)
|
166 |
+
* Added inverse selection on frontend. (Basic code supplied by Stefan)
|
167 |
+
* Added inverse selection on backend.
|
168 |
+
* Validated input on the tools tab.
|
169 |
+
|
170 |
= 1.1.19 =
|
171 |
|
172 |
* Bugfix: Check if MaxMind databases actually exist.
|