Ticket #203: feature-203-ip-address-mod-whitelist-02.diff
| File feature-203-ip-address-mod-whitelist-02.diff, 9.7 kB (added by oliver, 23 months ago) |
|---|
-
lib/OpenGuides/Config.pm
diff -urN openguides.orig/lib/OpenGuides/Config.pm openguides/lib/OpenGuides/Config.pm
old new 22 22 custom_template_path geo_handler ellipsoid gmaps_api_key centre_long 23 23 show_gmap_in_node_display google_analytics_key 24 24 centre_lat default_gmaps_zoom default_gmaps_search_zoom force_wgs84 25 licence_name licence_url licence_info_url moderation_requires_password 25 licence_name licence_url licence_info_url 26 moderation_requires_password moderate_whitelist 26 27 enable_node_image enable_common_categories enable_common_locales 27 28 spam_detector_module host_checker_module static_path static_url 28 29 send_moderation_notifications website_link_max_chars … … 80 81 indexing_directory => "/usr/lib/cgi-bin/openguides/indexes/", 81 82 enable_page_deletion => 0, 82 83 moderation_requires_password => 1, 84 moderate_whitelist => "", 83 85 admin_pass => "Change This!", 84 86 enable_node_image => 1, 85 87 enable_common_categories => 0, … … 336 338 337 339 =item * send_moderation_notifications 338 340 341 =item * moderate_whitelist 342 339 343 =item * website_link_max_chars (default: C<20>) 340 344 341 345 =back -
lib/OpenGuides/Test.pm
diff -urN openguides.orig/lib/OpenGuides/Test.pm openguides/lib/OpenGuides/Test.pm
old new 66 66 geo_handler => 1, 67 67 force_wgs84 => 1, 68 68 contact_email => 'admins@example.org', 69 moderate_whitelist => "", 69 70 } 70 71 ); 71 72 -
lib/OpenGuides/Utils.pm
diff -urN openguides.orig/lib/OpenGuides/Utils.pm openguides/lib/OpenGuides/Utils.pm
old new 10 10 use Wiki::Toolkit::Plugin::RSS::Reader; 11 11 use URI::Escape; 12 12 use MIME::Lite; 13 use Net::Netmask; 14 use List::Util qw( first ); 13 15 use Data::Validate::URI qw( is_web_uri ); 14 16 15 17 =head1 NAME … … 497 499 } 498 500 } 499 501 502 =item B<in_moderate_whitelist> 503 504 if (OpenGuides::Utils->in_moderate_whitelist( '127.0.0.1' )) { 505 # skip moderation and apply new verson to published site 506 } 507 508 Admins can supply a comma separated list of IP addresses or CIDR-notation 509 subnets indicating the hosts which can bypass enforced moderation. Any 510 values which cannot be parsed by C<NetAddr::IP> will be ignored. 511 512 =cut 513 514 sub in_moderate_whitelist { 515 my ($self, $config, $ip) = @_; 516 return undef if not defined $ip; 517 518 # create NetAddr::IP object of the test IP 519 my $addr = Net::Netmask->new2($ip) or return undef; 520 521 # load the configured whitelist 522 my @whitelist 523 = split ',', $config->moderate_whitelist; 524 525 # test each entry in the whitelist 526 return eval{ 527 first { Net::Netmask->new2($_)->match($addr->base) } @whitelist 528 }; 529 } 530 500 531 =back 501 532 502 533 =head1 AUTHOR -
lib/OpenGuides.pm
diff -urN openguides.orig/lib/OpenGuides.pm openguides/lib/OpenGuides.pm
old new 1556 1556 # Skip this for nodes needing moderation - this occurs for them once 1557 1557 # they've been moderated 1558 1558 my $needs_moderation = $wiki->node_required_moderation($node); 1559 unless( $needs_moderation ) { 1559 my $in_moderate_whitelist 1560 = OpenGuides::Utils->in_moderate_whitelist($self->config, $new_metadata{host}); 1561 1562 if ( $in_moderate_whitelist or not $needs_moderation ) { 1560 1563 $self->_autoCreateCategoryLocale( 1561 1564 id => $node, 1562 1565 metadata => \%new_metadata … … 1567 1570 \%new_metadata ); 1568 1571 1569 1572 if ($written) { 1570 if ( $needs_moderation and $config->send_moderation_notifications ) { 1571 my $body = "The node '$node' in the OpenGuides installation\n" . 1572 "'" . $config->site_name . "' requires moderation. ". 1573 "Please visit\n" . 1574 $config->script_url . $config->script_name . 1575 "?action=show_needing_moderation\nat your convenience.\n"; 1576 eval { 1577 OpenGuides::Utils->send_email( 1578 config => $config, 1579 subject => "Node requires moderation", 1580 body => $body, 1581 admin => 1, 1582 return_output => $return_output 1573 if ( $needs_moderation ) { 1574 if ( $in_moderate_whitelist ) { 1575 $self->wiki->moderate_node( 1576 name => $node, 1577 version => $written 1583 1578 ); 1584 }; 1585 warn $@ if $@; 1579 } 1580 elsif ( $config->send_moderation_notifications ) { 1581 my $body = "The node '$node' in the OpenGuides installation\n" . 1582 "'" . $config->site_name . "' requires moderation. ". 1583 "Please visit\n" . 1584 $config->script_url . $config->script_name . 1585 "?action=show_needing_moderation\nat your convenience.\n"; 1586 eval { 1587 OpenGuides::Utils->send_email( 1588 config => $config, 1589 subject => "Node requires moderation", 1590 body => $body, 1591 admin => 1, 1592 return_output => $return_output 1593 ); 1594 }; 1595 warn $@ if $@; 1596 } 1586 1597 } 1587 1598 1588 1599 my $output = $self->redirect_to_node($node); -
t/81_node_moderate_whitelist.t
diff -urN openguides.orig/t/81_node_moderate_whitelist.t openguides/t/81_node_moderate_whitelist.t
old new 1 use strict; 2 use Wiki::Toolkit::Setup::SQLite; 3 use OpenGuides; 4 use OpenGuides::Test; 5 use Test::More; 6 7 eval { require DBD::SQLite; }; 8 9 if ( $@ ) { 10 my ($error) = $@ =~ /^(.*?)\n/; 11 plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; 12 } 13 14 plan tests => 12; 15 16 Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); 17 my $config = OpenGuides::Test->make_basic_config; 18 $config->script_name( "wiki.cgi" ); 19 $config->script_url( "http://example.com/" ); 20 $config->moderate_whitelist( "127.0.0.1" ); 21 my $guide = OpenGuides->new( config => $config ); 22 isa_ok( $guide, "OpenGuides" ); 23 my $wiki = $guide->wiki; 24 isa_ok( $wiki, "Wiki::Toolkit" ); 25 26 # Clear out the database from any previous runs. 27 foreach my $del_node ( $wiki->list_all_nodes ) { 28 print "# Deleting node $del_node\n"; 29 $wiki->delete_node( $del_node ) or die "Can't delete $del_node"; 30 } 31 32 33 # Add a page 34 my $q = CGI->new; 35 $q->param( -name => "content", -value => "foo" ); 36 $q->param( -name => "categories", -value => "Alpha" ); 37 $q->param( -name => "locales", -value => "" ); 38 $q->param( -name => "phone", -value => "" ); 39 $q->param( -name => "fax", -value => "" ); 40 $q->param( -name => "website", -value => "" ); 41 $q->param( -name => "hours_text", -value => "" ); 42 $q->param( -name => "address", -value => "" ); 43 $q->param( -name => "postcode", -value => "" ); 44 $q->param( -name => "map_link", -value => "" ); 45 $q->param( -name => "os_x", -value => "" ); 46 $q->param( -name => "os_y", -value => "" ); 47 $q->param( -name => "username", -value => "bob" ); 48 $q->param( -name => "comment", -value => "foo" ); 49 $q->param( -name => "edit_type", -value => "Minor tidying" ); 50 $ENV{REMOTE_ADDR} = "127.0.0.1"; 51 52 my $output = $guide->commit_node( 53 return_output => 1, 54 id => "Wombats", 55 cgi_obj => $q, 56 ); 57 58 # Check it's moderated 59 my %details = $wiki->retrieve_node("Wombats"); 60 is($details{'moderated'}, 1, "Moderated"); 61 is($wiki->node_required_moderation("Wombats"), 0, "No moderation"); 62 63 # Turn on moderation 64 $wiki->set_node_moderation( 65 name => "Wombats", 66 required => 1, 67 ); 68 is($wiki->node_required_moderation("Wombats"), 1, "Moderation"); 69 70 71 # Now add a new one, with new categories and locales 72 $q->param( -name => "categories", -value => "Alpha\r\nBeta" ); 73 $q->param( -name => "locales", -value => "Hello" ); 74 $q->param( -name => "edit_type", -value => "Normal edit" ); 75 $q->param( -name => "checksum", -value => $details{checksum} ); 76 $output = $guide->commit_node( 77 return_output => 1, 78 id => "Wombats", 79 cgi_obj => $q, 80 ); 81 82 # Check that the current version is now 2 83 %details = $wiki->retrieve_node("Wombats"); 84 is($details{'version'}, 2, "Still on v1"); 85 is($details{'moderated'}, 1, "v1 Moderated"); 86 87 # Check that version 2 is moderated 88 my %v2 = $wiki->retrieve_node(name=>"Wombats",version=>2); 89 is($v2{'version'}, 2, "Is v2"); 90 is($v2{'moderated'}, 1, "Moderated"); 91 92 # Check that the new categories and locales are there 93 is(1, $wiki->node_exists("Category Alpha"), "Right Categories"); 94 is(1, $wiki->node_exists("Category Beta"), "Right Categories"); 95 is(1, $wiki->node_exists("Locale Hello"), "Right Locales"); 96
