Hello. I was just looking for this exact functionality, yay! But... are there any plans for creating a Drupal 7 version? Please?

Comments

Gemini Lights’s picture

Really looking forward towards a Drupal 7 version. +1

espirates’s picture

subscribe+

mediamike’s picture

yes I really need this feature also.
I should have stuck with drupal 6 if I can't get this module.

mgifford’s picture

This can't be that big a module. Could be pretty simple to run it through Coder to get an initial patch in any case.

Andrey Kozhuhov’s picture

Status: Active » Patch (to be ported)
StatusFileSize
new13.94 KB

I made 7.x version yesterday, try it...

Circlefusion1’s picture

Has anyone been able to test the above version?

espirates’s picture

I tested on localhost and it appears to be good to go :)

mgifford’s picture

Can someone run a patch so it's easier for the maintainer to evaluate?

Also, @KAU, did you run it through Coder? If not that should be done before the release.

jboukes’s picture

Assigned: Unassigned » jboukes

Hi Kau,

Very interesting! I am sorry for the (extremely) belated reply, but I do plan to take a look at this in the near future. Having a Drupal 7 version of Country Ban would be very awesome.

--JB

Andrey Kozhuhov’s picture

StatusFileSize
new1.52 MB

I've run it thought Coder and fix a lot of port bugs, it works on one of my projects. Now you can try it.

seanenroute’s picture

The link for the ip-tocountry.csv file at http://ip-to-country.webhosting.info/node/view/6 is not available. Does someone know a different location we can pick up a current version of the ip information?

seanenroute’s picture

Was testing it yesterday on a production website. It was banning a number of countries that hadn't been selected and several countries that had been banned were slipping through.

I'm not sure if it was the included ip addresses being out of date or something to do with the module itself. My personal guess at the moment is the ip addresses being out of date but I won't be able to check over it for a few days due to workload.

jboukes’s picture

It is pretty much assuredly because of the outdated IP addresses. The last I looked, webhosting.info had updated their IP's in 2010. A lot has changed since then.

The Drupal 6.0 version has been updated to rely on another module which uses a much, much fresher batch of IP addresses and thus is much more reliable. I do not know if these relied upon modules are available with Drupal 7. What needs to happen is a Drupal 7 version updated to match the 6.0 functionality, and then I need to get off of my tookus and properly release it.

mgifford’s picture

Interested in seeing the D7 release. Shouldn't be that hard to bring over the updated IP addresses and hopefully we have something from 2012 at this point. http://ip-to-country.webhosting.info/

Anyways, would be good to get a patch rather a zip so it's easy to compare with the latest D6 release.

agojc’s picture

As of november 22th, made myself a csv file from the one i downloaded on http://software77.net/geo-ip/ (too big to be uploaded here : 6 Mb). I had already done the same the day before, these files being updated daily. The module seems ok with these csvs, refresh is ok, works properly. Except that filtering doesn't. Totally or partially, don't know, but it's a fact that certain IPs clearly recognized either in ip2country or on the above site AND banned in countryban module... are not filtered !
Hope this helps...

wiredescape’s picture

What about using the ARIN (American Registry for Internet Numbers) database as ip2country project does or maybe using ip2country as api?

agojc’s picture

Would be a great idea indeed. Checking the origin country of IPs with this module works perfectly.
But... It needs someone who can code to do this (Is the maintainer for this module on the verge of doing it ?), and given the hypothesis that my csv file is good and up to date, i still can't see no reason why the module misses numerous IPs from filtered countries. Which could indicate that the issue lies somewhere else ?

Edit : after further investigating, it appears that the module seems responsible for the issue. Once you've understood how IPs determine the values found in the csv file, you can easily check whether or not the csv file is correct, and consequently whether or not the module gets the proper information. The point is the module does get the right data with the csv file made as explained above. Countries are perfectly recognized. And not quite well filtered...

Edit2 : finally got around this issue with Apache GeoIP module and rules written in .htaccess file.

kenyan’s picture

agojc, please share your solution as we await a drupal 7 version.

stella’s picture

Version: 6.x-1.0 » 6.x-1.4
Status: Patch (to be ported) » Needs review
StatusFileSize
new2.52 KB

The ports above were based on older D6 versions, so I created a fresh port of the country ban module for D7, based off the latest D6 version. It has a dependency on the ip2country module for determining the country of the IP address and I removed the dependency on the Country API module (which hasn't been ported yet). It wasn't really needed anyway.

I also added in a hook_form_alter() which prevents users from countries in "read only" mode from submitting forms, whether it be comment forms, webforms, etc.

Leeteq’s picture

Title: Drupal 7 version? » Drupal 7 version of Country Ban
Category: feature » task

Great, so how about a 7.x-dev branch?

mgifford’s picture

Issue summary: View changes

I think the Maintenance status should be changed. It's pretty inactive from the looks of it.

mclinn’s picture

I had great results with the D6 version so was glad to try the file in #19. From all I can tell it is working fine, though my "live" usage so far has been limited.

I turned the logic on its head, however, with a slight change to function countryban_get_banned_level(). I got tired of entering dozens of countries to block -- and it dawned on me that there were far fewer countries I wanted to allow rather than block.

I haven't changed any admin screens or anything, just added a string, e.g. "US/CA/AU/NZ/DE/FR" to the code. After the line $country_code = ip2country_get_country($ip);, I just check to see if the two-letter code is contained in my "approved countries" string. If so, let 'em in. If not, no dice.

It's working great for me. I can post more details if anyone is interested, just took a few lines of code.

Leeteq’s picture

Yes, @mclinn, that would be nice if you can post some code.

Cross-linking the Whitelist feature request with your comment.

#860968: Whitelisting

Leeteq’s picture

mclinn’s picture

OK, will be away from the computers for a few days but as soon as I get a chance I'll post what I did. Should be able to get to it within the week.

mclinn’s picture

Here is what I did for "quick and dirty" whitelisting, starting with the file in #19 above.

Note that this returns a "Complete Ban" for any ip not returning an approved country code. This is easily modified to "Read Only" by changing the $rval below to 1 vs. 2. You could add some logic to return different bans for different countries without too much trouble.

Starting at line 188, near the end of countryban.module:

ORIGINAL

 // Otherwise, proceed as normal.
  else {
    $ip = ip_address();
    $country_code = ip2country_get_country($ip);
  }
  return variable_get('countryban_' . $country_code, 0);
}

MODIFIED

// Otherwise, proceed as normal.
else {
    // 9/14/mcl: no variables table check, use string in fn mclmod01_ipblock()  	
    $ip = ip_address();
    //$country_code = ip2country_get_country($ip);
    $rval = mclmod01_ipblock($ip); 
  }
  //return variable_get('countryban_' . $country_code, 0);
  return $rval;
}

Here is function mclmod01_ipblock() from a custom module file. You could work this into the original code but I prefer keeping new stuff like this as separate as possible:

/**
 * Called by countryban.module
 * only allow country codes in var $allowstr
 * countryban admin page is ignored
 * 9/14/mcl
 */
function mclmod01_ipblock($ip)  {	
	$allowstr = "US/CA/AU/NZ";	// insert country codes to ALLOW here
	$myip = "11.222.333.444";  // skip this ip
	$lhost = "127.0.0.1";  // skip
	$vbox1 = "192.168.0.198";  // skip
	
	if ($ip == $myip OR $ip==$lhost OR $ip==$vbox1)  // local, don't record it
	  {
	  	$rval = 0;
	  	return $rval;
	  	}	
	  	
	$country_code = ip2country_get_country($ip);		
	if (stristr($allowstr, $country_code))  {
		   $rval = 0;
		   $msg = "ALLOWED: ";
		   $wdcatg = "cb_allowed";
		} 	
	else {
	   $rval = 2;	  
	   $msg = "BLOCKED: ";
	   $wdcatg = "cb_blocked";
	}	
	$msg .= "$country_code / IP: <a href = \"http://en.utrace.de/?query=$ip\">$ip</a>";	
	watchdog($wdcatg, $msg);
	
	return $rval;		
	}

That's it. Plug in your allowed countries, and be sure to add any IP addresses to ignore as shown. This is skipping the user access check and debug portion of the code so it will block any IP that doesn't return an approved country code, regardless of debug or privileges set.

I've also added "watchdog" recording, including a link to double check the IP location once it's recorded.

This could obviously be improved, new admin screen to modify approved countries without touching the code etc. But it is working fine for me in its present state. Maybe if there is an "official" release of a D7 version I'll figure out how to do patches and spruce this up a bit. I'm actually surprised this module hasn't received more attention as it does a superb job of eliminating a huge portion of the spammers and others who just want to mess with a website.

webdrips’s picture

I completely re-wrote this module for D7, and it's now called IP Ban: https://www.drupal.org/project/ip_ban