Needs review
Project:
Country Ban
Version:
6.x-1.4
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
7 Apr 2011 at 20:38 UTC
Updated:
12 Oct 2016 at 09:01 UTC
Jump to comment: Most recent, Most recent file
Hello. I was just looking for this exact functionality, yay! But... are there any plans for creating a Drupal 7 version? Please?
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | countryban.tgz | 2.52 KB | stella |
| #10 | countryban7.x-1.1.zip | 1.52 MB | Andrey Kozhuhov |
| #5 | countryban-7.x.zip | 13.94 KB | Andrey Kozhuhov |
Comments
Comment #1
Gemini Lights commentedReally looking forward towards a Drupal 7 version. +1
Comment #2
espirates commentedsubscribe+
Comment #3
mediamike commentedyes I really need this feature also.
I should have stuck with drupal 6 if I can't get this module.
Comment #4
mgiffordThis can't be that big a module. Could be pretty simple to run it through Coder to get an initial patch in any case.
Comment #5
Andrey Kozhuhov commentedI made 7.x version yesterday, try it...
Comment #6
Circlefusion1 commentedHas anyone been able to test the above version?
Comment #7
espirates commentedI tested on localhost and it appears to be good to go :)
Comment #8
mgiffordCan 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.
Comment #9
jboukes commentedHi 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
Comment #10
Andrey Kozhuhov commentedI've run it thought Coder and fix a lot of port bugs, it works on one of my projects. Now you can try it.
Comment #11
seanenroute commentedThe 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?
Comment #12
seanenroute commentedWas 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.
Comment #13
jboukes commentedIt 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.
Comment #14
mgiffordInterested 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.
Comment #15
agojc commentedAs 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...
Comment #16
wiredescape commentedWhat about using the ARIN (American Registry for Internet Numbers) database as ip2country project does or maybe using ip2country as api?
Comment #17
agojc commentedWould 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.
Comment #18
kenyan commentedagojc, please share your solution as we await a drupal 7 version.
Comment #19
stella commentedThe 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.
Comment #20
Leeteq commentedGreat, so how about a 7.x-dev branch?
Comment #21
mgiffordI think the Maintenance status should be changed. It's pretty inactive from the looks of it.
Comment #22
mclinn commentedI 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.
Comment #23
Leeteq commentedYes, @mclinn, that would be nice if you can post some code.
Cross-linking the Whitelist feature request with your comment.
#860968: Whitelisting
Comment #24
Leeteq commentedComment #25
mclinn commentedOK, 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.
Comment #26
mclinn commentedHere 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
MODIFIED
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:
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.
Comment #27
webdrips commentedI completely re-wrote this module for D7, and it's now called IP Ban: https://www.drupal.org/project/ip_ban