Author: earle
Date: 2007-08-03 20:16:51 +0100 (Fri, 03 Aug 2007)
New Revision: 1117
Added:
trunk/t/79_host_blacklist.t
trunk/templates/blacklisted_host.tt
Modified:
trunk/Build.PL
trunk/Changes
trunk/MANIFEST
trunk/lib/OpenGuides.pm
trunk/lib/OpenGuides/Config.pm
Log:
Add support for IP blacklisting modules.
Modified: trunk/Build.PL
===================================================================
--- trunk/Build.PL 2007-07-22 08:47:35 UTC (rev 1116)
+++ trunk/Build.PL 2007-08-03 19:16:51 UTC (rev 1117)
@@ -105,7 +105,8 @@
default_gmaps_search_zoom force_wgs84 google_analytics_key
licence_name licence_url licence_info_url moderation_requires_password
enable_node_image enable_common_categories enable_common_locales
- spam_detector_module static_path static_url send_moderation_notifications
+ spam_detector_module host_checker_module static_path static_url
+ send_moderation_notifications
) ) {
my $q_method = $var . "__qu";
my $qu = $existing_config->$q_method;
@@ -332,6 +333,7 @@
"admin_revert_user.tt",
"backlink_results.tt",
"banner.tt",
+ "blacklisted_host.tt",
"delete_confirm.tt",
"delete_done.tt",
"delete_password_wrong.tt",
Modified: trunk/Changes
===================================================================
--- trunk/Changes 2007-07-22 08:47:35 UTC (rev 1116)
+++ trunk/Changes 2007-08-03 19:16:51 UTC (rev 1117)
@@ -1,10 +1,12 @@
"#" items refer to tickets. See <http://dev.openguides.org/report/9> for
details.
More detailed changelogs can be found at
-http://dev.openguides.org/log/trunk
+<http://dev.openguides.org/log/trunk>.
0.62
Ensure that all modules we ship are versioned.
+ Added experimental support for local IP blacklisting modules; see the
+ display_node method in "perldoc OpenGuides" for details.
0.61 4 July 2007
Added experimental support for local spam detection modules; see the
Modified: trunk/MANIFEST
===================================================================
--- trunk/MANIFEST 2007-07-22 08:47:35 UTC (rev 1116)
+++ trunk/MANIFEST 2007-08-03 19:16:51 UTC (rev 1117)
@@ -30,6 +30,7 @@
templates/admin_revert_user.tt
templates/backlink_results.tt
templates/banner.tt
+templates/blacklisted_host.tt
templates/delete_confirm.tt
templates/delete_done.tt
templates/delete_password_wrong.tt
@@ -142,5 +143,6 @@
t/76_detect_spam.t
t/77_send_email.t
t/78_about.t
+t/79_host_blacklist.t
t/templates/15_test.tt
wiki.cgi
Modified: trunk/lib/OpenGuides/Config.pm
===================================================================
--- trunk/lib/OpenGuides/Config.pm 2007-07-22 08:47:35 UTC (rev 1116)
+++ trunk/lib/OpenGuides/Config.pm 2007-08-03 19:16:51 UTC (rev 1117)
@@ -3,7 +3,7 @@
use warnings;
use vars qw( $VERSION );
-$VERSION = '0.01';
+$VERSION = '0.02';
use Carp qw( croak );
use Config::Tiny;
@@ -24,7 +24,8 @@
centre_lat default_gmaps_zoom default_gmaps_search_zoom force_wgs84
licence_name licence_url licence_info_url moderation_requires_password
enable_node_image enable_common_categories enable_common_locales
- spam_detector_module static_path static_url send_moderation_notifications
+ spam_detector_module host_checker_module static_path static_url
+ send_moderation_notifications
);
my @questions = map { $_ . "__qu" } @variables;
OpenGuides::Config->mk_accessors( @variables );
@@ -111,6 +112,7 @@
licence_url => "",
licence_info_url => "",
spam_detector_module => "",
+ host_checker_module => "",
static_path => "/usr/local/share/openguides/static",
send_moderation_notifications => 1
);
@@ -194,6 +196,7 @@
licence_url => "What is the URL to your licence?",
licence_info_url => "What is the URL to your local page about your
licensing policy?",
spam_detector_module => "What module would you like to use for spam
detection? (optional)",
+ host_checker_module => "What module would you like to use to run an IP
blacklist? (optional)",
static_path => "What directory should we install static content (CSS,
images, javascript) to?",
static_url => "What is the URL corresponding to the static
content?",
send_moderation_notifications => "Should we send email notifications when
a moderated node is edited?"
@@ -323,6 +326,8 @@
=item * spam_detector_module
+=item * host_checker_module
+
=item * static_path
=item * static_url
Modified: trunk/lib/OpenGuides.pm
===================================================================
--- trunk/lib/OpenGuides.pm 2007-07-22 08:47:35 UTC (rev 1116)
+++ trunk/lib/OpenGuides.pm 2007-08-03 19:16:51 UTC (rev 1117)
@@ -176,6 +176,15 @@
(At the moment, C<return_tt_vars> acts as if the C<intercept_redirect>
parameter was passed.)
+If you have specified the C<host_checker_module> option in your
+C<wiki.conf>, this method will attempt to call the <blacklisted_host>
+method of that module to determine whether the host requesting the node
+has been blacklisted. If this method returns true, then the
+C<blacklisted_host.tt> template will be used to display an error message.
+
+The C<blacklisted_host> method will be passed a scalar containing the host's
+IP address.
+
=cut
sub display_node {
@@ -191,6 +200,30 @@
my %tt_vars;
+ # If we can, check to see if requesting host is blacklisted.
+ my $host_checker = $config->host_checker_module;
+ my $is_blacklisted;
+ if ( $host_checker ) {
+ eval {
+ eval "require $host_checker";
+ $is_blacklisted =
$host_checker->blacklisted_host(CGI->new->remote_host);
+ };
+ }
+
+ if ( $is_blacklisted ) {
+ my $output = OpenGuides::Template->output(
+ wiki => $self->wiki,
+ config => $config,
+ template => "blacklisted_host.tt",
+ vars => {
+ not_editable => 1,
+ },
+ );
+ return $output if $return_output;
+ print $output;
+ return;
+ }
+
$tt_vars{home_name} = $self->config->home_name;
if ( $id =~ /^(Category|Locale) (.*)$/ ) {
Added: trunk/t/79_host_blacklist.t
===================================================================
--- trunk/t/79_host_blacklist.t (rev 0)
+++ trunk/t/79_host_blacklist.t 2007-08-03 19:16:51 UTC (rev 1117)
@@ -0,0 +1,52 @@
+use strict;
+
+use OpenGuides;
+use OpenGuides::Test;
+use Test::More;
+use Wiki::Toolkit::Setup::SQLite;
+
+eval { require DBD::SQLite; };
+if ( $@ ) {
+ my ($error) = $@ =~ /^(.*?)\n/;
+ plan skip_all => "DBD::SQLite could not be used - no database to test with.
($error)";
+}
+
+plan tests => 1;
+
+# Clear out the database from any previous runs.
+unlink "t/node.db";
+unlink <t/indexes/*>;
+Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
+
+# Set up a guide which uses a spam detector module.
+my $config = OpenGuides::Test->make_basic_config;
+$config->host_checker_module( "OpenGuides::Local::HostBlacklist" );
+my $guide = OpenGuides->new( config => $config );
+
+# Ensure CGI tells us what we expect to hear.
+sub fake {'127.0.0.1'}
+
+use CGI;
+{
+ no warnings 'once';
+ *CGI::remote_host = \&fake;
+}
+
+my $output = $guide->display_node(
+ id => "Nonesuch",
+ return_output => 1,
+ );
+
+like($output, qr/Access denied/, 'host blacklist picks up IP');
+
+package OpenGuides::Local::HostBlacklist;
+
+sub blacklisted_host {
+ my ( $class, $host ) = @_;
+
+ if ( $host =~ /^127/ ) {
+ return 1;
+ }
+
+ return 0;
+}
Added: trunk/templates/blacklisted_host.tt
===================================================================
--- trunk/templates/blacklisted_host.tt (rev 0)
+++ trunk/templates/blacklisted_host.tt 2007-08-03 19:16:51 UTC (rev 1117)
@@ -0,0 +1,19 @@
+[% INCLUDE header.tt page_title = "Access denied" %]
+[% INCLUDE banner.tt %]
+
+[% IF !config.content_above_navbar_in_html %]
+ [% INCLUDE navbar.tt %]
+[% END %]
+
+<div id="maincontent">
+ <h1>Access denied</h1>
+
+ <p>Your Internet host address has been banned from accessing this site. If you
+ believe this to be in error, please contact the guide administrator.</p>
+</div>
+
+[% IF config.content_above_navbar_in_html %]
+ [% INCLUDE navbar.tt %]
+[% END %]
+
+[% INCLUDE footer.tt %]