My client had a need for this module with several features tweaked from the original. It ended up almost a complete rewrite.
Summary:
- It is about half the size in terms of code.
- No longer has any database tables.
- Introduced dependancy on IP to Country and Countries API modules because this module was just duplicating their data.
- Generates the country list using those apis so no more hard coded country list in the form that needs to be manually maintained.
- Added a 'ignore countryban' permission so good users can be assigned to a role that is never blocked regardless of their country.
- Issues proper drupal 403 Forbidden page when a country is completely blocked, instead of redirecting to the home page (the current module always infinitely redirected in a loop for me because the home page was forbidden too, so not sure that would have ever worked anyway).
- Allows /user/login page to be accessible from completely blocked countries so that the admin user can login (just in case you accidentally block yourself or are travelling).
- Theme function to generate admin form (renders a nice themed table with sticky headers by default).
- Changed ban settings for each country to select box from radio buttons to make form more concise and quicker to scan.
- Moved the code that did the ban status lookup for an IP into scope where it was only necessary and also made it static instead of every hook_user call.
- Removed csv updating function because ip2cc module does it already.
I attach it here and hope that the maintainer might want to roll it into the main module. If you want patch files I can give them to you but a complete replacement is probably easier.
If anyone wants to try it and is upgrading from an existing install there is one thing to be aware of. The variable names for the individual country ban settings have changed (stored in the variables table). Previously they were for example 'countryban_australia' but now they are 'countryban_AU'. This was done because there was some not very nice code which was converting country names and removing spaces and punctuation etc which was all fairly needless. I would just note down your settings then update and reapply them, as I have not written an upgrade script.
We are using this version now and it works well. Many thanks for the original module. Our spam from Indian "SEO" companies has been cut to zero.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | countryban_patched_again.zip | 4.33 KB | mr.j |
| countryban_patched.zip | 4.38 KB | mr.j |
Comments
Comment #1
mr.j commentedForgot to add. This version fixes all these issues:
#805942: Does country ban also blocks every user (including anonymous user) from accessing the site?
#938290: no such thing as hook_admin
#938292: theme country radio buttons into a table
#942040: install ignores db_prefix in settings.php
#822412: Why don't you reference the IP2CC module?
Comment #2
mr.j commentedUgh just noticed countryban.install still had a line that was trying to delete the schema on uninstall, but the schema no longer exists.
Fixed version attached.
Comment #3
jboukes commentedAwesome Mr. J! I will will definitely look into folding these changes in (or even simply using your new version). It is true it may be a little bit before I can get to it, as I am temporarily swamped.
In the meantime, if anyone might try this new version out and provide some feedback, that would be appreciated.
Thank you for sharing the update and fixes!
Comment #4
scolvin commentedThank you very much, very useful module and great improvements.
Would be wonderful if one could select all, or select whole a region to ban/set to read only.
Also would be wonderful if the module could provide control over which areas of a site can be visited by people from a particular country. this might be most easily be done by setting a role based on location? Sorry if some module already exists to do this, I've looked and can't see one.
Comment #5
mr.j commentedApplying a setting to all countries would be fairly simple using some javascript.
Doing it by region would be more difficult because there is nothing in the data that relates the countries to each other like that. So the module would have to introduce some data to relate the countries and maintain it over time - and I specifically tried to remove the need for any country data maintenance in our version of this module by making it dependant on ip2cc. So that maybe more trouble than its worth. I know its probably a pain to make a whole load of selections, but its the kind of thing you only need to do once (or at least very rarely) on a site.
Re last suggestion - it depends what you mean by "areas" of the site. If it is by path then there is the Path Access module. If it is by module or user permission then standard drupal could do it. But in either case you would have to assign users to roles like you say - and that would not really help with anonymous users.
Comment #6
Suzy commentedmr j. +1 this sounds ideal (along with troll) for our purposes - am just letting you know I've just downloaded and installed your version, I didn't use the previous version so won't be able to compare but the "ignore countryban" permission should be invaluable on it's own, Thanks for providing this
Comment #7
modctek commentedSubscribing - I like what this module does. I'd love to see the ability to set a level of access by default, as opposed to having to set it manually for each country. Granted, that only has to be done once, but if I'm implementing on multiple sites with fairly strict access rules, it gets tedious. Checkboxes/radio buttons might make it slightly faster.
Comment #8
drupalina commentedThis version of the module from attachment in comment #2 did not work for me (I did install the 2 dependable modules as well and imported and updated the databse in ip2cc module)
I wanted to completely block some countries. As a test I blocked Belgium and gave a ring to my friend in Belgium and asked what my website looked like. He looked and it opened in Belgium as usual (NOT GOOD) - he said that he could see the header, the menus, the blocks and the content.
Did I miss something? clearing cache? running cron? A README file or installation instructions would be really helpful at this point.
By the way, can anyone recommend some web proxy website so that I can check what my website looks like in another country?
What would also be useful is if there was an option not for Drupal 403, but a display of a separate html file -- that way people can customize the html and not show that there is drupal running. For example, would be nice to display a simple white page with a simple "Under construction" message.
Thanks.
Comment #9
mr.j commentedDoes the released version of the module work?
The version I wrote here should have no difference in terms of blocking from the released version of the module. It uses the same data.
If the regular released version doesn't work either, it could be an inaccuracy in the IP ranges used by IP to Country.
Google 'free web proxy'. I have found hidemyass.com to work in the past.
Comment #10
drupalina commentedI will test the official version and report here in few days (it takes a few days to get hold of my friend in Belgium :))
Thanks for the pointer, but HideMyAss does not give an option to select a specific country, or else I would not need to call my friend in Belgium. In fact, I haven't found any free Web Proxy that would allow selecting a specific country. Without such proxy the testing of this module's functionality is a pretty slow process.
Comment #11
sinasalek commentedThanks for sharing it! source code is much cleaner and easier to extend.
Some suggestions :
- One very useful option is possibility of making a whitelist instead of blacklist which is useful for local websites.
- There has to be a way to let search engines crawl the site for SEO
- Supporting anonymous users as well
I'll share a new version if i implemented this features in a generic way.
Comment #12
Suzy commented@sinasalek
I have a local website, which is exactly why CB, in particular the one with mr. j's refinements (why isn't this the official version yet? ;)), is ideal
it does all that, you just set the countries to read only instead of outright ban, this let's the SE crawl and supports anonymous users - "Read Only" just blocks the login / user signup page, reducing the spam signup dramatically (almost completely actually if you're in the UK ;)) - as for a whitelist.. it's a one time job (took me 3-4 minutes I think) to set all the countries to read only.. the "whitelist" is then one click each to "unban" the 3 countries I want to
I've set all but 3 countries to read only - and even if an existing member then tries to actually login to the site from a "read only" country they can still get in because I set all "authorised" members to ignore countryban in the permissions.. if anyone does really want to signup from a read only country, they can contact the admin - or I'm sure you could put a message to that effect on your login page (custom redirect page) for people who legitimately want to sign up - if they take the time to contact you they are likely not spammers but you could always check the email address on "stopforumspam.com" - so email them apologise for the necessary measures blah blah and give them a "sign up window" time.. say 24 hours - unban their country for 24 hours or as long as it takes them to sign up - then reban the country again .. then deal with with the rubbish that signed up during the window .. job done, it takes less time to do that that deal with spam sign ups every few hours and makes this module an absolute godsend!
did i say thanks Mr.J :)
Comment #13
sinasalek commented@suzy,
Yes Whiteley is not a big deal mostly a usability feature.
As for search engines, there is a difference between read-only and ban. There are many website that don't let people from other countries to consume their bandwidth so they completely ban non local visitors. However they still want search engines to index their website because otherwise visitors can't find the website through search engines unless they have local crawlers.
I really hope that the maintainer (@jboukes ) include @mr.j's effort in the next release.
Comment #14
jboukes commented>>"I really hope that the maintainer (@jboukes ) include @mr.j's effort in the next release."
I do intend to! I know I have been MIA. This current semester is killing me. Once the dust settles (a little bit longer) I intend to roll up a new release include much if not all of mr.j's edition.
Comment #15
sinasalek commentedThat would be great thanks @jboukes for the reply
Comment #16
drupalina commentedFEATURE REQUEST for new version:
Countries with Complete Ban can still see contents of blocks and menus etc, which contain a lot of information. This is because it gives "Access denied" to node content. Would it be possible to have a 3rd option to show a simple custom HTML page without any indication of drupal installation (no blocks, no menus, no logos, no access denied message) - just a simple white HTML page that we can later customize through Dreamweaver??? For banned countries I'd like to show just a white page that says "Nothing to see here" or something like that. I think this option would be helpful for many others who would want to do some redirects to other sites as well. Thanks!
PS: an update on #8... I've tested with another friend from France, and it works - it shows Access Denied, but for some reason it didn't work for another friend from Belgium. hmm....
Comment #17
modctek commentedIf a country is set to "Read-only" permissions via this modified version of the module, should anonymous visitors from the target country still be able to post comments (which is allowed in the global permission set for anonymous role)? Or does this module only prevent account creation? I ask because I've implemented the modified module, but we are still getting comment spam from countries set to "read only".
Comment #18
mr.j commentedmodctek, I don't think this will stop anonymous comments from anyone. At least the released version doesn't and I never added anything because they don't allow anonymous comments on the site this was developed for.
It shouldn't be too hard to add though. It probably just needs a check in hook_comment like this (pseudo-code only, this won't work):
Comment #19
wiredescape commentedsubscribing...
Comment #20
webdrips commentedThe Drupal 7 version of Country Ban can be found here: https://www.drupal.org/project/ip_ban