Changeset 1240


Ignore:
Timestamp:
Oct 20, 2008, 12:24:51 AM (13 years ago)
Author:
Dominic Hargreaves
Message:

Add the ability to whitelist hosts who can change moderated nodes
without explicit moderation - thanks Oliver (fixes #203)

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Build.PL

    r1239 r1240  
    312312        'XML::RSS'                            => 0,
    313313        'Data::Validate::URI'                 => 0,
     314        'Net::Netmask'                        => 0,
     315        'List::Utils'                         => 0,
    314316        },
    315317    build_requires => {
  • trunk/Changes

    r1238 r1240  
    1717        Add an admin navbar, to be displayed if the user requests (#261)
    1818        Move the node image outside the metadata div, to aid styling (#222)
     19        Add the ability to whitelist hosts who can change moderated nodes
     20          without explicit moderation (#203)
    1921
    20220.63    16 August 2008
  • trunk/MANIFEST

    r1236 r1240  
    146146t/78_about.t
    147147t/79_host_blacklist.t
     148t/81_node_moderate_whitelist.t
    148149t/85_universal_edit_link.t
    149150t/templates/15_test.tt
  • trunk/lib/OpenGuides.pm

    r1228 r1240  
    15571557    #  they've been moderated
    15581558    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 ) {
    15601563        $self->_autoCreateCategoryLocale(
    15611564                                          id       => $node,
     
    15681571
    15691572    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
    15831578                );
    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            }
    15861597        }
    15871598
  • trunk/lib/OpenGuides/Config.pm

    r1233 r1240  
    2323   show_gmap_in_node_display google_analytics_key
    2424   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
    2627   enable_node_image enable_common_categories enable_common_locales
    2728   spam_detector_module host_checker_module static_path static_url
     
    8182                     enable_page_deletion => 0,
    8283                     moderation_requires_password => 1,
     84                     moderate_whitelist => "",
    8385                     admin_pass => "Change This!",
    8486                     enable_node_image => 1,
     
    203205        send_moderation_notifications => "Should we send email notifications when a moderated node is edited?",
    204206        website_link_max_chars => "How many characters of the URL of node websites should be displayed?",
     207        moderate_whitelist => "Enter a comma-separated list of IP addresses able to make changes to moderated nodes and have them show up immediately",
    205208    );
    206209
     
    337340=item * send_moderation_notifications
    338341
     342=item * moderate_whitelist
     343
    339344=item * website_link_max_chars (default: C<20>)
    340345
  • trunk/lib/OpenGuides/Test.pm

    r1163 r1240  
    6767                     force_wgs84          => 1,
    6868                     contact_email        => 'admins@example.org',
     69                     moderate_whitelist   => "",
    6970                   }
    7071    );
  • trunk/lib/OpenGuides/Utils.pm

    r1231 r1240  
    1111use URI::Escape;
    1212use MIME::Lite;
     13use Net::Netmask;
     14use List::Util qw( first );
    1315use Data::Validate::URI qw( is_web_uri );
    1416
     
    498500}
    499501
     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
     508Admins can supply a comma separated list of IP addresses or CIDR-notation
     509subnets indicating the hosts which can bypass enforced moderation. Any
     510values which cannot be parsed by C<NetAddr::IP> will be ignored.
     511
     512=cut
     513
     514sub 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
    500531=back
    501532
Note: See TracChangeset for help on using the changeset viewer.